From: terencehill Date: Fri, 31 Jul 2015 13:33:48 +0000 (+0200) Subject: Port the improved scrolling by keys behaviour for lists that don't need to show an... X-Git-Tag: xonotic-v0.8.1~11^2~9 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=ae0dcac15aa2429893c71e414344c9eee941b74e;p=xonotic%2Fxonotic-data.pk3dir.git Port the improved scrolling by keys behaviour for lists that don't need to show an active selection from the credit list to the listbox class so it can be used by other classes too; now the stats list, like the credit list, doesn't show any selection as it's useless. --- diff --git a/qcsrc/menu/item/listbox.qc b/qcsrc/menu/item/listbox.qc index f90e3b901..b5ca74b3c 100644 --- a/qcsrc/menu/item/listbox.qc +++ b/qcsrc/menu/item/listbox.qc @@ -32,6 +32,7 @@ CLASS(ListBox, Item) ATTRIB(ListBox, controlBottom, float, 0) ATTRIB(ListBox, controlWidth, float, 0) ATTRIB(ListBox, dragScrollPos, vector, '0 0 0') + ATTRIB(ListBox, selectionDoesntMatter, bool, false) // improves scrolling by keys for lists that don't need to show an active selection ATTRIB(ListBox, src, string, string_null) // scrollbar ATTRIB(ListBox, color, vector, '1 1 1') @@ -166,6 +167,12 @@ float ListBox_keyDown(entity me, float key, float ascii, float shift) } else if(key == K_PGUP || key == K_KP_PGUP) { + if(me.selectionDoesntMatter) + { + me.scrollPosTarget = max(me.scrollPosTarget - 0.5, 0); + return 1; + } + float i = me.selectedItem; float a = me.getItemHeight(me, i); for (;;) @@ -181,6 +188,12 @@ float ListBox_keyDown(entity me, float key, float ascii, float shift) } else if(key == K_PGDN || key == K_KP_PGDN) { + if(me.selectionDoesntMatter) + { + me.scrollPosTarget = min(me.scrollPosTarget + 0.5, me.nItems * me.itemHeight - 1); + return 1; + } + float i = me.selectedItem; float a = me.getItemHeight(me, i); for (;;) @@ -195,9 +208,25 @@ float ListBox_keyDown(entity me, float key, float ascii, float shift) me.setSelected(me, i - 1); } else if(key == K_UPARROW || key == K_KP_UPARROW) + { + if(me.selectionDoesntMatter) + { + me.scrollPosTarget = max(me.scrollPosTarget - me.itemHeight, 0); + return 1; + } + me.setSelected(me, me.selectedItem - 1); + } else if(key == K_DOWNARROW || key == K_KP_DOWNARROW) + { + if(me.selectionDoesntMatter) + { + me.scrollPosTarget = min(me.scrollPosTarget + me.itemHeight, me.nItems * me.itemHeight - 1); + return 1; + } + me.setSelected(me, me.selectedItem + 1); + } else if(key == K_HOME || key == K_KP_HOME) me.setSelected(me, 0); else if(key == K_END || key == K_KP_END) diff --git a/qcsrc/menu/xonotic/credits.qc b/qcsrc/menu/xonotic/credits.qc index ba7f7019b..e3bc1c339 100644 --- a/qcsrc/menu/xonotic/credits.qc +++ b/qcsrc/menu/xonotic/credits.qc @@ -9,6 +9,7 @@ CLASS(XonoticCreditsList, XonoticListBox) METHOD(XonoticCreditsList, resizeNotify, void(entity, vector, vector, vector, vector)) METHOD(XonoticCreditsList, keyDown, float(entity, float, float, float)) METHOD(XonoticCreditsList, destroy, void(entity)) + ATTRIB(XonoticCreditsList, selectionDoesntMatter, bool, true) ATTRIB(XonoticCreditsList, realFontSize, vector, '0 0 0') ATTRIB(XonoticCreditsList, realUpperMargin, float, 0) @@ -88,19 +89,7 @@ void XonoticCreditsList_drawListBoxItem(entity me, int i, vector absSize, bool i float XonoticCreditsList_keyDown(entity me, float key, float ascii, float shift) { - me.dragScrollTimer = time; me.scrolling = 0; - if(key == K_PGUP || key == K_KP_PGUP) - me.scrollPosTarget = max(me.scrollPosTarget - 0.5, 0); - else if(key == K_PGDN || key == K_KP_PGDN) - me.scrollPosTarget = min(me.scrollPosTarget + 0.5, me.nItems * me.itemHeight - 1); - else if(key == K_UPARROW || key == K_KP_UPARROW) - me.scrollPosTarget = max(me.scrollPosTarget - me.itemHeight, 0); - else if(key == K_DOWNARROW || key == K_KP_DOWNARROW) - me.scrollPosTarget = min(me.scrollPosTarget + me.itemHeight, me.nItems * me.itemHeight - 1); - else - return SUPER(XonoticCreditsList).keyDown(me, key, ascii, shift); - - return 1; + return SUPER(XonoticCreditsList).keyDown(me, key, ascii, shift); } #endif diff --git a/qcsrc/menu/xonotic/statslist.qc b/qcsrc/menu/xonotic/statslist.qc index d9a22ec6e..bfa050abd 100644 --- a/qcsrc/menu/xonotic/statslist.qc +++ b/qcsrc/menu/xonotic/statslist.qc @@ -14,6 +14,7 @@ CLASS(XonoticStatsList, XonoticListBox) METHOD(XonoticStatsList, keyDown, float(entity, float, float, float)) METHOD(XonoticStatsList, destroy, void(entity)) METHOD(XonoticStatsList, showNotify, void(entity)) + ATTRIB(XonoticStatsList, selectionDoesntMatter, bool, true) ATTRIB(XonoticStatsList, listStats, float, -1) ATTRIB(XonoticStatsList, realFontSize, vector, '0 0 0') @@ -317,9 +318,7 @@ void XonoticStatsList_resizeNotify(entity me, vector relOrigin, vector relSize, void XonoticStatsList_drawListBoxItem(entity me, int i, vector absSize, bool isSelected, bool isFocused) { - if(isSelected) - draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED); - else if(isFocused) + if(isFocused) { me.focusedItemAlpha = getFadedAlpha(me.focusedItemAlpha, SKINALPHA_LISTBOX_FOCUSED, SKINFADEALPHA_LISTBOX_FOCUSED); draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_FOCUSED, me.focusedItemAlpha);