diff --git a/binaries/data/mods/public/gui/session/developer_overlay/DeveloperOverlayCheckbox.js b/binaries/data/mods/public/gui/session/developer_overlay/DeveloperOverlayCheckbox.js index 310e35f5bc..19b2513760 100644 --- a/binaries/data/mods/public/gui/session/developer_overlay/DeveloperOverlayCheckbox.js +++ b/binaries/data/mods/public/gui/session/developer_overlay/DeveloperOverlayCheckbox.js @@ -6,6 +6,7 @@ class DeveloperOverlayCheckbox constructor(handler, i) { this.handler = handler; + this.handler.update = () => this.update(); this.label = Engine.GetGUIObjectByName("dev_command_label[" + i + "]"); this.label.caption = this.handler.label(); @@ -25,14 +26,15 @@ class DeveloperOverlayCheckbox onPress() { this.handler.onPress(this.checkbox.checked); - - if (this.handler.checked) - this.update(); + this.update(); } update() { - this.checkbox.checked = this.handler.checked(); + if (this.handler.checked) + this.checkbox.checked = this.handler.checked(); + if (this.handler.enabled) + this.checkbox.enabled = this.handler.enabled(); } setHidden(hidden) diff --git a/binaries/data/mods/public/gui/session/developer_overlay/DeveloperOverlayCheckboxes.js b/binaries/data/mods/public/gui/session/developer_overlay/DeveloperOverlayCheckboxes.js index da41ebcacc..00a52b207c 100644 --- a/binaries/data/mods/public/gui/session/developer_overlay/DeveloperOverlayCheckboxes.js +++ b/binaries/data/mods/public/gui/session/developer_overlay/DeveloperOverlayCheckboxes.js @@ -201,6 +201,46 @@ DeveloperOverlayCheckboxes.prototype.EnableTimeWarp = class } }; + +DeveloperOverlayCheckboxes.prototype.ActivateRejoinTest = class +{ + constructor() + { + this.disabled = false; + } + + label() + { + return translate("Activate Rejoin Test"); + } + + onPress(checked) + { + let box = new SessionMessageBox(); + box.Title = "Rejoin Test"; + box.Caption = "Warning: the rejoin test can't be de-activated and is quite slow. Its only purpose is to check for OOS."; + let self = this; + box.Buttons = [ + { "caption": "Cancel" }, { "caption": "OK", "onPress": () => { + Engine.ActivateRejoinTest(); + this.disabled = true; + this.update(); + } } + ]; + box.display(); + } + + checked() + { + return this.disabled; + } + + enabled() + { + return !this.disabled && g_GameAttributes.mapType != "random"; + } +}; + DeveloperOverlayCheckboxes.prototype.PromoteSelectedUnits = class { label() diff --git a/source/ps/scripting/JSInterface_SavedGame.cpp b/source/ps/scripting/JSInterface_SavedGame.cpp index 8c4abc7191..7173c61f03 100644 --- a/source/ps/scripting/JSInterface_SavedGame.cpp +++ b/source/ps/scripting/JSInterface_SavedGame.cpp @@ -113,6 +113,13 @@ JS::Value JSI_SavedGame::StartSavedGame(ScriptInterface::CmptPrivate* pCmptPriva return guiContextMetadata; } +void ActivateRejoinTest(ScriptInterface::CmptPrivate*) +{ + if (!g_Game || !g_Game->GetSimulation2() || !g_Game->GetTurnManager()) + return; + g_Game->GetSimulation2()->ActivateRejoinTest(g_Game->GetTurnManager()->GetCurrentTurn() + 1); +} + void JSI_SavedGame::RegisterScriptFunctions(const ScriptInterface& scriptInterface) { scriptInterface.RegisterFunction("GetSavedGames"); @@ -121,5 +128,6 @@ void JSI_SavedGame::RegisterScriptFunctions(const ScriptInterface& scriptInterfa scriptInterface.RegisterFunction("SaveGamePrefix"); scriptInterface.RegisterFunction("QuickSave"); scriptInterface.RegisterFunction("QuickLoad"); + scriptInterface.RegisterFunction("ActivateRejoinTest"); scriptInterface.RegisterFunction("StartSavedGame"); } diff --git a/source/simulation2/Simulation2.cpp b/source/simulation2/Simulation2.cpp index 0492b64700..17b802e41a 100644 --- a/source/simulation2/Simulation2.cpp +++ b/source/simulation2/Simulation2.cpp @@ -898,6 +898,14 @@ bool CSimulation2::DeserializeState(std::istream& stream) return m->m_ComponentManager.DeserializeState(stream); } +void CSimulation2::ActivateRejoinTest(int turn) +{ + if (m->m_RejoinTestTurn != -1) + return; + LOGMESSAGERENDER("Rejoin test will activate in %i turns", turn - m->m_TurnNumber); + m->m_RejoinTestTurn = turn; +} + std::string CSimulation2::GenerateSchema() { return m->m_ComponentManager.GenerateSchema(); diff --git a/source/simulation2/Simulation2.h b/source/simulation2/Simulation2.h index 6bc526cbfc..9540329cfd 100644 --- a/source/simulation2/Simulation2.h +++ b/source/simulation2/Simulation2.h @@ -229,6 +229,11 @@ public: bool SerializeState(std::ostream& stream); bool DeserializeState(std::istream& stream); + /** + * Activate the rejoin-test feature for turn @param turn. + */ + void ActivateRejoinTest(int turn); + std::string GenerateSchema(); /////////////////////////////////////////////////////////////////////////////