From 375335ce2be89bd22fb8558b00a3d0c9510ee27c Mon Sep 17 00:00:00 2001 From: Zack Perez Date: Wed, 25 Nov 2026 09:23:56 -0600 Subject: [PATCH 1/5] Add New Game option to in-game main menu - Add "New Game (Ctrl-Shift-Q)" button below Load Game and above Preferences in the in-game main menu - Add confirmation popup before leaving the current game, matching the Retire workflow - Add Game.OnNewGame, which returns to the main entry screen after the player confirms - Add new_game input action and C7Action.NewGame for the Ctrl-Shift-Q shortcut - Enable the previously stubbed New Game button in GameMenu and add a NewGame signal on PopupOverlay --- C7/C7Game.tscn | 1 + C7/Game.cs | 10 ++++++++++ C7/Game_EmitMessages.cs | 24 +++++++++++++++++++++++- C7/UIElements/Popups/GameMenu.cs | 4 ++-- C7/UIElements/Popups/PopupOverlay.cs | 1 + C7/project.godot | 5 +++++ C7Engine/Actions.cs | 1 + 7 files changed, 43 insertions(+), 3 deletions(-) diff --git a/C7/C7Game.tscn b/C7/C7Game.tscn index d5799f248..ecfbbff0c 100644 --- a/C7/C7Game.tscn +++ b/C7/C7Game.tscn @@ -393,6 +393,7 @@ visible = false [connection signal="DiplomacySelection" from="CanvasLayer/PopupOverlay" to="." method="OnDiplomacySelected"] [connection signal="HidePopup" from="CanvasLayer/PopupOverlay" to="CanvasLayer/PopupOverlay" method="OnHidePopup"] [connection signal="LoadGame" from="CanvasLayer/PopupOverlay" to="." method="OnLoadGame"] +[connection signal="NewGame" from="CanvasLayer/PopupOverlay" to="." method="EmitNewGameConfirmationSignal"] [connection signal="OpenPreferences" from="CanvasLayer/PopupOverlay" to="." method="OnOpenPreferences"] [connection signal="Quit" from="CanvasLayer/PopupOverlay" to="." method="OnQuitTheGame"] [connection signal="Retire" from="CanvasLayer/PopupOverlay" to="." method="OnRetire"] diff --git a/C7/Game.cs b/C7/Game.cs index e0ca7c6e0..e2c8f62ae 100644 --- a/C7/Game.cs +++ b/C7/Game.cs @@ -627,6 +627,11 @@ public void OnRetire() { GetTree().ChangeSceneToFile("res://UIElements/MainMenu/main_menu.tscn"); } + public void OnNewGame() { + // Same as the original game: return to the main entry screen + GetTree().ChangeSceneToFile("res://UIElements/MainMenu/main_menu.tscn"); + } + public void OnSaveGame() { SavePaths.EnsureSaveFolderExists(); FileDialog.SetDirectoryForSaving(SavePaths.SaveFolder); @@ -1175,6 +1180,11 @@ private void ProcessAction(string currentAction) { return; } + if (currentAction == C7Action.NewGame) { + EmitNewGameConfirmationSignal(); + return; + } + if (currentAction == C7Action.Retire) { EmitRetireConfirmationSignal(); return; diff --git a/C7/Game_EmitMessages.cs b/C7/Game_EmitMessages.cs index dfbc10a71..dc2d98f12 100644 --- a/C7/Game_EmitMessages.cs +++ b/C7/Game_EmitMessages.cs @@ -84,7 +84,11 @@ public void EmitGameMainMenuSignal() { }; options.Add(loadGameBtn); - // TODO: add New Game option. This seems to do exactly the same as Retire in the original game + var newGameBtn = new ButtonAction() { + message = "New Game (Ctrl-Shift-Q)", + action = () => EmitNewGameConfirmationSignal(), + }; + options.Add(newGameBtn); var preferencesBtn = new ButtonAction() { message = "Preferences (Ctrl-P)", @@ -142,6 +146,24 @@ public void EmitRetireConfirmationSignal() { )); } + public void EmitNewGameConfirmationSignal() { + var message = "Leave this game and start a new one? All progress since your last save will be lost."; + + EmitSignal(SignalName.InteractivePopUp, new ParameterWrapper( + new ConfirmPopUp( + controller.id, + "Do you want to start a new game?", + message, + Advisor.None, + Mood.None, + "Yes, start a new game", + "No, let me keep playing", + () => OnNewGame(), + hSize: 500 + ) + )); + } + public void EmitDiplomacyPopUpSignal() { var options = new List(); diff --git a/C7/UIElements/Popups/GameMenu.cs b/C7/UIElements/Popups/GameMenu.cs index e7929d870..9d23aca34 100644 --- a/C7/UIElements/Popups/GameMenu.cs +++ b/C7/UIElements/Popups/GameMenu.cs @@ -22,7 +22,7 @@ public override void _Ready() { Tuple[] buttons = [ new("Map", ShowMap), new("Load Game", Load), - // new("New Game (Ctrl-Shift-Q)", NewGame), + new("New Game (Ctrl-Shift-Q)", NewGame), // TODO: Quick Start? new("Preferences (Ctrl-P)", OpenPreferences), new("Retire", Retire), @@ -63,7 +63,7 @@ private void Quit() { } private void NewGame() { - // TODO: Wire to a NewGame scene + GetParent().EmitSignal(PopupOverlay.SignalName.NewGame); } private void OpenPreferences() { diff --git a/C7/UIElements/Popups/PopupOverlay.cs b/C7/UIElements/Popups/PopupOverlay.cs index 6b5f2cb20..75122af13 100644 --- a/C7/UIElements/Popups/PopupOverlay.cs +++ b/C7/UIElements/Popups/PopupOverlay.cs @@ -21,6 +21,7 @@ public partial class PopupOverlay : HBoxContainer { [Signal] public delegate void SaveGameEventHandler(); [Signal] public delegate void LoadGameEventHandler(); [Signal] public delegate void RetireEventHandler(); + [Signal] public delegate void NewGameEventHandler(); [Signal] public delegate void QuitEventHandler(); [Signal] public delegate void OpenPreferencesEventHandler(); diff --git a/C7/project.godot b/C7/project.godot index a6b1f5dc5..0ef3a3cb4 100644 --- a/C7/project.godot +++ b/C7/project.godot @@ -70,6 +70,11 @@ retire={ "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":true,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":81,"key_label":0,"unicode":113,"location":0,"echo":false,"script":null) ] } +new_game={ +"deadzone": 0.5, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":true,"ctrl_pressed":true,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":81,"key_label":0,"unicode":113,"location":0,"echo":false,"script":null) +] +} open_game_menu={ "deadzone": 0.5, "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":true,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":77,"key_label":0,"unicode":109,"location":0,"echo":false,"script":null) diff --git a/C7Engine/Actions.cs b/C7Engine/Actions.cs index 15d518c7b..e122d0d99 100644 --- a/C7Engine/Actions.cs +++ b/C7Engine/Actions.cs @@ -28,6 +28,7 @@ public static class C7Action { public const string SaveGame = "save_game"; // Ctrl-S public const string LoadGame = "load_game"; // Ctrl-L public const string Retire = "retire"; // Ctrl-Q + public const string NewGame = "new_game"; // Ctrl-Shift-Q public const string ShowDomesticAdvisor = "show_domestic_advisor"; // F1 public const string ShowTradeAdvisor = "show_trade_advisor"; From 47680690a42ffa8b0e98dc74073e89996399a053 Mon Sep 17 00:00:00 2001 From: Zack Perez Date: Wed, 25 Nov 2026 09:32:36 -0600 Subject: [PATCH 2/5] Fix Ctrl-P Preferences keyboard shortcut - Remove duplicate Ctrl-P handling from HandleKeyboardInput, which toggled Preferences open and then the open_preferences action handler toggled it closed again in the same frame - Keep the open_preferences action handler as the single entry point, consistent with the Save, Load, and Retire shortcuts - Only open Preferences when no other modal is visible, so it can no longer open on top of the city screen or advisors --- C7/Game.cs | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/C7/Game.cs b/C7/Game.cs index e2c8f62ae..34a6e829d 100644 --- a/C7/Game.cs +++ b/C7/Game.cs @@ -915,15 +915,6 @@ private void HandleKeyboardInput(InputEventKey eventKeyDown) { return; } - if (eventKeyDown.Keycode == Godot.Key.P && eventKeyDown.IsCommandOrControlPressed()) { - if (preferences.Visible) { - preferences.HidePreferences(); - } else { - preferences.ShowPreferences(); - } - return; - } - if (eventKeyDown.Keycode == Godot.Key.F1) { EmitSignal(SignalName.ShowSpecificAdvisor, C7Action.ShowDomesticAdvisor); } @@ -1131,10 +1122,12 @@ private void ProcessAction(string currentAction) { return; } + // Ctrl-P is handled only here (not in HandleKeyboardInput), otherwise the + // key event and the action poll both toggle in the same frame and cancel out. if (currentAction == C7Action.OpenPreferences) { if (preferences.Visible) { preferences.HidePreferences(); - } else { + } else if (!HasVisibleModal()) { preferences.ShowPreferences(); } return; From 876f6f1a11af255f2b2b5c1485b43efda8da4c6b Mon Sep 17 00:00:00 2001 From: Zack Perez Date: Wed, 25 Nov 2026 09:46:14 -0600 Subject: [PATCH 3/5] Show defeat popup when retiring and persist time played in saves - Add "We are disgraced!" popup after confirming Retire, showing time spent, before returning to the main menu - Add GameData.timePlayedSeconds, accumulated by the UI each frame, so the engine state stays deterministic for headless tests - Serialize time played in SaveGame as TimePlayedSeconds; older saves without the field default to 0 - Add SaveTest covering the time played save and load round trip - Update Retire TODOs now that only the end-of-game score graphs remain --- C7/Game.cs | 8 ++++++ C7/Game_EmitMessages.cs | 39 +++++++++++++++++++++++++++- C7Engine/C7GameData/GameData.cs | 4 +++ C7Engine/C7GameData/Save/SaveGame.cs | 4 +++ EngineTests/GameData/SaveTest.cs | 16 ++++++++++++ 5 files changed, 70 insertions(+), 1 deletion(-) diff --git a/C7/Game.cs b/C7/Game.cs index 34a6e829d..a928805b9 100644 --- a/C7/Game.cs +++ b/C7/Game.cs @@ -492,6 +492,11 @@ private void InterestingEvent() { } public override void _Process(double delta) { + // Persisted with the save so time played carries across saves and loads + if (EngineStorage.gameData != null) { + EngineStorage.gameData.timePlayedSeconds += delta; + } + ProcessActions(); if (!EngineStorage.HasPendingAnimations()) @@ -623,6 +628,9 @@ private void DoActualEndTurn() { } public void OnRetire() { + // TODO: Retire should also show the end-of-game results (score graphs, etc.) before returning + // to the main menu. That screen doesn't exist yet; per-turn score data is already recorded in + // gameData.history (HistTurnRecord). The defeat popup is shown by EmitRetireDefeatSignal. // Quit to main menu, freeing previous scene data GetTree().ChangeSceneToFile("res://UIElements/MainMenu/main_menu.tscn"); } diff --git a/C7/Game_EmitMessages.cs b/C7/Game_EmitMessages.cs index dc2d98f12..31bc32a80 100644 --- a/C7/Game_EmitMessages.cs +++ b/C7/Game_EmitMessages.cs @@ -140,12 +140,47 @@ public void EmitRetireConfirmationSignal() { Mood.None, "Yes, retire from this game", "No, let me keep playing", - () => OnRetire(), + () => { }, + // Wait for this popup to close before showing the defeat popup + yesCallback: () => EmitRetireDefeatSignal(), hSize: 500 ) )); } + /// + /// Shown after the player confirms retiring, matching the base game's "We are disgraced!" popup. + /// Dismissing it returns to the main menu. + /// + private async void EmitRetireDefeatSignal() { + var elapsed = TimeSpan.FromSeconds(EngineStorage.gameData.timePlayedSeconds); + var message = "You have suffered a humiliating loss.\n\n" + + $"Time Spent: {Pluralize((int)elapsed.TotalHours, "hour")}, " + + $"{Pluralize(elapsed.Minutes, "minute")}, and {Pluralize(elapsed.Seconds, "second")}."; + + var disengaged = EngineStorage.WaitForMessageToEngine(); + + EmitSignal(SignalName.InteractivePopUp, new ParameterWrapper( + new InformationPopup( + controller.id, + "We are disgraced!", + message, + Advisor.None, + Mood.None, + hSize: 375, + margins: new Margins(top: 50) + ) + )); + + await disengaged; + // TODO: Show the end-of-game score graphs here once they exist (see OnRetire) + OnRetire(); + } + + private static string Pluralize(int count, string noun) { + return $"{count} {noun}{(count == 1 ? "" : "s")}"; + } + public void EmitNewGameConfirmationSignal() { var message = "Leave this game and start a new one? All progress since your last save will be lost."; @@ -335,6 +370,7 @@ private void EmitDefeatSignal(ID playerId) { var options = new List() { new ButtonAction() { message = "Return to the main menu", + // TODO: Show the end-of-game score graphs here once they exist (see OnRetire) action = () => OnRetire() }, new ButtonAction() { @@ -762,6 +798,7 @@ private void EmitVictorySignal(MsgVictory msg) { var options = new List { new ButtonAction() { message = "Good! I’m Done!", + // TODO: Show the end-of-game score graphs here once they exist (see OnRetire) action = () => OnRetire() }, new ButtonAction() { diff --git a/C7Engine/C7GameData/GameData.cs b/C7Engine/C7GameData/GameData.cs index 37a782174..98615aa43 100644 --- a/C7Engine/C7GameData/GameData.cs +++ b/C7Engine/C7GameData/GameData.cs @@ -72,6 +72,10 @@ public class GameData { public int healRateInHostileField; public int healRateInCity; + // Real-world time the player has spent in this game, accumulated by the UI + // and persisted across saves and loads. + public double timePlayedSeconds = 0; + public bool observerMode = false; public bool showGridCoordinates = false; public bool revealMap = false; diff --git a/C7Engine/C7GameData/Save/SaveGame.cs b/C7Engine/C7GameData/Save/SaveGame.cs index 928e5ffec..c728e0d3c 100644 --- a/C7Engine/C7GameData/Save/SaveGame.cs +++ b/C7Engine/C7GameData/Save/SaveGame.cs @@ -55,6 +55,7 @@ public static SaveGame FromGameData(GameData data) { Seed = data.seed, WorldCharacteristics = data.worldCharacteristics, TurnNumber = data.turn, + TimePlayedSeconds = data.timePlayedSeconds, Civilizations = data.civilizations, CultureGroups = data.cultureGroups, Alliances = data.alliances, @@ -237,6 +238,7 @@ private GameData InitializeGameData() { // copy data without references var data = new GameData(Seed) { turn = TurnNumber, + timePlayedSeconds = TimePlayedSeconds, worldCharacteristics = WorldCharacteristics, terrainTypes = TerrainTypes, Resources = Resources, @@ -508,6 +510,8 @@ private void ConvertAllianceWars(GameData data) { public int Seed = -1; public WorldCharacteristics WorldCharacteristics; public int TurnNumber = 0; + // Real-world seconds the player has spent in this game. Absent in older saves, so defaults to 0. + public double TimePlayedSeconds = 0; public SaveMap Map = new SaveMap(); public List TerrainTypes = new List(); public List TerrainImprovements = []; diff --git a/EngineTests/GameData/SaveTest.cs b/EngineTests/GameData/SaveTest.cs index e9b036be8..b336e1e36 100644 --- a/EngineTests/GameData/SaveTest.cs +++ b/EngineTests/GameData/SaveTest.cs @@ -310,6 +310,22 @@ public async Task SaveInObserverModeIsLoadable() { Assert.DoesNotContain(game.players, p => p.isHuman); } + [Fact] + public async Task TimePlayedSurvivesSaveAndLoad() { + await CreateHeadlessGame(fixture.saveGame); + WaitForStartTurnMessage(); + + C7GameData.GameData game = null; + EngineStorage.ReadGameData((C7GameData.GameData gameData) => { game = gameData; }); + game.timePlayedSeconds = 3723.5; + + string savePath = PathUtils.getDataPath("output/time-played-save.json"); + SaveGame.FromGameData(game).Save(savePath); + + C7GameData.GameData loaded = ToGameData(SaveGame.Load(savePath, (string unused) => { return unused; }, (string unused) => { return unused; })); + Assert.Equal(3723.5, loaded.timePlayedSeconds); + } + [Fact] public async Task WorldWrapDetails() { Player human = await CreateHeadlessGame(fixture.saveGame); From f094af0ad9ab051be6e02a4c9007b4291970f474 Mon Sep 17 00:00:00 2001 From: Zack Perez Date: Wed, 25 Nov 2026 09:58:16 -0600 Subject: [PATCH 4/5] Polish retire/defeat popups: Enter handling, defeat path, background sizing - Ignore key-repeat Enter events in the interactable popup controller so a held Enter can't also confirm the next popup - Add an optional onConfirm callback to InformationPopup so the "We are disgraced!" popup returns to the main menu directly instead of waiting on a UI message that is sent twice per confirmation - Show the "We are disgraced!" popup from the Game Over popup's "Return to the main menu" option, not only from Retire - Add a TODO on the victory popup for the victory screen and end-of-game score graphs - Redraw the popup background when its content resizes so late text wrapping no longer leaves the confirm button hanging below the box - Add a disallowEscape option for interactable popups and use it on the disgrace and Game Over popups so Esc can't skip their actions --- C7/Game.cs | 6 +++- C7/Game_EmitMessages.cs | 28 ++++++++------- C7/UIElements/Popups/InformationPopup.cs | 5 ++- C7/UIElements/Popups/InteractablePopUp.cs | 4 +++ .../Popups/InteractablePopUpController.cs | 35 ++++++++++++++++++- 5 files changed, 62 insertions(+), 16 deletions(-) diff --git a/C7/Game.cs b/C7/Game.cs index a928805b9..b5663858c 100644 --- a/C7/Game.cs +++ b/C7/Game.cs @@ -1102,7 +1102,11 @@ private bool IsModalSwitchEvent(InputEvent @event) { private void ProcessAction(string currentAction) { if (currentAction == C7Action.Escape && interactablePopUpController.Visible) { - interactablePopUpController.Visible = false; + // Some popups (e.g. the defeat ones) must be answered, since closing them this way + // skips their actions and would leave the player stuck in a finished game. + if (interactablePopUpController.CanDismissWithEscape) { + interactablePopUpController.Visible = false; + } return; } diff --git a/C7/Game_EmitMessages.cs b/C7/Game_EmitMessages.cs index 31bc32a80..5bad0dabc 100644 --- a/C7/Game_EmitMessages.cs +++ b/C7/Game_EmitMessages.cs @@ -152,14 +152,12 @@ public void EmitRetireConfirmationSignal() { /// Shown after the player confirms retiring, matching the base game's "We are disgraced!" popup. /// Dismissing it returns to the main menu. /// - private async void EmitRetireDefeatSignal() { + private void EmitRetireDefeatSignal() { var elapsed = TimeSpan.FromSeconds(EngineStorage.gameData.timePlayedSeconds); var message = "You have suffered a humiliating loss.\n\n" + $"Time Spent: {Pluralize((int)elapsed.TotalHours, "hour")}, " + $"{Pluralize(elapsed.Minutes, "minute")}, and {Pluralize(elapsed.Seconds, "second")}."; - var disengaged = EngineStorage.WaitForMessageToEngine(); - EmitSignal(SignalName.InteractivePopUp, new ParameterWrapper( new InformationPopup( controller.id, @@ -168,13 +166,13 @@ private async void EmitRetireDefeatSignal() { Advisor.None, Mood.None, hSize: 375, - margins: new Margins(top: 50) - ) + margins: new Margins(top: 50), + onConfirm: () => { + // TODO: Show the end-of-game score graphs here once they exist (see OnRetire) + OnRetire(); + } + ) { disallowEscape = true } )); - - await disengaged; - // TODO: Show the end-of-game score graphs here once they exist (see OnRetire) - OnRetire(); } private static string Pluralize(int count, string noun) { @@ -370,8 +368,12 @@ private void EmitDefeatSignal(ID playerId) { var options = new List() { new ButtonAction() { message = "Return to the main menu", - // TODO: Show the end-of-game score graphs here once they exist (see OnRetire) - action = () => OnRetire() + // Wait for this popup to close before showing the defeat popup, otherwise + // closing this one would also close the new one. + action = async () => { + await EngineStorage.WaitForMessageToEngine(); + EmitRetireDefeatSignal(); + } }, new ButtonAction() { message = "Let the game play on without me", @@ -390,7 +392,7 @@ private void EmitDefeatSignal(ID playerId) { Mood.Sad, hSize: 600, margins: new Margins(top: 100) - ) { hasCancel = false } + ) { hasCancel = false, disallowEscape = true } )); } @@ -798,7 +800,7 @@ private void EmitVictorySignal(MsgVictory msg) { var options = new List { new ButtonAction() { message = "Good! I’m Done!", - // TODO: Show the end-of-game score graphs here once they exist (see OnRetire) + // TODO: Show the victory screen and end-of-game score graphs here once they exist (see OnRetire) action = () => OnRetire() }, new ButtonAction() { diff --git a/C7/UIElements/Popups/InformationPopup.cs b/C7/UIElements/Popups/InformationPopup.cs index cbcdade16..c2520add6 100644 --- a/C7/UIElements/Popups/InformationPopup.cs +++ b/C7/UIElements/Popups/InformationPopup.cs @@ -1,3 +1,4 @@ +using System; using C7GameData; using Serilog; using static AdvisorHead; @@ -15,8 +16,10 @@ public class InformationPopup : InteractablePopUp { public InformationPopup( ID controllerId, string header, string message, Advisor advisor, Mood mood, int hSize = 400, - LayoutPreset layoutPreset = DEFAULT_LAYOUT_PRESET, Margins margins = null) + LayoutPreset layoutPreset = DEFAULT_LAYOUT_PRESET, Margins margins = null, + Action onConfirm = null) : base(controllerId, header, layoutPreset, margins) { + this.confirmAction = onConfirm; this.controllerId = controllerId; this.hSize = hSize; this.message = message; diff --git a/C7/UIElements/Popups/InteractablePopUp.cs b/C7/UIElements/Popups/InteractablePopUp.cs index b70225e03..9e5f706f3 100644 --- a/C7/UIElements/Popups/InteractablePopUp.cs +++ b/C7/UIElements/Popups/InteractablePopUp.cs @@ -24,6 +24,10 @@ public class InteractablePopUp { public List buttonActions { get; init; } public bool hasConfirm { get; init; } public bool hasCancel { get; init; } + // When true, Esc won't dismiss the popup, so the player has to choose one of its options + public bool disallowEscape { get; init; } + // Invoked after the popup has closed because the player pressed the confirm (OK) button or Enter + public Action confirmAction { get; init; } protected InteractablePopUp(ID controllerId, string header, LayoutPreset layoutPreset, Margins margins) { this.controllerId = controllerId; diff --git a/C7/UIElements/Popups/InteractablePopUpController.cs b/C7/UIElements/Popups/InteractablePopUpController.cs index 678d9e5ea..6a96cc90e 100644 --- a/C7/UIElements/Popups/InteractablePopUpController.cs +++ b/C7/UIElements/Popups/InteractablePopUpController.cs @@ -43,6 +43,10 @@ public partial class InteractablePopUpController : Control { private LayoutPreset layoutPreset = DEFAULT_LAYOUT_PRESET; private LineEditComponent lineEditComponent; + private Action confirmAction; + + // Whether Esc may dismiss the popup that is currently showing + public bool CanDismissWithEscape { get; private set; } = true; private float defaultOffsetTop; private float defaultOffsetBottom; @@ -82,6 +86,22 @@ public override void _Ready() { this.confirm.Pressed += this.OnConfirm; this.cancel.Pressed += this.OnCancel; this.lineEdit.TextSubmitted += this.LineTextSubmitted; + this.mainBgContainer.Resized += this.RefreshBackground; + } + + // The message label finishes wrapping (and so changes the content height) after the popup is first shown. + // Redraw the background whenever the content resizes, otherwise the box can end up shorter than its + // content and leave the confirm button hanging below it. + private void RefreshBackground() { + if (!this.Visible || this.bgTextureRect.Texture == null) { + return; + } + + int width = (int)this.mainBgContainer.GetSize().X; + int height = (int)this.mainBgContainer.GetSize().Y; + if (width > 0 && height > 0) { + this.bgTextureRect.Texture = this.CreateTextureBackGround(width, height); + } } // An intermediary method so that we can edit and submit text without having to grab/release focus @@ -91,8 +111,11 @@ private void LineTextSubmitted(string text) { public override void _UnhandledInput(InputEvent @event) { base._UnhandledInput(@event); - if (this.Visible && @event is InputEventKey eventKey && eventKey.Pressed) { + // Echo events are key repeats from a held key. Ignoring them means only a fresh key press acts, so + // the Enter that confirmed the previous popup can't also confirm the popup that replaces it. + if (this.Visible && @event is InputEventKey eventKey && eventKey.Pressed && !eventKey.Echo) { if (eventKey.Keycode == Key.Enter || eventKey.Keycode == Key.KpEnter) { + GetViewport().SetInputAsHandled(); this.OnConfirm(); } if (eventKey.Keycode == Key.Up) { @@ -148,6 +171,8 @@ private async void OnShowInteractablePopUpLocked(InteractablePopUp value) { this.mainTextContainer.Visible = true; this.mainTextLabel.Visible = true; this.mainTextLabel.Text = value.message; + this.confirmAction = value.confirmAction; + this.CanDismissWithEscape = !value.disallowEscape; if (string.IsNullOrEmpty(this.mainTextLabel.Text)) { this.mainTextContainer.Visible = false; @@ -281,10 +306,15 @@ private void OnConfirm() { this.lineEditComponent.callback.Invoke(this.lineEdit.Text.StripEdges()); } + // Take the action before closing, since closing clears it + Action action = this.confirmAction; + this.audioManager.PlayUIAudio("buttons.button_ok"); this.Hide(); this.CloseAndDelete(); new MsgUiDisengaged().send(); + + action?.Invoke(); } private void AddCancelButton() { @@ -328,6 +358,8 @@ private void CloseAndDelete() { this.advisorTextureRect.Texture = null; this.lineEditContainer.Hide(); this.lineEditComponent = null; + this.confirmAction = null; + this.CanDismissWithEscape = true; foreach (var child in buttonContainer.GetChildren()) { buttonContainer.RemoveChild(child); @@ -342,6 +374,7 @@ public override void _ExitTree() { base._ExitTree(); this.confirm.Pressed -= this.OnConfirm; this.cancel.Pressed -= this.OnCancel; + this.mainBgContainer.Resized -= this.RefreshBackground; } const int HTILE_SIZE = 61; From ac3afff6c7a576126b6b55bceaa013ca34091aaf Mon Sep 17 00:00:00 2001 From: Zack Perez Date: Wed, 25 Nov 2026 10:06:24 -0600 Subject: [PATCH 5/5] Add TODOs to consider showing time played on the Game Over and victory popups --- C7/Game_EmitMessages.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/C7/Game_EmitMessages.cs b/C7/Game_EmitMessages.cs index 5bad0dabc..3b1b738b1 100644 --- a/C7/Game_EmitMessages.cs +++ b/C7/Game_EmitMessages.cs @@ -365,6 +365,8 @@ public void EmitCivilizationDestroyedSignal(MsgCivilizationDestroyed msg) { } private void EmitDefeatSignal(ID playerId) { + // TODO: Consider adding the time played (gameData.timePlayedSeconds) to this popup's message. + // It is currently only shown on the "We are disgraced!" popup (see EmitRetireDefeatSignal). var options = new List() { new ButtonAction() { message = "Return to the main menu", @@ -791,6 +793,8 @@ private void EmitDisbandUnitConfirmationSignal(MsgDisbandUnitConfirmation msg) { } private void EmitVictorySignal(MsgVictory msg) { + // TODO: Consider adding the time played (gameData.timePlayedSeconds) to this popup's message, + // sharing the formatting used by EmitRetireDefeatSignal. var endMsg = $"The {msg.winner.civilization.noun} have won a {msg.victory.Header()} victory!\n" + "This game is over: No further score will be entered.\n\n";