4 CLASS(XonoticWeaponsList, XonoticListBox)
5 METHOD(XonoticWeaponsList, configureXonoticWeaponsList, void(entity));
6 METHOD(XonoticWeaponsList, toString, string(entity));
7 ATTRIB(XonoticWeaponsList, rowsPerItem, float, 1)
8 METHOD(XonoticWeaponsList, draw, void(entity));
9 METHOD(XonoticWeaponsList, drawListBoxItem, void(entity, int, vector, bool, bool));
10 METHOD(XonoticWeaponsList, resizeNotify, void(entity, vector, vector, vector, vector));
11 METHOD(XonoticWeaponsList, keyDown, float(entity, float, float, float));
12 ATTRIB(XonoticWeaponsList, realFontSize, vector, '0 0 0')
13 ATTRIB(XonoticWeaponsList, realUpperMargin, float, 0)
14 METHOD(XonoticWeaponsList, mouseDrag, float(entity, vector));
15 ENDCLASS(XonoticWeaponsList)
16 entity makeXonoticWeaponsList();
17 void WeaponsList_MoveUp_Click(entity btn, entity me);
18 void WeaponsList_MoveDown_Click(entity box, entity me);
22 entity makeXonoticWeaponsList()
25 me = NEW(XonoticWeaponsList);
26 me.configureXonoticWeaponsList(me);
29 void XonoticWeaponsList_configureXonoticWeaponsList(entity me)
31 me.configureXonoticListBox(me);
33 void XonoticWeaponsList_draw(entity me)
37 s = W_NumberWeaponOrder(cvar_string("cl_weaponpriority"));
38 t = W_FixWeaponOrder(s, 1);
40 cvar_set("cl_weaponpriority", W_NameWeaponOrder(t));
41 me.nItems = tokenize_console(t);
42 SUPER(XonoticWeaponsList).draw(me);
44 void WeaponsList_MoveUp_Click(entity box, entity me)
46 if(me.selectedItem > 0)
48 cvar_set("cl_weaponpriority", swapInPriorityList(cvar_string("cl_weaponpriority"), me.selectedItem - 1, me.selectedItem));
49 me.setSelected(me, me.selectedItem - 1);
52 void WeaponsList_MoveDown_Click(entity box, entity me)
54 if(me.selectedItem < me.nItems - 1)
56 cvar_set("cl_weaponpriority", swapInPriorityList(cvar_string("cl_weaponpriority"), me.selectedItem, me.selectedItem + 1));
57 me.setSelected(me, me.selectedItem + 1);
60 void XonoticWeaponsList_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
62 SUPER(XonoticWeaponsList).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
64 me.realFontSize_y = me.fontSize / (absSize.y * me.itemHeight);
65 me.realFontSize_x = me.fontSize / (absSize.x * (1 - me.controlWidth));
66 me.realUpperMargin = 0.5 * (1 - me.realFontSize.y);
68 float XonoticWeaponsList_mouseDrag(entity me, vector pos)
70 int i = me.selectedItem;
71 float f = SUPER(XonoticWeaponsList).mouseDrag(me, pos);
73 if(me.pressed != 1) // don't change priority if the person is just scrolling
75 if(me.selectedItem != i)
76 cvar_set("cl_weaponpriority", swapInPriorityList(cvar_string("cl_weaponpriority"), me.selectedItem, i));
81 string XonoticWeaponsList_toString(entity me)
86 n = tokenize_console(W_NumberWeaponOrder(cvar_string("cl_weaponpriority")));
88 for(i = 0; i < n; ++i)
90 e = get_weaponinfo(stof(argv(i)));
91 s = strcat(s, e.message, ", ");
93 return substring(s, 0, strlen(s) - 2);
95 void XonoticWeaponsList_drawListBoxItem(entity me, int i, vector absSize, bool isSelected, bool isFocused)
99 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED);
102 me.focusedItemAlpha = getFadedAlpha(me.focusedItemAlpha, SKINALPHA_LISTBOX_FOCUSED, SKINFADEALPHA_LISTBOX_FOCUSED);
103 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_FOCUSED, me.focusedItemAlpha);
105 e = get_weaponinfo(stof(argv(i)));
106 string msg = e.message;
107 if(e.spawnflags & WEP_FLAG_MUTATORBLOCKED)
108 msg = sprintf(_("%s (mutator weapon)"), msg);
110 vector save_fontscale = draw_fontscale;
111 float f = draw_CondensedFontFactor(msg, false, me.realFontSize, 1);
112 draw_fontscale.x *= f;
113 vector fs = me.realFontSize;
115 draw_Text(me.realUpperMargin * eY, msg, fs, SKINCOLOR_TEXT, SKINALPHA_TEXT, 0);
116 draw_fontscale = save_fontscale;
119 float XonoticWeaponsList_keyDown(entity me, float scan, float ascii, float shift)
123 WeaponsList_MoveUp_Click(NULL, me);
126 else if(ascii == 45) // -
128 WeaponsList_MoveDown_Click(NULL, me);
131 else if(SUPER(XonoticWeaponsList).keyDown(me, scan, ascii, shift))