Skip to content

Commit 5864ec4

Browse files
authored
Comms menu controls (#6736)
* Added new keybinds, keycontrol handlers, hudsquadmsg methods for alternate communication menu control scheme * .gitignore update. CMake in VStudio places builds in [Oo]ut/ folder by default * Added support for menu pages * Small formatting cleanup * code cleanup * removed unecessary variable * Updates after code review * Updated comments * XSTR_SIZE correction
1 parent c31c258 commit 5864ec4

7 files changed

Lines changed: 152 additions & 11 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ _ReSharper*/
4242

4343
#Project files
4444
[Bb]uild/
45+
[Oo]ut/
4546

4647
#Subversion files
4748
.svn

code/controlconfig/controlsconfig.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,13 @@ enum IoActionId : int {
297297
JOY_ABS_THROTTLE_AXIS = 127,
298298
JOY_REL_THROTTLE_AXIS = 128,
299299

300+
//!< @n
301+
//! Communication menu controls
302+
//! ----------------------------
303+
COMMS_MENU_MOVE_UP,
304+
COMMS_MENU_MOVE_DOWN,
305+
COMMS_MENU_SELECT,
306+
300307
TOGGLE_HUD_SHADOWS,
301308

302309
CYCLE_PRIMARY_WEAPON_PATTERN,

code/controlconfig/controlsconfigcommon.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,13 @@ void control_config_common_init_bindings() {
272272
(CUSTOM_CONTROL_3, KEY_ALTED | KEY_SHIFTED | KEY_3, -1, COMPUTER_TAB, 1786, "Custom Control 3", CC_TYPE_TRIGGER, true)
273273
(CUSTOM_CONTROL_4, KEY_ALTED | KEY_SHIFTED | KEY_4, -1, COMPUTER_TAB, 1787, "Custom Control 4", CC_TYPE_TRIGGER, true)
274274
(CUSTOM_CONTROL_5, KEY_ALTED | KEY_SHIFTED | KEY_5, -1, COMPUTER_TAB, 1788, "Custom Control 5", CC_TYPE_TRIGGER, true)
275+
276+
277+
//Comms Controls
278+
(COMMS_MENU_MOVE_UP, -1, -1, COMPUTER_TAB, 1883, "Communication Menu Move Up", CC_TYPE_TRIGGER)
279+
(COMMS_MENU_MOVE_DOWN, -1, -1, COMPUTER_TAB, 1884, "Communication Menu Move Down", CC_TYPE_TRIGGER)
280+
(COMMS_MENU_SELECT, -1, -1, COMPUTER_TAB, 1885, "Communication Menu Select", CC_TYPE_TRIGGER)
281+
275282
.end(); // Builder
276283

277284
// init default preset
@@ -438,6 +445,9 @@ SCP_unordered_map<SCP_string, IoActionId> old_text = {
438445
{"Custom Control 3", CUSTOM_CONTROL_3},
439446
{"Custom Control 4", CUSTOM_CONTROL_4},
440447
{"Custom Control 5", CUSTOM_CONTROL_5},
448+
{"Communication Menu Move Up", COMMS_MENU_MOVE_UP},
449+
{"Communication Menu Move Down", COMMS_MENU_MOVE_DOWN},
450+
{"Communication Menu Select", COMMS_MENU_SELECT},
441451
};
442452

443453
// Localization strings for hat positions. Back[0], Forward[1], Left[2], Right[3]
@@ -1164,6 +1174,10 @@ void LoadEnumsIntoActionMap() {
11641174
ADD_ENUM_TO_ACTION_MAP(JOY_ABS_THROTTLE_AXIS)
11651175
ADD_ENUM_TO_ACTION_MAP(JOY_REL_THROTTLE_AXIS)
11661176

1177+
ADD_ENUM_TO_ACTION_MAP(COMMS_MENU_MOVE_UP)
1178+
ADD_ENUM_TO_ACTION_MAP(COMMS_MENU_MOVE_DOWN)
1179+
ADD_ENUM_TO_ACTION_MAP(COMMS_MENU_SELECT)
1180+
11671181

11681182
#undef ADD_ENUM_TO_ACTION_MAP
11691183

code/hud/hudsquadmsg.cpp

Lines changed: 102 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ char Squad_msg_title[256] = "";
107107
mmode_item MsgItems[MAX_MENU_ITEMS];
108108
int Num_menu_items = -1; // number of items for a message menu
109109

110-
int First_menu_item= -1; // index of first item in the menu
110+
int First_menu_item= -1; // index of first item in the menu. This tracks what element of comms options collection is displayed as first option, and displays the next 9 options. Changes only by +/- MAX_MENU_ITEMS (10)
111+
int Selected_menu_item = First_menu_item; //!< index of selected item in the menu. Possible index range: 0 - 9, assuming MAX_MENU_ITEMS == 10, and First_menu_item gets initialized
111112
SCP_string Lua_sqd_msg_cat;
112113

113114
#define MAX_KEYS_NO_SCROLL 10
@@ -217,6 +218,7 @@ void hud_squadmsg_start()
217218

218219
Num_menu_items = -1; // reset the menu items
219220
First_menu_item = 0;
221+
Selected_menu_item = First_menu_item; // make first menu item a selected object
220222
Squad_msg_mode = SM_MODE_TYPE_SELECT; // start off at the base state
221223
Msg_mode_timestamp = timestamp(DEFAULT_MSG_TIMEOUT); // initialize our timer to bogus value
222224
Msg_shortcut_command = -1; // assume no shortcut key being used
@@ -485,6 +487,89 @@ void hud_squadmsg_page_up()
485487
}
486488
}
487489

490+
//Fuctions that allow selection of specific comms menu items with simple up/down/select buttons
491+
void hud_squadmsg_selection_move_down() {
492+
493+
//Check if comms menu is up
494+
if (Player->flags & PLAYER_FLAGS_MSG_MODE)
495+
{
496+
//move down
497+
++Selected_menu_item;
498+
499+
//play scrolling sound and reset the comms window timeout timer, so the window doesn't dissapear while we select our item
500+
gamesnd_play_iface(InterfaceSounds::SCROLL);
501+
Msg_mode_timestamp = timestamp(DEFAULT_MSG_TIMEOUT);
502+
503+
//Move to next page if we went outside of current one
504+
if (Selected_menu_item == MAX_MENU_DISPLAY
505+
&& (First_menu_item + MAX_MENU_DISPLAY < Num_menu_items))
506+
{
507+
hud_squadmsg_page_down();
508+
Selected_menu_item = 0;
509+
}
510+
511+
//Select the first menu item if we went outside items range, so we can loop around
512+
if (First_menu_item + Selected_menu_item >= Num_menu_items)
513+
{
514+
First_menu_item = 0;
515+
Selected_menu_item = First_menu_item;
516+
}
517+
}
518+
}
519+
520+
void hud_squadmsg_selection_move_up() {
521+
522+
//Check if comms menu is up
523+
if (Player->flags & PLAYER_FLAGS_MSG_MODE)
524+
{
525+
//move up
526+
--Selected_menu_item;
527+
528+
//play scrolling sound and reset the comms window timeout timer, so the window doesn't dissapear while we select our item
529+
gamesnd_play_iface(InterfaceSounds::SCROLL);
530+
Msg_mode_timestamp = timestamp(DEFAULT_MSG_TIMEOUT);
531+
532+
//Move to previous page if it exists
533+
if (Selected_menu_item < 0 && First_menu_item > 0)
534+
{
535+
hud_squadmsg_page_up();
536+
Selected_menu_item = MAX_MENU_DISPLAY - 1; //if we're moving to previous page in the first place, we assume it was already populated to the max
537+
}
538+
539+
//Select the last menu item if we went outside items range, so we can loop around
540+
else if (Selected_menu_item < 0)
541+
{
542+
//Assuming MAX_MENU_DISPLAY = 10, set First_menu_item to the nearest lower multiple of 10
543+
//So if we have 85 items in comms menu, looping back from 1st page to last would set First_menu_item to 80
544+
//exactly like pageUp/pageDown does
545+
First_menu_item = ((Num_menu_items - 1) / MAX_MENU_DISPLAY) * MAX_MENU_DISPLAY;
546+
Selected_menu_item = Num_menu_items - 1 - First_menu_item;
547+
}
548+
}
549+
}
550+
551+
//function that tricks hud_squadmsg_get_key() into thinking player selected a menu item with a num key press
552+
//Yes, this is a pretty much a hack, but it's simple and works with every squadmsq type.
553+
void hud_squadmsg_selection_select() {
554+
555+
//Check if comms menu is up
556+
if (Player->flags & PLAYER_FLAGS_MSG_MODE)
557+
{
558+
//Check if selected option is even active
559+
if (!(MsgItems[Selected_menu_item + First_menu_item].active))
560+
{
561+
gamesnd_play_iface(InterfaceSounds::GENERAL_FAIL);
562+
}
563+
else
564+
{
565+
Msg_key_used = 1;
566+
Msg_key = Selected_menu_item + 2; //+1 because menu items on actual menu start from 1, not 0
567+
//Another +1 because methods that use this later do -1. I'm not sure why they do that, but it works
568+
Selected_menu_item = 0; //Reset this value, so the position will reset at the next window
569+
}
570+
}
571+
}
572+
488573
int hud_squadmsg_get_total_keys()
489574
{
490575
int num_keys_used;
@@ -2839,6 +2924,7 @@ void HudGaugeSquadMessage::render(float /*frametime*/, bool config)
28392924

28402925
for (int i = 0; i < nitems; i++ ) {
28412926
int item_num;
2927+
bool isSelectedItem = First_menu_item + i == First_menu_item + Selected_menu_item;
28422928
char text[255];
28432929

28442930
if (!config) {
@@ -2867,22 +2953,30 @@ void HudGaugeSquadMessage::render(float /*frametime*/, bool config)
28672953
by += fl2i(Item_h * scale);
28682954

28692955
// set the text color
2870-
if (!config && (MsgItems[First_menu_item+i].active > 0) ) {
2956+
if (!config && (MsgItems[First_menu_item + i].active > 0)) {
28712957
setGaugeColor(HUD_C_BRIGHT, config);
2872-
} else {
2958+
}
2959+
else if (isSelectedItem) {
2960+
setGaugeColor(HUD_C_NORMAL, config);
2961+
}
2962+
else {
28732963
setGaugeColor(HUD_C_DIM, config);
28742964
}
28752965

2876-
// first do the number
28772966
if (MsgItems[First_menu_item + i].active >= 0) {
2878-
item_num = (i+1) % MAX_MENU_DISPLAY;
2879-
renderPrintfWithGauge(sx, sy, EG_SQ1 + i, scale, config, NOX("%1d."), item_num);
2967+
// first print an icon to indicate selected item
2968+
if (isSelectedItem) {
2969+
renderString(sx, sy, EG_SQ1 + i, ">>", scale, config);
2970+
}
2971+
// or do the number
2972+
else {
2973+
item_num = (i + 1) % MAX_MENU_DISPLAY;
2974+
renderPrintfWithGauge(sx, sy, EG_SQ1 + i, scale, config, NOX("%1d."), item_num);
2975+
}
28802976

28812977
// then the text
28822978
font::force_fit_string(text, 255, fl2i(Ship_name_max_width * scale), scale);
2883-
28842979
renderString(sx + fl2i(Item_offset_x * scale), sy, EG_SQ1 + i, text, scale, config);
2885-
28862980
sy += fl2i(Item_h * scale);
28872981
}
28882982

code/hud/hudsquadmsg.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,11 @@ void hud_enemymsg_toggle(); // debug function to allow messaging of enemies
190190
// Added for voicer implementation
191191
void hud_squadmsg_do_mode( int mode );
192192

193+
// functions for menu item selection with simple up/down/select buttons
194+
void hud_squadmsg_selection_move_down();
195+
void hud_squadmsg_selection_move_up();
196+
void hud_squadmsg_selection_select();
197+
193198
// Added for checking message validity - Mjn
194199
bool hud_squadmsg_ship_order_valid(int shipnum, int order);
195200

code/io/keycontrol.cpp

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,11 @@ int Normal_key_set[] = {
340340
CUSTOM_CONTROL_2,
341341
CUSTOM_CONTROL_3,
342342
CUSTOM_CONTROL_4,
343-
CUSTOM_CONTROL_5
343+
CUSTOM_CONTROL_5,
344+
345+
COMMS_MENU_MOVE_UP,
346+
COMMS_MENU_MOVE_DOWN,
347+
COMMS_MENU_SELECT
344348
};
345349

346350
int Dead_key_set[] = {
@@ -480,7 +484,11 @@ int Non_critical_key_set[] = {
480484
CUSTOM_CONTROL_2,
481485
CUSTOM_CONTROL_3,
482486
CUSTOM_CONTROL_4,
483-
CUSTOM_CONTROL_5
487+
CUSTOM_CONTROL_5,
488+
489+
COMMS_MENU_MOVE_UP,
490+
COMMS_MENU_MOVE_DOWN,
491+
COMMS_MENU_SELECT
484492
};
485493

486494
int Ignored_keys[CCFG_MAX];
@@ -2840,6 +2848,18 @@ int button_function(int n)
28402848
case SQUADMSG_MENU:
28412849
hud_squadmsg_toggle(); // leave the details to the messaging code!!!
28422850
break;
2851+
2852+
case COMMS_MENU_MOVE_DOWN:
2853+
hud_squadmsg_selection_move_down();
2854+
break;
2855+
2856+
case COMMS_MENU_MOVE_UP:
2857+
hud_squadmsg_selection_move_up();
2858+
break;
2859+
2860+
case COMMS_MENU_SELECT:
2861+
hud_squadmsg_selection_select();
2862+
break;
28432863

28442864
// show the mission goals screen
28452865
case SHOW_GOALS:

code/localization/localize.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ bool *Lcl_unexpected_tstring_check = nullptr;
6464
// NOTE: with map storage of XSTR strings, the indexes no longer need to be contiguous,
6565
// but internal strings should still increment XSTR_SIZE to avoid collisions.
6666
// retail XSTR_SIZE = 1570
67-
// #define XSTR_SIZE 1883 // This is the next available ID
67+
// #define XSTR_SIZE 1886 // This is the next available ID
6868

6969
// struct to allow for strings.tbl-determined x offset
7070
// offset is 0 for english, by default

0 commit comments

Comments
 (0)