From a2fd5039ab3a6d18c678887af5de78ced58df836 Mon Sep 17 00:00:00 2001 From: Laserlicht <13953785+Laserlicht@users.noreply.github.com> Date: Sat, 27 Jan 2024 01:16:55 +0100 Subject: [PATCH] setting --- Mods/vcmi/config/vcmi/english.json | 6 ++++-- Mods/vcmi/config/vcmi/german.json | 2 ++ client/battle/BattleWindow.cpp | 13 +++++++++++-- client/windows/settings/BattleOptionsTab.cpp | 12 ++++++++++++ client/windows/settings/BattleOptionsTab.h | 1 + config/schemas/settings.json | 6 +++++- config/widgets/settings/battleOptionsTab.json | 17 +++++++++++++++++ 7 files changed, 52 insertions(+), 5 deletions(-) diff --git a/Mods/vcmi/config/vcmi/english.json b/Mods/vcmi/config/vcmi/english.json index 3342a2cfc..c1fab0772 100644 --- a/Mods/vcmi/config/vcmi/english.json +++ b/Mods/vcmi/config/vcmi/english.json @@ -171,8 +171,10 @@ "vcmi.battleOptions.showStickyHeroInfoWindows.hover": "Show heroes statistics windows", "vcmi.battleOptions.showStickyHeroInfoWindows.help": "{Show heroes statistics windows}\n\nPermanently toggle on heroes statistics windows that show primary stats and spell points.", "vcmi.battleOptions.skipBattleIntroMusic.hover": "Skip Intro Music", - "vcmi.battleOptions.skipBattleIntroMusic.help": "{Skip Intro Music}\n\nAllow actions during the intro music that plays at the beginning of each battle.", - + "vcmi.battleOptions.skipBattleIntroMusic.help": "{Skip Intro Music}\n\nAllow actions during the intro music that plays at the beginning of each battle.", + "vcmi.battleOptions.endWithAutocombat.hover": "Ends battle", + "vcmi.battleOptions.endWithAutocombat.help": "{Ends battle}\n\nAuto-Combat plays battle to end instant", + "vcmi.adventureMap.revisitObject.hover" : "Revisit Object", "vcmi.adventureMap.revisitObject.help" : "{Revisit Object}\n\nIf a hero currently stands on a Map Object, he can revisit the location.", diff --git a/Mods/vcmi/config/vcmi/german.json b/Mods/vcmi/config/vcmi/german.json index 8a50c204b..f769eb9d9 100644 --- a/Mods/vcmi/config/vcmi/german.json +++ b/Mods/vcmi/config/vcmi/german.json @@ -171,6 +171,8 @@ "vcmi.battleOptions.showStickyHeroInfoWindows.help": "{Statistikfenster für Helden anzeigen}\n\nDauerhaftes Einschalten des Statistikfenster für Helden, das die primären Werte und Zauberpunkte anzeigt.", "vcmi.battleOptions.skipBattleIntroMusic.hover": "Intro-Musik überspringen", "vcmi.battleOptions.skipBattleIntroMusic.help": "{Intro-Musik überspringen}\n\n Überspringe die kurze Musik, die zu Beginn eines jeden Kampfes gespielt wird, bevor die Action beginnt. Kann auch durch Drücken der ESC-Taste übersprungen werden.", + "vcmi.battleOptions.endWithAutocombat.hover": "Kampf beenden", + "vcmi.battleOptions.endWithAutocombat.help": "{Kampf beenden}\n\nAutokampf spielt den Kampf sofort zu Ende", "vcmi.adventureMap.revisitObject.hover" : "Objekt erneut besuchen", "vcmi.adventureMap.revisitObject.help" : "{Objekt erneut besuchen}\n\nSteht ein Held gerade auf einem Kartenobjekt, kann er den Ort erneut aufsuchen.", diff --git a/client/battle/BattleWindow.cpp b/client/battle/BattleWindow.cpp index 0b9cbb78c..eb95593be 100644 --- a/client/battle/BattleWindow.cpp +++ b/client/battle/BattleWindow.cpp @@ -552,6 +552,12 @@ void BattleWindow::bAutofightf() if (owner.actionsController->spellcastingModeActive()) return; + if(settings["battle"]["endWithAutocombat"].Bool()) + { + endWithAutocombat(); + return; + } + //Stop auto-fight mode if(owner.curInt->isAutoFightOn) { @@ -722,7 +728,7 @@ void BattleWindow::blockUI(bool on) setShortcutBlocked(EShortcut::BATTLE_WAIT, on || owner.tacticsMode || !canWait); setShortcutBlocked(EShortcut::BATTLE_DEFEND, on || owner.tacticsMode); setShortcutBlocked(EShortcut::BATTLE_SELECT_ACTION, on || owner.tacticsMode); - setShortcutBlocked(EShortcut::BATTLE_AUTOCOMBAT, owner.actionsController->spellcastingModeActive()); + setShortcutBlocked(EShortcut::BATTLE_AUTOCOMBAT, settings["battle"]["endWithAutocombat"].Bool() ? on || owner.tacticsMode : owner.actionsController->spellcastingModeActive()); setShortcutBlocked(EShortcut::BATTLE_END_WITH_AUTOCOMBAT, on || owner.tacticsMode); setShortcutBlocked(EShortcut::BATTLE_TACTICS_END, on && owner.tacticsMode); setShortcutBlocked(EShortcut::BATTLE_TACTICS_NEXT, on && owner.tacticsMode); @@ -737,7 +743,8 @@ std::optional BattleWindow::getQueueHoveredUnitId() void BattleWindow::endWithAutocombat() { - close(); + if(!owner.makingTurn() || owner.tacticsMode) + return; auto ai = CDynLibHandler::getNewBattleAI(settings["server"]["friendlyAI"].String()); @@ -753,6 +760,8 @@ void BattleWindow::endWithAutocombat() owner.requestAutofightingAIToTakeAction(); + close(); + owner.curInt->battleInt.reset(); } diff --git a/client/windows/settings/BattleOptionsTab.cpp b/client/windows/settings/BattleOptionsTab.cpp index 35abf73cb..7c803614e 100644 --- a/client/windows/settings/BattleOptionsTab.cpp +++ b/client/windows/settings/BattleOptionsTab.cpp @@ -68,6 +68,10 @@ BattleOptionsTab::BattleOptionsTab(BattleInterface * owner) { enableAutocombatSpellsChangedCallback(value); }); + addCallback("endWithAutocombatChanged", [this](bool value) + { + endWithAutocombatChangedCallback(value); + }); build(config); std::shared_ptr animationSpeedToggle = widget("animationSpeedPicker"); @@ -99,6 +103,9 @@ BattleOptionsTab::BattleOptionsTab(BattleInterface * owner) std::shared_ptr enableAutocombatSpellsCheckbox = widget("enableAutocombatSpellsCheckbox"); enableAutocombatSpellsCheckbox->setSelected(settings["battle"]["enableAutocombatSpells"].Bool()); + + std::shared_ptr endWithAutocombatCheckbox = widget("endWithAutocombatCheckbox"); + endWithAutocombatCheckbox->setSelected(settings["battle"]["endWithAutocombat"].Bool()); } int BattleOptionsTab::getAnimSpeed() const @@ -248,3 +255,8 @@ void BattleOptionsTab::enableAutocombatSpellsChangedCallback(bool value) enableAutocombatSpells->Bool() = value; } +void BattleOptionsTab::endWithAutocombatChangedCallback(bool value) +{ + Settings endWithAutocombat = settings.write["battle"]["endWithAutocombat"]; + endWithAutocombat->Bool() = value; +} diff --git a/client/windows/settings/BattleOptionsTab.h b/client/windows/settings/BattleOptionsTab.h index 43d4d7e50..633726b2c 100644 --- a/client/windows/settings/BattleOptionsTab.h +++ b/client/windows/settings/BattleOptionsTab.h @@ -33,6 +33,7 @@ private: void skipBattleIntroMusicChangedCallback(bool value); void showStickyHeroWindowsChangedCallback(bool value, BattleInterface * parentBattleInterface); void enableAutocombatSpellsChangedCallback(bool value); + void endWithAutocombatChangedCallback(bool value); public: BattleOptionsTab(BattleInterface * owner = nullptr); }; diff --git a/config/schemas/settings.json b/config/schemas/settings.json index 48c3e1211..022cf10ab 100644 --- a/config/schemas/settings.json +++ b/config/schemas/settings.json @@ -304,7 +304,7 @@ "type" : "object", "additionalProperties" : false, "default" : {}, - "required" : [ "speedFactor", "mouseShadow", "cellBorders", "stackRange", "movementHighlightOnHover", "rangeLimitHighlightOnHover", "showQueue", "swipeAttackDistance", "queueSize", "stickyHeroInfoWindows", "enableAutocombatSpells" ], + "required" : [ "speedFactor", "mouseShadow", "cellBorders", "stackRange", "movementHighlightOnHover", "rangeLimitHighlightOnHover", "showQueue", "swipeAttackDistance", "queueSize", "stickyHeroInfoWindows", "enableAutocombatSpells", "endWithAutocombat" ], "properties" : { "speedFactor" : { "type" : "number", @@ -350,6 +350,10 @@ "enableAutocombatSpells" : { "type": "boolean", "default": true + }, + "endWithAutocombat" : { + "type": "boolean", + "default": false } } }, diff --git a/config/widgets/settings/battleOptionsTab.json b/config/widgets/settings/battleOptionsTab.json index 3b5df7a76..4db262212 100644 --- a/config/widgets/settings/battleOptionsTab.json +++ b/config/widgets/settings/battleOptionsTab.json @@ -47,6 +47,9 @@ }, { "text": "core.genrltxt.401" // First Aid Tent + }, + { + "text": "vcmi.battleOptions.endWithAutocombat.hover" } ] }, @@ -86,6 +89,20 @@ {} ] }, + + { + "type" : "verticalLayout", + "customType" : "checkbox", + "position": {"x": 380, "y": 233}, + "items": + [ + { + "help": "vcmi.battleOptions.endWithAutocombat", + "name": "endWithAutocombatCheckbox", + "callback": "endWithAutocombatChanged" + } + ] + }, /////////////////////////////////////// Left section - checkboxes { "name": "creatureInfoLabels",