Skip to content

Commit

Permalink
Use the correct texture for known/in progress/possible techs
Browse files Browse the repository at this point in the history
  • Loading branch information
TomWerner committed Jan 28, 2025
1 parent 8831107 commit 381dd15
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 6 deletions.
18 changes: 17 additions & 1 deletion C7/UIElements/Advisors/ScienceAdvisor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,30 @@ private void CreateUI() {

using (UIGameDataAccess gameDataAccess = new()) {
List<Tech> techs = gameDataAccess.gameData.techs;
List<ID> knownTechs = gameDataAccess.gameData.GetHumanPlayers()[0].knownTechs;

foreach (Tech tech in techs) {
// TODO: handle other eras.
if (tech.Era != "Ancient Times") {
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);
}
Expand Down
46 changes: 41 additions & 5 deletions C7/UIElements/Advisors/TechBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 381dd15

Please sign in to comment.