Xonotic
weaponslist.qc
Go to the documentation of this file.
1 #include "weaponslist.qh"
2 
3 #include <common/weapons/_all.qh>
4 
5 .bool disabled;
6 
8 {
9  entity me;
10  me = NEW(XonoticWeaponsList);
11  me.configureXonoticWeaponsList(me);
12  return me;
13 }
15 {
16  me.configureXonoticListBox(me);
17 }
19 {
20  // read in cvar?
21  string s, t;
22  s = W_NumberWeaponOrder(cvar_string("cl_weaponpriority"));
23  t = W_FixWeaponOrder(s, 1);
24  if(t != s)
25  cvar_set("cl_weaponpriority", W_NameWeaponOrder(t));
26  me.nItems = tokenize_console(t);
27  SUPER(XonoticWeaponsList).draw(me);
28 }
30 {
31  if(me.selectedItem > 0)
32  {
33  cvar_set("cl_weaponpriority", swapInPriorityList(cvar_string("cl_weaponpriority"), me.selectedItem - 1, me.selectedItem));
34  me.setSelected(me, me.selectedItem - 1);
35  }
36 }
38 {
39  if(me.selectedItem < me.nItems - 1)
40  {
41  cvar_set("cl_weaponpriority", swapInPriorityList(cvar_string("cl_weaponpriority"), me.selectedItem, me.selectedItem + 1));
42  me.setSelected(me, me.selectedItem + 1);
43  }
44 }
45 void XonoticWeaponsList_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
46 {
47  SUPER(XonoticWeaponsList).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
48 
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);
52 }
54 {
55  int i = me.selectedItem;
56  float f = SUPER(XonoticWeaponsList).mouseDrag(me, pos);
57 
58  if(me.pressed != 1) // don't change priority if the person is just scrolling
59  {
60  if(me.selectedItem != i)
61  {
62  if(me.applyButton)
63  me.applyButton.disabled = false;
64  cvar_set("cl_weaponpriority", swapInPriorityList(cvar_string("cl_weaponpriority"), me.selectedItem, i));
65  }
66  }
67 
68  return f;
69 }
71 {
72  float n, i;
73  string s;
74  entity e;
75  n = tokenize_console(W_NumberWeaponOrder(cvar_string("cl_weaponpriority")));
76  s = "";
77  for(i = 0; i < n; ++i)
78  {
79  e = REGISTRY_GET(Weapons, stof(argv(i)));
80  s = strcat(s, e.m_name, ", ");
81  }
82  return substring(s, 0, strlen(s) - 2);
83 }
84 void XonoticWeaponsList_drawListBoxItem(entity me, int i, vector absSize, bool isSelected, bool isFocused)
85 {
86  entity e;
87  if(isSelected)
88  draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED);
89  else if(isFocused)
90  {
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);
93  }
94  e = REGISTRY_GET(Weapons, stof(argv(i)));
95  string msg = e.m_name;
96  if(e.spawnflags & WEP_FLAG_MUTATORBLOCKED)
97  msg = strcat(msg, "*");
98 
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;
103  fs.x *= f;
104  draw_Text(me.realUpperMargin * eY, msg, fs, SKINCOLOR_TEXT, SKINALPHA_TEXT, 0);
105  draw_fontscale = save_fontscale;
106 }
107 
108 float XonoticWeaponsList_keyDown(entity me, float scan, float ascii, float shift)
109 {
110  if(ascii == 43) // +
111  {
113  return 1;
114  }
115  else if(ascii == 45) // -
116  {
118  return 1;
119  }
120  else if(SUPER(XonoticWeaponsList).keyDown(me, scan, ascii, shift))
121  return 1;
122  return 0;
123 }
void XonoticWeaponsList_configureXonoticWeaponsList(entity me)
Definition: weaponslist.qc:14
string W_FixWeaponOrder(string order, float complete)
Definition: all.qc:95
const vector eY
Definition: vector.qh:45
#define NEW(cname,...)
Definition: oo.qh:105
void XonoticWeaponsList_draw(entity me)
Definition: weaponslist.qc:18
bool disabled
Definition: weaponslist.qc:5
entity() spawn
#define REGISTRY_GET(id, i)
Definition: registry.qh:43
float XonoticWeaponsList_keyDown(entity me, float scan, float ascii, float shift)
Definition: weaponslist.qc:108
void WeaponsList_MoveDown_Click(entity box, entity me)
Definition: weaponslist.qc:37
void XonoticWeaponsList_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
Definition: weaponslist.qc:45
#define SUPER(cname)
Definition: oo.qh:219
string W_NumberWeaponOrder(string order)
Definition: all.qc:136
spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 f1 s1 strcat(_("Level %s: "), "^BG%s\3\, _("^BGPress ^F2%s^BG to enter the game"))
entity makeXonoticWeaponsList()
Definition: weaponslist.qc:7
#define NULL
Definition: post.qh:17
string swapInPriorityList(string order, float i, float j)
Definition: util.qc:540
float XonoticWeaponsList_mouseDrag(entity me, vector pos)
Definition: weaponslist.qc:53
vector(float skel, float bonenum) _skel_get_boneabs_hidden
#define tokenize_console
Definition: dpextensions.qh:24
string W_NameWeaponOrder(string order)
Definition: all.qc:125
string XonoticWeaponsList_toString(entity me)
Definition: weaponslist.qc:70
void XonoticWeaponsList_drawListBoxItem(entity me, int i, vector absSize, bool isSelected, bool isFocused)
Definition: weaponslist.qc:84
const int WEP_FLAG_MUTATORBLOCKED
Definition: weapon.qh:203
void WeaponsList_MoveUp_Click(entity box, entity me)
Definition: weaponslist.qc:29