Skip to content

Commit

Permalink
Display the currently researched tech in the lower right box
Browse files Browse the repository at this point in the history
  • Loading branch information
TomWerner committed Jan 26, 2025
1 parent e3a9b66 commit 1630c5a
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 16 deletions.
1 change: 1 addition & 0 deletions C7/C7Game.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
5 changes: 5 additions & 0 deletions C7/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Game>();

Expand Down Expand Up @@ -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;
}
}
Expand Down
4 changes: 4 additions & 0 deletions C7/UIElements/GameStatus/GameStatus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
46 changes: 30 additions & 16 deletions C7/UIElements/GameStatus/LowerRightInfoBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);

}
}

0 comments on commit 1630c5a

Please sign in to comment.