Skip to content

Commit 329974b

Browse files
committed
a few refinements to the new comm node selection feature
1. Don't display the selection arrows until the selection is actually moved, to avoid interfering with the standard selection feature 2. Use static variables and the new `TIMESTAMP` data type 3. Minor cleanup Follow-up to #6736.
1 parent 74beab5 commit 329974b

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

code/hud/hudsquadmsg.cpp

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ static int Msg_key_used; // local variable which tells if the key being p
4444
// with the messaging system was actually used
4545
static int Msg_key; // global which indicates which key was currently pressed
4646
static bool Msg_key_set_from_scripting; // is true if the key was set from scripting and not from a player keypress
47-
static int Msg_mode_timestamp;
47+
static TIMESTAMP Msg_mode_timestamp;
4848
int Msg_instance; // variable which holds ship/wing instance to send the message to
4949
int Msg_shortcut_command; // holds command when using a shortcut key
5050
static int Msg_target_objnum; // id of the current target of the player
@@ -107,9 +107,10 @@ 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. 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
112-
SCP_string Lua_sqd_msg_cat;
110+
static 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+
static 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
112+
static bool Display_selector = false;
113+
static SCP_string Lua_sqd_msg_cat;
113114

114115
#define MAX_KEYS_NO_SCROLL 10
115116
#define MAX_KEYS_USED 12 // maximum number of keys used for the messaging system
@@ -220,8 +221,10 @@ void hud_squadmsg_start()
220221
Num_menu_items = -1; // reset the menu items
221222
First_menu_item = 0;
222223
Selected_menu_item = First_menu_item; // make first menu item a selected object
224+
Display_selector = false;
225+
223226
Squad_msg_mode = SM_MODE_TYPE_SELECT; // start off at the base state
224-
Msg_mode_timestamp = timestamp(DEFAULT_MSG_TIMEOUT); // initialize our timer to bogus value
227+
Msg_mode_timestamp = _timestamp(DEFAULT_MSG_TIMEOUT); // initialize our timer to bogus value
225228
Msg_shortcut_command = -1; // assume no shortcut key being used
226229
Msg_target_objnum = Player_ai->target_objnum; // save the players target object number
227230
Msg_targeted_subsys = Player_ai->targeted_subsys; // save the players currently targted subsystem
@@ -496,10 +499,11 @@ void hud_squadmsg_selection_move_down() {
496499
{
497500
//move down
498501
++Selected_menu_item;
502+
Display_selector = true;
499503

500-
//play scrolling sound and reset the comms window timeout timer, so the window doesn't dissapear while we select our item
504+
//play scrolling sound and reset the comms window timeout timer, so the window doesn't disappear while we select our item
501505
gamesnd_play_iface(InterfaceSounds::SCROLL);
502-
Msg_mode_timestamp = timestamp(DEFAULT_MSG_TIMEOUT);
506+
Msg_mode_timestamp = _timestamp(DEFAULT_MSG_TIMEOUT);
503507

504508
//Move to next page if we went outside of current one
505509
if (Selected_menu_item == MAX_MENU_DISPLAY
@@ -525,10 +529,11 @@ void hud_squadmsg_selection_move_up() {
525529
{
526530
//move up
527531
--Selected_menu_item;
532+
Display_selector = true;
528533

529-
//play scrolling sound and reset the comms window timeout timer, so the window doesn't dissapear while we select our item
534+
//play scrolling sound and reset the comms window timeout timer, so the window doesn't disappear while we select our item
530535
gamesnd_play_iface(InterfaceSounds::SCROLL);
531-
Msg_mode_timestamp = timestamp(DEFAULT_MSG_TIMEOUT);
536+
Msg_mode_timestamp = _timestamp(DEFAULT_MSG_TIMEOUT);
532537

533538
//Move to previous page if it exists
534539
if (Selected_menu_item < 0 && First_menu_item > 0)
@@ -550,7 +555,7 @@ void hud_squadmsg_selection_move_up() {
550555
}
551556

552557
//function that tricks hud_squadmsg_get_key() into thinking player selected a menu item with a num key press
553-
//Yes, this is a pretty much a hack, but it's simple and works with every squadmsq type.
558+
//Yes, this is a pretty much a hack, but it's simple and works with every squadmsg type.
554559
void hud_squadmsg_selection_select() {
555560

556561
//Check if comms menu is up
@@ -2604,7 +2609,7 @@ int hud_squadmsg_do_frame( )
26042609
HUD_reset_clip(); // JAS: Is this needed?
26052610

26062611
if ( Msg_key_used || target_changed ) {
2607-
Msg_mode_timestamp = timestamp(DEFAULT_MSG_TIMEOUT);
2612+
Msg_mode_timestamp = _timestamp(DEFAULT_MSG_TIMEOUT);
26082613
return 1;
26092614
} else
26102615
return 0;
@@ -2925,7 +2930,7 @@ void HudGaugeSquadMessage::render(float /*frametime*/, bool config)
29252930

29262931
for (int i = 0; i < nitems; i++ ) {
29272932
int item_num;
2928-
bool isSelectedItem = First_menu_item + i == First_menu_item + Selected_menu_item;
2933+
bool isSelectedItem = (i == Selected_menu_item);
29292934
char text[255];
29302935

29312936
if (!config) {
@@ -2967,7 +2972,7 @@ void HudGaugeSquadMessage::render(float /*frametime*/, bool config)
29672972
if (MsgItems[First_menu_item + i].active >= 0) {
29682973
// first print an icon to indicate selected item
29692974
item_num = (i + 1) % MAX_MENU_DISPLAY;
2970-
if (isSelectedItem) {
2975+
if (isSelectedItem && Display_selector) {
29712976
renderPrintfWithGauge(sx, sy, EG_SQ1 + i, scale, config, XSTR(">>", 1887), item_num); //allow modders to change string and add number
29722977
}
29732978
// or do the number

0 commit comments

Comments
 (0)