From 3ed739ef561508f21ab632c7c902b37ec50ecbb4 Mon Sep 17 00:00:00 2001 From: Mohab <133429578+MohabCodeX@users.noreply.github.com> Date: Fri, 12 Sep 2025 01:11:42 +0300 Subject: [PATCH 1/3] Add resolution sorting functionality to device selection dialog --- Client/core/CSettings.cpp | 98 ++++++++++++++++++++++++++++++++------- 1 file changed, 80 insertions(+), 18 deletions(-) diff --git a/Client/core/CSettings.cpp b/Client/core/CSettings.cpp index 81a2c159891..05e0ba904c0 100644 --- a/Client/core/CSettings.cpp +++ b/Client/core/CSettings.cpp @@ -10,6 +10,8 @@ *****************************************************************************/ #include "StdInc.h" +#include +#include #include #include #include @@ -1683,6 +1685,25 @@ void CSettings::UpdateVideoTab() m_pPlayerMapImageCombo->SetSelectedItemByIndex(iVar); } +struct ResolutionData +{ + int width; + int height; + int depth; + int vidMode; + bool isWidescreen; + + bool operator==(const ResolutionData& other) const + { + return width == other.width && height == other.height && depth == other.depth; + } + + int getPixelCount() const + { + return width * height; + } +}; + // // PopulateResolutionComboBox // @@ -1696,47 +1717,88 @@ void CSettings::PopulateResolutionComboBox() bool bShowUnsafeResolutions = m_pCheckBoxShowUnsafeResolutions->GetSelected(); CGameSettings* gameSettings = CCore::GetSingleton().GetGame()->GetSettings(); + if (!gameSettings) + return; VideoMode vidModemInfo; int vidMode, numVidModes; + std::vector resolutions; + if (!m_pComboResolution) + return; + m_pComboResolution->Clear(); numVidModes = gameSettings->GetNumVideoModes(); for (vidMode = 0; vidMode < numVidModes; vidMode++) { - gameSettings->GetVideoModeInfo(&vidModemInfo, vidMode); + if (!gameSettings->GetVideoModeInfo(&vidModemInfo, vidMode)) + continue; // Remove resolutions that will make the gui unusable if (vidModemInfo.width < 640 || vidModemInfo.height < 480) continue; + // Check resolution is below desktop res unless that is allowed + if (gameSettings->IsUnsafeResolution(vidModemInfo.width, vidModemInfo.height) && !bShowUnsafeResolutions) + continue; + + if (!(vidModemInfo.flags & rwVIDEOMODEEXCLUSIVE)) + continue; + + ResolutionData resData; + resData.width = vidModemInfo.width; + resData.height = vidModemInfo.height; + resData.depth = vidModemInfo.depth; + resData.vidMode = vidMode; + resData.isWidescreen = (vidModemInfo.flags & rwVIDEOMODE_XBOX_WIDESCREEN) != 0; + // Check resolution hasn't already been added bool bDuplicate = false; - for (int i = 1; i < vidMode; i++) + for (const auto& existing : resolutions) { - VideoMode info; - gameSettings->GetVideoModeInfo(&info, i); - if (info.width == vidModemInfo.width && info.height == vidModemInfo.height && info.depth == vidModemInfo.depth) + if (existing == resData) + { bDuplicate = true; + break; + } } - if (bDuplicate) - continue; - - // Check resolution is below desktop res unless that is allowed - if (gameSettings->IsUnsafeResolution(vidModemInfo.width, vidModemInfo.height) && !bShowUnsafeResolutions) - continue; + + if (!bDuplicate) + resolutions.push_back(resData); + } - SString strMode("%lu x %lu x %lu", vidModemInfo.width, vidModemInfo.height, vidModemInfo.depth); + if (resolutions.empty()) + return; - if (vidModemInfo.flags & rwVIDEOMODEEXCLUSIVE) - m_pComboResolution->AddItem(strMode)->SetData((void*)vidMode); + // Sort resolutions by total pixels (descending), then by width, then by depth + std::sort(resolutions.begin(), resolutions.end(), [](const ResolutionData& a, const ResolutionData& b) { + int pixelCountA = a.getPixelCount(); + int pixelCountB = b.getPixelCount(); + if (pixelCountA != pixelCountB) + return pixelCountA > pixelCountB; + if (a.width != b.width) + return a.width > b.width; + return a.depth > b.depth; + }); + + SString selectedText; + VideoMode currentInfo; + if (gameSettings->GetVideoModeInfo(¤tInfo, iNextVidMode)) + { + for (const auto& res : resolutions) + { + SString strMode("%d x %d x %d", res.width, res.height, res.depth); + CGUIListItem* pItem = m_pComboResolution->AddItem(strMode); + if (pItem) + pItem->SetData((void*)res.vidMode); - VideoMode currentInfo; - gameSettings->GetVideoModeInfo(¤tInfo, iNextVidMode); + if (currentInfo.width == res.width && currentInfo.height == res.height && currentInfo.depth == res.depth) + selectedText = strMode; + } - if (currentInfo.width == vidModemInfo.width && currentInfo.height == vidModemInfo.height && currentInfo.depth == vidModemInfo.depth) - m_pComboResolution->SetText(strMode); + if (!selectedText.empty()) + m_pComboResolution->SetText(selectedText); } } From e0c44ef9f6e81ccf3a1f838381fce09060932203 Mon Sep 17 00:00:00 2001 From: Mohab <133429578+MohabCodeX@users.noreply.github.com> Date: Fri, 12 Sep 2025 01:23:23 +0300 Subject: [PATCH 2/3] Refactor resolution sorting --- Client/core/CSettings.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/Client/core/CSettings.cpp b/Client/core/CSettings.cpp index 05e0ba904c0..3742d6fcef4 100644 --- a/Client/core/CSettings.cpp +++ b/Client/core/CSettings.cpp @@ -1771,14 +1771,12 @@ void CSettings::PopulateResolutionComboBox() if (resolutions.empty()) return; - // Sort resolutions by total pixels (descending), then by width, then by depth + // Sort resolutions by width (descending), then by height, then by depth std::sort(resolutions.begin(), resolutions.end(), [](const ResolutionData& a, const ResolutionData& b) { - int pixelCountA = a.getPixelCount(); - int pixelCountB = b.getPixelCount(); - if (pixelCountA != pixelCountB) - return pixelCountA > pixelCountB; if (a.width != b.width) return a.width > b.width; + if (a.height != b.height) + return a.height > b.height; return a.depth > b.depth; }); From 0e34454a32cd0f4429d95bf4af76b6d4ae7ef19c Mon Sep 17 00:00:00 2001 From: Mohab <133429578+MohabCodeX@users.noreply.github.com> Date: Sat, 13 Sep 2025 13:49:09 +0300 Subject: [PATCH 3/3] Refactor CSettings class --- Client/core/CSettings.cpp | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/Client/core/CSettings.cpp b/Client/core/CSettings.cpp index 3742d6fcef4..df13df0ff5b 100644 --- a/Client/core/CSettings.cpp +++ b/Client/core/CSettings.cpp @@ -1692,16 +1692,6 @@ struct ResolutionData int depth; int vidMode; bool isWidescreen; - - bool operator==(const ResolutionData& other) const - { - return width == other.width && height == other.height && depth == other.depth; - } - - int getPixelCount() const - { - return width * height; - } }; // @@ -1757,7 +1747,7 @@ void CSettings::PopulateResolutionComboBox() bool bDuplicate = false; for (const auto& existing : resolutions) { - if (existing == resData) + if (existing.width == resData.width && existing.height == resData.height && existing.depth == resData.depth) { bDuplicate = true; break;