10
10
*****************************************************************************/
11
11
12
12
#include " StdInc.h"
13
+ #include < algorithm>
14
+ #include < vector>
13
15
#include < core/CClientCommands.h>
14
16
#include < game/CGame.h>
15
17
#include < game/CSettings.h>
@@ -1147,7 +1149,6 @@ void CSettings::CreateGUI()
1147
1149
m_pDebugSettingCombo->AddItem (" #0000 Lua trace" )->SetData ((void *)EDiagnosticDebug::LUA_TRACE_0000);
1148
1150
m_pDebugSettingCombo->AddItem (" #0000 Resize always" )->SetData ((void *)EDiagnosticDebug::RESIZE_ALWAYS_0000);
1149
1151
m_pDebugSettingCombo->AddItem (" #0000 Resize never" )->SetData ((void *)EDiagnosticDebug::RESIZE_NEVER_0000);
1150
- m_pDebugSettingCombo->AddItem (" #0000 Memory allocation debug" )->SetData ((void *)EDiagnosticDebug::BAD_ALLOC);
1151
1152
m_pDebugSettingCombo->SetReadOnly (true );
1152
1153
vecTemp.fY += fLineHeight ;
1153
1154
@@ -1693,6 +1694,15 @@ void CSettings::UpdateVideoTab()
1693
1694
m_pPlayerMapImageCombo->SetSelectedItemByIndex (iVar);
1694
1695
}
1695
1696
1697
+ struct ResolutionData
1698
+ {
1699
+ int width;
1700
+ int height;
1701
+ int depth;
1702
+ int vidMode;
1703
+ bool isWidescreen;
1704
+ };
1705
+
1696
1706
//
1697
1707
// PopulateResolutionComboBox
1698
1708
//
@@ -1706,47 +1716,86 @@ void CSettings::PopulateResolutionComboBox()
1706
1716
bool bShowUnsafeResolutions = m_pCheckBoxShowUnsafeResolutions->GetSelected ();
1707
1717
1708
1718
CGameSettings* gameSettings = CCore::GetSingleton ().GetGame ()->GetSettings ();
1719
+ if (!gameSettings)
1720
+ return ;
1709
1721
1710
1722
VideoMode vidModemInfo;
1711
1723
int vidMode, numVidModes;
1724
+ std::vector<ResolutionData> resolutions;
1712
1725
1726
+ if (!m_pComboResolution)
1727
+ return ;
1728
+
1713
1729
m_pComboResolution->Clear ();
1714
1730
numVidModes = gameSettings->GetNumVideoModes ();
1715
1731
1716
1732
for (vidMode = 0 ; vidMode < numVidModes; vidMode++)
1717
1733
{
1718
- gameSettings->GetVideoModeInfo (&vidModemInfo, vidMode);
1734
+ if (!gameSettings->GetVideoModeInfo (&vidModemInfo, vidMode))
1735
+ continue ;
1719
1736
1720
1737
// Remove resolutions that will make the gui unusable
1721
1738
if (vidModemInfo.width < 640 || vidModemInfo.height < 480 )
1722
1739
continue ;
1723
1740
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
+
1724
1755
// Check resolution hasn't already been added
1725
1756
bool bDuplicate = false ;
1726
- for (int i = 1 ; i < vidMode; i++ )
1757
+ for (const auto & existing : resolutions )
1727
1758
{
1728
- VideoMode info;
1729
- gameSettings->GetVideoModeInfo (&info, i);
1730
- 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
+ {
1731
1761
bDuplicate = true ;
1762
+ break ;
1763
+ }
1732
1764
}
1733
- if (bDuplicate)
1734
- continue ;
1735
-
1736
- // Check resolution is below desktop res unless that is allowed
1737
- if (gameSettings->IsUnsafeResolution (vidModemInfo.width , vidModemInfo.height ) && !bShowUnsafeResolutions)
1738
- continue ;
1765
+
1766
+ if (!bDuplicate)
1767
+ resolutions.push_back (resData);
1768
+ }
1739
1769
1740
- SString strMode (" %lu x %lu x %lu" , vidModemInfo.width , vidModemInfo.height , vidModemInfo.depth );
1770
+ if (resolutions.empty ())
1771
+ return ;
1741
1772
1742
- if (vidModemInfo.flags & rwVIDEOMODEEXCLUSIVE)
1743
- 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 );
1744
1792
1745
- VideoMode currentInfo;
1746
- gameSettings->GetVideoModeInfo (¤tInfo, iNextVidMode);
1793
+ if (currentInfo.width == res.width && currentInfo.height == res.height && currentInfo.depth == res.depth )
1794
+ selectedText = strMode;
1795
+ }
1747
1796
1748
- if (currentInfo. width == vidModemInfo. width && currentInfo. height == vidModemInfo. height && currentInfo. depth == vidModemInfo. depth )
1749
- m_pComboResolution->SetText (strMode );
1797
+ if (!selectedText. empty () )
1798
+ m_pComboResolution->SetText (selectedText );
1750
1799
}
1751
1800
}
1752
1801
0 commit comments