From 7d9c2125433d6f9c69749c750315a80f755c5713 Mon Sep 17 00:00:00 2001 From: nick huang Date: Wed, 23 Oct 2024 13:23:55 +0800 Subject: [PATCH] save before each battle. The launcher UI adds 'Save before battle' by replacing original 'Network port' button because insertion new button meaning to move all row index by 1. Also 'network port' seems fitting to be category of 'Network' which is near end of all buttons and it saves a lot modifications. --- config/schemas/settings.json | 7 +++- launcher/settingsView/csettingsview_moc.cpp | 9 +++++ launcher/settingsView/csettingsview_moc.h | 1 + launcher/settingsView/csettingsview_moc.ui | 37 +++++++++++++++++---- launcher/translation/chinese.ts | 5 +++ server/CGameHandler.cpp | 11 ++++++ 6 files changed, 62 insertions(+), 8 deletions(-) diff --git a/config/schemas/settings.json b/config/schemas/settings.json index 93ae2038f..aae7e641a 100644 --- a/config/schemas/settings.json +++ b/config/schemas/settings.json @@ -42,7 +42,8 @@ "savePrefix", "startTurnAutosave", "enableUiEnhancements", - "audioMuteFocus" + "audioMuteFocus", + "saveBeforeBattle" ], "properties" : { "playerName" : { @@ -146,6 +147,10 @@ "audioMuteFocus" : { "type": "boolean", "default": false + }, + "saveBeforeBattle" : { + "type": "boolean", + "default": false } } }, diff --git a/launcher/settingsView/csettingsview_moc.cpp b/launcher/settingsView/csettingsview_moc.cpp index 94ca8fc6c..130f325ec 100644 --- a/launcher/settingsView/csettingsview_moc.cpp +++ b/launcher/settingsView/csettingsview_moc.cpp @@ -214,6 +214,8 @@ void CSettingsView::loadToggleButtonSettings() setCheckbuttonState(ui->buttonRelativeCursorMode, settings["general"]["userRelativePointer"].Bool()); setCheckbuttonState(ui->buttonHapticFeedback, settings["general"]["hapticFeedback"].Bool()); + setCheckbuttonState(ui->buttonSaveBeforeBattle, settings["general"]["saveBeforeBattle"].Bool()); + std::string cursorType = settings["video"]["cursor"].String(); int cursorTypeIndex = vstd::find_pos(cursorTypesList, cursorType); setCheckbuttonState(ui->buttonCursorType, cursorTypeIndex); @@ -472,6 +474,13 @@ void CSettingsView::on_buttonAutoSave_toggled(bool value) updateCheckbuttonText(ui->buttonAutoSave); } +void CSettingsView::on_buttonSaveBeforeBattle_toggled(bool value) +{ + Settings node = settings.write["general"]["saveBeforeBattle"]; + node->Bool() = value; + updateCheckbuttonText(ui->buttonSaveBeforeBattle); +} + void CSettingsView::on_comboBoxLanguage_currentIndexChanged(int index) { Settings node = settings.write["general"]["language"]; diff --git a/launcher/settingsView/csettingsview_moc.h b/launcher/settingsView/csettingsview_moc.h index d05e7eb1e..af52c8c7c 100644 --- a/launcher/settingsView/csettingsview_moc.h +++ b/launcher/settingsView/csettingsview_moc.h @@ -50,6 +50,7 @@ private slots: void on_buttonAutoCheck_toggled(bool value); void on_comboBoxDisplayIndex_currentIndexChanged(int index); void on_buttonAutoSave_toggled(bool value); + void on_buttonSaveBeforeBattle_toggled(bool value); void on_comboBoxLanguage_currentIndexChanged(int index); void on_buttonCursorType_toggled(bool value); void on_pushButtonTranslation_clicked(); diff --git a/launcher/settingsView/csettingsview_moc.ui b/launcher/settingsView/csettingsview_moc.ui index 10ac9d634..2ace86b8b 100644 --- a/launcher/settingsView/csettingsview_moc.ui +++ b/launcher/settingsView/csettingsview_moc.ui @@ -69,7 +69,7 @@ - + Mods Validation @@ -301,7 +301,7 @@ - + true @@ -507,7 +507,7 @@ - + 1024 @@ -667,7 +667,7 @@ - + true @@ -707,7 +707,7 @@ - + Network port @@ -1133,7 +1133,7 @@ - + @@ -1424,7 +1424,7 @@ Fullscreen Exclusive Mode - game will cover entirety of your screen and will use - + true @@ -1449,6 +1449,29 @@ Fullscreen Exclusive Mode - game will cover entirety of your screen and will use + + + + Save before battle + + + + + + + + 0 + 0 + + + + + + + true + + + diff --git a/launcher/translation/chinese.ts b/launcher/translation/chinese.ts index c80f1cfaa..5cc851e94 100644 --- a/launcher/translation/chinese.ts +++ b/launcher/translation/chinese.ts @@ -1009,6 +1009,11 @@ Fullscreen Exclusive Mode - game will cover entirety of your screen and will use Autosave 自动存档 + + + Save before battle + 战斗前存档 + VSync diff --git a/server/CGameHandler.cpp b/server/CGameHandler.cpp index 373988702..cdc51a211 100644 --- a/server/CGameHandler.cpp +++ b/server/CGameHandler.cpp @@ -4276,10 +4276,21 @@ void CGameHandler::newObject(CGObjectInstance * object, PlayerColor initiator) void CGameHandler::startBattle(const CArmedInstance *army1, const CArmedInstance *army2, int3 tile, const CGHeroInstance *hero1, const CGHeroInstance *hero2, const BattleLayout & layout, const CGTownInstance *town) { + if (settings["general"]["saveBeforeBattle"].Bool()) + { + logGlobal->debug("gameHandler save before battle."); + save("Saves/BATTLE"); + } battles->startBattle(army1, army2, tile, hero1, hero2, layout, town); } void CGameHandler::startBattle(const CArmedInstance *army1, const CArmedInstance *army2 ) { + if (settings["general"]["saveBeforeBattle"].Bool()) + { + logGlobal->debug("gameHandler save before battle."); + save("Saves/BATTLE"); + } + battles->startBattle(army1, army2); }