diff --git a/client/windows/SettingsMainContainer.cpp b/client/windows/SettingsMainContainer.cpp index 2f0a86a67..196de8b15 100644 --- a/client/windows/SettingsMainContainer.cpp +++ b/client/windows/SettingsMainContainer.cpp @@ -10,13 +10,21 @@ #include "StdInc.h" -#include "gui/CGuiHandler.h" -#include "gui/InterfaceObjectConfigurable.h" #include "SettingsMainContainer.h" + #include "SystemOptionsWindow.h" #include "VcmiSettingsWindow.h" + #include "../../lib/filesystem/ResourceID.h" -#include "battle/BattleInterfaceClasses.h" +#include "../../lib/CGeneralTextHandler.h" +#include "../battle/BattleInterfaceClasses.h" +#include "../gui/CGuiHandler.h" +#include "../lobby/CSavingScreen.h" +#include "../widgets/Images.h" +#include "../CGameInfo.h" +#include "../CPlayerInterface.h" +#include "../CServerHandler.h" + SettingsMainContainer::SettingsMainContainer() : InterfaceObjectConfigurable() { @@ -26,13 +34,41 @@ SettingsMainContainer::SettingsMainContainer() : InterfaceObjectConfigurable() addCallback("activateMainTab", [this](int) { openTab(0); }); addCallback("activateBattleSettingsTab", [this](int) { openTab(1); }); addCallback("activateVcmiSettingsTab", [this](int) { openTab(2); }); + + 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(settings["general"]["lastSettingsTab"].isNumber()) defaultTabIndex = settings["general"]["lastSettingsTab"].Integer(); - tabContentArea = std::make_shared(std::bind(&SettingsMainContainer::createTab, this, _1), Point(50, 50), defaultTabIndex); + tabContentArea = std::make_shared(std::bind(&SettingsMainContainer::createTab, this, _1), Point(0, 50), defaultTabIndex); } std::shared_ptr SettingsMainContainer::createTab(size_t index) @@ -58,4 +94,49 @@ void SettingsMainContainer::openTab(size_t index) Settings lastUsedTab = settings.write["general"]["lastSettingsTab"]; lastUsedTab->Integer() = index; +} + +void SettingsMainContainer::close() +{ + if(GH.topInt().get() != this) + logGlobal->error("Only top interface must be closed"); + GH.popInts(1); +} + +void SettingsMainContainer::quitGameButtonCallback() +{ + LOCPLINT->showYesNoDialog(CGI->generaltexth->allTexts[578], [this](){ closeAndPushEvent(SDL_USEREVENT, EUserEvent::FORCE_QUIT); }, 0); +} + +void SettingsMainContainer::backButtonCallback() +{ + close(); +} + +void SettingsMainContainer::mainMenuButtonCallback() +{ + LOCPLINT->showYesNoDialog(CGI->generaltexth->allTexts[578], [this](){ closeAndPushEvent(SDL_USEREVENT, EUserEvent::RETURN_TO_MAIN_MENU); }, 0); +} + +void SettingsMainContainer::loadGameButtonCallback() +{ + close(); + LOCPLINT->proposeLoadingGame(); +} + +void SettingsMainContainer::saveGameButtonCallback() +{ + close(); + GH.pushIntT(); +} + +void SettingsMainContainer::restartGameButtonCallback() +{ + LOCPLINT->showYesNoDialog(CGI->generaltexth->allTexts[67], [this](){ closeAndPushEvent(SDL_USEREVENT, EUserEvent::RESTART_GAME); }, 0); +} + +void SettingsMainContainer::closeAndPushEvent(int eventType, int code) +{ + close(); + GH.pushSDLEvent(eventType, code); } \ No newline at end of file diff --git a/client/windows/SettingsMainContainer.h b/client/windows/SettingsMainContainer.h index daf29fd68..f821a4d3c 100644 --- a/client/windows/SettingsMainContainer.h +++ b/client/windows/SettingsMainContainer.h @@ -21,6 +21,16 @@ private: std::shared_ptr createTab(size_t index); void openTab(size_t index); + + void close(); //TODO: copypaste of WindowBase::close(), consider changing Windowbase to IWindowbase with default close() implementation and changing WindowBase inheritance to CIntObject + IWindowBase + void closeAndPushEvent(int eventType, int code = 0); + + void loadGameButtonCallback(); + void saveGameButtonCallback(); + void quitGameButtonCallback(); + void backButtonCallback(); + void restartGameButtonCallback(); + void mainMenuButtonCallback(); public: SettingsMainContainer(); }; diff --git a/client/windows/SystemOptionsWindow.cpp b/client/windows/SystemOptionsWindow.cpp index ec25a4291..bcaa09bcd 100644 --- a/client/windows/SystemOptionsWindow.cpp +++ b/client/windows/SystemOptionsWindow.cpp @@ -23,7 +23,6 @@ #include "VcmiSettingsWindow.h" #include "GUIClasses.h" #include "CServerHandler.h" -#include "lobby/CSavingScreen.h" static void setIntSetting(std::string group, std::string field, int value) @@ -50,12 +49,6 @@ SystemOptionsWindow::SystemOptionsWindow() OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE; const JsonNode config(ResourceID("config/widgets/optionsMenu.json")); - 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(); }); addCallback("playerHeroSpeedChanged", std::bind(&setIntSetting, "adventure", "heroSpeed", _1)); addCallback("enemyHeroSpeedChanged", std::bind(&setIntSetting, "adventure", "enemySpeed", _1)); addCallback("mapScrollSpeedChanged", std::bind(&setIntSetting, "adventure", "scrollSpeed", _1)); @@ -66,14 +59,8 @@ SystemOptionsWindow::SystemOptionsWindow() addCallback("setGameResolution", std::bind(&SystemOptionsWindow::selectGameResolution, this)); addCallback("setMusic", [this](int value) { setIntSetting("general", "music", value); widget("musicSlider")->redraw(); }); addCallback("setVolume", [this](int value) { setIntSetting("general", "sound", value); widget("soundVolumeSlider")->redraw(); }); - addCallback("openVcmiSettings", [this](int) { showVcmiSettingsButtonCallback(); }); build(config); -// std::shared_ptr background = widget("background"); -// pos.w = background->pos.w; -// pos.h = background->pos.h; -// pos = center(); - std::shared_ptr resolutionLabel = widget("resolutionLabel"); const auto & currentResolution = settings["video"]["screenRes"]; resolutionLabel->setText(resolutionToString(currentResolution["width"].Integer(), currentResolution["height"].Integer())); @@ -101,9 +88,9 @@ SystemOptionsWindow::SystemOptionsWindow() std::shared_ptr fullscreenCheckbox = widget("fullscreenCheckbox"); fullscreenCheckbox->setSelected((bool)settings["video"]["fullscreen"].Bool()); onFullscreenChanged([&](const JsonNode &newState) //used when pressing F4 etc. to change fullscreen checkbox state - { - widget("fullscreenCheckbox")->setSelected(newState.Bool()); - }); + { + widget("fullscreenCheckbox")->setSelected(newState.Bool()); + }); std::shared_ptr musicSlider = widget("musicSlider"); @@ -111,31 +98,9 @@ SystemOptionsWindow::SystemOptionsWindow() std::shared_ptr volumeSlider = widget("soundVolumeSlider"); volumeSlider->moveTo(CCS->soundh->getVolume()); - - - 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); - } } -void SystemOptionsWindow::close() -{ - if(GH.topInt().get() != this) - logGlobal->error("Only top interface must be closed"); - GH.popInts(1); -} + void SystemOptionsWindow::selectGameResolution() { @@ -187,48 +152,4 @@ void SystemOptionsWindow::setGameResolution(int index) resText += "x"; resText += boost::lexical_cast(iter->first.second); widget("resolutionLabel")->setText(resText); -} - -void SystemOptionsWindow::quitGameButtonCallback() -{ - LOCPLINT->showYesNoDialog(CGI->generaltexth->allTexts[578], [this](){ closeAndPushEvent(SDL_USEREVENT, EUserEvent::FORCE_QUIT); }, 0); -} - -void SystemOptionsWindow::backButtonCallback() -{ - close(); -} - -void SystemOptionsWindow::mainMenuButtonCallback() -{ - LOCPLINT->showYesNoDialog(CGI->generaltexth->allTexts[578], [this](){ closeAndPushEvent(SDL_USEREVENT, EUserEvent::RETURN_TO_MAIN_MENU); }, 0); -} - -void SystemOptionsWindow::loadGameButtonCallback() -{ - close(); - LOCPLINT->proposeLoadingGame(); -} - -void SystemOptionsWindow::saveGameButtonCallback() -{ - close(); - GH.pushIntT(); -} - -void SystemOptionsWindow::restartGameButtonCallback() -{ - LOCPLINT->showYesNoDialog(CGI->generaltexth->allTexts[67], [this](){ closeAndPushEvent(SDL_USEREVENT, EUserEvent::RESTART_GAME); }, 0); -} - -void SystemOptionsWindow::showVcmiSettingsButtonCallback() -{ - close(); - GH.pushIntT(); -} - -void SystemOptionsWindow::closeAndPushEvent(int eventType, int code) -{ - close(); - GH.pushSDLEvent(eventType, code); } \ No newline at end of file diff --git a/client/windows/SystemOptionsWindow.h b/client/windows/SystemOptionsWindow.h index 67b8907a2..c26b123e6 100644 --- a/client/windows/SystemOptionsWindow.h +++ b/client/windows/SystemOptionsWindow.h @@ -17,19 +17,8 @@ class SystemOptionsWindow : public InterfaceObjectConfigurable private: SettingsListener onFullscreenChanged; - //functions bound to buttons - void loadGameButtonCallback(); - void saveGameButtonCallback(); - void quitGameButtonCallback(); - void backButtonCallback(); - void restartGameButtonCallback(); - void mainMenuButtonCallback(); - void showVcmiSettingsButtonCallback(); - - void close(); //TODO: copypaste of WindowBase::close(), consider changing Windowbase to IWindowbase with default close() implementation and changing WindowBase inheritance to CIntObject + IWindowBase void selectGameResolution(); void setGameResolution(int index); - void closeAndPushEvent(int eventType, int code = 0); public: SystemOptionsWindow(); diff --git a/client/windows/VcmiSettingsWindow.cpp b/client/windows/VcmiSettingsWindow.cpp index 2451443f2..c24cd09fd 100644 --- a/client/windows/VcmiSettingsWindow.cpp +++ b/client/windows/VcmiSettingsWindow.cpp @@ -13,33 +13,13 @@ #include "../lib/filesystem/ResourceID.h" #include "gui/CGuiHandler.h" -#include "SystemOptionsWindow.h" VcmiSettingsWindow::VcmiSettingsWindow() : InterfaceObjectConfigurable() { OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE; const JsonNode config(ResourceID("config/widgets/vcmiSettings.json")); - addCallback("closeWindow", [this](int) { backButtonCallback(); }); - addCallback("openSystemOptions", [this](int) { openSystemOptionsCallback(); }); build(config); } -void VcmiSettingsWindow::close() -{ - if(GH.topInt().get() != this) - logGlobal->error("Only top interface must be closed"); - GH.popInts(1); -} - -void VcmiSettingsWindow::backButtonCallback() -{ - close(); -} - -void VcmiSettingsWindow::openSystemOptionsCallback() -{ - close(); - GH.pushIntT(); -} diff --git a/client/windows/VcmiSettingsWindow.h b/client/windows/VcmiSettingsWindow.h index e2610953d..755fa2221 100644 --- a/client/windows/VcmiSettingsWindow.h +++ b/client/windows/VcmiSettingsWindow.h @@ -14,9 +14,6 @@ class VcmiSettingsWindow : public InterfaceObjectConfigurable { private: - void close(); //TODO: copypaste of WindowBase::close(), consider changing Windowbase to IWindowbase with default close() implementation and changing WindowBase inheritance to CIntObject + IWindowBase - void backButtonCallback(); - void openSystemOptionsCallback(); public: VcmiSettingsWindow(); diff --git a/config/widgets/optionsMenu.json b/config/widgets/optionsMenu.json index 3dc07c007..33c39cd9c 100644 --- a/config/widgets/optionsMenu.json +++ b/config/widgets/optionsMenu.json @@ -77,72 +77,6 @@ ] }, - { - "name": "loadButton", - "type": "button", - "position": {"x": 246, "y": 298}, - "image": "SOLOAD.DEF", - "imageOrder": [1, 0, 2, 3], - "help": "core.help.321", - "callback": "loadGame", - "hotkey": "l" - }, - - { - "name": "saveButton", - "type": "button", - "position": {"x": 357, "y": 298}, - "image": "SOSAVE.DEF", - "imageOrder": [1, 0, 2, 3], - "help": "core.help.322", - "callback": "saveGame", - "hotkey": "s" - }, - - { - "name": "restartButton", - "type": "button", - "position": {"x": 246, "y": 357}, - "image": "SORSTRT.DEF", - "imageOrder": [1, 0, 2, 3], - "help": "core.help.323", - "callback": "restartGame", - "hotkey": "r" - }, - - { - "name": "mainMenuButton", - "type": "button", - "position": {"x": 357, "y": 357}, - "image": "SOMAIN.DEF", - "imageOrder": [1, 0, 2, 3], - "help": "core.help.320", - "callback": "returnToMainMenu", - "hotkey": "m" - }, - - { - "name": "quitButton", - "type": "button", - "position": {"x": 246, "y": 415}, - "image": "soquit.def", - "imageOrder": [1, 0, 2, 3], - "help": "core.help.324", - "callback": "quitGame", - "hotkey": "q" - }, - - { - "name": "closeSettingsButton", - "type": "button", - "position": {"x": 357, "y": 415}, - "image": "soretrn.def", - "imageOrder": [1, 0, 2, 3], - "help": "core.help.325", - "callback": "closeWindow", - "hotkey": ["esc", "backspace"] - }, - { "name": "heroMovementSpeedPicker", "type": "toggleGroup", diff --git a/config/widgets/settingsMainContainer.json b/config/widgets/settingsMainContainer.json index 77f7f5e33..90aff2cfa 100644 --- a/config/widgets/settingsMainContainer.json +++ b/config/widgets/settingsMainContainer.json @@ -7,6 +7,7 @@ "image": "vcmiSettingsWindow", "position": {"x": 0, "y": 0} }, + { "name": "activateSystemOptionsButton", "type": "button", @@ -19,7 +20,7 @@ { "name": "activateBattleSettingsButton", "type": "button", - "position": {"x": 250, "y": 0}, + "position": {"x": 220, "y": 0}, "image": "buttons/vcmisettings", "help": "TODO", "callback": "activateBattleSettingsTab" @@ -28,10 +29,76 @@ { "name": "activateVcmiSettingsButton", "type": "button", - "position": {"x": 500, "y": 0}, + "position": {"x": 440, "y": 0}, "image": "buttons/vcmisettings", "help": "TODO", "callback": "activateVcmiSettingsTab" + }, + + { + "name": "loadButton", + "type": "button", + "position": {"x": 346, "y": 298}, + "image": "SOLOAD.DEF", + "imageOrder": [1, 0, 2, 3], + "help": "core.help.321", + "callback": "loadGame", + "hotkey": "l" + }, + + { + "name": "saveButton", + "type": "button", + "position": {"x": 457, "y": 298}, + "image": "SOSAVE.DEF", + "imageOrder": [1, 0, 2, 3], + "help": "core.help.322", + "callback": "saveGame", + "hotkey": "s" + }, + + { + "name": "restartButton", + "type": "button", + "position": {"x": 346, "y": 357}, + "image": "SORSTRT.DEF", + "imageOrder": [1, 0, 2, 3], + "help": "core.help.323", + "callback": "restartGame", + "hotkey": "r" + }, + + { + "name": "mainMenuButton", + "type": "button", + "position": {"x": 457, "y": 357}, + "image": "SOMAIN.DEF", + "imageOrder": [1, 0, 2, 3], + "help": "core.help.320", + "callback": "returnToMainMenu", + "hotkey": "m" + }, + + { + "name": "quitButton", + "type": "button", + "position": {"x": 346, "y": 415}, + "image": "soquit.def", + "imageOrder": [1, 0, 2, 3], + "help": "core.help.324", + "callback": "quitGame", + "hotkey": "q" + }, + + { + "name": "closeSettingsButton", + "type": "button", + "position": {"x": 457, "y": 415}, + "image": "soretrn.def", + "imageOrder": [1, 0, 2, 3], + "help": "core.help.325", + "callback": "closeWindow", + "hotkey": ["esc", "backspace"] } ] } \ No newline at end of file diff --git a/config/widgets/vcmiSettings.json b/config/widgets/vcmiSettings.json index 7294351f5..790df6357 100644 --- a/config/widgets/vcmiSettings.json +++ b/config/widgets/vcmiSettings.json @@ -1,14 +1,5 @@ { "items": [ - { - "name": "closeSettingsButton", - "type": "button", - "position": {"x": 357, "y": 415}, - "image": "soretrn.def", - "imageOrder": [1, 0, 2, 3], - "help": "core.help.325", - "callback": "closeWindow" - } ] } \ No newline at end of file