]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/xonotic/dialog_multiplayer_create_mutators.c
Merge remote-tracking branch 'origin/Mario/vehicle_crash_fix'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / xonotic / dialog_multiplayer_create_mutators.c
1 #ifdef INTERFACE
2 CLASS(XonoticMutatorsDialog) EXTENDS(XonoticDialog)
3         METHOD(XonoticMutatorsDialog, toString, string(entity))
4         METHOD(XonoticMutatorsDialog, fill, void(entity))
5         METHOD(XonoticMutatorsDialog, showNotify, void(entity))
6         METHOD(XonoticMutatorsDialog, close, void(entity))
7         ATTRIB(XonoticMutatorsDialog, title, string, _("Mutators"))
8         ATTRIB(XonoticMutatorsDialog, color, vector, SKINCOLOR_DIALOG_MUTATORS)
9         ATTRIB(XonoticMutatorsDialog, intendedWidth, float, 0.9)
10         ATTRIB(XonoticMutatorsDialog, rows, float, 19)
11         ATTRIB(XonoticMutatorsDialog, columns, float, 6)
12         ATTRIB(XonoticMutatorsDialog, refilterEntity, entity, NULL)
13 ENDCLASS(XonoticMutatorsDialog)
14 #endif
15
16 #ifdef IMPLEMENTATION
17 void XonoticMutatorsDialog_showNotify(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 = sprintf(_("%s Arena"), substring(s, 3, strlen(s) - 3));
57
58         weaponarenastring = strzone(s);
59
60         return weaponarenastring;
61 }
62
63 string XonoticMutatorsDialog_toString(entity me)
64 {
65         string s;
66         s = "";
67         if(cvar("g_dodging"))
68                 s = strcat(s, ", ", _("Dodging"));
69         if(cvar("g_minstagib"))
70                 s = strcat(s, ", ", _("MinstaGib"));
71         if(cvar("g_new_toys"))
72                 s = strcat(s, ", ", _("New Toys"));
73         if(cvar("g_nix"))
74                 s = strcat(s, ", ", _("NIX"));
75         if(cvar("g_rocket_flying"))
76                 s = strcat(s, ", ", _("Rocket Flying"));
77         if(cvar("g_invincible_projectiles"))
78                 s = strcat(s, ", ", _("Invincible Projectiles"));
79         if(cvar_string("g_weaponarena") != "0")
80                 s = strcat(s, ", ", WeaponArenaString());
81         if(cvar("g_start_weapon_laser") == 0)
82                 s = strcat(s, ", ", _("No start weapons"));
83         if(cvar("sv_gravity") < 800)
84                 s = strcat(s, ", ", _("Low gravity"));
85         if(cvar("g_cloaked"))
86                 s = strcat(s, ", ", _("Cloaked"));
87         if(cvar("g_grappling_hook"))
88                 s = strcat(s, ", ", _("Hook"));
89         if(cvar("g_midair"))
90                 s = strcat(s, ", ", _("Midair"));
91         if(cvar("g_vampire"))
92                 s = strcat(s, ", ", _("Vampire"));
93         if(cvar("g_pinata"))
94                 s = strcat(s, ", ", _("Piñata"));
95         if(cvar("g_weapon_stay"))
96                 s = strcat(s, ", ", _("Weapons stay"));
97         if(cvar("g_bloodloss") > 0)
98                 s = strcat(s, ", ", _("Blood loss"));
99         if(cvar("g_jetpack"))
100                 s = strcat(s, ", ", _("Jet pack"));
101         if(cvar("g_powerups") == 0)
102                 s = strcat(s, ", ", _("No powerups"));
103         if(cvar("g_powerups") > 0)
104                 s = strcat(s, ", ", _("Powerups"));
105         if(cvar("g_touchexplode") > 0)
106                 s = strcat(s, ", ", _("Touch explode"));
107         if(s == "")
108                 return ZCTX(_("MUT^None"));
109         else
110                 return substring(s, 2, strlen(s) - 2);
111 }
112
113
114
115 // WARNING: dirty hack. TODO clean this up by putting this behaviour in extra classes.
116 void loadCvarsLaserWeaponArenaWeaponButton(entity me)
117 {
118         tokenize_console(cvar_string("g_weaponarena"));
119         me.checked = (argv(0) == me.cvarValue);
120 }
121
122 void saveCvarsLaserWeaponArenaWeaponButton(entity me)
123 {
124         string suffix;
125
126         suffix = "";
127         if(me.cvarValue != "laser" && me.cvarValue != "most")
128                 if(cvar("menu_weaponarena_with_laser"))
129                         suffix = " laser";
130         if(me.checked)
131                 cvar_set("g_weaponarena", strcat(me.cvarValue, suffix));
132         else
133                 cvar_set("g_weaponarena", me.cvarOffValue);
134 }
135
136 .void(entity) draw_weaponarena;
137 .void(entity) saveCvars_weaponarena;
138 void saveCvarsLaserWeaponArenaLaserButton(entity me)
139 {
140         // run the old function
141         me.saveCvars_weaponarena(me);
142
143         me.disabled = ((cvar_string("g_weaponarena") == "0") || (cvar_string("g_weaponarena") == "laser") || (cvar_string("g_weaponarena") == "most"));
144
145         if not(me.disabled)
146         {
147                 // check for the laser suffix
148                 string s;
149                 s = cvar_string("g_weaponarena");
150                 if(me.checked && substring(s, strlen(s) - 6, 6) != " laser")
151                         s = strcat(s, " laser");
152                 else if(!me.checked && substring(s, strlen(s) - 6, 6) == " laser")
153                         s = substring(s, 0, strlen(s) - 6);
154                 cvar_set("g_weaponarena", s);
155         }
156 }
157
158 void preDrawLaserWeaponArenaLaserButton(entity me)
159 {
160         me.disabled = ((cvar_string("g_weaponarena") == "0") || (cvar_string("g_weaponarena") == "laser") || (cvar_string("g_weaponarena") == "most"));
161         // run the old function
162         me.draw_weaponarena(me);
163 }
164 // WARNING: end of dirty hack. Do not try this at home.
165
166 float checkCompatibility_pinata(entity me)
167 {
168         if(cvar("g_minstagib"))
169                 return 0;
170         if(cvar("g_nix"))
171                 return 0;
172         if(cvar_string("g_weaponarena") != "0")
173                 return 0;
174         return 1;
175 }
176 float checkCompatibility_weaponstay(entity me)
177 {
178         return checkCompatibility_pinata(me);
179 }
180 float checkCompatibility_newtoys(entity me)
181 {
182         if(cvar("g_minstagib"))
183                 return 0;
184         if(cvar_string("g_weaponarena") == "most")
185                 return 1;
186         if(cvar_string("g_weaponarena") == "all")
187                 return 1;
188         if(cvar_string("g_weaponarena") != "0")
189                 return 0;
190         return 1;
191 }
192
193 void XonoticMutatorsDialog_fill(entity me)
194 {
195         entity e, s, w;
196         float i, j;
197         string str, hstr;
198         me.TR(me);
199                 me.TD(me, 1, 2, makeXonoticTextLabel(0, _("Gameplay mutators:")));
200         me.TR(me);
201                 me.TDempty(me, 0.2);
202                 me.TD(me, 1, 1.8, e = makeXonoticCheckBox(0, "g_dodging", _("Dodging")));
203         me.TR(me);
204                 me.TDempty(me, 0.2);
205                 me.TD(me, 1, 1.8, e = makeXonoticCheckBox(0, "g_touchexplode", _("Touch explode")));
206         me.TR(me);
207                 me.TDempty(me, 0.2);
208                 me.TD(me, 1, 1.8, e = makeXonoticCheckBox(0, "g_cloaked", _("Cloaked")));
209         me.TR(me);
210                 me.TDempty(me, 0.2);
211                 me.TD(me, 1, 1.8, e = makeXonoticCheckBox(0, "g_midair", _("Midair")));
212         me.TR(me);
213                 me.TDempty(me, 0.2);
214                 me.TD(me, 1, 1.8, e = makeXonoticCheckBox(0, "g_vampire", _("Vampire")));
215         me.TR(me);
216                 me.TDempty(me, 0.2);
217                 s = makeXonoticSlider(10, 50, 1, "g_bloodloss");
218                 me.TD(me, 1, 1.8, e = makeXonoticSliderCheckBox(0, 1, s, _("Blood loss")));
219                         setDependent(e, "g_minstagib", 0, 0);
220         me.TR(me);
221                 me.TDempty(me, 0.4);
222                 me.TD(me, 1, 1.6, s);
223         me.TR(me);
224                 me.TDempty(me, 0.2);
225                 s = makeXonoticSlider(80, 400, 8, "sv_gravity");
226                         s.valueDigits = 0;
227                         s.valueDisplayMultiplier = 0.125; // show gravity in percent
228                 me.TD(me, 1, 1.8, e = makeXonoticSliderCheckBox(800, 1, s, _("Low gravity")));
229                         e.savedValue = 200; // good on silvercity
230         me.TR(me);
231                 me.TDempty(me, 0.4);
232                 me.TD(me, 1, 1.6, s);
233         me.TR(me);
234                 me.TD(me, 1, 2, makeXonoticTextLabel(0, _("Weapon & item mutators:")));
235         me.TR(me);
236                 me.TDempty(me, 0.2);
237                 me.TD(me, 1, 1.8, e = makeXonoticCheckBox(0, "g_grappling_hook", _("Grappling hook")));
238         me.TR(me);
239                 me.TDempty(me, 0.2);
240                 me.TD(me, 1, 1.8, e = makeXonoticCheckBox(0, "g_jetpack", _("Jet pack")));
241         me.TR(me);
242                 me.TDempty(me, 0.2);
243                 me.TD(me, 1, 1.8, e = makeXonoticCheckBox(0, "g_invincible_projectiles", _("Invincible Projectiles")));
244         me.TR(me);
245                 me.TDempty(me, 0.2);
246                 me.TD(me, 1, 1.8, e = makeXonoticCheckBox(0, "g_new_toys", _("New Toys")));
247                         setDependentWeird(e, checkCompatibility_newtoys);
248         me.TR(me);
249                 me.TDempty(me, 0.2);
250                 me.TD(me, 1, 1.8, e = makeXonoticCheckBox(0, "g_rocket_flying", _("Rocket Flying")));
251         me.TR(me);
252                 me.TDempty(me, 0.2);
253                 me.TD(me, 1, 1.8, e = makeXonoticCheckBox(0, "g_pinata", _("Piñata")));
254                         setDependentWeird(e, checkCompatibility_pinata);
255         me.TR(me);
256                 me.TDempty(me, 0.2);
257                 me.TD(me, 1, 1.8, e = makeXonoticCheckBox(0, "g_weapon_stay", _("Weapons stay")));
258                         setDependentWeird(e, checkCompatibility_weaponstay);
259         me.TR(me);
260
261         me.gotoRC(me, 0, 2); me.setFirstColumn(me, me.currentColumn);
262                 me.TD(me, 1, 4, makeXonoticTextLabel(0, _("Weapon arenas:")));
263         me.TR(me);
264                 me.TDempty(me, 0.2);
265                 me.TD(me, 1, 1.8, e = makeXonoticRadioButton(1, string_null, string_null, _("Regular (no arena)")));
266         for(i = WEP_FIRST, j = 0; i <= WEP_LAST; ++i)
267         {
268                 w = get_weaponinfo(i);
269                 if(w.spawnflags & WEP_FLAG_HIDDEN)
270                         continue;
271                 if(j & 1 == 0)
272                         me.TR(me);
273                 str = w.netname;
274                 hstr = w.message;
275                 me.TDempty(me, 0.2);
276                 me.TD(me, 1, 1.8, e = makeXonoticRadioButton(1, "g_weaponarena", strzone(str), strzone(hstr)));
277                         e.cvarOffValue = "0";
278                         // custom load/save logic that ignores a " laser" suffix, or adds it 
279                         e.loadCvars = loadCvarsLaserWeaponArenaWeaponButton;
280                         e.saveCvars = saveCvarsLaserWeaponArenaWeaponButton;
281                         e.loadCvars(e);
282                 ++j;
283         }
284         me.TR(me);
285                 me.TDempty(me, 0.2);
286                 me.TD(me, 1, 1.8, e = makeXonoticCheckBox(0, "menu_weaponarena_with_laser", _("with laser")));
287                         // hook the draw function to gray it out
288                         e.draw_weaponarena = e.draw;
289                         e.draw = preDrawLaserWeaponArenaLaserButton;
290                         // hook the save function to notify about the cvar
291                         e.saveCvars_weaponarena = e.saveCvars;
292                         e.saveCvars = saveCvarsLaserWeaponArenaLaserButton;
293         me.TR(me);
294                 me.TD(me, 1, 4, makeXonoticTextLabel(0, _("Special arenas:")));
295         me.TR(me);
296                 me.TDempty(me, 0.2);
297                 me.TD(me, 1, 1.8, e = makeXonoticRadioButton(1, "g_minstagib", string_null, _("MinstaGib")));
298         me.TR(me);
299                 me.TDempty(me, 0.2);
300                 me.TD(me, 1, 1.8, e = makeXonoticRadioButton(1, "g_nix", string_null, _("NIX")));
301         me.TR(me);
302                 me.TDempty(me, 0.4);
303                 me.TD(me, 1, 1.6, e = makeXonoticCheckBox(0, "g_nix_with_laser", _("with laser")));
304                         setDependent(e, "g_nix", 1, 1);
305         me.TR(me);
306                 me.TDempty(me, 0.2);
307                 me.TD(me, 1, 1.8, e = makeXonoticRadioButton(1, "g_weaponarena", "most", _("Most weapons")));
308                         e.cvarOffValue = "0";
309         me.TR(me);
310                 me.TDempty(me, 0.2);
311                 me.TD(me, 1, 1.8, e = makeXonoticRadioButton(1, "g_start_weapon_laser", "0", _("No start weapons")));
312                         e.cvarOffValue = "-1";
313                         makeMulti(e, "g_start_weapon_shotgun g_start_weapon_uzi g_start_weapon_grenadelauncher g_start_weapon_minelayer g_start_weapon_electro g_start_weapon_crylink g_start_weapon_nex g_start_weapon_hagar g_start_weapon_rocketlauncher g_start_weapon_rifle g_start_weapon_hlac g_start_weapon_seeker g_start_weapon_minstanex g_start_weapon_hook g_start_weapon_porto g_start_weapon_tuba g_start_weapon_minelayer");
314
315         me.gotoRC(me, me.rows - 1, 0);
316                 me.TD(me, 1, me.columns, e = makeXonoticButton(_("OK"), '0 0 0'));
317                         e.onClick = Dialog_Close;
318                         e.onClickEntity = me;
319 }
320
321 void XonoticMutatorsDialog_close(entity me)
322 {
323         if(me.refilterEntity)
324                 me.refilterEntity.refilter(me.refilterEntity);
325         SUPER(XonoticMutatorsDialog).close(me);
326 }
327 #endif