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..9f149895 100644 --- a/C7/UIElements/Advisors/TechBox.cs +++ b/C7/UIElements/Advisors/TechBox.cs @@ -4,19 +4,55 @@ 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); + + switch (techState) { + case TechState.kKnown: + TextureNormal = knownTechBox; + break; + case TechState.kInProgress: + TextureNormal = inProgressTechBox; + break; + case TechState.kPossible: + TextureNormal = possibleTechBox; + break; + case TechState.kBlocked: + TextureNormal = blockedTechBox; + break; + } ImageTexture iconTexture = Util.LoadTextureFromPCX(tech.SmallIconPath); TextureRect icon = new() {