mirror of
https://github.com/GabsPuNs/Project-Zenith-Main.git
synced 2026-07-18 03:30:40 +00:00
Port Settings Control and Audio Menu. Add focus sound.
This commit is contained in:
@@ -1,10 +1,8 @@
|
||||
#include "stdafx.h"
|
||||
|
||||
// Non-RmlUi includes that depend on Windows macros
|
||||
#include "UI.h"
|
||||
#include "UIScene_SettingsUIMenu.h"
|
||||
#include "../../Minecraft.h"
|
||||
#include "../../Windows64/KeyboardMouseInput.h"
|
||||
|
||||
// RmlUi includes (Windows macros temporarily suppressed)
|
||||
#pragma push_macro("byte")
|
||||
#pragma push_macro("GetNextSibling")
|
||||
#pragma push_macro("GetFirstChild")
|
||||
@@ -12,9 +10,7 @@
|
||||
#undef GetNextSibling
|
||||
#undef GetFirstChild
|
||||
|
||||
#include "UIScene_SettingsUIMenu.h"
|
||||
#include "RmlManager.h"
|
||||
#include "../../Windows64/KeyboardMouseInput.h"
|
||||
#include <RmlUi/Core/Input.h>
|
||||
#include <RmlUi/Core/Context.h>
|
||||
#include <RmlUi/Core/Box.h>
|
||||
@@ -24,16 +20,6 @@
|
||||
#pragma pop_macro("GetNextSibling")
|
||||
#pragma pop_macro("byte")
|
||||
|
||||
static Rml::String WideToUTF8(LPCWSTR wsz)
|
||||
{
|
||||
if (!wsz) return Rml::String();
|
||||
int len = WideCharToMultiByte(CP_UTF8, 0, wsz, -1, nullptr, 0, nullptr, nullptr);
|
||||
if (len <= 0) return Rml::String();
|
||||
Rml::String result(static_cast<size_t>(len) - 1, '\0');
|
||||
WideCharToMultiByte(CP_UTF8, 0, wsz, -1, &result[0], len, nullptr, nullptr);
|
||||
return result;
|
||||
}
|
||||
|
||||
struct ToggleEntry { const char* id; eGameSetting setting; };
|
||||
struct SliderEntry { const char* id; int* value; int idsString; int setting; };
|
||||
|
||||
@@ -51,8 +37,7 @@ static const ToggleEntry s_toggles[] =
|
||||
static const char* s_sliderIds[] = { "UISize", "UISizeSplitscreen" };
|
||||
|
||||
UIScene_SettingsUIMenu::UIScene_SettingsUIMenu(int iPad, void *initData, UILayer *parentLayer)
|
||||
: UIScene(iPad, parentLayer)
|
||||
, m_document(nullptr)
|
||||
: UIScene_RmlBase(iPad, parentLayer)
|
||||
, m_uiSizeValue(2)
|
||||
, m_uiSizeSplitscreenValue(2)
|
||||
, m_dragSliderIndex(-1)
|
||||
@@ -79,8 +64,8 @@ UIScene_SettingsUIMenu::UIScene_SettingsUIMenu(int iPad, void *initData, UILayer
|
||||
m_uiSizeValue = app.GetGameSettings(m_iPad, eGameSetting_UISize) + 1;
|
||||
m_uiSizeSplitscreenValue = app.GetGameSettings(m_iPad, eGameSetting_UISizeSplitscreen) + 1;
|
||||
|
||||
setSliderValue("UISize", WideToUTF8(app.GetString(IDS_SLIDER_UISIZE)), m_uiSizeValue, 1, 3);
|
||||
setSliderValue("UISizeSplitscreen", WideToUTF8(app.GetString(IDS_SLIDER_UISIZESPLITSCREEN)), m_uiSizeSplitscreenValue, 1, 3);
|
||||
setSliderValue("UISize", utils.WideToUtf8(app.GetString(IDS_SLIDER_UISIZE)), m_uiSizeValue, 1, 3);
|
||||
setSliderValue("UISizeSplitscreen", utils.WideToUtf8(app.GetString(IDS_SLIDER_UISIZESPLITSCREEN)), m_uiSizeSplitscreenValue, 1, 3);
|
||||
|
||||
registerEvents();
|
||||
|
||||
@@ -95,6 +80,7 @@ UIScene_SettingsUIMenu::UIScene_SettingsUIMenu(int iPad, void *initData, UILayer
|
||||
if (el) el->SetProperty("display", "none");
|
||||
}
|
||||
|
||||
updateComponents();
|
||||
ui.HidePressStart();
|
||||
TelemetryManager->RecordMenuShown(m_iPad, eUIScene_SettingsUIMenu, 0);
|
||||
}
|
||||
@@ -113,17 +99,29 @@ void UIScene_SettingsUIMenu::registerEvents()
|
||||
{
|
||||
for (size_t i = 0; i < sizeof(s_toggles) / sizeof(s_toggles[0]); i++)
|
||||
{
|
||||
Rml::Element* el = m_document->GetElementById(Rml::String(s_toggles[i].id) + "_toggle");
|
||||
if (el) el->AddEventListener(Rml::EventId::Click, this);
|
||||
Rml::Element* el = m_document->GetElementById(Rml::String(s_toggles[i].id));
|
||||
if (el)
|
||||
{
|
||||
el->AddEventListener(Rml::EventId::Click, this);
|
||||
el->AddEventListener(Rml::EventId::Mouseover, this);
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < sizeof(s_sliderIds) / sizeof(s_sliderIds[0]); i++)
|
||||
{
|
||||
Rml::Element* elTrack = m_document->GetElementById(Rml::String(s_sliderIds[i]) + "_track");
|
||||
if (elTrack) elTrack->AddEventListener(Rml::EventId::Mousedown, this);
|
||||
if (elTrack)
|
||||
{
|
||||
elTrack->AddEventListener(Rml::EventId::Mousedown, this);
|
||||
elTrack->AddEventListener(Rml::EventId::Mouseover, this);
|
||||
}
|
||||
|
||||
Rml::Element* elThumb = m_document->GetElementById(Rml::String(s_sliderIds[i]) + "_thumb");
|
||||
if (elThumb) elThumb->AddEventListener(Rml::EventId::Mousedown, this);
|
||||
if (elThumb)
|
||||
{
|
||||
elThumb->AddEventListener(Rml::EventId::Mousedown, this);
|
||||
elThumb->AddEventListener(Rml::EventId::Mouseover, this);
|
||||
}
|
||||
}
|
||||
|
||||
m_document->AddEventListener(Rml::EventId::Mousemove, this);
|
||||
@@ -134,17 +132,29 @@ void UIScene_SettingsUIMenu::deregisterEvents()
|
||||
{
|
||||
for (size_t i = 0; i < sizeof(s_toggles) / sizeof(s_toggles[0]); i++)
|
||||
{
|
||||
Rml::Element* el = m_document->GetElementById(Rml::String(s_toggles[i].id) + "_toggle");
|
||||
if (el) el->RemoveEventListener(Rml::EventId::Click, this);
|
||||
Rml::Element* el = m_document->GetElementById(Rml::String(s_toggles[i].id));
|
||||
if (el)
|
||||
{
|
||||
el->RemoveEventListener(Rml::EventId::Click, this);
|
||||
el->RemoveEventListener(Rml::EventId::Mouseover, this);
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < sizeof(s_sliderIds) / sizeof(s_sliderIds[0]); i++)
|
||||
{
|
||||
Rml::Element* elTrack = m_document->GetElementById(Rml::String(s_sliderIds[i]) + "_track");
|
||||
if (elTrack) elTrack->RemoveEventListener(Rml::EventId::Mousedown, this);
|
||||
if (elTrack)
|
||||
{
|
||||
elTrack->RemoveEventListener(Rml::EventId::Mousedown, this);
|
||||
elTrack->RemoveEventListener(Rml::EventId::Mouseover, this);
|
||||
}
|
||||
|
||||
Rml::Element* elThumb = m_document->GetElementById(Rml::String(s_sliderIds[i]) + "_thumb");
|
||||
if (elThumb) elThumb->RemoveEventListener(Rml::EventId::Mousedown, this);
|
||||
if (elThumb)
|
||||
{
|
||||
elThumb->RemoveEventListener(Rml::EventId::Mousedown, this);
|
||||
elThumb->RemoveEventListener(Rml::EventId::Mouseover, this);
|
||||
}
|
||||
}
|
||||
|
||||
m_document->RemoveEventListener(Rml::EventId::Mousemove, this);
|
||||
@@ -237,54 +247,6 @@ void UIScene_SettingsUIMenu::updateComponents()
|
||||
}
|
||||
}
|
||||
|
||||
void UIScene_SettingsUIMenu::gainFocus()
|
||||
{
|
||||
if (!bHasFocus && stealsFocus())
|
||||
{
|
||||
bHasFocus = true;
|
||||
updateComponents();
|
||||
handleGainFocus(m_bFocussedOnce);
|
||||
if (bHasFocus)
|
||||
m_bFocussedOnce = true;
|
||||
if (m_document)
|
||||
m_document->Show();
|
||||
}
|
||||
}
|
||||
|
||||
void UIScene_SettingsUIMenu::handleLoseFocus()
|
||||
{
|
||||
if (m_document)
|
||||
m_document->Hide();
|
||||
}
|
||||
|
||||
void UIScene_SettingsUIMenu::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);
|
||||
|
||||
RmlManager::Get().Update();
|
||||
}
|
||||
|
||||
void UIScene_SettingsUIMenu::ProcessEvent(Rml::Event& event)
|
||||
{
|
||||
if (event.GetId() == Rml::EventId::Click)
|
||||
@@ -294,11 +256,9 @@ void UIScene_SettingsUIMenu::ProcessEvent(Rml::Event& event)
|
||||
|
||||
for (size_t i = 0; i < sizeof(s_toggles) / sizeof(s_toggles[0]); i++)
|
||||
{
|
||||
if (id == Rml::String(s_toggles[i].id) + "_toggle")
|
||||
if (id == Rml::String(s_toggles[i].id))
|
||||
{
|
||||
Rml::Element* row = el->GetParentNode();
|
||||
if (row)
|
||||
row->SetClass("checked", !row->IsClassSet("checked"));
|
||||
el->SetClass("checked", !el->IsClassSet("checked"));
|
||||
ui.PlayUISFX(eSFX_Press);
|
||||
return;
|
||||
}
|
||||
@@ -333,9 +293,9 @@ void UIScene_SettingsUIMenu::ProcessEvent(Rml::Event& event)
|
||||
}
|
||||
}
|
||||
else if (event.GetId() == Rml::EventId::Mouseup)
|
||||
{
|
||||
m_dragSliderIndex = -1;
|
||||
}
|
||||
else if (event.GetId() == Rml::EventId::Mouseover)
|
||||
ui.PlayUISFX(eSFX_Focus);
|
||||
}
|
||||
|
||||
static void saveToggle(Rml::ElementDocument* doc, int iPad, const ToggleEntry& t)
|
||||
@@ -408,7 +368,7 @@ void UIScene_SettingsUIMenu::handleSliderMove(int sliderIndex, int value)
|
||||
eGameSetting setting = (sliderIndex == 0) ? eGameSetting_UISize : eGameSetting_UISizeSplitscreen;
|
||||
|
||||
*member = value;
|
||||
Rml::String prefix = WideToUTF8(app.GetString(idsString));
|
||||
Rml::String prefix = utils.WideToUtf8(app.GetString(idsString));
|
||||
setSliderValue(id, prefix, value, 1, 3);
|
||||
|
||||
if (value != app.GetGameSettings(m_iPad, setting) + 1)
|
||||
|
||||
Reference in New Issue
Block a user