Xonotic
textslider.qc
Go to the documentation of this file.
1 #include "textslider.qh"
2 
3 entity makeXonoticTextSlider_T(string theCvar, string theTooltip)
4 {
5  entity me;
7  me.configureXonoticTextSlider(me, theCvar, theTooltip);
8  return me;
9 }
11 {
12  return makeXonoticTextSlider_T(theCvar, string_null);
13 }
14 void XonoticTextSlider_configureXonoticTextSlider(entity me, string theCvar, string theTooltip)
15 {
16  me.configureSliderVisuals(me, me.fontSize, me.align, me.valueSpace, me.image);
17  me.controlledCvar = (theCvar) ? theCvar : string_null;
18  // me.loadCvars(me); // don't load it yet
19  setZonedTooltip(me, theTooltip, theCvar);
20 }
22 {
23  if(val != me.value)
24  {
25  SUPER(XonoticTextSlider).setValue( me, val );
26  me.saveCvars(me);
27  }
28 }
30 {
31  if(val != me.value)
32  {
33  SUPER(XonoticTextSlider).setValue_noAnim(me, val);
34  me.saveCvars(me);
35  }
36 }
38 {
39  if (!me.controlledCvar)
40  return;
41 
42  float n = tokenize_console(me.controlledCvar);
43  string s = cvar_string(argv(0));
44  float i;
45  for(i = 1; i < n; ++i)
46  s = strcat(s, " ", cvar_string(argv(i)));
47  me.setValueFromIdentifier_noAnim(me, s);
48  if(me.value < 0 && n > 1)
49  {
50  // if it failed: check if all cvars have the same value
51  // if yes, try its value as 1-word identifier
52  for(i = 1; i < n; ++i)
53  if(cvar_string(argv(i)) != cvar_string(argv(i-1)))
54  break;
55  if(i >= n)
56  me.setValueFromIdentifier_noAnim(me, cvar_string(argv(0)));
57  }
58 }
60 {
61  if (!me.controlledCvar)
62  return;
63 
64  if(me.value >= 0 && me.value < me.nValues)
65  {
66  float n = tokenize_console(me.controlledCvar);
67  if(n == 1)
68  {
69  // this is a special case to allow spaces in the identifiers
70  cvar_set(argv(0), me.getIdentifier(me));
71  CheckSendCvars(me, argv(0));
72  }
73  else
74  {
75  float i;
76  float m = tokenize_console(strcat(me.controlledCvar, " ", me.getIdentifier(me)));
77  if(m == n + 1)
78  {
79  for(i = 0; i < n; ++i)
80  {
81  cvar_set(argv(i), argv(n));
82  CheckSendCvars(me, argv(i));
83  }
84  }
85  else if(m == n * 2)
86  {
87  for(i = 0; i < n; ++i)
88  {
89  cvar_set(argv(i), argv(i + n));
90  CheckSendCvars(me, argv(i));
91  }
92  }
93  else
94  error("XonoticTextSlider: invalid identifier ", me.getIdentifier(me), " does not match cvar list ", me.controlledCvar);
95  }
96  }
97 }
99 {
100  me.configureTextSliderValues(me, string_null);
101  me.loadCvars(me);
102 }
string string_null
Definition: nil.qh:9
#define NEW(cname,...)
Definition: oo.qh:105
void XonoticTextSlider_setValue(entity me, float val)
Definition: textslider.qc:21
entity() spawn
entity makeXonoticTextSlider_T(string theCvar, string theTooltip)
Definition: textslider.qc:3
void XonoticTextSlider_configureXonoticTextSlider(entity me, string theCvar, string theTooltip)
Definition: textslider.qc:14
#define SUPER(cname)
Definition: oo.qh:219
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"))
#define tokenize_console
Definition: dpextensions.qh:24
void XonoticTextSlider_saveCvars(entity me)
Definition: textslider.qc:59
void XonoticTextSlider_setValue_noAnim(entity me, float val)
Definition: textslider.qc:29
entity makeXonoticTextSlider(string theCvar)
Definition: textslider.qc:10
void XonoticTextSlider_loadCvars(entity me)
Definition: textslider.qc:37
void XonoticTextSlider_configureXonoticTextSliderValues(entity me)
Definition: textslider.qc:98