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{
16 entity me;
18 me.configureXonoticListBox(me);
19 return me;
20}
21
23{
24 // read in cvar?
25 string s, t;
26 s = W_NumberWeaponOrder(cvar_string("cl_weaponpriority"));
27 t = W_FixWeaponOrder(s, 1);
28 if(t != s)
29 cvar_set("cl_weaponpriority", W_NameWeaponOrder(t));
30 me.nItems = tokenize_console(t);
31 SUPER(XonoticWeaponsList).draw(me);
32}
34{
35 if(me.selectedItem > 0)
36 {
37 cvar_set("cl_weaponpriority", swapInPriorityList(cvar_string("cl_weaponpriority"), me.selectedItem - 1, me.selectedItem));
38 me.setSelected(me, me.selectedItem - 1);
39 }
40}
42{
43 if(me.selectedItem < me.nItems - 1)
44 {
45 cvar_set("cl_weaponpriority", swapInPriorityList(cvar_string("cl_weaponpriority"), me.selectedItem, me.selectedItem + 1));
46 me.setSelected(me, me.selectedItem + 1);
47 }
48}
49void XonoticWeaponsList_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
50{
51 SUPER(XonoticWeaponsList).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
52
53 me.itemAbsSize.y = absSize.y * me.itemHeight;
54 me.itemAbsSize.x = absSize.x * (1 - me.controlWidth);
55 me.realFontSize.y = me.fontSize / me.itemAbsSize.y;
56 me.realFontSize.x = me.fontSize / me.itemAbsSize.x;
57 me.realUpperMargin = 0.5 * (1 - me.realFontSize.y);
58
60 e.display(e, XonoticWeaponsList_cb);
62 float aspect_ratio = sz.y ? sz.x / sz.y : 1;
63 me.columnIconOrigin = 0.25 * me.realFontSize.x;
64 me.columnIconSize = me.itemAbsSize.y / me.itemAbsSize.x * aspect_ratio;
65
66 me.columnNameOrigin = me.columnIconOrigin + me.columnIconSize + (0.25 * me.realFontSize.x);
67 me.columnNameSize = 1 - me.columnIconSize - (1.5 * me.realFontSize.x); // unused
68}
70{
71 int i = me.selectedItem;
72 float f = SUPER(XonoticWeaponsList).mouseDrag(me, pos);
73
74 if(me.pressed != 1) // don't change priority if the person is just scrolling
75 {
76 if(me.selectedItem != i)
77 {
78 if(me.applyButton)
79 me.applyButton.disabled = false;
80 cvar_set("cl_weaponpriority", swapInPriorityList(cvar_string("cl_weaponpriority"), me.selectedItem, i));
81 }
82 }
83
84 return f;
85}
87{
88 float n, i;
89 string s;
90 entity e;
91 n = tokenize_console(W_NumberWeaponOrder(cvar_string("cl_weaponpriority")));
92 s = "";
93 for(i = 0; i < n; ++i)
94 {
95 e = REGISTRY_GET(Weapons, stof(argv(i)));
96 s = strcat(s, e.m_name, ", ");
97 }
98 return substring(s, 0, strlen(s) - 2);
99}
100void XonoticWeaponsList_drawListBoxItem(entity me, int i, vector absSize, bool isSelected, bool isFocused)
101{
102 entity e;
103 if(isSelected)
104 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED);
105 else if(isFocused)
106 {
107 me.focusedItemAlpha = getFadedAlpha(me.focusedItemAlpha, SKINALPHA_LISTBOX_FOCUSED, SKINFADEALPHA_LISTBOX_FOCUSED);
108 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_FOCUSED, me.focusedItemAlpha);
109 }
110 e = REGISTRY_GET(Weapons, stof(argv(i)));
111 e.display(e, XonoticWeaponsList_cb);
112 string msg = XonoticWeaponsList_cb_name;
113 string icon = XonoticWeaponsList_cb_icon;
114
115 draw_Picture(me.columnIconOrigin * eX, icon, me.columnIconSize * eX + eY, '1 1 1', SKINALPHA_LISTBOX_SELECTED);
116
117 bool drawStar = e.spawnflags & WEP_FLAG_MUTATORBLOCKED;
118 vector save_fontscale = draw_fontscale;
119 float f = draw_CondensedFontFactor(strcat(msg, drawStar ? "*" : ""), false, me.realFontSize, 1);
120 draw_fontscale.x *= f;
121 vector fs = me.realFontSize;
122 fs.x *= f;
123 draw_Text(me.realUpperMargin * eY + me.columnNameOrigin * eX, msg, fs, SKINCOLOR_TEXT, SKINALPHA_TEXT, 0);
124 if(drawStar)
125 draw_Text(me.realUpperMargin * eY + (me.columnNameOrigin + draw_TextWidth(msg, 0, fs)) * eX, "*", fs, SKINCOLOR_HEADER, SKINALPHA_HEADER, 0);
126 draw_fontscale = save_fontscale;
127}
128
129float XonoticWeaponsList_keyDown(entity me, float key, float ascii, float shift)
130{
131 if (((shift & S_CTRL) && (key == K_UPARROW || key == K_KP_UPARROW))
132 || ascii == '+')
133 {
135 return 1;
136 }
137 else if (((shift & S_CTRL) && (key == K_DOWNARROW || key == K_KP_DOWNARROW))
138 || ascii == '-')
139 {
141 return 1;
142 }
143 else if(SUPER(XonoticWeaponsList).keyDown(me, key, ascii, shift))
144 return 1;
145 return 0;
146}
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
bool disabled
string swapInPriorityList(string order, float i, float j)
Definition util.qc:655
#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:316
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:120
string W_NameWeaponOrder(string order)
Definition all.qc:110
string W_FixWeaponOrder(string order, float complete)
Definition all.qc:95
const int WEP_FIRST
Definition all.qh:326
const int WEP_FLAG_MUTATORBLOCKED
Definition weapon.qh:219
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)