mirror of
https://github.com/GabsPuNs/Project-Zenith-Main.git
synced 2026-07-10 18:48:25 +00:00
168 lines
3.9 KiB
C++
168 lines
3.9 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_HelpAndOptionsMenu.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_HelpAndOptionsMenu::UIScene_HelpAndOptionsMenu(int iPad, void *initData, UILayer *parentLayer)
|
|
: UIScene_RmlBase(iPad, parentLayer)
|
|
{
|
|
Rml::Context* ctx = RmlManager::Get().GetContext();
|
|
if (!ctx)
|
|
{
|
|
app.DebugPrintf("[RmlHelpAndOptions] No RmlUi context available\n");
|
|
return;
|
|
}
|
|
|
|
m_document = ctx->LoadDocument("HelpOptions.rml");
|
|
if (!m_document)
|
|
{
|
|
app.DebugPrintf("[RmlHelpAndOptions] Failed to load HelpOptions.rml\n");
|
|
return;
|
|
}
|
|
|
|
m_document->Show();
|
|
|
|
if (!ProfileManager.IsFullVersion())
|
|
{
|
|
auto* el = m_document->GetElementById("change_skin");
|
|
if (el) el->SetProperty("display", "none");
|
|
}
|
|
|
|
if (app.GetLocalPlayerCount() > 1)
|
|
{
|
|
auto* el = m_document->GetElementById("credits");
|
|
if (el) el->SetProperty("display", "none");
|
|
}
|
|
|
|
RegisterEvents({ "change_skin", "how_to_play", "controls", "settings", "credits" });
|
|
m_document->GetElementById("change_skin")->Focus();
|
|
|
|
ui.HidePressStart();
|
|
TelemetryManager->RecordMenuShown(m_iPad, eUIScene_HelpAndOptionsMenu, 0);
|
|
}
|
|
|
|
UIScene_HelpAndOptionsMenu::~UIScene_HelpAndOptionsMenu()
|
|
{
|
|
if (m_document)
|
|
{
|
|
UnregisterEvents({ "change_skin", "how_to_play", "controls", "settings", "credits" });
|
|
m_document->Close();
|
|
}
|
|
}
|
|
|
|
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)
|
|
{
|
|
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::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_HelpAndOptionsMenu::navigateBack()
|
|
{
|
|
ui.PlayUISFX(eSFX_Back);
|
|
UIScene::navigateBack();
|
|
}
|
|
|
|
void UIScene_HelpAndOptionsMenu::OnChangeSkin()
|
|
{
|
|
ui.PlayUISFX(eSFX_Press);
|
|
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);
|
|
}
|