2 * Copyright (C) Volition, Inc. 1999. All rights reserved.
4 * All source code herein is the property of Volition, Inc. You may not sell
5 * or otherwise commercially exploit the source or things you created based on
10 * $Logfile: /Freespace2/code/Mission/MissionHotKey.cpp $
15 * C module for the Hotkey selection screen
18 * Revision 1.5 2003/05/25 02:30:43 taylor
21 * Revision 1.4 2002/06/09 04:41:22 relnev
22 * added copyright header
24 * Revision 1.3 2002/06/01 07:12:33 relnev
25 * a few NDEBUG updates.
27 * removed a few warnings.
29 * Revision 1.2 2002/05/07 03:16:46 theoddone33
30 * The Great Newline Fix
32 * Revision 1.1.1.1 2002/05/03 03:28:10 root
36 * 5 10/14/99 2:50p Jefff
39 * 4 8/17/99 3:00p Jefff
42 * 3 10/13/98 9:28a Dave
43 * Started neatening up freespace.h. Many variables renamed and
44 * reorganized. Added AlphaColors.[h,cpp]
46 * 2 10/07/98 10:53a Dave
49 * 1 10/07/98 10:49a Dave
51 * 54 6/09/98 5:15p Lawrance
52 * French/German localization
54 * 53 6/09/98 10:31a Hoffoss
55 * Created index numbers for all xstr() references. Any new xstr() stuff
56 * added from here on out should be added to the end if the list. The
57 * current list count can be found in FreeSpace.cpp (search for
60 * 52 5/26/98 11:10a Lawrance
61 * Fix bug where window controls get disabled when F1 pressed twice
63 * 51 5/06/98 10:47a Allender
64 * allow escape pods to be shown on hotkey screen
66 * 50 5/05/98 1:49a Lawrance
67 * Add in missing help overlays
69 * 49 4/25/98 7:40p Allender
70 * fixd some small hotkey stuff. Worked on turret orientation being
71 * correct for multiplayer. new sexpression called end-campaign will will
72 * end the main campaign
74 * 48 4/20/98 12:36a Mike
75 * Make team vs. team work when player is hostile. Several targeting
78 * 47 4/13/98 10:52a Jasen
79 * Updated coords for new Hotkey config screen.
81 * 46 3/11/98 10:33p Allender
82 * made a "hidden" hotkey which is the last hotkey in the set, which means
83 * to hide the ship/wing until the mission is entered.
85 * 45 3/11/98 11:20a Hoffoss
86 * Changed hotkey screen to only show friendly and hostile catagories
87 * (everything non-friendly is hostile).
89 * 44 3/10/98 9:51a Allender
90 * minor fixups to hotkey stuff.
92 * 43 3/07/98 8:09p Allender
93 * maybe restore hotkeys when setting defaults
95 * 42 2/27/98 4:31p Allender
96 * don't show ships on hotkey screen which are hidden to sensors
98 * 41 2/23/98 8:14a John
100 * 40 2/23/98 8:06a John
101 * Externalized some strings
103 * 39 2/22/98 12:19p John
104 * Externalized some strings
106 * 38 2/10/98 2:06p Hoffoss
107 * Eliminated cargo (and NavBouys) from hotkey list.
109 * 37 1/29/98 10:26a Hoffoss
110 * Made changes so arrow buttons repeat scrolling when held down.
112 * 36 1/28/98 6:22p Dave
113 * Made standalone use ~8 megs less memory. Fixed multiplayer submenu
116 * 35 1/26/98 4:42p Allender
117 * fixed restoration of hotkeys when replaying mission. Change the
118 * meaning of "departed wing" to mean anytime a wing "departs" (with any
119 * number of remaining wingmen).
121 * 34 1/19/98 9:37p Allender
122 * Great Compiler Warning Purge of Jan, 1998. Used pragma's in a couple
123 * of places since I was unsure of what to do with code.
125 * 33 1/18/98 5:09p Lawrance
126 * Added support for TEAM_TRAITOR
128 * 32 1/14/98 5:22p Allender
129 * save/restore hotkey selections when replaying the same mission
131 * 31 12/15/97 12:13p Hoffoss
132 * Changed code to allow hotkey listing to repeat scroll when mouse held
135 * 30 12/10/97 2:30p Hoffoss
136 * Removed dead code that isn't being used anymore.
138 * 29 12/09/97 8:12a Allender
139 * changes to hotkey stuff. Don't allow mission defined hotkeys to
140 * override user defined ones once the mission starts
142 * 28 12/03/97 4:16p Hoffoss
143 * Changed sound stuff used in interface screens for interface purposes.
145 * 27 12/01/97 3:39p Hoffoss
146 * Changed naming of headings.
148 * 26 12/01/97 3:29p Jasen
149 * Fixed button coordinates.
151 * 25 12/01/97 2:50p Hoffoss
152 * Improved hotkey screen. F keys are in seperate columns now, and
153 * Shift-F key adds that to item.
155 * 24 11/24/97 10:14p Allender
156 * fixed a couple of problem with assignments in the hotkey screen. alpha
157 * wing problems, num_ships problems
159 * 23 11/19/97 3:40p Allender
160 * don't allow player to get assigned by himself to a hotkey. Don't allow
161 * navbuoys to be assigned either
163 * 22 11/10/97 5:36p Hoffoss
164 * Fixed bug in last fix. :)
169 #include "missionhotkey.h"
170 #include "gamesequence.h"
171 #include "freespace.h"
177 #include "audiostr.h"
180 #include "linklist.h"
181 #include "hudtarget.h"
185 #include "missionscreencommon.h"
188 #include "controlsconfig.h"
189 #include "contexthelp.h"
190 #include "alphacolors.h"
193 static int Key_sets[MAX_KEYED_TARGETS] = {
204 /////////////////////////////
206 static int Hotkey_bits[MAX_SHIPS]; // bitfield indicating which hotkeys are used by each ship
208 static int Hotkey_sets_saved; // have we saved the sets for this mission
210 static int Mission_hotkey_save_timestamp; // timestamp used to tell us when we can save
211 #define HOTKEY_SAVE_TIME 15000 // save sets this number of milliseconds into the mission
215 char name[NAME_LENGTH];
218 HK_save_info Hotkey_saved_info[MAX_HOTKEY_TARGET_ITEMS];
219 int Num_hotkeys_saved;
222 static char *Hotkey_background_fname[GR_NUM_RESOLUTIONS] = {
224 "2_Hotkeys" // GR_1024
227 static char *Hotkey_mask_fname[GR_NUM_RESOLUTIONS] = {
228 "Hotkeys-M", // GR_640
229 "2_Hotkeys-M" // GR_1024
232 //#define GROUP_LIST_X 40
233 //#define GROUP_LIST_W 160
235 // #define ICON_LIST_X 219
236 // #define ICON_LIST_W 8
238 // #define ICON_LIST_X 280
239 // #define ICON_LIST_W 8
241 //#define SHIP_LIST_X 242
242 //#define SHIP_LIST_X2 259
243 //#define SHIP_LIST_W 341
244 //#define SHIP_LIST_W2 324
246 // #define SHIP_LIST_X 302
247 // #define SHIP_LIST_X2 319
248 // #define SHIP_LIST_W 281
249 // #define SHIP_LIST_W2 264
252 // #define LIST_H 280
259 #define HOTKEY_LINE_HEADING 1
260 #define HOTKEY_LINE_WING 2
261 #define HOTKEY_LINE_SHIP 3
262 #define HOTKEY_LINE_SUBSHIP 4 // ship that is in a wing
264 #define WING_FLAG 0x80000
266 #define MAX_LINES 200
267 #define NUM_BUTTONS 10
268 #define LIST_BUTTONS_MAX 40
270 #define SCROLL_UP_BUTTON 0
271 #define SCROLL_DOWN_BUTTON 1
272 #define CANCEL_BUTTON 2
273 #define CLEAR_BUTTON 3
274 #define RESET_BUTTON 4
275 #define ADD_HOTKEY_BUTTON 5
276 #define REMOVE_HOTKEY_BUTTON 6
277 #define HELP_BUTTON 7
278 #define OPTIONS_BUTTON 8
279 #define ACCEPT_BUTTON 9
281 // coords for entire ship box
282 static int Hotkey_list_coords[GR_NUM_RESOLUTIONS][4] = {
303 // coords for big "F9" thing in the corner
304 static int Hotkey_function_name_coords[GR_NUM_RESOLUTIONS][4] = {
326 #define FIELD_LEFT_EDGE 0
336 #define FIELD_RIGHT_EDGE 10
337 // x coords of unseen field boundaries ( | field1 | field2 | ... | )
338 // entried will all be centered in fields except FIELD_SHIP which will be left justified
339 // an edge is named by the field on its left
340 static int Hotkey_field_edge[GR_NUM_RESOLUTIONS][11] = {
342 29, 56, 83, 110, 137, 164, 191, 218, 245, 280, 531
345 47, 91, 135, 179, 223, 267, 311, 355, 399, 448, 849
350 static int Hotkey_function_field_width[GR_NUM_RESOLUTIONS] = {
354 static int Hotkey_wing_icon_x[GR_NUM_RESOLUTIONS] = {
358 static int Hotkey_ship_x[GR_NUM_RESOLUTIONS] = {
364 // pragma pair put into place because of compiler warnings about being unable to inline
365 // the constructor function of the hotkey_buttons set.
366 #pragma warning(disable: 4710)
369 struct hotkey_buttons {
373 UI_BUTTON button; // because we have a class inside this struct, we need the constructor below..
375 hotkey_buttons(char *name, int x1, int y1, int h) : filename(name), x(x1), y(y1), hotspot(h) {}
378 // button definitions
379 static hotkey_buttons Buttons[GR_NUM_RESOLUTIONS][NUM_BUTTONS] = {
383 hotkey_buttons("HK_00", 0, 87, 0), // scroll up
384 hotkey_buttons("HK_01", 0, 131, 1), // scroll down
385 hotkey_buttons("HK_04", 216, 351, 4), // cancel
386 hotkey_buttons("HK_08", 286, 351, 8), // clear
387 hotkey_buttons("HK_09", 362, 351, 9), // reset
388 hotkey_buttons("HK_02", 591, 80, 2), // add hotkey
389 hotkey_buttons("HK_03", 591, 144, 3), // remove hotkey
390 hotkey_buttons("HK_06", 469, 424, 6), // help
391 hotkey_buttons("HK_07", 448, 452, 7), // options
392 hotkey_buttons("HK_05", 561, 411, 5) // accept
395 hotkey_buttons("HKB_00", 1, 94, 0),
396 hotkey_buttons("HKB_01", 1, 133, 1),
397 hotkey_buttons("HKB_02", 15, 342, 2),
398 hotkey_buttons("HKB_03", 84, 342, 3),
399 hotkey_buttons("HKB_04", 161, 342, 4),
400 hotkey_buttons("HKB_05", 539, 5, 5),
401 hotkey_buttons("HKB_06", 539, 44, 6),
402 hotkey_buttons("HKB_07", 539, 431, 7),
403 hotkey_buttons("HKB_08", 539, 455, 8),
404 hotkey_buttons("HKB_09", 575, 432, 9)
409 hotkey_buttons("2_HKB_00", 2, 150, 0),
410 hotkey_buttons("2_HKB_01", 2, 213, 1),
411 hotkey_buttons("2_HKB_02", 24, 548, 2),
412 hotkey_buttons("2_HKB_03", 135, 548, 3),
413 hotkey_buttons("2_HKB_04", 258, 548, 4),
414 hotkey_buttons("2_HKB_05", 862, 8, 5),
415 hotkey_buttons("2_HKB_06", 862, 71, 6),
416 hotkey_buttons("2_HKB_07", 863, 690, 7),
417 hotkey_buttons("2_HKB_08", 862, 728, 8),
418 hotkey_buttons("2_HKB_09", 920, 692, 9)
424 #pragma warning(default: 4710)
428 #define HOTKEY_NUM_TEXT 0
430 #define HOTKEY_NUM_TEXT 6
432 static UI_XSTR Hotkey_text[GR_NUM_RESOLUTIONS][HOTKEY_NUM_TEXT] = {
436 { "Cancel", 1516, 7, 392, UI_XSTR_COLOR_GREEN, -1, &Buttons[GR_640][CANCEL_BUTTON].button },
437 { "Clear", 1517, 85, 392, UI_XSTR_COLOR_GREEN, -1, &Buttons[GR_640][CLEAR_BUTTON].button },
438 { "Reset", 1518, 159, 392, UI_XSTR_COLOR_GREEN, -1, &Buttons[GR_640][RESET_BUTTON].button },
439 { "Help", 1519, 500, 440, UI_XSTR_COLOR_GREEN, -1, &Buttons[GR_640][HELP_BUTTON].button },
440 { "Options", 1520, 479, 464, UI_XSTR_COLOR_GREEN, -1, &Buttons[GR_640][OPTIONS_BUTTON].button },
441 { "Accept", 1521, 573, 413, UI_XSTR_COLOR_GREEN, -1, &Buttons[GR_640][ACCEPT_BUTTON].button }
447 { "Cancel", 1516, 30, 629, UI_XSTR_COLOR_GREEN, -1, &Buttons[GR_1024][CANCEL_BUTTON].button },
448 { "Clear", 1517, 151, 629, UI_XSTR_COLOR_GREEN, -1, &Buttons[GR_1024][CLEAR_BUTTON].button },
449 { "Reset", 1518, 269, 629, UI_XSTR_COLOR_GREEN, -1, &Buttons[GR_1024][RESET_BUTTON].button },
450 { "Help", 1519, 800, 704, UI_XSTR_COLOR_GREEN, -1, &Buttons[GR_1024][HELP_BUTTON].button },
451 { "Options", 1520, 797, 743, UI_XSTR_COLOR_GREEN, -1, &Buttons[GR_1024][OPTIONS_BUTTON].button },
452 { "Accept", 1521, 902, 661, UI_XSTR_COLOR_GREEN, -1, &Buttons[GR_1024][ACCEPT_BUTTON].button }
463 int y; // Y coordinate of line
464 } Hotkey_lines[MAX_LINES];
466 static int Cur_hotkey = 0;
467 static int Scroll_offset;
468 static int Num_lines;
469 static int Selected_line;
470 static int Background_bitmap;
472 static UI_WINDOW Ui_window;
473 static UI_BUTTON List_buttons[LIST_BUTTONS_MAX]; // buttons for each line of text in list
474 //static UI_BUTTON List_region;
476 //////////////////////
479 // function used in a couple of places to get the actual hotkey set number from a key value.
480 // not trivial since our current keysets (F5 - F12) do not have sequential keycodes
481 int mission_hotkey_get_set_num( int k )
485 for (i = 0; i < MAX_KEYED_TARGETS; i++ ) {
486 if ( Key_sets[i] == k ) {
491 Int3(); // get allender
495 // function to maybe restore some hotkeys during the first N seconds of the mission
496 void mission_hotkey_maybe_restore()
500 for ( i = 0; i < Num_hotkeys_saved; i++ ) {
501 // don't process something that has no set
502 if ( Hotkey_saved_info[i].setnum == -1 )
505 // the ship is present, add it to the given set.
506 index = ship_name_lookup(Hotkey_saved_info[i].name);
508 hud_target_hotkey_add_remove( Hotkey_saved_info[i].setnum, &Objects[Ships[index].objnum], HOTKEY_USER_ADDED );
509 Hotkey_saved_info[i].setnum = -1;
514 // ---------------------------------------------------------------------
515 // mission_hotkey_set_defaults()
517 // Set up the hotkey lists for the player based on the mission designer
520 void mission_hotkey_set_defaults()
527 for ( i = 0; i < MAX_KEYED_TARGETS; i++ ) {
528 hud_target_hotkey_clear(i);
531 // set the variable letting us know that we should save the hotkey sets
532 Hotkey_sets_saved = 0;
533 Mission_hotkey_save_timestamp = timestamp(HOTKEY_SAVE_TIME);
535 // if we have hotkeys saved from the previous run of this mission, then simply keep the cleared
536 // sets, and let the restore code take care of it! This works because this function is currently
537 // only called from one place -- after the mission loads.
538 if ( Num_hotkeys_saved > 0 ) {
539 mission_hotkey_maybe_restore();
543 // Check for ships with a hotkey assigned
544 obj_merge_created_list();
545 for ( A = GET_FIRST(&obj_used_list); A !=END_OF_LIST(&obj_used_list); A = GET_NEXT(A) ) {
547 if ( (A == &obj_used_list) || (A->type != OBJ_SHIP) || ((Game_mode & GM_NORMAL) && (A == Player_obj)) ) {
551 Assert(A->instance >= 0 && A->instance < MAX_SHIPS);
552 sp = &Ships[A->instance];
554 if ( sp->hotkey == -1 )
557 // if the hotkey is the last hotkey in the list, then don't add it either since this hotkey is a special
558 // marker to indicate that this ship should remain invisible in the hotkey screen until after mission
560 if ( sp->hotkey == MAX_KEYED_TARGETS )
563 Assert(sp->objnum >= 0);
564 hud_target_hotkey_add_remove( sp->hotkey, &Objects[sp->objnum], HOTKEY_MISSION_FILE_ADDED );
567 // Check for wings with a hotkey assigned
568 for ( i = 0; i < num_wings; i++ ) {
571 if ( wp->hotkey == -1 )
574 // like ships, skip this wing if the hotkey is the last hotkey item
575 if ( wp->hotkey == MAX_KEYED_TARGETS )
578 for ( j = 0; j < wp->current_count; j++ ) {
579 if ( wp->ship_index[j] == -1 )
582 sp = &Ships[wp->ship_index[j]];
583 hud_target_hotkey_add_remove( wp->hotkey, &Objects[sp->objnum], HOTKEY_MISSION_FILE_ADDED );
588 // function to reset the saved hotkeys -- called when a new mission is loaded
589 void mission_hotkey_reset_saved()
591 Num_hotkeys_saved = 0;
594 // next function called when we might want to save the hotkey sets for the player. We will save the hotkey
595 // sets N seconds into the mission
596 void mission_hotkey_maybe_save_sets()
599 htarget_list *hitem, *plist;
602 if ( !timestamp_elapsed(Mission_hotkey_save_timestamp) ) {
603 mission_hotkey_maybe_restore();
607 // no processing if we have saved them.
608 if ( Hotkey_sets_saved )
611 for ( i = 0; i < MAX_HOTKEY_TARGET_ITEMS; i++ )
612 Hotkey_saved_info[i].setnum = -1;
614 Num_hotkeys_saved = 0;
615 hkp = &(Hotkey_saved_info[0]);
617 for ( i = 0; i < MAX_KEYED_TARGETS; i++ ) {
619 // get the list. do nothing if list is empty
620 plist = &(Player->keyed_targets[i]);
624 for ( hitem = GET_FIRST(plist); hitem != END_OF_LIST(plist); hitem = GET_NEXT(hitem) ) {
625 Assert( Num_hotkeys_saved < MAX_HOTKEY_TARGET_ITEMS );
627 strcpy( hkp->name, Ships[hitem->objp->instance].ship_name );
633 Hotkey_sets_saved = 1;
636 // function which gets called from MissionParse to maybe add a ship or wing to a hotkey set.
637 // this intermediate function is needed so that we don't blast over possibly saved hotkey sets
638 void mission_hotkey_mf_add( int set, int objnum, int how_to_add )
640 // if we are restoring hotkeys, and the timer hasn't elapsed, then return and let the
641 // hotkey restoration code deal with it
642 if ( Num_hotkeys_saved && !timestamp_elapsed(Mission_hotkey_save_timestamp) )
645 // we can add it to the set
646 hud_target_hotkey_add_remove( set, &Objects[objnum], how_to_add );
649 void mission_hotkey_validate()
651 htarget_list *hitem, *plist;
655 for ( i = 0; i < MAX_KEYED_TARGETS; i++ ) {
656 plist = &(Players[Player_num].keyed_targets[i]);
657 if ( EMPTY( plist ) ) // no items in list, then do nothing
660 hitem = GET_FIRST(plist);
661 while ( hitem != END_OF_LIST(plist) ) {
663 // ensure this object is still valid and in the obj_used_list
665 for ( A = GET_FIRST(&obj_used_list); A !=END_OF_LIST(&obj_used_list); A = GET_NEXT(A) ) {
666 if ( A->signature == hitem->objp->signature ) {
671 if ( obj_valid == FALSE ) {
674 temp = GET_NEXT(hitem);
675 list_remove( plist, hitem );
676 list_append( &htarget_free_list, hitem );
681 hitem = GET_NEXT( hitem );
687 // get the Hotkey_bits of a whole wing (bits must be set in all ships of wing for a hotkey bit to be set)
688 int get_wing_hotkeys(int n)
690 int i, total = 0xffffffff;
692 Assert((n >= 0) && (n < num_wings));
693 for (i=0; i<Wings[n].current_count; i++) {
696 // don't count the player ship for the total -- you cannot assign the player since bad things
697 // can happen on the hud.
698 ship_index = Wings[n].ship_index[i];
699 if ( &Ships[ship_index] == Player_ship )
702 total &= Hotkey_bits[Wings[n].ship_index[i]];
708 // add a line of hotkey smuck to end of list
709 int hotkey_line_add(char *text, int type, int index, int y)
711 if (Num_lines >= MAX_LINES)
714 Hotkey_lines[Num_lines].label = text;
715 Hotkey_lines[Num_lines].type = type;
716 Hotkey_lines[Num_lines].index = index;
717 Hotkey_lines[Num_lines].y = y;
721 // insert a line of hotkey smuck before line 'n'.
722 int hotkey_line_insert(int n, char *text, int type, int index)
726 if (Num_lines >= MAX_LINES)
731 Hotkey_lines[z] = Hotkey_lines[z - 1];
735 Hotkey_lines[z].label = text;
736 Hotkey_lines[z].type = type;
737 Hotkey_lines[z].index = index;
741 // insert a line of hotkey smuck somewhere between 'start' and end of list such that it is
743 int hotkey_line_add_sorted(char *text, int type, int index, int start)
747 if (Num_lines >= MAX_LINES)
751 while ((z >= start) && ((Hotkey_lines[z].type == HOTKEY_LINE_SUBSHIP) || (stricmp(text, Hotkey_lines[z].label) < 0)))
755 while ((z < Num_lines) && (Hotkey_lines[z].type == HOTKEY_LINE_SUBSHIP))
758 return hotkey_line_insert(z, text, type, index);
761 int hotkey_get_team(int i)
763 if (Ships[i].team == Player_ship->team)
764 return TEAM_FRIENDLY;
769 int hotkey_build_team_listing(int team, int y)
773 int i, j, s, z, start;
774 int font_height = gr_get_font_height();
776 for (i=0; i<MAX_SHIPS; i++)
777 if (hotkey_get_team(i) == team)
783 if (team == Player_ship->team)
784 str = XSTR( "Friendly ships", 402);
786 str = XSTR( "Enemy ships", 403);
789 hotkey_line_add(str, HOTKEY_LINE_HEADING, 0, y);
794 // next loop used to loop through max ships, comparing team values. MWA changed this to iterate
795 // through object list. Seemed safer since it doesn't rely on the team value getting reset to
796 // a bogus value between missions
797 //for (i=0; i<MAX_SHIPS; i++) {
798 // if ((Ships[i].team == team) && (Ships[i].wingnum < 0)) {
799 // hotkey_line_add_sorted(Ships[i].ship_name, HOTKEY_LINE_SHIP, i, start);
802 for ( so = GET_FIRST(&Ship_obj_list); so != END_OF_LIST(&Ship_obj_list); so = GET_NEXT(so) ) {
805 // don't process non-ships, or the player ship
806 if ( (Game_mode & GM_NORMAL) && (so->objnum == OBJ_INDEX(Player_obj)) )
809 shipnum = Objects[so->objnum].instance;
811 // filter out cargo containers, navbouys, etc
812 if ( (Ship_info[Ships[shipnum].ship_info_index].flags & SIF_HARMLESS) && !(Ship_info[Ships[shipnum].ship_info_index].flags & SIF_ESCAPEPOD) )
815 // don't process non-ships (dunno what that would be, though).
816 if (Ship_info[Ships[shipnum].ship_info_index].flags & SIF_NO_SHIP_TYPE)
819 // don't process ships invisible to sensors, dying or departing
820 if ( Ships[shipnum].flags & (SF_HIDDEN_FROM_SENSORS|SF_DYING|SF_DEPARTING) )
823 // if a ship's hotkey is the last hotkey on the list, then maybe make the hotkey -1 if
824 // we are now in mission. Otherwise, skip this ship
825 if ( Ships[shipnum].hotkey == MAX_KEYED_TARGETS ) {
826 if ( !(Game_mode & GM_IN_MISSION) )
827 continue; // skip to next ship
828 Ships[shipnum].hotkey = -1;
831 // be sure this ship isn't in a wing, and that the teams match
832 if ( (hotkey_get_team(shipnum) == team) && (Ships[shipnum].wingnum < 0) ) {
833 hotkey_line_add_sorted(Ships[shipnum].ship_name, HOTKEY_LINE_SHIP, shipnum, start);
837 for (i=0; i<num_wings; i++) {
838 if (Wings[i].current_count && (hotkey_get_team( Wings[i].ship_index[Wings[i].special_ship] ) == team)) {
840 // special check for the player's wing. If he's in a wing, and the only guy left, don't
842 if ( (Player_ship->wingnum == i) && (Wings[i].current_count == 1) )
845 // if a ship's hotkey is the last hotkey on the list, then maybe make the hotkey -1 if
846 // we are now in mission. Otherwise, skip this ship
847 if ( Wings[i].hotkey == MAX_KEYED_TARGETS ) {
848 if ( !(Game_mode & GM_IN_MISSION) )
849 continue; // skip to next ship
850 Wings[i].hotkey = -1;
853 // don't add any wing data whose ships are hidden from sensors
854 for ( j = 0; j < Wings[i].current_count; j++ ) {
855 if ( Ships[Wings[i].ship_index[j]].flags & SF_HIDDEN_FROM_SENSORS )
858 // if we didn't reach the end of the list, don't display the wing
859 if ( j < Wings[i].current_count )
862 z = hotkey_line_add_sorted(Wings[i].name, HOTKEY_LINE_WING, i, start);
863 if (Wings[i].flags & WF_EXPANDED) {
864 for (j=0; j<Wings[i].current_count; j++) {
865 s = Wings[i].ship_index[j];
866 z = hotkey_line_insert(z + 1, Ships[s].ship_name, HOTKEY_LINE_SUBSHIP, s);
872 z = HOTKEY_LINE_HEADING;
873 for (i=start; i<Num_lines; i++) {
874 if (Hotkey_lines[i].type == HOTKEY_LINE_SUBSHIP)
877 y += font_height + 2;
879 Hotkey_lines[i].y = y;
882 y += font_height + 8;
886 void hotkey_build_listing()
892 y = hotkey_build_team_listing(TEAM_FRIENDLY, y);
893 y = hotkey_build_team_listing(TEAM_HOSTILE, y);
896 int hotkey_line_query_visible(int n)
900 if ((n < 0) || (n >= Num_lines))
903 y = Hotkey_lines[n].y - Hotkey_lines[Scroll_offset].y;
904 if ((y < 0) || (y + gr_get_font_height() > Hotkey_list_coords[gr_screen.res][3]))
910 void hotkey_scroll_screen_up()
914 Assert(Selected_line > Scroll_offset);
915 while (!hotkey_line_query_visible(Selected_line) || (Hotkey_lines[Selected_line].type == HOTKEY_LINE_HEADING))
918 gamesnd_play_iface(SND_SCROLL);
921 gamesnd_play_iface(SND_GENERAL_FAIL);
924 void hotkey_scroll_line_up()
926 if (Selected_line > 1) {
928 while (Hotkey_lines[Selected_line].type == HOTKEY_LINE_HEADING)
931 if (Selected_line < Scroll_offset)
932 Scroll_offset = Selected_line;
934 gamesnd_play_iface(SND_SCROLL);
937 gamesnd_play_iface(SND_GENERAL_FAIL);
940 void hotkey_scroll_screen_down()
942 if (Hotkey_lines[Num_lines - 1].y + gr_get_font_height() > Hotkey_lines[Scroll_offset].y + Hotkey_list_coords[gr_screen.res][3]) {
944 while (!hotkey_line_query_visible(Selected_line) || (Hotkey_lines[Selected_line].type == HOTKEY_LINE_HEADING)) {
946 Assert(Selected_line < Num_lines);
949 gamesnd_play_iface(SND_SCROLL);
952 gamesnd_play_iface(SND_GENERAL_FAIL);
955 void hotkey_scroll_line_down()
957 if (Selected_line < Num_lines - 1) {
959 while (Hotkey_lines[Selected_line].type == HOTKEY_LINE_HEADING)
962 Assert(Selected_line > Scroll_offset);
963 while (!hotkey_line_query_visible(Selected_line))
966 gamesnd_play_iface(SND_SCROLL);
969 gamesnd_play_iface(SND_GENERAL_FAIL);
976 if (Hotkey_lines[Selected_line].type == HOTKEY_LINE_WING) {
977 i = Hotkey_lines[Selected_line].index;
978 Wings[i].flags ^= WF_EXPANDED;
979 hotkey_build_listing();
980 for (z=0; z<Num_lines; z++)
981 if ((Hotkey_lines[z].type == HOTKEY_LINE_WING) && (Hotkey_lines[z].index == i)) {
991 htarget_list *hitem, *plist;
993 for (i=0; i<MAX_SHIPS; i++)
996 for ( i=0; i<MAX_KEYED_TARGETS; i++ ) {
997 plist = &(Players[Player_num].keyed_targets[i]);
998 if ( EMPTY(plist) ) // no items in list, then do nothing
1001 for ( hitem = GET_FIRST(plist); hitem != END_OF_LIST(plist); hitem = GET_NEXT(hitem) ) {
1002 Assert(hitem->objp->type == OBJ_SHIP);
1003 Hotkey_bits[hitem->objp->instance] |= (1 << i);
1008 void clear_hotkeys()
1012 z = Hotkey_lines[Selected_line].type;
1013 if (z == HOTKEY_LINE_WING) {
1014 z = Hotkey_lines[Selected_line].index;
1015 b = ~get_wing_hotkeys(z);
1016 for (i=0; i<Wings[z].current_count; i++)
1017 Hotkey_bits[Wings[z].ship_index[i]] &= b;
1019 } else if ((z == HOTKEY_LINE_SHIP) || (z == HOTKEY_LINE_SUBSHIP)) {
1020 Hotkey_bits[Hotkey_lines[Selected_line].index] = 0;
1029 for (i=0; i<MAX_KEYED_TARGETS; i++) {
1030 hud_target_hotkey_clear(i);
1031 for ( so = GET_FIRST(&Ship_obj_list); so != END_OF_LIST(&Ship_obj_list); so = GET_NEXT(so) ) {
1032 if ( Hotkey_bits[Objects[so->objnum].instance] & (1 << i) ) {
1033 hud_target_hotkey_add_remove(i, &Objects[so->objnum], HOTKEY_USER_ADDED );
1039 void add_hotkey(int hotkey)
1043 z = Hotkey_lines[Selected_line].type;
1044 if (z == HOTKEY_LINE_WING) {
1045 z = Hotkey_lines[Selected_line].index;
1046 for (i=0; i<Wings[z].current_count; i++)
1047 Hotkey_bits[Wings[z].ship_index[i]] |= (1 << hotkey);
1049 } else if ((z == HOTKEY_LINE_SHIP) || (z == HOTKEY_LINE_SUBSHIP)) {
1050 Hotkey_bits[Hotkey_lines[Selected_line].index] |= (1 << hotkey);
1054 void remove_hotkey()
1058 z = Hotkey_lines[Selected_line].type;
1059 if (z == HOTKEY_LINE_WING) {
1060 z = Hotkey_lines[Selected_line].index;
1061 for (i=0; i<Wings[z].current_count; i++)
1062 Hotkey_bits[Wings[z].ship_index[i]] &= ~(1 << Cur_hotkey);
1064 } else if ((z == HOTKEY_LINE_SHIP) || (z == HOTKEY_LINE_SUBSHIP)) {
1065 Hotkey_bits[Hotkey_lines[Selected_line].index] &= ~(1 << Cur_hotkey);
1069 void hotkey_button_pressed(int n)
1072 case SCROLL_UP_BUTTON:
1073 hotkey_scroll_screen_up();
1076 case SCROLL_DOWN_BUTTON:
1077 hotkey_scroll_screen_down();
1080 case ADD_HOTKEY_BUTTON:
1081 add_hotkey(Cur_hotkey);
1082 gamesnd_play_iface(SND_USER_SELECT);
1085 case REMOVE_HOTKEY_BUTTON:
1087 gamesnd_play_iface(SND_USER_SELECT);
1092 // fall through to CANCEL_BUTTON
1095 mission_hotkey_exit();
1096 gamesnd_play_iface(SND_USER_SELECT);
1100 launch_context_help();
1101 gamesnd_play_iface(SND_HELP_PRESSED);
1104 case OPTIONS_BUTTON:
1105 gameseq_post_event(GS_EVENT_OPTIONS_MENU);
1106 gamesnd_play_iface(SND_USER_SELECT);
1111 gamesnd_play_iface(SND_USER_SELECT);
1116 gamesnd_play_iface(SND_USER_SELECT);
1121 // ---------------------------------------------------------------------
1122 // mission_hotkey_init()
1124 // Initialize the hotkey assignment screen system. Called when GS_STATE_HOTKEY_SCREEN
1127 void mission_hotkey_init()
1132 // pause all beam weapon sounds
1133 beam_pause_sounds();
1135 // pause all game music
1136 audiostream_pause_all();
1139 common_set_interface_palette(); // set the interface palette
1140 Ui_window.create(0, 0, gr_screen.max_w, gr_screen.max_h, 0);
1141 Ui_window.set_mask_bmap(Hotkey_mask_fname[gr_screen.res]);
1143 for (i=0; i<NUM_BUTTONS; i++) {
1144 b = &Buttons[gr_screen.res][i];
1146 b->button.create(&Ui_window, "", b->x, b->y, 60, 30, i < 2 ? 1 : 0, 1);
1147 // set up callback for when a mouse first goes over a button
1148 b->button.set_highlight_action(common_play_highlight_sound);
1149 b->button.set_bmaps(b->filename);
1150 b->button.link_hotspot(b->hotspot);
1153 // add all xstr text
1154 for(i=0; i<HOTKEY_NUM_TEXT; i++) {
1155 Ui_window.add_XSTR(&Hotkey_text[gr_screen.res][i]);
1158 for (i=0; i<LIST_BUTTONS_MAX; i++) {
1159 List_buttons[i].create(&Ui_window, "", 0, 0, 60, 30, (i < 2), 1);
1160 List_buttons[i].hide();
1161 List_buttons[i].disable();
1164 // set up hotkeys for buttons so we draw the correct animation frame when a key is pressed
1165 Buttons[gr_screen.res][SCROLL_UP_BUTTON].button.set_hotkey(KEY_PAGEUP);
1166 Buttons[gr_screen.res][SCROLL_DOWN_BUTTON].button.set_hotkey(KEY_PAGEDOWN);
1168 // ensure help overlay is off
1169 help_overlay_set_state(HOTKEY_OVERLAY,0);
1171 // load in relevant bitmaps
1172 Background_bitmap = bm_load(Hotkey_background_fname[gr_screen.res]);
1173 if (Background_bitmap < 0) {
1174 // bitmap didnt load -- this is bad
1177 Wing_bmp = bm_load("WingDesignator");
1179 // bitmap didnt load -- this is bad
1185 hotkey_build_listing();
1188 // ---------------------------------------------------------------------
1189 // mission_hotkey_close()
1191 // Cleanup the hotkey assignment screen system. Called when GS_STATE_HOTKEY_SCREEN
1194 void mission_hotkey_close()
1196 if (Background_bitmap)
1197 bm_unload(Background_bitmap);
1199 bm_unload(Wing_bmp);
1201 // unload the overlay bitmap
1203 help_overlay_unload(HOTKEY_OVERLAY);
1206 // unpause all beam weapon sounds
1207 beam_unpause_sounds();
1209 // unpause all game music
1210 audiostream_unpause_all();
1212 Ui_window.destroy();
1213 common_free_interface_palette(); // restore game palette
1217 // ---------------------------------------------------------------------
1218 // mission_hotkey_do_frame()
1220 // Called once per frame to process user input for the Hotkey Assignment Screen
1222 void mission_hotkey_do_frame(float frametime)
1225 int i, k, w, h, y, z, line, hotkeys;
1226 int font_height = gr_get_font_height();
1227 int select_tease_line = -1; // line mouse is down on, but won't be selected until button released
1230 if ( help_overlay_active(HOTKEY_OVERLAY) ) {
1231 Buttons[gr_screen.res][HELP_BUTTON].button.reset_status();
1232 Ui_window.set_ignore_gadgets(1);
1235 k = Ui_window.process() & ~KEY_DEBUGGED;
1237 if ( (k > 0) || B1_JUST_RELEASED ) {
1238 if ( help_overlay_active(HOTKEY_OVERLAY) ) {
1239 help_overlay_set_state(HOTKEY_OVERLAY, 0);
1240 Ui_window.set_ignore_gadgets(0);
1245 if ( !help_overlay_active(HOTKEY_OVERLAY) ) {
1246 Ui_window.set_ignore_gadgets(0);
1250 case KEY_DOWN: // scroll list down
1251 hotkey_scroll_line_down();
1254 case KEY_UP: // scroll list up
1255 hotkey_scroll_line_up();
1258 case KEY_PAGEDOWN: // scroll list down
1259 hotkey_scroll_screen_down();
1262 case KEY_PAGEUP: // scroll list up
1263 hotkey_scroll_screen_up();
1266 case KEY_CTRLED | KEY_ENTER:
1268 // fall through to next state -- allender changed this behavior since ESC should always cancel, no?
1271 mission_hotkey_exit();
1282 add_hotkey(Cur_hotkey);
1291 gameseq_post_event(GS_EVENT_OPTIONS_MENU);
1294 case KEY_CTRLED | KEY_R:
1298 case KEY_CTRLED | KEY_C:
1304 for (i=0; i<MAX_KEYED_TARGETS; i++) {
1305 if (k == Key_sets[i])
1308 if (k == (Key_sets[i] | KEY_SHIFTED))
1312 // handle pressed buttons
1313 for (i=0; i<NUM_BUTTONS; i++) {
1314 if (Buttons[gr_screen.res][i].button.pressed()) {
1315 hotkey_button_pressed(i);
1316 break; // only need to handle 1 button @ a time
1320 for (i=0; i<LIST_BUTTONS_MAX; i++) {
1321 // check for tease line
1322 if (List_buttons[i].button_down()) {
1323 select_tease_line = i + Scroll_offset;
1326 // check for selected list item
1327 if (List_buttons[i].pressed()) {
1328 Selected_line = i + Scroll_offset;
1329 List_buttons[i].get_mouse_pos(&z, NULL);
1330 z += Hotkey_list_coords[gr_screen.res][0]; // adjust to full screen space
1331 if ((z >= Hotkey_wing_icon_x[gr_screen.res]) && (z < (Hotkey_wing_icon_x[gr_screen.res]) + Hotkey_function_field_width[gr_screen.res])) {
1336 if (List_buttons[i].double_clicked()) {
1337 Selected_line = i + Scroll_offset;
1339 switch (Hotkey_lines[Selected_line].type) {
1340 case HOTKEY_LINE_WING:
1341 hotkeys = get_wing_hotkeys(Hotkey_lines[Selected_line].index);
1344 case HOTKEY_LINE_SHIP:
1345 case HOTKEY_LINE_SUBSHIP:
1346 hotkeys = Hotkey_bits[Hotkey_lines[Selected_line].index];
1350 if (hotkeys != -1) {
1351 if (hotkeys & (1 << Cur_hotkey))
1354 add_hotkey(Cur_hotkey);
1359 if (Background_bitmap >= 0) {
1360 gr_set_bitmap(Background_bitmap);
1367 gr_init_color(&circle_color, 160, 160, 0);
1369 // draw the big "F10" in the little box
1371 gr_set_color_fast(&Color_text_normal);
1372 strcpy(buf, Scan_code_text[Key_sets[Cur_hotkey]]);
1373 gr_get_string_size(&w, &h, buf);
1374 gr_printf(Hotkey_function_name_coords[gr_screen.res][0] + (Hotkey_function_name_coords[gr_screen.res][2] - w) / 2, Hotkey_function_name_coords[gr_screen.res][1], buf);
1377 line = Scroll_offset;
1378 while (hotkey_line_query_visible(line)) {
1379 z = Hotkey_lines[line].index;
1380 y = Hotkey_list_coords[gr_screen.res][1] + Hotkey_lines[line].y - Hotkey_lines[Scroll_offset].y;
1382 switch (Hotkey_lines[line].type) {
1383 case HOTKEY_LINE_HEADING:
1384 gr_set_color_fast(&Color_text_heading);
1386 gr_get_string_size(&w, &h, Hotkey_lines[line].label);
1388 gr_line(Hotkey_list_coords[gr_screen.res][0], i, Hotkey_ship_x[gr_screen.res] - 2, i);
1389 gr_line(Hotkey_ship_x[gr_screen.res] + w + 1, i, Hotkey_list_coords[gr_screen.res][0] + Hotkey_list_coords[gr_screen.res][2], i);
1392 case HOTKEY_LINE_WING:
1393 gr_set_bitmap(Wing_bmp);
1394 bm_get_info(Wing_bmp, NULL, &h, NULL);
1395 i = y + font_height / 2 - h / 2 - 1;
1396 gr_bitmap(Hotkey_wing_icon_x[gr_screen.res], i);
1398 // i = y + font_height / 2 - 1;
1399 // gr_set_color_fast(&circle_color);
1400 // gr_circle(ICON_LIST_X + 4, i, 5);
1402 // gr_set_color_fast(&Color_bright);
1403 // gr_line(ICON_LIST_X, i, ICON_LIST_X + 2, i);
1404 // gr_line(ICON_LIST_X + 4, i - 4, ICON_LIST_X + 4, i - 2);
1405 // gr_line(ICON_LIST_X + 6, i, ICON_LIST_X + 8, i);
1406 // gr_line(ICON_LIST_X + 4, i + 2, ICON_LIST_X + 4, i + 4);
1408 hotkeys = get_wing_hotkeys(Hotkey_lines[line].index);
1411 case HOTKEY_LINE_SHIP:
1412 case HOTKEY_LINE_SUBSHIP:
1413 hotkeys = Hotkey_bits[Hotkey_lines[line].index];
1420 if (Hotkey_lines[line].type != HOTKEY_LINE_HEADING) {
1421 List_buttons[line - Scroll_offset].update_dimensions(Hotkey_list_coords[gr_screen.res][0], y, Hotkey_list_coords[gr_screen.res][0] + Hotkey_list_coords[gr_screen.res][2] - Hotkey_list_coords[gr_screen.res][0], font_height);
1422 List_buttons[line - Scroll_offset].enable();
1423 if (hotkeys & (1 << Cur_hotkey)) {
1424 if (line == Selected_line)
1425 gr_set_color_fast(&Color_text_active_hi);
1427 gr_set_color_fast(&Color_text_active);
1430 if (line == Selected_line)
1431 gr_set_color_fast(&Color_text_selected);
1432 else if (line == select_tease_line)
1433 gr_set_color_fast(&Color_text_subselected);
1435 gr_set_color_fast(&Color_text_normal);
1439 List_buttons[line - Scroll_offset].disable();
1442 // print active hotkeys associated for this line
1444 for (i=0; i<MAX_KEYED_TARGETS; i++) {
1445 if (hotkeys & (1 << i)) {
1446 gr_printf(Hotkey_list_coords[gr_screen.res][0] + Hotkey_function_field_width[gr_screen.res]*i, y, Scan_code_text[Key_sets[i]]);
1451 for (i=0; i<MAX_KEYED_TARGETS; i++) {
1452 if (hotkeys & (1 << i)) {
1453 strcat(buf, Scan_code_text[Key_sets[i]]);
1458 Assert(strlen(buf) > 1);
1459 buf[strlen(buf) - 2] = 0; // lose the ", " on the end
1461 gr_force_fit_string(buf, 255, GROUP_LIST_W);
1462 gr_printf(GROUP_LIST_X, y, buf);*/
1465 // draw ship/wing name
1466 strcpy(buf, Hotkey_lines[line].label);
1467 if (Hotkey_lines[line].type == HOTKEY_LINE_SUBSHIP) {
1469 gr_force_fit_string(buf, 255, Hotkey_list_coords[gr_screen.res][0] + Hotkey_list_coords[gr_screen.res][2] - (Hotkey_ship_x[gr_screen.res]+20));
1470 gr_printf(Hotkey_ship_x[gr_screen.res]+20, y, buf);
1472 gr_force_fit_string(buf, 255, Hotkey_list_coords[gr_screen.res][0] + Hotkey_list_coords[gr_screen.res][2] - Hotkey_ship_x[gr_screen.res]);
1473 gr_printf(Hotkey_ship_x[gr_screen.res], y, buf);
1479 i = line - Scroll_offset;
1480 while (i < LIST_BUTTONS_MAX)
1481 List_buttons[i++].disable();
1483 // blit help overlay if active
1484 help_overlay_maybe_blit(HOTKEY_OVERLAY);
1489 void mission_hotkey_exit()
1491 gameseq_post_event(GS_EVENT_PREVIOUS_STATE);