Skip to content

Commit

Permalink
Detect invalid menu item selections in L4D-based games (#1543)
Browse files Browse the repository at this point in the history
Some games have implemented CHudMenu::SelectMenuItem to close the menu
even if an invalid slot has been selected, which causes us a problem as
we'll never get any notification from the client and we'll keep the menu
alive on our end indefinitely. For these games, pretend that every slot
is valid for selection so we're guaranteed to get a menuselect command.
We don't want to do this for every game as the common SelectMenuItem
implementation ignores invalid selections and keeps the menu open, which
is a much nicer user experience.

Fixes #1385
  • Loading branch information
asherkin committed Jul 18, 2021
1 parent f8f5a18 commit 32d951e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
19 changes: 17 additions & 2 deletions core/MenuStyle_Radio.cpp
Expand Up @@ -61,7 +61,7 @@ unsigned int g_RadioMenuTimeout = 0;
#define MAX_MENUSLOT_KEYS 10

static unsigned int s_RadioMaxPageItems = MAX_MENUSLOT_KEYS;

static bool s_RadioClosesOnInvalidSlot = false;

CRadioStyle::CRadioStyle()
{
Expand Down Expand Up @@ -124,6 +124,12 @@ void CRadioStyle::OnSourceModLevelChange(const char *mapName)
}
}

const char *closes = g_pGameConf->GetKeyValue("RadioMenuClosesOnInvalidSlot");
if (closes != nullptr && strcmp(closes, "yes") == 0)
{
s_RadioClosesOnInvalidSlot = true;
}

g_Menus.SetDefaultStyle(this);

g_UserMsgs.HookUserMessage(g_ShowMenuId, this, false);
Expand Down Expand Up @@ -464,7 +470,16 @@ void CRadioMenuPlayer::Radio_Init(int keys, const char *title, const char *text)
sizeof(display_pkt),
text);
}
display_keys = keys;

// Some games have implemented CHudMenu::SelectMenuItem to close the menu
// even if an invalid slot has been selected, which causes us a problem as
// we'll never get any notification from the client and we'll keep the menu
// alive on our end indefinitely. For these games, pretend that every slot
// is valid for selection so we're guaranteed to get a menuselect command.
// We don't want to do this for every game as the common SelectMenuItem
// implementation ignores invalid selections and keeps the menu open, which
// is a much nicer user experience.
display_keys = s_RadioClosesOnInvalidSlot ? 0x7ff : keys;
}

void CRadioMenuPlayer::Radio_Refresh()
Expand Down
17 changes: 16 additions & 1 deletion gamedata/core.games/common.games.txt
Expand Up @@ -197,7 +197,7 @@
}
}

"#default"
"#default"
{
"#supported"
{
Expand Down Expand Up @@ -366,4 +366,19 @@
"RadioMenuMaxPageItems" "6"
}
}

"#default"
{
"#supported"
{
"engine" "left4dead"
"engine" "left4dead2"
"engine" "nucleardawn"
}

"Keys"
{
"RadioMenuClosesOnInvalidSlot" "yes"
}
}
}

0 comments on commit 32d951e

Please sign in to comment.