/* * SettingsMainContainer.cpp, part of VCMI engine * * Authors: listed in file AUTHORS in main folder * * License: GNU General Public License v2.0 or later * Full text of license available in license.txt file, in main folder * */ #include "StdInc.h" #include "SettingsMainWindow.h" #include "GeneralOptionsTab.h" #include "AdventureOptionsTab.h" #include "BattleOptionsTab.h" #include "OtherOptionsTab.h" #include "filesystem/ResourceID.h" #include "CGeneralTextHandler.h" #include "gui/CGuiHandler.h" #include "lobby/CSavingScreen.h" #include "widgets/Buttons.h" #include "widgets/Images.h" #include "widgets/ObjectLists.h" #include "CGameInfo.h" #include "CPlayerInterface.h" #include "CServerHandler.h" SettingsMainWindow::SettingsMainWindow(BattleInterface * parentBattleUi) : InterfaceObjectConfigurable() { OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE; const JsonNode config(ResourceID("config/widgets/settings/settingsMainContainer.json")); addCallback("activateSettingsTab", [this](int tabId) { openTab(tabId); }); addCallback("loadGame", [this](int) { loadGameButtonCallback(); }); addCallback("saveGame", [this](int) { saveGameButtonCallback(); }); addCallback("restartGame", [this](int) { restartGameButtonCallback(); }); addCallback("quitGame", [this](int) { quitGameButtonCallback(); }); addCallback("returnToMainMenu", [this](int) { mainMenuButtonCallback(); }); addCallback("closeWindow", [this](int) { backButtonCallback(); }); build(config); std::shared_ptr background = widget("background"); pos.w = background->pos.w; pos.h = background->pos.h; pos = center(); std::shared_ptr loadButton = widget("loadButton"); assert(loadButton); std::shared_ptr saveButton = widget("saveButton"); assert(saveButton); std::shared_ptr restartButton = widget("restartButton"); assert(restartButton); if(CSH->isGuest()) { loadButton->block(true); saveButton->block(true); restartButton->block(true); } int defaultTabIndex = 0; if(parentBattleUi != nullptr) defaultTabIndex = 2; else if(settings["general"]["lastSettingsTab"].isNumber()) defaultTabIndex = settings["general"]["lastSettingsTab"].Integer(); parentBattleInterface = parentBattleUi; tabContentArea = std::make_shared(std::bind(&SettingsMainWindow::createTab, this, _1), Point(0, 40), defaultTabIndex); std::shared_ptr mainTabs = widget("settingsTabs"); mainTabs->setSelected(defaultTabIndex); } std::shared_ptr SettingsMainWindow::createTab(size_t index) { switch(index) { case 0: return std::make_shared(); case 1: return std::make_shared(); case 2: return std::make_shared(parentBattleInterface); case 3: return std::make_shared(); default: logGlobal->error("Wrong settings tab ID!"); return std::make_shared(); } } void SettingsMainWindow::openTab(size_t index) { tabContentArea->setActive(index); CIntObject::redraw(); Settings lastUsedTab = settings.write["general"]["lastSettingsTab"]; lastUsedTab->Integer() = index; } void SettingsMainWindow::close() { if(GH.topInt().get() != this) logGlobal->error("Only top interface must be closed"); GH.popInts(1); } void SettingsMainWindow::quitGameButtonCallback() { LOCPLINT->showYesNoDialog(CGI->generaltexth->allTexts[578], [this](){ closeAndPushEvent(EUserEvent::FORCE_QUIT); }, 0); } void SettingsMainWindow::backButtonCallback() { close(); } void SettingsMainWindow::mainMenuButtonCallback() { LOCPLINT->showYesNoDialog(CGI->generaltexth->allTexts[578], [this](){ closeAndPushEvent(EUserEvent::RETURN_TO_MAIN_MENU); }, 0); } void SettingsMainWindow::loadGameButtonCallback() { close(); LOCPLINT->proposeLoadingGame(); } void SettingsMainWindow::saveGameButtonCallback() { close(); GH.pushIntT(); } void SettingsMainWindow::restartGameButtonCallback() { LOCPLINT->showYesNoDialog(CGI->generaltexth->allTexts[67], [this](){ closeAndPushEvent(EUserEvent::RESTART_GAME); }, 0); } void SettingsMainWindow::closeAndPushEvent(EUserEvent code) { close(); GH.pushUserEvent(code); }