Debian Codegraph @

Descent3/ctlconfig.cpp

raw symbols SCIP
1 /*
2 * Descent 3
3 * Copyright (C) 2024 Parallax Software
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 --- HISTORICAL COMMENTS FOLLOW ---
19
20 * $Logfile: /DescentIII/main/ctlconfig.cpp $
21 * $Revision: 78 $
22 * $Date: 4/19/00 5:25p $
23 * $Author: Matt $
24 *
25 * <insert description of file here>
26 *
27 * $Log: /DescentIII/main/ctlconfig.cpp $
28 *
29 * 78 4/19/00 5:25p Matt
30 * From Duane for 1.4
31 * Several Mac config changes
32 * Fixed a bug that caused the deadzone value to be decreased each time
33 * you the config dialog was used.
34 *
35 * 77 3/20/00 12:03p Matt
36 * Merge of Duane's post-1.3 changes.
37 * Mac deadzone stuff (Mac only)
38 *
39 * 76 10/22/99 3:40p Kevin
40 * Mac merge fixes
41 *
42 * 75 10/22/99 10:50a Matt
43 * Mac merge
44 *
45 * 74 7/28/99 4:18p Kevin
46 * Macintosh!
47 *
48 * 73 7/16/99 11:16a Samir
49 * multiple hat support.
50 *
51 * 72 6/10/99 9:07p Samir
52 * fixed weapon string name localization issues.
53 *
54 * 71 5/12/99 1:18p Samir
55 * play music during game too when in menus.
56 *
57 * 70 5/06/99 1:40a Samir
58 * adjusted some text.
59 *
60 * 69 5/02/99 2:19a Samir
61 * new weapon autoselect interface (a little more like D2)
62 *
63 * 68 4/30/99 12:12p Samir
64 * added strings for key ramping, other buttons in general config menu.
65 *
66 * 67 4/29/99 2:59p Samir
67 * added help and made CTRL-C clear for controller screens.
68 *
69 * 66 4/29/99 2:18a Samir
70 * updated art for options style menu.
71 *
72 * 65 4/22/99 3:43p Kevin
73 * Training missions show controls on screen
74 *
75 * 64 4/19/99 5:09p Samir
76 * ugh, forgot to destroy revert gadget when unrealizing ui page.
77 *
78 * 63 4/18/99 4:21p Samir
79 * added restore settings for either joystick or keyboard settings.
80 *
81 * 62 4/15/99 2:55p Samir
82 * added UI for mouselook.
83 *
84 * 61 3/22/99 6:20p Jeff
85 * added 2 more audio taunts. a mulitplayer event when someone plays an
86 * audio taunt. option to disable audio taunts.
87 *
88 * 60 3/17/99 4:18p Samir
89 * added button to calibrate joystick.
90 *
91 * 59 3/05/99 2:44p Samir
92 * needs to be cleaned up later, but mouse and joystick sensitivities are
93 * read in always, and set by the controller system. A cancel method
94 * needs to be implemented for these functions.
95 *
96 * 58 3/05/99 12:24p Samir
97 * weapon select screen has more help to determine what's high and what's
98 * low.
99 *
100 * 57 3/03/99 3:41a Samir
101 * moved ok and cancel buttons in weapon_select_dialog.
102 *
103 * 56 3/02/99 1:14p Samir
104 * added joystick/mouse enable and gamma help.
105 *
106 * 55 3/01/99 8:51p Samir
107 * fixed potential crash with no forcefeedback.
108 *
109 * 54 3/01/99 8:12p Samir
110 * don;t display force feedback menu if no stick.
111 *
112 * 53 3/01/99 5:01a Samir
113 * made sure NEWUIRES_FORCEQUIT was added to all new interfaces.
114 *
115 * 52 2/28/99 3:22a Samir
116 * added rearview text.
117 *
118 * 51 2/26/99 2:13a Samir
119 * massive reorg of weapon select prec
120 *
121 * 50 2/24/99 6:21p Samir
122 * moved sensitivity sliders to config key/controller and cleaned up
123 * weapon select menu.
124 *
125 * 49 2/24/99 12:41p Samir
126 * put in weapon selection.
127 *
128 * 48 2/23/99 2:00p Samir
129 * added keyboard ramping slider.
130 *
131 * 47 2/19/99 11:07p Samir
132 * don't verify control changes if new element has a NULL controller
133 * instead of a null binding (hats can have a 'null binding' and be valid.
134 *
135 * 46 2/16/99 12:07p Samir
136 * redid controller config with new ui.
137 *
138 * 45 2/10/99 3:39p Samir
139 * table file parsing stuff
140 *
141 * 44 1/28/99 3:58p Jeff
142 * localization update
143 *
144 * 43 1/06/99 6:33p Samir
145 * more hacks for demo.
146 *
147 * 42 1/06/99 6:28p Samir
148 * demo hack for controller checkbox code not in sync with UI checkbox
149 * code.
150 *
151 * 41 12/17/98 5:59p Samir
152 * moved mouse enabled and joy enabled to config menu.
153 *
154 * 40 11/30/98 4:54p Samir
155 * added rear view config item.
156 *
157 * 39 10/22/98 10:54p Samir
158 * put mouse or joystick disabled messages if pilot disabled them, to help
159 * those configuring.
160 *
161 * 38 10/21/98 11:14a Samir
162 * added generic code to skip rendering while in game controller config or
163 * telcom.
164 *
165 * 37 10/18/98 7:24p Samir
166 * added a reset to defaults options for key and joystick config.
167 *
168 * 36 10/18/98 1:07p Samir
169 * tweaked user interface for controller config.
170 *
171 * 35 10/17/98 7:33p Samir
172 * fixed bug when initializing elements list per panel.
173 *
174 * 34 10/13/98 6:33p Samir
175 * poll mulitplayer every frame if needed in controller config screen.
176 *
177 * 33 10/07/98 6:29p Samir
178 * bail if multiplayer game ended in ui.
179 *
180 * 32 10/02/98 4:15p Samir
181 * added fancy artwork for config screens.
182 *
183 * 31 10/01/98 12:57p Samir
184 * basic weapon autoselect config working.
185 *
186 * 30 9/30/98 4:35p Samir
187 * revamped control configuration ui,
188 *
189 * 29 9/23/98 6:19p Jeff
190 * finished up (hopefully) updating the config/ui dialogs to meet our
191 * standard. Keyboard/joystick config still needs some work
192 *
193 * 28 9/17/98 3:24p Samir
194 * added headlight configuration.
195 *
196 * 27 9/10/98 12:39p Samir
197 * added senstivity issures for controller.
198 *
199 * 26 8/31/98 6:49p Jeff
200 * made inventory and countermeasure keys customizable
201 *
202 * 25 6/29/98 6:42p Samir
203 * Properly handle controller pausing and resumption.
204 *
205 * 24 6/18/98 5:49p Samir
206 * finished controller string localization minus the binding stuff.
207 *
208 * 23 6/18/98 4:48p Samir
209 * added changes for multiple configs for joystick controls.
210 *
211 * 22 6/17/98 3:27p Jeff
212 * Changes made for localization
213 *
214 * 21 6/16/98 10:38a Jeff
215 * localization, strings pulled out to stringtable.h and d3.str
216 *
217 * 20 6/05/98 5:34p Samir
218 * new config system.
219 *
220 * 19 5/19/98 3:36p Samir
221 * added automap key.
222 *
223 * 18 5/15/98 3:13p Samir
224 * added 2 key support for controller functions.
225 *
226 * 17 5/12/98 3:04p Samir
227 * added button control for pbh.
228 *
229 * 16 5/11/98 4:53p Samir
230 * added axis sliding, config.
231 *
232 * 15 5/05/98 5:15p Samir
233 * adjusted menus to work in 512x384 as well as 640x480.
234 *
235 * 14 4/24/98 2:43a Samir
236 * added ability to turn off controller.
237 *
238 * 13 4/13/98 7:01p Samir
239 * added snazzy listbox and edit box art.
240 *
241 * 12 4/08/98 3:44p Samir
242 * added toggle bank and configuration for afterburner
243 *
244 * 11 3/20/98 1:19p Jeff
245 * Changes made to use Default_pilot string for pilot filename to use.
246 *
247 * 10 3/17/98 2:36p Samir
248 * Added Macros.h
249 *
250 * 9 3/05/98 6:38p Samir
251 * Use UI_FONT now.
252 *
253 * 8 2/16/98 9:27p Samir
254 * Simple joystick configuration working.
255 *
256 * 7 2/16/98 3:02p Samir
257 * Joystick config sort of working.
258 *
259 * 6 2/15/98 7:06p Samir
260 * Keyboard configuration system done. Not joystick.
261 *
262 * 5 2/13/98 7:10p Samir
263 * Fixed prob when pressing ALT (since it set a bit in the return key
264 * value that's greater that 256)
265 *
266 * 4 2/13/98 6:37p Samir
267 * Simple keyboard configuration.
268 *
269 * 3 2/10/98 4:55p Samir
270 * Added rudimentary items for controller config.
271 *
272 * 2 2/10/98 3:45p Samir
273 * Added list of configuration items.
274 *
275 * 1 2/10/98 11:49a Samir
276 * Initial revision.
277 *
278 * $NoKeywords: $
279 */
280 #include "ctlconfig.h"
281 #include "CtlCfgElem.h"
282 #include "ctlconfigtxt.h"
283 #include "game.h"
284 #include "weapon.h"
285 #include "pilot.h"
286 #include "bitmap.h"
287 #include "multi.h"
288 #include "gameloop.h"
289 #include "gamefont.h"
290 #include "D3ForceFeedback.h"
291 #include "hlsoundlib.h"
292 #include "ddio.h"
293 #include <string.h>
294 //////////////////////////////////////////////////////////////////////////////
295 #define IDV_KCONFIG 10
296 #define IDV_CCONFIG 11
297 #define IDV_WPNSEL 17
298 #define IDV_OPTIONS 18
299
300 // used for adjusting settings.
301 #define CFG_AXIS_SENS_RANGE 20
302 const int16_t UID_JOYCFG = 0x1000;
303
304
305 // Setup of config screens.
306 #define CCITEM_WPN_X 0
307 #define CCITEM_WPN_Y 20
308 #define CCITEM_AUX_X 0
309 #define CCITEM_AUX_Y 160
310 #define CCITEM_THRUST_X 295
311 #define CCITEM_THRUST_Y 20
312 #define CCITEM_ROT_X 295
313 #define CCITEM_ROT_Y 160
314 t_cfg_element Cfg_key_elements[] = {
315 // column1 -indices 0-15
316 {-1, CtlText_WeaponGroup, CCITEM_WPN_X, CCITEM_WPN_Y},
317 {ctfFIREPRIMARY_KEY, CtlText_FirePrimary, 0, 0},
318 {ctfFIRESECONDARY_KEY, CtlText_FireSecondary, 0, 0},
319 {ctfFIREFLARE_KEY, CtlText_FireFlare, 0, 0},
320 {ctfWPNSEL_PCYCLEKEY, CtlText_WpnCycP, 0, 0},
321 {ctfWPNSEL_SCYCLEKEY, CtlText_WpnCycS, 0, 0},
322 {-1, CtlText_MiscGroup, CCITEM_AUX_X, CCITEM_AUX_Y},
323 {ctfHEADLIGHT_KEY, CtlText_Headlight, 0, 0},
324 {ctfREARVIEW_KEY, CtlText_Rearview, 0, 0},
325 {ctfAUTOMAP_KEY, CtlText_Automap, 0, 0},
326 {ctfPREV_INVKEY, CtlText_PrevInv, 0, 0},
327 {ctfNEXT_INVKEY, CtlText_NextInv, 0, 0},
328 {ctfINV_USEKEY, CtlText_InvUse, 0, 0},
329 {ctfPREV_CNTMSKEY, CtlText_PrevCntMs, 0, 0},
330 {ctfNEXT_CNTMSKEY, CtlText_NextCntMs, 0, 0},
331 {ctfCNTMS_USEKEY, CtlText_CntMsUse, 0, 0},
332 {ctfAUDIOTAUNT1_KEY, CtlText_AudioTaunt1, 0, 0},
333 {ctfAUDIOTAUNT2_KEY, CtlText_AudioTaunt2, 0, 0},
334 {ctfAUDIOTAUNT3_KEY, CtlText_AudioTaunt3, 0, 0},
335 {ctfAUDIOTAUNT4_KEY, CtlText_AudioTaunt4, 0, 0},
336 {-1, CtlText_ThrustGroup, CCITEM_THRUST_X, CCITEM_THRUST_Y},
337 {ctfFORWARD_THRUSTKEY, CtlText_Accelerate, 0, 0},
338 {ctfREVERSE_THRUSTKEY, CtlText_Reverse, 0, 0},
339 {ctfAFTERBURN_KEY, CtlText_Afterburn, 0, 0},
340 {ctfTOGGLE_SLIDEKEY, CtlText_ToggleSlide, 0, 0},
341 {ctfLEFT_THRUSTKEY, CtlText_SlideLeft, 0, 0},
342 {ctfRIGHT_THRUSTKEY, CtlText_SlideRight, 0, 0},
343 {ctfUP_THRUSTKEY, CtlText_SlideUp, 0, 0},
344 {ctfDOWN_THRUSTKEY, CtlText_SlideDown, 0, 0},
345 {-1, CtlText_TurningGroup, CCITEM_ROT_X, CCITEM_ROT_Y},
346 {ctfPITCH_UPKEY, CtlText_PitchUp, 0, 0},
347 {ctfPITCH_DOWNKEY, CtlText_PitchDown, 0, 0},
348 {ctfHEADING_LEFTKEY, CtlText_TurnLeft, 0, 0},
349 {ctfHEADING_RIGHTKEY, CtlText_TurnRight, 0, 0},
350 {ctfTOGGLE_BANKKEY, CtlText_ToggleBank, 0, 0},
351 {ctfBANK_LEFTKEY, CtlText_BankLeft, 0, 0},
352 {ctfBANK_RIGHTKEY, CtlText_BankRight, 0, 0}};
353 #define CCITEM_WPN_X2 0
354 #define CCITEM_WPN_Y2 20
355 #define CCITEM_AUX_X2 0
356 #define CCITEM_AUX_Y2 160
357 #define CCITEM_THRUST_X2 295
358 #define CCITEM_THRUST_Y2 20
359 #define CCITEM_ROT_X2 295
360 #define CCITEM_ROT_Y2 200
361 t_cfg_element Cfg_joy_elements[] = {{-1, CtlText_WeaponGroup, CCITEM_WPN_X2, CCITEM_WPN_Y2},
362 {ctfFIREPRIMARY_BUTTON, CtlText_FirePrimary, 0, 0},
363 {ctfFIRESECONDARY_BUTTON, CtlText_FireSecondary, 0, 0},
364 {ctfFIREFLARE_BUTTON, CtlText_FireFlare, 0, 0},
365 {ctfWPNSEL_PCYCLEBTN, CtlText_WpnCycP, 0, 0},
366 {ctfWPNSEL_SCYCLEBTN, CtlText_WpnCycS, 0, 0},
367 {-1, CtlText_MiscGroup, CCITEM_AUX_X2, CCITEM_AUX_Y2},
368 {ctfHEADLIGHT_BUTTON, CtlText_Headlight, 0, 0},
369 {ctfREARVIEW_BTN, CtlText_Rearview, 0, 0},
370 {ctfAUTOMAP_BUTTON, CtlText_Automap, 0, 0},
371 {ctfPREV_INVBTN, CtlText_PrevInv, 0, 0},
372 {ctfNEXT_INVBTN, CtlText_NextInv, 0, 0},
373 {ctfINV_USEBTN, CtlText_InvUse, 0, 0},
374 {ctfPREV_CNTMSBTN, CtlText_PrevCntMs, 0, 0},
375 {ctfNEXT_CNTMSBTN, CtlText_NextCntMs, 0, 0},
376 {ctfCNTMS_USEBTN, CtlText_CntMsUse, 0, 0},
377 {ctfAUDIOTAUNT1_BTN, CtlText_AudioTaunt1, 0, 0},
378 {ctfAUDIOTAUNT2_BTN, CtlText_AudioTaunt2, 0, 0},
379 {ctfAUDIOTAUNT3_BTN, CtlText_AudioTaunt3, 0, 0},
380 {ctfAUDIOTAUNT4_BTN, CtlText_AudioTaunt4, 0, 0},
381 {-1, CtlText_ThrustGroup, CCITEM_THRUST_X2, CCITEM_THRUST_Y2},
382 {ctfFORWARD_THRUSTAXIS, CtlText_Forward, 0, 0},
383 {ctfFORWARD_BUTTON, CtlText_Accelerate, 0, 0},
384 {ctfREVERSE_BUTTON, CtlText_Reverse, 0, 0},
385 {ctfAFTERBURN_BUTTON, CtlText_Afterburn, 0, 0},
386 {ctfUP_THRUSTAXIS, CtlText_SlideVert, 0, 0},
387 {ctfRIGHT_THRUSTAXIS, CtlText_SlideHoriz, 0, 0},
388 {ctfTOGGLE_SLIDEBUTTON, CtlText_ToggleSlide, 0, 0},
389 {ctfUP_BUTTON, CtlText_SlideUp, 0, 0},
390 {ctfDOWN_BUTTON, CtlText_SlideDown, 0, 0},
391 {ctfLEFT_BUTTON, CtlText_SlideLeft, 0, 0},
392 {ctfRIGHT_BUTTON, CtlText_SlideRight, 0, 0},
393 {-1, CtlText_TurningGroup, CCITEM_ROT_X2, CCITEM_ROT_Y2},
394 {ctfPITCH_DOWNAXIS, CtlText_Pitch, 0, 0},
395 {ctfPITCH_UPBUTTON, CtlText_PitchUp, 0, 0},
396 {ctfPITCH_DOWNBUTTON, CtlText_PitchDown, 0, 0},
397 {ctfHEADING_RIGHTAXIS, CtlText_Heading, 0, 0},
398 {ctfHEADING_LEFTBUTTON, CtlText_TurnLeft, 0, 0},
399 {ctfHEADING_RIGHTBUTTON, CtlText_TurnRight, 0, 0},
400 {ctfBANK_RIGHTAXIS, CtlText_Bank, 0, 0},
401 {ctfTOGGLE_BANKBUTTON, CtlText_ToggleBank, 0, 0},
402 {ctfBANK_LEFTBUTTON, CtlText_BankLeft, 0, 0},
403 {ctfBANK_RIGHTBUTTON, CtlText_BankRight, 0, 0}};
404 #define N_JOY_CFG_FN (sizeof(Cfg_joy_elements) / sizeof(t_cfg_element))
405 #define N_KEY_CFG_FN (sizeof(Cfg_key_elements) / sizeof(t_cfg_element))
406 static void ctl_cfg_set_and_verify_changes(int16_t fnid, ct_type elem_type, uint8_t controller, uint8_t elem, int8_t slot);
407 static void ctl_cfg_element_options_dialog(int16_t fnid);
408 // used for adjusting settings.
409 static int weapon_select_dialog(int wpn, bool is_secondary);
410 #define UID_KEYCFG_ID 0x1000
411 #define UID_JOYCFG_ID 0x1100
412 #define UID_PRIMARY_WPN 0x1200
413 #define UID_PRIMARY_DIS 0x1220
414 #define UID_SECONDARY_WPN 0x1300
415 #define UID_SECONDARY_DIS 0x1320
416 #define UID_WPNLIST 0x1400
417 #define UID_RESETDEFAULTS 0x2000
418 #define UID_CFGSETTINGS 0x2001
419 #define UID_CLEAR_SLOT 0x2002
420 #define UID_REVERT 0x2003
421 //////////////////////////////////////////////////////////////////////////////
422 //
423 class cfg_screen {
424 protected:
425 newuiSheet *m_sheet;
426 newuiLargeMenu *m_menu;
427
428 public:
429 virtual void setup(newuiLargeMenu *menu) = 0;
430 virtual void finish() = 0;
431 virtual void realize() = 0;
432 virtual void unrealize() = 0;
433 virtual void process(int res){};
434 };
435 //////////////////////////////////////////////////////////////////////////////
436 // KEY CONFIG
437 #define KEYCFG_EXTRAS_X 0
438 #define KEYCFG_EXTRAS_Y 4
439 #define KEYCFG_EXTRAS_W 160
440 class key_cfg_screen : public cfg_screen {
441 cfg_element m_elem[N_KEY_CFG_FN];
442 newuiButton m_reset_btn;
443 newuiButton m_key_settings;
444 newuiButton m_revert_btn;
445 UIText m_help1_txt;
446 UIText m_help2_txt;
447 cntrldata m_old_controls[N_KEY_CFG_FN];
448
449 public:
450 virtual void setup(newuiLargeMenu *menu);
451 virtual void finish();
452 virtual void process(int res);
453 virtual void realize();
454 virtual void unrealize();
455 };
456 void key_cfg_screen::setup(newuiLargeMenu *menu) {
457 int i;
458 m_menu = menu;
459 m_sheet = menu->AddOption(IDV_KCONFIG, TXT_OPTCUSTKEYB);
460 // save original settings.
461 for (i = 0; i < N_KEY_CFG_FN; i++) {
462 Controller->get_controller_function(Cfg_key_elements[i].fn_id, m_old_controls[i].type, &m_old_controls[i].value,
463 m_old_controls[i].flags);
464 }
465 }
466 void key_cfg_screen::finish() {}
467 void key_cfg_screen::process(int res) {
468 int i;
469 for (i = 0; i < N_KEY_CFG_FN; i++) {
470 if (m_elem[i].GetID() != -1 && m_elem[i].GetID() == res) {
471 // we chose a slot to configure.
472 uint8_t elem, controller;
473 int8_t slot;
474 ct_type elem_type;
475 if (m_elem[i].GetActiveSlot() == CFGELEM_SLOT_CLEAR) {
476 ctl_cfg_element_options_dialog((int16_t)(res - UID_KEYCFG_ID));
477 } else if (m_elem[i].Configure(&elem_type, &controller, &elem, &slot)) {
478 ctl_cfg_set_and_verify_changes((int16_t)(res - UID_KEYCFG_ID), elem_type, controller, elem, slot);
479 }
480 break;
481 }
482 }
483 switch (res) {
484 case UID_RESETDEFAULTS:
485 for (i = 0; i < NUM_CONTROLLER_FUNCTIONS; i++) {
486 if (Controller_needs[i].ctype[0] == ctKey) {
487 ASSERT(Controller_needs[i].ctype[1] == ctKey);
488 Controller->assign_function(&Controller_needs[i]);
489 }
490 }
491 break;
492 case UID_CFGSETTINGS:
493 key_settings_dialog();
494 break;
495 case UID_REVERT:
496 // restore original settings.
497 for (i = 0; i < N_KEY_CFG_FN; i++) {
498 Controller->set_controller_function(Cfg_key_elements[i].fn_id, m_old_controls[i].type, m_old_controls[i].value,
499 m_old_controls[i].flags);
500 }
501 break;
502 }
503 }
504 void key_cfg_screen::realize() {
505 // create controls
506 int i, x = 0, y;
507 t_cfg_element *cfg_elem = &Cfg_key_elements[0];
508 m_reset_btn.Create(m_menu, UID_RESETDEFAULTS, TXT_RESETTODEFAULT, KEYCFG_EXTRAS_X + m_sheet->X(),
509 KEYCFG_EXTRAS_Y + m_sheet->Y(), NEWUI_BTNF_LONG);
510 m_key_settings.Create(m_menu, UID_CFGSETTINGS, TXT_ADJUSTSETTINGS, KEYCFG_EXTRAS_X + m_sheet->X() + KEYCFG_EXTRAS_W,
511 KEYCFG_EXTRAS_Y + m_sheet->Y(), NEWUI_BTNF_LONG);
512 m_revert_btn.Create(m_menu, UID_REVERT, TXT_REVERTCONTROLS, KEYCFG_EXTRAS_X + m_sheet->X() + KEYCFG_EXTRAS_W * 2,
513 KEYCFG_EXTRAS_Y + m_sheet->Y(), NEWUI_BTNF_LONG);
514 UITextItem itemHelpF1{MONITOR9_NEWUI_FONT, TXT_KEYCFGSCREENHELP1, NEWUI_MONITORFONT_COLOR};
515 m_help1_txt.Create(m_menu, &itemHelpF1, 280, 30);
516 UITextItem itemHelp{MONITOR9_NEWUI_FONT, TXT_CFGSCREENHELP, NEWUI_MONITORFONT_COLOR};
517 m_help2_txt.Create(m_menu, &itemHelp, 280, 40);
518 for (i = 0; i < N_KEY_CFG_FN; i++) {
519 if (cfg_elem->fn_id == -1) {
520 x = cfg_elem->x + m_sheet->X();
521 y = cfg_elem->y + m_sheet->Y();
522 }
523 m_elem[i].Create(m_menu, cfg_elem->text, x, y, cfg_elem->fn_id,
524 (cfg_elem->fn_id == -1) ? -1 : UID_KEYCFG_ID + cfg_elem->fn_id);
525 y += m_elem[i].H() + 2;
526 cfg_elem++;
527 }
528 }
529 void key_cfg_screen::unrealize() {
530 // create controls
531 int i;
532 t_cfg_element *cfg_elem = &Cfg_key_elements[0];
533 m_help2_txt.Destroy();
534 m_help1_txt.Destroy();
535 m_key_settings.Destroy();
536 m_reset_btn.Destroy();
537 m_revert_btn.Destroy();
538 for (i = 0; i < N_KEY_CFG_FN; i++) {
539 m_elem[i].Destroy();
540 cfg_elem++;
541 }
542 }
543 //////////////////////////////////////////////////////////////////////////////
544 // JOY CONFIG
545 class joy_cfg_screen : public cfg_screen {
546 cfg_element m_elem[N_JOY_CFG_FN];
547 newuiButton m_reset_btn;
548 newuiButton m_controller_settings;
549 newuiButton m_revert_btn;
550 cntrldata m_old_controls[N_JOY_CFG_FN];
551 UIText m_help1_txt;
552 UIText m_help2_txt;
553
554 public:
555 virtual void setup(newuiLargeMenu *menu);
556 virtual void finish();
557 virtual void process(int res);
558 virtual void realize();
559 virtual void unrealize();
560 };
561 // setup user interfaces for each screen.
562 void joy_cfg_screen::setup(newuiLargeMenu *menu) {
563 int i;
564 m_menu = menu;
565 m_sheet = menu->AddOption(IDV_CCONFIG, TXT_OPTCUSTCONT);
566
567 // save original settings.
568 for (i = 0; i < N_JOY_CFG_FN; i++) {
569 Controller->get_controller_function(Cfg_joy_elements[i].fn_id, m_old_controls[i].type, &m_old_controls[i].value,
570 m_old_controls[i].flags);
571 }
572 }
573 void joy_cfg_screen::finish() {}
574 void joy_cfg_screen::process(int res) {
575 int i;
576
577 for (i = 0; i < N_JOY_CFG_FN; i++) {
578 if (m_elem[i].GetID() != -1 && m_elem[i].GetID() == res) {
579 // we chose a slot to configure.
580 uint8_t elem, controller;
581 int8_t slot;
582 ct_type elem_type;
583 if (m_elem[i].GetActiveSlot() == CFGELEM_SLOT_CLEAR) {
584 ctl_cfg_element_options_dialog((int16_t)(res - UID_JOYCFG_ID));
585 } else if (m_elem[i].Configure(&elem_type, &controller, &elem, &slot)) {
586 ctl_cfg_set_and_verify_changes((int16_t)(res - UID_JOYCFG_ID), elem_type, controller, elem, slot);
587 }
588 break;
589 }
590 }
591 switch (res) {
592 case UID_RESETDEFAULTS:
593 for (i = 0; i < NUM_CONTROLLER_FUNCTIONS; i++) {
594 if (Controller_needs[i].ctype[0] != ctKey) {
595 ASSERT(Controller_needs[i].ctype[1] != ctKey);
596 Controller->assign_function(&Controller_needs[i]);
597 }
598 }
599 break;
600 case UID_CFGSETTINGS:
601 joystick_settings_dialog();
602 break;
603 case UID_REVERT:
604 // restore original settings.
605 for (i = 0; i < N_KEY_CFG_FN; i++) {
606 Controller->set_controller_function(Cfg_joy_elements[i].fn_id, m_old_controls[i].type, m_old_controls[i].value,
607 m_old_controls[i].flags);
608 }
609 break;
610 }
611 }
612
613 void joy_cfg_screen::realize() {
614 int i, x = 0, y;
615 t_cfg_element *cfg_elem = &Cfg_joy_elements[0];
616 m_reset_btn.Create(m_menu, UID_RESETDEFAULTS, TXT_RESETTODEFAULT, KEYCFG_EXTRAS_X + m_sheet->X(),
617 KEYCFG_EXTRAS_Y + m_sheet->Y(), NEWUI_BTNF_LONG);
618 m_controller_settings.Create(m_menu, UID_CFGSETTINGS, TXT_ADJUSTSETTINGS,
619 KEYCFG_EXTRAS_X + m_sheet->X() + KEYCFG_EXTRAS_W, KEYCFG_EXTRAS_Y + m_sheet->Y(),
620 NEWUI_BTNF_LONG);
621 m_revert_btn.Create(m_menu, UID_REVERT, TXT_REVERTCONTROLS, KEYCFG_EXTRAS_X + m_sheet->X() + KEYCFG_EXTRAS_W * 2,
622 KEYCFG_EXTRAS_Y + m_sheet->Y(), NEWUI_BTNF_LONG);
623 UITextItem itemHelpF1{MONITOR9_NEWUI_FONT, TXT_JOYCFGSCREENHELP1, NEWUI_MONITORFONT_COLOR};
624 m_help1_txt.Create(m_menu, &itemHelpF1, 280, 30);
625 UITextItem itemHelp{MONITOR9_NEWUI_FONT, TXT_CFGSCREENHELP, NEWUI_MONITORFONT_COLOR};
626 m_help2_txt.Create(m_menu, &itemHelp, 280, 40);
627 for (i = 0; i < N_JOY_CFG_FN; i++) {
628 if (cfg_elem->fn_id == -1) {
629 x = cfg_elem->x + m_sheet->X();
630 y = cfg_elem->y + m_sheet->Y();
631 }
632 m_elem[i].Create(m_menu, cfg_elem->text, x, y, cfg_elem->fn_id,
633 (cfg_elem->fn_id == -1) ? -1 : UID_JOYCFG_ID + cfg_elem->fn_id);
634 y += m_elem[i].H() + 2;
635 cfg_elem++;
636 }
637 }
638 void joy_cfg_screen::unrealize() {
639 // create controls
640 int i;
641
642 m_controller_settings.Destroy();
643 t_cfg_element *cfg_elem = &Cfg_joy_elements[0];
644 for (i = 0; i < N_JOY_CFG_FN; i++) {
645 m_elem[i].Destroy();
646 cfg_elem++;
647 }
648 m_help2_txt.Destroy();
649 m_help1_txt.Destroy();
650 m_reset_btn.Destroy();
651 m_revert_btn.Destroy();
652 }
653 //////////////////////////////////////////////////////////////////////////////
654 // WEAPON SEL CONFIG
655 #define WPNSEL_PRIMARY_X 70
656 #define WPNSEL_PRIMARY_Y 170
657 #define WPNSEL_SECONDARY_X 340
658 #define WPNSEL_SECONDARY_Y 170
659 extern float Key_ramp_speed;
660 class wpnsel_cfg_screen : public cfg_screen {
661 UIText m_primary_title;
662 UIText m_primary_low;
663 UIText m_primary_high;
664 newuiTinyButton m_primary_disables[MAX_PRIMARY_WEAPONS];
665 newuiButton m_primary_buttons[MAX_PRIMARY_WEAPONS];
666 UIText m_secondary_title;
667 UIText m_secondary_low;
668 UIText m_secondary_high;
669 newuiTinyButton m_secondary_disables[MAX_SECONDARY_WEAPONS];
670 newuiButton m_secondary_buttons[MAX_SECONDARY_WEAPONS];
671 UIText m_weapon_choose;
672 newuiButton m_reset_btn;
673 int m_selection_status; // -1 = no selection, 0 = primary, 1 = secondary
674 int m_switch_slot;
675
676 public:
677 virtual void setup(newuiLargeMenu *menu);
678 virtual void finish();
679 virtual void process(int res);
680 virtual void realize();
681 virtual void unrealize();
682 };
683 void wpnsel_cfg_screen::setup(newuiLargeMenu *menu) {
684 m_menu = menu;
685 m_sheet = menu->AddOption(IDV_WPNSEL, TXT_WPNSELPREC);
686 m_sheet->NewGroup(NULL, 0, 20);
687 m_sheet->AddText(TXT_WPNCFGHELP0);
688 m_sheet->AddText(TXT_WPNCFGHELP1);
689 m_selection_status = -1;
690 m_switch_slot = -1;
691 }
692 void wpnsel_cfg_screen::finish() {}
693 void wpnsel_cfg_screen::process(int res) {
694 int slot, i;
695 bool is_secondary = false, do_swap_ui = false, do_disable_ui = false, update_buttons = false;
696 mprintf(0, "res=%d\n", res);
697 if (m_selection_status == -1) {
698 if (res == UID_RESETDEFAULTS) {
699 for (i = 0; i < MAX_PRIMARY_WEAPONS; i++)
700 SetAutoSelectPrimaryWpnIdx(i, DefaultPrimarySelectList[i]);
701 for (i = 0; i < MAX_SECONDARY_WEAPONS; i++)
702 SetAutoSelectSecondaryWpnIdx(i, DefaultSecondarySelectList[i]);
703 update_buttons = true;
704 } else if (res == UID_CLEAR_SLOT) {
705 // figure out id of current gadget highlighted.
706 UIGadget *gadget = m_menu->GetFocus();
707 if (gadget) {
708 // below code will then determine the correct information.
709 res = gadget->GetID();
710 do_disable_ui = true;
711 }
712 }
713 }
714 slot = -1;
715 if (res >= UID_PRIMARY_WPN && res < (UID_PRIMARY_WPN + MAX_PRIMARY_WEAPONS) && m_selection_status != 1) {
716 slot = res - UID_PRIMARY_WPN;
717 is_secondary = false;
718 if (!do_disable_ui)
719 do_swap_ui = true;
720 } else if (res >= UID_SECONDARY_WPN && res < (UID_SECONDARY_WPN + MAX_SECONDARY_WEAPONS) && m_selection_status != 0) {
721 slot = res - UID_SECONDARY_WPN;
722 is_secondary = true;
723 if (!do_disable_ui)
724 do_swap_ui = true;
725 } else if (res >= UID_PRIMARY_DIS && res < (UID_PRIMARY_DIS + MAX_PRIMARY_WEAPONS) && m_selection_status == -1) {
726 slot = res - UID_PRIMARY_DIS;
727 is_secondary = false;
728 do_disable_ui = true;
729 } else if (res >= UID_SECONDARY_DIS && res < (UID_SECONDARY_DIS + MAX_SECONDARY_WEAPONS) &&
730 m_selection_status == -1) {
731 slot = res - UID_SECONDARY_DIS;
732 is_secondary = true;
733 do_disable_ui = true;
734 }
735 mprintf(0, "slot=%d\n", slot);
736
737 // do different uis
738 if (do_disable_ui) {
739 ASSERT(m_selection_status == -1 && slot != -1);
740 uint16_t wpnidx = is_secondary ? GetAutoSelectSecondaryWpnIdx(slot) : GetAutoSelectPrimaryWpnIdx(slot);
741 wpnidx = wpnidx ^ WPNSEL_SKIP;
742 if (is_secondary) {
743 SetAutoSelectSecondaryWpnIdx(slot, wpnidx);
744 } else {
745 SetAutoSelectPrimaryWpnIdx(slot, wpnidx);
746 }
747 update_buttons = true;
748 }
749 // here we see if we are selecting a weapon to switch with another, if one is already selected, we
750 // see if the user has selected another (in the same category)
751 //
752 else if (do_swap_ui) {
753 uint16_t wpnidx;
754 if (slot != -1) {
755 if (m_selection_status == -1) {
756 m_switch_slot = slot;
757 m_selection_status = is_secondary ? 1 : 0;
758 // disable proper controls here.
759 for (i = 0; i < MAX_PRIMARY_WEAPONS; i++) {
760 if (m_selection_status == 1) {
761 m_primary_disables[i].Disable();
762 m_primary_buttons[i].Disable();
763 } else {
764 m_secondary_disables[i].Disable();
765 m_secondary_buttons[i].Disable();
766 }
767 }
768 if (!m_weapon_choose.IsCreated()) {
769 UIGadget *focused_gadget = m_menu->GetFocus();
770 UITextItem item{MONITOR9_NEWUI_FONT, TXT_WPNCFGHELP2, GR_RGB(240, 240, 0)};
771 m_weapon_choose.Create(m_menu, &item, WPNSEL_PRIMARY_X, WPNSEL_PRIMARY_Y - 48);
772 if (focused_gadget)
773 m_menu->SetFocusOnGadget(focused_gadget);
774 }
775 } else {
776 int slot_idx = m_switch_slot;
777 uint16_t new_wpnidx =
778 is_secondary ? GetAutoSelectSecondaryWpnIdx(m_switch_slot) : GetAutoSelectPrimaryWpnIdx(m_switch_slot);
779
780 ASSERT(m_switch_slot != -1);
781 if (slot > m_switch_slot) {
782 new_wpnidx =
783 is_secondary ? GetAutoSelectSecondaryWpnIdx(m_switch_slot) : GetAutoSelectPrimaryWpnIdx(m_switch_slot);
784 while (slot_idx < slot) {
785 if (is_secondary) {
786 wpnidx = GetAutoSelectSecondaryWpnIdx(slot_idx + 1);
787 SetAutoSelectSecondaryWpnIdx(slot_idx, wpnidx);
788 } else {
789 wpnidx = GetAutoSelectPrimaryWpnIdx(slot_idx + 1);
790 SetAutoSelectPrimaryWpnIdx(slot_idx, wpnidx);
791 }
792 slot_idx++;
793 }
794 update_buttons = true;
795 } else if (slot < m_switch_slot) {
796 while (slot_idx > slot) {
797 if (is_secondary) {
798 wpnidx = GetAutoSelectSecondaryWpnIdx(slot_idx - 1);
799 SetAutoSelectSecondaryWpnIdx(slot_idx, wpnidx);
800 } else {
801 wpnidx = GetAutoSelectPrimaryWpnIdx(slot_idx - 1);
802 SetAutoSelectPrimaryWpnIdx(slot_idx, wpnidx);
803 }
804 slot_idx--;
805 }
806 update_buttons = true;
807 }
808 if (is_secondary) {
809 SetAutoSelectSecondaryWpnIdx(slot, new_wpnidx);
810 } else {
811 SetAutoSelectPrimaryWpnIdx(slot, new_wpnidx);
812 }
813 m_selection_status = -1;
814 m_switch_slot = -1;
815 if (m_weapon_choose.IsCreated()) {
816 m_weapon_choose.Destroy();
817 }
818 }
819 }
820 }
821 // if above actions modified buttons, refresh em.
822 if (update_buttons) {
823 wpnsel_cfg_screen::unrealize();
824 wpnsel_cfg_screen::realize();
825 }
826 }
827 void wpnsel_cfg_screen::realize() {
828 int i;
829 // make sure and reset these here.
830 m_selection_status = -1;
831 m_switch_slot = -1;
832
833 m_reset_btn.Create(m_menu, UID_RESETDEFAULTS, TXT_RESETTODEFAULT, KEYCFG_EXTRAS_X + m_sheet->X(),
834 KEYCFG_EXTRAS_Y + m_sheet->Y(), NEWUI_BTNF_LONG);
835 UITextItem itemPrimaryTitle{MONITOR9_NEWUI_FONT, TXT_PRIMARY};
836 m_primary_title.Create(m_menu, &itemPrimaryTitle, WPNSEL_PRIMARY_X, WPNSEL_PRIMARY_Y - 28);
837 UITextItem itemSecondaryTitle{MONITOR9_NEWUI_FONT, TXT_SECONDARY};
838 m_secondary_title.Create(m_menu, &itemSecondaryTitle, WPNSEL_SECONDARY_X, WPNSEL_SECONDARY_Y - 28);
839 UITextItem itemLowPriorityTitle{MONITOR9_NEWUI_FONT, TXT_LOWPRIORITY};
840 m_primary_low.Create(m_menu, &itemLowPriorityTitle, WPNSEL_PRIMARY_X, WPNSEL_SECONDARY_Y - 11);
841 m_secondary_low.Create(m_menu, &itemLowPriorityTitle, WPNSEL_SECONDARY_X, WPNSEL_SECONDARY_Y - 11);
842 for (i = 0; i < MAX_PRIMARY_WEAPONS; i++) {
843 int wpnidx;
844 char str[64];
845 wpnidx = GetAutoSelectPrimaryWpnIdx(i);
846 if (wpnidx != WPNSEL_INVALID) {
847 if (wpnidx & WPNSEL_SKIP) {
848 wpnidx &= (~WPNSEL_SKIP);
849 snprintf(str, sizeof(str), TXT_WPNSELBTN, TXT(Static_weapon_names_msg[wpnidx]));
850 } else {
851 snprintf(str, sizeof(str), "%s", TXT(Static_weapon_names_msg[wpnidx]));
852 }
853 m_primary_disables[i].Create(m_menu, UID_PRIMARY_DIS + i, "X", WPNSEL_PRIMARY_X, WPNSEL_PRIMARY_Y + i * 12);
854 m_primary_buttons[i].Create(m_menu, UID_PRIMARY_WPN + i, str, WPNSEL_PRIMARY_X + 28, WPNSEL_PRIMARY_Y + i * 12,
855 NEWUI_BTNF_LONG);
856 }
857 wpnidx = GetAutoSelectSecondaryWpnIdx(i);
858 if (wpnidx != WPNSEL_INVALID) {
859 if (wpnidx & WPNSEL_SKIP) {
860 wpnidx &= (~WPNSEL_SKIP);
861 snprintf(str, sizeof(str), TXT_WPNSELBTN, TXT(Static_weapon_names_msg[wpnidx]));
862 } else {
863 snprintf(str, sizeof(str), "%s", TXT(Static_weapon_names_msg[wpnidx]));
864 }
865 m_secondary_disables[i].Create(m_menu, UID_SECONDARY_DIS + i, "X", WPNSEL_SECONDARY_X,
866 WPNSEL_SECONDARY_Y + i * 12);
867 m_secondary_buttons[i].Create(m_menu, UID_SECONDARY_WPN + i, str, WPNSEL_SECONDARY_X + 28,
868 WPNSEL_SECONDARY_Y + i * 12, NEWUI_BTNF_LONG);
869 }
870 }
871 UITextItem itemHighPriority{MONITOR9_NEWUI_FONT, TXT_HIGHPRIORITY};
872 m_primary_high.Create(m_menu, &itemHighPriority, WPNSEL_PRIMARY_X, WPNSEL_PRIMARY_Y + i * 12 + 2);
873 m_secondary_high.Create(m_menu, &itemHighPriority, WPNSEL_SECONDARY_X, WPNSEL_SECONDARY_Y + i * 12 + 2);
874 // add accelerator keys
875 m_menu->AddAcceleratorKey(KEY_CTRLED + KEY_C, UID_CLEAR_SLOT);
876 }
877 void wpnsel_cfg_screen::unrealize() {
878 int i;
879 m_menu->ResetAcceleratorKey();
880 if (m_weapon_choose.IsCreated()) {
881 m_weapon_choose.Destroy();
882 }
883 for (i = 0; i < MAX_PRIMARY_WEAPONS; i++) {
884 m_primary_buttons[i].Destroy();
885 m_primary_disables[i].Destroy();
886 m_secondary_buttons[i].Destroy();
887 m_secondary_disables[i].Destroy();
888 }
889 m_secondary_high.Destroy();
890 m_primary_high.Destroy();
891
892 m_secondary_low.Destroy();
893 m_primary_low.Destroy();
894 m_secondary_title.Destroy();
895 m_primary_title.Destroy();
896
897 m_reset_btn.Destroy();
898 }
899 //////////////////////////////////////////////////////////////////////////////
900 // this will take out any repeats of element and slot in function id.
901 void ctl_cfg_set_and_verify_changes(int16_t fnid, ct_type elem_type, uint8_t ctrl, uint8_t elem, int8_t slot) {
902 ct_type ctype_fn[CTLBINDS_PER_FUNC];
903 uint8_t cfgflags_fn[CTLBINDS_PER_FUNC];
904 ct_config_data ccfgdata_fn;
905 t_cfg_element *fn_list;
906 tCfgDataParts cfgparts;
907 int i, n_fn;
908 if (fnid == -1) {
909 Int3(); // get samir
910 return;
911 }
912 ASSERT(slot < N_CFGELEM_SLOTS && slot >= 0);
913 if (ctrl == NULL_CONTROLLER) {
914 return;
915 }
916 // if element is repeated anywhere in function list other than 'fnid'[slot] of elem_type, then remove that
917 // binding.
918 if (elem_type == ctNone) {
919 Int3();
920 return;
921 } else if (elem_type == ctKey) {
922 n_fn = N_KEY_CFG_FN;
923 fn_list = Cfg_key_elements;
924 } else {
925 n_fn = N_JOY_CFG_FN;
926 fn_list = Cfg_joy_elements;
927 }
928 for (i = 0; i < n_fn; i++) {
929 // get current function. if element in any slot matches elem_type, and elem, then remove it.
930 bool match_found = false;
931 Controller->get_controller_function(fn_list[i].fn_id, ctype_fn, &ccfgdata_fn, cfgflags_fn);
932
933 parse_config_data(&cfgparts, ctype_fn[0], ctype_fn[1], ccfgdata_fn);
934 if (elem_type == ctype_fn[0] && elem == cfgparts.bind_0 && cfgparts.ctrl_0 == ctrl) {
935 // match found! clear this part out.
936 cfgparts.bind_0 = NULL_BINDING;
937 cfgparts.ctrl_0 = NULL_CONTROLLER;
938 match_found = true;
939 }
940 if (elem_type == ctype_fn[1] && elem == cfgparts.bind_1 && cfgparts.ctrl_1 == ctrl) {
941 // match found! clear this part out.
942 cfgparts.bind_1 = NULL_BINDING;
943 cfgparts.ctrl_1 = NULL_CONTROLLER;
944 match_found = true;
945 }
946 if (match_found) {
947 // this will effectively clear any matches found.
948 ccfgdata_fn = unify_config_data(&cfgparts);
949 Controller->set_controller_function(fn_list[i].fn_id, ctype_fn, ccfgdata_fn, cfgflags_fn);
950 }
951 }
952 Controller->get_controller_function(fnid, ctype_fn, &ccfgdata_fn, cfgflags_fn);
953
954 parse_config_data(&cfgparts, ctype_fn[0], ctype_fn[1], ccfgdata_fn);
955
956 ctype_fn[slot] = elem_type;
957 cfgflags_fn[slot] = 0;
958 if (slot == 1) {
959 cfgparts.bind_1 = elem;
960 cfgparts.ctrl_1 = ctrl;
961 } else {
962 cfgparts.bind_0 = elem;
963 cfgparts.ctrl_0 = ctrl;
964 }
965 ccfgdata_fn = unify_config_data(&cfgparts);
966 Controller->set_controller_function(fnid, ctype_fn, ccfgdata_fn, cfgflags_fn);
967 }
968 // used as a help/options dialog for each controller config element
969 void ctl_cfg_element_options_dialog(int16_t fnid) {
970 newuiTiledWindow wnd;
971 newuiSheet *sheet;
972 int *inv_binding[CTLBINDS_PER_FUNC];
973 bool *clear_binding[CTLBINDS_PER_FUNC];
974 ct_type ctype_fn[CTLBINDS_PER_FUNC];
975 uint8_t cfgflags_fn[CTLBINDS_PER_FUNC];
976 ct_config_data ccfgdata_fn;
977
978 tCfgDataParts cfgparts;
979 int res, y;
980 char str[64];
981
982 if (fnid == -1) {
983 Int3(); // get samir
984 return;
985 }
986 // determine which configuration pipe to go down
987 Controller->get_controller_function(fnid, ctype_fn, &ccfgdata_fn, cfgflags_fn);
988 parse_config_data(&cfgparts, ctype_fn[0], ctype_fn[1], ccfgdata_fn);
989 switch (ctype_fn[0]) {
990 case ctKey:
991 strcpy(str, TXT_CFGHELP_KEYB);
992 break;
993 case ctAxis:
994 case ctMouseAxis:
995 strcpy(str, TXT_CFGHELP_JOY);
996 break;
997 case ctButton:
998 case ctMouseButton:
999 case ctPOV:
1000 case ctPOV2:
1001 case ctPOV3:
1002 case ctPOV4:
1003 strcpy(str, TXT_CFGHELP_BTNS);
1004 break;
1005 default:
1006 str[0] = 0;
1007 }
1008 // open a small window
1009 wnd.Create(NULL, 0, 0, 320, 192);
1010 sheet = wnd.GetSheet();
1011 // the standard ok and cancel buttons
1012 sheet->NewGroup(NULL, 116, 110, NEWUI_ALIGN_HORIZ);
1013 sheet->AddButton(TXT_OK, UID_OK);
1014 sheet->AddButton(TXT_CANCEL, UID_CANCEL);
1015 sheet->NewGroup(NULL, 0, 0);
1016 sheet->AddText(TXT_CFGHELP_TEXT);
1017 sheet->AddText(str);
1018 y = 40;
1019 // check if there's a binding, if so, then check if we should put up invert axis option.
1020 clear_binding[0] = NULL;
1021 inv_binding[0] = NULL;
1022 if (cfgparts.ctrl_0 != NULL_CONTROLLER) {
1023 snprintf(str, sizeof(str), TXT_CFG_BIND_1, cfg_binding_text(ctype_fn[0], cfgparts.ctrl_0, cfgparts.bind_0));
1024 sheet->NewGroup(str, 0, y, NEWUI_ALIGN_HORIZ);
1025 clear_binding[0] = sheet->AddCheckBox(TXT_CFG_CLEAR);
1026 if (ctype_fn[0] == ctAxis || ctype_fn[0] == ctMouseAxis) {
1027 sheet->AddText(TXT_CFG_INVERT);
1028 inv_binding[0] = sheet->AddFirstRadioButton(TXT_NO);
1029 sheet->AddRadioButton(TXT_YES);
1030 *inv_binding[0] = CHECK_FLAG(cfgflags_fn[0], CTFNF_INVERT) ? 1 : 0;
1031 }
1032 y += 30;
1033 }
1034 // check if there's a binding, if so, then check if we should put up invert axis option.
1035 clear_binding[1] = NULL;
1036 inv_binding[1] = NULL;
1037 if (cfgparts.ctrl_1 != NULL_CONTROLLER) {
1038 snprintf(str, sizeof(str), TXT_CFG_BIND_2, cfg_binding_text(ctype_fn[1], cfgparts.ctrl_1, cfgparts.bind_1));
1039 sheet->NewGroup(str, 0, y, NEWUI_ALIGN_HORIZ);
1040 clear_binding[1] = sheet->AddCheckBox(TXT_CFG_CLEAR);
1041 if (ctype_fn[1] == ctAxis || ctype_fn[1] == ctMouseAxis) {
1042 sheet->AddText(TXT_CFG_INVERT);
1043 inv_binding[1] = sheet->AddFirstRadioButton(TXT_NO);
1044 sheet->AddRadioButton(TXT_YES);
1045 *inv_binding[1] = CHECK_FLAG(cfgflags_fn[1], CTFNF_INVERT) ? 1 : 0;
1046 }
1047 y += 30;
1048 }
1049 wnd.Open();
1050 do {
1051 res = wnd.DoUI();
1052 if (res == NEWUIRES_FORCEQUIT) {
1053 break;
1054 }
1055 } while (res != UID_OK && res != UID_CANCEL);
1056 if (res == UID_OK) {
1057 if (clear_binding[0] && (*clear_binding[0])) {
1058 cfgparts.bind_0 = NULL_BINDING;
1059 cfgparts.ctrl_0 = NULL_CONTROLLER;
1060 }
1061 if (clear_binding[1] && (*clear_binding[1])) {
1062 cfgparts.bind_1 = NULL_BINDING;
1063 cfgparts.ctrl_1 = NULL_CONTROLLER;
1064 }
1065 if (inv_binding[0]) {
1066 cfgflags_fn[0] = (*inv_binding[0]) ? (cfgflags_fn[0] | CTFNF_INVERT) : (cfgflags_fn[0] & (~CTFNF_INVERT));
1067 }
1068 if (inv_binding[1]) {
1069 cfgflags_fn[1] = (*inv_binding[1]) ? (cfgflags_fn[1] | CTFNF_INVERT) : (cfgflags_fn[1] & (~CTFNF_INVERT));
1070 }
1071
1072 ccfgdata_fn = unify_config_data(&cfgparts);
1073 Controller->set_controller_function(fnid, ctype_fn, ccfgdata_fn, cfgflags_fn);
1074 }
1075 wnd.Close();
1076 wnd.Destroy();
1077 }
1078 // used in weapon selection: returns new slot.
1079 int weapon_select_dialog(int wpn, bool is_secondary) {
1080 newuiTiledWindow wnd;
1081 newuiListBox *lbox;
1082 newuiSheet *sheet;
1083 int res, i;
1084 uint16_t retval;
1085 wpn &= (~WPNSEL_SKIP);
1086 wnd.Create(NULL, 0, 0, 320, 288);
1087 sheet = wnd.GetSheet();
1088 sheet->NewGroup(NULL, 116, 210, NEWUI_ALIGN_HORIZ);
1089 sheet->AddButton(TXT_OK, UID_OK);
1090 sheet->AddButton(TXT_CANCEL, UID_CANCEL);
1091 sheet->NewGroup(NULL, 0, 0);
1092 sheet->AddText(TXT_WPNCFGHELP3);
1093 sheet->AddText(TXT(Static_weapon_names_msg[wpn]));
1094 sheet->NewGroup(NULL, 0, 40);
1095 lbox = sheet->AddListBox(192, 160, UID_WPNLIST, UILB_NOSORT);
1096 // add primaries or secondaries.
1097 for (i = 0; i < 10; i++) {
1098 int wpnidx;
1099 char str[64];
1100 wpnidx = is_secondary ? GetAutoSelectSecondaryWpnIdx(i) : GetAutoSelectPrimaryWpnIdx(i);
1101 if (wpnidx != WPNSEL_INVALID) {
1102 if (wpnidx & WPNSEL_SKIP) {
1103 wpnidx &= (~WPNSEL_SKIP);
1104 snprintf(str, sizeof(str), TXT_WPNSELBTN, TXT(Static_weapon_names_msg[wpnidx]));
1105 } else {
1106 snprintf(str, sizeof(str), "%s", TXT(Static_weapon_names_msg[wpnidx]));
1107 }
1108 lbox->AddItem(str);
1109 } else {
1110 lbox->AddItem("ERR-WPN");
1111 }
1112 }
1113 wnd.Open();
1114 res = wnd.DoUI();
1115 wnd.Close();
1116 switch (res) {
1117 case UID_WPNLIST:
1118 case UID_OK:
1119 retval = lbox->GetCurrentIndex();
1120 break;
1121 default:
1122 retval = -1;
1123 }
1124 wnd.Destroy();
1125
1126 return retval;
1127 }
1128 void joystick_calibration() {
1129 }
1130 void joystick_settings_dialog() {
1131 newuiTiledWindow wnd;
1132 newuiSheet *sheet;
1133 int res, i, y;
1134 int16_t curpos;
1135 tSliderSettings slider_set;
1136 char axis_str[N_JOY_AXIS] = {'X', 'Y', 'Z', 'R', 'U', 'V'};
1137 int16_t *joy_sens[N_JOY_AXIS];
1138 int16_t *mse_sens[N_MOUSE_AXIS];
1139 int16_t *ff_gain = NULL;
1140 bool *ff_enabled = NULL;
1141 bool *ff_auto_center = NULL;
1142 bool ff_auto_center_support = false;
1143 bool ff_found = false;
1144 bool *joy_enabled;
1145 bool *mse_enabled;
1146 int *msectl;
1147
1148 wnd.Create(TXT_JOYMOUSESETTINGS, 0, 0, 480, 384);
1149 sheet = wnd.GetSheet();
1150 // standard ui
1151 sheet->NewGroup(NULL, 270, 288, NEWUI_ALIGN_HORIZ);
1152 sheet->AddButton(TXT_OK, UID_OK);
1153 sheet->AddButton(TXT_CANCEL, UID_CANCEL);
1154 // sensitivity sliders for joystick
1155 sheet->NewGroup(TXT_SENSITIVITY, 0, 0);
1156 for (i = 0; i < N_JOY_AXIS; i++) {
1157 char str[16];
1158 float val = Controller->get_axis_sensitivity(ctAxis, i + 1);
1159 slider_set.min_val.f = 0.0f;
1160 slider_set.max_val.f = JOY_AXIS_SENS_RANGE;
1161 slider_set.type = SLIDER_UNITS_FLOAT;
1162 curpos = CALC_SLIDER_POS_FLOAT(val, &slider_set, CFG_AXIS_SENS_RANGE);
1163 snprintf(str, sizeof(str), TXT_CONTAXIS, axis_str[i]);
1164 joy_sens[i] = sheet->AddSlider(str, CFG_AXIS_SENS_RANGE, curpos, &slider_set);
1165 }
1166 sheet->NewGroup(TXT_MSESENS, 0, 220);
1167
1168 for (i = 0; i < N_MOUSE_AXIS; i++) {
1169 char str[16];
1170 float val = Controller->get_axis_sensitivity(ctMouseAxis, i + 1);
1171 slider_set.min_val.f = 0.0f;
1172 slider_set.max_val.f = MSE_AXIS_SENS_RANGE;
1173 slider_set.type = SLIDER_UNITS_FLOAT;
1174 curpos = CALC_SLIDER_POS_FLOAT(val, &slider_set, CFG_AXIS_SENS_RANGE);
1175 snprintf(str, sizeof(str), TXT_CONTAXIS, axis_str[i]);
1176 mse_sens[i] = sheet->AddSlider(str, CFG_AXIS_SENS_RANGE, curpos, &slider_set);
1177 }
1178 // joystick and mouse enabled
1179 y = 0;
1180 sheet->NewGroup(TXT_CONTROL_TOGGLES, 210, y);
1181 joy_enabled = sheet->AddLongCheckBox(TXT_JOYENABLED);
1182 mse_enabled = sheet->AddLongCheckBox(TXT_CFG_MOUSEENABLED);
1183 *joy_enabled = CHECK_FLAG(Current_pilot.read_controller, READF_JOY) ? true : false;
1184 *mse_enabled = CHECK_FLAG(Current_pilot.read_controller, READF_MOUSE) ? true : false;
1185 y += 50;
1186 sheet->NewGroup(TXT_MOUSECONTROL, 210, y);
1187 msectl = sheet->AddFirstLongRadioButton(TXT_MOUSEFLIGHTSIM);
1188 sheet->AddLongRadioButton(TXT_MOUSELOOK);
1189 *msectl = Current_pilot.mouselook_control ? 1 : 0;
1190 y += 50;
1191 sheet->NewGroup(NULL, 210, y);
1192 sheet->AddLongButton(TXT_CALIBJOYSTICK, UID_JOYCFG);
1193 // force feedback stuff
1194 y += 30;
1195 ddio_ff_GetInfo(&ff_found, NULL);
1196 if (ff_found) {
1197 sheet->NewGroup(TXT_TITLE_FORCEFEEDBACK, 210, y);
1198 ff_enabled = sheet->AddLongCheckBox(TXT_CFG_FFENABLED, ForceIsEnabled());
1199 ff_auto_center_support = ddio_ffjoy_SupportAutoCenter(kJoy1);
1200 if (ff_auto_center_support) {
1201 // force feedback joystick supports autocentering
1202 // ----------------------------------------------
1203 ff_auto_center = sheet->AddLongCheckBox(TXT_CFG_FFAUTOCENTER, ForceIsAutoCenter());
1204 }
1205 curpos = (int16_t)(ForceGetGain() * 50.0f);
1206 slider_set.type = SLIDER_UNITS_PERCENT;
1207 ff_gain = sheet->AddSlider(TXT_CFG_FORCEGAIN, 50, curpos, &slider_set);
1208 }
1209 wnd.Open();
1210 do {
1211 res = wnd.DoUI();
1212 if (res == NEWUIRES_FORCEQUIT) {
1213 break;
1214 }
1215 if (res == UID_JOYCFG) {
1216 joystick_calibration();
1217 }
1218 } while (res != UID_OK && res != UID_CANCEL);
1219 if (res == UID_OK) {
1220 float f_temp;
1221
1222 Current_pilot.read_controller = (*joy_enabled) ? READF_JOY : 0;
1223 for (i = 0; i < N_JOY_AXIS; i++) {
1224 float val = CALC_SLIDER_FLOAT_VALUE(*joy_sens[i], 0.0f, JOY_AXIS_SENS_RANGE, CFG_AXIS_SENS_RANGE);
1225 Controller->set_axis_sensitivity(ctAxis, i + 1, val);
1226 }
1227 Current_pilot.read_controller |= (*mse_enabled) ? READF_MOUSE : 0;
1228 for (i = 0; i < N_MOUSE_AXIS; i++) {
1229 float val = CALC_SLIDER_FLOAT_VALUE(*mse_sens[i], 0.0f, MSE_AXIS_SENS_RANGE, CFG_AXIS_SENS_RANGE);
1230 Controller->set_axis_sensitivity(ctMouseAxis, i + 1, val);
1231 }
1232 Current_pilot.mouselook_control = (*msectl) ? true : false;
1233 // force feedback stuff
1234 if (ff_enabled) {
1235 if (*ff_enabled) {
1236 ForceEnable();
1237 } else {
1238 ForceDisable();
1239 }
1240 }
1241 if (ff_auto_center_support) {
1242 if (*ff_auto_center) {
1243 ForceEnableAutoCenter();
1244 } else {
1245 ForceDisableAutoCenter();
1246 }
1247 }
1248 if (ff_gain) {
1249 f_temp = (*ff_gain) * 0.5f;
1250 ForceSetGain(f_temp);
1251 }
1252 }
1253 wnd.Close();
1254 wnd.Destroy();
1255 }
1256 #define CFG_KEY_RAMP_MAX 1.0f
1257 #define CFG_KEY_RAMP_RANGE 20
1258 void key_settings_dialog() {
1259 newuiTiledWindow wnd;
1260 newuiSheet *sheet;
1261 int res;
1262 int16_t curpos;
1263 tSliderSettings slider_set;
1264 int16_t *key_ramp_speed;
1265 wnd.Create(TXT_KEYSETTINGS, 0, 0, 384, 256);
1266 sheet = wnd.GetSheet();
1267 sheet->NewGroup(NULL, 0, 30);
1268 slider_set.min_val.f = 0.0f;
1269 slider_set.max_val.f = CFG_KEY_RAMP_MAX;
1270 slider_set.type = SLIDER_UNITS_FLOAT;
1271 curpos = CALC_SLIDER_POS_FLOAT(Key_ramp_speed, &slider_set, CFG_KEY_RAMP_RANGE);
1272 key_ramp_speed = sheet->AddSlider(TXT_KEYRAMPINGTIME, CFG_KEY_RAMP_RANGE, curpos, &slider_set);
1273 sheet->NewGroup(NULL, 180, 160, NEWUI_ALIGN_HORIZ);
1274 sheet->AddButton(TXT_OK, UID_OK);
1275 sheet->AddButton(TXT_CANCEL, UID_CANCEL);
1276 wnd.Open();
1277 do {
1278 res = wnd.DoUI();
1279 if (res == NEWUIRES_FORCEQUIT) {
1280 break;
1281 }
1282 } while (res != UID_OK && res != UID_CANCEL);
1283 if (res == UID_OK) {
1284 Key_ramp_speed = CALC_SLIDER_FLOAT_VALUE(*key_ramp_speed, 0.0f, CFG_KEY_RAMP_MAX, CFG_KEY_RAMP_RANGE);
1285 }
1286 wnd.Close();
1287 wnd.Destroy();
1288 }
1289 //////////////////////////////////////////////////////////////////////////////
1290 // configure controller new way
1291 struct t_ctlcfgswitchcb_data {
1292 joy_cfg_screen *joycfg;
1293 key_cfg_screen *keycfg;
1294 wpnsel_cfg_screen *wpncfg;
1295 cfg_screen *curcfg;
1296 };
1297
1298 // called when we switch menus
1299 void CtlConfigSwitchCB(newuiMenu *menu, int16_t old_option_id, int16_t new_option_id, void *data) {
1300 t_ctlcfgswitchcb_data *cfgdata = (t_ctlcfgswitchcb_data *)data;
1301 // performs custom gadget deinitialization and reinitilization
1302 if (cfgdata->curcfg) {
1303 cfgdata->curcfg->unrealize();
1304 }
1305
1306 switch (new_option_id) {
1307 case IDV_KCONFIG:
1308 cfgdata->curcfg = cfgdata->keycfg;
1309 break;
1310 case IDV_CCONFIG:
1311 cfgdata->curcfg = cfgdata->joycfg;
1312 break;
1313 case IDV_WPNSEL:
1314 cfgdata->curcfg = cfgdata->wpncfg;
1315 break;
1316 default:
1317 cfgdata->curcfg = NULL;
1318 }
1319 if (cfgdata->curcfg) {
1320 cfgdata->curcfg->realize();
1321 }
1322 }
1323 // keep multiplayer going!
1324 void CtlConfigUICB() {
1325 if (Game_mode & (GM_MULTI)) {
1326 Skip_render_game_frame = true;
1327 GameFrame();
1328 Skip_render_game_frame = false;
1329 } else if (GetFunctionMode() == GAME_MODE) {
1330 extern void GameProcessMusic();
1331 float saved_frame_time = Frametime;
1332 Frametime = UIFrameTime;
1333 Sound_system.BeginSoundFrame(true);
1334 GameProcessMusic();
1335 Sound_system.EndSoundFrame();
1336 Frametime = saved_frame_time;
1337 }
1338 }
1339 // the main controller config menu loop
1340 void CtlConfig(int mode) {
1341 newuiLargeMenu menu;
1342 joy_cfg_screen joycfg;
1343 key_cfg_screen keycfg;
1344 wpnsel_cfg_screen wpncfg;
1345 t_ctlcfgswitchcb_data cfg_cb_data;
1346 int res;
1347 void (*old_callback)() = GetUICallback();
1348 int old_mode = GetScreenMode();
1349 // must switch to standard resolution for large window
1350 SetScreenMode(SM_MENU);
1351 LoadControlConfig();
1352 // open menu
1353 menu.Create();
1354 menu.Open();
1355 joycfg.setup(&menu);
1356 keycfg.setup(&menu);
1357 wpncfg.setup(&menu);
1358 cfg_cb_data.joycfg = &joycfg;
1359 cfg_cb_data.keycfg = &keycfg;
1360 cfg_cb_data.wpncfg = &wpncfg;
1361 cfg_cb_data.curcfg = NULL;
1362 menu.AddSimpleOption(UID_CANCEL, TXT_GEN_EXIT);
1363 menu.SetCurrentOption((mode == CTLCONFIG_WPNSEL) ? IDV_WPNSEL
1364 : (mode == CTLCONFIG_CONTROLLER) ? IDV_CCONFIG
1365 : IDV_KCONFIG);
1366 menu.SetOnOptionSwitchCB(CtlConfigSwitchCB, (void *)&cfg_cb_data);
1367
1368 // if(mode==CTLCONFIG_CONTROLLER) {
1369 // inSprocket_Configure();
1370 // }
1371 // make sure game is running!
1372 SetUICallback(CtlConfigUICB);
1373 // run menu
1374 do {
1375 res = menu.DoUI();
1376 // immediate checking of any option ids.
1377 if (res == UID_CANCEL || res == NEWUIRES_FORCEQUIT) {
1378 break; // next pass will quit
1379 }
1380 // if(res == IDV_CCONFIG) {
1381 // inSprocket_Configure();
1382 // }
1383 switch (menu.GetCurrentOption()) {
1384 case IDV_KCONFIG:
1385 keycfg.process(res);
1386 break;
1387 case IDV_CCONFIG:
1388 joycfg.process(res);
1389 break;
1390 case IDV_WPNSEL:
1391 wpncfg.process(res);
1392 break;
1393 };
1394 } while (1);
1395 // write them out and close.
1396 wpncfg.finish();
1397 keycfg.finish();
1398 joycfg.finish();
1399 SaveControlConfig(); // write out config to pilot when destroying window
1400 PltWriteFile(&Current_pilot);
1401 menu.Close();
1402 menu.Destroy();
1403 SetScreenMode(old_mode);
1404 SetUICallback(old_callback);
1405 Skip_render_game_frame = false;
1406 }
1407 int CtlFindBinding(int controlid, bool keyboard) {
1408 int i = 0;
1409
1410 if (keyboard) {
1411 for (i = 0; i < N_KEY_CFG_FN; i++) {
1412 if (Cfg_key_elements[i].fn_id == controlid)
1413 return i;
1414 }
1415 } else {
1416 for (i = 0; i < N_JOY_CFG_FN; i++) {
1417 if (Cfg_joy_elements[i].fn_id == controlid)
1418 return i;
1419 }
1420 }
1421 return -1;
1422 }