]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/xonotic/dialog_multiplayer_create_mutators.c
get rid of g_powerup_*; add g_powerups
[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, 17)
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_nix"))
72                 s = strcat(s, ", ", _("NIX"));
73         if(cvar("g_rocket_flying"))
74                 s = strcat(s, ", ", _("Rocket Flying"));
75         if(cvar("g_invincible_projectiles"))
76                 s = strcat(s, ", ", _("Invincible Projectiles"));
77         if(cvar_string("g_weaponarena") != "0")
78                 s = strcat(s, ", ", WeaponArenaString());
79         if(cvar("g_start_weapon_laser") == 0)
80                 s = strcat(s, ", ", _("No start weapons"));
81         if(cvar("sv_gravity") < 800)
82                 s = strcat(s, ", ", _("Low gravity"));
83         if(cvar("g_cloaked"))
84                 s = strcat(s, ", ", _("Cloaked"));
85         if(cvar("g_grappling_hook"))
86                 s = strcat(s, ", ", _("Hook"));
87         if(cvar("g_midair"))
88                 s = strcat(s, ", ", _("Midair"));
89         if(cvar("g_vampire"))
90                 s = strcat(s, ", ", _("Vampire"));
91         if(cvar("g_pinata"))
92                 s = strcat(s, ", ", _("Piñata"));
93         if(cvar("g_weapon_stay"))
94                 s = strcat(s, ", ", _("Weapons stay"));
95         if(cvar("g_bloodloss") > 0)
96                 s = strcat(s, ", ", _("Blood loss"));
97         if(cvar("g_jetpack"))
98                 s = strcat(s, ", ", _("Jet pack"));
99         if(!cvar("g_powerups"))
100                 s = strcat(s, ", ", _("No powerups"));
101         if(s == "")
102                 return ZCTX(_("MUT^None"));
103         else
104                 return substring(s, 2, strlen(s) - 2);
105 }
106
107
108
109 // WARNING: dirty hack. TODO clean this up by putting this behaviour in extra classes.
110 void loadCvarsLaserWeaponArenaWeaponButton(entity me)
111 {
112         tokenize_console(cvar_string("g_weaponarena"));
113         me.checked = (argv(0) == me.cvarValue);
114 }
115
116 void saveCvarsLaserWeaponArenaWeaponButton(entity me)
117 {
118         string suffix;
119
120         suffix = "";
121         if(me.cvarValue != "laser" && me.cvarValue != "most")
122                 if(cvar("menu_weaponarena_with_laser"))
123                         suffix = " laser";
124         if(me.checked)
125                 cvar_set("g_weaponarena", strcat(me.cvarValue, suffix));
126         else
127                 cvar_set("g_weaponarena", me.cvarOffValue);
128 }
129
130 .void(entity) draw_weaponarena;
131 .void(entity) saveCvars_weaponarena;
132 void saveCvarsLaserWeaponArenaLaserButton(entity me)
133 {
134         // run the old function
135         me.saveCvars_weaponarena(me);
136
137         me.disabled = ((cvar_string("g_weaponarena") == "0") || (cvar_string("g_weaponarena") == "laser") || (cvar_string("g_weaponarena") == "most"));
138
139         if not(me.disabled)
140         {
141                 // check for the laser suffix
142                 string s;
143                 s = cvar_string("g_weaponarena");
144                 if(me.checked && substring(s, strlen(s) - 6, 6) != " laser")
145                         s = strcat(s, " laser");
146                 else if(!me.checked && substring(s, strlen(s) - 6, 6) == " laser")
147                         s = substring(s, 0, strlen(s) - 6);
148                 cvar_set("g_weaponarena", s);
149         }
150 }
151
152 void preDrawLaserWeaponArenaLaserButton(entity me)
153 {
154         me.disabled = ((cvar_string("g_weaponarena") == "0") || (cvar_string("g_weaponarena") == "laser") || (cvar_string("g_weaponarena") == "most"));
155         // run the old function
156         me.draw_weaponarena(me);
157 }
158 // WARNING: end of dirty hack. Do not try this at home.
159
160
161
162 void XonoticMutatorsDialog_fill(entity me)
163 {
164         entity e, s, w;
165         float i, j;
166         string str, hstr;
167         me.TR(me);
168                 me.TD(me, 1, 2, makeXonoticTextLabel(0, _("Gameplay mutators:")));
169         me.TR(me);
170                 me.TDempty(me, 0.2);
171                 me.TD(me, 1, 2, e = makeXonoticCheckBox(0, "g_dodging", _("Dodging")));
172         me.TR(me);
173                 me.TDempty(me, 0.2);
174                 me.TD(me, 1, 2, e = makeXonoticCheckBox(0, "g_cloaked", _("Cloaked")));
175         me.TR(me);
176                 me.TDempty(me, 0.2);
177                 me.TD(me, 1, 2, e = makeXonoticCheckBox(0, "g_midair", _("Midair")));
178         me.TR(me);
179                 me.TDempty(me, 0.2);
180                 me.TD(me, 1, 2, e = makeXonoticCheckBox(0, "g_vampire", _("Vampire")));
181         me.TR(me);
182                 me.TDempty(me, 0.2);
183                 s = makeXonoticSlider(10, 50, 1, "g_bloodloss");
184                 me.TD(me, 1, 2, e = makeXonoticSliderCheckBox(0, 1, s, _("Blood loss")));
185         me.TR(me);
186                 me.TDempty(me, 0.4);
187                 me.TD(me, 1, 1.8, s);
188         me.TR(me);
189                 me.TDempty(me, 0.2);
190                 s = makeXonoticSlider(80, 400, 8, "sv_gravity");
191                         s.valueDigits = 0;
192                         s.valueDisplayMultiplier = 0.125; // show gravity in percent
193                 me.TD(me, 1, 2, e = makeXonoticSliderCheckBox(800, 1, s, _("Low gravity")));
194                         e.savedValue = 200; // good on silvercity
195         me.TR(me);
196                 me.TDempty(me, 0.4);
197                 me.TD(me, 1, 1.8, s);
198         me.TR(me);
199                 me.TD(me, 1, 2, makeXonoticTextLabel(0, _("Weapon & item mutators:")));
200         me.TR(me);
201                 me.TDempty(me, 0.2);
202                 me.TD(me, 1, 2, e = makeXonoticCheckBox(0, "g_grappling_hook", _("Grappling hook")));
203         me.TR(me);
204                 me.TDempty(me, 0.2);
205                 me.TD(me, 1, 2, e = makeXonoticCheckBox(0, "g_jetpack", _("Jet pack")));
206         me.TR(me);
207                 me.TDempty(me, 0.2);
208                 me.TD(me, 1, 2, e = makeXonoticCheckBox(0, "g_invincible_projectiles", _("Invincible Projectiles")));
209         me.TR(me);
210                 me.TDempty(me, 0.2);
211                 me.TD(me, 1, 2, e = makeXonoticCheckBox(0, "g_rocket_flying", _("Rocket Flying")));
212         me.TR(me);
213                 me.TDempty(me, 0.2);
214                 me.TD(me, 1, 2, e = makeXonoticCheckBox(0, "g_pinata", _("Piñata")));
215         me.TR(me);
216                 me.TDempty(me, 0.2);
217                 me.TD(me, 1, 2, e = makeXonoticCheckBoxEx(2, 0, "g_weapon_stay", _("Weapons stay")));
218         me.TR(me);
219
220         me.gotoRC(me, 0, 2); me.setFirstColumn(me, me.currentColumn);
221                 me.TD(me, 1, 4, makeXonoticTextLabel(0, _("Weapon arenas:")));
222         me.TR(me);
223                 me.TDempty(me, 0.2);
224                 me.TD(me, 1, 2, e = makeXonoticRadioButton(1, string_null, string_null, _("Regular (no arena)")));
225         for(i = WEP_FIRST, j = 0; i <= WEP_LAST; ++i)
226         {
227                 w = get_weaponinfo(i);
228                 if(w.spawnflags & WEP_FLAG_HIDDEN)
229                         continue;
230                 if(j & 1 == 0)
231                         me.TR(me);
232                 str = w.netname;
233                 hstr = w.message;
234                 me.TDempty(me, 0.2);
235                 me.TD(me, 1, 2, e = makeXonoticRadioButton(1, "g_weaponarena", strzone(str), strzone(hstr)));
236                         e.cvarOffValue = "0";
237                         // custom load/save logic that ignores a " laser" suffix, or adds it 
238                         e.loadCvars = loadCvarsLaserWeaponArenaWeaponButton;
239                         e.saveCvars = saveCvarsLaserWeaponArenaWeaponButton;
240                         e.loadCvars(e);
241                 ++j;
242         }
243         me.TR(me);
244                 me.TDempty(me, 0.2);
245                 me.TD(me, 1, 1, e = makeXonoticCheckBox(0, "menu_weaponarena_with_laser", _("with laser")));
246                         // hook the draw function to gray it out
247                         e.draw_weaponarena = e.draw;
248                         e.draw = preDrawLaserWeaponArenaLaserButton;
249                         // hook the save function to notify about the cvar
250                         e.saveCvars_weaponarena = e.saveCvars;
251                         e.saveCvars = saveCvarsLaserWeaponArenaLaserButton;
252         me.TR(me);
253                 me.TD(me, 1, 4, makeXonoticTextLabel(0, _("Special arenas:")));
254         me.TR(me);
255                 me.TDempty(me, 0.2);
256                 me.TD(me, 1, 2, e = makeXonoticRadioButton(1, "g_minstagib", string_null, _("MinstaGib")));
257         me.TR(me);
258                 me.TDempty(me, 0.2);
259                 me.TD(me, 1, 2, e = makeXonoticRadioButton(1, "g_nix", string_null, _("NIX")));
260         me.TR(me);
261                 me.TDempty(me, 0.4);
262                 me.TD(me, 1, 1, e = makeXonoticCheckBox(0, "g_nix_with_laser", _("with laser")));
263                         setDependent(e, "g_nix", 1, 1);
264         me.TR(me);
265                 me.TDempty(me, 0.2);
266                 me.TD(me, 1, 2, e = makeXonoticRadioButton(1, "g_weaponarena", "most", _("Most weapons")));
267                         e.cvarOffValue = "0";
268         me.TR(me);
269                 me.TDempty(me, 0.2);
270                 me.TD(me, 1, 2, e = makeXonoticRadioButton(1, "g_start_weapon_laser", "0", _("No start weapons")));
271                         e.cvarOffValue = "-1";
272                         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");
273
274         me.gotoRC(me, me.rows - 1, 0);
275                 me.TD(me, 1, me.columns, e = makeXonoticButton(_("OK"), '0 0 0'));
276                         e.onClick = Dialog_Close;
277                         e.onClickEntity = me;
278 }
279
280 void XonoticMutatorsDialog_close(entity me)
281 {
282         if(me.refilterEntity)
283                 me.refilterEntity.refilter(me.refilterEntity);
284         SUPER(XonoticMutatorsDialog).close(me);
285 }
286 #endif