mirror of
https://github.com/hedge-dev/UnleashedRecomp.git
synced 2026-04-27 21:01:37 +00:00
message_window: implemented mouse input
This commit is contained in:
parent
efd2c40cfd
commit
f01d422b31
1 changed files with 63 additions and 35 deletions
|
|
@ -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,54 +234,72 @@ 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) ||
|
|
||||||
pInputState->GetPadState().LeftStickVertical > 0.5f;
|
|
||||||
|
|
||||||
bool downIsHeld = pInputState->GetPadState().IsDown(SWA::eKeyState_DpadDown) ||
|
|
||||||
pInputState->GetPadState().LeftStickVertical < -0.5f;
|
|
||||||
|
|
||||||
bool scrollUp = !g_upWasHeld && upIsHeld;
|
|
||||||
bool scrollDown = !g_downWasHeld && downIsHeld;
|
|
||||||
|
|
||||||
if (scrollUp)
|
|
||||||
{
|
{
|
||||||
--g_selectedRowIndex;
|
bool upIsHeld = pInputState->GetPadState().IsDown(SWA::eKeyState_DpadUp) ||
|
||||||
if (g_selectedRowIndex < 0)
|
pInputState->GetPadState().LeftStickVertical > 0.5f;
|
||||||
g_selectedRowIndex = rowCount - 1;
|
|
||||||
|
bool downIsHeld = pInputState->GetPadState().IsDown(SWA::eKeyState_DpadDown) ||
|
||||||
|
pInputState->GetPadState().LeftStickVertical < -0.5f;
|
||||||
|
|
||||||
|
bool scrollUp = !g_upWasHeld && upIsHeld;
|
||||||
|
bool scrollDown = !g_downWasHeld && downIsHeld;
|
||||||
|
|
||||||
|
if (scrollUp)
|
||||||
|
{
|
||||||
|
--g_selectedRowIndex;
|
||||||
|
if (g_selectedRowIndex < 0)
|
||||||
|
g_selectedRowIndex = rowCount - 1;
|
||||||
|
}
|
||||||
|
else if (scrollDown)
|
||||||
|
{
|
||||||
|
++g_selectedRowIndex;
|
||||||
|
if (g_selectedRowIndex >= rowCount)
|
||||||
|
g_selectedRowIndex = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (scrollUp || scrollDown)
|
||||||
|
Game_PlaySound("sys_actstg_pausecursor");
|
||||||
|
|
||||||
|
g_upWasHeld = upIsHeld;
|
||||||
|
g_downWasHeld = downIsHeld;
|
||||||
|
|
||||||
|
if (pInputState->GetPadState().IsTapped(SWA::eKeyState_B))
|
||||||
|
{
|
||||||
|
g_result = -1;
|
||||||
|
|
||||||
|
Game_PlaySound("sys_actstg_pausecansel");
|
||||||
|
MessageWindow::Close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (scrollDown)
|
else
|
||||||
{
|
{
|
||||||
++g_selectedRowIndex;
|
auto clipRectMin = drawList->GetClipRectMin();
|
||||||
if (g_selectedRowIndex >= rowCount)
|
auto clipRectMax = drawList->GetClipRectMax();
|
||||||
g_selectedRowIndex = 0;
|
|
||||||
|
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 (scrollUp || scrollDown)
|
if (isAccepted)
|
||||||
Game_PlaySound("sys_actstg_pausecursor");
|
|
||||||
|
|
||||||
g_upWasHeld = upIsHeld;
|
|
||||||
g_downWasHeld = downIsHeld;
|
|
||||||
|
|
||||||
if (pInputState->GetPadState().IsTapped(SWA::eKeyState_A))
|
|
||||||
{
|
{
|
||||||
g_result = g_selectedRowIndex;
|
g_result = g_selectedRowIndex;
|
||||||
|
|
||||||
Game_PlaySound("sys_actstg_pausedecide");
|
Game_PlaySound("sys_actstg_pausedecide");
|
||||||
MessageWindow::Close();
|
MessageWindow::Close();
|
||||||
}
|
}
|
||||||
else if (pInputState->GetPadState().IsTapped(SWA::eKeyState_B))
|
|
||||||
{
|
|
||||||
g_result = -1;
|
|
||||||
|
|
||||||
Game_PlaySound("sys_actstg_pausecansel");
|
drawList->PopClipRect();
|
||||||
MessageWindow::Close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (!g_isControlsVisible && pInputState->GetPadState().IsTapped(SWA::eKeyState_A))
|
if (!g_isControlsVisible && isAccepted)
|
||||||
{
|
{
|
||||||
g_controlsAppearTime = ImGui::GetTime();
|
g_controlsAppearTime = ImGui::GetTime();
|
||||||
g_isControlsVisible = true;
|
g_isControlsVisible = true;
|
||||||
|
|
@ -287,8 +310,12 @@ void MessageWindow::Draw()
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (pInputState->GetPadState().IsTapped(SWA::eKeyState_A))
|
if (isAccepted)
|
||||||
|
{
|
||||||
|
g_result = 0;
|
||||||
|
|
||||||
MessageWindow::Close();
|
MessageWindow::Close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue