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,235 +1,260 @@
#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_HelpAndOptionsMenu.h"
#include "..\..\Minecraft.h"
#include "RmlManager.h"
#include "../../Windows64/KeyboardMouseInput.h"
#include <RmlUi/Core/Input.h>
#include <RmlUi/Core/Context.h>
UIScene_HelpAndOptionsMenu::UIScene_HelpAndOptionsMenu(int iPad, void *initData, UILayer *parentLayer) : UIScene(iPad, parentLayer)
#pragma pop_macro("GetFirstChild")
#pragma pop_macro("GetNextSibling")
#pragma pop_macro("byte")
UIScene_HelpAndOptionsMenu::UIScene_HelpAndOptionsMenu(int iPad, void *initData, UILayer *parentLayer)
: UIScene(iPad, parentLayer)
, m_document(nullptr)
{
// Setup all the Iggy references we need for this scene
initialiseMovie();
m_bNotInGame=(Minecraft::GetInstance()->level==nullptr);
m_buttons[BUTTON_HAO_CHANGESKIN].init(IDS_CHANGE_SKIN,BUTTON_HAO_CHANGESKIN);
m_buttons[BUTTON_HAO_HOWTOPLAY].init(IDS_HOW_TO_PLAY,BUTTON_HAO_HOWTOPLAY);
m_buttons[BUTTON_HAO_CONTROLS].init(IDS_CONTROLS,BUTTON_HAO_CONTROLS);
m_buttons[BUTTON_HAO_SETTINGS].init(IDS_SETTINGS,BUTTON_HAO_SETTINGS);
m_buttons[BUTTON_HAO_CREDITS].init(IDS_CREDITS,BUTTON_HAO_CREDITS);
//m_buttons[BUTTON_HAO_REINSTALL].init(app.GetString(IDS_REINSTALL_CONTENT),BUTTON_HAO_REINSTALL);
m_buttons[BUTTON_HAO_DEBUG].init(IDS_DEBUG_SETTINGS,BUTTON_HAO_DEBUG);
/* 4J-TomK - we should never remove a control before the other buttons controls are initialised!
(because vita touchboxes are rebuilt on remove since the remaining positions might change) */
// We don't have a reinstall content, so remove the button
removeControl( &m_buttons[BUTTON_HAO_REINSTALL], false );
#ifndef _DEBUG
removeControl( &m_buttons[BUTTON_HAO_DEBUG], false);
#else
if(!app.DebugSettingsOn()) removeControl( &m_buttons[BUTTON_HAO_DEBUG], false);
#endif
#ifdef _XBOX_ONE
// 4J-PB - in order to buy the skin packs, we need the signed offer ids for them, which we get in the availability info
// we need to retrieve this info though, so do it here
app.AddDLCRequest(e_Marketplace_Content); // content is skin packs, texture packs and mash-up packs
// we also need to mount the local DLC so we can tell what's been purchased
app.StartInstallDLCProcess(iPad);
#endif
// 4J-PB - do not need a storage device to see this menu - just need one when you choose to re-install them
bool bNotInGame=(Minecraft::GetInstance()->level==nullptr);
// any content to be re-installed?
if(m_iPad==ProfileManager.GetPrimaryPad() && bNotInGame)
Rml::Context* ctx = RmlManager::Get().GetContext();
if (!ctx)
{
// We should show the reinstall menu
app.DebugPrintf("Reinstall Menu required...\n");
app.DebugPrintf("[RmlHelpAndOptions] No RmlUi context available\n");
return;
}
m_document = ctx->LoadDocument("HelpOptions.rml");
if (m_document)
{
m_document->Show();
bool bNotInGame = (Minecraft::GetInstance()->level == nullptr);
// Change Skin: hide if not full version
if (!ProfileManager.IsFullVersion())
{
auto* el = m_document->GetElementById("change_skin");
if (el) el->SetProperty("display", "none");
}
// Credits: hide in splitscreen
if (app.GetLocalPlayerCount() > 1)
{
auto* el = m_document->GetElementById("credits");
if (el) el->SetProperty("display", "none");
}
// Register button click listeners
m_document->GetElementById("change_skin")->AddEventListener(Rml::EventId::Click, this);
m_document->GetElementById("how_to_play")->AddEventListener(Rml::EventId::Click, this);
m_document->GetElementById("controls")->AddEventListener(Rml::EventId::Click, this);
m_document->GetElementById("settings")->AddEventListener(Rml::EventId::Click, this);
m_document->GetElementById("credits")->AddEventListener(Rml::EventId::Click, this);
// Focus first visible button
m_document->GetElementById("change_skin")->Focus();
}
else
{
removeControl( &m_buttons[BUTTON_HAO_REINSTALL], false);
app.DebugPrintf("[RmlHelpAndOptions] Failed to load HelpOptions.rml\n");
}
if(app.GetLocalPlayerCount()>1)
{
// no credits in splitscreen
removeControl( &m_buttons[BUTTON_HAO_CREDITS], false);
ui.HidePressStart();
#if TO_BE_IMPLEMENTED
app.AdjustSplitscreenScene(m_hObj,&m_OriginalPosition,m_iPad,false);
#endif
if(ProfileManager.GetPrimaryPad()!=m_iPad)
{
removeControl( &m_buttons[BUTTON_HAO_REINSTALL], false);
}
}
if(!ProfileManager.IsFullVersion() )//|| ProfileManager.IsGuest(m_iPad))
{
removeControl( &m_buttons[BUTTON_HAO_CHANGESKIN], false);
}
// 4J-TomK Moved horizontal resize check to the end to prevent horizontal scaling for buttons that might get removed anyways (debug options for example)
doHorizontalResizeCheck();
//StorageManager.TMSPP_GetUserQuotaInfo(C4JStorage::eGlobalStorage_TitleUser,iPad);
//StorageManager.WebServiceRequestGetFriends(iPad);
TelemetryManager->RecordMenuShown(m_iPad, eUIScene_HelpAndOptionsMenu, 0);
}
UIScene_HelpAndOptionsMenu::~UIScene_HelpAndOptionsMenu()
{
if (m_document)
{
m_document->GetElementById("change_skin")->RemoveEventListener(Rml::EventId::Click, this);
m_document->GetElementById("how_to_play")->RemoveEventListener(Rml::EventId::Click, this);
m_document->GetElementById("controls")->RemoveEventListener(Rml::EventId::Click, this);
m_document->GetElementById("settings")->RemoveEventListener(Rml::EventId::Click, this);
m_document->GetElementById("credits")->RemoveEventListener(Rml::EventId::Click, this);
m_document->Close();
m_document = nullptr;
}
}
wstring UIScene_HelpAndOptionsMenu::getMoviePath()
void UIScene_HelpAndOptionsMenu::gainFocus()
{
if(app.GetLocalPlayerCount() > 1)
if (!bHasFocus && stealsFocus())
{
return L"HelpAndOptionsMenuSplit";
bHasFocus = true;
updateTooltips();
updateComponents();
if (!m_bFocussedOnce)
{
}
handleGainFocus(m_bFocussedOnce);
if (bHasFocus)
m_bFocussedOnce = true;
if (m_document)
m_document->Show();
}
else
}
void UIScene_HelpAndOptionsMenu::handleLoseFocus()
{
if (m_document)
m_document->Hide();
}
void UIScene_HelpAndOptionsMenu::reloadMovie(bool force)
{
}
void UIScene_HelpAndOptionsMenu::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_HelpAndOptionsMenu::render(S32 width, S32 height, C4JRender::eViewportType viewport)
{
}
void UIScene_HelpAndOptionsMenu::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)
{
return L"HelpAndOptionsMenu";
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:
case ACTION_MENU_PAUSEMENU:
navigateBack();
handled = true;
break;
default:
break;
}
}
void UIScene_HelpAndOptionsMenu::ProcessEvent(Rml::Event& event)
{
const Rml::String& id = event.GetCurrentElement()->GetId();
if (event == Rml::EventId::Click)
{
if (id == "change_skin") OnChangeSkin();
else if (id == "how_to_play") OnHowToPlay();
else if (id == "controls") OnControls();
else if (id == "settings") OnSettings();
else if (id == "credits") OnCredits();
}
}
void UIScene_HelpAndOptionsMenu::updateTooltips()
{
ui.SetTooltips( m_iPad, IDS_TOOLTIPS_SELECT,IDS_TOOLTIPS_BACK);
}
void UIScene_HelpAndOptionsMenu::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_HelpAndOptionsMenu::handleReload()
void UIScene_HelpAndOptionsMenu::navigateBack()
{
#ifndef _DEBUG // def _FINAL_BUILD // disable debug settings in release builds
removeControl( &m_buttons[BUTTON_HAO_DEBUG], false);
#else
if(!app.DebugSettingsOn()) removeControl( &m_buttons[BUTTON_HAO_DEBUG], false);
#endif
// 4J-PB - do not need a storage device to see this menu - just need one when you choose to re-install them
bool bNotInGame=(Minecraft::GetInstance()->level==nullptr);
// any content to be re-installed?
if(m_iPad==ProfileManager.GetPrimaryPad() && bNotInGame)
{
// We should show the reinstall menu
app.DebugPrintf("Reinstall Menu required...\n");
}
else
{
removeControl( &m_buttons[BUTTON_HAO_REINSTALL], false);
}
if(app.GetLocalPlayerCount()>1)
{
// no credits in splitscreen
removeControl( &m_buttons[BUTTON_HAO_CREDITS], false);
#if TO_BE_IMPLEMENTED
app.AdjustSplitscreenScene(m_hObj,&m_OriginalPosition,m_iPad,false);
#endif
if(ProfileManager.GetPrimaryPad()!=m_iPad)
{
removeControl( &m_buttons[BUTTON_HAO_REINSTALL], false);
}
}
if(!ProfileManager.IsFullVersion() )//|| ProfileManager.IsGuest(m_iPad))
{
#if TO_BE_IMPLEMENTED
m_Buttons[BUTTON_HAO_CHANGESKIN].SetEnable(FALSE);
m_Buttons[BUTTON_HAO_CHANGESKIN].EnableInput(FALSE);
// set the focus to the second button
XuiElementSetUserFocus(m_Buttons[BUTTON_HAO_HOWTOPLAY].m_hObj, m_iPad);
#endif
}
if(!ProfileManager.IsFullVersion() )//|| ProfileManager.IsGuest(m_iPad))
{
removeControl( &m_buttons[BUTTON_HAO_CHANGESKIN], false);
}
doHorizontalResizeCheck();
ui.PlayUISFX(eSFX_Back);
UIScene::navigateBack();
}
void UIScene_HelpAndOptionsMenu::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)
{
case ACTION_MENU_CANCEL:
if(pressed && !repeat)
{
navigateBack();
}
break;
case ACTION_MENU_OK:
#ifdef __ORBIS__
case ACTION_MENU_TOUCHPAD_PRESS:
#endif
//CD - Added for audio
if(pressed)
{
ui.PlayUISFX(eSFX_Press);
}
case ACTION_MENU_UP:
case ACTION_MENU_DOWN:
sendInputToMovie(key, repeat, pressed, released);
break;
}
}
void UIScene_HelpAndOptionsMenu::handlePress(F64 controlId, F64 childId)
void UIScene_HelpAndOptionsMenu::OnChangeSkin()
{
ui.PlayUISFX(eSFX_Press);
switch(static_cast<int>(controlId))
{
case BUTTON_HAO_CHANGESKIN:
ui.NavigateToScene(m_iPad, eUIScene_SkinSelectMenu);
break;
case BUTTON_HAO_HOWTOPLAY:
ui.NavigateToScene(m_iPad, eUIScene_HowToPlayMenu);
break;
case BUTTON_HAO_CONTROLS:
ui.NavigateToScene(m_iPad, eUIScene_ControlsMenu);
break;
case BUTTON_HAO_SETTINGS:
ui.NavigateToScene(m_iPad, eUIScene_SettingsMenu);
break;
case BUTTON_HAO_CREDITS:
ui.NavigateToScene(m_iPad, eUIScene_Credits);
break;
case BUTTON_HAO_REINSTALL:
ui.NavigateToScene(m_iPad, eUIScene_ReinstallMenu);
break;
case BUTTON_HAO_DEBUG:
ui.NavigateToScene(m_iPad, eUIScene_DebugOptions);
break;
}
ui.NavigateToScene(m_iPad, eUIScene_SkinSelectMenu);
}
void UIScene_HelpAndOptionsMenu::OnHowToPlay()
{
ui.PlayUISFX(eSFX_Press);
ui.NavigateToScene(m_iPad, eUIScene_HowToPlayMenu);
}
void UIScene_HelpAndOptionsMenu::OnControls()
{
ui.PlayUISFX(eSFX_Press);
ui.NavigateToScene(m_iPad, eUIScene_ControlsMenu);
}
void UIScene_HelpAndOptionsMenu::OnSettings()
{
ui.PlayUISFX(eSFX_Press);
ui.NavigateToScene(m_iPad, eUIScene_SettingsMenu);
}
void UIScene_HelpAndOptionsMenu::OnCredits()
{
ui.PlayUISFX(eSFX_Press);
ui.NavigateToScene(m_iPad, eUIScene_Credits);
}