1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-08-13 19:54:17 +02:00

Resolutions selector now shows all available resolutions

This commit is contained in:
Ivan Savenko
2023-04-30 18:48:15 +03:00
parent b4e7093c01
commit 8d28f96619
2 changed files with 8 additions and 64 deletions

View File

@@ -22,7 +22,7 @@
#include "CPlayerInterface.h" #include "CPlayerInterface.h"
#include "windows/GUIClasses.h" #include "windows/GUIClasses.h"
#include "CServerHandler.h" #include "CServerHandler.h"
#include "renderSDL/SDL_Extensions.h" #include "render/IWindowHandler.h"
static void setIntSetting(std::string group, std::string field, int value) static void setIntSetting(std::string group, std::string field, int value)
@@ -148,23 +148,6 @@ GeneralOptionsTab::GeneralOptionsTab()
std::shared_ptr<CLabel> soundVolumeLabel = widget<CLabel>("soundValueLabel"); std::shared_ptr<CLabel> soundVolumeLabel = widget<CLabel>("soundValueLabel");
soundVolumeLabel->setText(std::to_string(CCS->soundh->getVolume()) + "%"); soundVolumeLabel->setText(std::to_string(CCS->soundh->getVolume()) + "%");
}
bool GeneralOptionsTab::isResolutionSupported(const Point & resolution)
{
return isResolutionSupported( resolution, settings["video"]["fullscreen"].Bool());
}
bool GeneralOptionsTab::isResolutionSupported(const Point & resolution, bool fullscreen)
{
if (!fullscreen)
return true;
auto supportedList = CSDL_Ext::getSupportedResolutions();
return CSDL_Ext::isResolutionSupported(supportedList, resolution);
} }
void GeneralOptionsTab::selectGameResolution() void GeneralOptionsTab::selectGameResolution()
@@ -174,7 +157,7 @@ void GeneralOptionsTab::selectGameResolution()
std::vector<std::string> items; std::vector<std::string> items;
size_t currentResolutionIndex = 0; size_t currentResolutionIndex = 0;
size_t i = 0; size_t i = 0;
for(const auto & it : selectableResolutions) for(const auto & it : supportedResolutions)
{ {
auto resolutionStr = resolutionToEntryString(it.x, it.y); auto resolutionStr = resolutionToEntryString(it.x, it.y);
if(widget<CLabel>("resolutionLabel")->getText() == resolutionToLabelString(it.x, it.y)) if(widget<CLabel>("resolutionLabel")->getText() == resolutionToLabelString(it.x, it.y))
@@ -195,12 +178,12 @@ void GeneralOptionsTab::selectGameResolution()
void GeneralOptionsTab::setGameResolution(int index) void GeneralOptionsTab::setGameResolution(int index)
{ {
assert(index >= 0 && index < selectableResolutions.size()); assert(index >= 0 && index < supportedResolutions.size());
if ( index < 0 || index >= selectableResolutions.size() ) if ( index < 0 || index >= supportedResolutions.size() )
return; return;
Point resolution = selectableResolutions[index]; Point resolution = supportedResolutions[index];
Settings gameRes = settings.write["video"]["screenRes"]; Settings gameRes = settings.write["video"]["screenRes"];
gameRes["width"].Float() = resolution.x; gameRes["width"].Float() = resolution.x;
@@ -211,50 +194,14 @@ void GeneralOptionsTab::setGameResolution(int index)
void GeneralOptionsTab::setFullscreenMode(bool on) void GeneralOptionsTab::setFullscreenMode(bool on)
{ {
fillSelectableResolutions();
const auto & screenRes = settings["video"]["screenRes"];
const Point desiredResolution(screenRes["width"].Integer(), screenRes["height"].Integer());
const Point currentResolution = GH.screenDimensions();
if (!isResolutionSupported(currentResolution, on))
{
widget<CToggleButton>("fullscreenCheckbox")->setSelected(!on);
LOCPLINT->showInfoDialog(CGI->generaltexth->translate("vcmi.systemOptions.fullscreenFailed"));
return;
}
setBoolSetting("video", "fullscreen", on); setBoolSetting("video", "fullscreen", on);
if (!isResolutionSupported(desiredResolution, on))
{
// user changed his desired resolution and switched to fullscreen
// however resolution he selected before is not available in fullscreen
// so reset it back to currect resolution which is confirmed to be supported earlier
Settings gameRes = settings.write["video"]["screenRes"];
gameRes["width"].Float() = currentResolution.x;
gameRes["height"].Float() = currentResolution.y;
widget<CLabel>("resolutionLabel")->setText(resolutionToLabelString(currentResolution.x, currentResolution.y));
}
} }
void GeneralOptionsTab::fillSelectableResolutions() void GeneralOptionsTab::fillSelectableResolutions()
{ {
selectableResolutions.clear(); supportedResolutions = GH.windowHandler().getSupportedResolutions();
// TODO: CONFIGURABLE ADVMAP boost::range::sort(supportedResolutions, [](const auto & left, const auto & right)
static const std::vector<Point> supportedResolutions = {
{ 800, 600 }
};
for(const auto & dimensions : supportedResolutions)
{
if(isResolutionSupported(dimensions))
selectableResolutions.push_back(dimensions);
}
boost::range::sort(selectableResolutions, [](const auto & left, const auto & right)
{ {
return left.x * left.y < right.x * right.y; return left.x * left.y < right.x * right.y;
}); });

View File

@@ -19,16 +19,13 @@ private:
SettingsListener onFullscreenChanged; SettingsListener onFullscreenChanged;
std::vector<Point> supportedResolutions; std::vector<Point> supportedResolutions;
std::vector<Point> selectableResolutions;
void setFullscreenMode( bool on); void setFullscreenMode( bool on);
void fillSelectableResolutions(); void fillSelectableResolutions();
bool isResolutionSupported(const Point & resolution);
bool isResolutionSupported(const Point & resolution, bool fullscreen);
void selectGameResolution(); void selectGameResolution();
void setGameResolution(int index); void setGameResolution(int index);
public: public:
GeneralOptionsTab(); GeneralOptionsTab();
}; };