Mercurial > ~darius > hgwebdir.cgi > paradise_client
comparison option.c @ 3:5a977ccbc7a9 default tip
Empty changelog
author | darius |
---|---|
date | Sat, 06 Dec 1997 05:41:29 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
2:fba0b6e6cdc7 | 3:5a977ccbc7a9 |
---|---|
1 /* $Id: option.c,v 1.1.1.1 1997/12/06 05:41:29 darius Exp $ */ | |
2 | |
3 /* | |
4 * option.c | |
5 */ | |
6 #include "copyright.h" | |
7 | |
8 #include <stdio.h> | |
9 #include <ctype.h> | |
10 #include "Wlib.h" | |
11 #ifdef SOUND | |
12 #include "Slib.h" | |
13 #endif | |
14 #include "defs.h" | |
15 #include "struct.h" | |
16 #include "data.h" | |
17 #include "packets.h" | |
18 #include "proto.h" | |
19 | |
20 #ifdef DEBUG | |
21 #define IFDEBUG(foo) foo | |
22 #else | |
23 #define IFDEBUG(foo) | |
24 #endif | |
25 | |
26 static int notdone; /* not done flag */ | |
27 static int oldzoom = -2; | |
28 | |
29 /* kludgy way to make options that do some action when clicked: */ | |
30 static int clearPhaserStats = 1; | |
31 static int reloadShipBitmaps = 1; | |
32 | |
33 #ifdef ROTATERACE | |
34 static int old_rotate, old_rotate_deg; | |
35 #endif | |
36 | |
37 static int old_ping; | |
38 | |
39 /* static int updateSpeed= 5;*/ | |
40 static int lastUpdateSpeed = -1; | |
41 | |
42 static char newkeys[14]; | |
43 static char newckeys[14]; | |
44 static char newbuttons[14]; | |
45 static char newcbuttons[14]; | |
46 | |
47 static int remapAllShips = 1; | |
48 | |
49 char *keymapmes[] = { | |
50 "Key/Buttonmap only affect THIS ship type", | |
51 "Key/Buttonmap affect ALL ship types", | |
52 "" | |
53 }; | |
54 | |
55 #ifdef TIMER | |
56 char *timermes[] = | |
57 {"Timer shows nothing (off)", | |
58 "Timer shows time of day", | |
59 "Timer shows time on server", | |
60 "Timer shows time in ship", | |
61 "Timer shows user-set time", | |
62 ""}; | |
63 #endif /* TIMER */ | |
64 | |
65 char *localmes[] = | |
66 {"Show owner on local planets", | |
67 "Show facilities on local planets", | |
68 "Show nothing on local planets", | |
69 "Show surface properties on local planets", | |
70 "Show MOO facilities on local planets", | |
71 ""}; | |
72 | |
73 char *galacticmes[] = | |
74 {"Show owner on galactic map", | |
75 "Show facilities on galactic map", | |
76 "Show nothing on galactic map", | |
77 "Show surface properties on galactic map", | |
78 "Show scout info age on galactic map", | |
79 "Show MOO facilities on galactic map", | |
80 ""}; | |
81 | |
82 #ifdef ROTATERACE | |
83 char *rotatemess[] = | |
84 {"Don't rotate galaxy", | |
85 "Rotate galaxy 90 degrees", | |
86 "Rotate galaxy 180 degrees", | |
87 "Rotate galaxy 270 degrees", | |
88 "" | |
89 }; | |
90 #endif | |
91 | |
92 char *mapupdates[] = | |
93 {"Don't update galactic map", | |
94 "Update galactic map frequently", | |
95 "Update galactic map rarely", | |
96 ""}; | |
97 | |
98 static char *lockoptions[] = | |
99 {"Don't show lock icon", | |
100 "show lock icon on galactic map only", | |
101 "Show lock icon on tactical map only", | |
102 "Show lock icon on both map windows", ""}; | |
103 | |
104 static char *phaseroptions[] = | |
105 {"Don't show phaser messages", | |
106 "Phaser messages in kill window", | |
107 "Phaser messages in phaser window", | |
108 "Phaser messages in phaser window only", | |
109 "Phaser messages in total review only", | |
110 ""}; | |
111 | |
112 static char *dashboardoptions[] = | |
113 {"Old Dashboard", | |
114 "New Dashboard", | |
115 "Color Dashboard", | |
116 "Rainbow Dashboard", | |
117 ""}; | |
118 | |
119 static char *autoZoomOpts[] = | |
120 {"Don't auto-zoom map", | |
121 "Auto-zoom map on Red OR Yellow Alert", | |
122 "Auto-zoom map on Red Alert", | |
123 ""}; | |
124 | |
125 static char *autoUnZoomOpts[] = | |
126 {"Don't auto-unzoom map", | |
127 "Auto-unzoom map on Green alert", | |
128 "Auto-unzoom map on Green OR Yellow Alert", | |
129 ""}; | |
130 | |
131 static char *autoSetWarOpts[] = | |
132 {"Don't auto set war declarations", | |
133 "Set war with non-zero player teams", | |
134 "Set war with largest enemy team", | |
135 ""}; | |
136 | |
137 /* useful for options that are an int with a range */ | |
138 struct int_range { | |
139 int min_value; /* value is >= this */ | |
140 int max_value; /* value is <= this */ | |
141 int increment; /* a click raises/lowers this amount */ | |
142 /* do bitwise shift by 1 if increment */ | |
143 /* == -1 */ | |
144 }; | |
145 | |
146 | |
147 /* | |
148 * Only one of op_option, op_targetwin, and op_string should be defined. If | |
149 * op_string is defined, op_size should be too and op_text is used without a | |
150 * "Don't" prefix. if op_range is defined, there should be a %d in op_text | |
151 * for it, op_size will be non-useful, and the 'Don't ' prefix won't appear | |
152 */ | |
153 struct option { | |
154 char *op_text; /* text to display when on */ | |
155 int *op_option; /* variable to test/modify (optional) */ | |
156 W_Window *op_targetwin; /* target window to map/unmap (optional) */ | |
157 char *op_string; /* string to modify (optional) */ | |
158 int op_size; /* size of *op_string (optional) */ | |
159 char **op_array; /* array of strings to switch between */ | |
160 struct int_range *op_range; /* struct definint an integer range option */ | |
161 | |
162 int op_num; /* used internally */ | |
163 }; | |
164 | |
165 /* for the paged options menus */ | |
166 struct option_menu { | |
167 int page_num; /* page number of this menu */ | |
168 struct option_menu *Next; | |
169 struct option *menu; /* pointers to arrary of options */ | |
170 int numopt; /* number of options in this menu page */ | |
171 int updated; /* 1 if options can be changed externally */ | |
172 }; | |
173 | |
174 /* pointer to first entry in the options menu list */ | |
175 static | |
176 struct option_menu *FirstMenu = NULL; | |
177 static | |
178 struct option_menu *CurrentMenu = NULL; /* menu currently looked at */ | |
179 int MenuPage = 1; /* current menu page */ | |
180 int MaxOptions = 0; /* maximum number of options in all menu | |
181 pages */ | |
182 struct int_range MenuPages = | |
183 {1, 1, 1}; | |
184 | |
185 /* range of updates for keep-info-window-up option */ | |
186 struct int_range keepInfo_range = | |
187 {0, 100, 1}; | |
188 | |
189 /* updates: use of the int range thing... */ | |
190 struct int_range updates_range = | |
191 {1, 10, 1}; | |
192 | |
193 struct int_range redraw_delay_range = | |
194 {0, 10, 1}; | |
195 | |
196 /* range of menus. Will be updated when menu list is assembled */ | |
197 struct int_range Menus_Range = | |
198 {1, 1, 1}; | |
199 | |
200 #ifdef CONTINUOUS_MOUSE | |
201 struct int_range clickDelay_range = | |
202 {0, 20, 1}; | |
203 #endif /* CONTINUOUS_MOUSE */ | |
204 | |
205 #ifdef BEEPLITE | |
206 struct int_range beeplite_planet_range = | |
207 {0, 50, 1}; | |
208 struct int_range beeplite_player_range = | |
209 {0, 50, 1}; | |
210 #endif | |
211 | |
212 struct int_range zoom_override_range = | |
213 {0, 99, 1}; | |
214 | |
215 #ifdef LOCAL_SHIPSTATS | |
216 struct int_range statHeight_range = | |
217 {4,100, 4}; | |
218 #endif | |
219 | |
220 /* range for tacPlanetInfo */ | |
221 struct int_range tacPlanetInfo_range = {0, 31, 1}; | |
222 | |
223 /* menus */ | |
224 | |
225 struct option Features_Menu[] = | |
226 { | |
227 {"Defaults Menu", &MenuPage, 0, 0, 0, NULL, &Menus_Range}, | |
228 {"Page %d (click here to change)", &MenuPage, 0, 0, 0, NULL, &Menus_Range}, | |
229 {0, &mapmode, 0, 0, 0, mapupdates, NULL}, | |
230 {0, &showgalactic, 0, 0, 0, galacticmes, NULL}, | |
231 {0, &showlocal, 0, 0, 0, localmes, NULL}, | |
232 #ifdef SHOW_IND | |
233 {"show IND planets", &showIND, 0, 0, 0, NULL, NULL}, | |
234 #endif | |
235 {"send MOTD bitmaps", &sendmotdbitmaps, 0, 0, 0, NULL, NULL}, | |
236 {"reload ship bitmaps", &reloadShipBitmaps, 0, 0, 0, NULL, NULL}, | |
237 {"stay peaceful when reborn", &keeppeace, 0, 0, 0, NULL, NULL}, | |
238 {0, &remapAllShips, 0, 0, 0, keymapmes, NULL}, | |
239 {"new keymap entries: %s_", 0, 0, newkeys, 13, NULL, NULL}, | |
240 {"new ckeymap entries: %s_", 0, 0, newckeys, 13, NULL, NULL}, | |
241 {"new buttonmap entries: %s_", 0, 0, newbuttons, 13, NULL, NULL}, | |
242 {"new cbuttonmap entries: %s_", 0, 0, newcbuttons, 13, NULL, NULL}, | |
243 {"report kill messages", &reportKills, 0, 0, 0, NULL, NULL}, | |
244 #if 0 | |
245 /* need to figure out how to dispatch options */ | |
246 {"recv variable packets", &recv_short, 0, 0, 0, NULL}, | |
247 {"recv kill messages", &recv_kmesg, 0, 0, 0, NULL}, | |
248 #endif | |
249 {"keep info %d upds (0=forever)", &keepInfo, 0, 0, 0, 0, &keepInfo_range}, | |
250 {"%d updates per second", &updateSpeed, 0, 0, 0, 0, &updates_range}, | |
251 {"%d/10 sec screen refresh delay", &redrawDelay, 0, 0, 0, 0, &redraw_delay_range}, | |
252 {"collect ping stats", &ping, 0, 0, 0, NULL, NULL}, | |
253 {"avoid message kludge", &niftyNewMessages, 0, 0, 0, NULL, NULL}, | |
254 #ifdef CONTINUOUS_MOUSE | |
255 {"use continuous mouse", &continuousMouse, 0, 0, 0, NULL, NULL}, | |
256 {"%d updates repeat delay", &clickDelay, 0, 0, 0, 0, &clickDelay_range}, | |
257 #endif /* CONTINUOUS_MOUSE */ | |
258 #ifdef UNIX_SOUND | |
259 {"play sound effects", &playSounds, 0, 0, 0, NULL, NULL}, | |
260 #endif | |
261 {"done", ¬done, 0, 0, 0, NULL, NULL}, | |
262 {NULL, 0, 0, 0, 0, NULL, NULL, /**/ -1} | |
263 }; | |
264 | |
265 struct option Window_Menu[] = | |
266 { | |
267 {"Window Menu", &MenuPage, 0, 0, 0, NULL, &Menus_Range}, | |
268 {"Page %d (click here to change)", &MenuPage, 0, 0, 0, NULL, &Menus_Range}, | |
269 {"show \"all\" message window", 0, &messWin[WALL].window, 0, 0, NULL, NULL}, | |
270 {"show \"team\" message window", 0, &messWin[WTEAM].window, 0, 0, NULL, NULL}, | |
271 {"show \"your\" message window", 0, &messWin[WINDIV].window, 0, 0, NULL, NULL}, | |
272 {"show \"kill\" message window", 0, &messWin[WKILL].window, 0, 0, NULL, NULL}, | |
273 {"show \"phaser\" message window", 0, &messWin[WPHASER].window, 0, 0, NULL, NULL}, | |
274 {"show \"joined\" message window", 0, &messWin[WREVIEW].window, 0, 0, NULL, NULL}, | |
275 {"show ship statistics window", 0, &statwin, 0, 0, NULL, NULL}, | |
276 {"show network statistics window", 0, &pStats, 0, 0, NULL, NULL}, | |
277 {"show help window", 0, &helpWin, 0, 0, NULL, NULL}, | |
278 #ifdef XTREKRC_HELP | |
279 {"show xtrekrc defaults window", 0, &defWin, 0, 0, NULL, NULL}, | |
280 #endif | |
281 #ifdef TOOLS | |
282 {"show shell tools window", 0, &toolsWin, 0, 0, NULL, NULL}, | |
283 #endif | |
284 {0, &showPhaser, 0, 0, 0, phaseroptions, NULL}, | |
285 {"", &showLock, 0, 0, 0, lockoptions, NULL}, | |
286 {"show lock line", &lockLine, 0, 0, 0, NULL, NULL}, | |
287 {"sort planets by team", &mapSort, 0, 0, 0, NULL, NULL}, | |
288 #ifdef NOWARP | |
289 {"enable message warp", &warp, 0, 0, 0, NULL, NULL}, | |
290 #endif | |
291 {"use info icon", &infoIcon, 0, 0, 0, NULL, NULL}, | |
292 {"done", ¬done, 0, 0, 0, NULL, NULL}, | |
293 {NULL, 0, 0, 0, 0, NULL, NULL, /**/ -1} | |
294 }; | |
295 | |
296 struct option Display_Menu[] = | |
297 { | |
298 {"Features Display Menu", &MenuPage, 0, 0, 0, NULL, &Menus_Range}, | |
299 {"Page %d (click here to change)", &MenuPage, 0, 0, 0, NULL, &Menus_Range}, | |
300 #ifdef ROTATERACE | |
301 {0, &rotate, 0, 0, 0, rotatemess, NULL}, | |
302 #endif | |
303 {"draw background stars", &blk_showStars, 0, 0, 0, NULL}, | |
304 {"show warp/star streaks", &warpStreaks, 0, 0, 0, NULL, NULL}, | |
305 {"show tractor/pressor", &showTractorPressor, 0, 0, 0, NULL, NULL}, | |
306 {"show all tractors/pressors", &showAllTractorPressor, 0, 0, 0, NULL, NULL}, | |
307 {"show shields", &showShields, 0, 0, 0, NULL, NULL}, | |
308 {"show shield damage", &show_shield_dam, 0, 0, 0, NULL, NULL}, | |
309 #ifdef VARY_HULL | |
310 {"show hull damage indicators", &vary_hull, 0, 0, 0, NULL, NULL}, | |
311 #endif /* VARY_HULL */ | |
312 | |
313 {"show tactical planet names", &namemode, 0, 0, 0, NULL, NULL}, | |
314 | |
315 {"zoom galactic map", &blk_zoom, 0, 0, 0, NULL, NULL}, | |
316 {0,&autoZoom, 0, 0, 0, autoZoomOpts, NULL}, | |
317 {0,&autoUnZoom, 0, 0, 0, autoUnZoomOpts, NULL}, | |
318 {"Manual zoom overrides auto-zoom %d updates",&autoZoomOverride, 0, 0, 0, NULL, | |
319 &zoom_override_range}, | |
320 {"draw galactic map grid", &drawgrid, 0, 0, 0, NULL}, | |
321 {"show sector numbers", §orNums, 0, 0, 0, NULL, NULL}, | |
322 {"show view box", &viewBox, 0, 0, 0, NULL, NULL}, | |
323 {0, &autoSetWar, 0, 0, 0, autoSetWarOpts, NULL}, | |
324 {"show planet info on tactical: %d", &tacPlanetInfo, 0, 0, 0, 0, &tacPlanetInfo_range}, | |
325 #ifdef BEEPLITE | |
326 {"use RCD highlighting", &UseLite, 0, 0, 0, NULL, NULL}, | |
327 {"highlight/use default RCDs", &DefLite, 0, 0, 0, NULL, NULL}, | |
328 {"No. of updates to highlight player: %d", &beep_lite_cycle_time_player, | |
329 0, 0, 0, NULL, &beeplite_player_range}, | |
330 {"No. of updates to highlight planet: %d", &beep_lite_cycle_time_planet, | |
331 0, 0, 0, NULL, &beeplite_planet_range}, | |
332 #endif | |
333 {"done", ¬done, 0, 0, 0, NULL, NULL}, | |
334 {NULL, 0, 0, 0, 0, NULL, NULL, /**/ -1} | |
335 }; | |
336 | |
337 struct option Playerdash_Menu[] = | |
338 { | |
339 {"Playerlist/Dashboard Menu", &MenuPage, 0, 0, 0, NULL, &Menus_Range}, | |
340 {"Page %d (click here to change)", &MenuPage, 0, 0, 0, NULL, &Menus_Range}, | |
341 {"sort playerlist", &sortPlayers, 0, 0, 0, NULL, NULL}, | |
342 {"show dead players in playerlist", &showDead, 0, 0, 0, NULL, NULL}, | |
343 {"show players as they log in", &showPreLogins, 0, 0, 0, NULL, NULL}, | |
344 {"hide 0.00 kills in playerlist", &hideNoKills, 0, 0, 0, NULL, NULL}, | |
345 {"sort outfitting to bottom", &sortOutfitting, 0, 0, 0, NULL, NULL}, | |
346 {0, &Dashboard, 0, 0, 0, dashboardoptions, NULL}, | |
347 #ifdef TIMER | |
348 {0, &timerType, 0, 0, 0, timermes, NULL}, | |
349 #endif /* TIMER */ | |
350 #ifdef LOCAL_SHIPSTATS | |
351 {"show ship stats on local window",&localShipStats, 0, 0, 0, NULL, NULL}, | |
352 {"Local ship stats height: %d",&statHeight, 0, 0, 0, NULL, &statHeight_range}, | |
353 #endif | |
354 #ifdef PACKET_LIGHTS | |
355 {"show packet lights", &packetLights, 0, 0, 0, NULL, NULL}, | |
356 #endif | |
357 {"keep phaser statistics", &phaserStats,0,0,0,NULL, NULL}, | |
358 {"clear phaser statistics", &clearPhaserStats, 0, 0, 0, NULL, NULL}, | |
359 {"done", ¬done, 0, 0, 0, NULL, NULL}, | |
360 {NULL, 0, 0, 0, 0, NULL, NULL, /**/ -1} | |
361 }; | |
362 | |
363 #ifdef HOCKEY | |
364 struct option Hockey_Menu[] = | |
365 { | |
366 {"Hockey Menu", &MenuPage, 0, 0, 0, NULL, &Menus_Range}, | |
367 {"Page %d (click here to change)", &MenuPage, 0, 0, 0, NULL, &Menus_Range}, | |
368 {"show tactical hockey lines", &tacticalHockeyLines, 0, 0, 0, NULL, NULL}, | |
369 {"show galactic hockey lines", &galacticHockeyLines, 0, 0, 0, NULL, NULL}, | |
370 {"show planets on the galactic", &cleanHockeyGalactic, 0, 0, 0, NULL, NULL}, | |
371 {"color hockey lines by team", &teamColorHockeyLines, 0, 0, 0, NULL, NULL}, | |
372 {"done", ¬done, 0, 0, 0, NULL, NULL}, | |
373 {NULL, 0, 0, 0, 0, NULL, NULL, /**/ -1} | |
374 }; | |
375 #endif /*HOCKEY*/ | |
376 | |
377 #if 0 | |
378 struct option Network_Menu[] = | |
379 { | |
380 {"Network menu", &MenuPage, 0, 0, 0, NULL, &Menus_Range}, | |
381 {"Page %d (click here to change)", &MenuPage, 0, 0, 0, NULL, &Menus_Range}, | |
382 | |
383 {"done", ¬done, 0, 0, 0, NULL, NULL}, | |
384 {NULL, 0, 0, 0, 0, NULL, NULL, /**/ -1} | |
385 }; | |
386 #endif /* 0 */ | |
387 | |
388 #if 0 | |
389 { | |
390 "show shields", &showShields, 0, 0, 0, NULL, NULL | |
391 }, | |
392 { | |
393 "show UDP control window", 0, &udpWin, 0, 0, NULL, NULL | |
394 }, | |
395 { | |
396 "show short packets window", 0, &spWin, 0, 0, NULL, NULL | |
397 }, | |
398 struct option SillyFeatures_Menu[] = | |
399 { | |
400 {"Silly Features Menu", &MenuPage, 0, 0, 0, NULL, &Menus_Range}, | |
401 {"Page %d (click here to change)", &MenuPage, 0, 0, 0, NULL, &Menus_Range}, | |
402 {"alert on extra border(s)", &extraBorder, 0, 0, 0, NULL, NULL}, | |
403 #ifdef BORGTEST | |
404 {"borg torp test", &bd, 0, 0, 0, NULL, NULL}, /* BORG TEST */ | |
405 #endif | |
406 {"done", ¬done, 0, 0, 0, NULL, NULL}, | |
407 {NULL, 0, 0, 0, 0, NULL, NULL, /**/ -1} | |
408 }; | |
409 #endif /* 0 */ | |
410 | |
411 #ifdef AMIGA | |
412 | |
413 static char *autopointmess[] = { | |
414 "AutoPoint: none", | |
415 "AutoPoint: Redirect input", | |
416 "AutoPoint: Activate window on input", | |
417 "AutoPoint: Full (inefficient)", "" | |
418 }; | |
419 | |
420 static char *dooshSoundMess[] = { | |
421 "Play doosh sound when YOU kill a carrier", | |
422 "Play doosh sound when ANY carrier dies", | |
423 "" | |
424 }; | |
425 | |
426 struct int_range soundVolRange = {0, 64, 4}; | |
427 struct int_range speechVolRange = {0, 64, 4}; | |
428 | |
429 extern int speechVol; | |
430 extern int S_AddPeriod; | |
431 extern int monoBitmaps; | |
432 | |
433 struct option Amiga_Menu[] = { | |
434 {"Amiga Features Menu", &MenuPage, 0, 0, 0, NULL, &Menus_Range}, | |
435 {"Page %d (click to change)", &MenuPage, 0, 0, 0, NULL, &Menus_Range}, | |
436 {0, &autoPoint, 0, 0, 0, autopointmess, NULL}, | |
437 {"do keyboard window depth", &W_KeyDepth, 0, 0, 0, NULL, NULL}, | |
438 {"use AnimPointers", &animPointers, 0, 0, 0, NULL, NULL}, | |
439 {"use one color bitmaps", &monoBitmaps, 0, 0, 0, NULL, NULL}, | |
440 {"use Workbench screen", &useWorkbench, 0, 0, 0, NULL, NULL}, | |
441 {"speak messages to \"all\"", &S_SpeakAll, 0, 0, 0, NULL, NULL}, | |
442 {"speak messages to you", &S_SpeakYour, 0, 0, 0, NULL, NULL}, | |
443 {"speak messages to team", &S_SpeakTeam, 0, 0, 0, NULL, NULL}, | |
444 {"speak \"kill\" messages", &S_SpeakKill, 0, 0, 0, NULL, NULL}, | |
445 {"speak messages from God", &S_SpeakGod, 0, 0, 0, NULL, NULL}, | |
446 {"speak messages from YOU", &S_SpeakSelf, 0, 0, 0, NULL, NULL}, | |
447 {"speak login/out messages", &S_SpeakLogins, 0, 0, 0, NULL, NULL}, | |
448 {"ignore repeated messages", &S_IgnoreMultiple, 0, 0, 0, 0, 0}, | |
449 {"add a period to the end of messages", &S_AddPeriod, 0, 0, 0, 0, 0}, | |
450 {"Speech volume: %d", &speechVol, 0, 0, 0, NULL, &speechVolRange}, | |
451 #ifdef SOUND | |
452 {"play digitized sounds", &soundOn, 0, 0, 0, NULL, NULL}, | |
453 {"Sound volume: %d", &soundVol, 0, 0, 0, NULL, &soundVolRange}, | |
454 {"show sounds window", 0, &soundWin, 0, 0, NULL, NULL}, | |
455 {0, &alwaysSoundDoosh, 0, 0, 0, dooshSoundMess, 0}, | |
456 #endif | |
457 {"done", ¬done, 0, 0, 0, NULL, NULL}, | |
458 {NULL, 0, 0, 0, 0, NULL, NULL, /**/ -1} | |
459 }; | |
460 | |
461 #endif /* AMIGA */ | |
462 | |
463 #define NUMOPTIONS(menu) ((sizeof((menu))/sizeof((menu)[0]))-1) | |
464 | |
465 | |
466 /* option menu sizes and such */ | |
467 #define OPTIONBORDER 2 | |
468 #define OPTIONLEN 40 | |
469 | |
470 static void RefreshOptions P((void)); | |
471 static void SetMenuPage P((int pagenum)); | |
472 static int InitOptionMenus P((void)); | |
473 static void AddOptMenu P((struct option NewMenu[], int updated)); | |
474 static int NumOptions P((struct option OpMenu[])); | |
475 /*static void UpdateOptions P((void));*/ | |
476 void optionrefresh P((register struct option * op)); | |
477 | |
478 | |
479 /* Set up the option menus and window. */ | |
480 void | |
481 optionwindow() | |
482 { | |
483 /* Init not done flag */ | |
484 notdone = 1; | |
485 | |
486 old_ping = ping; | |
487 old_rotate = rotate; | |
488 old_rotate_deg = rotate_deg; | |
489 | |
490 *newkeys = '\0'; | |
491 *newckeys = '\0'; | |
492 *newbuttons = '\0'; | |
493 *newcbuttons = '\0'; | |
494 if (FirstMenu == NULL) { | |
495 if (!paradise) { /* remove the extra planet settings */ | |
496 localmes[3] = ""; | |
497 galacticmes[3] = ""; | |
498 } | |
499 MaxOptions = InitOptionMenus(); | |
500 if (MaxOptions < 0) { | |
501 fprintf(stderr, "InitOptionMenus() error %d!\n", MaxOptions); | |
502 notdone = 0; | |
503 return; | |
504 } | |
505 } | |
506 /* Create window big enough to hold option windows */ | |
507 if (optionWin == NULL) { | |
508 | |
509 optionWin = W_MakeMenu("option", WINSIDE + 10, -BORDER + 10, OPTIONLEN, | |
510 MaxOptions, baseWin, OPTIONBORDER); | |
511 CurrentMenu = FirstMenu; | |
512 | |
513 RefreshOptions(); | |
514 } | |
515 W_ResizeMenu(optionWin, OPTIONLEN, CurrentMenu->numopt); | |
516 /* Map window */ | |
517 W_MapWindow(optionWin); | |
518 } | |
519 | |
520 /* refresh all current options */ | |
521 static void | |
522 RefreshOptions() | |
523 { | |
524 int i; | |
525 struct option_menu *option; | |
526 | |
527 if (notdone == 0 || (option = CurrentMenu) == NULL) | |
528 return; | |
529 | |
530 for (i = 0; i < option->numopt; i++) { | |
531 optionrefresh(&(option->menu[i])); | |
532 } | |
533 #ifdef nodef /* if we resize, we don't need this */ | |
534 if (option->numopt < MaxOptions) | |
535 for (i = option->numopt; i < MaxOptions; i++) { | |
536 OptionClear(i); | |
537 } | |
538 #endif | |
539 } | |
540 | |
541 #ifdef nodef | |
542 /* blank out option line 'i' */ | |
543 static void | |
544 OptionClear(i) | |
545 { | |
546 char *blanktext = " "; | |
547 if (optionWin && notdone) | |
548 W_WriteText(optionWin, 0, i, textColor, blanktext, OPTIONLEN, 0); | |
549 } | |
550 #endif | |
551 | |
552 /* Redraw the specified option entry */ | |
553 void | |
554 optionredrawtarget(win) | |
555 W_Window win; | |
556 { | |
557 register struct option *op; | |
558 | |
559 #ifdef nodef | |
560 if (notdone == 0) | |
561 return; | |
562 #endif | |
563 | |
564 for (op = CurrentMenu->menu; op->op_text; op++) { | |
565 if (op->op_targetwin && win == *op->op_targetwin) { | |
566 optionrefresh(op); | |
567 break; | |
568 } | |
569 } | |
570 } | |
571 | |
572 /* Redraw the specified option option */ | |
573 void | |
574 optionredrawoption(ip) | |
575 int *ip; | |
576 { | |
577 register struct option *op; | |
578 | |
579 #ifdef nodef | |
580 if (notdone == 0) | |
581 return; | |
582 #endif | |
583 | |
584 for (op = CurrentMenu->menu; op->op_num >= 0; op++) { | |
585 if (ip == op->op_option) { | |
586 optionrefresh(op); | |
587 break; | |
588 } | |
589 } | |
590 } | |
591 | |
592 /* Refresh the option window given by the option struct */ | |
593 void | |
594 optionrefresh(op) | |
595 register struct option *op; | |
596 { | |
597 register int on; | |
598 char buf[BUFSIZ]; | |
599 | |
600 if (op == NULL || notdone == 0) | |
601 return; | |
602 | |
603 if (op->op_string) { | |
604 (void) sprintf(buf, op->op_text, op->op_string); | |
605 } else if (op->op_array) { /* Array of strings */ | |
606 strcpy(buf, op->op_array[*op->op_option]); | |
607 } else if (op->op_range) { | |
608 (void) sprintf(buf, op->op_text, *(op->op_option)); | |
609 } else { | |
610 /* Either a boolean or a window */ | |
611 if (op->op_option) | |
612 on = *op->op_option;/* use int for status */ | |
613 else if (op->op_targetwin) | |
614 on = W_IsMapped(*op->op_targetwin); /* use window for status */ | |
615 else | |
616 on = 1; /* shouldn't happen */ | |
617 | |
618 if (!on) | |
619 strcpy(buf, "Don't "); | |
620 else | |
621 buf[0] = '\0'; | |
622 strcat(buf, op->op_text); | |
623 } | |
624 | |
625 if (islower(buf[0])) | |
626 buf[0] = toupper(buf[0]); | |
627 | |
628 if (op->op_num == 0) { /* title */ | |
629 W_WriteText(optionWin, 0, op->op_num, W_Yellow, buf, strlen(buf), 0); | |
630 } else if (op->op_num == 1) { /* "click" entry */ | |
631 W_WriteText(optionWin, 0, op->op_num, W_Green, buf, strlen(buf), 0); | |
632 } else | |
633 W_WriteText(optionWin, 0, op->op_num, textColor, buf, strlen(buf), 0); | |
634 } | |
635 | |
636 /* deal with events sent to the option window */ | |
637 int | |
638 optionaction(data) | |
639 W_Event *data; | |
640 { | |
641 register struct option *op; | |
642 int i; | |
643 register char *cp; | |
644 | |
645 if (data->y >= CurrentMenu->numopt) { | |
646 W_Beep(); | |
647 return (0); | |
648 } | |
649 if (notdone == 0) | |
650 return (0); | |
651 | |
652 op = &(CurrentMenu->menu[data->y]); | |
653 | |
654 /* Update string; don't claim keystrokes for non-string options */ | |
655 /* deal with options with string input first */ | |
656 if (op->op_string == 0) { | |
657 if (data->type == W_EV_KEY) | |
658 return (0); | |
659 } else { | |
660 if (data->type == W_EV_BUTTON) | |
661 return (0); | |
662 switch (data->key) { | |
663 | |
664 case '\b': /* delete character */ | |
665 case '\177': | |
666 cp = op->op_string; | |
667 i = strlen(cp); | |
668 if (i > 0) { | |
669 cp += i - 1; | |
670 *cp = '\0'; | |
671 } | |
672 break; | |
673 | |
674 case '\027': /* word erase */ | |
675 cp = op->op_string; | |
676 i = strlen(cp); | |
677 /* back up over blanks */ | |
678 while (--i >= 0 && isspace(cp[i])); | |
679 i++; | |
680 /* back up over non-blanks */ | |
681 while (--i >= 0 && !isspace(cp[i])); | |
682 i++; | |
683 cp[i] = '\0'; | |
684 break; | |
685 | |
686 case '\025': /* kill line */ | |
687 case '\030': | |
688 op->op_string[0] = '\0'; | |
689 break; | |
690 | |
691 default: /* add character to the list */ | |
692 if (data->key < 32 || data->key > 127) | |
693 break; | |
694 cp = op->op_string; | |
695 i = strlen(cp); | |
696 if (i < (op->op_size - 1) && !iscntrl(data->key)) { | |
697 cp += i; | |
698 cp[1] = '\0'; | |
699 cp[0] = data->key; | |
700 } else | |
701 W_Beep(); | |
702 break; | |
703 } | |
704 } | |
705 | |
706 /* Toggle int, if it exists */ | |
707 if (op->op_array) { | |
708 if (data->key == W_LBUTTON) { | |
709 (*op->op_option)++; | |
710 if (*(op->op_array)[*op->op_option] == '\0') { | |
711 *op->op_option = 0; | |
712 } | |
713 } else if (data->key == W_MBUTTON) { | |
714 /* set option number to zero on the middle key to ease shutoff */ | |
715 *op->op_option = 0; | |
716 } else if (data->key == W_RBUTTON) { | |
717 /* if right button, decrease option */ | |
718 (*op->op_option)--; | |
719 /* if decreased too far, set to top option */ | |
720 if (*(op->op_option) < 0) { | |
721 *op->op_option = 0; | |
722 while (*(op->op_array)[*op->op_option] != '\0') { | |
723 (*op->op_option)++; | |
724 } | |
725 (*op->op_option)--; | |
726 } | |
727 } | |
728 if(op->op_option == &showgalactic) | |
729 redrawall=1; | |
730 } else if (op->op_range) { | |
731 if (data->key == W_RBUTTON) { | |
732 if (op->op_range->increment == -1) /* bitwise shifts by 1 */ | |
733 if (*op->op_option == 0) | |
734 (*op->op_option) = op->op_range->max_value; | |
735 else | |
736 (*op->op_option) = (*op->op_option) >> 1; | |
737 else | |
738 (*op->op_option) -= op->op_range->increment; | |
739 } else if (data->key == W_MBUTTON) { | |
740 (*op->op_option) = op->op_range->min_value; | |
741 } else if (data->key == W_LBUTTON) { | |
742 if (op->op_range->increment == -1) | |
743 if (*op->op_option == 0) | |
744 (*op->op_option) = 1; | |
745 else | |
746 (*op->op_option) = (*op->op_option) << 1; | |
747 else | |
748 (*op->op_option) += op->op_range->increment; | |
749 } | |
750 /* wrap value around within option range */ | |
751 if (*(op->op_option) > op->op_range->max_value) | |
752 *(op->op_option) = op->op_range->min_value; | |
753 if (*(op->op_option) < op->op_range->min_value) | |
754 *(op->op_option) = op->op_range->max_value; | |
755 } else if (op->op_option) { | |
756 *op->op_option = !*op->op_option; | |
757 if(op->op_option == &blk_zoom) { | |
758 if(!paradise) { | |
759 blk_zoom=0; | |
760 } else { | |
761 redrawall=1; | |
762 } | |
763 } else if((op->op_option == &blk_showStars) && !paradise) | |
764 blk_showStars = 0; | |
765 else if((op->op_option == &drawgrid) || | |
766 (op->op_option == §orNums)) | |
767 redrawall=1; | |
768 else if(op->op_option == &clearPhaserStats) { | |
769 phasFired=phasHits=totalDmg=0; | |
770 clearPhaserStats=1; | |
771 warning("Phaser statistics reset!"); | |
772 } else if(op->op_option == &reloadShipBitmaps) { | |
773 free_shipshapes(); | |
774 slurp_ship_bitmaps(); | |
775 reloadShipBitmaps = 1; | |
776 warning("Read ship bitmaps"); | |
777 } | |
778 #ifdef AMIGA | |
779 else if(op->op_option == &useWorkbench) { | |
780 switchScreen(); | |
781 } | |
782 #endif | |
783 } | |
784 /* Map/unmap window, if it exists */ | |
785 if (op->op_targetwin) { | |
786 if (W_IsMapped(*op->op_targetwin)) { | |
787 if (*op->op_targetwin == udpWin) | |
788 udpdone(); | |
789 else if (*op->op_targetwin == spWin) | |
790 spdone(); | |
791 else | |
792 W_UnmapWindow(*op->op_targetwin); | |
793 } else { | |
794 if (*op->op_targetwin == udpWin) | |
795 udpwindow(); | |
796 else if (*op->op_targetwin == spWin) | |
797 spwindow(); | |
798 #ifdef SOUND | |
799 else if (*op->op_targetwin == soundWin) | |
800 S_SoundWindow(); | |
801 #endif | |
802 else | |
803 W_MapWindow(*op->op_targetwin); | |
804 if (*op->op_targetwin == pStats) | |
805 redrawPStats(); | |
806 #ifdef XTREKRC_HELP | |
807 if (*op->op_targetwin == defWin) | |
808 showdef(); | |
809 #endif | |
810 } | |
811 } | |
812 /* deal with possible menu change */ | |
813 if (MenuPage != CurrentMenu->page_num) { | |
814 SetMenuPage(MenuPage); | |
815 RefreshOptions(); | |
816 } | |
817 if (!notdone) /* if done, that is */ | |
818 optiondone(); | |
819 else | |
820 optionrefresh(op); | |
821 | |
822 | |
823 return (1); | |
824 } | |
825 | |
826 /* | |
827 * find the menu in the menus linked list that matches the one in the * | |
828 * argument | |
829 */ | |
830 static void | |
831 SetMenuPage(pagenum) | |
832 int pagenum; | |
833 { | |
834 int i = 1; | |
835 if (FirstMenu != NULL) | |
836 for (CurrentMenu = FirstMenu; CurrentMenu->Next != NULL && | |
837 CurrentMenu->page_num != pagenum; i++, CurrentMenu = CurrentMenu->Next); | |
838 W_ResizeMenu(optionWin, OPTIONLEN, CurrentMenu->numopt); | |
839 } | |
840 | |
841 void | |
842 optiondone() | |
843 { | |
844 int shpn; | |
845 struct ship *shp; | |
846 | |
847 /* Unmap window */ | |
848 W_UnmapWindow(optionWin); | |
849 | |
850 if(remapAllShips) { | |
851 for(shpn=0;shpn<nshiptypes;shpn++) { | |
852 shp=getship(shpn); | |
853 keymapAdd(newkeys, shp->s_keymap); | |
854 ckeymapAdd(newckeys, shp->s_keymap); | |
855 buttonmapAdd(newbuttons, shp->s_buttonmap); | |
856 cbuttonmapAdd(newcbuttons, shp->s_buttonmap); | |
857 } | |
858 } else { /* only affect current ship */ | |
859 /* update keymap and buttonmap [Bdyess] */ | |
860 keymapAdd(newkeys, myship->s_keymap); | |
861 ckeymapAdd(newckeys, myship->s_keymap); | |
862 buttonmapAdd(newbuttons, myship->s_buttonmap); | |
863 cbuttonmapAdd(newcbuttons, myship->s_buttonmap); | |
864 } | |
865 | |
866 /* optionrefresh(&(option[KEYMAP])); Not sure why this is really needed */ | |
867 | |
868 sendOptionsPacket(); /* update server as to the client's options */ | |
869 | |
870 if (updateSpeed != lastUpdateSpeed) { | |
871 sendUpdatePacket(1000000 / updateSpeed); | |
872 lastUpdateSpeed = updateSpeed; | |
873 } | |
874 if (oldzoom != blk_zoom) { | |
875 redrawall = 1; | |
876 oldzoom = blk_zoom; | |
877 } | |
878 if (ping != old_ping) { | |
879 old_ping = ping; | |
880 if (ping) | |
881 startPing(); | |
882 else | |
883 stopPing(); | |
884 } | |
885 #ifdef BEEPLITE | |
886 if (DefLite) | |
887 litedefaults(); | |
888 #endif | |
889 | |
890 #ifdef ROTATERACE | |
891 if (rotate != old_rotate) { | |
892 | |
893 rotate_all(); | |
894 #if 0 | |
895 register i; | |
896 register struct planet *l; | |
897 int nplan = (paradise) ? nplanets : 40; | |
898 | |
899 redrawall = 1; | |
900 reinitPlanets = 1; | |
901 | |
902 for (i = 0, l = planets; i < nplan; i++, l++) { | |
903 if (rotate) { | |
904 rotate_deg = -old_rotate_deg + rotate * 64; | |
905 rotate_coord(&l->pl_x, &l->pl_y, rotate_deg, | |
906 blk_gwidth / 2, blk_gwidth / 2); | |
907 rotate_deg = rotate * 64; | |
908 } else { | |
909 rotate_deg = -old_rotate_deg; | |
910 rotate_coord(&l->pl_x, &l->pl_y, rotate_deg, | |
911 blk_gwidth / 2, blk_gwidth / 2); | |
912 rotate_deg = 0; | |
913 } | |
914 } | |
915 #endif | |
916 old_rotate = rotate; | |
917 old_rotate_deg = rotate_deg; | |
918 | |
919 } | |
920 #endif | |
921 } | |
922 | |
923 /* set up menus linked list */ | |
924 static int | |
925 InitOptionMenus() | |
926 { | |
927 int i = 1; | |
928 int maxopts = 0; | |
929 | |
930 IFDEBUG(printf("Adding OptionMenus\n"); | |
931 ) | |
932 /* AddOptMenu( &OptionsMenu, 0); */ | |
933 AddOptMenu(Features_Menu, 0); | |
934 AddOptMenu(Window_Menu, 0); | |
935 AddOptMenu(Display_Menu, 0); | |
936 AddOptMenu(Playerdash_Menu, 0); | |
937 #ifdef HOCKEY | |
938 AddOptMenu(Hockey_Menu, 0); | |
939 #endif /*HOCKEY*/ | |
940 #ifdef AMIGA | |
941 AddOptMenu(Amiga_Menu, 0); | |
942 #endif | |
943 /* AddOptMenu(SillyFeatures_Menu, 0); */ | |
944 /* AddOptMenu(Network_Menu, 0); */ | |
945 | |
946 for (i = 1, CurrentMenu = FirstMenu; CurrentMenu != NULL; | |
947 i++, CurrentMenu = CurrentMenu->Next) { | |
948 CurrentMenu->page_num = i; /* repage the menus.. */ | |
949 if (CurrentMenu->numopt > maxopts) | |
950 maxopts = CurrentMenu->numopt; | |
951 } | |
952 CurrentMenu = FirstMenu; | |
953 Menus_Range.max_value = i - 1; | |
954 IFDEBUG(printf("OptionMenus Added! Maxopt = %d \n", i); | |
955 ) | |
956 return maxopts; | |
957 } | |
958 | |
959 static void | |
960 AddOptMenu(NewMenu, updated) | |
961 struct option NewMenu[]; | |
962 int updated; | |
963 { | |
964 struct option_menu *menuptr; | |
965 struct option_menu *newmenu; | |
966 int i = 0; | |
967 | |
968 IFDEBUG(printf("AddOptMenu\n"); | |
969 ) | |
970 menuptr = FirstMenu; | |
971 | |
972 newmenu = (struct option_menu *) malloc(sizeof(struct option_menu)); | |
973 if (newmenu == NULL) { | |
974 perror("Malloc Error adding a menu"); | |
975 return; | |
976 } | |
977 /* add to list */ | |
978 if (FirstMenu == NULL) { | |
979 FirstMenu = newmenu; | |
980 } else { | |
981 for (i = 0, menuptr = FirstMenu; menuptr->Next != NULL; menuptr = menuptr->Next) | |
982 i++; | |
983 menuptr->Next = newmenu; | |
984 } | |
985 newmenu->page_num = i; | |
986 newmenu->Next = NULL; | |
987 newmenu->numopt = NumOptions(NewMenu); | |
988 newmenu->menu = NewMenu; | |
989 newmenu->updated = updated; | |
990 IFDEBUG(printf("Menu Added! \n", i); | |
991 ) | |
992 } | |
993 | |
994 static int | |
995 NumOptions(OpMenu) | |
996 struct option OpMenu[]; | |
997 { | |
998 int i = 0; | |
999 struct option *ptr; | |
1000 | |
1001 ptr = &OpMenu[0]; | |
1002 for (i = 0; ptr->op_num != -1 && ptr->op_option != ¬done; i++) { | |
1003 IFDEBUG(printf("Option #%d..\n", i); | |
1004 ) | |
1005 IFDEBUG(if (ptr->op_text != NULL) printf("OP_Text:%s\n", ptr->op_text); | |
1006 ) | |
1007 ptr = &OpMenu[i]; | |
1008 ptr->op_num = i; | |
1009 } | |
1010 | |
1011 IFDEBUG(printf("NumOptions in this menu: %d\n", i); | |
1012 ) | |
1013 return i; | |
1014 } | |
1015 | |
1016 /* | |
1017 * a function that could be called regularly, to deal with menus that * might | |
1018 * be updated by external events. I.e. the udp menu! | |
1019 */ | |
1020 #if 0 | |
1021 static void | |
1022 UpdateOptions() | |
1023 { | |
1024 if (notdone == 0) | |
1025 return; /* don't update if menu isn't in use */ | |
1026 if (CurrentMenu->updated) | |
1027 RefreshOptions(); | |
1028 } | |
1029 #endif /* 0 */ |