2023-02-02 18:17:16 +02:00
|
|
|
/*
|
2023-02-12 18:49:41 +02:00
|
|
|
* BattleOptionsTab.cpp, part of VCMI engine
|
2023-02-02 18:17:16 +02:00
|
|
|
*
|
|
|
|
* 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-12 18:49:41 +02:00
|
|
|
#include "BattleOptionsTab.h"
|
2023-02-02 18:17:16 +02:00
|
|
|
#include "CConfigHandler.h"
|
|
|
|
|
2023-02-18 17:35:07 +02:00
|
|
|
#include "../../battle/BattleInterface.h"
|
|
|
|
#include "../../gui/CGuiHandler.h"
|
2023-02-12 18:29:23 +02:00
|
|
|
#include "../../../lib/filesystem/ResourceID.h"
|
|
|
|
#include "../../../lib/CGeneralTextHandler.h"
|
|
|
|
#include "../../widgets/Buttons.h"
|
|
|
|
#include "../../widgets/TextControls.h"
|
2023-02-02 18:17:16 +02:00
|
|
|
|
2023-02-12 18:49:41 +02:00
|
|
|
BattleOptionsTab::BattleOptionsTab(BattleInterface * owner):
|
2023-02-02 18:17:16 +02:00
|
|
|
InterfaceObjectConfigurable()
|
|
|
|
{
|
|
|
|
OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
|
|
|
|
|
2023-02-12 18:49:41 +02:00
|
|
|
const JsonNode config(ResourceID("config/widgets/settings/battleOptionsTab.json"));
|
|
|
|
addCallback("viewGridChanged", std::bind(&BattleOptionsTab::viewGridChangedCallback, this, _1, owner));
|
|
|
|
addCallback("movementShadowChanged", std::bind(&BattleOptionsTab::movementShadowChangedCallback, this, _1, owner));
|
|
|
|
addCallback("mouseShadowChanged", std::bind(&BattleOptionsTab::mouseShadowChangedCallback, this, _1));
|
|
|
|
addCallback("animationSpeedChanged", std::bind(&BattleOptionsTab::animationSpeedChangedCallback, this, _1));
|
2023-02-15 23:38:41 +02:00
|
|
|
addCallback("showQueueChanged", std::bind(&BattleOptionsTab::showQueueChangedCallback, this, _1, owner));
|
2023-02-14 21:30:06 +02:00
|
|
|
addCallback("queueSizeChanged", std::bind(&BattleOptionsTab::queueSizeChangedCallback, this, _1));
|
2023-02-15 21:29:29 +02:00
|
|
|
addCallback("skipBattleIntroMusicChanged", std::bind(&BattleOptionsTab::skipBattleIntroMusicChangedCallback, this, _1));
|
2023-02-02 18:17:16 +02:00
|
|
|
build(config);
|
|
|
|
|
2023-02-12 14:51:57 +02:00
|
|
|
std::shared_ptr<CToggleGroup> animationSpeedToggle = widget<CToggleGroup>("animationSpeedPicker");
|
|
|
|
animationSpeedToggle->setSelected(getAnimSpeed());
|
|
|
|
|
2023-02-14 21:30:06 +02:00
|
|
|
std::shared_ptr<CToggleGroup> queueSizeToggle = widget<CToggleGroup>("queueSizePicker");
|
|
|
|
queueSizeToggle->setSelected(getQueueSizeId());
|
2023-02-12 14:51:57 +02:00
|
|
|
|
|
|
|
std::shared_ptr<CToggleButton> viewGridCheckbox = widget<CToggleButton>("viewGridCheckbox");
|
|
|
|
viewGridCheckbox->setSelected((bool)settings["battle"]["cellBorders"].Bool());
|
|
|
|
|
|
|
|
std::shared_ptr<CToggleButton> movementShadowCheckbox = widget<CToggleButton>("movementShadowCheckbox");
|
|
|
|
movementShadowCheckbox->setSelected((bool)settings["battle"]["stackRange"].Bool());
|
|
|
|
|
|
|
|
std::shared_ptr<CToggleButton> mouseShadowCheckbox = widget<CToggleButton>("mouseShadowCheckbox");
|
|
|
|
mouseShadowCheckbox->setSelected((bool)settings["battle"]["mouseShadow"].Bool());
|
2023-02-14 21:30:06 +02:00
|
|
|
|
|
|
|
std::shared_ptr<CToggleButton> showQueueCheckbox = widget<CToggleButton>("showQueueCheckbox");
|
|
|
|
showQueueCheckbox->setSelected((bool)settings["battle"]["showQueue"].Bool());
|
2023-02-15 21:29:29 +02:00
|
|
|
|
|
|
|
std::shared_ptr<CToggleButton> skipBattleIntroMusicCheckbox = widget<CToggleButton>("skipBattleIntroMusicCheckbox");
|
|
|
|
skipBattleIntroMusicCheckbox->setSelected((bool)settings["gameTweaks"]["skipBattleIntroMusic"].Bool());
|
2023-02-02 18:17:16 +02:00
|
|
|
}
|
|
|
|
|
2023-02-12 18:49:41 +02:00
|
|
|
int BattleOptionsTab::getAnimSpeed() const
|
2023-02-02 18:17:16 +02:00
|
|
|
{
|
|
|
|
if(settings["session"]["spectate"].Bool() && !settings["session"]["spectate-battle-speed"].isNull())
|
2023-02-12 12:55:21 +02:00
|
|
|
return static_cast<int>(std::round(settings["session"]["spectate-battle-speed"].Float()));
|
2023-02-02 18:17:16 +02:00
|
|
|
|
2023-02-12 12:55:21 +02:00
|
|
|
return static_cast<int>(std::round(settings["battle"]["speedFactor"].Float()));
|
2023-02-12 14:51:57 +02:00
|
|
|
}
|
|
|
|
|
2023-02-14 21:30:06 +02:00
|
|
|
int BattleOptionsTab::getQueueSizeId() const
|
|
|
|
{
|
|
|
|
std::string text = settings["battle"]["queueSize"].String();
|
|
|
|
if(text == "auto")
|
|
|
|
return 0;
|
|
|
|
else if(text == "small")
|
|
|
|
return 1;
|
|
|
|
else if(text == "big")
|
|
|
|
return 2;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string BattleOptionsTab::getQueueSizeStringFromId(int value) const
|
|
|
|
{
|
|
|
|
switch(value)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
return "auto";
|
|
|
|
case 1:
|
|
|
|
return "small";
|
|
|
|
case 2:
|
|
|
|
return "big";
|
|
|
|
default:
|
|
|
|
return "auto";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-12 18:49:41 +02:00
|
|
|
void BattleOptionsTab::viewGridChangedCallback(bool value, BattleInterface * parentBattleInterface)
|
2023-02-12 14:51:57 +02:00
|
|
|
{
|
|
|
|
Settings cellBorders = settings.write["battle"]["cellBorders"];
|
|
|
|
cellBorders->Bool() = value;
|
|
|
|
if(parentBattleInterface)
|
|
|
|
parentBattleInterface->redrawBattlefield();
|
|
|
|
}
|
|
|
|
|
2023-02-12 18:49:41 +02:00
|
|
|
void BattleOptionsTab::movementShadowChangedCallback(bool value, BattleInterface * parentBattleInterface)
|
2023-02-12 14:51:57 +02:00
|
|
|
{
|
|
|
|
Settings stackRange = settings.write["battle"]["stackRange"];
|
|
|
|
stackRange->Bool() = value;
|
|
|
|
if(parentBattleInterface)
|
|
|
|
parentBattleInterface->redrawBattlefield();
|
|
|
|
}
|
|
|
|
|
2023-02-12 18:49:41 +02:00
|
|
|
void BattleOptionsTab::mouseShadowChangedCallback(bool value)
|
2023-02-12 14:51:57 +02:00
|
|
|
{
|
|
|
|
Settings shadow = settings.write["battle"]["mouseShadow"];
|
|
|
|
shadow->Bool() = value;
|
|
|
|
}
|
|
|
|
|
2023-02-12 18:49:41 +02:00
|
|
|
void BattleOptionsTab::animationSpeedChangedCallback(int value)
|
2023-02-12 14:51:57 +02:00
|
|
|
{
|
|
|
|
Settings speed = settings.write["battle"]["speedFactor"];
|
|
|
|
speed->Float() = float(value);
|
|
|
|
}
|
|
|
|
|
2023-02-15 23:38:41 +02:00
|
|
|
void BattleOptionsTab::showQueueChangedCallback(bool value, BattleInterface * parentBattleInterface)
|
2023-02-14 21:30:06 +02:00
|
|
|
{
|
2023-02-15 23:38:41 +02:00
|
|
|
if(!parentBattleInterface)
|
|
|
|
{
|
|
|
|
Settings showQueue = settings.write["battle"]["showQueue"];
|
|
|
|
showQueue->Bool() = value;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
parentBattleInterface->setBattleQueueVisibility(value);
|
|
|
|
}
|
2023-02-14 21:30:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void BattleOptionsTab::queueSizeChangedCallback(int value)
|
|
|
|
{
|
|
|
|
std::string stringifiedValue = getQueueSizeStringFromId(value);
|
|
|
|
Settings size = settings.write["battle"]["queueSize"];
|
|
|
|
size->String() = stringifiedValue;
|
|
|
|
}
|
|
|
|
|
2023-02-15 21:29:29 +02:00
|
|
|
void BattleOptionsTab::skipBattleIntroMusicChangedCallback(bool value)
|
|
|
|
{
|
|
|
|
Settings musicSkipSettingValue = settings.write["gameTweaks"]["skipBattleIntroMusic"];
|
|
|
|
musicSkipSettingValue->Bool() = value;
|
|
|
|
}
|
|
|
|
|