]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/menu/nexuiz/dialog_multiplayer_create_mutators.c
add a multi-cvar single-value tgo the text slider
[divverent/nexuiz.git] / data / qcsrc / menu / nexuiz / dialog_multiplayer_create_mutators.c
1 #ifdef INTERFACE
2 CLASS(NexuizMutatorsDialog) EXTENDS(NexuizDialog)
3         METHOD(NexuizMutatorsDialog, toString, string(entity))
4         METHOD(NexuizMutatorsDialog, fill, void(entity))
5         METHOD(NexuizMutatorsDialog, showNotify, void(entity))
6         METHOD(NexuizMutatorsDialog, close, void(entity))
7         ATTRIB(NexuizMutatorsDialog, title, string, "Mutators")
8         ATTRIB(NexuizMutatorsDialog, color, vector, SKINCOLOR_DIALOG_MUTATORS)
9         ATTRIB(NexuizMutatorsDialog, intendedWidth, float, 0.9)
10         ATTRIB(NexuizMutatorsDialog, rows, float, 18)
11         ATTRIB(NexuizMutatorsDialog, columns, float, 6)
12         ATTRIB(NexuizMutatorsDialog, refilterEntity, entity, NULL)
13 ENDCLASS(NexuizMutatorsDialog)
14 #endif
15
16 #ifdef IMPLEMENTATION
17 void showNotifyNexuizMutatorsDialog(entity me)
18 {
19         loadAllCvars(me);
20 }
21
22 string weaponarenastring;
23 string weaponarenastring_cvar;
24 string WeaponArenaString()
25 {
26         string s;
27         float n, i, j;
28         entity e;
29         s = cvar_string("g_weaponarena");
30         if(s == "0")
31                 return "";
32         if(s == "all")
33                 return "All Weapons Arena";
34         if(s == "most")
35                 return "Most Weapons Arena";
36         if(s == weaponarenastring_cvar)
37                 return weaponarenastring;
38         if(weaponarenastring)
39                 strunzone(weaponarenastring);
40         if(weaponarenastring_cvar)
41                 strunzone(weaponarenastring_cvar);
42
43         weaponarenastring_cvar = strzone(s);
44
45         n = tokenize_console(s);
46         s = "";
47         for(i = 0; i < n; ++i)
48         {
49                 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
50                 {
51                         e = get_weaponinfo(j);
52                         if(argv(i) == e.netname)
53                                 s = strcat(s, " & ", e.message);
54                 }
55         }
56         s = strcat(substring(s, 3, strlen(s) - 3), " Arena");
57         
58         weaponarenastring = strzone(s);
59
60         return weaponarenastring;
61 }
62
63 string toStringNexuizMutatorsDialog(entity me)
64 {
65         string s;
66         s = "";
67         if(cvar("g_minstagib"))
68                 s = strcat(s, ", MinstaGib");
69         if(cvar("g_nixnex"))
70                 s = strcat(s, ", NixNex");
71         if(cvar_string("g_weaponarena") != "0")
72                 s = strcat(s, ", ", WeaponArenaString());
73         if(cvar("g_start_weapon_laser") == 0)
74                 s = strcat(s, ", No start weapons");
75         if(cvar("sv_gravity") < 800)
76                 s = strcat(s, ", Low gravity");
77         if(cvar("g_cloaked"))
78                 s = strcat(s, ", Cloaked");
79         if(cvar("g_footsteps"))
80                 s = strcat(s, ", Steps");
81         if(cvar("g_grappling_hook"))
82                 s = strcat(s, ", Hook");
83         if(cvar("g_laserguided_missile"))
84                 s = strcat(s, ", LG missiles");
85         if(cvar("g_midair"))
86                 s = strcat(s, ", Midair");
87         if(cvar("g_vampire"))
88                 s = strcat(s, ", Vampire");
89         if(cvar("g_pinata"))
90                 s = strcat(s, ", Pinata");
91         if(cvar("g_weapon_stay"))
92                 s = strcat(s, ", Weapons stay");
93         if(cvar("g_bloodloss") > 0)
94                 s = strcat(s, ", Bloodloss");
95         if(cvar("g_jetpack"))
96                 s = strcat(s, ", Jet pack");
97         if(s == "")
98                 return "None";
99         else
100                 return substring(s, 2, strlen(s) - 2);
101 }
102
103
104
105 // WARNING: dirty hack. TODO clean this up by putting this behaviour in extra classes.
106 void loadCvarsLaserWeaponArenaWeaponButton(entity me)
107 {
108         tokenize_console(cvar_string("g_weaponarena"));
109         me.checked = (argv(0) == me.cvarValue);
110 }
111
112 void saveCvarsLaserWeaponArenaWeaponButton(entity me)
113 {
114         string suffix;
115
116         suffix = "";
117         if(me.cvarValue != "laser" && me.cvarValue != "most")
118                 if(cvar("menu_weaponarena_with_laser"))
119                         suffix = " laser";
120         if(me.checked)
121                 cvar_set("g_weaponarena", strcat(me.cvarValue, suffix));
122         else
123                 cvar_set("g_weaponarena", me.cvarOffValue);
124 }
125
126 .void(entity) draw_weaponarena;
127 .void(entity) saveCvars_weaponarena;
128 void saveCvarsLaserWeaponArenaLaserButton(entity me)
129 {
130         // run the old function
131         me.saveCvars_weaponarena(me);
132
133         me.disabled = ((cvar_string("g_weaponarena") == "0") || (cvar_string("g_weaponarena") == "laser") || (cvar_string("g_weaponarena") == "most"));
134
135         if not(me.disabled)
136         {
137                 // check for the laser suffix
138                 string s;
139                 s = cvar_string("g_weaponarena");
140                 if(me.checked && substring(s, strlen(s) - 6, 6) != " laser")
141                         s = strcat(s, " laser");
142                 else if(!me.checked && substring(s, strlen(s) - 6, 6) == " laser")
143                         s = substring(s, 0, strlen(s) - 6);
144                 cvar_set("g_weaponarena", s);
145         }
146 }
147
148 void preDrawLaserWeaponArenaLaserButton(entity me)
149 {
150         me.disabled = ((cvar_string("g_weaponarena") == "0") || (cvar_string("g_weaponarena") == "laser") || (cvar_string("g_weaponarena") == "most"));
151         // run the old function
152         me.draw_weaponarena(me);
153 }
154 // WARNING: end of dirty hack. Do not try this at home.
155
156
157
158 void fillNexuizMutatorsDialog(entity me)
159 {
160         entity e, s, w;
161         float i, j;
162         string str, hstr;
163         me.TR(me);
164                 me.TD(me, 1, 2, makeNexuizTextLabel(0, "Gameplay mutators:"));
165         me.TR(me);
166                 me.TDempty(me, 0.2);
167                 me.TD(me, 1, 2, e = makeNexuizCheckBox(0, "g_cloaked", "Cloaked"));
168         me.TR(me);
169                 me.TDempty(me, 0.2);
170                 me.TD(me, 1, 2, e = makeNexuizCheckBox(0, "g_footsteps", "Footsteps"));
171         me.TR(me);
172                 me.TDempty(me, 0.2);
173                 me.TD(me, 1, 2, e = makeNexuizCheckBox(0, "g_midair", "Midair"));
174         me.TR(me);
175                 me.TDempty(me, 0.2);
176                 me.TD(me, 1, 2, e = makeNexuizCheckBox(0, "g_vampire", "Vampire"));
177         me.TR(me);
178                 me.TDempty(me, 0.2);
179                 s = makeNexuizSlider(10, 50, 1, "g_bloodloss");
180                 me.TD(me, 1, 2, e = makeNexuizSliderCheckBox(0, 1, s, "Blood loss"));
181         me.TR(me);
182                 me.TDempty(me, 0.4);
183                 me.TD(me, 1, 1.8, s);
184         me.TR(me);
185                 me.TDempty(me, 0.2);
186                 s = makeNexuizSlider(80, 400, 8, "sv_gravity");
187                         s.valueDigits = 0;
188                         s.valueDisplayMultiplier = 0.125; // show gravity in percent
189                 me.TD(me, 1, 2, e = makeNexuizSliderCheckBox(800, 1, s, "Low gravity"));
190                         e.savedValue = 200; // good on silvercity
191         me.TR(me);
192                 me.TDempty(me, 0.4);
193                 me.TD(me, 1, 1.8, s);
194         me.TR(me);
195         me.TR(me);
196                 me.TD(me, 1, 2, makeNexuizTextLabel(0, "Weapon & item mutators:"));
197         me.TR(me);
198                 me.TDempty(me, 0.2);
199                 me.TD(me, 1, 2, e = makeNexuizCheckBox(0, "g_grappling_hook", "Grappling hook"));
200         me.TR(me);
201                 me.TDempty(me, 0.2);
202                 me.TD(me, 1, 2, e = makeNexuizCheckBox(0, "g_jetpack", "Jet pack"));
203         me.TR(me);
204                 me.TDempty(me, 0.2);
205                 me.TD(me, 1, 2, e = makeNexuizCheckBox(0, "g_laserguided_missile", "Laser guided missiles"));
206         me.TR(me);
207                 me.TDempty(me, 0.2);
208                 me.TD(me, 1, 2, e = makeNexuizCheckBox(0, "g_pinata", "Pinata"));
209         me.TR(me);
210                 me.TDempty(me, 0.2);
211                 me.TD(me, 1, 2, e = makeNexuizCheckBoxEx(2, 0, "g_weapon_stay", "Weapons stay"));
212         me.TR(me);
213
214         me.gotoRC(me, 0, 2); me.setFirstColumn(me, me.currentColumn);
215                 me.TD(me, 1, 4, makeNexuizTextLabel(0, "Weapon arenas:"));
216         me.TR(me);
217                 me.TDempty(me, 0.2);
218                 me.TD(me, 1, 2, e = makeNexuizRadioButton(1, string_null, string_null, "Regular (no arena)"));
219         for(i = WEP_FIRST, j = 0; i <= WEP_LAST; ++i)
220         {
221                 w = get_weaponinfo(i);
222                 if(w.spawnflags & WEPSPAWNFLAG_HIDDEN)
223                         continue;
224                 if(j & 1 == 0)
225                         me.TR(me);
226                 str = w.netname;
227                 hstr = w.message;
228                 me.TDempty(me, 0.2);
229                 me.TD(me, 1, 2, e = makeNexuizRadioButton(1, "g_weaponarena", strzone(str), strzone(hstr)));
230                         e.cvarOffValue = "0";
231                         // custom load/save logic that ignores a " laser" suffix, or adds it 
232                         e.loadCvars = loadCvarsLaserWeaponArenaWeaponButton;
233                         e.saveCvars = saveCvarsLaserWeaponArenaWeaponButton;
234                         e.loadCvars(e);
235                 ++j;
236         }
237         me.TR(me);
238                 me.TDempty(me, 0.2);
239                 me.TD(me, 1, 1, e = makeNexuizCheckBox(0, "menu_weaponarena_with_laser", "with laser"));
240                         // hook the draw function to gray it out
241                         e.draw_weaponarena = e.draw;
242                         e.draw = preDrawLaserWeaponArenaLaserButton;
243                         // hook the save function to notify about the cvar
244                         e.saveCvars_weaponarena = e.saveCvars;
245                         e.saveCvars = saveCvarsLaserWeaponArenaLaserButton;
246         me.TR(me);
247                 me.TD(me, 1, 4, makeNexuizTextLabel(0, "Special arenas:"));
248         me.TR(me);
249                 me.TDempty(me, 0.2);
250                 me.TD(me, 1, 2, e = makeNexuizRadioButton(1, "g_minstagib", string_null, "MinstaGib"));
251         me.TR(me);
252                 me.TDempty(me, 0.2);
253                 me.TD(me, 1, 2, e = makeNexuizRadioButton(1, "g_nixnex", string_null, "NixNex"));
254         me.TR(me);
255                 me.TDempty(me, 0.4);
256                 me.TD(me, 1, 1, e = makeNexuizCheckBox(0, "g_nixnex_with_laser", "with laser"));
257                         setDependent(e, "g_nixnex", 1, 1);
258         me.TR(me);
259                 me.TDempty(me, 0.2);
260                 me.TD(me, 1, 2, e = makeNexuizRadioButton(1, "g_weaponarena", "most", "Most weapons"));
261                         e.cvarOffValue = "0";
262         me.TR(me);
263                 me.TDempty(me, 0.2);
264                 me.TD(me, 1, 2, e = makeNexuizRadioButton(1, "g_start_weapon_laser", "0", "No start weapons"));
265                         e.cvarOffValue = "-1";
266                         makeMulti(e, "g_start_weapon_shotgun g_start_weapon_uzi g_start_weapon_grenadelauncher g_start_weapon_electro g_start_weapon_crylink g_start_weapon_nex g_start_weapon_hagar g_start_weapon_rocketlauncher g_start_weapon_campingrifle g_start_weapon_hlac g_start_weapon_seeker g_start_weapon_minstanex g_start_weapon_hook g_start_weapon_porto g_start_weapon_tuba");
267
268         me.gotoRC(me, me.rows - 1, 0);
269                 me.TD(me, 1, me.columns, e = makeNexuizButton("OK", '0 0 0'));
270                         e.onClick = Dialog_Close;
271                         e.onClickEntity = me;
272 }
273
274 void closeNexuizMutatorsDialog(entity me)
275 {
276         if(me.refilterEntity)
277                 me.refilterEntity.refilter(me.refilterEntity);
278         closeDialog(me);
279 }
280 #endif