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