options_menu: fix buffered A press selecting first option upon entry

This commit is contained in:
Hyper 2024-11-19 02:06:16 +00:00
parent 4d70dbd3b8
commit dc3bfb8e3c
2 changed files with 47 additions and 33 deletions

View file

@ -14,6 +14,8 @@ static ImFont* g_newRodinFont;
static const IConfigDef* g_selectedItem; static const IConfigDef* g_selectedItem;
static bool g_isEnterKeyBuffered = false;
void OptionsMenu::Init() void OptionsMenu::Init()
{ {
auto& io = ImGui::GetIO(); auto& io = ImGui::GetIO();
@ -402,6 +404,8 @@ static void DrawConfigOption(int32_t rowIndex, float yOffset, ConfigDef<T>* conf
{ {
g_selectedItem = config; g_selectedItem = config;
if (!g_isEnterKeyBuffered)
{
if constexpr (std::is_same_v<T, bool>) if constexpr (std::is_same_v<T, bool>)
{ {
if (padState.IsTapped(SWA::eKeyState_A)) if (padState.IsTapped(SWA::eKeyState_A))
@ -437,6 +441,11 @@ static void DrawConfigOption(int32_t rowIndex, float yOffset, ConfigDef<T>* conf
lockedOnOption = g_lockedOnOption; lockedOnOption = g_lockedOnOption;
} }
} }
}
// We've entered the menu now, no need to check this.
if (padState.IsReleased(SWA::eKeyState_A))
g_isEnterKeyBuffered = false;
bool fadedOut = g_lockedOnOption && g_selectedItem != config; bool fadedOut = g_lockedOnOption && g_selectedItem != config;
float alpha = fadedOut ? 0.5f : 1.0f; float alpha = fadedOut ? 0.5f : 1.0f;
@ -811,9 +820,7 @@ void DrawInfoPanel()
void OptionsMenu::Draw() void OptionsMenu::Draw()
{ {
auto inputState = SWA::CInputState::GetInstance(); if (!s_isVisible || SWA::CInputState::GetInstance()->GetPadState().IsDown(SWA::eKeyState_Y))
if (!s_isVisible || inputState->GetPadState().IsDown(SWA::eKeyState_Y))
return; return;
g_callbackDataIndex = 0; g_callbackDataIndex = 0;
@ -821,7 +828,7 @@ void OptionsMenu::Draw()
auto& res = ImGui::GetIO().DisplaySize; auto& res = ImGui::GetIO().DisplaySize;
auto drawList = ImGui::GetForegroundDrawList(); auto drawList = ImGui::GetForegroundDrawList();
if (s_isDimBackground) if (s_isStage)
drawList->AddRectFilled({ 0.0f, 0.0f }, res, IM_COL32(0, 0, 0, 223)); drawList->AddRectFilled({ 0.0f, 0.0f }, res, IM_COL32(0, 0, 0, 223));
DrawScanlineBars(); DrawScanlineBars();
@ -832,8 +839,15 @@ void OptionsMenu::Draw()
void OptionsMenu::Open(bool stage) void OptionsMenu::Open(bool stage)
{ {
s_isVisible = true; s_isVisible = true;
s_isDimBackground = stage; s_isStage = stage;
g_categoryIndex = 0; g_categoryIndex = 0;
/* Store button state so we can track it later
and prevent the first item being selected. */
if (SWA::CInputState::GetInstance()->GetPadState().IsDown(SWA::eKeyState_A))
g_isEnterKeyBuffered = true;
ResetSelection(); ResetSelection();
*(bool*)g_memory.Translate(0x8328BB26) = false; *(bool*)g_memory.Translate(0x8328BB26) = false;
@ -844,7 +858,7 @@ void OptionsMenu::Open(bool stage)
void OptionsMenu::Close(bool stage) void OptionsMenu::Close(bool stage)
{ {
s_isVisible = false; s_isVisible = false;
s_isDimBackground = stage; s_isStage = stage;
*(bool*)g_memory.Translate(0x8328BB26) = true; *(bool*)g_memory.Translate(0x8328BB26) = true;

View file

@ -4,7 +4,7 @@ struct OptionsMenu
{ {
public: public:
inline static bool s_isVisible = false; inline static bool s_isVisible = false;
inline static bool s_isDimBackground = false; inline static bool s_isStage = false;
static void Init(); static void Init();
static void Draw(); static void Draw();