Add RmlUi

This commit is contained in:
Zero
2026-06-10 16:12:51 +02:00
parent b1d5ea2253
commit d2b7ff5f43
1255 changed files with 270119 additions and 1362 deletions

View File

@@ -1,168 +1,316 @@
#include "stdafx.h"
// Non-RmlUi includes that depend on Windows macros
#include "UI.h"
#include "../../Minecraft.h"
// RmlUi includes (Windows macros temporarily suppressed)
#pragma push_macro("byte")
#pragma push_macro("GetNextSibling")
#pragma push_macro("GetFirstChild")
#undef byte
#undef GetNextSibling
#undef GetFirstChild
#include "UIScene_SettingsMenu.h"
#include "..\..\Minecraft.h"
#include "RmlManager.h"
#include "../../Windows64/KeyboardMouseInput.h"
#include <RmlUi/Core/Input.h>
#include <RmlUi/Core/Context.h>
UIScene_SettingsMenu::UIScene_SettingsMenu(int iPad, void *initData, UILayer *parentLayer) : UIScene(iPad, parentLayer)
#pragma pop_macro("GetFirstChild")
#pragma pop_macro("GetNextSibling")
#pragma pop_macro("byte")
UIScene_SettingsMenu::UIScene_SettingsMenu(int iPad, void *initData, UILayer *parentLayer)
: UIScene(iPad, parentLayer)
, m_document(nullptr)
, m_bConfirmDialog(false)
{
// Setup all the Iggy references we need for this scene
initialiseMovie();
bool bNotInGame=(Minecraft::GetInstance()->level==nullptr);
m_buttons[BUTTON_ALL_OPTIONS].init(IDS_OPTIONS,BUTTON_ALL_OPTIONS);
m_buttons[BUTTON_ALL_AUDIO].init(IDS_AUDIO,BUTTON_ALL_AUDIO);
m_buttons[BUTTON_ALL_CONTROL].init(IDS_CONTROL,BUTTON_ALL_CONTROL);
m_buttons[BUTTON_ALL_GRAPHICS].init(IDS_GRAPHICS,BUTTON_ALL_GRAPHICS);
m_buttons[BUTTON_ALL_UI].init(IDS_USER_INTERFACE,BUTTON_ALL_UI);
m_buttons[BUTTON_ALL_RESETTODEFAULTS].init(IDS_RESET_TO_DEFAULTS,BUTTON_ALL_RESETTODEFAULTS);
if(ProfileManager.GetPrimaryPad()!=m_iPad)
Rml::Context* ctx = RmlManager::Get().GetContext();
if (!ctx)
{
removeControl( &m_buttons[BUTTON_ALL_AUDIO], bNotInGame);
removeControl( &m_buttons[BUTTON_ALL_GRAPHICS], bNotInGame);
app.DebugPrintf("[RmlSettingsMenu] No RmlUi context available\n");
return;
}
doHorizontalResizeCheck();
if(app.GetLocalPlayerCount()>1)
m_document = ctx->LoadDocument("SettingsMenu.rml");
if (m_document)
{
#if TO_BE_IMPLEMENTED
app.AdjustSplitscreenScene(m_hObj,&m_OriginalPosition,m_iPad,false);
#endif
m_document->Show();
// Apply conditional visibility matching original Iggy scene behavior
bool bNotInGame = (Minecraft::GetInstance()->level == nullptr);
// Audio and Graphics: hidden if not primary pad
if (ProfileManager.GetPrimaryPad() != m_iPad)
{
auto* elAudio = m_document->GetElementById("audio");
if (elAudio) elAudio->SetProperty("display", "none");
auto* elGraphics = m_document->GetElementById("graphics");
if (elGraphics) elGraphics->SetProperty("display", "none");
}
// Register button click listeners
m_document->GetElementById("options")->AddEventListener(Rml::EventId::Click, this);
m_document->GetElementById("audio")->AddEventListener(Rml::EventId::Click, this);
m_document->GetElementById("controls")->AddEventListener(Rml::EventId::Click, this);
m_document->GetElementById("graphics")->AddEventListener(Rml::EventId::Click, this);
m_document->GetElementById("ui")->AddEventListener(Rml::EventId::Click, this);
m_document->GetElementById("reset_defaults")->AddEventListener(Rml::EventId::Click, this);
m_document->GetElementById("confirm_yes")->AddEventListener(Rml::EventId::Click, this);
m_document->GetElementById("confirm_no")->AddEventListener(Rml::EventId::Click, this);
// Focus first visible button
m_document->GetElementById("options")->Focus();
}
else
{
app.DebugPrintf("[RmlSettingsMenu] Failed to load SettingsMenu.rml\n");
}
updateComponents();
ui.HidePressStart();
TelemetryManager->RecordMenuShown(m_iPad, eUIScene_SettingsMenu, 0);
}
UIScene_SettingsMenu::~UIScene_SettingsMenu()
{
}
wstring UIScene_SettingsMenu::getMoviePath()
{
if(app.GetLocalPlayerCount() > 1)
if (m_document)
{
return L"SettingsMenuSplit";
}
else
{
return L"SettingsMenu";
m_document->GetElementById("options")->RemoveEventListener(Rml::EventId::Click, this);
m_document->GetElementById("audio")->RemoveEventListener(Rml::EventId::Click, this);
m_document->GetElementById("controls")->RemoveEventListener(Rml::EventId::Click, this);
m_document->GetElementById("graphics")->RemoveEventListener(Rml::EventId::Click, this);
m_document->GetElementById("ui")->RemoveEventListener(Rml::EventId::Click, this);
m_document->GetElementById("reset_defaults")->RemoveEventListener(Rml::EventId::Click, this);
m_document->GetElementById("confirm_yes")->RemoveEventListener(Rml::EventId::Click, this);
m_document->GetElementById("confirm_no")->RemoveEventListener(Rml::EventId::Click, this);
m_document->Close();
m_document = nullptr;
}
}
void UIScene_SettingsMenu::handleReload()
void UIScene_SettingsMenu::gainFocus()
{
bool bNotInGame=(Minecraft::GetInstance()->level==nullptr);
if(ProfileManager.GetPrimaryPad()!=m_iPad)
if (!bHasFocus && stealsFocus())
{
removeControl( &m_buttons[BUTTON_ALL_AUDIO], bNotInGame);
removeControl( &m_buttons[BUTTON_ALL_GRAPHICS], bNotInGame);
bHasFocus = true;
updateTooltips();
updateComponents();
if (!m_bFocussedOnce)
{
}
handleGainFocus(m_bFocussedOnce);
if (bHasFocus)
m_bFocussedOnce = true;
if (m_document)
m_document->Show();
}
}
doHorizontalResizeCheck();
void UIScene_SettingsMenu::handleLoseFocus()
{
if (m_document)
m_document->Hide();
}
void UIScene_SettingsMenu::updateTooltips()
{
ui.SetTooltips( m_iPad, IDS_TOOLTIPS_SELECT,IDS_TOOLTIPS_BACK);
}
void UIScene_SettingsMenu::updateComponents()
{
bool bNotInGame=(Minecraft::GetInstance()->level==nullptr);
if(bNotInGame)
bool bNotInGame = (Minecraft::GetInstance()->level == nullptr);
if (bNotInGame)
{
m_parentLayer->showComponent(m_iPad,eUIComponent_Panorama,true);
m_parentLayer->showComponent(m_iPad,eUIComponent_Logo,true);
m_parentLayer->showComponent(m_iPad, eUIComponent_Panorama, true);
m_parentLayer->showComponent(m_iPad, eUIComponent_Logo, true);
}
else
{
m_parentLayer->showComponent(m_iPad,eUIComponent_Panorama,false);
if( app.GetLocalPlayerCount() == 1 ) m_parentLayer->showComponent(m_iPad,eUIComponent_Logo,true);
else m_parentLayer->showComponent(m_iPad,eUIComponent_Logo,false);
m_parentLayer->showComponent(m_iPad, eUIComponent_Panorama, false);
if (app.GetLocalPlayerCount() == 1)
m_parentLayer->showComponent(m_iPad, eUIComponent_Logo, true);
else
m_parentLayer->showComponent(m_iPad, eUIComponent_Logo, false);
}
}
void UIScene_SettingsMenu::reloadMovie(bool force)
{
}
void UIScene_SettingsMenu::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_SettingsMenu::render(S32 width, S32 height, C4JRender::eViewportType viewport)
{
}
void UIScene_SettingsMenu::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);
Rml::Context* ctx = RmlManager::Get().GetContext();
if (!ctx)
return;
switch(key)
if (!pressed)
return;
switch (key)
{
case ACTION_MENU_CANCEL:
if(pressed)
{
// if the profile data has been changed, then force a profile write
// It seems we're allowed to break the 5 minute rule if it's the result of a user action
app.CheckGameSettingsChanged(true,iPad);
navigateBack();
}
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);
break;
case ACTION_MENU_UP:
case ACTION_MENU_DOWN:
sendInputToMovie(key, repeat, pressed, released);
break;
}
}
void UIScene_SettingsMenu::handlePress(F64 controlId, F64 childId)
{
//CD - Added for audio
ui.PlayUISFX(eSFX_Press);
switch(static_cast<int>(controlId))
{
case BUTTON_ALL_OPTIONS:
ui.NavigateToScene(m_iPad, eUIScene_SettingsOptionsMenu);
break;
case BUTTON_ALL_AUDIO:
ui.NavigateToScene(m_iPad, eUIScene_SettingsAudioMenu);
break;
case BUTTON_ALL_CONTROL:
ui.NavigateToScene(m_iPad, eUIScene_SettingsControlMenu);
break;
case BUTTON_ALL_GRAPHICS:
ui.NavigateToScene(m_iPad, eUIScene_SettingsGraphicsMenu);
break;
case BUTTON_ALL_UI:
ui.NavigateToScene(m_iPad, eUIScene_SettingsUIMenu);
break;
case BUTTON_ALL_RESETTODEFAULTS:
if (g_KBMInput.IsKeyPressed(VK_RETURN))
{
// check they really want to do this
UINT uiIDA[2];
uiIDA[0]=IDS_CONFIRM_CANCEL;
uiIDA[1]=IDS_CONFIRM_OK;
ui.RequestAlertMessage(IDS_DEFAULTS_TITLE, IDS_DEFAULTS_TEXT, uiIDA, 2, m_iPad,&UIScene_SettingsMenu::ResetDefaultsDialogReturned,this);
}
ctx->ProcessKeyDown(Rml::Input::KI_RETURN, 0);
handled = true;
}
break;
case ACTION_MENU_CANCEL:
case ACTION_MENU_PAUSEMENU:
if (m_bConfirmDialog)
{
OnConfirmNo();
handled = true;
}
else
{
app.CheckGameSettingsChanged(true, iPad);
navigateBack();
handled = true;
}
break;
default:
break;
}
}
int UIScene_SettingsMenu::ResetDefaultsDialogReturned(void *pParam,int iPad,C4JStorage::EMessageResult result)
void UIScene_SettingsMenu::ProcessEvent(Rml::Event& event)
{
UIScene_SettingsMenu* pClass = static_cast<UIScene_SettingsMenu *>(pParam);
const Rml::String& id = event.GetCurrentElement()->GetId();
// results switched for this dialog
if(result==C4JStorage::EMessage_ResultDecline)
if (event == Rml::EventId::Click)
{
#if (defined __PS3__ || defined __ORBIS__ || defined _DURANGO || defined __PSVITA__)
app.SetDefaultOptions(StorageManager.GetDashboardProfileSettings(pClass->m_iPad),pClass->m_iPad);
#else
app.SetDefaultOptions(ProfileManager.GetDashboardProfileSettings(pClass->m_iPad),pClass->m_iPad);
#endif
// if the profile data has been changed, then force a profile write
// It seems we're allowed to break the 5 minute rule if it's the result of a user action
app.CheckGameSettingsChanged(true,iPad);
if (id == "options") OnOptions();
else if (id == "audio") OnAudio();
else if (id == "controls") OnControls();
else if (id == "graphics") OnGraphics();
else if (id == "ui") OnUI();
else if (id == "reset_defaults") OnResetToDefaults();
else if (id == "confirm_yes") OnConfirmYes();
else if (id == "confirm_no") OnConfirmNo();
}
return 0;
}
void UIScene_SettingsMenu::navigateBack()
{
ui.PlayUISFX(eSFX_Back);
UIScene::navigateBack();
}
void UIScene_SettingsMenu::OnOptions()
{
ui.PlayUISFX(eSFX_Press);
ui.NavigateToScene(m_iPad, eUIScene_SettingsOptionsMenu);
}
void UIScene_SettingsMenu::OnAudio()
{
ui.PlayUISFX(eSFX_Press);
ui.NavigateToScene(m_iPad, eUIScene_SettingsAudioMenu);
}
void UIScene_SettingsMenu::OnControls()
{
ui.PlayUISFX(eSFX_Press);
ui.NavigateToScene(m_iPad, eUIScene_SettingsControlMenu);
}
void UIScene_SettingsMenu::OnGraphics()
{
ui.PlayUISFX(eSFX_Press);
ui.NavigateToScene(m_iPad, eUIScene_SettingsGraphicsMenu);
}
void UIScene_SettingsMenu::OnUI()
{
ui.PlayUISFX(eSFX_Press);
ui.NavigateToScene(m_iPad, eUIScene_SettingsUIMenu);
}
void UIScene_SettingsMenu::ShowConfirmDialog(bool show)
{
if (!m_document)
return;
auto* confirmDialog = m_document->GetElementById("confirm_dialog");
auto* buttons = m_document->GetElementById("buttons");
if (show)
{
if (buttons) buttons->SetProperty("display", "none");
if (confirmDialog) confirmDialog->SetProperty("display", "block");
m_document->GetElementById("confirm_no")->Focus();
m_bConfirmDialog = true;
}
else
{
if (confirmDialog) confirmDialog->SetProperty("display", "none");
if (buttons) buttons->SetProperty("display", "block");
m_document->GetElementById("reset_defaults")->Focus();
m_bConfirmDialog = false;
}
}
void UIScene_SettingsMenu::OnResetToDefaults()
{
ShowConfirmDialog(true);
}
void UIScene_SettingsMenu::OnConfirmYes()
{
app.SetDefaultOptions(ProfileManager.GetDashboardProfileSettings(m_iPad), m_iPad);
app.CheckGameSettingsChanged(true, m_iPad);
navigateBack();
}
void UIScene_SettingsMenu::OnConfirmNo()
{
ShowConfirmDialog(false);
}