/* * AdventureOptionsTab.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" #include "AdventureOptionsTab.h" #include "../../../lib/filesystem/ResourcePath.h" #include "../../gui/CGuiHandler.h" #include "../../widgets/Buttons.h" #include "../../widgets/TextControls.h" #include "../../widgets/Images.h" #include "CConfigHandler.h" static void setBoolSetting(std::string group, std::string field, bool value) { Settings fullscreen = settings.write[group][field]; fullscreen->Bool() = value; } static void setIntSetting(std::string group, std::string field, int value) { Settings entry = settings.write[group][field]; entry->Float() = value; } AdventureOptionsTab::AdventureOptionsTab() : InterfaceObjectConfigurable() { OBJECT_CONSTRUCTION; setRedrawParent(true); #ifdef VCMI_MOBILE addConditional("mobile", true); addConditional("desktop", false); #else addConditional("mobile", false); addConditional("desktop", true); #endif const JsonNode config(JsonPath::builtin("config/widgets/settings/adventureOptionsTab.json")); addCallback("playerHeroSpeedChanged", [this](int value) { auto targetLabel = widget("heroSpeedValueLabel"); if (targetLabel) { if (value <= 0) { targetLabel->setText("-"); } else { int valuePercentage = 100 * 100 / value; targetLabel->setText(std::to_string(valuePercentage) + "%"); } } setIntSetting("adventure", "heroMoveTime", value); }); addCallback("enemyHeroSpeedChanged", [this](int value) { auto targetLabel = widget("enemySpeedValueLabel"); if (targetLabel) { if (value <= 0) { targetLabel->setText("-"); } else { int valuePercentage = 100 * 100 / value; targetLabel->setText(std::to_string(valuePercentage) + "%"); } } setIntSetting("adventure", "enemyMoveTime", value); }); addCallback("mapScrollSpeedChanged", [this](int value) { auto targetLabel = widget("mapScrollingValueLabel"); int valuePercentage = 100 * value / 1200; // H3 max value is "1200", displaying it to be 100% if (targetLabel) targetLabel->setText(std::to_string(valuePercentage) + "%"); return setIntSetting("adventure", "scrollSpeedPixels", value); }); addCallback("heroReminderChanged", [](bool value) { return setBoolSetting("adventure", "heroReminder", value); }); addCallback("quickCombatChanged", [](bool value) { return setBoolSetting("adventure", "quickCombat", value); }); //settings that do not belong to base game: addCallback("numericQuantitiesChanged", [](bool value) { return setBoolSetting("gameTweaks", "numericCreaturesQuantities", value); }); addCallback("forceMovementInfoChanged", [](bool value) { return setBoolSetting("gameTweaks", "forceMovementInfo", value); }); addCallback("showGridChanged", [](bool value) { return setBoolSetting("gameTweaks", "showGrid", value); }); addCallback("infoBarPickChanged", [](bool value) { return setBoolSetting("gameTweaks", "infoBarPick", value); }); addCallback("borderScrollChanged", [](bool value) { return setBoolSetting("adventure", "borderScroll", value); }); addCallback("infoBarCreatureManagementChanged", [](bool value) { return setBoolSetting("gameTweaks", "infoBarCreatureManagement", value); }); addCallback("leftButtonDragChanged", [](bool value) { return setBoolSetting("adventure", "leftButtonDrag", value); }); addCallback("smoothDraggingChanged", [](bool value) { return setBoolSetting("adventure", "smoothDragging", value); }); addCallback("skipAdventureMapAnimationsChanged", [](bool value) { return setBoolSetting("gameTweaks", "skipAdventureMapAnimations", value); }); addCallback("hideBackgroundChanged", [](bool value) { return setBoolSetting("adventure", "hideBackground", value); }); build(config); std::shared_ptr playerHeroSpeedToggle = widget("heroMovementSpeedPicker"); playerHeroSpeedToggle->setSelected(static_cast(settings["adventure"]["heroMoveTime"].Float())); std::shared_ptr enemyHeroSpeedToggle = widget("enemyMovementSpeedPicker"); enemyHeroSpeedToggle->setSelected(static_cast(settings["adventure"]["enemyMoveTime"].Float())); std::shared_ptr mapScrollSpeedToggle = widget("mapScrollSpeedPicker"); mapScrollSpeedToggle->setSelected(static_cast(settings["adventure"]["scrollSpeedPixels"].Float())); std::shared_ptr heroReminderCheckbox = widget("heroReminderCheckbox"); heroReminderCheckbox->setSelected(settings["adventure"]["heroReminder"].Bool()); std::shared_ptr quickCombatCheckbox = widget("quickCombatCheckbox"); quickCombatCheckbox->setSelected(settings["adventure"]["quickCombat"].Bool()); std::shared_ptr numericQuantitiesCheckbox = widget("numericQuantitiesCheckbox"); numericQuantitiesCheckbox->setSelected(settings["gameTweaks"]["numericCreaturesQuantities"].Bool()); std::shared_ptr forceMovementInfoCheckbox = widget("forceMovementInfoCheckbox"); forceMovementInfoCheckbox->setSelected(settings["gameTweaks"]["forceMovementInfo"].Bool()); std::shared_ptr showGridCheckbox = widget("showGridCheckbox"); showGridCheckbox->setSelected(settings["gameTweaks"]["showGrid"].Bool()); std::shared_ptr infoBarPickCheckbox = widget("infoBarPickCheckbox"); infoBarPickCheckbox->setSelected(settings["gameTweaks"]["infoBarPick"].Bool()); std::shared_ptr borderScrollCheckbox = widget("borderScrollCheckbox"); borderScrollCheckbox->setSelected(settings["adventure"]["borderScroll"].Bool()); std::shared_ptr infoBarCreatureManagementCheckbox = widget("infoBarCreatureManagementCheckbox"); infoBarCreatureManagementCheckbox->setSelected(settings["gameTweaks"]["infoBarCreatureManagement"].Bool()); std::shared_ptr leftButtonDragCheckbox = widget("leftButtonDragCheckbox"); if (leftButtonDragCheckbox) leftButtonDragCheckbox->setSelected(settings["adventure"]["leftButtonDrag"].Bool()); std::shared_ptr smoothDraggingCheckbox = widget("smoothDraggingCheckbox"); if (smoothDraggingCheckbox) smoothDraggingCheckbox->setSelected(settings["adventure"]["smoothDragging"].Bool()); std::shared_ptr skipAdventureMapAnimationsCheckbox = widget("skipAdventureMapAnimationsCheckbox"); skipAdventureMapAnimationsCheckbox->setSelected(settings["gameTweaks"]["skipAdventureMapAnimations"].Bool()); std::shared_ptr hideBackgroundCheckbox = widget("hideBackgroundCheckbox"); hideBackgroundCheckbox->setSelected(settings["adventure"]["hideBackground"].Bool()); }