From 57a4c529bf93976b8cc3855e984edd982718f905 Mon Sep 17 00:00:00 2001 From: Tom Date: Wed, 22 Jan 2025 21:54:42 -0600 Subject: [PATCH] Use the correct texture for known/in progress/possible techs #392 --- C7/UIElements/Advisors/ScienceAdvisor.cs | 18 ++++++++++- C7/UIElements/Advisors/TechBox.cs | 40 +++++++++++++++++++++--- 2 files changed, 52 insertions(+), 6 deletions(-) diff --git a/C7/UIElements/Advisors/ScienceAdvisor.cs b/C7/UIElements/Advisors/ScienceAdvisor.cs index 5c1e607f..fc623c9f 100644 --- a/C7/UIElements/Advisors/ScienceAdvisor.cs +++ b/C7/UIElements/Advisors/ScienceAdvisor.cs @@ -51,6 +51,7 @@ private void CreateUI() { using (UIGameDataAccess gameDataAccess = new()) { List techs = gameDataAccess.gameData.techs; + List knownTechs = gameDataAccess.gameData.GetHumanPlayers()[0].knownTechs; foreach (Tech tech in techs) { // TODO: handle other eras. @@ -58,7 +59,22 @@ private void CreateUI() { continue; } - TechBox techButton = new(tech); + // TODO: track the currently researched tech for kInProgress. + TechBox.TechState techState = TechBox.TechState.kBlocked; + if (knownTechs.Contains(tech.id)) { + techState = TechBox.TechState.kKnown; + } else { + bool prereqsKnown = true; + foreach (Tech prereq in tech.Prerequisites) { + if (!knownTechs.Contains(prereq.id)) { + prereqsKnown = false; + break; + } + } + techState = prereqsKnown ? TechBox.TechState.kPossible : TechBox.TechState.kBlocked; + } + + TechBox techButton = new(tech, techState); techButton.SetPosition(new Vector2(tech.X, tech.Y)); AddChild(techButton); } diff --git a/C7/UIElements/Advisors/TechBox.cs b/C7/UIElements/Advisors/TechBox.cs index f0b4a35c..b8d25584 100644 --- a/C7/UIElements/Advisors/TechBox.cs +++ b/C7/UIElements/Advisors/TechBox.cs @@ -1,22 +1,52 @@ +using System; using C7GameData; using Godot; public partial class TechBox : TextureButton { private Tech tech; + private TechState techState; - public TechBox(Tech tech) { + public enum TechState { + // This tech is known to the player. + kKnown, + // The player is actively researching this tech. + kInProgress, + // The player could research this tech. + kPossible, + // The player needs to research the prerequisites before this tech can + // be researched. + kBlocked, + } + + public TechBox(Tech tech, TechState techState) { this.tech = tech; + this.techState = techState; } public override void _Ready() { // TODO: Figure out how to pick which of the different sized tech boxes // we should use for a given tech. // - // NOTE: this pcx has 4 columns (discovered, planned, possible, - // not yet researchable), and 16 rows, 4 per era, with different sizes. - ImageTexture techBox = Util.LoadTextureFromPCX("Art/Advisors/techboxes.pcx", 1, 1, 180, 80); - TextureNormal = techBox; + // NOTE: this pcx has 16 rows, 4 per era, with different sizes. + // + // NOTE: the x coordinates of each column were found via guess+check. + ImageTexture knownTechBox = Util.LoadTextureFromPCX("Art/Advisors/techboxes.pcx", + 1, 1, 180, 80); + ImageTexture inProgressTechBox = Util.LoadTextureFromPCX("Art/Advisors/techboxes.pcx", + 192, 1, 180, 80); + ImageTexture possibleTechBox = Util.LoadTextureFromPCX("Art/Advisors/techboxes.pcx", + 381, 1, 180, 80); + ImageTexture blockedTechBox = Util.LoadTextureFromPCX("Art/Advisors/techboxes.pcx", + 568, 1, 180, 80); + + TextureNormal = techState switch { + TechState.kKnown => knownTechBox, + TechState.kInProgress => inProgressTechBox, + TechState.kPossible => possibleTechBox, + TechState.kBlocked => blockedTechBox, + _ => throw new ArgumentOutOfRangeException("Invalid tech state") + }; ImageTexture iconTexture = Util.LoadTextureFromPCX(tech.SmallIconPath); TextureRect icon = new() {