1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00
vcmi/client/windows/settings/BattleOptionsTab.cpp

283 lines
9.1 KiB
C++
Raw Normal View History

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
2023-02-18 17:35:07 +02:00
#include "../../battle/BattleInterface.h"
#include "../../gui/CGuiHandler.h"
#include "../../../lib/CConfigHandler.h"
#include "../../../lib/filesystem/ResourcePath.h"
#include "../../../lib/texts/CGeneralTextHandler.h"
2023-02-12 18:29:23 +02:00
#include "../../widgets/Buttons.h"
#include "../../widgets/TextControls.h"
2023-02-02 18:17:16 +02:00
BattleOptionsTab::BattleOptionsTab(BattleInterface * owner)
2023-02-02 18:17:16 +02:00
{
OBJECT_CONSTRUCTION;
setRedrawParent(true);
2023-02-02 18:17:16 +02:00
const JsonNode config(JsonPath::builtin("config/widgets/settings/battleOptionsTab.json"));
2023-02-18 18:49:43 +02:00
addCallback("viewGridChanged", [this, owner](bool value)
{
viewGridChangedCallback(value, owner);
});
addCallback("movementShadowChanged", [this, owner](bool value)
{
movementShadowChangedCallback(value, owner);
});
addCallback("movementHighlightOnHoverChanged", [this, owner](bool value)
{
movementHighlightOnHoverChangedCallback(value, owner);
});
addCallback("rangeLimitHighlightOnHoverChanged", [this, owner](bool value)
2023-05-14 20:07:47 +02:00
{
rangeLimitHighlightOnHoverChangedCallback(value, owner);
2023-05-14 20:07:47 +02:00
});
2023-02-18 18:49:43 +02:00
addCallback("mouseShadowChanged", [this](bool value)
{
mouseShadowChangedCallback(value);
});
addCallback("animationSpeedChanged", [this](int value)
{
animationSpeedChangedCallback(value);
});
addCallback("showQueueChanged", [this, owner](bool value)
{
showQueueChangedCallback(value, owner);
});
addCallback("queueSizeChanged", [this, owner](int value)
2023-02-18 18:49:43 +02:00
{
queueSizeChangedCallback(value, owner);
2023-02-18 18:49:43 +02:00
});
addCallback("skipBattleIntroMusicChanged", [this](bool value)
{
skipBattleIntroMusicChangedCallback(value);
});
addCallback("showStickyHeroWindowsChanged", [this, owner](bool value)
{
showStickyHeroWindowsChangedCallback(value, owner);
});
2024-07-19 19:43:22 +02:00
addCallback("showQuickSpellChanged", [this, owner](bool value)
{
showQuickSpellChangedCallback(value, owner);
});
addCallback("enableAutocombatSpellsChanged", [this](bool value)
{
enableAutocombatSpellsChangedCallback(value);
});
2024-01-27 02:16:55 +02:00
addCallback("endWithAutocombatChanged", [this](bool value)
{
endWithAutocombatChangedCallback(value);
});
2023-02-02 18:17:16 +02:00
build(config);
std::shared_ptr<CToggleGroup> animationSpeedToggle = widget<CToggleGroup>("animationSpeedPicker");
animationSpeedToggle->setSelected(getAnimSpeed());
std::shared_ptr<CToggleGroup> queueSizeToggle = widget<CToggleGroup>("queueSizePicker");
queueSizeToggle->setSelected(getQueueSizeId());
std::shared_ptr<CToggleButton> viewGridCheckbox = widget<CToggleButton>("viewGridCheckbox");
2023-02-18 18:49:43 +02:00
viewGridCheckbox->setSelected(settings["battle"]["cellBorders"].Bool());
std::shared_ptr<CToggleButton> movementShadowCheckbox = widget<CToggleButton>("movementShadowCheckbox");
2023-02-18 18:49:43 +02:00
movementShadowCheckbox->setSelected(settings["battle"]["stackRange"].Bool());
std::shared_ptr<CToggleButton> movementHighlightOnHoverCheckbox = widget<CToggleButton>("movementHighlightOnHoverCheckbox");
movementHighlightOnHoverCheckbox->setSelected(settings["battle"]["movementHighlightOnHover"].Bool());
std::shared_ptr<CToggleButton> rangeLimitHighlightOnHoverCheckbox = widget<CToggleButton>("rangeLimitHighlightOnHoverCheckbox");
rangeLimitHighlightOnHoverCheckbox->setSelected(settings["battle"]["rangeLimitHighlightOnHover"].Bool());
2023-05-14 20:07:47 +02:00
std::shared_ptr<CToggleButton> showStickyHeroInfoWindowsCheckbox = widget<CToggleButton>("showStickyHeroInfoWindowsCheckbox");
showStickyHeroInfoWindowsCheckbox->setSelected(settings["battle"]["stickyHeroInfoWindows"].Bool());
2024-07-19 19:43:22 +02:00
std::shared_ptr<CToggleButton> showQuickSpellCheckbox = widget<CToggleButton>("showQuickSpellCheckbox");
showQuickSpellCheckbox->setSelected(settings["battle"]["enableQuickSpellPanel"].Bool());
std::shared_ptr<CToggleButton> mouseShadowCheckbox = widget<CToggleButton>("mouseShadowCheckbox");
2023-02-18 18:49:43 +02:00
mouseShadowCheckbox->setSelected(settings["battle"]["mouseShadow"].Bool());
std::shared_ptr<CToggleButton> skipBattleIntroMusicCheckbox = widget<CToggleButton>("skipBattleIntroMusicCheckbox");
2023-02-18 18:49:43 +02:00
skipBattleIntroMusicCheckbox->setSelected(settings["gameTweaks"]["skipBattleIntroMusic"].Bool());
std::shared_ptr<CToggleButton> enableAutocombatSpellsCheckbox = widget<CToggleButton>("enableAutocombatSpellsCheckbox");
enableAutocombatSpellsCheckbox->setSelected(settings["battle"]["enableAutocombatSpells"].Bool());
2024-01-27 02:16:55 +02:00
std::shared_ptr<CToggleButton> endWithAutocombatCheckbox = widget<CToggleButton>("endWithAutocombatCheckbox");
endWithAutocombatCheckbox->setSelected(settings["battle"]["endWithAutocombat"].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())
return static_cast<int>(std::round(settings["session"]["spectate-battle-speed"].Float()));
2023-02-02 18:17:16 +02:00
return static_cast<int>(std::round(settings["battle"]["speedFactor"].Float()));
}
int BattleOptionsTab::getQueueSizeId() const
{
std::string sizeText = settings["battle"]["queueSize"].String();
bool visible = settings["battle"]["showQueue"].Bool();
if(!visible)
return -1;
if(sizeText == "none")
return -1;
if(sizeText == "auto")
return 0;
if(sizeText == "small")
return 1;
if(sizeText == "big")
return 2;
return 0;
}
std::string BattleOptionsTab::getQueueSizeStringFromId(int value) const
{
switch(value)
{
case -1:
return "none";
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)
{
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)
{
Settings stackRange = settings.write["battle"]["stackRange"];
stackRange->Bool() = value;
if(parentBattleInterface)
parentBattleInterface->redrawBattlefield();
}
void BattleOptionsTab::movementHighlightOnHoverChangedCallback(bool value, BattleInterface * parentBattleInterface)
{
Settings stackRange = settings.write["battle"]["movementHighlightOnHover"];
stackRange->Bool() = value;
if(parentBattleInterface)
parentBattleInterface->redrawBattlefield();
}
void BattleOptionsTab::rangeLimitHighlightOnHoverChangedCallback(bool value, BattleInterface * parentBattleInterface)
2023-05-14 20:07:47 +02:00
{
Settings stackRange = settings.write["battle"]["rangeLimitHighlightOnHover"];
2023-05-14 20:07:47 +02:00
stackRange->Bool() = value;
if(parentBattleInterface)
parentBattleInterface->redrawBattlefield();
}
2023-02-12 18:49:41 +02:00
void BattleOptionsTab::mouseShadowChangedCallback(bool value)
{
Settings shadow = settings.write["battle"]["mouseShadow"];
shadow->Bool() = value;
}
2023-02-12 18:49:41 +02:00
void BattleOptionsTab::animationSpeedChangedCallback(int value)
{
Settings speed = settings.write["battle"]["speedFactor"];
2023-02-18 18:49:43 +02:00
speed->Float() = static_cast<float>(value);
auto targetLabel = widget<CLabel>("animationSpeedValueLabel");
int valuePercentage = value * 100 / 3; // H3 max value is "3", displaying it to be 100%
if (targetLabel)
targetLabel->setText(std::to_string(valuePercentage) + "%");
}
2023-02-15 23:38:41 +02:00
void BattleOptionsTab::showQueueChangedCallback(bool value, BattleInterface * parentBattleInterface)
{
2023-02-15 23:38:41 +02:00
if(!parentBattleInterface)
{
Settings showQueue = settings.write["battle"]["showQueue"];
showQueue->Bool() = value;
}
else
{
parentBattleInterface->setBattleQueueVisibility(value);
}
}
void BattleOptionsTab::showStickyHeroWindowsChangedCallback(bool value, BattleInterface * parentBattleInterface)
{
if(!parentBattleInterface)
{
Settings showStickyWindows = settings.write["battle"]["stickyHeroInfoWindows"];
showStickyWindows->Bool() = value;
}
else
{
parentBattleInterface->setStickyHeroWindowsVisibility(value);
2024-07-19 19:43:22 +02:00
}
}
void BattleOptionsTab::showQuickSpellChangedCallback(bool value, BattleInterface * parentBattleInterface)
{
if(!parentBattleInterface)
{
Settings showQuickSpell = settings.write["battle"]["enableQuickSpellPanel"];
showQuickSpell->Bool() = value;
}
else
{
parentBattleInterface->setStickyQuickSpellWindowVisibility(value);
}
}
void BattleOptionsTab::queueSizeChangedCallback(int value, BattleInterface * parentBattleInterface)
{
if (value == -1)
{
showQueueChangedCallback(false, parentBattleInterface);
return;
}
std::string stringifiedValue = getQueueSizeStringFromId(value);
Settings size = settings.write["battle"]["queueSize"];
size->String() = stringifiedValue;
showQueueChangedCallback(true, parentBattleInterface);
}
void BattleOptionsTab::skipBattleIntroMusicChangedCallback(bool value)
{
Settings musicSkipSettingValue = settings.write["gameTweaks"]["skipBattleIntroMusic"];
musicSkipSettingValue->Bool() = value;
}
void BattleOptionsTab::enableAutocombatSpellsChangedCallback(bool value)
{
Settings enableAutocombatSpells = settings.write["battle"]["enableAutocombatSpells"];
enableAutocombatSpells->Bool() = value;
}
2024-01-27 02:16:55 +02:00
void BattleOptionsTab::endWithAutocombatChangedCallback(bool value)
{
Settings endWithAutocombat = settings.write["battle"]["endWithAutocombat"];
endWithAutocombat->Bool() = value;
}