mirror of
https://github.com/GabsPuNs/Project-Zenith-Main.git
synced 2026-07-09 19:48:27 +00:00
188 lines
4.6 KiB
C++
188 lines
4.6 KiB
C++
#include "UI.h"
|
|
#include "../../Minecraft.h"
|
|
|
|
#pragma push_macro("byte")
|
|
#pragma push_macro("GetNextSibling")
|
|
#pragma push_macro("GetFirstChild")
|
|
#undef byte
|
|
#undef GetNextSibling
|
|
#undef GetFirstChild
|
|
|
|
#include "UIScene_SettingsMenu.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")
|
|
|
|
UIScene_SettingsMenu::UIScene_SettingsMenu(int iPad, void *initData, UILayer *parentLayer)
|
|
: UIScene_RmlBase(iPad, parentLayer)
|
|
{
|
|
Rml::Context* ctx = RmlManager::Get().GetContext();
|
|
if (!ctx)
|
|
{
|
|
app.DebugPrintf("[RmlSettingsMenu] No RmlUi context available\n");
|
|
return;
|
|
}
|
|
|
|
m_document = ctx->LoadDocument("SettingsMenu.rml");
|
|
if (!m_document)
|
|
{
|
|
app.DebugPrintf("[RmlSettingsMenu] Failed to load SettingsMenu.rml\n");
|
|
return;
|
|
}
|
|
|
|
m_document->Show();
|
|
|
|
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");
|
|
}
|
|
|
|
RegisterEvents({ "options", "audio", "controls", "graphics", "ui", "reset_defaults" });
|
|
m_document->GetElementById("options")->Focus();
|
|
|
|
updateComponents();
|
|
ui.HidePressStart();
|
|
TelemetryManager->RecordMenuShown(m_iPad, eUIScene_SettingsMenu, 0);
|
|
}
|
|
|
|
UIScene_SettingsMenu::~UIScene_SettingsMenu()
|
|
{
|
|
if (m_document)
|
|
{
|
|
UnregisterEvents({ "options", "audio", "controls", "graphics", "ui", "reset_defaults" });
|
|
m_document->Close();
|
|
}
|
|
}
|
|
|
|
void UIScene_SettingsMenu::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:
|
|
case ACTION_MENU_PAUSEMENU:
|
|
app.CheckGameSettingsChanged(true, iPad);
|
|
navigateBack();
|
|
handled = true;
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
void UIScene_SettingsMenu::ProcessEvent(Rml::Event& event)
|
|
{
|
|
const Rml::String& id = event.GetCurrentElement()->GetId();
|
|
|
|
if (event == Rml::EventId::Click)
|
|
{
|
|
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();
|
|
}
|
|
}
|
|
|
|
void UIScene_SettingsMenu::updateComponents()
|
|
{
|
|
bool bNotInGame = (Minecraft::GetInstance()->level == nullptr);
|
|
if (bNotInGame)
|
|
{
|
|
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);
|
|
m_parentLayer->showComponent(m_iPad, eUIComponent_Logo, app.GetLocalPlayerCount() == 1);
|
|
}
|
|
}
|
|
|
|
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::OnResetToDefaults()
|
|
{
|
|
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);
|
|
}
|
|
|
|
int UIScene_SettingsMenu::ResetDefaultsDialogReturned(void *pParam, int iPad, C4JStorage::EMessageResult result)
|
|
{
|
|
auto pClass = static_cast<UIScene_SettingsMenu*>(pParam);
|
|
|
|
if (result == C4JStorage::EMessage_ResultDecline)
|
|
{
|
|
app.SetDefaultOptions(ProfileManager.GetDashboardProfileSettings(pClass->m_iPad), pClass->m_iPad);
|
|
app.CheckGameSettingsChanged(true, iPad);
|
|
}
|
|
return 0;
|
|
}
|