mirror of
https://github.com/GabsPuNs/Project-Zenith-Main.git
synced 2026-07-09 22:28:12 +00:00
281 lines
6.8 KiB
C++
281 lines
6.8 KiB
C++
#include "UI.h"
|
|
|
|
#pragma push_macro("byte")
|
|
#pragma push_macro("GetNextSibling")
|
|
#pragma push_macro("GetFirstChild")
|
|
#undef byte
|
|
#undef GetNextSibling
|
|
#undef GetFirstChild
|
|
|
|
#include "UIScene_MessageBox.h"
|
|
#include "RmlManager.h"
|
|
#include "../../Windows64/KeyboardMouseInput.h"
|
|
#include <RmlUi/Core/Input.h>
|
|
#include <RmlUi/Core/Context.h>
|
|
|
|
#pragma pop_macro("GetFirstChild")
|
|
#pragma pop_macro("GetNextSibling")
|
|
#pragma pop_macro("byte")
|
|
|
|
extern KeyboardMouseInput g_KBMInput;
|
|
|
|
UIScene_MessageBox::UIScene_MessageBox(int iPad, void *initData, UILayer *parentLayer)
|
|
: UIScene(iPad, parentLayer)
|
|
, m_document(nullptr)
|
|
, m_buttonCount(0)
|
|
, m_Func(nullptr)
|
|
, m_lpParam(nullptr)
|
|
{
|
|
MessageBoxInfo *param = static_cast<MessageBoxInfo *>(initData);
|
|
|
|
m_Func = param->Func;
|
|
m_lpParam = param->lpParam;
|
|
m_buttonCount = param->uiOptionC;
|
|
|
|
Rml::Context* ctx = RmlManager::Get().GetContext();
|
|
if (!ctx)
|
|
{
|
|
app.DebugPrintf("[RmlMsgBox] No RmlUi context available\n");
|
|
return;
|
|
}
|
|
|
|
m_document = ctx->LoadDocument("MessageBox.rml");
|
|
if (!m_document)
|
|
{
|
|
app.DebugPrintf("[RmlMsgBox] Failed to load MessageBox.rml\n");
|
|
return;
|
|
}
|
|
|
|
app.DebugPrintf("[RmlMsgBox] Document loaded OK\n");
|
|
|
|
wstring titleText = app.GetString(param->uiTitle);
|
|
wstring descText = app.GetString(param->uiText);
|
|
|
|
Rml::String titleUtf8 = utils.WideToUtf8(titleText);
|
|
Rml::String descUtf8 = utils.WideToUtf8(descText);
|
|
|
|
if (auto* titleEl = m_document->GetElementById("title"))
|
|
titleEl->SetInnerRML(titleUtf8);
|
|
if (auto* descEl = m_document->GetElementById("description"))
|
|
descEl->SetInnerRML(descUtf8);
|
|
|
|
int buttonIndex = 0;
|
|
Rml::Element* buttons[4] = {
|
|
m_document->GetElementById("button0"),
|
|
m_document->GetElementById("button1"),
|
|
m_document->GetElementById("button2"),
|
|
m_document->GetElementById("button3")
|
|
};
|
|
|
|
for (int i = 0; i < 4; i++)
|
|
{
|
|
if (buttons[i])
|
|
{
|
|
buttons[i]->AddEventListener(Rml::EventId::Click, this);
|
|
buttons[i]->SetProperty("display", "none");
|
|
}
|
|
}
|
|
|
|
int startIndex = 4 - m_buttonCount;
|
|
if (startIndex < 0)
|
|
startIndex = 0;
|
|
|
|
int labelIndex = 0;
|
|
for (int i = startIndex; i < 4; i++)
|
|
{
|
|
if (buttons[i])
|
|
{
|
|
wstring label = app.GetString(param->uiOptionA[labelIndex]);
|
|
Rml::String labelUtf8 = utils.WideToUtf8(label);
|
|
buttons[i]->SetInnerRML(labelUtf8);
|
|
buttons[i]->SetProperty("display", "block");
|
|
labelIndex++;
|
|
}
|
|
}
|
|
|
|
int focusButton = param->dwFocusButton;
|
|
if (focusButton >= 0 && focusButton < 4 && buttons[focusButton])
|
|
buttons[focusButton]->Focus();
|
|
|
|
m_document->Show();
|
|
|
|
parentLayer->addComponent(iPad, eUIComponent_MenuBackground);
|
|
}
|
|
|
|
UIScene_MessageBox::~UIScene_MessageBox()
|
|
{
|
|
if (m_document)
|
|
{
|
|
m_document->GetElementById("button0")->RemoveEventListener(Rml::EventId::Click, this);
|
|
m_document->GetElementById("button1")->RemoveEventListener(Rml::EventId::Click, this);
|
|
m_document->GetElementById("button2")->RemoveEventListener(Rml::EventId::Click, this);
|
|
m_document->GetElementById("button3")->RemoveEventListener(Rml::EventId::Click, this);
|
|
m_document->Close();
|
|
m_document = nullptr;
|
|
}
|
|
|
|
m_parentLayer->removeComponent(eUIComponent_MenuBackground);
|
|
}
|
|
|
|
void UIScene_MessageBox::gainFocus()
|
|
{
|
|
if (!bHasFocus && stealsFocus())
|
|
{
|
|
bHasFocus = true;
|
|
updateTooltips();
|
|
updateComponents();
|
|
handleGainFocus(m_bFocussedOnce);
|
|
if (bHasFocus)
|
|
m_bFocussedOnce = true;
|
|
|
|
if (m_document)
|
|
m_document->Show();
|
|
}
|
|
}
|
|
|
|
void UIScene_MessageBox::handleLoseFocus()
|
|
{
|
|
if (m_document)
|
|
m_document->Hide();
|
|
}
|
|
|
|
void UIScene_MessageBox::reloadMovie(bool force)
|
|
{
|
|
}
|
|
|
|
void UIScene_MessageBox::tick()
|
|
{
|
|
m_hasTickedOnce = true;
|
|
|
|
UIScene::tick();
|
|
|
|
Rml::Context* ctx = RmlManager::Get().GetContext();
|
|
if (!ctx || !bHasFocus)
|
|
return;
|
|
|
|
ctx->ProcessMouseMove(g_KBMInput.GetMouseX(), g_KBMInput.GetMouseY(), 0);
|
|
|
|
if (g_KBMInput.IsMouseButtonPressed(KeyboardMouseInput::MOUSE_LEFT))
|
|
ctx->ProcessMouseButtonDown(0, 0);
|
|
if (g_KBMInput.IsMouseButtonReleased(KeyboardMouseInput::MOUSE_LEFT))
|
|
ctx->ProcessMouseButtonUp(0, 0);
|
|
if (g_KBMInput.IsMouseButtonPressed(KeyboardMouseInput::MOUSE_RIGHT))
|
|
ctx->ProcessMouseButtonDown(1, 0);
|
|
if (g_KBMInput.IsMouseButtonReleased(KeyboardMouseInput::MOUSE_RIGHT))
|
|
ctx->ProcessMouseButtonUp(1, 0);
|
|
|
|
int wheelDelta = g_KBMInput.GetMouseWheel();
|
|
if (wheelDelta != 0)
|
|
ctx->ProcessMouseWheel(wheelDelta / -120, 0);
|
|
|
|
ctx->Update();
|
|
}
|
|
|
|
void UIScene_MessageBox::render(S32 width, S32 height, C4JRender::eViewportType viewport)
|
|
{
|
|
}
|
|
|
|
void UIScene_MessageBox::handleInput(int iPad, int key, bool repeat, bool pressed, bool released, bool &handled)
|
|
{
|
|
Rml::Context* ctx = RmlManager::Get().GetContext();
|
|
if (!ctx)
|
|
return;
|
|
|
|
if (!pressed)
|
|
return;
|
|
|
|
switch (key)
|
|
{
|
|
case ACTION_MENU_UP:
|
|
ctx->ProcessKeyDown(Rml::Input::KI_UP, 0);
|
|
handled = true;
|
|
break;
|
|
case ACTION_MENU_DOWN:
|
|
ctx->ProcessKeyDown(Rml::Input::KI_DOWN, 0);
|
|
handled = true;
|
|
break;
|
|
case ACTION_MENU_OK:
|
|
if (g_KBMInput.IsKeyPressed(VK_RETURN))
|
|
{
|
|
ctx->ProcessKeyDown(Rml::Input::KI_RETURN, 0);
|
|
handled = true;
|
|
}
|
|
break;
|
|
case ACTION_MENU_CANCEL:
|
|
{
|
|
C4JStorage::EMessageResult result = C4JStorage::EMessage_Cancelled;
|
|
int( *tmpFunc)(LPVOID,int,const C4JStorage::EMessageResult) = m_Func;
|
|
LPVOID tmpParam = m_lpParam;
|
|
int tmpPad = m_iPad;
|
|
|
|
navigateBack();
|
|
|
|
if (tmpFunc)
|
|
tmpFunc(tmpParam, tmpPad, result);
|
|
|
|
handled = true;
|
|
break;
|
|
}
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
bool UIScene_MessageBox::hasFocus(int iPad)
|
|
{
|
|
if (m_iPad == 255) // Message box is for everyone
|
|
return bHasFocus;
|
|
else if (ProfileManager.IsSignedIn(m_iPad)) // Owner is still present
|
|
return bHasFocus && (iPad == m_iPad);
|
|
else // Original owner has left so let everyone interact
|
|
return bHasFocus;
|
|
}
|
|
|
|
void UIScene_MessageBox::ProcessEvent(Rml::Event& event)
|
|
{
|
|
const Rml::String& id = event.GetCurrentElement()->GetId();
|
|
|
|
if (event == Rml::EventId::Click)
|
|
{
|
|
if (id == "button0") OnButtonClicked(0);
|
|
else if (id == "button1") OnButtonClicked(1);
|
|
else if (id == "button2") OnButtonClicked(2);
|
|
else if (id == "button3") OnButtonClicked(3);
|
|
}
|
|
}
|
|
|
|
void UIScene_MessageBox::OnButtonClicked(int buttonIndex)
|
|
{
|
|
//GabsPuN: Something is wrong with the IDs. This fixed it but
|
|
//I don't know if this is the right way to do it
|
|
int startIndex = 4 - m_buttonCount;
|
|
if (startIndex < 0)
|
|
startIndex = 0;
|
|
|
|
int RButtonIndex = buttonIndex - startIndex;
|
|
|
|
C4JStorage::EMessageResult result = C4JStorage::EMessage_Cancelled;
|
|
switch (RButtonIndex)
|
|
{
|
|
case 0: result = C4JStorage::EMessage_ResultAccept; break;
|
|
case 1: result = C4JStorage::EMessage_ResultDecline; break;
|
|
case 2: result = C4JStorage::EMessage_ResultThirdOption; break;
|
|
case 3: result = C4JStorage::EMessage_ResultFourthOption; break;
|
|
}
|
|
|
|
ui.PlayUISFX(eSFX_Press);
|
|
|
|
int( *tmpFunc)(LPVOID,int,const C4JStorage::EMessageResult) = m_Func;
|
|
LPVOID tmpParam = m_lpParam;
|
|
int tmpPad = m_iPad;
|
|
|
|
navigateBack();
|
|
if (tmpFunc)
|
|
tmpFunc(tmpParam, tmpPad, result);
|
|
}
|
|
|
|
void UIScene_MessageBox::navigateBack()
|
|
{
|
|
UIScene::navigateBack();
|
|
}
|