From b7f6af4616ccf1b9e6080a0dba4c74ceee0e1d06 Mon Sep 17 00:00:00 2001 From: HARMSTONE <132402536+HARMSTONE@users.noreply.github.com> Date: Wed, 11 Mar 2026 19:43:27 +0100 Subject: [PATCH] Modernize project codebase --- .../UI/UIScene_SettingsGraphicsMenu.cpp | 171 ++++++++++-------- 1 file changed, 94 insertions(+), 77 deletions(-) diff --git a/Minecraft.Client/Common/UI/UIScene_SettingsGraphicsMenu.cpp b/Minecraft.Client/Common/UI/UIScene_SettingsGraphicsMenu.cpp index f70c7113b..31bdb7d8e 100644 --- a/Minecraft.Client/Common/UI/UIScene_SettingsGraphicsMenu.cpp +++ b/Minecraft.Client/Common/UI/UIScene_SettingsGraphicsMenu.cpp @@ -7,22 +7,30 @@ namespace { - const int FOV_MIN = 70; - const int FOV_MAX = 110; - const int FOV_SLIDER_MAX = 100; + constexpr int FOV_MIN = 70; + constexpr int FOV_MAX = 110; + constexpr int FOV_SLIDER_MAX = 100; + constexpr int fpsCaps[] = { 30, 60, 120, 0 }; - const int fpsCaps[] = {30, 60, 120, 0}; + void formatFpsCapLabel(WCHAR* buf, int idx) + { + if (fpsCaps[idx] == 0) + swprintf(buf, 256, L"Max Framerate: Unlimited"); + else + swprintf(buf, 256, L"Max Framerate: %d", fpsCaps[idx]); + } - int clampFov(int value) + int ClampFov(int value) { if (value < FOV_MIN) return FOV_MIN; if (value > FOV_MAX) return FOV_MAX; return value; } - int fovToSliderValue(float fov) + [[maybe_unused]] + int FovToSliderValue(float fov) { - int clampedFov = clampFov((int)(fov + 0.5f)); + const int clampedFov = ClampFov(static_cast(fov + 0.5f)); return ((clampedFov - FOV_MIN) * FOV_SLIDER_MAX) / (FOV_MAX - FOV_MIN); } @@ -32,14 +40,6 @@ namespace if (sliderValue > FOV_SLIDER_MAX) sliderValue = FOV_SLIDER_MAX; return FOV_MIN + ((sliderValue * (FOV_MAX - FOV_MIN)) / FOV_SLIDER_MAX); } - - void formatFpsCapLabel(WCHAR* buf, int idx) - { - if (fpsCaps[idx] == 0) - swprintf(buf, 256, L"Max Framerate: Unlimited"); - else - swprintf(buf, 256, L"Max Framerate: %d", fpsCaps[idx]); - } } int UIScene_SettingsGraphicsMenu::LevelToDistance(int level) @@ -52,40 +52,44 @@ int UIScene_SettingsGraphicsMenu::LevelToDistance(int level) int UIScene_SettingsGraphicsMenu::DistanceToLevel(int dist) { - static const int table[6] = {2,4,8,16,32,64}; - for(int i = 0; i < 6; i++){ - if(table[i] == dist) - return i; - } - return 3; + static const int table[6] = {2,4,8,16,32,64}; + for(int i = 0; i < 6; i++){ + if(table[i] == dist) + return i; + } + return 3; } UIScene_SettingsGraphicsMenu::UIScene_SettingsGraphicsMenu(int iPad, void *initData, UILayer *parentLayer) : UIScene(iPad, parentLayer) { + // Setup all the Iggy references we need for this scene initialiseMovie(); Minecraft* pMinecraft = Minecraft::GetInstance(); - m_bNotInGame = (Minecraft::GetInstance()->level == NULL); + m_bNotInGame=(Minecraft::GetInstance()->level==nullptr); - m_checkboxClouds.init(app.GetString(IDS_CHECKBOX_RENDER_CLOUDS), eControl_Clouds, (app.GetGameSettings(m_iPad, eGameSetting_Clouds) != 0)); - m_checkboxBedrockFog.init(app.GetString(IDS_CHECKBOX_RENDER_BEDROCKFOG), eControl_BedrockFog, (app.GetGameSettings(m_iPad, eGameSetting_BedrockFog) != 0)); - m_checkboxCustomSkinAnim.init(app.GetString(IDS_CHECKBOX_CUSTOM_SKIN_ANIM), eControl_CustomSkinAnim, (app.GetGameSettings(m_iPad, eGameSetting_CustomSkinAnim) != 0)); - m_checkboxVSync.init(L"VSync", eControl_VSync, (app.GetGameSettings(m_iPad, eGameSetting_VSync) != 0)); + m_checkboxClouds.init(app.GetString(IDS_CHECKBOX_RENDER_CLOUDS),eControl_Clouds,(app.GetGameSettings(m_iPad,eGameSetting_Clouds)!=0)); + m_checkboxBedrockFog.init(app.GetString(IDS_CHECKBOX_RENDER_BEDROCKFOG),eControl_BedrockFog,(app.GetGameSettings(m_iPad,eGameSetting_BedrockFog)!=0)); + m_checkboxCustomSkinAnim.init(app.GetString(IDS_CHECKBOX_CUSTOM_SKIN_ANIM),eControl_CustomSkinAnim,(app.GetGameSettings(m_iPad,eGameSetting_CustomSkinAnim)!=0)); + m_checkboxVSync.init(L"VSync",eControl_VSync,(app.GetGameSettings(m_iPad,eGameSetting_VSync)!=0)); + + WCHAR TempString[256]; - swprintf(TempString, 256, L"Render Distance: %d", (int)app.GetGameSettings(m_iPad, eGameSetting_RenderDistance)); - m_sliderRenderDistance.init(TempString, eControl_RenderDistance, 0, 5, DistanceToLevel((int)app.GetGameSettings(m_iPad, eGameSetting_RenderDistance))); + swprintf(TempString, 256, L"Render Distance: %d",app.GetGameSettings(m_iPad,eGameSetting_RenderDistance)); + m_sliderRenderDistance.init(TempString,eControl_RenderDistance,0,5,DistanceToLevel(app.GetGameSettings(m_iPad,eGameSetting_RenderDistance))); + + swprintf( TempString, 256, L"%ls: %d%%", app.GetString( IDS_SLIDER_GAMMA ),app.GetGameSettings(m_iPad,eGameSetting_Gamma)); + m_sliderGamma.init(TempString,eControl_Gamma,0,100,app.GetGameSettings(m_iPad,eGameSetting_Gamma)); - swprintf(TempString, 256, L"%ls: %d%%", app.GetString(IDS_SLIDER_GAMMA), (int)app.GetGameSettings(m_iPad, eGameSetting_Gamma)); - m_sliderGamma.init(TempString, eControl_Gamma, 0, 100, (int)app.GetGameSettings(m_iPad, eGameSetting_Gamma)); - - int initialFovSlider = (int)app.GetGameSettings(m_iPad, eGameSetting_FOV); - swprintf(TempString, 256, L"FOV: %d", sliderValueToFov(initialFovSlider)); + const int initialFovSlider = app.GetGameSettings(m_iPad, eGameSetting_FOV); + const int initialFovDeg = sliderValueToFov(initialFovSlider); + swprintf(TempString, 256, L"FOV: %d", initialFovDeg); m_sliderFOV.init(TempString, eControl_FOV, 0, FOV_SLIDER_MAX, initialFovSlider); - - swprintf(TempString, 256, L"%ls: %d%%", app.GetString(IDS_SLIDER_INTERFACEOPACITY), (int)app.GetGameSettings(m_iPad, eGameSetting_InterfaceOpacity)); - m_sliderInterfaceOpacity.init(TempString, eControl_InterfaceOpacity, 0, 100, (int)app.GetGameSettings(m_iPad, eGameSetting_InterfaceOpacity)); + + swprintf( TempString, 256, L"%ls: %d%%", app.GetString( IDS_SLIDER_INTERFACEOPACITY ),app.GetGameSettings(m_iPad,eGameSetting_InterfaceOpacity)); + m_sliderInterfaceOpacity.init(TempString,eControl_InterfaceOpacity,0,100,app.GetGameSettings(m_iPad,eGameSetting_InterfaceOpacity)); int fpsCapIndex = (int)app.GetGameSettings(m_iPad, eGameSetting_FpsCap); if (fpsCapIndex < 0 || fpsCapIndex > 3) fpsCapIndex = 1; @@ -93,30 +97,35 @@ UIScene_SettingsGraphicsMenu::UIScene_SettingsGraphicsMenu(int iPad, void *initD m_sliderFpsCap.init(TempString, eControl_FpsCap, 0, 3, fpsCapIndex); doHorizontalResizeCheck(); - - bool bInGame = (Minecraft::GetInstance()->level != NULL); - bool bIsPrimaryPad = (ProfileManager.GetPrimaryPad() == m_iPad); + const bool bInGame=(Minecraft::GetInstance()->level!=nullptr); + const bool bIsPrimaryPad=(ProfileManager.GetPrimaryPad()==m_iPad); + // if we're not in the game, we need to use basescene 0 if(bInGame) { + // If the game has started, then you need to be the host to change the in-game gamertags if(bIsPrimaryPad) { + // we are the primary player on this machine, but not the game host + // are we the game host? If not, we need to remove the bedrockfog setting if(!g_NetworkManager.IsHost()) { + // hide the in-game bedrock fog setting removeControl(&m_checkboxBedrockFog, true); } } else { + // We shouldn't have the bedrock fog option, or the m_CustomSkinAnim option removeControl(&m_checkboxBedrockFog, true); removeControl(&m_checkboxCustomSkinAnim, true); } } - if(app.GetLocalPlayerCount() > 1) + if(app.GetLocalPlayerCount()>1) { #if TO_BE_IMPLEMENTED - app.AdjustSplitscreenScene(m_hObj, &m_OriginalPosition, m_iPad); + app.AdjustSplitscreenScene(m_hObj,&m_OriginalPosition,m_iPad); #endif } } @@ -139,23 +148,24 @@ wstring UIScene_SettingsGraphicsMenu::getMoviePath() void UIScene_SettingsGraphicsMenu::updateTooltips() { - ui.SetTooltips(m_iPad, IDS_TOOLTIPS_SELECT, IDS_TOOLTIPS_BACK); + ui.SetTooltips( m_iPad, IDS_TOOLTIPS_SELECT,IDS_TOOLTIPS_BACK); } void UIScene_SettingsGraphicsMenu::updateComponents() { - bool bNotInGame = (Minecraft::GetInstance()->level == NULL); + const 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); + } } @@ -167,10 +177,11 @@ void UIScene_SettingsGraphicsMenu::handleInput(int iPad, int key, bool repeat, b case ACTION_MENU_CANCEL: if(pressed) { - app.SetGameSettings(m_iPad, eGameSetting_Clouds, m_checkboxClouds.IsChecked() ? 1 : 0); - app.SetGameSettings(m_iPad, eGameSetting_BedrockFog, m_checkboxBedrockFog.IsChecked() ? 1 : 0); - app.SetGameSettings(m_iPad, eGameSetting_CustomSkinAnim, m_checkboxCustomSkinAnim.IsChecked() ? 1 : 0); - app.SetGameSettings(m_iPad, eGameSetting_VSync, m_checkboxVSync.IsChecked() ? 1 : 0); + // check the checkboxes + app.SetGameSettings(m_iPad,eGameSetting_Clouds,m_checkboxClouds.IsChecked()?1:0); + app.SetGameSettings(m_iPad,eGameSetting_BedrockFog,m_checkboxBedrockFog.IsChecked()?1:0); + app.SetGameSettings(m_iPad,eGameSetting_CustomSkinAnim,m_checkboxCustomSkinAnim.IsChecked()?1:0); + app.SetGameSettings(m_iPad,eGameSetting_VSync,m_checkboxVSync.IsChecked()?1:0); navigateBack(); handled = true; @@ -194,59 +205,65 @@ void UIScene_SettingsGraphicsMenu::handleInput(int iPad, int key, bool repeat, b void UIScene_SettingsGraphicsMenu::handleSliderMove(F64 sliderId, F64 currentValue) { WCHAR TempString[256]; - int value = (int)currentValue; - switch((int)sliderId) + const int value = static_cast(currentValue); + switch(static_cast(sliderId)) { case eControl_RenderDistance: { m_sliderRenderDistance.handleSliderMove(value); - int dist = LevelToDistance(value); - app.SetGameSettings(m_iPad, eGameSetting_RenderDistance, dist); + const int dist = LevelToDistance(value); - Minecraft* mc = Minecraft::GetInstance(); + app.SetGameSettings(m_iPad,eGameSetting_RenderDistance,dist); + + const Minecraft* mc = Minecraft::GetInstance(); mc->options->viewDistance = 3 - value; - swprintf(TempString, 256, L"Render Distance: %d", dist); + swprintf(TempString,256,L"Render Distance: %d",dist); m_sliderRenderDistance.setLabel(TempString); } break; case eControl_Gamma: m_sliderGamma.handleSliderMove(value); - app.SetGameSettings(m_iPad, eGameSetting_Gamma, value); - swprintf(TempString, 256, L"%ls: %d%%", app.GetString(IDS_SLIDER_GAMMA), value); + + app.SetGameSettings(m_iPad,eGameSetting_Gamma,value); + swprintf( TempString, 256, L"%ls: %d%%", app.GetString( IDS_SLIDER_GAMMA ),value); m_sliderGamma.setLabel(TempString); + break; case eControl_FOV: { m_sliderFOV.handleSliderMove(value); - Minecraft* pMinecraft = Minecraft::GetInstance(); - int fovValue = sliderValueToFov(value); - pMinecraft->gameRenderer->SetFovVal((float)fovValue); + const Minecraft* pMinecraft = Minecraft::GetInstance(); + const int fovValue = sliderValueToFov(value); + pMinecraft->gameRenderer->SetFovVal(static_cast(fovValue)); app.SetGameSettings(m_iPad, eGameSetting_FOV, value); - swprintf(TempString, 256, L"FOV: %d", fovValue); - m_sliderFOV.setLabel(TempString); + WCHAR tempString[256]; + swprintf(tempString, 256, L"FOV: %d", fovValue); + m_sliderFOV.setLabel(tempString); } break; case eControl_InterfaceOpacity: m_sliderInterfaceOpacity.handleSliderMove(value); - app.SetGameSettings(m_iPad, eGameSetting_InterfaceOpacity, value); - swprintf(TempString, 256, L"%ls: %d%%", app.GetString(IDS_SLIDER_INTERFACEOPACITY), value); + + app.SetGameSettings(m_iPad,eGameSetting_InterfaceOpacity,value); + swprintf( TempString, 256, L"%ls: %d%%", app.GetString( IDS_SLIDER_INTERFACEOPACITY ),value); m_sliderInterfaceOpacity.setLabel(TempString); + break; case eControl_FpsCap: - { - int idx = value; - if (idx < 0) idx = 0; - if (idx > 3) idx = 3; - m_sliderFpsCap.handleSliderMove(idx); - app.SetGameSettings(m_iPad, eGameSetting_FpsCap, idx); - formatFpsCapLabel(TempString, idx); - m_sliderFpsCap.setLabel(TempString); - } - break; + { + int idx = value; + if (idx < 0) idx = 0; + if (idx > 3) idx = 3; + m_sliderFpsCap.handleSliderMove(idx); + app.SetGameSettings(m_iPad, eGameSetting_FpsCap, idx); + formatFpsCapLabel(TempString, idx); + m_sliderFpsCap.setLabel(TempString); + } + break; } }