1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-24 08:32:34 +02:00

highlight current resolution in the resolution selector in game options

This commit is contained in:
Andrey Filipenkov 2022-10-01 10:33:48 +03:00
parent 99502c97d0
commit c9ae43abe8
2 changed files with 21 additions and 15 deletions

View File

@ -438,6 +438,11 @@ static void setBoolSetting(std::string group, std::string field, bool value)
fullscreen->Bool() = value;
}
static std::string resolutionToString(int w, int h)
{
return std::to_string(w) + 'x' + std::to_string(h);
}
CSystemOptionsWindow::CSystemOptionsWindow()
: CWindowObject(PLAYER_COLORED, "SysOpBck"),
onFullscreenChanged(settings.listen["video"]["fullscreen"])
@ -550,11 +555,8 @@ CSystemOptionsWindow::CSystemOptionsWindow()
gameResButton = std::make_shared<CButton>(Point(28, 275),"buttons/resolution", CButton::tooltip(texts["resolutionButton"]), std::bind(&CSystemOptionsWindow::selectGameRes, this), SDLK_g);
std::string resText;
resText += boost::lexical_cast<std::string>(settings["video"]["screenRes"]["width"].Float());
resText += "x";
resText += boost::lexical_cast<std::string>(settings["video"]["screenRes"]["height"].Float());
gameResLabel = std::make_shared<CLabel>(170, 292, FONT_MEDIUM, CENTER, Colors::YELLOW, resText);
const auto & screenRes = settings["video"]["screenRes"];
gameResLabel = std::make_shared<CLabel>(170, 292, FONT_MEDIUM, CENTER, Colors::YELLOW, resolutionToString(screenRes["width"].Integer(), screenRes["height"].Integer()));
}
void CSystemOptionsWindow::selectGameRes()
@ -567,6 +569,8 @@ void CSystemOptionsWindow::selectGameRes()
SDL_GetDisplayBounds(std::max(0, SDL_GetWindowDisplayIndex(mainWindow)), &displayBounds);
#endif
size_t currentResolutionIndex = 0;
size_t i = 0;
for(const auto & it : conf.guiOptions)
{
const auto & resolution = it.first;
@ -575,12 +579,14 @@ void CSystemOptionsWindow::selectGameRes()
continue;
#endif
std::string resX = boost::lexical_cast<std::string>(resolution.first);
std::string resY = boost::lexical_cast<std::string>(resolution.second);
items.push_back(resX + 'x' + resY);
auto resolutionStr = resolutionToString(resolution.first, resolution.second);
if(gameResLabel->text == resolutionStr)
currentResolutionIndex = i;
items.push_back(std::move(resolutionStr));
++i;
}
GH.pushIntT<CObjectListWindow>(items, nullptr, texts["label"].String(), texts["help"].String(), std::bind(&CSystemOptionsWindow::setGameRes, this, _1));
GH.pushIntT<CObjectListWindow>(items, nullptr, texts["label"].String(), texts["help"].String(), std::bind(&CSystemOptionsWindow::setGameRes, this, _1), currentResolutionIndex);
}
void CSystemOptionsWindow::setGameRes(int index)
@ -2213,10 +2219,10 @@ void CObjectListWindow::CItem::clickLeft(tribool down, bool previousState)
parent->changeSelection(index);
}
CObjectListWindow::CObjectListWindow(const std::vector<int> & _items, std::shared_ptr<CIntObject> titleWidget_, std::string _title, std::string _descr, std::function<void(int)> Callback)
CObjectListWindow::CObjectListWindow(const std::vector<int> & _items, std::shared_ptr<CIntObject> titleWidget_, std::string _title, std::string _descr, std::function<void(int)> Callback, size_t initialSelection)
: CWindowObject(PLAYER_COLORED, "TPGATE"),
onSelect(Callback),
selected(0)
selected(initialSelection)
{
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
items.reserve(_items.size());
@ -2228,10 +2234,10 @@ CObjectListWindow::CObjectListWindow(const std::vector<int> & _items, std::share
init(titleWidget_, _title, _descr);
}
CObjectListWindow::CObjectListWindow(const std::vector<std::string> & _items, std::shared_ptr<CIntObject> titleWidget_, std::string _title, std::string _descr, std::function<void(int)> Callback)
CObjectListWindow::CObjectListWindow(const std::vector<std::string> & _items, std::shared_ptr<CIntObject> titleWidget_, std::string _title, std::string _descr, std::function<void(int)> Callback, size_t initialSelection)
: CWindowObject(PLAYER_COLORED, "TPGATE"),
onSelect(Callback),
selected(0)
selected(initialSelection)
{
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
items.reserve(_items.size());

View File

@ -185,8 +185,8 @@ public:
/// Callback will be called when OK button is pressed, returns id of selected item. initState = initially selected item
/// Image can be nullptr
///item names will be taken from map objects
CObjectListWindow(const std::vector<int> &_items, std::shared_ptr<CIntObject> titleWidget_, std::string _title, std::string _descr, std::function<void(int)> Callback);
CObjectListWindow(const std::vector<std::string> &_items, std::shared_ptr<CIntObject> titleWidget_, std::string _title, std::string _descr, std::function<void(int)> Callback);
CObjectListWindow(const std::vector<int> &_items, std::shared_ptr<CIntObject> titleWidget_, std::string _title, std::string _descr, std::function<void(int)> Callback, size_t initialSelection = 0);
CObjectListWindow(const std::vector<std::string> &_items, std::shared_ptr<CIntObject> titleWidget_, std::string _title, std::string _descr, std::function<void(int)> Callback, size_t initialSelection = 0);
std::shared_ptr<CIntObject> genItem(size_t index);
void elementSelected();//call callback and close this window