diff --git a/Minecraft.Client/Assets/UI/HelpOptions.rml b/Minecraft.Client/Assets/UI/HelpOptions.rml index 1115dc42..ffb6c760 100644 --- a/Minecraft.Client/Assets/UI/HelpOptions.rml +++ b/Minecraft.Client/Assets/UI/HelpOptions.rml @@ -1,6 +1,5 @@ - Help & Options diff --git a/Minecraft.Client/Assets/UI/LoadCreateJoinMenu.rml b/Minecraft.Client/Assets/UI/LoadCreateJoinMenu.rml index 8aa0861f..d07d0a12 100644 --- a/Minecraft.Client/Assets/UI/LoadCreateJoinMenu.rml +++ b/Minecraft.Client/Assets/UI/LoadCreateJoinMenu.rml @@ -1,6 +1,5 @@ - Load/Create/Join Menu diff --git a/Minecraft.Client/Assets/UI/PauseMenu.rml b/Minecraft.Client/Assets/UI/PauseMenu.rml index bcd3100f..8957e66b 100644 --- a/Minecraft.Client/Assets/UI/PauseMenu.rml +++ b/Minecraft.Client/Assets/UI/PauseMenu.rml @@ -1,6 +1,5 @@ - Pause Menu diff --git a/Minecraft.Client/Assets/UI/SettingsAudioMenu.rcss b/Minecraft.Client/Assets/UI/SettingsAudioMenu.rcss new file mode 100644 index 00000000..809ae463 --- /dev/null +++ b/Minecraft.Client/Assets/UI/SettingsAudioMenu.rcss @@ -0,0 +1,160 @@ +body +{ + width: 100%; + height: 100%; + font-family: Minecraft Default; + font-size: 36dp; + font-effect: shadow(1dp 1dp #000000); + color: #333333; + background: transparent; + display: flex; + align-items: center; + justify-content: center; +} + +div#settings_audio_menu +{ + width: auto; + height: auto; + padding: 30dp 24dp; + decorator: image(images/lce/frame_MessageBox_background.png); + display: flex; + flex-direction: column; + align-items: stretch; +} + +div#controls +{ + width: auto; + display: flex; + flex-direction: column; + align-items: stretch; +} + +.toggle_row +{ + display: flex; + align-items: center; + align-self: flex-start; + width: auto; + height: auto; + margin-top: 2dp; +} + +.toggle_row button +{ + display: inline-block; + width: 30dp; + height: 30dp; + padding: 0; + border: none; + background: transparent; + cursor: pointer; +} + +.toggle_row .toggle_switch +{ + display: block; + width: 36dp; + height: 36dp; + decorator: image(images/lce/Tickbox_Background.png); + position: relative; +} + +.toggle_row:hover .toggle_switch +{ + decorator: image(images/lce/Tickbox_Over.png); +} + +.toggle_row:hover .toggle_label +{ + color: #ffff00; + font-effect: shadow(1dp 1dp #000000); +} + +.tick_mark +{ + display: block; + width: 42dp; + height: 36dp; + decorator: image(images/lce/Tick.png); +} + +.toggle_row:not(.checked) .tick_mark +{ + display: none; +} + +.toggle_label +{ + display: inline-block; + font-effect: none; + margin-left: 12dp; + white-space: nowrap; + cursor: pointer; +} + +.slider_row +{ + display: flex; + flex-direction: column; + align-items: stretch; + width: auto; + margin-bottom: 10dp; + cursor: pointer; +} + +.slider_container +{ + display: block; + position: relative; + width: auto; + min-width: 400dp; + height: 56dp; + right: 2dp; + padding: 0 12dp; + text-align: center; + box-sizing: border-box; + border: 3dp transparent; + decorator: image(images/lce/Slider_Background.png); +} + +.slider_container:hover +{ + border-color: #ffff00; + decorator: image(images/lce/Slider_BackgroundH.png); +} + +.slider_label +{ + display: inline-block; + vertical-align: middle; + color: #ffffff; + line-height: 50dp; + padding: 0 12dp; + white-space: nowrap; +} + +.slider_container:hover .slider_label +{ + color: #ffff00; +} + +.slider_track +{ + display: block; + position: relative; + width: 100%; + height: 100%; + cursor: resize; +} + +.slider_thumb +{ + position: absolute; + width: 24dp; + height: 50dp; + decorator: image(images/lce/Slider.png); + cursor: resize; + transform: translateX(-50%); +} diff --git a/Minecraft.Client/Assets/UI/SettingsAudioMenu.rml b/Minecraft.Client/Assets/UI/SettingsAudioMenu.rml new file mode 100644 index 00000000..2d5e19e9 --- /dev/null +++ b/Minecraft.Client/Assets/UI/SettingsAudioMenu.rml @@ -0,0 +1,31 @@ + + + + + +
+
+
+
+
+
+ [IDS_SLIDER_MUSIC]: 2 +
+
+
+
+
+
+
+ [IDS_SLIDER_SOUND]: 2 +
+
+
+
+ + [IDS_CHECKBOX_CAVESOUNDS] +
+
+
+ +
diff --git a/Minecraft.Client/Assets/UI/SettingsControlMenu.rcss b/Minecraft.Client/Assets/UI/SettingsControlMenu.rcss new file mode 100644 index 00000000..4cd20f36 --- /dev/null +++ b/Minecraft.Client/Assets/UI/SettingsControlMenu.rcss @@ -0,0 +1,100 @@ +body +{ + width: 100%; + height: 100%; + font-family: Minecraft Default; + font-size: 36dp; + font-effect: shadow(1dp 1dp #000000); + color: #ffffff; + background: transparent; + display: flex; + align-items: center; + justify-content: center; +} + +div#settings_control_menu +{ + width: auto; + height: auto; + padding: 30dp 24dp; + decorator: image(images/lce/frame_MessageBox_background.png); + display: flex; + flex-direction: column; + align-items: stretch; +} + +div#controls +{ + width: auto; + display: flex; + flex-direction: column; + align-items: stretch; +} + +.slider_row +{ + display: flex; + flex-direction: column; + align-items: stretch; + width: auto; + margin-top: 10dp; + cursor: pointer; +} + +.slider_row:first-child +{ + margin-top: 0; +} + +.slider_container +{ + display: block; + position: relative; + width: auto; + height: 56dp; + right: 2dp; + padding: 0 12dp; + text-align: center; + box-sizing: border-box; + border: 3dp transparent; + decorator: image(images/lce/Slider_Background.png); +} + +.slider_container:hover +{ + border-color: #ffff00; + decorator: image(images/lce/Slider_BackgroundH.png); +} + +.slider_label +{ + display: inline-block; + vertical-align: middle; + line-height: 50dp; + padding: 0 12dp; + white-space: nowrap; +} + +.slider_container:hover .slider_label +{ + color: #ffff00; +} + +.slider_track +{ + display: block; + position: relative; + width: 100%; + height: 100%; + cursor: resize; +} + +.slider_thumb +{ + position: absolute; + width: 24dp; + height: 50dp; + decorator: image(images/lce/Slider.png); + cursor: resize; + transform: translateX(-50%); +} diff --git a/Minecraft.Client/Assets/UI/SettingsControlMenu.rml b/Minecraft.Client/Assets/UI/SettingsControlMenu.rml new file mode 100644 index 00000000..07f1e4bb --- /dev/null +++ b/Minecraft.Client/Assets/UI/SettingsControlMenu.rml @@ -0,0 +1,27 @@ + + + + + +
+
+
+
+
+
+ [IDS_SLIDER_SENSITIVITY_INGAME]: 2 +
+
+
+
+
+
+
+ [IDS_SLIDER_SENSITIVITY_INMENU]: 2 +
+
+
+
+
+ +
diff --git a/Minecraft.Client/Assets/UI/SettingsMenu.rml b/Minecraft.Client/Assets/UI/SettingsMenu.rml index e076d36d..ab0e7bb2 100644 --- a/Minecraft.Client/Assets/UI/SettingsMenu.rml +++ b/Minecraft.Client/Assets/UI/SettingsMenu.rml @@ -1,6 +1,5 @@ - Settings diff --git a/Minecraft.Client/Assets/UI/SettingsUIMenu.rcss b/Minecraft.Client/Assets/UI/SettingsUIMenu.rcss index 557d73a3..a6e8a01d 100644 --- a/Minecraft.Client/Assets/UI/SettingsUIMenu.rcss +++ b/Minecraft.Client/Assets/UI/SettingsUIMenu.rcss @@ -3,7 +3,7 @@ body width: 100%; height: 100%; font-family: Minecraft Default; - font-size: 26dp; + font-size: 36dp; font-effect: shadow(1dp 1dp #000000); color: #333333; background: transparent; @@ -14,43 +14,31 @@ body div#settings_ui_menu { - width: 449dp; + width: auto; height: auto; - margin: auto; - margin-top: 320dp; - padding: 20dp 34dp; + padding: 30dp 24dp; decorator: image(images/lce/frame_MessageBox_background.png); display: flex; flex-direction: column; - align-items: center; -} - -p#title -{ - color: #333333; - font-size: 29dp; - font-weight: bold; - margin-bottom: 10dp; - text-align: center; - width: 100%; + align-items: stretch; } div#controls { - width: 100%; + width: auto; display: flex; flex-direction: column; - align-items: center; + align-items: stretch; } .toggle_row { display: flex; align-items: center; - width: 100%; - min-height: 30dp; - padding: 1dp 0; - margin-bottom: 3dp; + align-self: flex-start; + width: auto; + height: auto; + margin-bottom: 2dp; } .toggle_row button @@ -67,22 +55,28 @@ div#controls .toggle_row .toggle_switch { display: block; - width: 30dp; - height: 30dp; + width: 36dp; + height: 36dp; decorator: image(images/lce/Tickbox_Background.png); position: relative; } -.toggle_row button:hover .toggle_switch +.toggle_row:hover .toggle_switch { decorator: image(images/lce/Tickbox_Over.png); } +.toggle_row:hover .toggle_label +{ + color: #ffff00; + font-effect: shadow(1dp 1dp #000000); +} + .tick_mark { display: block; - width: 100%; - height: 100%; + width: 42dp; + height: 36dp; decorator: image(images/lce/Tick.png); } @@ -94,46 +88,50 @@ div#controls .toggle_label { display: inline-block; - font-size: 20dp; - color: #333333; - margin-left: 9dp; - line-height: 30dp; + font-effect: none; + margin-left: 12dp; + white-space: nowrap; + cursor: pointer; } .slider_row { display: flex; flex-direction: column; - width: 100%; - margin-bottom: 6dp; - padding: 2dp 0; + align-items: stretch; + width: auto; + margin-top: 10dp; + cursor: pointer; } .slider_container { - width: 100%; - height: 30dp; + display: block; position: relative; + width: auto; + height: 56dp; + right: 2dp; + padding: 0 12dp; + text-align: center; + box-sizing: border-box; + border: 3dp transparent; decorator: image(images/lce/Slider_Background.png); - border: 1dp transparent; } .slider_container:hover { border-color: #ffff00; + decorator: image(images/lce/Slider_BackgroundH.png); } .slider_label { - position: absolute; - left: 0; - top: 0; - width: 100%; - height: 100%; - font-size: 20dp; + display: inline-block; + vertical-align: middle; color: #ffffff; - text-align: center; - line-height: 30dp; + line-height: 50dp; + padding: 0 12dp; + white-space: nowrap; } .slider_container:hover .slider_label @@ -143,10 +141,9 @@ div#controls .slider_track { - position: absolute; - left: 8dp; - right: 8dp; - top: 0; + display: block; + position: relative; + width: 100%; height: 100%; cursor: resize; } @@ -154,8 +151,8 @@ div#controls .slider_thumb { position: absolute; - width: 12dp; - height: 30dp; + width: 24dp; + height: 50dp; decorator: image(images/lce/Slider.png); cursor: resize; transform: translateX(-50%); diff --git a/Minecraft.Client/Assets/UI/SettingsUIMenu.rml b/Minecraft.Client/Assets/UI/SettingsUIMenu.rml index f2db8b0c..613ce3cc 100644 --- a/Minecraft.Client/Assets/UI/SettingsUIMenu.rml +++ b/Minecraft.Client/Assets/UI/SettingsUIMenu.rml @@ -1,6 +1,5 @@ - UI Settings diff --git a/Minecraft.Client/Assets/UI/images/lce/Slider_BackgroundH.png b/Minecraft.Client/Assets/UI/images/lce/Slider_BackgroundH.png new file mode 100644 index 00000000..577cca9b Binary files /dev/null and b/Minecraft.Client/Assets/UI/images/lce/Slider_BackgroundH.png differ diff --git a/Minecraft.Client/Common/UI/UIScene_HelpAndOptionsMenu.cpp b/Minecraft.Client/Common/UI/UIScene_HelpAndOptionsMenu.cpp index da7a0e71..f06a2962 100644 --- a/Minecraft.Client/Common/UI/UIScene_HelpAndOptionsMenu.cpp +++ b/Minecraft.Client/Common/UI/UIScene_HelpAndOptionsMenu.cpp @@ -113,6 +113,8 @@ void UIScene_HelpAndOptionsMenu::ProcessEvent(Rml::Event& event) else if (id == "settings") OnSettings(); else if (id == "credits") OnCredits(); } + else if (event == Rml::EventId::Mouseover) + ui.PlayUISFX(eSFX_Focus); } void UIScene_HelpAndOptionsMenu::updateComponents() diff --git a/Minecraft.Client/Common/UI/UIScene_LoadCreateJoinMenu.cpp b/Minecraft.Client/Common/UI/UIScene_LoadCreateJoinMenu.cpp index d01a344d..4355fcac 100644 --- a/Minecraft.Client/Common/UI/UIScene_LoadCreateJoinMenu.cpp +++ b/Minecraft.Client/Common/UI/UIScene_LoadCreateJoinMenu.cpp @@ -229,6 +229,7 @@ void UIScene_LoadCreateJoinMenu::AddListItem(const char* listId, const wstring& sprintf_s(btnId, "%s_btn_%d", listId, index); btn->SetId(btnId); btn->AddEventListener(Rml::EventId::Click, this); + btn->AddEventListener(Rml::EventId::Mouseover, this); item->AppendChild(std::move(btnPtr)); container->AppendChild(std::move(itemPtr)); @@ -303,7 +304,11 @@ UIScene_LoadCreateJoinMenu::UIScene_LoadCreateJoinMenu(int iPad, void* initData, // Register tab button click listeners auto registerTab = [&](const char* id) { auto* el = m_document->GetElementById(id); - if (el) el->AddEventListener(Rml::EventId::Click, this); + if (el) + { + el->AddEventListener(Rml::EventId::Click, this); + el->AddEventListener(Rml::EventId::Mouseover, this); + } }; registerTab("tab_load"); registerTab("tab_create"); @@ -372,7 +377,11 @@ UIScene_LoadCreateJoinMenu::~UIScene_LoadCreateJoinMenu() { auto removeTab = [&](const char* id) { auto* el = m_document->GetElementById(id); - if (el) el->RemoveEventListener(Rml::EventId::Click, this); + if (el) + { + el->RemoveEventListener(Rml::EventId::Click, this); + el->RemoveEventListener(Rml::EventId::Mouseover, this); + } }; removeTab("tab_load"); removeTab("tab_create"); @@ -417,6 +426,8 @@ void UIScene_LoadCreateJoinMenu::ProcessEvent(Rml::Event& event) } } } + else if (event == Rml::EventId::Mouseover) + ui.PlayUISFX(eSFX_Focus); } // -- Update / Tooltips / Components -- diff --git a/Minecraft.Client/Common/UI/UIScene_MessageBox.cpp b/Minecraft.Client/Common/UI/UIScene_MessageBox.cpp index 4fb727e5..d0f67e17 100644 --- a/Minecraft.Client/Common/UI/UIScene_MessageBox.cpp +++ b/Minecraft.Client/Common/UI/UIScene_MessageBox.cpp @@ -68,6 +68,7 @@ UIScene_MessageBox::UIScene_MessageBox(int iPad, void *initData, UILayer *parent if (buttons[i]) { buttons[i]->AddEventListener(Rml::EventId::Click, this); + buttons[i]->AddEventListener(Rml::EventId::Mouseover, this); buttons[i]->SetProperty("display", "none"); } } @@ -98,17 +99,7 @@ UIScene_MessageBox::~UIScene_MessageBox() { if (m_document) { - Rml::Element* buttons[4] = { - m_document->GetElementById("button0"), - m_document->GetElementById("button1"), - m_document->GetElementById("button2"), - m_document->GetElementById("button3") - }; - for (int i = 0; i < 4; i++) - { - if (buttons[i]) - buttons[i]->RemoveEventListener(Rml::EventId::Click, this); - } + UnregisterEvents({ "button0", "button1", "button2", "button3" }); m_document->Close(); } @@ -182,6 +173,8 @@ void UIScene_MessageBox::ProcessEvent(Rml::Event& event) else if (id == "button2") OnButtonClicked(2); else if (id == "button3") OnButtonClicked(3); } + else if (event == Rml::EventId::Mouseover) + ui.PlayUISFX(eSFX_Focus); } void UIScene_MessageBox::OnButtonClicked(int buttonIndex) diff --git a/Minecraft.Client/Common/UI/UIScene_PauseMenu.cpp b/Minecraft.Client/Common/UI/UIScene_PauseMenu.cpp index c9cd913c..894c7624 100644 --- a/Minecraft.Client/Common/UI/UIScene_PauseMenu.cpp +++ b/Minecraft.Client/Common/UI/UIScene_PauseMenu.cpp @@ -129,6 +129,8 @@ void UIScene_PauseMenu::ProcessEvent(Rml::Event& event) else if (id == "save_game") OnSaveGame(); else if (id == "exit_game") OnExitGame(); } + else if (event == Rml::EventId::Mouseover) + ui.PlayUISFX(eSFX_Focus); } void UIScene_PauseMenu::ShowScene(bool show) @@ -159,11 +161,13 @@ void UIScene_PauseMenu::OnResume() void UIScene_PauseMenu::OnHelpAndOptions() { + ui.PlayUISFX(eSFX_Press); ui.NavigateToScene(m_iPad, eUIScene_HelpAndOptionsMenu); } void UIScene_PauseMenu::OnAchievements() { + ui.PlayUISFX(eSFX_Press); ui.NavigateToScene(m_iPad, eUIScene_AchievementsMenu); } @@ -172,6 +176,8 @@ void UIScene_PauseMenu::OnSaveGame() if (m_iPad != ProfileManager.GetPrimaryPad()) return; + ui.PlayUISFX(eSFX_Press); + bool bSaveExists; StorageManager.DoesSaveExist(&bSaveExists); @@ -183,13 +189,13 @@ void UIScene_PauseMenu::OnSaveGame() 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() { + ui.PlayUISFX(eSFX_Press); + Minecraft* pMinecraft = Minecraft::GetInstance(); UINT uiIDA[3]; diff --git a/Minecraft.Client/Common/UI/UIScene_RmlBase.cpp b/Minecraft.Client/Common/UI/UIScene_RmlBase.cpp index d27ebaf6..4c7a3ce8 100644 --- a/Minecraft.Client/Common/UI/UIScene_RmlBase.cpp +++ b/Minecraft.Client/Common/UI/UIScene_RmlBase.cpp @@ -84,7 +84,11 @@ void UIScene_RmlBase::RegisterEvents(std::initializer_list ids) for (const char* id : ids) { auto* el = m_document->GetElementById(id); - if (el) el->AddEventListener(Rml::EventId::Click, this); + if (el) + { + el->AddEventListener(Rml::EventId::Click, this); + el->AddEventListener(Rml::EventId::Mouseover, this); + } } } @@ -94,6 +98,10 @@ void UIScene_RmlBase::UnregisterEvents(std::initializer_list ids) for (const char* id : ids) { auto* el = m_document->GetElementById(id); - if (el) el->RemoveEventListener(Rml::EventId::Click, this); + if (el) + { + el->RemoveEventListener(Rml::EventId::Click, this); + el->RemoveEventListener(Rml::EventId::Mouseover, this); + } } } diff --git a/Minecraft.Client/Common/UI/UIScene_SettingsAudioMenu.cpp b/Minecraft.Client/Common/UI/UIScene_SettingsAudioMenu.cpp index 90013fcc..2ce2eb91 100644 --- a/Minecraft.Client/Common/UI/UIScene_SettingsAudioMenu.cpp +++ b/Minecraft.Client/Common/UI/UIScene_SettingsAudioMenu.cpp @@ -1,131 +1,353 @@ #include "UI.h" #include "UIScene_SettingsAudioMenu.h" +#include "../../Windows64/KeyboardMouseInput.h" -UIScene_SettingsAudioMenu::UIScene_SettingsAudioMenu(int iPad, void *initData, UILayer *parentLayer) : UIScene(iPad, parentLayer) +#pragma push_macro("byte") +#pragma push_macro("GetNextSibling") +#pragma push_macro("GetFirstChild") +#undef byte +#undef GetNextSibling +#undef GetFirstChild + +#include "RmlManager.h" +#include +#include +#include +#include + +#pragma pop_macro("GetFirstChild") +#pragma pop_macro("GetNextSibling") +#pragma pop_macro("byte") + +struct ToggleEntry { const char* id; eGameSetting setting; }; +struct SliderEntry { const char* id; int* value; int idsString; int setting; }; + +static const ToggleEntry s_toggles[] = { - // Setup all the Iggy references we need for this scene - initialiseMovie(); + { "CaveSounds", eGameSetting_CaveSounds }, +}; - WCHAR TempString[256]; - swprintf( TempString, 256, L"%ls: %d%%", app.GetString( IDS_SLIDER_MUSIC ),app.GetGameSettings(m_iPad,eGameSetting_MusicVolume)); - m_sliderMusic.init(TempString,eControl_Music,0,100,app.GetGameSettings(m_iPad,eGameSetting_MusicVolume)); - - swprintf( TempString, 256, L"%ls: %d%%", app.GetString( IDS_SLIDER_SOUND ),app.GetGameSettings(m_iPad,eGameSetting_SoundFXVolume)); - m_sliderSound.init(TempString,eControl_Sound,0,100,app.GetGameSettings(m_iPad,eGameSetting_SoundFXVolume)); +static const char* s_sliderIds[] = { "Music", "Sound" }; - swprintf( TempString, 256, L"%ls", app.GetString( IDS_CHECKBOX_CAVESOUNDS )); - m_checkboxCaveSounds.init(TempString, eControl_CaveSounds,(app.GetGameSettings(m_iPad,eGameSetting_CaveSounds)!=0)); - - doHorizontalResizeCheck(); - - if(app.GetLocalPlayerCount()>1) +UIScene_SettingsAudioMenu::UIScene_SettingsAudioMenu(int iPad, void *initData, UILayer *parentLayer) + : UIScene_RmlBase(iPad, parentLayer) + , m_musicValue(100) + , m_soundValue(100) + , m_dragSliderIndex(-1) +{ + Rml::Context* ctx = RmlManager::Get().GetContext(); + if (!ctx) { -#if TO_BE_IMPLEMENTED - app.AdjustSplitscreenScene(m_hObj,&m_OriginalPosition,m_iPad); -#endif + app.DebugPrintf("[RmlSettingsUIMenu] No RmlUi context available\n"); + return; } + + m_document = ctx->LoadDocument("SettingsAudioMenu.rml"); + if (!m_document) + { + app.DebugPrintf("[RmlSettingsUIMenu] Failed to load SettingsUIMenu.rml\n"); + return; + } + + m_document->Show(); + + for (size_t i = 0; i < sizeof(s_toggles) / sizeof(s_toggles[0]); i++) + setToggleChecked(s_toggles[i].id, app.GetGameSettings(m_iPad, s_toggles[i].setting) != 0); + + m_musicValue = app.GetGameSettings(m_iPad, eGameSetting_MusicVolume); + m_soundValue = app.GetGameSettings(m_iPad, eGameSetting_SoundFXVolume); + + setSliderValue("Music", utils.WideToUtf8(app.GetString(IDS_SLIDER_MUSIC)), m_musicValue, 1, 100); + setSliderValue("Sound", utils.WideToUtf8(app.GetString(IDS_SLIDER_SOUND)), m_soundValue, 1, 100); + + registerEvents(); + + updateComponents(); + ui.HidePressStart(); + TelemetryManager->RecordMenuShown(m_iPad, eUIScene_SettingsAudioMenu, 0); } + UIScene_SettingsAudioMenu::~UIScene_SettingsAudioMenu() { -} - -wstring UIScene_SettingsAudioMenu::getMoviePath() -{ - if(app.GetLocalPlayerCount() > 1) + if (m_document) { - return L"SettingsAudioMenuSplit"; - } - else - { - return L"SettingsAudioMenu"; + deregisterEvents(); + m_document->Close(); + m_document = nullptr; } } -void UIScene_SettingsAudioMenu::updateTooltips() +void UIScene_SettingsAudioMenu::registerEvents() { - ui.SetTooltips( m_iPad, IDS_TOOLTIPS_SELECT,IDS_TOOLTIPS_BACK); + 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)); + 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); + 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); + elThumb->AddEventListener(Rml::EventId::Mouseover, this); + } + } + + m_document->AddEventListener(Rml::EventId::Mousemove, this); + m_document->AddEventListener(Rml::EventId::Mouseup, this); +} + +void UIScene_SettingsAudioMenu::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)); + 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); + 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); + elThumb->RemoveEventListener(Rml::EventId::Mouseover, this); + } + } + + m_document->RemoveEventListener(Rml::EventId::Mousemove, this); + m_document->RemoveEventListener(Rml::EventId::Mouseup, this); +} + + +void UIScene_SettingsAudioMenu::setToggleChecked(const Rml::String& id, bool checked) +{ + Rml::Element* el = m_document->GetElementById(id); + if (!el) return; + el->SetClass("checked", checked); +} + +bool UIScene_SettingsAudioMenu::isToggleChecked(const Rml::String& id) +{ + Rml::Element* el = m_document->GetElementById(id); + return el && el->IsClassSet("checked"); +} + +void UIScene_SettingsAudioMenu::setSliderValue(const Rml::String& id, const Rml::String& labelPrefix, int value, int min, int max) +{ + Rml::Element* label = m_document->GetElementById(id + "_label"); + if (label) + { + char buf[64]; + snprintf(buf, sizeof(buf), "%s: %d%%", labelPrefix.c_str(), value); + label->SetInnerRML(Rml::String(buf)); + } + + Rml::Element* thumb = m_document->GetElementById(id + "_thumb"); + if (thumb) + { + float fraction = (max > min) ? (float)(value - min) / (float)(max - min) : 0.0f; + char buf[16]; + snprintf(buf, sizeof(buf), "%.0f%%", fraction * 100.0f); + thumb->SetProperty("left", Rml::String(buf)); + } +} + +int UIScene_SettingsAudioMenu::getSliderValue(const Rml::String& id) +{ + if (id == "Music") + return m_musicValue; + if (id == "Sound") + return m_soundValue; + return 0; +} + +void UIScene_SettingsAudioMenu::handleSliderMouseEvent(int sliderIndex, const Rml::Event& event) +{ + if (!m_document) return; + + Rml::String trackId = Rml::String(s_sliderIds[sliderIndex]) + "_track"; + Rml::Element* track = m_document->GetElementById(trackId); + if (!track) return; + + float mouseX = event.GetParameter("mouse_x", 0.0f); + Rml::Box box = track->GetBox(); + float boxLeft = track->GetAbsoluteOffset().x; + float boxWidth = box.GetSize().x; + + if (boxWidth > 0.0f) + { + float fraction = (mouseX - boxLeft) / boxWidth; + if (fraction < 0.0f) fraction = 0.0f; + if (fraction > 1.0f) fraction = 1.0f; + + int newValue = 1 + static_cast(fraction * 99.0f + 0.5f); + if (newValue < 1) newValue = 1; + if (newValue > 100) newValue = 100; + + handleSliderMove(sliderIndex, newValue); + } } void UIScene_SettingsAudioMenu::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); + 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); + if (app.GetLocalPlayerCount() == 1) m_parentLayer->showComponent(m_iPad, eUIComponent_Logo, true); + else m_parentLayer->showComponent(m_iPad, eUIComponent_Logo, false); } } +void UIScene_SettingsAudioMenu::ProcessEvent(Rml::Event& event) +{ + if (event.GetId() == Rml::EventId::Click) + { + Rml::Element* el = event.GetCurrentElement(); + const Rml::String& id = el->GetId(); + + for (size_t i = 0; i < sizeof(s_toggles) / sizeof(s_toggles[0]); i++) + { + if (id == Rml::String(s_toggles[i].id)) + { + el->SetClass("checked", !el->IsClassSet("checked")); + ui.PlayUISFX(eSFX_Press); + return; + } + } + } + else if (event.GetId() == Rml::EventId::Mousedown) + { + Rml::Element* el = event.GetCurrentElement(); + const Rml::String& id = el->GetId(); + + for (size_t i = 0; i < sizeof(s_sliderIds) / sizeof(s_sliderIds[0]); i++) + { + Rml::String trackId = Rml::String(s_sliderIds[i]) + "_track"; + Rml::String thumbId = Rml::String(s_sliderIds[i]) + "_thumb"; + if (id == trackId || id == thumbId) + { + m_dragSliderIndex = static_cast(i); + handleSliderMouseEvent(static_cast(i), event); + ui.PlayUISFX(eSFX_Scroll); + return; + } + } + } + else if (event.GetId() == Rml::EventId::Mousemove) + { + if (m_dragSliderIndex >= 0) + { + int oldValue = getSliderValue(s_sliderIds[m_dragSliderIndex]); + handleSliderMouseEvent(m_dragSliderIndex, event); + if (getSliderValue(s_sliderIds[m_dragSliderIndex]) != oldValue) + ui.PlayUISFX(eSFX_Scroll); + } + } + 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) +{ + Rml::Element* el = doc->GetElementById(t.id); + bool checked = el && el->IsClassSet("checked"); + app.SetGameSettings(iPad, t.setting, checked ? 1 : 0); +} + void UIScene_SettingsAudioMenu::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); + Rml::Context* ctx = RmlManager::Get().GetContext(); + if (!ctx) + return; - switch(key) + if (!pressed) + return; + + switch (key) { - case ACTION_MENU_CANCEL: - if(pressed) - { - // check the checkboxes - app.SetGameSettings(m_iPad,eGameSetting_CaveSounds,m_checkboxCaveSounds.IsChecked()?1:0); - - navigateBack(); - } + 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_LEFT: + ctx->ProcessKeyDown(Rml::Input::KI_LEFT, 0); + handled = true; + break; + case ACTION_MENU_RIGHT: + ctx->ProcessKeyDown(Rml::Input::KI_RIGHT, 0); + handled = true; break; case ACTION_MENU_OK: -#ifdef __ORBIS__ - case ACTION_MENU_TOUCHPAD_PRESS: -#endif - sendInputToMovie(key, repeat, pressed, released); + ctx->ProcessKeyDown(Rml::Input::KI_RETURN, 0); + handled = true; break; - case ACTION_MENU_UP: - case ACTION_MENU_DOWN: - case ACTION_MENU_LEFT: - case ACTION_MENU_RIGHT: - sendInputToMovie(key, repeat, pressed, released); + case ACTION_MENU_CANCEL: + case ACTION_MENU_PAUSEMENU: + for (size_t i = 0; i < sizeof(s_toggles) / sizeof(s_toggles[0]); i++) + saveToggle(m_document, m_iPad, s_toggles[i]); + + navigateBack(); + handled = true; + break; + default: break; } } -void UIScene_SettingsAudioMenu::handleSliderMove(F64 sliderId, F64 currentValue) + +void UIScene_SettingsAudioMenu::handleSliderMove(int sliderIndex, int value) { - WCHAR TempString[256]; - int value = static_cast(currentValue); - switch(static_cast(sliderId)) + int* member = (sliderIndex == 0) ? &m_musicValue : &m_soundValue; + const char* id = s_sliderIds[sliderIndex]; + int idsString = (sliderIndex == 0) ? IDS_SLIDER_MUSIC : IDS_SLIDER_SOUND; + eGameSetting setting = (sliderIndex == 0) ? eGameSetting_MusicVolume : eGameSetting_SoundFXVolume; + + *member = value; + Rml::String prefix = utils.WideToUtf8(app.GetString(idsString)); + setSliderValue(id, prefix, value, 1, 100); + + if (value != app.GetGameSettings(m_iPad, setting)) { - case eControl_Music: - m_sliderMusic.handleSliderMove(value); - - app.SetGameSettings(m_iPad,eGameSetting_MusicVolume,value); - swprintf( (WCHAR *)TempString, 256, L"%ls: %d%%", app.GetString( IDS_SLIDER_MUSIC ),value); - m_sliderMusic.setLabel(TempString); - - break; - case eControl_Sound: - m_sliderSound.handleSliderMove(value); - - app.SetGameSettings(m_iPad,eGameSetting_SoundFXVolume,value); - swprintf( (WCHAR *)TempString, 256, L"%ls: %d%%", app.GetString( IDS_SLIDER_SOUND ),value); - m_sliderSound.setLabel(TempString); - - break; - } -} - -void UIScene_SettingsAudioMenu::handleCheckboxToggled(F64 controlId, bool selected) -{ - switch(static_cast(controlId)) - { - case eControl_CaveSounds: - app.SetGameSettings(m_iPad, eGameSetting_CaveSounds, selected ? 1 : 0); - break; + app.SetGameSettings(m_iPad, setting, value); + ui.UpdateSelectedItemPos(m_iPad); } } \ No newline at end of file diff --git a/Minecraft.Client/Common/UI/UIScene_SettingsAudioMenu.h b/Minecraft.Client/Common/UI/UIScene_SettingsAudioMenu.h index b3e75ec1..b5d8cf91 100644 --- a/Minecraft.Client/Common/UI/UIScene_SettingsAudioMenu.h +++ b/Minecraft.Client/Common/UI/UIScene_SettingsAudioMenu.h @@ -1,42 +1,44 @@ #pragma once -#include "UIScene.h" +#pragma push_macro("byte") +#pragma push_macro("GetNextSibling") +#pragma push_macro("GetFirstChild") +#undef byte +#undef GetNextSibling +#undef GetFirstChild -class UIScene_SettingsAudioMenu : public UIScene +#include "UIScene_RmlBase.h" + +class UIScene_SettingsAudioMenu : public UIScene_RmlBase { private: - enum EControls - { - eControl_Music, - eControl_Sound, - eControl_CaveSounds - }; + int m_musicValue; + int m_soundValue; + int m_dragSliderIndex; - UIControl_Slider m_sliderMusic, m_sliderSound; // Sliders - UIControl_CheckBox m_checkboxCaveSounds; // Checkboxes - UI_BEGIN_MAP_ELEMENTS_AND_NAMES(UIScene) - UI_MAP_ELEMENT( m_sliderMusic, "Music") - UI_MAP_ELEMENT( m_sliderSound, "Sound") - UI_MAP_ELEMENT( m_checkboxCaveSounds, "CheckboxCaveSounds") - UI_END_MAP_ELEMENTS_AND_NAMES() + void setToggleChecked(const Rml::String& id, bool checked); + bool isToggleChecked(const Rml::String& id); + void setSliderValue(const Rml::String& id, const Rml::String& labelPrefix, int value, int min, int max); + int getSliderValue(const Rml::String& id); + + void registerEvents(); + void deregisterEvents(); public: UIScene_SettingsAudioMenu(int iPad, void *initData, UILayer *parentLayer); virtual ~UIScene_SettingsAudioMenu(); - virtual EUIScene getSceneType() { return eUIScene_SettingsAudioMenu;} - - virtual void updateTooltips(); + EUIScene getSceneType() override { return eUIScene_SettingsAudioMenu;} + void handleInput(int iPad, int key, bool repeat, bool pressed, bool released, bool &handled) override; virtual void updateComponents(); + void ProcessEvent(Rml::Event& event) override; + protected: - // TODO: This should be pure virtual in this class - virtual wstring getMoviePath(); + virtual void handleSliderMove(int sliderIndex, int value); + void handleSliderMouseEvent(int sliderIndex, const Rml::Event& event); +}; -public: - // INPUT - virtual void handleInput(int iPad, int key, bool repeat, bool pressed, bool released, bool &handled); - - virtual void handleSliderMove(F64 sliderId, F64 currentValue); - virtual void handleCheckboxToggled(F64 controlId, bool selected); -}; \ No newline at end of file +#pragma pop_macro("GetFirstChild") +#pragma pop_macro("GetNextSibling") +#pragma pop_macro("byte") diff --git a/Minecraft.Client/Common/UI/UIScene_SettingsControlMenu.cpp b/Minecraft.Client/Common/UI/UIScene_SettingsControlMenu.cpp index df990754..c8e09a2d 100644 --- a/Minecraft.Client/Common/UI/UIScene_SettingsControlMenu.cpp +++ b/Minecraft.Client/Common/UI/UIScene_SettingsControlMenu.cpp @@ -1,115 +1,284 @@ #include "UI.h" + +#pragma push_macro("byte") +#pragma push_macro("GetNextSibling") +#pragma push_macro("GetFirstChild") +#undef byte +#undef GetNextSibling +#undef GetFirstChild + #include "UIScene_SettingsControlMenu.h" +#include "RmlManager.h" +#include "../../Windows64/KeyboardMouseInput.h" +#include +#include +#include +#include -UIScene_SettingsControlMenu::UIScene_SettingsControlMenu(int iPad, void *initData, UILayer *parentLayer) : UIScene(iPad, parentLayer) +#pragma pop_macro("GetFirstChild") +#pragma pop_macro("GetNextSibling") +#pragma pop_macro("byte") + +struct SliderEntry { const char* id; int* value; int idsString; int setting; }; + +static const char* s_sliderIds[] = { "GameSensitivity", "InterfaceSensitivity" }; + +UIScene_SettingsControlMenu::UIScene_SettingsControlMenu(int iPad, void *initData, UILayer *parentLayer) + : UIScene_RmlBase(iPad, parentLayer) + , m_gameSensitivityValue(100) + , m_interfaceSensitivityValue(100) + , m_dragSliderIndex(-1) { - // Setup all the Iggy references we need for this scene - initialiseMovie(); - - WCHAR TempString[256]; - swprintf( (WCHAR *)TempString, 256, L"%ls: %d%%", app.GetString( IDS_SLIDER_SENSITIVITY_INGAME ),app.GetGameSettings(m_iPad,eGameSetting_Sensitivity_InGame)); - m_sliderSensitivityInGame.init(TempString,eControl_SensitivityInGame,0,200,app.GetGameSettings(m_iPad,eGameSetting_Sensitivity_InGame)); - - swprintf( (WCHAR *)TempString, 256, L"%ls: %d%%", app.GetString( IDS_SLIDER_SENSITIVITY_INMENU ),app.GetGameSettings(m_iPad,eGameSetting_Sensitivity_InMenu)); - m_sliderSensitivityInMenu.init(TempString,eControl_SensitivityInMenu,0,200,app.GetGameSettings(m_iPad,eGameSetting_Sensitivity_InMenu)); - - doHorizontalResizeCheck(); - - if(app.GetLocalPlayerCount()>1) + Rml::Context* ctx = RmlManager::Get().GetContext(); + if (!ctx) { -#if TO_BE_IMPLEMENTED - app.AdjustSplitscreenScene(m_hObj,&m_OriginalPosition,m_iPad,false); -#endif + app.DebugPrintf("[RmlSettingsMenu] No RmlUi context available\n"); + return; } + + m_document = ctx->LoadDocument("SettingsControlMenu.rml"); + if (!m_document) + { + app.DebugPrintf("[RmlSettingsMenu] Failed to load SettingsMenu.rml\n"); + return; + } + + m_document->Show(); + + m_gameSensitivityValue = app.GetGameSettings(m_iPad, eGameSetting_Sensitivity_InGame); + m_interfaceSensitivityValue = app.GetGameSettings(m_iPad, eGameSetting_Sensitivity_InMenu); + + setSliderValue("GameSensitivity", utils.WideToUtf8(app.GetString(IDS_SLIDER_SENSITIVITY_INGAME)), m_gameSensitivityValue, 1, 200); + setSliderValue("InterfaceSensitivity", utils.WideToUtf8(app.GetString(IDS_SLIDER_SENSITIVITY_INMENU)), m_interfaceSensitivityValue, 1, 200); + + registerEvents(); + + updateComponents(); + ui.HidePressStart(); + TelemetryManager->RecordMenuShown(m_iPad, eUIScene_SettingsControlMenu, 0); } UIScene_SettingsControlMenu::~UIScene_SettingsControlMenu() { -} - -wstring UIScene_SettingsControlMenu::getMoviePath() -{ - if(app.GetLocalPlayerCount() > 1) + if (m_document) { - return L"SettingsControlMenuSplit"; - } - else - { - return L"SettingsControlMenu"; + deregisterEvents(); + m_document->Close(); + m_document = nullptr; } } -void UIScene_SettingsControlMenu::updateTooltips() +void UIScene_SettingsControlMenu::registerEvents() { - ui.SetTooltips( m_iPad, IDS_TOOLTIPS_SELECT,IDS_TOOLTIPS_BACK); + 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); + 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); + elThumb->AddEventListener(Rml::EventId::Mouseover, this); + } + } + + m_document->AddEventListener(Rml::EventId::Mousemove, this); + m_document->AddEventListener(Rml::EventId::Mouseup, this); +} + +void UIScene_SettingsControlMenu::deregisterEvents() +{ + 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); + 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); + elThumb->RemoveEventListener(Rml::EventId::Mouseover, this); + } + } + + m_document->RemoveEventListener(Rml::EventId::Mousemove, this); + m_document->RemoveEventListener(Rml::EventId::Mouseup, this); +} + +void UIScene_SettingsControlMenu::setSliderValue(const Rml::String& id, const Rml::String& labelPrefix, int value, int min, int max) +{ + Rml::Element* label = m_document->GetElementById(id + "_label"); + if (label) + { + char buf[64]; + snprintf(buf, sizeof(buf), "%s: %d%%", labelPrefix.c_str(), value); + label->SetInnerRML(Rml::String(buf)); + } + + Rml::Element* thumb = m_document->GetElementById(id + "_thumb"); + if (thumb) + { + float fraction = (max > min) ? (float)(value - min) / (float)(max - min) : 0.0f; + char buf[16]; + snprintf(buf, sizeof(buf), "%.0f%%", fraction * 100.0f); + thumb->SetProperty("left", Rml::String(buf)); + } +} + +int UIScene_SettingsControlMenu::getSliderValue(const Rml::String& id) +{ + if (id == "GameSensitivity") + return m_gameSensitivityValue; + if (id == "InterfaceSensitivity") + return m_interfaceSensitivityValue; + + return 0; +} + +void UIScene_SettingsControlMenu::handleSliderMouseEvent(int sliderIndex, const Rml::Event& event) +{ + if (!m_document) return; + + Rml::String trackId = Rml::String(s_sliderIds[sliderIndex]) + "_track"; + Rml::Element* track = m_document->GetElementById(trackId); + if (!track) return; + + float mouseX = event.GetParameter("mouse_x", 0.0f); + Rml::Box box = track->GetBox(); + float boxLeft = track->GetAbsoluteOffset().x; + float boxWidth = box.GetSize().x; + + if (boxWidth > 0.0f) + { + float fraction = (mouseX - boxLeft) / boxWidth; + if (fraction < 0.0f) fraction = 0.0f; + if (fraction > 1.0f) fraction = 1.0f; + + int newValue = 1 + static_cast(fraction * 199.0f + 0.5f); + if (newValue < 1) newValue = 1; + if (newValue > 200) newValue = 200; + + handleSliderMove(sliderIndex, newValue); + } } void UIScene_SettingsControlMenu::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); + 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); + if (app.GetLocalPlayerCount() == 1) m_parentLayer->showComponent(m_iPad, eUIComponent_Logo, true); + else m_parentLayer->showComponent(m_iPad, eUIComponent_Logo, false); } } +void UIScene_SettingsControlMenu::ProcessEvent(Rml::Event& event) +{ + if (event.GetId() == Rml::EventId::Mousedown) + { + Rml::Element* el = event.GetCurrentElement(); + const Rml::String& id = el->GetId(); + + for (size_t i = 0; i < sizeof(s_sliderIds) / sizeof(s_sliderIds[0]); i++) + { + Rml::String trackId = Rml::String(s_sliderIds[i]) + "_track"; + Rml::String thumbId = Rml::String(s_sliderIds[i]) + "_thumb"; + if (id == trackId || id == thumbId) + { + m_dragSliderIndex = static_cast(i); + handleSliderMouseEvent(static_cast(i), event); + ui.PlayUISFX(eSFX_Scroll); + return; + } + } + } + else if (event.GetId() == Rml::EventId::Mousemove) + { + if (m_dragSliderIndex >= 0) + { + int oldValue = getSliderValue(s_sliderIds[m_dragSliderIndex]); + handleSliderMouseEvent(m_dragSliderIndex, event); + if (getSliderValue(s_sliderIds[m_dragSliderIndex]) != oldValue) + ui.PlayUISFX(eSFX_Scroll); + } + } + else if (event.GetId() == Rml::EventId::Mouseup) + m_dragSliderIndex = -1; + else if (event.GetId() == Rml::EventId::Mouseover) + ui.PlayUISFX(eSFX_Focus); +} + void UIScene_SettingsControlMenu::handleInput(int iPad, int key, bool repeat, bool pressed, bool released, bool &handled) { - ui.AnimateKeyPress(iPad, key, repeat, pressed, released); + Rml::Context* ctx = RmlManager::Get().GetContext(); + if (!ctx) + return; - switch(key) + if (!pressed) + return; + + switch (key) { - case ACTION_MENU_CANCEL: - if(pressed) - { - navigateBack(); - handled = true; - } + 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_LEFT: + ctx->ProcessKeyDown(Rml::Input::KI_LEFT, 0); + handled = true; + break; + case ACTION_MENU_RIGHT: + ctx->ProcessKeyDown(Rml::Input::KI_RIGHT, 0); + handled = true; break; case ACTION_MENU_OK: -#ifdef __ORBIS__ - case ACTION_MENU_TOUCHPAD_PRESS: -#endif - sendInputToMovie(key, repeat, pressed, released); + ctx->ProcessKeyDown(Rml::Input::KI_RETURN, 0); + handled = true; break; - case ACTION_MENU_UP: - case ACTION_MENU_DOWN: - case ACTION_MENU_LEFT: - case ACTION_MENU_RIGHT: - sendInputToMovie(key, repeat, pressed, released); + case ACTION_MENU_CANCEL: + case ACTION_MENU_PAUSEMENU: + navigateBack(); + handled = true; + break; + default: break; } } -void UIScene_SettingsControlMenu::handleSliderMove(F64 sliderId, F64 currentValue) +void UIScene_SettingsControlMenu::handleSliderMove(int sliderIndex, int value) { - WCHAR TempString[256]; - int value = static_cast(currentValue); - switch(static_cast(sliderId)) + int* member = (sliderIndex == 0) ? &m_gameSensitivityValue : &m_interfaceSensitivityValue; + const char* id = s_sliderIds[sliderIndex]; + int idsString = (sliderIndex == 0) ? IDS_SLIDER_SENSITIVITY_INGAME : IDS_SLIDER_SENSITIVITY_INMENU; + eGameSetting setting = (sliderIndex == 0) ? eGameSetting_Sensitivity_InGame : eGameSetting_Sensitivity_InMenu; + + *member = value; + Rml::String prefix = utils.WideToUtf8(app.GetString(idsString)); + setSliderValue(id, prefix, value, 1, 200); + + if (value != app.GetGameSettings(m_iPad, setting)) { - case eControl_SensitivityInGame: - m_sliderSensitivityInGame.handleSliderMove(value); - - app.SetGameSettings(m_iPad,eGameSetting_Sensitivity_InGame,value); - swprintf( (WCHAR *)TempString, 256, L"%ls: %d%%", app.GetString( IDS_SLIDER_SENSITIVITY_INGAME ),value); - m_sliderSensitivityInGame.setLabel(TempString); - - break; - case eControl_SensitivityInMenu: - m_sliderSensitivityInMenu.handleSliderMove(value); - - app.SetGameSettings(m_iPad,eGameSetting_Sensitivity_InMenu,value); - swprintf( (WCHAR *)TempString, 256, L"%ls: %d%%", app.GetString( IDS_SLIDER_SENSITIVITY_INMENU ),value); - m_sliderSensitivityInMenu.setLabel(TempString); - - break; + app.SetGameSettings(m_iPad, setting, value); + ui.UpdateSelectedItemPos(m_iPad); } -} +} \ No newline at end of file diff --git a/Minecraft.Client/Common/UI/UIScene_SettingsControlMenu.h b/Minecraft.Client/Common/UI/UIScene_SettingsControlMenu.h index 6d3b864c..d746a1c8 100644 --- a/Minecraft.Client/Common/UI/UIScene_SettingsControlMenu.h +++ b/Minecraft.Client/Common/UI/UIScene_SettingsControlMenu.h @@ -1,37 +1,42 @@ #pragma once -#include "UIScene.h" +#pragma push_macro("byte") +#pragma push_macro("GetNextSibling") +#pragma push_macro("GetFirstChild") +#undef byte +#undef GetNextSibling +#undef GetFirstChild -class UIScene_SettingsControlMenu : public UIScene +#include "UIScene_RmlBase.h" + +class UIScene_SettingsControlMenu : public UIScene_RmlBase { private: - enum EControls - { - eControl_SensitivityInGame, - eControl_SensitivityInMenu - }; + int m_gameSensitivityValue; + int m_interfaceSensitivityValue; + int m_dragSliderIndex; + + void setSliderValue(const Rml::String& id, const Rml::String& labelPrefix, int value, int min, int max); + int getSliderValue(const Rml::String& id); + + void registerEvents(); + void deregisterEvents(); - UIControl_Slider m_sliderSensitivityInGame, m_sliderSensitivityInMenu; // Sliders - UI_BEGIN_MAP_ELEMENTS_AND_NAMES(UIScene) - UI_MAP_ELEMENT( m_sliderSensitivityInGame, "SensitivityInGame") - UI_MAP_ELEMENT( m_sliderSensitivityInMenu, "SensitivityInMenu") - UI_END_MAP_ELEMENTS_AND_NAMES() public: UIScene_SettingsControlMenu(int iPad, void *initData, UILayer *parentLayer); virtual ~UIScene_SettingsControlMenu(); - virtual EUIScene getSceneType() { return eUIScene_SettingsControlMenu;} - - virtual void updateTooltips(); - virtual void updateComponents(); + EUIScene getSceneType() override { return eUIScene_SettingsControlMenu; } + void handleInput(int iPad, int key, bool repeat, bool pressed, bool released, bool &handled) override; + void updateComponents() override; + + void ProcessEvent(Rml::Event& event) override; protected: - // TODO: This should be pure virtual in this class - virtual wstring getMoviePath(); + virtual void handleSliderMove(int sliderIndex, int value); + void handleSliderMouseEvent(int sliderIndex, const Rml::Event& event); +}; -public: - // INPUT - virtual void handleInput(int iPad, int key, bool repeat, bool pressed, bool released, bool &handled); - - virtual void handleSliderMove(F64 sliderId, F64 currentValue); -}; \ No newline at end of file +#pragma pop_macro("GetFirstChild") +#pragma pop_macro("GetNextSibling") +#pragma pop_macro("byte") \ No newline at end of file diff --git a/Minecraft.Client/Common/UI/UIScene_SettingsMenu.cpp b/Minecraft.Client/Common/UI/UIScene_SettingsMenu.cpp index 126a8507..1b61deb8 100644 --- a/Minecraft.Client/Common/UI/UIScene_SettingsMenu.cpp +++ b/Minecraft.Client/Common/UI/UIScene_SettingsMenu.cpp @@ -112,6 +112,8 @@ void UIScene_SettingsMenu::ProcessEvent(Rml::Event& event) else if (id == "ui") OnUI(); else if (id == "reset_defaults") OnResetToDefaults(); } + else if (event == Rml::EventId::Mouseover) + ui.PlayUISFX(eSFX_Focus); } void UIScene_SettingsMenu::updateComponents() diff --git a/Minecraft.Client/Common/UI/UIScene_SettingsUIMenu.cpp b/Minecraft.Client/Common/UI/UIScene_SettingsUIMenu.cpp index 3706d01c..5d97adef 100644 --- a/Minecraft.Client/Common/UI/UIScene_SettingsUIMenu.cpp +++ b/Minecraft.Client/Common/UI/UIScene_SettingsUIMenu.cpp @@ -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 #include #include @@ -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(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) diff --git a/Minecraft.Client/Common/UI/UIScene_SettingsUIMenu.h b/Minecraft.Client/Common/UI/UIScene_SettingsUIMenu.h index 15471482..850ba1a5 100644 --- a/Minecraft.Client/Common/UI/UIScene_SettingsUIMenu.h +++ b/Minecraft.Client/Common/UI/UIScene_SettingsUIMenu.h @@ -7,15 +7,11 @@ #undef GetNextSibling #undef GetFirstChild -#include "UIScene.h" -#include -#include +#include "UIScene_RmlBase.h" -class UIScene_SettingsUIMenu : public UIScene, public Rml::EventListener +class UIScene_SettingsUIMenu : public UIScene_RmlBase { private: - Rml::ElementDocument* m_document; - int m_uiSizeValue; int m_uiSizeSplitscreenValue; int m_dragSliderIndex; @@ -32,22 +28,13 @@ public: UIScene_SettingsUIMenu(int iPad, void *initData, UILayer *parentLayer); virtual ~UIScene_SettingsUIMenu(); - virtual EUIScene getSceneType() { return eUIScene_SettingsUIMenu; } - - virtual void tick(); - virtual void updateComponents(); - - virtual void gainFocus() override; + EUIScene getSceneType() override { return eUIScene_SettingsUIMenu; } + void handleInput(int iPad, int key, bool repeat, bool pressed, bool released, bool &handled) override; + void updateComponents() override; void ProcessEvent(Rml::Event& event) override; protected: - virtual wstring getMoviePath() { return L""; } - - virtual void handleLoseFocus() override; - - virtual void handleInput(int iPad, int key, bool repeat, bool pressed, bool released, bool &handled); - virtual void handleSliderMove(int sliderIndex, int value); void handleSliderMouseEvent(int sliderIndex, const Rml::Event& event); };