mirror of
https://github.com/GabsPuNs/Project-Zenith-Main.git
synced 2026-07-10 07:38:46 +00:00
240 lines
6.3 KiB
C++
240 lines
6.3 KiB
C++
#include "UI.h"
|
|
#include "../../MinecraftServer.h"
|
|
#include "../../MultiPlayerLocalPlayer.h"
|
|
|
|
#pragma push_macro("byte")
|
|
#pragma push_macro("GetNextSibling")
|
|
#pragma push_macro("GetFirstChild")
|
|
#undef byte
|
|
#undef GetNextSibling
|
|
#undef GetFirstChild
|
|
|
|
#include "UIScene_PauseMenu.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_PauseMenu::UIScene_PauseMenu(int iPad, void *initData, UILayer *parentLayer)
|
|
: UIScene_RmlBase(iPad, parentLayer)
|
|
{
|
|
Rml::Context* ctx = RmlManager::Get().GetContext();
|
|
if (!ctx)
|
|
{
|
|
app.DebugPrintf("[RmlPauseMenu] No RmlUi context available\n");
|
|
return;
|
|
}
|
|
|
|
m_document = ctx->LoadDocument("PauseMenu.rml");
|
|
if (m_document)
|
|
{
|
|
app.DebugPrintf("[RmlPauseMenu] Document loaded OK, showing...\n");
|
|
m_document->Show();
|
|
app.DebugPrintf("[RmlPauseMenu] Document shown, visible=%d, context docs=%d\n",
|
|
m_document->IsVisible(), ctx->GetNumDocuments());
|
|
|
|
RegisterEvents({ "resume", "help_options", "achievements", "save_game", "exit_game" });
|
|
m_document->GetElementById("resume")->Focus();
|
|
}
|
|
else
|
|
app.DebugPrintf("[RmlPauseMenu] Failed to load PauseMenu.rml\n");
|
|
|
|
ui.HidePressStart();
|
|
|
|
m_parentLayer->showComponent(m_iPad, eUIComponent_Panorama, false);
|
|
m_parentLayer->showComponent(m_iPad, eUIComponent_MenuBackground, true);
|
|
m_parentLayer->showComponent(m_iPad, eUIComponent_Logo, true);
|
|
|
|
if (g_NetworkManager.IsLocalGame() && g_NetworkManager.GetPlayerCount() == 1)
|
|
app.SetXuiServerAction(ProfileManager.GetPrimaryPad(), eXuiServerAction_PauseServer, (void*)TRUE);
|
|
|
|
TelemetryManager->RecordMenuShown(m_iPad, eUIScene_PauseMenu, 0);
|
|
TelemetryManager->RecordPauseOrInactive(m_iPad);
|
|
}
|
|
|
|
UIScene_PauseMenu::~UIScene_PauseMenu()
|
|
{
|
|
if (m_document)
|
|
{
|
|
UnregisterEvents({ "resume", "help_options", "achievements", "save_game", "exit_game" });
|
|
m_document->Close();
|
|
}
|
|
|
|
m_parentLayer->showComponent(m_iPad, eUIComponent_Panorama, false);
|
|
m_parentLayer->showComponent(m_iPad, eUIComponent_MenuBackground, false);
|
|
m_parentLayer->showComponent(m_iPad, eUIComponent_Logo, false);
|
|
}
|
|
|
|
void UIScene_PauseMenu::handleInput(int iPad, int key, bool repeat, bool pressed, bool released, bool &handled)
|
|
{
|
|
if (m_bIgnoreInput)
|
|
return;
|
|
|
|
if (pressed)
|
|
{
|
|
if (iPad == ProfileManager.GetPrimaryPad() && g_NetworkManager.IsLocalGame())
|
|
app.SetXuiServerAction(ProfileManager.GetPrimaryPad(), eXuiServerAction_PauseServer, (void*)FALSE);
|
|
}
|
|
|
|
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);
|
|
break;
|
|
case ACTION_MENU_DOWN:
|
|
ctx->ProcessKeyDown(Rml::Input::KI_DOWN, 0);
|
|
break;
|
|
case ACTION_MENU_OK:
|
|
if (g_KBMInput.IsKeyPressed(VK_RETURN))
|
|
ctx->ProcessKeyDown(Rml::Input::KI_RETURN, 0);
|
|
break;
|
|
case ACTION_MENU_CANCEL:
|
|
case ACTION_MENU_PAUSEMENU:
|
|
navigateBack();
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
handled = true;
|
|
}
|
|
|
|
void UIScene_PauseMenu::ProcessEvent(Rml::Event& event)
|
|
{
|
|
if (m_bIgnoreInput)
|
|
return;
|
|
|
|
const Rml::String& id = event.GetCurrentElement()->GetId();
|
|
|
|
if (event == Rml::EventId::Click)
|
|
{
|
|
if (id == "resume") OnResume();
|
|
else if (id == "help_options") OnHelpAndOptions();
|
|
else if (id == "achievements") OnAchievements();
|
|
else if (id == "save_game") OnSaveGame();
|
|
else if (id == "exit_game") OnExitGame();
|
|
}
|
|
}
|
|
|
|
void UIScene_PauseMenu::ShowScene(bool show)
|
|
{
|
|
if (m_document)
|
|
{
|
|
if (show)
|
|
m_document->Show();
|
|
else
|
|
m_document->Hide();
|
|
}
|
|
}
|
|
|
|
void UIScene_PauseMenu::navigateBack()
|
|
{
|
|
if (m_iPad == ProfileManager.GetPrimaryPad() && g_NetworkManager.IsLocalGame())
|
|
app.SetXuiServerAction(ProfileManager.GetPrimaryPad(), eXuiServerAction_PauseServer, (void*)FALSE);
|
|
|
|
ui.PlayUISFX(eSFX_Back);
|
|
UIScene::navigateBack();
|
|
}
|
|
|
|
void UIScene_PauseMenu::OnResume()
|
|
{
|
|
ui.PlayUISFX(eSFX_Back);
|
|
navigateBack();
|
|
}
|
|
|
|
void UIScene_PauseMenu::OnHelpAndOptions()
|
|
{
|
|
ui.NavigateToScene(m_iPad, eUIScene_HelpAndOptionsMenu);
|
|
}
|
|
|
|
void UIScene_PauseMenu::OnAchievements()
|
|
{
|
|
ui.NavigateToScene(m_iPad, eUIScene_AchievementsMenu);
|
|
}
|
|
|
|
void UIScene_PauseMenu::OnSaveGame()
|
|
{
|
|
if (m_iPad != ProfileManager.GetPrimaryPad())
|
|
return;
|
|
|
|
bool bSaveExists;
|
|
StorageManager.DoesSaveExist(&bSaveExists);
|
|
|
|
if (bSaveExists)
|
|
{
|
|
UINT uiIDA[2];
|
|
uiIDA[0] = IDS_CONFIRM_CANCEL;
|
|
uiIDA[1] = IDS_CONFIRM_OK;
|
|
ui.RequestAlertMessage(IDS_TITLE_SAVE_GAME, IDS_CONFIRM_SAVE_GAME, uiIDA, 2, m_iPad, &IUIScene_PauseMenu::SaveGameDialogReturned, (LPVOID)GetCallbackUniqueId());
|
|
}
|
|
else
|
|
{
|
|
app.SetAction(m_iPad, eAppAction_SaveGame);
|
|
}
|
|
}
|
|
|
|
void UIScene_PauseMenu::OnExitGame()
|
|
{
|
|
Minecraft* pMinecraft = Minecraft::GetInstance();
|
|
|
|
UINT uiIDA[3];
|
|
|
|
if (m_iPad == ProfileManager.GetPrimaryPad())
|
|
{
|
|
int playTime = -1;
|
|
if (pMinecraft->localplayers[m_iPad] != NULL)
|
|
playTime = (int)pMinecraft->localplayers[m_iPad]->getSessionTimer();
|
|
|
|
if (StorageManager.GetSaveDisabled())
|
|
{
|
|
uiIDA[0] = IDS_CONFIRM_CANCEL;
|
|
uiIDA[1] = IDS_CONFIRM_OK;
|
|
ui.RequestAlertMessage(IDS_EXIT_GAME, IDS_CONFIRM_EXIT_GAME_PROGRESS_LOST, uiIDA, 2, m_iPad, &IUIScene_PauseMenu::ExitGameDialogReturned, (LPVOID)GetCallbackUniqueId());
|
|
}
|
|
else
|
|
{
|
|
if (g_NetworkManager.IsHost())
|
|
{
|
|
uiIDA[0] = IDS_CONFIRM_CANCEL;
|
|
uiIDA[1] = IDS_EXIT_GAME_SAVE;
|
|
uiIDA[2] = IDS_EXIT_GAME_NO_SAVE;
|
|
|
|
if (g_NetworkManager.GetPlayerCount() > 1)
|
|
ui.RequestAlertMessage(IDS_EXIT_GAME, IDS_CONFIRM_EXIT_GAME_CONFIRM_DISCONNECT_SAVE, uiIDA, 3, m_iPad, &UIScene_PauseMenu::ExitGameSaveDialogReturned, (LPVOID)GetCallbackUniqueId());
|
|
else
|
|
ui.RequestAlertMessage(IDS_EXIT_GAME, IDS_CONFIRM_EXIT_GAME, uiIDA, 3, m_iPad, &UIScene_PauseMenu::ExitGameSaveDialogReturned, (LPVOID)GetCallbackUniqueId());
|
|
}
|
|
else
|
|
{
|
|
uiIDA[0] = IDS_CONFIRM_CANCEL;
|
|
uiIDA[1] = IDS_CONFIRM_OK;
|
|
|
|
ui.RequestAlertMessage(IDS_EXIT_GAME, IDS_CONFIRM_EXIT_GAME, uiIDA, 2, m_iPad, &IUIScene_PauseMenu::ExitGameDialogReturned, (LPVOID)GetCallbackUniqueId());
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
int playTime = -1;
|
|
if (pMinecraft->localplayers[m_iPad] != NULL)
|
|
playTime = (int)pMinecraft->localplayers[m_iPad]->getSessionTimer();
|
|
|
|
if (pMinecraft->localplayers[m_iPad] != nullptr)
|
|
TelemetryManager->RecordLevelExit(m_iPad, eSen_LevelExitStatus_Exited);
|
|
|
|
app.SetAction(m_iPad, eAppAction_ExitPlayer);
|
|
return;
|
|
}
|
|
}
|