Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
weaponslist.qc
Go to the documentation of this file.
1#include "weaponslist.qh"
2
4
5.bool disabled;
6
8void XonoticWeaponsList_cb(string _name, string _icon)
9{
12}
13
15{
17 me.configureXonoticListBox(me);
18 return me;
19}
20
22{
23 // read in cvar?
24 string s, t;
25 s = W_NumberWeaponOrder(cvar_string("cl_weaponpriority"));
26 t = W_FixWeaponOrder(s, 1);
27 if(t != s)
28 cvar_set("cl_weaponpriority", W_NameWeaponOrder(t));
29 me.nItems = tokenize_console(t);
30 SUPER(XonoticWeaponsList).draw(me);
31}
33{
34 if(me.selectedItem > 0)
35 {
36 cvar_set("cl_weaponpriority", swapInPriorityList(cvar_string("cl_weaponpriority"), me.selectedItem - 1, me.selectedItem));
37 me.setSelected(me, me.selectedItem - 1);
38 }
39}
41{
42 if(me.selectedItem < me.nItems - 1)
43 {
44 cvar_set("cl_weaponpriority", swapInPriorityList(cvar_string("cl_weaponpriority"), me.selectedItem, me.selectedItem + 1));
45 me.setSelected(me, me.selectedItem + 1);
46 }
47}
48void XonoticWeaponsList_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
49{
50 SUPER(XonoticWeaponsList).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
51
52 me.itemAbsSize.y = absSize.y * me.itemHeight;
53 me.itemAbsSize.x = absSize.x * (1 - me.controlWidth);
54 me.realFontSize.y = me.fontSize / me.itemAbsSize.y;
55 me.realFontSize.x = me.fontSize / me.itemAbsSize.x;
56 me.realUpperMargin = 0.5 * (1 - me.realFontSize.y);
57
59 e.display(e, XonoticWeaponsList_cb);
61 float aspect_ratio = sz.y ? sz.x / sz.y : 1;
62 me.columnIconOrigin = 0.25 * me.realFontSize.x;
63 me.columnIconSize = me.itemAbsSize.y / me.itemAbsSize.x * aspect_ratio;
64
65 me.columnNameOrigin = me.columnIconOrigin + me.columnIconSize + (0.25 * me.realFontSize.x);
66 me.columnNameSize = 1 - me.columnIconSize - (1.5 * me.realFontSize.x); // unused
67}
69{
70 int i = me.selectedItem;
71 float f = SUPER(XonoticWeaponsList).mouseDrag(me, pos);
72
73 if(me.pressed != 1) // don't change priority if the person is just scrolling
74 {
75 if(me.selectedItem != i)
76 {
77 if(me.applyButton)
78 me.applyButton.disabled = false;
79 cvar_set("cl_weaponpriority", swapInPriorityList(cvar_string("cl_weaponpriority"), me.selectedItem, i));
80 }
81 }
82
83 return f;
84}
86{
87 float n, i;
88 string s;
89 entity e;
90 n = tokenize_console(W_NumberWeaponOrder(cvar_string("cl_weaponpriority")));
91 s = "";
92 for(i = 0; i < n; ++i)
93 {
94 e = REGISTRY_GET(Weapons, stof(argv(i)));
95 s = strcat(s, e.m_name, ", ");
96 }
97 return substring(s, 0, strlen(s) - 2);
98}
99void XonoticWeaponsList_drawListBoxItem(entity me, int i, vector absSize, bool isSelected, bool isFocused)
100{
101 entity e;
102 if(isSelected)
103 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED);
104 else if(isFocused)
105 {
106 me.focusedItemAlpha = getFadedAlpha(me.focusedItemAlpha, SKINALPHA_LISTBOX_FOCUSED, SKINFADEALPHA_LISTBOX_FOCUSED);
107 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_FOCUSED, me.focusedItemAlpha);
108 }
109 e = REGISTRY_GET(Weapons, stof(argv(i)));
110 e.display(e, XonoticWeaponsList_cb);
111 string msg = XonoticWeaponsList_cb_name;
112 string icon = XonoticWeaponsList_cb_icon;
113
114 draw_Picture(me.columnIconOrigin * eX, icon, me.columnIconSize * eX + eY, '1 1 1', SKINALPHA_LISTBOX_SELECTED);
115
116 bool drawStar = e.spawnflags & WEP_FLAG_MUTATORBLOCKED;
117 vector save_fontscale = draw_fontscale;
118 float f = draw_CondensedFontFactor(strcat(msg, drawStar ? "*" : ""), false, me.realFontSize, 1);
119 draw_fontscale.x *= f;
120 vector fs = me.realFontSize;
121 fs.x *= f;
122 draw_Text(me.realUpperMargin * eY + me.columnNameOrigin * eX, msg, fs, SKINCOLOR_TEXT, SKINALPHA_TEXT, 0);
123 if(drawStar)
124 draw_Text(me.realUpperMargin * eY + (me.columnNameOrigin + draw_TextWidth(msg, 0, fs)) * eX, "*", fs, SKINCOLOR_HEADER, SKINALPHA_HEADER, 0);
125 draw_fontscale = save_fontscale;
126}
127
128float XonoticWeaponsList_keyDown(entity me, float key, float ascii, float shift)
129{
130 if (((shift & S_CTRL) && (key == K_UPARROW || key == K_KP_UPARROW))
131 || ascii == '+')
132 {
134 return 1;
135 }
136 else if (((shift & S_CTRL) && (key == K_DOWNARROW || key == K_KP_DOWNARROW))
137 || ascii == '-')
138 {
140 return 1;
141 }
142 else if(SUPER(XonoticWeaponsList).keyDown(me, key, ascii, shift))
143 return 1;
144 return 0;
145}
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
bool disabled
string swapInPriorityList(string order, float i, float j)
Definition util.qc:651
#define strlen
#define tokenize_console
Weapons
Definition guide.qh:113
const int S_CTRL
Definition hud.qh:130
float K_UPARROW
Definition keycodes.qc:15
float K_DOWNARROW
Definition keycodes.qc:16
float K_KP_UPARROW
Definition keycodes.qc:64
float K_KP_DOWNARROW
Definition keycodes.qc:53
void draw_Picture(vector theOrigin, string pic, vector theSize, vector theColor, float theAlpha)
Definition draw.qc:72
float draw_CondensedFontFactor(string theText, float ICanHasKallerz, vector SizeThxBye, float maxWidth)
Definition draw.qc:317
void draw_Text(vector theOrigin, string theText, vector theSize, vector theColor, float theAlpha, float ICanHasKallerz)
Definition draw.qc:282
vector draw_PictureSize(string pic)
Definition draw.qc:80
float draw_TextWidth(string theText, float ICanHasKallerz, vector SizeThxBye)
Definition draw.qc:304
void draw_Fill(vector theOrigin, vector theSize, vector theColor, float theAlpha)
Definition draw.qc:97
#define draw_fontscale
Definition draw.qh:5
float getFadedAlpha(float currentAlpha, float startAlpha, float targetAlpha)
Definition util.qc:816
void cvar_set(string name, string value)
float stof(string val,...)
string substring(string s, float start, float length)
const string cvar_string(string name)
string argv(float n)
strcat(_("^F4Countdown stopped!"), "\n^BG", _("Teams are too unbalanced."))
#define NEW(cname,...)
Definition oo.qh:117
#define SUPER(cname)
Definition oo.qh:231
#define NULL
Definition post.qh:14
#define REGISTRY_GET(id, i)
Definition registry.qh:43
vector
Definition self.qh:92
const vector eY
Definition vector.qh:45
const vector eX
Definition vector.qh:44
string W_NumberWeaponOrder(string order)
Definition all.qc:126
string W_NameWeaponOrder(string order)
Definition all.qc:115
string W_FixWeaponOrder(string order, float complete)
Definition all.qc:99
const int WEP_FIRST
Definition all.qh:342
const int WEP_FLAG_MUTATORBLOCKED
Definition weapon.qh:261
entity makeXonoticWeaponsList()
void WeaponsList_MoveDown_Click(entity box, entity me)
void WeaponsList_MoveUp_Click(entity box, entity me)
string XonoticWeaponsList_cb_icon
Definition weaponslist.qc:7
void XonoticWeaponsList_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
void XonoticWeaponsList_cb(string _name, string _icon)
Definition weaponslist.qc:8
float XonoticWeaponsList_keyDown(entity me, float key, float ascii, float shift)
float XonoticWeaponsList_mouseDrag(entity me, vector pos)
void XonoticWeaponsList_drawListBoxItem(entity me, int i, vector absSize, bool isSelected, bool isFocused)
string XonoticWeaponsList_cb_name
Definition weaponslist.qc:7
void XonoticWeaponsList_draw(entity me)
string XonoticWeaponsList_toString(entity me)