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