1010 *****************************************************************************/
1111
1212#include " StdInc.h"
13+ #include < algorithm>
14+ #include < vector>
1315#include < core/CClientCommands.h>
1416#include < game/CGame.h>
1517#include < game/CSettings.h>
@@ -1692,6 +1694,15 @@ void CSettings::UpdateVideoTab()
16921694 m_pPlayerMapImageCombo->SetSelectedItemByIndex (iVar);
16931695}
16941696
1697+ struct ResolutionData
1698+ {
1699+ int width;
1700+ int height;
1701+ int depth;
1702+ int vidMode;
1703+ bool isWidescreen;
1704+ };
1705+
16951706//
16961707// PopulateResolutionComboBox
16971708//
@@ -1705,47 +1716,86 @@ void CSettings::PopulateResolutionComboBox()
17051716 bool bShowUnsafeResolutions = m_pCheckBoxShowUnsafeResolutions->GetSelected ();
17061717
17071718 CGameSettings* gameSettings = CCore::GetSingleton ().GetGame ()->GetSettings ();
1719+ if (!gameSettings)
1720+ return ;
17081721
17091722 VideoMode vidModemInfo;
17101723 int vidMode, numVidModes;
1724+ std::vector<ResolutionData> resolutions;
17111725
1726+ if (!m_pComboResolution)
1727+ return ;
1728+
17121729 m_pComboResolution->Clear ();
17131730 numVidModes = gameSettings->GetNumVideoModes ();
17141731
17151732 for (vidMode = 0 ; vidMode < numVidModes; vidMode++)
17161733 {
1717- gameSettings->GetVideoModeInfo (&vidModemInfo, vidMode);
1734+ if (!gameSettings->GetVideoModeInfo (&vidModemInfo, vidMode))
1735+ continue ;
17181736
17191737 // Remove resolutions that will make the gui unusable
17201738 if (vidModemInfo.width < 640 || vidModemInfo.height < 480 )
17211739 continue ;
17221740
1741+ // Check resolution is below desktop res unless that is allowed
1742+ if (gameSettings->IsUnsafeResolution (vidModemInfo.width , vidModemInfo.height ) && !bShowUnsafeResolutions)
1743+ continue ;
1744+
1745+ if (!(vidModemInfo.flags & rwVIDEOMODEEXCLUSIVE))
1746+ continue ;
1747+
1748+ ResolutionData resData;
1749+ resData.width = vidModemInfo.width ;
1750+ resData.height = vidModemInfo.height ;
1751+ resData.depth = vidModemInfo.depth ;
1752+ resData.vidMode = vidMode;
1753+ resData.isWidescreen = (vidModemInfo.flags & rwVIDEOMODE_XBOX_WIDESCREEN) != 0 ;
1754+
17231755 // Check resolution hasn't already been added
17241756 bool bDuplicate = false ;
1725- for (int i = 1 ; i < vidMode; i++ )
1757+ for (const auto & existing : resolutions )
17261758 {
1727- VideoMode info;
1728- gameSettings->GetVideoModeInfo (&info, i);
1729- if (info.width == vidModemInfo.width && info.height == vidModemInfo.height && info.depth == vidModemInfo.depth )
1759+ if (existing.width == resData.width && existing.height == resData.height && existing.depth == resData.depth )
1760+ {
17301761 bDuplicate = true ;
1762+ break ;
1763+ }
17311764 }
1732- if (bDuplicate)
1733- continue ;
1734-
1735- // Check resolution is below desktop res unless that is allowed
1736- if (gameSettings->IsUnsafeResolution (vidModemInfo.width , vidModemInfo.height ) && !bShowUnsafeResolutions)
1737- continue ;
1765+
1766+ if (!bDuplicate)
1767+ resolutions.push_back (resData);
1768+ }
17381769
1739- SString strMode (" %lu x %lu x %lu" , vidModemInfo.width , vidModemInfo.height , vidModemInfo.depth );
1770+ if (resolutions.empty ())
1771+ return ;
17401772
1741- if (vidModemInfo.flags & rwVIDEOMODEEXCLUSIVE)
1742- m_pComboResolution->AddItem (strMode)->SetData ((void *)vidMode);
1773+ // Sort resolutions by width (descending), then by height, then by depth
1774+ std::sort (resolutions.begin (), resolutions.end (), [](const ResolutionData& a, const ResolutionData& b) {
1775+ if (a.width != b.width )
1776+ return a.width > b.width ;
1777+ if (a.height != b.height )
1778+ return a.height > b.height ;
1779+ return a.depth > b.depth ;
1780+ });
1781+
1782+ SString selectedText;
1783+ VideoMode currentInfo;
1784+ if (gameSettings->GetVideoModeInfo (¤tInfo, iNextVidMode))
1785+ {
1786+ for (const auto & res : resolutions)
1787+ {
1788+ SString strMode (" %d x %d x %d" , res.width , res.height , res.depth );
1789+ CGUIListItem* pItem = m_pComboResolution->AddItem (strMode);
1790+ if (pItem)
1791+ pItem->SetData ((void *)res.vidMode );
17431792
1744- VideoMode currentInfo;
1745- gameSettings->GetVideoModeInfo (¤tInfo, iNextVidMode);
1793+ if (currentInfo.width == res.width && currentInfo.height == res.height && currentInfo.depth == res.depth )
1794+ selectedText = strMode;
1795+ }
17461796
1747- if (currentInfo. width == vidModemInfo. width && currentInfo. height == vidModemInfo. height && currentInfo. depth == vidModemInfo. depth )
1748- m_pComboResolution->SetText (strMode );
1797+ if (!selectedText. empty () )
1798+ m_pComboResolution->SetText (selectedText );
17491799 }
17501800}
17511801
0 commit comments