1 #include "weaponslist.qh"
3 #include <common/weapons/_all.qh>
7 entity makeXonoticWeaponsList()
10 me = NEW(XonoticWeaponsList);
11 me.configureXonoticWeaponsList(me);
14 void XonoticWeaponsList_configureXonoticWeaponsList(entity me)
16 me.configureXonoticListBox(me);
18 void XonoticWeaponsList_draw(entity me)
22 s = W_NumberWeaponOrder(cvar_string("cl_weaponpriority"));
23 t = W_FixWeaponOrder(s, 1);
25 cvar_set("cl_weaponpriority", W_NameWeaponOrder(t));
26 me.nItems = tokenize_console(t);
27 SUPER(XonoticWeaponsList).draw(me);
29 void WeaponsList_MoveUp_Click(entity box, entity me)
31 if(me.selectedItem > 0)
33 cvar_set("cl_weaponpriority", swapInPriorityList(cvar_string("cl_weaponpriority"), me.selectedItem - 1, me.selectedItem));
34 me.setSelected(me, me.selectedItem - 1);
37 void WeaponsList_MoveDown_Click(entity box, entity me)
39 if(me.selectedItem < me.nItems - 1)
41 cvar_set("cl_weaponpriority", swapInPriorityList(cvar_string("cl_weaponpriority"), me.selectedItem, me.selectedItem + 1));
42 me.setSelected(me, me.selectedItem + 1);
45 void XonoticWeaponsList_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
47 SUPER(XonoticWeaponsList).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
49 me.realFontSize_y = me.fontSize / (absSize.y * me.itemHeight);
50 me.realFontSize_x = me.fontSize / (absSize.x * (1 - me.controlWidth));
51 me.realUpperMargin = 0.5 * (1 - me.realFontSize.y);
53 float XonoticWeaponsList_mouseDrag(entity me, vector pos)
55 int i = me.selectedItem;
56 float f = SUPER(XonoticWeaponsList).mouseDrag(me, pos);
58 if(me.pressed != 1) // don't change priority if the person is just scrolling
60 if(me.selectedItem != i)
63 me.applyButton.disabled = false;
64 cvar_set("cl_weaponpriority", swapInPriorityList(cvar_string("cl_weaponpriority"), me.selectedItem, i));
70 string XonoticWeaponsList_toString(entity me)
75 n = tokenize_console(W_NumberWeaponOrder(cvar_string("cl_weaponpriority")));
77 for(i = 0; i < n; ++i)
79 e = Weapons_from(stof(argv(i)));
80 s = strcat(s, e.m_name, ", ");
82 return substring(s, 0, strlen(s) - 2);
84 void XonoticWeaponsList_drawListBoxItem(entity me, int i, vector absSize, bool isSelected, bool isFocused)
88 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED);
91 me.focusedItemAlpha = getFadedAlpha(me.focusedItemAlpha, SKINALPHA_LISTBOX_FOCUSED, SKINFADEALPHA_LISTBOX_FOCUSED);
92 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_FOCUSED, me.focusedItemAlpha);
94 e = Weapons_from(stof(argv(i)));
95 string msg = e.m_name;
96 if(e.spawnflags & WEP_FLAG_MUTATORBLOCKED)
97 msg = strcat(msg, "*");
99 vector save_fontscale = draw_fontscale;
100 float f = draw_CondensedFontFactor(msg, false, me.realFontSize, 1);
101 draw_fontscale.x *= f;
102 vector fs = me.realFontSize;
104 draw_Text(me.realUpperMargin * eY, msg, fs, SKINCOLOR_TEXT, SKINALPHA_TEXT, 0);
105 draw_fontscale = save_fontscale;
108 float XonoticWeaponsList_keyDown(entity me, float scan, float ascii, float shift)
112 WeaponsList_MoveUp_Click(NULL, me);
115 else if(ascii == 45) // -
117 WeaponsList_MoveDown_Click(NULL, me);
120 else if(SUPER(XonoticWeaponsList).keyDown(me, scan, ascii, shift))