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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "StdInc.h"
|
2023-02-18 18:58:22 +02:00
|
|
|
#include "SettingsMainWindow.h"
|
2023-01-31 00:26:33 +02:00
|
|
|
|
2023-02-12 20:25:59 +02:00
|
|
|
#include "AdventureOptionsTab.h"
|
2023-02-12 18:49:41 +02:00
|
|
|
#include "BattleOptionsTab.h"
|
2023-03-03 00:24:05 +02:00
|
|
|
#include "GeneralOptionsTab.h"
|
2023-02-18 18:58:22 +02:00
|
|
|
#include "OtherOptionsTab.h"
|
2023-01-31 00:26:33 +02:00
|
|
|
|
2023-06-26 20:51:10 +02:00
|
|
|
#include "CMT.h"
|
2023-03-03 00:24:05 +02:00
|
|
|
#include "CGameInfo.h"
|
2023-02-12 18:29:23 +02:00
|
|
|
#include "CGeneralTextHandler.h"
|
2023-03-03 00:24:05 +02:00
|
|
|
#include "CPlayerInterface.h"
|
|
|
|
#include "CServerHandler.h"
|
|
|
|
#include "filesystem/ResourceID.h"
|
2023-02-12 18:29:23 +02:00
|
|
|
#include "gui/CGuiHandler.h"
|
2023-05-16 14:10:26 +02:00
|
|
|
#include "gui/WindowHandler.h"
|
2023-06-02 15:42:18 +02:00
|
|
|
#include "render/Canvas.h"
|
2023-02-12 18:29:23 +02:00
|
|
|
#include "lobby/CSavingScreen.h"
|
2023-02-18 17:35:07 +02:00
|
|
|
#include "widgets/Buttons.h"
|
2023-02-12 18:29:23 +02:00
|
|
|
#include "widgets/Images.h"
|
2023-02-18 17:35:07 +02:00
|
|
|
#include "widgets/ObjectLists.h"
|
2023-03-03 00:24:05 +02:00
|
|
|
#include "windows/CMessage.h"
|
2023-01-30 21:18:59 +02:00
|
|
|
|
2023-02-18 18:58:22 +02:00
|
|
|
SettingsMainWindow::SettingsMainWindow(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-02-16 22:37:37 +02:00
|
|
|
addCallback("activateSettingsTab", [this](int tabId) { openTab(tabId); });
|
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-03-03 00:24:05 +02:00
|
|
|
std::shared_ptr<CIntObject> background = widget<CIntObject>("background");
|
2023-01-31 00:26:33 +02:00
|
|
|
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);
|
|
|
|
|
2023-03-05 00:51:46 +02:00
|
|
|
loadButton->block(CSH->isGuest());
|
|
|
|
saveButton->block(CSH->isGuest() || parentBattleUi);
|
|
|
|
restartButton->block(CSH->isGuest() || parentBattleUi);
|
2023-01-31 00:26:33 +02:00
|
|
|
|
2023-01-30 23:15:37 +02:00
|
|
|
int defaultTabIndex = 0;
|
2023-02-18 17:35:07 +02:00
|
|
|
if(parentBattleUi != nullptr)
|
|
|
|
defaultTabIndex = 2;
|
|
|
|
else if(settings["general"]["lastSettingsTab"].isNumber())
|
2023-01-30 23:15:37 +02:00
|
|
|
defaultTabIndex = settings["general"]["lastSettingsTab"].Integer();
|
|
|
|
|
2023-02-12 16:49:17 +02:00
|
|
|
parentBattleInterface = parentBattleUi;
|
2023-02-19 13:18:54 +02:00
|
|
|
tabContentArea = std::make_shared<CTabbedInt>(std::bind(&SettingsMainWindow::createTab, this, _1), Point(0, 0), defaultTabIndex);
|
2023-03-04 13:37:27 +02:00
|
|
|
tabContentArea->type |= REDRAW_PARENT;
|
2023-02-16 22:37:37 +02:00
|
|
|
|
|
|
|
std::shared_ptr<CToggleGroup> mainTabs = widget<CToggleGroup>("settingsTabs");
|
|
|
|
mainTabs->setSelected(defaultTabIndex);
|
2023-01-30 21:18:59 +02:00
|
|
|
}
|
|
|
|
|
2023-02-18 18:58:22 +02:00
|
|
|
std::shared_ptr<CIntObject> SettingsMainWindow::createTab(size_t index)
|
2023-01-30 21:18:59 +02:00
|
|
|
{
|
|
|
|
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 20:25:59 +02:00
|
|
|
return std::make_shared<AdventureOptionsTab>();
|
2023-01-30 23:15:37 +02:00
|
|
|
case 2:
|
2023-02-12 20:25:59 +02:00
|
|
|
return std::make_shared<BattleOptionsTab>(parentBattleInterface);
|
|
|
|
case 3:
|
2023-02-18 18:58:22 +02:00
|
|
|
return std::make_shared<OtherOptionsTab>();
|
2023-01-30 21:18:59 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2023-02-18 18:58:22 +02:00
|
|
|
void SettingsMainWindow::openTab(size_t index)
|
2023-01-30 23:15:37 +02:00
|
|
|
{
|
|
|
|
tabContentArea->setActive(index);
|
|
|
|
CIntObject::redraw();
|
|
|
|
|
|
|
|
Settings lastUsedTab = settings.write["general"]["lastSettingsTab"];
|
|
|
|
lastUsedTab->Integer() = index;
|
2023-01-31 00:26:33 +02:00
|
|
|
}
|
|
|
|
|
2023-02-18 18:58:22 +02:00
|
|
|
void SettingsMainWindow::close()
|
2023-01-31 00:26:33 +02:00
|
|
|
{
|
2023-05-16 17:34:23 +02:00
|
|
|
if(!GH.windows().isTopWindow(this))
|
2023-01-31 00:26:33 +02:00
|
|
|
logGlobal->error("Only top interface must be closed");
|
2023-05-16 15:20:35 +02:00
|
|
|
GH.windows().popWindows(1);
|
2023-01-31 00:26:33 +02:00
|
|
|
}
|
|
|
|
|
2023-02-18 18:58:22 +02:00
|
|
|
void SettingsMainWindow::quitGameButtonCallback()
|
2023-01-31 00:26:33 +02:00
|
|
|
{
|
2023-06-26 20:51:10 +02:00
|
|
|
LOCPLINT->showYesNoDialog(
|
|
|
|
CGI->generaltexth->allTexts[578],
|
|
|
|
[this]()
|
|
|
|
{
|
|
|
|
close();
|
|
|
|
GH.dispatchMainThread( []()
|
|
|
|
{
|
|
|
|
handleQuit(false);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
0
|
|
|
|
);
|
2023-01-31 00:26:33 +02:00
|
|
|
}
|
|
|
|
|
2023-02-18 18:58:22 +02:00
|
|
|
void SettingsMainWindow::backButtonCallback()
|
2023-01-31 00:26:33 +02:00
|
|
|
{
|
|
|
|
close();
|
|
|
|
}
|
|
|
|
|
2023-02-18 18:58:22 +02:00
|
|
|
void SettingsMainWindow::mainMenuButtonCallback()
|
2023-01-31 00:26:33 +02:00
|
|
|
{
|
2023-06-26 20:51:10 +02:00
|
|
|
LOCPLINT->showYesNoDialog(
|
|
|
|
CGI->generaltexth->allTexts[578],
|
|
|
|
[this]()
|
|
|
|
{
|
|
|
|
close();
|
|
|
|
GH.dispatchMainThread( []()
|
|
|
|
{
|
|
|
|
CSH->endGameplay();
|
|
|
|
GH.defActionsDef = 63;
|
|
|
|
CMM->menu->switchToTab("main");
|
|
|
|
});
|
|
|
|
},
|
|
|
|
0
|
|
|
|
);
|
2023-01-31 00:26:33 +02:00
|
|
|
}
|
|
|
|
|
2023-02-18 18:58:22 +02:00
|
|
|
void SettingsMainWindow::loadGameButtonCallback()
|
2023-01-31 00:26:33 +02:00
|
|
|
{
|
|
|
|
close();
|
|
|
|
LOCPLINT->proposeLoadingGame();
|
|
|
|
}
|
|
|
|
|
2023-02-18 18:58:22 +02:00
|
|
|
void SettingsMainWindow::saveGameButtonCallback()
|
2023-01-31 00:26:33 +02:00
|
|
|
{
|
|
|
|
close();
|
2023-05-16 15:20:35 +02:00
|
|
|
GH.windows().createAndPushWindow<CSavingScreen>();
|
2023-01-31 00:26:33 +02:00
|
|
|
}
|
|
|
|
|
2023-02-18 18:58:22 +02:00
|
|
|
void SettingsMainWindow::restartGameButtonCallback()
|
2023-01-31 00:26:33 +02:00
|
|
|
{
|
2023-06-26 20:51:10 +02:00
|
|
|
LOCPLINT->showYesNoDialog(
|
|
|
|
CGI->generaltexth->allTexts[67],
|
|
|
|
[this]()
|
|
|
|
{
|
|
|
|
close();
|
|
|
|
GH.dispatchMainThread([](){
|
|
|
|
CSH->sendRestartGame();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
0
|
|
|
|
);
|
2023-03-03 00:24:05 +02:00
|
|
|
}
|
|
|
|
|
2023-06-02 15:42:18 +02:00
|
|
|
void SettingsMainWindow::showAll(Canvas & to)
|
2023-03-03 00:24:05 +02:00
|
|
|
{
|
|
|
|
auto color = LOCPLINT ? LOCPLINT->playerID : PlayerColor(1);
|
|
|
|
if(settings["session"]["spectate"].Bool())
|
|
|
|
color = PlayerColor(1); // TODO: Spectator shouldn't need special code for UI colors
|
|
|
|
|
|
|
|
CIntObject::showAll(to);
|
2023-06-02 15:42:18 +02:00
|
|
|
CMessage::drawBorder(color, to.getInternalSurface(), pos.w+28, pos.h+29, pos.x-14, pos.y-15);
|
2023-03-03 00:24:05 +02:00
|
|
|
}
|
2023-05-19 22:54:43 +02:00
|
|
|
|
|
|
|
void SettingsMainWindow::onScreenResize()
|
|
|
|
{
|
|
|
|
InterfaceObjectConfigurable::onScreenResize();
|
|
|
|
|
|
|
|
auto tab = std::dynamic_pointer_cast<GeneralOptionsTab>(tabContentArea->getItem());
|
|
|
|
|
|
|
|
if (tab)
|
|
|
|
tab->updateResolutionSelector();
|
|
|
|
}
|