]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/menu/xonotic/picker.qc
Merge branch 'master' into terencehill/lms_updates
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / xonotic / picker.qc
index 86eb7dc90cb73bebbc7b699e0b521748671855e0..527697683218d87a2550f862ddd36b2a3dd67299 100644 (file)
@@ -1,39 +1,11 @@
-#ifdef INTERFACE
-CLASS(XonoticPicker) EXTENDS(Item)
-       METHOD(XonoticPicker, configureXonoticPicker, void(entity))
-       METHOD(XonoticPicker, mousePress, float(entity, vector))
-       METHOD(XonoticPicker, mouseRelease, float(entity, vector))
-       METHOD(XonoticPicker, mouseMove, float(entity, vector))
-       METHOD(XonoticPicker, mouseDrag, float(entity, vector))
-       METHOD(XonoticPicker, keyDown, float(entity, float, float, float))
-       METHOD(XonoticPicker, draw, void(entity))
-       ATTRIB(XonoticPicker, focusable, float, 1)
-       ATTRIB(XonoticPicker, disabled, float, 0)
-       ATTRIB(XonoticPicker, alpha, float, 1)
-       ATTRIB(XonoticPicker, disabledAlpha, float, SKINALPHA_DISABLED)
-
-       ATTRIB(XonoticPicker, rows, float, 3)
-       ATTRIB(XonoticPicker, columns, float, 2)
-
-       METHOD(XonoticPicker, moveFocus, void(entity, vector, vector))
-       METHOD(XonoticPicker, cellSelect, void(entity, vector))
-       METHOD(XonoticPicker, cellDraw, void(entity, vector, vector, float))
-       METHOD(XonoticPicker, cellIsValid, bool(entity, vector))
-       ATTRIB(XonoticPicker, realCellSize, vector, '0 0 0')
-       ATTRIB(XonoticPicker, selectedCell, vector, '-1 -1 0')
-       ATTRIB(XonoticPicker, focusedCell, vector, '-1 -1 0')
-       ATTRIB(XonoticPicker, focusedCellTime, float, 0)
-       ATTRIB(XonoticPicker, pressedCell, vector, '-1 -1 0')
-ENDCLASS(XonoticPicker)
-entity makeXonoticPicker();
-#endif
-
-#ifdef IMPLEMENTATION
+#include "picker.qh"
+
+.bool pressed;
 
 entity makeXonoticPicker()
 {
        entity me;
-       me = spawnXonoticPicker();
+       me = NEW(XonoticPicker);
        me.configureXonoticPicker(me);
        return me;
 }
@@ -57,7 +29,7 @@ float XonoticPicker_mouseMove(entity me, vector coords)
        }
 
        if(me.focusedCell != prevFocusedCell)
-               me.focusedCellTime = time;
+               me.focusedCellAlpha = SKINALPHA_LISTBOX_FOCUSED;
 
        return 1;
 }
@@ -67,17 +39,17 @@ float XonoticPicker_mouseDrag(entity me, vector coords)
        return me.mouseMove(me, coords);
 }
 
-float XonoticPicker_mousePress(entity me, vector coords)
+METHOD(XonoticPicker, mousePress, bool(XonoticPicker this, vector pos))
 {
-       me.mouseMove(me, coords);
+       this.mouseMove(this, pos);
 
-       if(me.focusedCell.x >= 0)
+       if(this.focusedCell.x >= 0)
        {
-               me.pressed = 1;
-               me.pressedCell = me.focusedCell;
+               this.pressed = 1;
+               this.pressedCell = this.focusedCell;
        }
 
-       return 1;
+       return true;
 }
 
 float XonoticPicker_mouseRelease(entity me, vector coords)
@@ -98,10 +70,18 @@ float XonoticPicker_keyDown(entity me, float key, float ascii, float shift)
 {
        switch(key)
        {
+               case K_END:
+               case K_KP_END:
+                       // lower left cell then left arrow to select the last valid cell
+                       me.focusedCell = eY * (me.rows - 1);
                case K_LEFTARROW:
                case K_KP_LEFTARROW:
                        me.moveFocus(me, me.focusedCell, '-1 0 0');
                        return 1;
+               case K_HOME:
+               case K_KP_HOME:
+                       // upper right cell then right arrow to select the first valid cell
+                       me.focusedCell = eX * (me.columns - 1);
                case K_RIGHTARROW:
                case K_KP_RIGHTARROW:
                        me.moveFocus(me, me.focusedCell, '1 0 0');
@@ -114,15 +94,6 @@ float XonoticPicker_keyDown(entity me, float key, float ascii, float shift)
                case K_KP_DOWNARROW:
                        me.moveFocus(me, me.focusedCell, '0 1 0');
                        return 1;
-               case K_HOME:
-               case K_KP_HOME:
-                       me.focusedCell = '0 0 0';
-                       return 1;
-               case K_END:
-               case K_KP_END:
-                       me.focusedCell_x = me.columns - 1;
-                       me.focusedCell_y = me.rows - 1;
-                       return 1;
                case K_ENTER:
                case K_KP_ENTER:
                case K_INS:
@@ -141,6 +112,8 @@ void XonoticPicker_moveFocus(entity me, vector initialCell, vector step)
        if(me.focusedCell != initialCell) // Recursion break
                if(!me.cellIsValid(me, me.focusedCell))
                        me.moveFocus(me, initialCell, step);
+
+       me.focusedCellAlpha = SKINALPHA_LISTBOX_FOCUSED;
 }
 
 void XonoticPicker_cellSelect(entity me, vector cell)
@@ -153,7 +126,7 @@ bool XonoticPicker_cellIsValid(entity me, vector cell)
        return true;
 }
 
-void XonoticPicker_cellDraw(entity me, vector cell, vector cellPos, float highlightTime)
+void XonoticPicker_cellDraw(entity me, vector cell, vector cellPos)
 {
 }
 
@@ -186,10 +159,13 @@ void XonoticPicker_draw(entity me)
                        else if(cell == me.focusedCell && me.focused)
                        {
                                if(!me.pressed || me.focusedCell == me.pressedCell)
-                                       draw_Fill(cellPos, me.realCellSize, SKINCOLOR_LISTBOX_FOCUSED, getHighlightAlpha(SKINALPHA_LISTBOX_FOCUSED, SKINFADEALPHA_LISTBOX_FOCUSED, me.focusedCellTime));
+                               {
+                                       me.focusedCellAlpha = getFadedAlpha(me.focusedCellAlpha, SKINALPHA_LISTBOX_FOCUSED, SKINFADEALPHA_LISTBOX_FOCUSED);
+                                       draw_Fill(cellPos, me.realCellSize, SKINCOLOR_LISTBOX_FOCUSED, me.focusedCellAlpha);
+                               }
                        }
 
-                       me.cellDraw(me, cell, cellPos, (me.focusedCell == cell) ? me.focusedCellTime : 0);
+                       me.cellDraw(me, cell, cellPos);
                }
        }
 
@@ -197,4 +173,3 @@ void XonoticPicker_draw(entity me)
 
        SUPER(XonoticPicker).draw(me);
 }
-#endif