From 86b6f4e73b5ccc39002944ef9aa2c5d0f778df6e Mon Sep 17 00:00:00 2001 From: Tom Date: Sun, 26 Jan 2025 11:05:33 -0600 Subject: [PATCH] Display the currently researched tech in the lower right box #392 --- C7/C7Game.tscn | 1 + C7/Game.cs | 5 ++ C7/UIElements/GameStatus/GameStatus.cs | 4 ++ C7/UIElements/GameStatus/LowerRightInfoBox.cs | 46 ++++++++++++------- 4 files changed, 40 insertions(+), 16 deletions(-) diff --git a/C7/C7Game.tscn b/C7/C7Game.tscn index d40eeb4e..15c4d7df 100644 --- a/C7/C7Game.tscn +++ b/C7/C7Game.tscn @@ -259,6 +259,7 @@ script = ExtResource("3") [connection signal="ShowSpecificAdvisor" from="." to="CanvasLayer/Advisor" method="OnShowSpecificAdvisor"] [connection signal="TurnEnded" from="." to="CanvasLayer/Control/GameStatus" method="OnTurnEnded"] [connection signal="TurnStarted" from="." to="CanvasLayer/Control/GameStatus" method="OnTurnStarted"] +[connection signal="UpdateTechProgress" from="." to="CanvasLayer/Control/GameStatus" method="OnUpdateTechProgress"] [connection signal="BuildCity" from="CanvasLayer/PopupOverlay" to="." method="OnBuildCity"] [connection signal="HidePopup" from="CanvasLayer/PopupOverlay" to="CanvasLayer/PopupOverlay" method="OnHidePopup"] [connection signal="Quit" from="CanvasLayer/PopupOverlay" to="." method="OnQuitTheGame"] diff --git a/C7/Game.cs b/C7/Game.cs index 4ede59fe..cc94f713 100644 --- a/C7/Game.cs +++ b/C7/Game.cs @@ -13,6 +13,7 @@ public partial class Game : Node2D { [Signal] public delegate void ShowSpecificAdvisorEventHandler(); [Signal] public delegate void NewAutoselectedUnitEventHandler(); [Signal] public delegate void NoMoreAutoselectableUnitsEventHandler(); + [Signal] public delegate void UpdateTechProgressEventHandler(); private ILogger log = LogManager.ForContext(); @@ -212,6 +213,10 @@ public void processEngineMessages(GameData gameData) { // F6 is the science advisor. // TODO: Move the F* key strings to a set of constants/enum. EmitSignal(SignalName.ShowSpecificAdvisor, "F6"); + Tech tech = gameData.techs.Find(x => x.id == gameData.GetHumanPlayers()[0].currentlyResearchedTech); + + // TODO: calculate research speed. + EmitSignal(SignalName.UpdateTechProgress, tech.Name, -1); break; } } diff --git a/C7/UIElements/GameStatus/GameStatus.cs b/C7/UIElements/GameStatus/GameStatus.cs index 9a6f1695..27815924 100644 --- a/C7/UIElements/GameStatus/GameStatus.cs +++ b/C7/UIElements/GameStatus/GameStatus.cs @@ -37,4 +37,8 @@ private void OnTurnStarted(int turnNumber) { private void OnNoMoreAutoselectableUnits() { LowerRightInfoBox.SetEndOfTurnStatus(); } + + private void OnUpdateTechProgress(string techName, int turnsRemaining) { + LowerRightInfoBox.UpdateTechProgress(techName, turnsRemaining); + } } diff --git a/C7/UIElements/GameStatus/LowerRightInfoBox.cs b/C7/UIElements/GameStatus/LowerRightInfoBox.cs index 839ffcca..500ac98b 100644 --- a/C7/UIElements/GameStatus/LowerRightInfoBox.cs +++ b/C7/UIElements/GameStatus/LowerRightInfoBox.cs @@ -15,6 +15,7 @@ public partial class LowerRightInfoBox : TextureRect { Label attackDefenseMovement = new Label(); Label terrainType = new Label(); Label yearAndGold = new Label(); + Label scienceProgress = new(); Timer blinkingTimer = new Timer(); bool timerStarted = false; //This "isStopped" returns false if it's never been started. So we need this to know if we've ever started it. @@ -68,26 +69,18 @@ private void CreateUI() { terrainType.OffsetRight = -30; boxRightRectangle.AddChild(terrainType); - //For the centered labels, we anchor them center, with equal weight on each side. - //Then, when they are visible, we add a left margin that's negative and equal to half - //their width. - //Seems like there probably is an easier way, but I haven't found it yet. Label civAndGovt = new Label(); - civAndGovt.Text = "Carthage - Despotism (5.5.0)"; - civAndGovt.HorizontalAlignment = HorizontalAlignment.Center; - civAndGovt.SetPosition(new Vector2(0, 90)); - civAndGovt.AnchorLeft = 0.5f; - civAndGovt.AnchorRight = 0.5f; + civAndGovt.SetPosition(new Vector2(0, 75)); boxRightRectangle.AddChild(civAndGovt); - civAndGovt.OffsetLeft = -1 * (civAndGovt.Size.X / 2.0f); + SetTextAndCenterLabel(civAndGovt, "Carthage - Despotism (5.5.0)"); - yearAndGold.Text = "Turn 0 10 Gold (+0 per turn)"; - yearAndGold.HorizontalAlignment = HorizontalAlignment.Center; - yearAndGold.SetPosition(new Vector2(0, 105)); - yearAndGold.AnchorLeft = 0.5f; - yearAndGold.AnchorRight = 0.5f; + yearAndGold.SetPosition(new Vector2(0, 90)); boxRightRectangle.AddChild(yearAndGold); - yearAndGold.OffsetLeft = -1 * (yearAndGold.Size.X / 2.0f); + SetTextAndCenterLabel(yearAndGold, "Turn 0 10 Gold (+0 per turn)"); + + scienceProgress.SetPosition(new Vector2(0, 105)); + boxRightRectangle.AddChild(scienceProgress); + SetTextAndCenterLabel(scienceProgress, ""); //Setup up, but do not start, the timer. blinkingTimer.OneShot = false; @@ -153,4 +146,25 @@ public void UpdateUnitInfo(MapUnit NewUnit, TerrainType terrain) { public void SetTurn(int turnNumber) { yearAndGold.Text = $"Turn {turnNumber} 10 Gold (+0 per turn)"; } + + public void UpdateTechProgress(string techName, int turnsRemaining) { + if (turnsRemaining > 0) { + SetTextAndCenterLabel(scienceProgress, $"{techName} (-- turns)"); + } else { + SetTextAndCenterLabel(scienceProgress, $"{techName} ({turnsRemaining} turns)"); + } + } + + private void SetTextAndCenterLabel(Label label, string text) { + //For the centered labels, we anchor them center, with equal weight on each side. + //Then, when they are visible, we add a left margin that's negative and equal to half + //their width. + //Seems like there probably is an easier way, but I haven't found it yet. + label.Text = text; + label.HorizontalAlignment = HorizontalAlignment.Center; + label.AnchorLeft = 0.5f; + label.AnchorRight = 0.5f; + label.OffsetLeft = -1 * (label.Size.X / 2.0f); + + } }