|
|
@@ -425,280 +425,6 @@ CLevelWindow::~CLevelWindow()
|
|
|
LOCPLINT->showingDialog->setn(false);
|
|
|
}
|
|
|
|
|
|
-static void setIntSetting(std::string group, std::string field, int value)
|
|
|
-{
|
|
|
- Settings entry = settings.write[group][field];
|
|
|
- entry->Float() = value;
|
|
|
-}
|
|
|
-
|
|
|
-static void setBoolSetting(std::string group, std::string field, bool value)
|
|
|
-{
|
|
|
- Settings fullscreen = settings.write[group][field];
|
|
|
- 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"])
|
|
|
-{
|
|
|
- OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
|
|
|
- title = std::make_shared<CLabel>(242, 32, FONT_BIG, ETextAlignment::CENTER, Colors::YELLOW, CGI->generaltexth->allTexts[568]);
|
|
|
-
|
|
|
- //left window section
|
|
|
- leftGroup = std::make_shared<CLabelGroup>(FONT_MEDIUM, ETextAlignment::CENTER, Colors::YELLOW);
|
|
|
- leftGroup->add(122, 64, CGI->generaltexth->allTexts[569]);
|
|
|
- leftGroup->add(122, 130, CGI->generaltexth->allTexts[570]);
|
|
|
- leftGroup->add(122, 196, CGI->generaltexth->allTexts[571]);
|
|
|
- leftGroup->add(122, 262, CGI->generaltexth->translate("vcmi.systemOptions.resolutionButton.hover"));
|
|
|
- leftGroup->add(122, 347, CGI->generaltexth->allTexts[394]);
|
|
|
- leftGroup->add(122, 412, CGI->generaltexth->allTexts[395]);
|
|
|
-
|
|
|
- //right section
|
|
|
- rightGroup = std::make_shared<CLabelGroup>(FONT_MEDIUM, ETextAlignment::TOPLEFT, Colors::WHITE);
|
|
|
- rightGroup->add(282, 57, CGI->generaltexth->allTexts[572]);
|
|
|
- rightGroup->add(282, 89, CGI->generaltexth->allTexts[573]);
|
|
|
- rightGroup->add(282, 121, CGI->generaltexth->allTexts[574]);
|
|
|
- rightGroup->add(282, 153, CGI->generaltexth->allTexts[577]);
|
|
|
- rightGroup->add(282, 217, CGI->generaltexth->translate("vcmi.systemOptions.fullscreenButton.hover"));
|
|
|
-
|
|
|
- //setting up buttons
|
|
|
- load = std::make_shared<CButton>(Point(246, 298), "SOLOAD.DEF", CGI->generaltexth->zelp[321], [&](){ bloadf(); }, SDLK_l);
|
|
|
- load->setImageOrder(1, 0, 2, 3);
|
|
|
-
|
|
|
- save = std::make_shared<CButton>(Point(357, 298), "SOSAVE.DEF", CGI->generaltexth->zelp[322], [&](){ bsavef(); }, SDLK_s);
|
|
|
- save->setImageOrder(1, 0, 2, 3);
|
|
|
-
|
|
|
- restart = std::make_shared<CButton>(Point(246, 357), "SORSTRT", CGI->generaltexth->zelp[323], [&](){ brestartf(); }, SDLK_r);
|
|
|
- restart->setImageOrder(1, 0, 2, 3);
|
|
|
-
|
|
|
- if(CSH->isGuest())
|
|
|
- {
|
|
|
- load->block(true);
|
|
|
- save->block(true);
|
|
|
- restart->block(true);
|
|
|
- }
|
|
|
-
|
|
|
- mainMenu = std::make_shared<CButton>(Point(357, 357), "SOMAIN.DEF", CGI->generaltexth->zelp[320], [&](){ bmainmenuf(); }, SDLK_m);
|
|
|
- mainMenu->setImageOrder(1, 0, 2, 3);
|
|
|
-
|
|
|
- quitGame = std::make_shared<CButton>(Point(246, 415), "soquit.def", CGI->generaltexth->zelp[324], [&](){ bquitf(); }, SDLK_q);
|
|
|
- quitGame->setImageOrder(1, 0, 2, 3);
|
|
|
-
|
|
|
- backToMap = std::make_shared<CButton>( Point(357, 415), "soretrn.def", CGI->generaltexth->zelp[325], [&](){ breturnf(); }, SDLK_RETURN);
|
|
|
- backToMap->setImageOrder(1, 0, 2, 3);
|
|
|
- backToMap->assignedKeys.insert(SDLK_ESCAPE);
|
|
|
-
|
|
|
- heroMoveSpeed = std::make_shared<CToggleGroup>(0);
|
|
|
- enemyMoveSpeed = std::make_shared<CToggleGroup>(0);
|
|
|
- mapScrollSpeed = std::make_shared<CToggleGroup>(0);
|
|
|
-
|
|
|
- heroMoveSpeed->addToggle(1, std::make_shared<CToggleButton>(Point( 28, 77), "sysopb1.def", CGI->generaltexth->zelp[349]));
|
|
|
- heroMoveSpeed->addToggle(2, std::make_shared<CToggleButton>(Point( 76, 77), "sysopb2.def", CGI->generaltexth->zelp[350]));
|
|
|
- heroMoveSpeed->addToggle(4, std::make_shared<CToggleButton>(Point(124, 77), "sysopb3.def", CGI->generaltexth->zelp[351]));
|
|
|
- heroMoveSpeed->addToggle(8, std::make_shared<CToggleButton>(Point(172, 77), "sysopb4.def", CGI->generaltexth->zelp[352]));
|
|
|
- heroMoveSpeed->setSelected((int)settings["adventure"]["heroSpeed"].Float());
|
|
|
- heroMoveSpeed->addCallback(std::bind(&setIntSetting, "adventure", "heroSpeed", _1));
|
|
|
-
|
|
|
- enemyMoveSpeed->addToggle(2, std::make_shared<CToggleButton>(Point( 28, 144), "sysopb5.def", CGI->generaltexth->zelp[353]));
|
|
|
- enemyMoveSpeed->addToggle(4, std::make_shared<CToggleButton>(Point( 76, 144), "sysopb6.def", CGI->generaltexth->zelp[354]));
|
|
|
- enemyMoveSpeed->addToggle(8, std::make_shared<CToggleButton>(Point(124, 144), "sysopb7.def", CGI->generaltexth->zelp[355]));
|
|
|
- enemyMoveSpeed->addToggle(0, std::make_shared<CToggleButton>(Point(172, 144), "sysopb8.def", CGI->generaltexth->zelp[356]));
|
|
|
- enemyMoveSpeed->setSelected((int)settings["adventure"]["enemySpeed"].Float());
|
|
|
- enemyMoveSpeed->addCallback(std::bind(&setIntSetting, "adventure", "enemySpeed", _1));
|
|
|
-
|
|
|
- mapScrollSpeed->addToggle(1, std::make_shared<CToggleButton>(Point( 28, 210), "sysopb9.def", CGI->generaltexth->zelp[357]));
|
|
|
- mapScrollSpeed->addToggle(2, std::make_shared<CToggleButton>(Point( 92, 210), "sysob10.def", CGI->generaltexth->zelp[358]));
|
|
|
- mapScrollSpeed->addToggle(4, std::make_shared<CToggleButton>(Point(156, 210), "sysob11.def", CGI->generaltexth->zelp[359]));
|
|
|
- mapScrollSpeed->setSelected((int)settings["adventure"]["scrollSpeed"].Float());
|
|
|
- mapScrollSpeed->addCallback(std::bind(&setIntSetting, "adventure", "scrollSpeed", _1));
|
|
|
-
|
|
|
- musicVolume = std::make_shared<CVolumeSlider>(Point(29, 359), "syslb.def", CCS->musich->getVolume(), CVolumeSlider::MUSIC);
|
|
|
- musicVolume->addCallback(std::bind(&setIntSetting, "general", "music", _1));
|
|
|
-
|
|
|
- effectsVolume = std::make_shared<CVolumeSlider>(Point(29, 425), "syslb.def", CCS->soundh->getVolume(), CVolumeSlider::SOUND);
|
|
|
- effectsVolume->addCallback(std::bind(&setIntSetting, "general", "sound", _1));
|
|
|
-
|
|
|
- showReminder = std::make_shared<CToggleButton>(Point(246, 87), "sysopchk.def", CGI->generaltexth->zelp[361], [&](bool value)
|
|
|
- {
|
|
|
- setBoolSetting("adventure", "heroReminder", value);
|
|
|
- });
|
|
|
- showReminder->setSelected(settings["adventure"]["heroReminder"].Bool());
|
|
|
-
|
|
|
- quickCombat = std::make_shared<CToggleButton>(Point(246, 87+32), "sysopchk.def", CGI->generaltexth->zelp[362], [&](bool value)
|
|
|
- {
|
|
|
- setBoolSetting("adventure", "quickCombat", value);
|
|
|
- });
|
|
|
- quickCombat->setSelected(settings["adventure"]["quickCombat"].Bool());
|
|
|
-
|
|
|
- spellbookAnim = std::make_shared<CToggleButton>(Point(246, 87+64), "sysopchk.def", CGI->generaltexth->zelp[364], [&](bool value)
|
|
|
- {
|
|
|
- setBoolSetting("video", "spellbookAnimation", value);
|
|
|
- });
|
|
|
- spellbookAnim->setSelected(settings["video"]["spellbookAnimation"].Bool());
|
|
|
-
|
|
|
- fullscreen = std::make_shared<CToggleButton>(Point(246, 215), "sysopchk.def", CButton::tooltipLocalized("vcmi.systemOptions.fullscreenButton"), [&](bool value)
|
|
|
- {
|
|
|
- setFullscreenMode(value);
|
|
|
- });
|
|
|
- fullscreen->setSelected(settings["video"]["fullscreen"].Bool());
|
|
|
-
|
|
|
- onFullscreenChanged([&](const JsonNode &newState){ fullscreen->setSelected(newState.Bool());});
|
|
|
-
|
|
|
- gameResButton = std::make_shared<CButton>(Point(28, 275),"buttons/resolution", CButton::tooltipLocalized("vcmi.systemOptions.resolutionButton"), std::bind(&CSystemOptionsWindow::selectGameRes, this), SDLK_g);
|
|
|
-
|
|
|
- const auto & screenRes = settings["video"]["screenRes"];
|
|
|
- gameResLabel = std::make_shared<CLabel>(170, 292, FONT_MEDIUM, ETextAlignment::CENTER, Colors::YELLOW, resolutionToString(screenRes["width"].Integer(), screenRes["height"].Integer()));
|
|
|
-}
|
|
|
-
|
|
|
-void CSystemOptionsWindow::setFullscreenMode( bool on)
|
|
|
-{
|
|
|
- fillSelectableResolutions();
|
|
|
-
|
|
|
- const auto & screenRes = settings["video"]["screenRes"];
|
|
|
- const Point desiredResolution(screenRes["width"].Integer(), screenRes["height"].Integer());
|
|
|
- const Point currentResolution(screen->w, screen->h);
|
|
|
-
|
|
|
- if (!isResolutionSupported(currentResolution, on))
|
|
|
- {
|
|
|
- fullscreen->setSelected(!on);
|
|
|
- LOCPLINT->showInfoDialog(CGI->generaltexth->translate("vcmi.systemOptions.fullscreenFailed"));
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- 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;
|
|
|
-
|
|
|
- gameResLabel->setText(resolutionToString(currentResolution.x, currentResolution.y));
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-void CSystemOptionsWindow::fillSelectableResolutions()
|
|
|
-{
|
|
|
- selectableResolutions.clear();
|
|
|
-
|
|
|
- for(const auto & it : conf.guiOptions)
|
|
|
- {
|
|
|
- const Point dimensions(it.first.first, it.first.second);
|
|
|
-
|
|
|
- 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;
|
|
|
- });
|
|
|
-}
|
|
|
-
|
|
|
-bool CSystemOptionsWindow::isResolutionSupported(const Point & resolution)
|
|
|
-{
|
|
|
- return isResolutionSupported( resolution, settings["video"]["fullscreen"].Bool());
|
|
|
-}
|
|
|
-
|
|
|
-bool CSystemOptionsWindow::isResolutionSupported(const Point & resolution, bool fullscreen)
|
|
|
-{
|
|
|
- if (!fullscreen)
|
|
|
- return true;
|
|
|
-
|
|
|
- auto supportedList = CSDL_Ext::getSupportedResolutions();
|
|
|
-
|
|
|
- return CSDL_Ext::isResolutionSupported(supportedList, resolution);
|
|
|
-}
|
|
|
-
|
|
|
-void CSystemOptionsWindow::selectGameRes()
|
|
|
-{
|
|
|
- fillSelectableResolutions();
|
|
|
-
|
|
|
- std::vector<std::string> items;
|
|
|
- size_t currentResolutionIndex = 0;
|
|
|
- size_t i = 0;
|
|
|
- for(const auto & it : selectableResolutions)
|
|
|
- {
|
|
|
- auto resolutionStr = resolutionToString(it.x, it.y);
|
|
|
- if(gameResLabel->getText() == resolutionStr)
|
|
|
- currentResolutionIndex = i;
|
|
|
-
|
|
|
- items.push_back(std::move(resolutionStr));
|
|
|
- ++i;
|
|
|
- }
|
|
|
-
|
|
|
- GH.pushIntT<CObjectListWindow>(items, nullptr,
|
|
|
- CGI->generaltexth->translate("vcmi.systemOptions.resolutionMenu.hover"),
|
|
|
- CGI->generaltexth->translate("vcmi.systemOptions.resolutionMenu.help"),
|
|
|
- std::bind(&CSystemOptionsWindow::setGameRes, this, _1),
|
|
|
- currentResolutionIndex);
|
|
|
-}
|
|
|
-
|
|
|
-void CSystemOptionsWindow::setGameRes(int index)
|
|
|
-{
|
|
|
- assert(index >= 0 && index < selectableResolutions.size());
|
|
|
-
|
|
|
- if ( index < 0 || index >= selectableResolutions.size() )
|
|
|
- return;
|
|
|
-
|
|
|
- Point resolution = selectableResolutions[index];
|
|
|
-
|
|
|
- Settings gameRes = settings.write["video"]["screenRes"];
|
|
|
- gameRes["width"].Float() = resolution.x;
|
|
|
- gameRes["height"].Float() = resolution.y;
|
|
|
-
|
|
|
- std::string resText;
|
|
|
- resText += std::to_string(resolution.x);
|
|
|
- resText += "x";
|
|
|
- resText += std::to_string(resolution.y);
|
|
|
- gameResLabel->setText(resText);
|
|
|
-}
|
|
|
-
|
|
|
-void CSystemOptionsWindow::bquitf()
|
|
|
-{
|
|
|
- LOCPLINT->showYesNoDialog(CGI->generaltexth->allTexts[578], [this](){ closeAndPushEvent(EUserEvent::FORCE_QUIT); }, 0);
|
|
|
-}
|
|
|
-
|
|
|
-void CSystemOptionsWindow::breturnf()
|
|
|
-{
|
|
|
- close();
|
|
|
-}
|
|
|
-
|
|
|
-void CSystemOptionsWindow::bmainmenuf()
|
|
|
-{
|
|
|
- LOCPLINT->showYesNoDialog(CGI->generaltexth->allTexts[578], [this](){ closeAndPushEvent(EUserEvent::RETURN_TO_MAIN_MENU); }, 0);
|
|
|
-}
|
|
|
-
|
|
|
-void CSystemOptionsWindow::bloadf()
|
|
|
-{
|
|
|
- close();
|
|
|
- LOCPLINT->proposeLoadingGame();
|
|
|
-}
|
|
|
-
|
|
|
-void CSystemOptionsWindow::bsavef()
|
|
|
-{
|
|
|
- close();
|
|
|
- GH.pushIntT<CSavingScreen>();
|
|
|
-}
|
|
|
-
|
|
|
-void CSystemOptionsWindow::brestartf()
|
|
|
-{
|
|
|
- LOCPLINT->showYesNoDialog(CGI->generaltexth->allTexts[67], [this](){ closeAndPushEvent(EUserEvent::RESTART_GAME); }, 0);
|
|
|
-}
|
|
|
-
|
|
|
-void CSystemOptionsWindow::closeAndPushEvent(EUserEvent code)
|
|
|
-{
|
|
|
- close();
|
|
|
- GH.pushUserEvent(code);
|
|
|
-}
|
|
|
|
|
|
CTavernWindow::CTavernWindow(const CGObjectInstance * TavernObj)
|
|
|
: CStatusbarWindow(PLAYER_COLORED, "TPTAVERN"),
|