Browse Source

Move buttons from mainOptions to SystemOptionsWindow

Dydzio 2 years ago
parent
commit
88744633de

+ 85 - 4
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<CPicture> background = widget<CPicture>("background");
+	pos.w = background->pos.w;
+	pos.h = background->pos.h;
+	pos = center();
+
+	std::shared_ptr<CButton> loadButton = widget<CButton>("loadButton");
+	assert(loadButton);
+
+	std::shared_ptr<CButton> saveButton = widget<CButton>("saveButton");
+	assert(saveButton);
+
+	std::shared_ptr<CButton> restartButton = widget<CButton>("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<CTabbedInt>(std::bind(&SettingsMainContainer::createTab, this, _1), Point(50, 50), defaultTabIndex);
+	tabContentArea = std::make_shared<CTabbedInt>(std::bind(&SettingsMainContainer::createTab, this, _1), Point(0, 50), defaultTabIndex);
 }
 
 std::shared_ptr<CIntObject> 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<CSavingScreen>();
+}
+
+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);
 }

+ 10 - 0
client/windows/SettingsMainContainer.h

@@ -21,6 +21,16 @@ private:
 
 	std::shared_ptr<CIntObject> 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();
 };

+ 4 - 83
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<CSlider>("musicSlider")->redraw(); });
 	addCallback("setVolume", [this](int value) { setIntSetting("general", "sound", value); widget<CSlider>("soundVolumeSlider")->redraw(); });
-	addCallback("openVcmiSettings", [this](int) { showVcmiSettingsButtonCallback(); });
 	build(config);
 
-//	std::shared_ptr<CPicture> background = widget<CPicture>("background");
-//	pos.w = background->pos.w;
-//	pos.h = background->pos.h;
-//	pos = center();
-
 	std::shared_ptr<CLabel> resolutionLabel = widget<CLabel>("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<CToggleButton> fullscreenCheckbox = widget<CToggleButton>("fullscreenCheckbox");
 	fullscreenCheckbox->setSelected((bool)settings["video"]["fullscreen"].Bool());
 	onFullscreenChanged([&](const JsonNode &newState) //used when pressing F4 etc. to change fullscreen checkbox state
-						{
-							widget<CToggleButton>("fullscreenCheckbox")->setSelected(newState.Bool());
-						});
+	{
+		widget<CToggleButton>("fullscreenCheckbox")->setSelected(newState.Bool());
+	});
 
 
 	std::shared_ptr<CSlider> musicSlider = widget<CSlider>("musicSlider");
@@ -111,31 +98,9 @@ SystemOptionsWindow::SystemOptionsWindow()
 
 	std::shared_ptr<CSlider> volumeSlider = widget<CSlider>("soundVolumeSlider");
 	volumeSlider->moveTo(CCS->soundh->getVolume());
-
-
-	std::shared_ptr<CButton> loadButton = widget<CButton>("loadButton");
-	assert(loadButton);
-
-	std::shared_ptr<CButton> saveButton = widget<CButton>("saveButton");
-	assert(saveButton);
-
-	std::shared_ptr<CButton> restartButton = widget<CButton>("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<std::string>(iter->first.second);
 	widget<CLabel>("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<CSavingScreen>();
-}
-
-void SystemOptionsWindow::restartGameButtonCallback()
-{
-	LOCPLINT->showYesNoDialog(CGI->generaltexth->allTexts[67], [this](){ closeAndPushEvent(SDL_USEREVENT, EUserEvent::RESTART_GAME); }, 0);
-}
-
-void SystemOptionsWindow::showVcmiSettingsButtonCallback()
-{
-	close();
-	GH.pushIntT<VcmiSettingsWindow>();
-}
-
-void SystemOptionsWindow::closeAndPushEvent(int eventType, int code)
-{
-	close();
-	GH.pushSDLEvent(eventType, code);
 }

+ 0 - 11
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();

+ 0 - 20
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<SystemOptionsWindow>();
-}
 

+ 0 - 3
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();

+ 0 - 66
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",

+ 69 - 2
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"]
 		}
 	]
 }

+ 0 - 9
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"
-		}
 	]
 }