2023-01-30 21:18:59 +02:00
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2023-02-02 12:55:13 +02:00
|
|
|
#include <SDL_events.h>
|
2023-01-30 21:18:59 +02:00
|
|
|
#include "StdInc.h"
|
|
|
|
|
|
|
|
#include "SettingsMainContainer.h"
|
2023-01-31 00:26:33 +02:00
|
|
|
|
2023-02-12 18:49:41 +02:00
|
|
|
#include "GeneralOptionsTab.h"
|
2023-01-30 21:18:59 +02:00
|
|
|
#include "VcmiSettingsWindow.h"
|
2023-02-12 18:49:41 +02:00
|
|
|
#include "BattleOptionsTab.h"
|
2023-01-31 00:26:33 +02:00
|
|
|
|
2023-02-12 18:29:23 +02:00
|
|
|
#include "filesystem/ResourceID.h"
|
|
|
|
#include "CGeneralTextHandler.h"
|
|
|
|
#include "gui/CGuiHandler.h"
|
|
|
|
#include "lobby/CSavingScreen.h"
|
|
|
|
#include "widgets/Images.h"
|
|
|
|
#include "CGameInfo.h"
|
|
|
|
#include "CPlayerInterface.h"
|
|
|
|
#include "CServerHandler.h"
|
2023-01-31 00:26:33 +02:00
|
|
|
|
2023-01-30 21:18:59 +02:00
|
|
|
|
2023-02-12 16:49:17 +02:00
|
|
|
SettingsMainContainer::SettingsMainContainer(BattleInterface * parentBattleUi) : InterfaceObjectConfigurable()
|
2023-01-30 21:18:59 +02:00
|
|
|
{
|
|
|
|
OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
|
|
|
|
|
2023-02-12 18:49:41 +02:00
|
|
|
const JsonNode config(ResourceID("config/widgets/settings/settingsMainContainer.json"));
|
2023-01-30 23:15:37 +02:00
|
|
|
addCallback("activateMainTab", [this](int) { openTab(0); });
|
|
|
|
addCallback("activateBattleSettingsTab", [this](int) { openTab(1); });
|
|
|
|
addCallback("activateVcmiSettingsTab", [this](int) { openTab(2); });
|
2023-01-31 00:26:33 +02:00
|
|
|
|
|
|
|
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(); });
|
2023-01-30 21:18:59 +02:00
|
|
|
build(config);
|
|
|
|
|
2023-01-31 00:26:33 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2023-01-30 23:15:37 +02:00
|
|
|
int defaultTabIndex = 0;
|
|
|
|
if(settings["general"]["lastSettingsTab"].isNumber())
|
|
|
|
defaultTabIndex = settings["general"]["lastSettingsTab"].Integer();
|
|
|
|
|
2023-02-12 16:49:17 +02:00
|
|
|
parentBattleInterface = parentBattleUi;
|
2023-01-31 00:26:33 +02:00
|
|
|
tabContentArea = std::make_shared<CTabbedInt>(std::bind(&SettingsMainContainer::createTab, this, _1), Point(0, 50), defaultTabIndex);
|
2023-01-30 21:18:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
std::shared_ptr<CIntObject> SettingsMainContainer::createTab(size_t index)
|
|
|
|
{
|
|
|
|
switch(index)
|
|
|
|
{
|
|
|
|
case 0:
|
2023-02-12 18:49:41 +02:00
|
|
|
return std::make_shared<GeneralOptionsTab>();
|
2023-01-30 21:18:59 +02:00
|
|
|
case 1:
|
2023-02-12 18:49:41 +02:00
|
|
|
return std::make_shared<BattleOptionsTab>(parentBattleInterface);
|
2023-01-30 23:15:37 +02:00
|
|
|
case 2:
|
2023-01-30 21:18:59 +02:00
|
|
|
return std::make_shared<VcmiSettingsWindow>();
|
|
|
|
default:
|
|
|
|
logGlobal->error("Wrong settings tab ID!");
|
2023-02-12 18:49:41 +02:00
|
|
|
return std::make_shared<GeneralOptionsTab>();
|
2023-01-30 21:18:59 +02:00
|
|
|
}
|
2023-01-30 23:15:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void SettingsMainContainer::openTab(size_t index)
|
|
|
|
{
|
|
|
|
tabContentArea->setActive(index);
|
|
|
|
CIntObject::redraw();
|
|
|
|
|
|
|
|
Settings lastUsedTab = settings.write["general"]["lastSettingsTab"];
|
|
|
|
lastUsedTab->Integer() = index;
|
2023-01-31 00:26:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void SettingsMainContainer::close()
|
|
|
|
{
|
|
|
|
if(GH.topInt().get() != this)
|
|
|
|
logGlobal->error("Only top interface must be closed");
|
|
|
|
GH.popInts(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SettingsMainContainer::quitGameButtonCallback()
|
|
|
|
{
|
2023-02-12 13:05:12 +02:00
|
|
|
LOCPLINT->showYesNoDialog(CGI->generaltexth->allTexts[578], [this](){ closeAndPushEvent(EUserEvent::FORCE_QUIT); }, 0);
|
2023-01-31 00:26:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void SettingsMainContainer::backButtonCallback()
|
|
|
|
{
|
|
|
|
close();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SettingsMainContainer::mainMenuButtonCallback()
|
|
|
|
{
|
2023-02-12 13:05:12 +02:00
|
|
|
LOCPLINT->showYesNoDialog(CGI->generaltexth->allTexts[578], [this](){ closeAndPushEvent(EUserEvent::RETURN_TO_MAIN_MENU); }, 0);
|
2023-01-31 00:26:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void SettingsMainContainer::loadGameButtonCallback()
|
|
|
|
{
|
|
|
|
close();
|
|
|
|
LOCPLINT->proposeLoadingGame();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SettingsMainContainer::saveGameButtonCallback()
|
|
|
|
{
|
|
|
|
close();
|
|
|
|
GH.pushIntT<CSavingScreen>();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SettingsMainContainer::restartGameButtonCallback()
|
|
|
|
{
|
2023-02-12 13:05:12 +02:00
|
|
|
LOCPLINT->showYesNoDialog(CGI->generaltexth->allTexts[67], [this](){ closeAndPushEvent(EUserEvent::RESTART_GAME); }, 0);
|
2023-01-31 00:26:33 +02:00
|
|
|
}
|
|
|
|
|
2023-02-12 13:05:12 +02:00
|
|
|
void SettingsMainContainer::closeAndPushEvent(EUserEvent code)
|
2023-01-31 00:26:33 +02:00
|
|
|
{
|
|
|
|
close();
|
2023-02-12 13:05:12 +02:00
|
|
|
GH.pushUserEvent(code);
|
2023-01-30 21:18:59 +02:00
|
|
|
}
|