Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
mixedslider.qc
Go to the documentation of this file.
1#include "mixedslider.qh"
2
3 string MixedSlider_valueToText(entity me, int val)
4 {
5 if (val >= me.nValues || val < 0)
6 return _("Custom");
7 return me.(valueStrings[val]);
8 }
10 {
11 if (val >= me.nValues || val < 0)
12 return -1; // this shouldn't occur
13 return me.(valueNumberIdentifiers[val]);
14 }
15 void MixedSlider_setValueFromNumberIdentifier(entity me, float id, bool allowAnim)
16 {
17 for (int i = 0; i < me.nValues; ++i)
18 if (me.valueToNumberIdentifier(me, i) == id)
19 {
20 SUPER(MixedSlider).setValue(me, i, allowAnim);
21 return;
22 }
23 SUPER(MixedSlider).setValue(me, -1, allowAnim);
24 }
26 {
27 return me.valueToNumberIdentifier(me, me.value);
28 }
30 {
31 return formatStringSpecial(me.formatString, id, me.valueDigits);
32 }
33 void MixedSlider_adjustDigitsForStep(entity me, float valueStep)
34 {
35 float newDigits = 3;
36 if (fabs(floor(valueStep * 100 + 0.5) - (valueStep * 100)) < 0.01) // about a whole number of 100ths
37 newDigits = 2;
38 if (fabs(floor(valueStep * 10 + 0.5) - (valueStep * 10)) < 0.01) // about a whole number of 10ths
39 newDigits = 1;
40 if (fabs(floor(valueStep * 1 + 0.5) - (valueStep * 1)) < 0.01) // about a whole number
41 newDigits = 0;
42 if (newDigits > me.valueDigits)
43 me.valueDigits = newDigits;
44 }
46 {
47 me.nValues = 0;
48 }
49 void MixedSlider_addRange(entity me, float theValueMin, float theValueMax, float theValueStep)
50 {
51 me.adjustDigitsForStep(me, theValueStep);
52 for (float id = theValueMin; id <= theValueMax + theValueStep / 2; id += theValueStep)
53 { // plus half to prevent almost all floating point errors
54 me.(valueStrings[me.nValues]) = strzone(me.rangedIdentifierToText(me, id));
55 me.(valueNumberIdentifiers[me.nValues]) = stof(ftos_decimals(id, me.valueDigits));
56 ++me.nValues;
57 }
58 }
59 void MixedSlider_addText(entity me, string theString, float theIdentifier)
60 {
61 me.(valueStrings[me.nValues]) = theString;
62 me.(valueNumberIdentifiers[me.nValues]) = theIdentifier;
63 ++me.nValues;
64 }
65 void MixedSlider_insertRange(entity me, int pos, float theValueMin, float theValueMax, float theValueStep)
66 {
67 me.adjustDigitsForStep(me, theValueStep);
68 // calculate insertedCount first to prevent needing to duplicate valueStrings and valueNumberIdentifiers
69 int insertedCount = ceil((theValueMax - theValueMin) / theValueStep + 0.5);
70 me.nValues += insertedCount;
71
72 for (int i = me.nValues - 1; i > pos; --i)
73 {
74 me.(valueStrings[i]) = me.(valueStrings[i - insertedCount]);
75 me.(valueNumberIdentifiers[i]) = me.(valueNumberIdentifiers[i - insertedCount]);
76 }
77 for (float id = theValueMin; id <= theValueMax + theValueStep / 2; id += theValueStep)
78 {
79 string rounded_id_str = me.rangedIdentifierToText(me, id);
80 me.(valueStrings[pos]) = strzone(rounded_id_str);
81 me.(valueNumberIdentifiers[pos]) = stof(rounded_id_str);
82 ++pos;
83 }
84 }
85 void MixedSlider_insertText(entity me, int pos, string theString, float theIdentifier)
86 {
87 ++me.nValues;
88 for (int i = me.nValues - 1; i > pos; --i)
89 {
90 me.(valueStrings[i]) = me.(valueStrings[i - 1]);
91 me.(valueNumberIdentifiers[i]) = me.(valueNumberIdentifiers[i - 1]);
92 }
93 me.(valueStrings[pos]) = theString;
94 me.(valueNumberIdentifiers[pos]) = theIdentifier;
95 }
97 {
98 me.configureSliderValues(me, 0, 0, me.nValues - 1, 1, 1, 1);
99 me.setValueFromNumberIdentifier(me, theDefault, false);
100 }
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
void MixedSlider_insertText(entity me, int pos, string theString, float theIdentifier)
void MixedSlider_clearValues(entity me)
void MixedSlider_configureMixedSliderValues(entity me, float theDefault)
void MixedSlider_adjustDigitsForStep(entity me, float valueStep)
void MixedSlider_setValueFromNumberIdentifier(entity me, float id, bool allowAnim)
string MixedSlider_rangedIdentifierToText(entity me, float id)
float MixedSlider_valueToNumberIdentifier(entity me, int val)
Definition mixedslider.qc:9
void MixedSlider_addText(entity me, string theString, float theIdentifier)
void MixedSlider_addRange(entity me, float theValueMin, float theValueMax, float theValueStep)
void MixedSlider_insertRange(entity me, int pos, float theValueMin, float theValueMax, float theValueStep)
string MixedSlider_valueToText(entity me, int val)
Definition mixedslider.qc:3
float MixedSlider_getNumberIdentifier(entity me)
string formatStringSpecial(string formatStr, float value, int decs)
Definition slider.qc:6
float ceil(float f)
float stof(string val,...)
float fabs(float f)
float floor(float f)
string strzone(string s)
#define SUPER(cname)
Definition oo.qh:231
ERASEABLE string ftos_decimals(float number, int decimals)
converts a number to a string with the indicated number of decimals
Definition string.qh:469