]> icculus.org git repositories - taylor/freespace2.git/blob - src/controlconfig/controlsconfigcommon.cpp
Initial revision
[taylor/freespace2.git] / src / controlconfig / controlsconfigcommon.cpp
1 /*
2  * $Logfile: /Freespace2/code/ControlConfig/ControlsConfigCommon.cpp $
3  * $Revision$
4  * $Date$
5  * $Author$
6  *
7  * C module for keyboard, joystick and mouse configuration common stuff (between Fred and FreeSpace)
8  *
9  * $Log$
10  * Revision 1.1  2002/05/03 03:28:08  root
11  * Initial revision
12  *
13  * 
14  * 14    11/01/99 3:36p Jefff
15  * had scan code texts for y and z in german swapped
16  * 
17  * 13    11/01/99 2:16p Jefff
18  * minor key name change in german
19  * 
20  * 12    10/29/99 6:10p Jefff
21  * squashed the damned y/z german issues once and for all
22  * 
23  * 11    10/28/99 11:16p Jefff
24  * Changed some german key names.  Made key translations always use the
25  * english table.
26  * 
27  * 10    10/28/99 2:05a Jefff
28  * revised some german key names.  changed some y/z switch stuff.
29  * 
30  * 9     10/25/99 5:39p Jefff
31  * swap init binding for y and z keys in German builds
32  * 
33  * 8     9/01/99 2:56p Jefff
34  * a few control key description changes
35  * 
36  * 7     8/22/99 5:53p Dave
37  * Scoring fixes. Added self destruct key. Put callsigns in the logfile
38  * instead of ship designations for multiplayer players.
39  * 
40  * 6     8/19/99 10:59a Dave
41  * Packet loss detection.
42  * 
43  * 5     8/01/99 12:39p Dave
44  * Added HUD contrast control key (for nebula).
45  * 
46  * 4     7/23/99 2:57p Andsager
47  * fix translate_key_to_index to work with localization
48  * 
49  * 3     11/05/98 4:18p Dave
50  * First run nebula support. Beefed up localization a bit. Removed all
51  * conditional compiles for foreign versions. Modified mission file
52  * format.
53  * 
54  * 2     10/07/98 10:52a Dave
55  * Initial checkin.
56  * 
57  * 1     10/07/98 10:48a Dave
58  * 
59  * 41    6/19/98 3:51p Lawrance
60  * localize control text
61  * 
62  * 40    6/17/98 11:05a Lawrance
63  * localize the control config strings
64  * 
65  * 39    5/24/98 2:28p Hoffoss
66  * Because we never really care about if the left or the right shift or
67  * alt key was used, but rather than either shift or alt was used, made
68  * both map to the left one.  Solves some problems, causes none.
69  * 
70  * 38    5/22/98 11:21a Hoffoss
71  * Added bank when pressed back in.
72  * 
73  * 37    5/15/98 8:37p Lawrance
74  * Add 'equalize recharge rates' and 'target ship that sent last
75  * transmission' key bindings
76  * 
77  * 36    5/13/98 7:15p Hoffoss
78  * Fixed remaining bugs with axis binding.
79  * 
80  * 35    5/13/98 1:17a Hoffoss
81  * Added joystick axes configurability.
82  * 
83  * 34    5/12/98 11:25a Hoffoss
84  * Disabled bank when pressed action.
85  * 
86  * 33    5/09/98 10:48p Lawrance
87  * change text for view bindings
88  * 
89  * 32    5/09/98 4:52p Lawrance
90  * Implement padlock view (up/rear/left/right)
91  * 
92  * 31    4/30/98 9:43p Hoffoss
93  * Added new actions for free look movement which are default bounded to
94  * the hat.
95  * 
96  * 30    4/25/98 1:25p Lawrance
97  * Add time compression keys to key config
98  * 
99  * 29    4/25/98 12:43p Allender
100  * added new shortcut key for attack my subsystem
101  * 
102  * 28    4/18/98 5:00p Dave
103  * Put in observer zoom key. Made mission sync screen more informative.
104  * 
105  * 27    4/17/98 1:24a Lawrance
106  * fix spelling error
107  * 
108  * 26    4/15/98 11:06a Lawrance
109  * fix bug with a multi key showing up in demo, remove obsolete bindings
110  * from demo and full version
111  * 
112  * 25    4/10/98 12:47p Allender
113  * changed working on replay popup.  Don't reference repair in comm menu.
114  * Added Shift-R for repair me
115  * 
116  * 24    4/08/98 11:11a Hoffoss
117  * Fixed some bugs that showed up due to fixing other bugs the other day
118  * with controls.
119  * 
120  * 23    4/07/98 4:06p Lawrance
121  * Change binding next for bomb targeting
122  * 
123  * 22    4/07/98 1:52p Lawrance
124  * fix error in binding text for energy keys 
125  * 
126  * 21    4/06/98 11:17a Hoffoss
127  * Fixed num lock/pause interplay bug.
128  * 
129  * 20    4/01/98 6:46p Lawrance
130  * change text for Alt+J
131  * 
132  * 19    3/31/98 4:15p Hoffoss
133  * Disabled the show objectives action.
134  * 
135  * 18    3/25/98 2:16p Dave
136  * Select random default image for newly created pilots. Fixed several
137  * multi-pause messaging bugs. Begin work on online help for multiplayer
138  * keys.
139  * 
140  * 17    3/19/98 5:04p Dave
141  * Put in support for targeted multiplayer text and voice messaging (all,
142  * friendly, hostile, individual).
143  * 
144  * 16    3/17/98 11:25a Hoffoss
145  * Fixed some of the action's names.
146  * 
147  * 15    3/17/98 10:48a Hoffoss
148  * Allowed a special hack for "bank while pressed" action to use alt and
149  * shift keys standalone.
150  * 
151  * 14    2/28/98 9:47p Lawrance
152  * change some binding text
153  * 
154  * 13    2/28/98 7:02p Lawrance
155  * overhaul on-line help
156  * 
157  * 12    2/26/98 12:33a Lawrance
158  * Added back slew mode,  lots of changes to external and chase views.
159  * 
160  * 11    2/23/98 11:25a Sandeep
161  * added default keys
162  * 
163  * 10    2/22/98 6:27p Lawrance
164  * External mode takes precedence over chase mode.  Fix bug with repair
165  * ships docking in chase mode.
166  * 
167  * 9     2/22/98 12:19p John
168  * Externalized some strings
169  * 
170  * 8     2/02/98 6:59p Lawrance
171  * Adding new targeting keys (bomb, uninspected cargo, new ship, live
172  * turrets).
173  * 
174  * 7     1/27/98 4:24p Allender
175  * moved hotkey selection to F3 instead of X.  Made palette flash
176  * disappear in multiplayer pause menu
177  * 
178  * 6     1/22/98 4:53p Hoffoss
179  * Made training messages/directives display a joystick button in place of
180  * a keypress if there is no keypress bound to the action.
181  * 
182  * 5     1/22/98 4:15p Hoffoss
183  * Added code to allow popup to tell player he needs to bind a key for the
184  * training mission.
185  * 
186  * 4     1/02/98 4:42p Allender
187  * removed unused key bindings from control config list
188  * 
189  * 3     12/30/97 4:47p Allender
190  * work with ignore my target command.  Added new keyboard hotkey.  Made
191  * it work globally
192  * 
193  * 2     12/24/97 3:37p Hoffoss
194  * Moved control config stuff to seperate library to Fred can access it as
195  * well.
196  * 
197  * 1     12/24/97 3:27p Hoffoss
198  * 
199  * 1     12/24/97 11:58a Hoffoss
200  * 
201  * 98    12/22/97 2:15p Hoffoss
202  * Fixed bug where joystick axis lines weren't being displayed.
203  * 
204  * 97    12/16/97 2:44p Hoffoss
205  * Added clear button to control config screen.
206  * 
207  * 96    12/12/97 3:07p Hoffoss
208  * Changed how deleting bindings work.  Each control of an action can be
209  * deleted independently or both at once.
210  * 
211  * 95    12/07/97 2:36p John
212  * Made warp out be Alt+J instead of J
213  * 
214  * 94    12/03/97 4:59p Hoffoss
215  * Added reset sound and change control config sounds around.
216  * 
217  * 93    12/03/97 4:16p Hoffoss
218  * Changed sound stuff used in interface screens for interface purposes.
219  * 
220  * 92    12/01/97 5:25p Hoffoss
221  * Routed interface sound playing through a special function that will
222  * only allow one instance of the sound to play at a time, avoiding
223  * over-mixing problems.
224  * 
225  * 91    12/01/97 3:38p Hoffoss
226  * Changed placement of 'More' indicator.
227  * 
228  * 90    11/25/97 3:49p Hoffoss
229  * Changed subhilighting to happen when mouse is over line, rather than
230  * mouse button down but not up again yet.
231  * 
232  * 89    11/24/97 10:20p Lawrance
233  * Add key 'KEY_N' to target next ship on monitoring view
234  * 
235  * 88    11/24/97 6:15p Lawrance
236  * fix button scroll problem
237  * 
238  * 87    11/23/97 6:15p Hoffoss
239  * Make exiting the controls config screen save the pilot, so changes keep
240  * even if programs crashes or something.
241  * 
242  * 86    11/21/97 5:57p Hoffoss
243  * Fixed bug where timef type controls weren't checking joystick buttons.
244  * 
245  * 85    11/21/97 4:06p Hoffoss
246  * Fixed bug with enabling of axis are reversed.
247  * 
248  * 84    11/20/97 4:47p Hoffoss
249  * Swapped throttle and rudder, which apparently were backwards.
250  * 
251  * 83    11/20/97 4:00p Lawrance
252  * set z to a valid value
253  * 
254  * 82    11/20/97 3:52p Hoffoss
255  * Made "None" appear if no control is bound to function.
256  * 
257  * 81    11/20/97 2:10p Hoffoss
258  * Added defaults for  joystick buttons 2 and 3.
259  * 
260  * 80    11/20/97 1:08a Lawrance
261  * add support for 'R' key - target closest friendly repair ship
262  * 
263  * 79    11/19/97 8:33p Hoffoss
264  * New controls config screen baby!
265  * 
266  * 78    11/17/97 7:09p Hoffoss
267  * Made chase view control a trigger type.
268  * 
269  * 77    11/17/97 6:40p Lawrance
270  * Changed 'I' key to toggle of extended target info, moved target closest
271  * locked missile to 'L'
272  * 
273  * 76    11/17/97 3:26p Jasen
274  * Adjusted coordinates for the help button .ani location
275  * 
276  * 75    11/16/97 3:51p Hoffoss
277  * Added more button to config screen when scrolling allowed.
278  * 
279  * 74    11/16/97 3:20p Hoffoss
280  * Added various suggestions from the Todolist.
281  * 
282  * 73    11/14/97 4:33p Mike
283  * Change Debug key to backquote (from F11).
284  * Balance a ton of subsystems in ships.tbl.
285  * Change "Heavy Laser" to "Disruptor".
286  * 
287  * 72    11/12/97 2:54p Hoffoss
288  * Made modifiers non-stand alone, added support for red tabs on
289  * conflicts.
290  * 
291  * 71    10/30/97 6:01p Hoffoss
292  * Changed screen to utilize the new text color standards.
293  * 
294  * 70    10/29/97 7:25p Hoffoss
295  * Added crude support for UI button double click checking.
296  * 
297  * 69    10/29/97 6:32p Hoffoss
298  * Changed some interface apperances.
299  * 
300  * 68    10/29/97 4:54p Hoffoss
301  * Changed scan_code_text element for Enter to 'Enter' instead of 'a' with
302  * a caret over it (what's that all about?)
303  * 
304  * 67    10/28/97 10:42a Hoffoss
305  * Fixed handling of continuous controls that have modifiers to the key.
306  * 
307  * 66    10/28/97 10:03a Hoffoss
308  * Fixed bug with continuous type controls not registering if pressed and
309  * released too quickly.  Also some other little changes.
310  * 
311  * 65    10/28/97 12:12a Lawrance
312  * remove unused keys (Alt-H and Alt-F)
313  * 
314  * 64    10/27/97 12:23p Hoffoss
315  * Improved warning system and fixed coloring bug.
316  * 
317  * 63    10/27/97 11:39a Hoffoss
318  * Added control conflicts checking.
319  * 
320  * 62    10/26/97 3:20p Hoffoss
321  * Added many missing features to control config screen.
322  * 
323  * 61    10/25/97 5:41p Hoffoss
324  * More functionality added to the controls config screen.
325  * 
326  * 60    10/24/97 11:00p Hoffoss
327  * Controls config screen much improved.
328  * 
329  * 59    10/22/97 4:50p Hoffoss
330  * Disabled throttle by default.
331  * 
332  * 58    10/22/97 11:00a Hoffoss
333  * Changed VIEW_SLEW and VIEW_EXTERNAL to be continuous rather than
334  * trigger actions.
335  * 
336  * 57    10/21/97 7:05p Hoffoss
337  * Overhauled the key/joystick control structure and usage throughout the
338  * entire FreeSpace code.  The whole system is very different now.
339  * 
340  * 56    10/18/97 7:19p Hoffoss
341  * Added timestamp recording when a key is pressed.
342  * 
343  * 55    10/13/97 4:33p Hoffoss
344  * Made training messages go away after time.
345  * 
346  * 54    10/13/97 3:24p Hoffoss
347  * Made it so training message text can be arbitrarily bolded.
348  * 
349  * 53    9/24/97 4:52p Hoffoss
350  * Changed training message key token handling, and implemented a new
351  * training message system method to test out for a while.
352  * 
353  * 52    9/14/97 10:24p Lawrance
354  * add damage screen popup window
355  * 
356  * 51    9/10/97 6:02p Hoffoss
357  * Added code to check for key-pressed sexp operator in FreeSpace as part
358  * of training mission stuff.
359  * 
360  * 50    9/09/97 3:39p Sandeep
361  * warning level 4 bugs
362  * $NoKeywords: $
363  *
364 */
365
366 #include "controlsconfig.h"
367 #include "key.h"
368 #include "joy.h"
369 #include "localize.h"
370
371 #define TARGET_TAB                      0
372 #define SHIP_TAB                                1
373 #define WEAPON_TAB                      2
374 #define COMPUTER_TAB                    3
375
376 int Failed_key_index;
377
378 // assume control keys are used as modifiers until we find out 
379 int Shift_is_modifier;
380 int Ctrl_is_modifier;
381 int Alt_is_modifier;
382
383 int Axis_enabled[JOY_NUM_AXES] = { 1, 1, 1, 0, 0, 0 };
384 int Axis_enabled_defaults[JOY_NUM_AXES] = { 1, 1, 1, 0, 0, 0 };
385 int Invert_axis[JOY_NUM_AXES] = { 0, 0, 0, 0, 0, 0 };
386 int Invert_axis_defaults[JOY_NUM_AXES] = { 0, 0, 0, 0, 0, 0 };
387
388 // arrays which hold the key mappings.  The array index represents a key-independent action.
389 //
390 //XSTR:OFF
391 config_item Control_config[CCFG_MAX + 1] = {
392         // targeting a ship
393         {                           KEY_T,                              -1, TARGET_TAB, "Target Next Ship" },
394         {             KEY_SHIFTED | KEY_T,                              -1, TARGET_TAB, "Target Previous Ship" },
395         {                           KEY_H,                              2,  TARGET_TAB, "Target Next Closest Hostile Ship" },
396         {                  KEY_SHIFTED | KEY_H,                         -1, TARGET_TAB, "Target Previous Closest Hostile Ship" },
397         { KEY_ALTED |               KEY_H,                              -1, TARGET_TAB, "Toggle Auto Targeting" },
398         {                           KEY_F,                              -1, TARGET_TAB, "Target Next Closest Friendly Ship" },
399         {             KEY_SHIFTED | KEY_F,                              -1, TARGET_TAB, "Target Previous Closest Friendly Ship" },
400         {                           KEY_Y,                              4,  TARGET_TAB, "Target Ship in Reticle" },
401         {                           KEY_G,                              -1, TARGET_TAB, "Target Target's Nearest Attacker" },
402         { KEY_ALTED     |                                        KEY_Y,                         -1, TARGET_TAB, "Target Last Ship to Send Transmission" },
403         { KEY_ALTED |               KEY_T,                              -1, TARGET_TAB, "Turn Off Auto-Targeting" },
404
405         // targeting a ship's subsystem
406         {                           KEY_V,                              -1, TARGET_TAB, "Target Subsystem in Reticle" },
407         {                           KEY_S,                              -1, TARGET_TAB, "Target Next Subsystem" },
408         {             KEY_SHIFTED | KEY_S,                              -1, TARGET_TAB, "Target Previous Subsystem" },
409         { KEY_ALTED |               KEY_S,                              -1, TARGET_TAB, "Turn Off Auto-Targeting of Subsystems" },
410
411         // matching speed
412         {                           KEY_M,                              -1, COMPUTER_TAB,       "Match Target Speed" },
413         { KEY_ALTED |               KEY_M,                              -1, COMPUTER_TAB,       "Toggle Auto Speed Matching" },
414
415         // weapons
416         {                           KEY_LCTRL,                  0,       WEAPON_TAB,    "Fire Primary Weapon", CC_TYPE_CONTINUOUS },
417         {                           KEY_SPACEBAR,               1,  WEAPON_TAB, "Fire Secondary Weapon", CC_TYPE_CONTINUOUS },
418         {                           KEY_PERIOD,         -1, WEAPON_TAB, "Cycle Forward Primary Weapon" },
419         {                           KEY_COMMA,                  -1, WEAPON_TAB, "Cycle Backward Primary Weapon" },
420         {                           KEY_DIVIDE,         -1, WEAPON_TAB, "Cycle Secondary Weapon Bank" },
421         {             KEY_SHIFTED | KEY_DIVIDE,         -1, WEAPON_TAB, "Cycle Secondary Weapon Firing Rate" },
422         {                           KEY_X,                              3,       WEAPON_TAB,    "Launch Countermeasure" },
423
424         // controls
425         {                           KEY_A,                              -1, SHIP_TAB,           "Forward Thrust", CC_TYPE_CONTINUOUS },
426         {                           KEY_Z,                              -1, SHIP_TAB,           "Reverse Thrust", CC_TYPE_CONTINUOUS },
427         {                           KEY_PAD7,                   -1, SHIP_TAB,           "Bank Left", CC_TYPE_CONTINUOUS },
428         {                           KEY_PAD9,                   -1, SHIP_TAB,           "Bank Right", CC_TYPE_CONTINUOUS },
429         {                           KEY_PAD8,                   -1, SHIP_TAB,           "Pitch Forward", CC_TYPE_CONTINUOUS },
430         {                           KEY_PAD2,                   -1, SHIP_TAB,           "Pitch Backward", CC_TYPE_CONTINUOUS },
431         {                           KEY_PAD4,                   -1, SHIP_TAB,           "Turn Left", CC_TYPE_CONTINUOUS },
432         {                           KEY_PAD6,                   -1, SHIP_TAB,           "Turn Right", CC_TYPE_CONTINUOUS },
433
434         // throttle controls
435         {                           KEY_BACKSP,         -1, SHIP_TAB,           "Set Throttle to Zero" },
436         {                           KEY_SLASH,                  -1, SHIP_TAB,           "Set Throttle to Max" },
437         {                           KEY_LBRACKET,               -1, SHIP_TAB,           "Set Throttle to One-Third" },
438         {                           KEY_RBRACKET,               -1, SHIP_TAB,           "Set Throttle to Two-Thirds" },
439         {                           KEY_EQUAL,                  -1, SHIP_TAB,           "Increase Throttle 5 Percent" },
440         {                           KEY_MINUS,                  -1, SHIP_TAB,           "Decrease Throttle 5 Percent" },
441
442         // squadmate messaging
443         {             KEY_SHIFTED | KEY_A,                              -1, COMPUTER_TAB,       "Attack My Target" },
444         {             KEY_SHIFTED | KEY_Z,                              -1, COMPUTER_TAB,       "Disarm My Target" },
445         {             KEY_SHIFTED | KEY_D,                              -1, COMPUTER_TAB,       "Disable My Target" },
446         {             KEY_SHIFTED | KEY_V,                              -1, COMPUTER_TAB,       "Attack my Subsystem" },
447         {             KEY_SHIFTED | KEY_X,                              -1, COMPUTER_TAB,       "Capture My Target" },
448         {             KEY_SHIFTED | KEY_E,                              -1, COMPUTER_TAB,       "Engage Enemy" },
449         {             KEY_SHIFTED | KEY_W,                              -1, COMPUTER_TAB,       "Form on my Wing" },
450         {             KEY_SHIFTED | KEY_I,                              -1, COMPUTER_TAB,       "Ignore my Target" },
451         {             KEY_SHIFTED | KEY_P,                              -1, COMPUTER_TAB,       "Protect my Target" },
452         {             KEY_SHIFTED | KEY_C,                              -1, COMPUTER_TAB,       "Cover me" },
453         {             KEY_SHIFTED | KEY_J,                              -1, COMPUTER_TAB,       "Return to base" },
454         {                                 KEY_SHIFTED | KEY_R,                          -1, COMPUTER_TAB, "Rearm me" },
455
456         {                                                                        KEY_R,                         6,  TARGET_TAB, "Target Closest Attacking Ship" },
457
458         // Views
459         {                           KEY_PADMULTIPLY,    -1, COMPUTER_TAB,       "Chase View" },
460         {                           KEY_PADPERIOD,      -1, COMPUTER_TAB,       "External View"},
461         {                           KEY_PADENTER,               -1, COMPUTER_TAB,       "Toggle External Camera Lock"},
462         {                           KEY_PAD0,                   -1, COMPUTER_TAB,       "Free Look View", CC_TYPE_CONTINUOUS },
463         {                           KEY_PADDIVIDE,      -1, COMPUTER_TAB,       "Current Target View" },
464         {                           KEY_PADPLUS,                -1, COMPUTER_TAB,       "Increase View Distance", CC_TYPE_CONTINUOUS },
465         {                           KEY_PADMINUS,               -1, COMPUTER_TAB,       "Decrease View Distance", CC_TYPE_CONTINUOUS },
466         {                           KEY_PAD5,                   -1, COMPUTER_TAB,       "Center View", CC_TYPE_CONTINUOUS },
467         {                                                                        -1,                                    33, COMPUTER_TAB, "View Up", CC_TYPE_CONTINUOUS },
468         {                                                                        -1,                                    32, COMPUTER_TAB, "View Rear", CC_TYPE_CONTINUOUS },
469         {                                                                        -1,                                    34, COMPUTER_TAB, "View Left", CC_TYPE_CONTINUOUS },
470         {                                                                        -1,                                    35, COMPUTER_TAB, "View Right", CC_TYPE_CONTINUOUS },
471
472         {                           KEY_RAPOSTRO,               -1, COMPUTER_TAB,       "Cycle Radar Range" },
473         {                           KEY_C,                              -1, COMPUTER_TAB, "Communications Menu" },
474         {                           -1,                                 -1, -1,                         "Show Objectives" },
475         { KEY_ALTED |               KEY_J,                              -1, COMPUTER_TAB,       "Enter Subspace (End Mission)" },
476         {                           KEY_J,                              -1, TARGET_TAB, "Target Target's Target" },
477         {                           KEY_TAB,                    5,  SHIP_TAB,           "Afterburner", CC_TYPE_CONTINUOUS },
478         
479         {                           KEY_INSERT,         -1, COMPUTER_TAB,       "Increase Weapon Energy" },
480         {                           KEY_DELETE,         -1, COMPUTER_TAB,       "Decrease Weapon Energy" },
481         {                           KEY_HOME,                   -1, COMPUTER_TAB,       "Increase Shield Energy" },
482         {                           KEY_END,                    -1, COMPUTER_TAB,       "Decrease Shield Energy" },
483         {                           KEY_PAGEUP,         -1, COMPUTER_TAB,       "Increase Engine Energy" },
484         {                           KEY_PAGEDOWN,               -1, COMPUTER_TAB,       "Decrease Engine Energy" },
485         { KEY_ALTED |               KEY_D,                              -1, COMPUTER_TAB, "Equalize Energy Settings" },
486
487         {                           KEY_Q,                              7,  COMPUTER_TAB,       "Equalize Shield" },
488         {                           KEY_UP,                             -1, COMPUTER_TAB,       "Augment Forward Shield" },
489         {                           KEY_DOWN,                   -1, COMPUTER_TAB,       "Augment Rear Shield" },
490         {                           KEY_LEFT,                   -1, COMPUTER_TAB,       "Augment Left Shield" },
491         {                           KEY_RIGHT,                  -1, COMPUTER_TAB,       "Augment Right Shield" },
492         {                           KEY_SCROLLOCK,      -1, COMPUTER_TAB,       "Transfer Energy Laser->Shield" },
493         {             KEY_SHIFTED | KEY_SCROLLOCK,      -1, COMPUTER_TAB,       "Transfer Energy Shield->Laser" },
494         {                           -1,                                 -1, -1,                         "Show Damage Popup Window" },   
495
496         {                           -1,                                 -1, SHIP_TAB,           "Bank When Pressed", CC_TYPE_CONTINUOUS },
497         {                                                                        -1,                                    -1, -1,                         "Show NavMap" },
498         { KEY_ALTED |                KEY_E,                             -1, COMPUTER_TAB,       "Add or Remove Escort" },
499         { KEY_ALTED | KEY_SHIFTED | KEY_E,                              -1, COMPUTER_TAB,       "Clear Escort List" },
500         {                                                    KEY_E,                             -1, TARGET_TAB, "Target Next Escort Ship" },
501         { KEY_ALTED     |                                        KEY_R,                         -1, TARGET_TAB, "Target Closest Repair Ship" },
502
503         {                           KEY_U,                              -1, TARGET_TAB, "Target Next Uninspected Cargo" },
504         {             KEY_SHIFTED | KEY_U,                              -1, TARGET_TAB, "Target Previous Uninspected Cargo" },
505         {                                                                        KEY_N,                         -1, TARGET_TAB, "Target Newest Ship In Area" },
506         {                           KEY_K,                              -1, TARGET_TAB, "Target Next Live Turret" },
507         {             KEY_SHIFTED | KEY_K,                              -1, TARGET_TAB, "Target Previous Live Turret" },
508
509         {                                                                        KEY_B,                         -1, TARGET_TAB, "Target Next Hostile Bomb or Bomber" },
510         {             KEY_SHIFTED | KEY_B,                              -1, TARGET_TAB, "Target Previous Hostile Bomb or Bomber" },
511
512         // multiplayer messaging keys
513         {                                                                        KEY_1,                         -1, COMPUTER_TAB,       "(Multiplayer) Message All", CC_TYPE_CONTINUOUS },
514         {                                                                        KEY_2,                         -1, COMPUTER_TAB, "(Multiplayer) Message Friendly", CC_TYPE_CONTINUOUS },
515         {                                                                        KEY_3,                         -1, COMPUTER_TAB, "(Multiplayer) Message Hostile", CC_TYPE_CONTINUOUS },
516         {                                                                        KEY_4,                         -1, COMPUTER_TAB, "(Multiplayer) Message Target", CC_TYPE_CONTINUOUS },
517         { KEY_ALTED     |                                        KEY_X,                         -1, COMPUTER_TAB, "(Multiplayer) Observer zoom to target"},     
518
519         {             KEY_SHIFTED | KEY_PERIOD,         -1, COMPUTER_TAB,       "Increase time compression" },
520         {             KEY_SHIFTED | KEY_COMMA,                  -1, COMPUTER_TAB,       "Decrease time compression" },
521
522         {                                                                        KEY_L,                         -1, COMPUTER_TAB, "Toggle high HUD contrast" }, 
523
524         {                                 KEY_SHIFTED | KEY_N,                          -1, COMPUTER_TAB, "(Multiplayer) Toggle network info"},
525         {                                 KEY_SHIFTED | KEY_END,                        -1, COMPUTER_TAB, "(Multiplayer) Self destruct"},
526
527         {                           -1,                                 -1, -1,                         "" }
528 };
529
530 char *Scan_code_text_german[] = {
531         "",                             "Esc",                          "1",                            "2",                            "3",                            "4",                            "5",                            "6",
532         "7",                            "8",                            "9",                            "0",                            "Akzent '",                             "\xE1",                         "R\x81""cktaste",               "Tab",
533         "Q",                            "W",                            "E",                            "R",                            "T",                            "Z",                            "U",                            "I",
534         "O",                            "P",                            "\x9A",                         "+",                            "Eingabe",                      "Strg Links",                   "A",                            "S",
535
536         "D",                            "F",                            "G",                            "H",                            "J",                            "K",                            "L",                            "\x99",
537         "\xAE",                         "`",                            "Shift",                        "#",                            "Y",                            "X",                            "C",                            "V",
538         "B",                            "N",                            "M",                            ",",                            ".",                            "-",                            "Shift",                        "Num *",
539         "Alt",                          "Leertaste",                    "Hochstell",                    "F1",                           "F2",                           "F3",                           "F4",                           "F5",
540
541         "F6",                           "F7",                           "F8",                           "F9",                           "F10",                          "Pause",                        "Rollen",                       "Num 7",
542         "Num 8",                        "Num 9",                        "Num -",                        "Num 4",                        "Num 5",                        "Num 6",                        "Num +",                        "Num 1",
543         "Num 2",                        "Num 3",                        "Num 0",                        "Num ,",                        "",                             "",                             "",                             "F11",
544         "F12",                          "",                             "",                             "",                             "",                             "",                             "",                             "",
545
546         "",                             "",                             "",                             "",                             "",                             "",                             "",                             "",
547         "",                             "",                             "",                             "",                             "",                             "",                             "",                             "",
548         "",                             "",                             "",                             "",                             "",                             "",                             "",                             "",
549         "",                             "",                             "",                             "",                             "",                             "",                             "",                             "",
550
551         "",                             "",                             "",                             "",                             "",                             "",                             "",                             "",
552         "",                             "",                             "",                             "",                             "",                             "",                             "",                             "",
553         "",                             "",                             "",                             "",                             "",                             "",                             "",                             "",
554         "",                             "",                             "",                             "",                             "Num Eingabe",                  "Strg Rechts",                  "",                             "",
555
556         "",                             "",                             "",                             "",                             "",                             "",                             "",                             "",
557         "",                             "",                             "",                             "",                             "",                             "",                             "",                             "",
558         "",                             "",                             "",                             "",                             "",                             "Num /",                        "",                             "Druck",
559         "Alt",                          "",                             "",                             "",                             "",                             "",                             "",                             "",
560
561         "",                             "",                             "",                             "",                             "",                             "Num Lock",                     "",                             "Pos 1",
562         "Pfeil Hoch",                   "Bild Hoch",                    "",                             "Pfeil Links",                  "",                             "Pfeil Rechts",                 "",                             "Ende",
563         "Pfeil Runter",                         "Bild Runter",                  "Einfg",                        "Entf",                         "",                             "",                             "",                             "",
564         "",                             "",                             "",                             "",                             "",                             "",                             "",                             "",
565
566         "",                             "",                             "",                             "",                             "",                             "",                             "",                             "",
567         "",                             "",                             "",                             "",                             "",                             "",                             "",                             "",
568         "",                             "",                             "",                             "",                             "",                             "",                             "",                             "",
569         "",                             "",                             "",                             "",                             "",                             "",                             "",                             "",
570 };
571
572 char *Joy_button_text_german[] = {
573         "Knopf 1",              "Knopf 2",              "Knopf 3",              "Knopf 4",              "Knopf 5",              "Knopf 6",
574         "Knopf 7",              "Knopf 8",              "Knopf 9",              "Knopf 10",             "Knopf 11",             "Knopf 12",
575         "Knopf 13",             "Knopf 14",             "Knopf 15",             "Knopf 16",             "Knopf 17",             "Knopf 18",
576         "Knopf 19",             "Knopf 20",             "Knopf 21",             "Knopf 22",             "Knopf 23",             "Knopf 24",
577         "Knopf 25",             "Knopf 26",             "Knopf 27",             "Knopf 28",             "Knopf 29",             "Knopf 30",
578         "Knopf 31",             "Knopf 32",             "Hut Hinten",   "Hut Vorne",    "Hut Links",    "Hut Rechts"
579 };
580
581 char *Scan_code_text_french[] = {
582         "",                             "\x90""chap",                   "1",                            "2",                            "3",                            "4",                            "5",                            "6",
583         "7",                            "8",                            "9",                            "0",                            "-",                            "=",                            "Fl\x82""che Ret.",                     "Tab",
584         "Q",                            "W",                            "E",                            "R",                            "T",                            "Y",                            "U",                            "I",
585         "O",                            "P",                            "[",                            "]",                            "Entr\x82""e",                  "Ctrl Gauche",                  "A",                            "S",
586
587         "D",                            "F",                            "G",                            "H",                            "J",                            "K",                            "L",                            ";",
588         "'",                            "`",                            "Maj.",                 "\\",                           "Z",                            "X",                            "C",                            "V",
589         "B",                            "N",                            "M",                            ",",                            ".",                            "/",                            "Maj.",                 "Pav\x82 *",
590         "Alt",                          "Espace",                       "Verr. Maj.",                   "F1",                           "F2",                           "F3",                           "F4",                           "F5",
591
592         "F6",                           "F7",                           "F8",                           "F9",                           "F10",                          "Pause",                        "Arret defil",          "Pav\x82 7",
593         "Pav\x82 8",                    "Pav\x82 9",                    "Pav\x82 -",                    "Pav\x82 4",                    "Pav\x82 5",                    "Pav\x82 6",                    "Pav\x82 +",                    "Pav\x82 1",
594         "Pav\x82 2",                    "Pav\x82 3",                    "Pav\x82 0",                    "Pav\x82 .",                    "",                             "",                             "",                             "F11",
595         "F12",                          "",                             "",                             "",                             "",                             "",                             "",                             "",
596
597         "",                             "",                             "",                             "",                             "",                             "",                             "",                             "",
598         "",                             "",                             "",                             "",                             "",                             "",                             "",                             "",
599         "",                             "",                             "",                             "",                             "",                             "",                             "",                             "",
600         "",                             "",                             "",                             "",                             "",                             "",                             "",                             "",
601
602         "",                             "",                             "",                             "",                             "",                             "",                             "",                             "",
603         "",                             "",                             "",                             "",                             "",                             "",                             "",                             "",
604         "",                             "",                             "",                             "",                             "",                             "",                             "",                             "",
605         "",                             "",                             "",                             "",                             "Pav\x82 Entr",                 "Ctrl Droite",          "",                             "",
606
607         "",                             "",                             "",                             "",                             "",                             "",                             "",                             "",
608         "",                             "",                             "",                             "",                             "",                             "",                             "",                             "",
609         "",                             "",                             "",                             "",                             "",                             "Pav\x82 /",                    "",                             "Impr \x82""cran",
610         "Alt",                          "",                             "",                             "",                             "",                             "",                             "",                             "",
611
612         "",                             "",                             "",                             "",                             "",                             "Verr num",                     "",                             "Orig.",
613         "Fl\x82""che Haut",                     "Page Haut",                    "",                             "Fl\x82""che Gauche",                   "",                             "Fl\x82""che Droite",                   "",                     "Fin",
614         "Fl\x82""che Bas",                      "Page Bas",                     "Inser",                        "Suppr",                        "",                             "",                             "",                             "",
615         "",                             "",                             "",                             "",                             "",                             "",                             "",                             "",
616
617         "",                             "",                             "",                             "",                             "",                             "",                             "",                             "",
618         "",                             "",                             "",                             "",                             "",                             "",                             "",                             "",
619         "",                             "",                             "",                             "",                             "",                             "",                             "",                             "",
620         "",                             "",                             "",                             "",                             "",                             "",                             "",                             "",
621 };
622
623 char *Joy_button_text_french[] = {
624         "Bouton 1",             "Bouton 2",             "Bouton 3",             "Bouton 4",             "Bouton 5",             "Bouton 6",
625         "Bouton 7",             "Bouton 8",             "Bouton 9",             "Bouton 10",            "Bouton 11",            "Bouton 12",
626         "Bouton 13",            "Bouton 14",            "Bouton 15",            "Bouton 16",            "Bouton 17",            "Bouton 18",
627         "Bouton 19",            "Bouton 20",            "Bouton 21",            "Bouton 22",            "Bouton 23",            "Bouton 24",
628         "Bouton 25",            "Bouton 26",            "Bouton 27",            "Bouton 28",            "Bouton 29",            "Bouton 30",
629         "Bouton 31",            "Bouton 32",            "Chapeau Arrière",              "Chapeau Avant",                "Chapeau Gauche",               "Chapeau Droite"
630 };
631
632 //      This is the text that is displayed on the screen for the keys a player selects
633 char *Scan_code_text_english[] = {
634         "",                             "Esc",                  "1",                            "2",                            "3",                            "4",                            "5",                            "6",
635         "7",                            "8",                            "9",                            "0",                            "-",                            "=",                            "Backspace",    "Tab",
636         "Q",                            "W",                            "E",                            "R",                            "T",                            "Y",                            "U",                            "I",
637         "O",                            "P",                            "[",                            "]",                            "Enter",                        "Left Ctrl",    "A",                            "S",
638
639         "D",                            "F",                            "G",                            "H",                            "J",                            "K",                            "L",                            ";",
640         "'",                            "`",                            "Shift",                        "\\",                           "Z",                            "X",                            "C",                            "V",
641         "B",                            "N",                            "M",                            ",",                            ".",                            "/",                            "Shift",                        "Pad *",
642         "Alt",                  "Spacebar",             "Caps Lock",    "F1",                           "F2",                           "F3",                           "F4",                           "F5",
643
644         "F6",                           "F7",                           "F8",                           "F9",                           "F10",                  "Pause",                        "Scroll Lock",  "Pad 7",
645         "Pad 8",                        "Pad 9",                        "Pad -",                        "Pad 4",                        "Pad 5",                        "Pad 6",                        "Pad +",                        "Pad 1",
646         "Pad 2",                        "Pad 3",                        "Pad 0",                        "Pad .",                        "",                             "",                             "",                             "F11",
647         "F12",                  "",                             "",                             "",                             "",                             "",                             "",                             "",
648
649         "",                             "",                             "",                             "",                             "",                             "",                             "",                             "",
650         "",                             "",                             "",                             "",                             "",                             "",                             "",                             "",
651         "",                             "",                             "",                             "",                             "",                             "",                             "",                             "",
652         "",                             "",                             "",                             "",                             "",                             "",                             "",                             "",
653
654         "",                             "",                             "",                             "",                             "",                             "",                             "",                             "",
655         "",                             "",                             "",                             "",                             "",                             "",                             "",                             "",
656         "",                             "",                             "",                             "",                             "",                             "",                             "",                             "",
657         "",                             "",                             "",                             "",                             "Pad Enter",    "Right Ctrl",   "",                             "",
658
659         "",                             "",                             "",                             "",                             "",                             "",                             "",                             "",
660         "",                             "",                             "",                             "",                             "",                             "",                             "",                             "",
661         "",                             "",                             "",                             "",                             "",                             "Pad /",                        "",                             "Print Scrn",
662         "Alt",                  "",                             "",                             "",                             "",                             "",                             "",                             "",
663
664         "",                             "",                             "",                             "",                             "",                             "Num Lock",             "",                             "Home",
665         "Up Arrow",             "Page Up",              "",                             "Left Arrow",   "",                             "Right Arrow",  "",                             "End",
666         "Down Arrow",  "Page Down",     "Insert",               "Delete",               "",                             "",                             "",                             "",
667         "",                             "",                             "",                             "",                             "",                             "",                             "",                             "",
668
669         "",                             "",                             "",                             "",                             "",                             "",                             "",                             "",
670         "",                             "",                             "",                             "",                             "",                             "",                             "",                             "",
671         "",                             "",                             "",                             "",                             "",                             "",                             "",                             "",
672         "",                             "",                             "",                             "",                             "",                             "",                             "",                             "",
673 };
674
675 char *Joy_button_text_english[] = {
676         "Button 1",             "Button 2",             "Button 3",             "Button 4",             "Button 5",             "Button 6",
677         "Button 7",             "Button 8",             "Button 9",             "Button 10",    "Button 11",    "Button 12",
678         "Button 13",    "Button 14",    "Button 15",    "Button 16",    "Button 17",    "Button 18",
679         "Button 19",    "Button 20",    "Button 21",    "Button 22",    "Button 23",    "Button 24",
680         "Button 25",    "Button 26",    "Button 27",    "Button 28",    "Button 29",    "Button 30",
681         "Button 31",    "Button 32",    "Hat Back",             "Hat Forward",  "Hat Left",             "Hat Right"
682 };
683
684 char **Scan_code_text = Scan_code_text_english;
685 char **Joy_button_text = Joy_button_text_english;
686
687 void set_modifier_status()
688 {
689         int i;
690
691         Alt_is_modifier = 0;
692         Shift_is_modifier = 0;
693         Ctrl_is_modifier = 0;
694
695         for (i=0; i<CCFG_MAX; i++) {
696                 if (Control_config[i].key_id < 0)
697                         continue;
698
699                 if (Control_config[i].key_id & KEY_ALTED)
700                         Alt_is_modifier = 1;
701
702                 if (Control_config[i].key_id & KEY_SHIFTED)
703                         Shift_is_modifier = 1;
704
705                 if (Control_config[i].key_id & KEY_CTRLED) {
706                         Assert(0);  // get Alan
707                         Ctrl_is_modifier = 1;
708                 }
709         }
710 }
711
712 int translate_key_to_index(char *key)
713 {
714         int i, index = -1, alt = 0, shift = 0, max_scan_codes;
715
716         if (Lcl_gr) {
717                 max_scan_codes = sizeof(Scan_code_text_german) / sizeof(char *);
718         } else if (Lcl_fr) {
719                 max_scan_codes = sizeof(Scan_code_text_french) / sizeof(char *);
720         } else {
721                 max_scan_codes = sizeof(Scan_code_text_english) / sizeof(char *);
722         }
723
724         // look for modifiers
725         Assert(key);
726         if (!strnicmp(key, "Alt", 3)) {
727                 alt = 1;
728                 key += 3;
729                 if (*key)
730                         key++;
731         }
732
733         char *translated_shift;
734         
735         if(Lcl_gr){
736                 translated_shift = "Shift";
737         } else if(Lcl_fr){      
738                 translated_shift = "Maj.";
739         } else {        
740                 translated_shift = "Shift";
741         }
742
743         if (!strnicmp(key, translated_shift, 5)) {
744                 shift = 1;
745                 key += 5;
746                 if (*key)
747                         key++;
748         }
749
750         // look up index for default key
751         if (*key) {
752                 for (i=0; i<max_scan_codes; i++)
753                         if (!stricmp(key, Scan_code_text_english[i])) {
754                                 index = i;
755                                 break;
756                         }
757
758                 if (i == max_scan_codes)
759                         return -1;
760
761                 if (shift)
762                         index |= KEY_SHIFTED;
763                 if (alt)
764                         index |= KEY_ALTED;
765
766                 // convert scancode to Control_config index
767                 for (i=0; i<CCFG_MAX; i++) {
768                         if (Control_config[i].key_default == index) {
769                                 index = i;
770                                 break;
771                         }
772                 }
773
774                 if (i == CCFG_MAX)
775                         return -1;
776
777                 return index;
778         }
779
780         return -1;
781 }
782
783 // Given the system default key 'key', return the current key that is bound to the function
784 // Both are 'key' and the return value are descriptive strings that can be displayed
785 // directly to the user.  If 'key' isn't a real key or not normally bound to anything,
786 // or there is no key current bound to the function, NULL is returned.
787 char *translate_key(char *key)
788 {
789         int index = -1, code = -1;
790
791         index = translate_key_to_index(key);
792         if (index < 0)
793                 return NULL;
794
795         code = Control_config[index].key_id;
796         Failed_key_index = index;
797         if (code < 0) {
798                 code = Control_config[index].joy_id;
799                 if (code >= 0)
800                         return Joy_button_text[code];
801         }
802
803         return textify_scancode(code);
804 }
805
806 char *textify_scancode(int code)
807 {
808         static char text[40];
809
810         if (code < 0)
811                 return "None";
812
813         *text = 0;
814         if (code & KEY_ALTED) {
815                 if(Lcl_gr){             
816                         strcat(text, "Alt-");
817                 } else if(Lcl_fr){              
818                         strcat(text, "Alt-");
819                 } else {                
820                         strcat(text, "Alt-");
821                 }               
822         }
823
824         if (code & KEY_SHIFTED) {               
825                 if(Lcl_gr){
826                         strcat(text, "Shift-");
827                 } else if(Lcl_fr){              
828                         strcat(text, "Maj.-");
829                 } else {                
830                         strcat(text, "Shift-");
831                 }
832         }
833
834         strcat(text, Scan_code_text[code & KEY_MASK]);
835         return text;
836 }
837 //XSTR:ON
838
839 // initialize common control config stuff - call at game startup after localization has been initialized
840 void control_config_common_init()
841 {
842         if(Lcl_gr){
843                 Scan_code_text = Scan_code_text_german;
844                 Joy_button_text = Joy_button_text_german;
845                 
846                 // swap init bindings for y and z keys
847                 Control_config[TARGET_SHIP_IN_RETICLE].key_default = KEY_Z;
848                 Control_config[TARGET_LAST_TRANMISSION_SENDER].key_default = KEY_ALTED | KEY_Z;
849                 Control_config[REVERSE_THRUST].key_default = KEY_Y;
850                 Control_config[DISARM_MESSAGE].key_default = KEY_SHIFTED | KEY_Y;               
851         } else if(Lcl_fr){
852                 Scan_code_text = Scan_code_text_french;
853                 Joy_button_text = Joy_button_text_french;
854         } else {
855                 Scan_code_text = Scan_code_text_english;
856                 Joy_button_text = Joy_button_text_english;
857         }
858 }