mirror of
https://github.com/GabsPuNs/Project-Zenith-Main.git
synced 2026-07-10 06:28:31 +00:00
Implement MessageBox UI: Add styles and structure for message box, including buttons and event handling
This commit is contained in:
@@ -1,160 +1,282 @@
|
||||
#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>
|
||||
|
||||
UIScene_MessageBox::UIScene_MessageBox(int iPad, void *initData, UILayer *parentLayer) : UIScene(iPad, parentLayer)
|
||||
#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)
|
||||
{
|
||||
// Setup all the Iggy references we need for this scene
|
||||
initialiseMovie();
|
||||
|
||||
MessageBoxInfo *param = static_cast<MessageBoxInfo *>(initData);
|
||||
|
||||
m_buttonCount = param->uiOptionC;
|
||||
|
||||
IggyDataValue result;
|
||||
IggyDataValue value[2];
|
||||
value[0].type = IGGY_DATATYPE_number;
|
||||
value[0].number = param->uiOptionC;
|
||||
|
||||
value[1].type = IGGY_DATATYPE_number;
|
||||
value[1].number = param->dwFocusButton;
|
||||
IggyResult out = IggyPlayerCallMethodRS ( getMovie() , &result, IggyPlayerRootPath( getMovie() ), m_funcInit , 2 , value );
|
||||
|
||||
int buttonIndex = 0;
|
||||
if(param->uiOptionC > 3)
|
||||
{
|
||||
m_buttonButtons[eControl_Button0].init(app.GetString(param->uiOptionA[buttonIndex]),buttonIndex);
|
||||
++buttonIndex;
|
||||
}
|
||||
if(param->uiOptionC > 2)
|
||||
{
|
||||
m_buttonButtons[eControl_Button1].init(app.GetString(param->uiOptionA[buttonIndex]),buttonIndex);
|
||||
++buttonIndex;
|
||||
}
|
||||
if(param->uiOptionC > 1)
|
||||
{
|
||||
m_buttonButtons[eControl_Button2].init(app.GetString(param->uiOptionA[buttonIndex]),buttonIndex);
|
||||
++buttonIndex;
|
||||
}
|
||||
m_buttonButtons[eControl_Button3].init(app.GetString(param->uiOptionA[buttonIndex]),buttonIndex);
|
||||
|
||||
m_labelTitle.init(app.GetString(param->uiTitle));
|
||||
m_labelContent.init(app.GetString(param->uiText));
|
||||
|
||||
out = IggyPlayerCallMethodRS ( getMovie() , &result, IggyPlayerRootPath( getMovie() ), m_funcAutoResize , 0 , nullptr );
|
||||
|
||||
m_Func = param->Func;
|
||||
m_lpParam = param->lpParam;
|
||||
m_buttonCount = param->uiOptionC;
|
||||
|
||||
parentLayer->addComponent(iPad,eUIComponent_MenuBackground);
|
||||
Rml::Context* ctx = RmlManager::Get().GetContext();
|
||||
if (!ctx)
|
||||
{
|
||||
app.DebugPrintf("[RmlMsgBox] No RmlUi context available\n");
|
||||
return;
|
||||
}
|
||||
|
||||
// 4J-TomK - rebuild touch after auto resize
|
||||
#ifdef __PSVITA__
|
||||
ui.TouchBoxRebuild(this);
|
||||
#endif
|
||||
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");
|
||||
|
||||
m_document->GetElementById("button0")->AddEventListener(Rml::EventId::Click, this);
|
||||
m_document->GetElementById("button1")->AddEventListener(Rml::EventId::Click, this);
|
||||
m_document->GetElementById("button2")->AddEventListener(Rml::EventId::Click, this);
|
||||
m_document->GetElementById("button3")->AddEventListener(Rml::EventId::Click, this);
|
||||
|
||||
wstring titleText = app.GetString(param->uiTitle);
|
||||
wstring descText = app.GetString(param->uiText);
|
||||
|
||||
auto* titleEl = m_document->GetElementById("title");
|
||||
auto* descEl = m_document->GetElementById("description");
|
||||
|
||||
Rml::String titleUtf8(titleText.begin(), titleText.end());
|
||||
Rml::String descUtf8(descText.begin(), descText.end());
|
||||
|
||||
if (titleEl) titleEl->SetInnerRML(titleUtf8);
|
||||
if (descEl) 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]->SetProperty("display", "none");
|
||||
}
|
||||
|
||||
if (m_buttonCount > 3 && buttons[0])
|
||||
{
|
||||
wstring label = app.GetString(param->uiOptionA[buttonIndex]);
|
||||
buttons[0]->SetInnerRML(Rml::String(label.begin(), label.end()));
|
||||
buttons[0]->SetProperty("display", "block");
|
||||
++buttonIndex;
|
||||
}
|
||||
if (m_buttonCount > 2 && buttons[1])
|
||||
{
|
||||
wstring label = app.GetString(param->uiOptionA[buttonIndex]);
|
||||
buttons[1]->SetInnerRML(Rml::String(label.begin(), label.end()));
|
||||
buttons[1]->SetProperty("display", "block");
|
||||
++buttonIndex;
|
||||
}
|
||||
if (m_buttonCount > 1 && buttons[2])
|
||||
{
|
||||
wstring label = app.GetString(param->uiOptionA[buttonIndex]);
|
||||
buttons[2]->SetInnerRML(Rml::String(label.begin(), label.end()));
|
||||
buttons[2]->SetProperty("display", "block");
|
||||
++buttonIndex;
|
||||
}
|
||||
if (buttons[3])
|
||||
{
|
||||
wstring label = app.GetString(param->uiOptionA[buttonIndex]);
|
||||
buttons[3]->SetInnerRML(Rml::String(label.begin(), label.end()));
|
||||
buttons[3]->SetProperty("display", "block");
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
wstring UIScene_MessageBox::getMoviePath()
|
||||
void UIScene_MessageBox::gainFocus()
|
||||
{
|
||||
if(app.GetLocalPlayerCount() > 1 && !m_parentLayer->IsFullscreenGroup())
|
||||
if (!bHasFocus && stealsFocus())
|
||||
{
|
||||
return L"MessageBoxSplit";
|
||||
}
|
||||
else
|
||||
{
|
||||
return L"MessageBox";
|
||||
bHasFocus = true;
|
||||
updateTooltips();
|
||||
updateComponents();
|
||||
handleGainFocus(m_bFocussedOnce);
|
||||
if (bHasFocus)
|
||||
m_bFocussedOnce = true;
|
||||
|
||||
if (m_document)
|
||||
m_document->Show();
|
||||
}
|
||||
}
|
||||
|
||||
void UIScene_MessageBox::updateTooltips()
|
||||
void UIScene_MessageBox::handleLoseFocus()
|
||||
{
|
||||
ui.SetTooltips( m_parentLayer->IsFullscreenGroup()?XUSER_INDEX_ANY:m_iPad, IDS_TOOLTIPS_SELECT, IDS_TOOLTIPS_CANCEL);
|
||||
if (m_document)
|
||||
m_document->Hide();
|
||||
}
|
||||
|
||||
void UIScene_MessageBox::handleReload()
|
||||
void UIScene_MessageBox::reloadMovie(bool force)
|
||||
{
|
||||
IggyDataValue result;
|
||||
IggyDataValue value[2];
|
||||
value[0].type = IGGY_DATATYPE_number;
|
||||
value[0].number = m_buttonCount;
|
||||
}
|
||||
|
||||
value[1].type = IGGY_DATATYPE_number;
|
||||
value[1].number = static_cast<F64>(getControlFocus());
|
||||
IggyResult out = IggyPlayerCallMethodRS ( getMovie() , &result, IggyPlayerRootPath( getMovie() ), m_funcInit , 2 , value );
|
||||
void UIScene_MessageBox::tick()
|
||||
{
|
||||
m_hasTickedOnce = true;
|
||||
|
||||
out = IggyPlayerCallMethodRS ( getMovie() , &result, IggyPlayerRootPath( getMovie() ), m_funcAutoResize , 0 , nullptr );
|
||||
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)
|
||||
{
|
||||
//app.DebugPrintf("UIScene_DebugOverlay handling input for pad %d, key %d, down- %s, pressed- %s, released- %s\n", iPad, key, down?"TRUE":"FALSE", pressed?"TRUE":"FALSE", released?"TRUE":"FALSE");
|
||||
ui.AnimateKeyPress(m_iPad, key, repeat, pressed, released);
|
||||
switch(key)
|
||||
Rml::Context* ctx = RmlManager::Get().GetContext();
|
||||
if (!ctx)
|
||||
return;
|
||||
|
||||
if (!pressed)
|
||||
return;
|
||||
|
||||
switch (key)
|
||||
{
|
||||
case ACTION_MENU_CANCEL:
|
||||
if(pressed)
|
||||
{
|
||||
navigateBack();
|
||||
if(m_Func) m_Func(m_lpParam, iPad, C4JStorage::EMessage_Cancelled);
|
||||
}
|
||||
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:
|
||||
#ifdef __ORBIS__
|
||||
case ACTION_MENU_TOUCHPAD_PRESS:
|
||||
#endif
|
||||
sendInputToMovie(key, repeat, pressed, released);
|
||||
if (g_KBMInput.IsKeyPressed(VK_RETURN))
|
||||
{
|
||||
ctx->ProcessKeyDown(Rml::Input::KI_RETURN, 0);
|
||||
handled = true;
|
||||
}
|
||||
break;
|
||||
case ACTION_MENU_UP:
|
||||
case ACTION_MENU_DOWN:
|
||||
sendInputToMovie(key, repeat, pressed, released);
|
||||
break;
|
||||
}
|
||||
handled = true;
|
||||
}
|
||||
|
||||
void UIScene_MessageBox::handlePress(F64 controlId, F64 childId)
|
||||
{
|
||||
C4JStorage::EMessageResult result = C4JStorage::EMessage_Cancelled;
|
||||
switch(static_cast<int>(controlId))
|
||||
case ACTION_MENU_CANCEL:
|
||||
{
|
||||
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;
|
||||
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;
|
||||
}
|
||||
|
||||
navigateBack();
|
||||
if(m_Func) m_Func(m_lpParam, m_iPad, result);
|
||||
}
|
||||
|
||||
bool UIScene_MessageBox::hasFocus(int iPad)
|
||||
{
|
||||
// 4J-JEV: Fix for PS4 #5204 - [TRC][R4033] The application can be locked up by second user logging out of the system.
|
||||
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)
|
||||
{
|
||||
C4JStorage::EMessageResult result = C4JStorage::EMessage_Cancelled;
|
||||
switch (buttonIndex)
|
||||
{
|
||||
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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user