message_window: implemented mouse input

This commit is contained in:
Hyper 2024-12-04 00:09:34 +00:00
parent efd2c40cfd
commit f01d422b31

View file

@ -2,6 +2,7 @@
#include "imgui_utils.h" #include "imgui_utils.h"
#include <api/SWA.h> #include <api/SWA.h>
#include <gpu/video.h> #include <gpu/video.h>
#include <ui/installer_wizard.h>
#include <exports.h> #include <exports.h>
#include <res/images/common/select_fade.dds.h> #include <res/images/common/select_fade.dds.h>
@ -184,7 +185,7 @@ void MessageWindow::Draw()
if (!s_isVisible) if (!s_isVisible)
return; return;
auto pInputState = SWA::CInputState::GetInstance(); auto pInputState = InstallerWizard::s_isVisible ? nullptr : SWA::CInputState::GetInstance();
auto drawList = ImGui::GetForegroundDrawList(); auto drawList = ImGui::GetForegroundDrawList();
auto& res = ImGui::GetIO().DisplaySize; auto& res = ImGui::GetIO().DisplaySize;
@ -213,6 +214,10 @@ void MessageWindow::Draw()
drawList->PopClipRect(); drawList->PopClipRect();
bool isAccepted = pInputState
? pInputState->GetPadState().IsTapped(SWA::eKeyState_A)
: ImGui::IsMouseClicked(ImGuiMouseButton_Left);
if (g_buttons.size()) if (g_buttons.size())
{ {
auto itemWidth = std::max(Scale(162), Scale(CalcWidestTextSize(g_fntSeurat, fontSize, g_buttons))); auto itemWidth = std::max(Scale(162), Scale(CalcWidestTextSize(g_fntSeurat, fontSize, g_buttons)));
@ -229,8 +234,8 @@ void MessageWindow::Draw()
for (auto& button : g_buttons) for (auto& button : g_buttons)
DrawButton(rowCount++, windowMarginY, itemWidth, itemHeight, button); DrawButton(rowCount++, windowMarginY, itemWidth, itemHeight, button);
drawList->PopClipRect(); if (pInputState)
{
bool upIsHeld = pInputState->GetPadState().IsDown(SWA::eKeyState_DpadUp) || bool upIsHeld = pInputState->GetPadState().IsDown(SWA::eKeyState_DpadUp) ||
pInputState->GetPadState().LeftStickVertical > 0.5f; pInputState->GetPadState().LeftStickVertical > 0.5f;
@ -259,14 +264,7 @@ void MessageWindow::Draw()
g_upWasHeld = upIsHeld; g_upWasHeld = upIsHeld;
g_downWasHeld = downIsHeld; g_downWasHeld = downIsHeld;
if (pInputState->GetPadState().IsTapped(SWA::eKeyState_A)) if (pInputState->GetPadState().IsTapped(SWA::eKeyState_B))
{
g_result = g_selectedRowIndex;
Game_PlaySound("sys_actstg_pausedecide");
MessageWindow::Close();
}
else if (pInputState->GetPadState().IsTapped(SWA::eKeyState_B))
{ {
g_result = -1; g_result = -1;
@ -276,7 +274,32 @@ void MessageWindow::Draw()
} }
else else
{ {
if (!g_isControlsVisible && pInputState->GetPadState().IsTapped(SWA::eKeyState_A)) auto clipRectMin = drawList->GetClipRectMin();
auto clipRectMax = drawList->GetClipRectMax();
for (int i = 0; i < rowCount; i++)
{
ImVec2 itemMin = { clipRectMin.x + windowMarginX, clipRectMin.y + windowMarginY + itemHeight * i };
ImVec2 itemMax = { clipRectMax.x - windowMarginX, clipRectMin.y + windowMarginY + itemHeight * i + itemHeight };
if (ImGui::IsMouseHoveringRect(itemMin, itemMax, false))
g_selectedRowIndex = i;
}
}
if (isAccepted)
{
g_result = g_selectedRowIndex;
Game_PlaySound("sys_actstg_pausedecide");
MessageWindow::Close();
}
drawList->PopClipRect();
}
else
{
if (!g_isControlsVisible && isAccepted)
{ {
g_controlsAppearTime = ImGui::GetTime(); g_controlsAppearTime = ImGui::GetTime();
g_isControlsVisible = true; g_isControlsVisible = true;
@ -287,11 +310,15 @@ void MessageWindow::Draw()
} }
else else
{ {
if (pInputState->GetPadState().IsTapped(SWA::eKeyState_A)) if (isAccepted)
{
g_result = 0;
MessageWindow::Close(); MessageWindow::Close();
} }
} }
} }
}
bool MessageWindow::Open(std::string text, int* result, std::span<std::string> buttons, int defaultButtonIndex) bool MessageWindow::Open(std::string text, int* result, std::span<std::string> buttons, int defaultButtonIndex)
{ {
@ -328,6 +355,7 @@ void MessageWindow::Close()
g_controlsAppearTime = ImGui::GetTime(); g_controlsAppearTime = ImGui::GetTime();
g_isClosing = true; g_isClosing = true;
g_isControlsVisible = false; g_isControlsVisible = false;
g_foregroundCount = 0;
g_isAwaitingResult = false; g_isAwaitingResult = false;
} }