Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 21 additions & 13 deletions C7/UIElements/Popups/TileInfoPopup.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using C7Engine;
using C7GameData;
using Godot;
Expand All @@ -15,8 +16,8 @@ public partial class TileInfoPopup : Popup {
private TextureButton closeButton = new();

private Label terrainLabel = new();
private Label overlayLabel = new();
private Label resourceLabel = new();
private Label featuresLabel = new();

private Label foodLabel = new();
private Label shieldLabel = new();
Expand All @@ -35,7 +36,7 @@ public TileInfoPopup(Game game, Tile tile, Vector2 position, float zoom) {
margins = new Margins();
alignment = BoxContainer.AlignmentMode.Begin;

_labels.AddRange([terrainLabel, overlayLabel, resourceLabel, foodLabel, shieldLabel, goldLabel]);
_labels.AddRange([terrainLabel, resourceLabel, featuresLabel, foodLabel, shieldLabel, goldLabel]);

InitBoxTexture();
InitCloseButton();
Expand Down Expand Up @@ -79,13 +80,13 @@ private void DrawTileInfoBox(Vector2 tileCenter) {
closeButton.SetScale(scale);

// Re-position labels
var xStep = 100 * _zoom;
var xStep = 140 * _zoom;
var yStep = 15 * _zoom;
var contentOffset = new Vector2(25, 105) * _zoom;
var contentAnchor = boxTextureRect.Position + contentOffset;
terrainLabel.SetPosition(contentAnchor + new Vector2(0, 0));
overlayLabel.SetPosition(contentAnchor + new Vector2(0, yStep));
resourceLabel.SetPosition(contentAnchor + new Vector2(0, 2 * yStep));
resourceLabel.SetPosition(contentAnchor + new Vector2(0, yStep));
featuresLabel.SetPosition(contentAnchor + new Vector2(0, 2 * yStep));
foodLabel.SetPosition(contentAnchor + new Vector2(xStep, 0));
shieldLabel.SetPosition(contentAnchor + new Vector2(xStep, yStep));
goldLabel.SetPosition(contentAnchor + new Vector2(xStep, 2 * yStep));
Expand Down Expand Up @@ -113,23 +114,30 @@ private void SetTileInfoContent(Tile tile, GameData gameData) {
var isObserverMode = gameData.observerMode;

if (player.tileKnowledge.isTileKnown(tile) || isObserverMode) {
terrainLabel.Text = tile.baseTerrainType?.DisplayName ?? "";
overlayLabel.Text = tile.overlayTerrainType?.DisplayName ?? "";
resourceLabel.Text = tile.Resource?.Name ?? "";
if (tile.baseTerrainType == tile.overlayTerrainType) {
terrainLabel.Text = tile.baseTerrainType?.DisplayName ?? "";
} else {
terrainLabel.Text = string.Join(" ", tile.baseTerrainType?.DisplayName, tile.overlayTerrainType?.DisplayName);
}
resourceLabel.Text = tile.Resource?.Name ?? (tile.isBonusShield ? "Bonus" : "");
featuresLabel.Text = string.Join(", ", new string[] {
tile.OwningPlayer()?.civilization.adjective,
tile.hasHadForestCleared ? "Cleared" : null,
(tile.isFreshWater || tile.IsLand() && (tile.BordersRiver() || tile.NeighborsFreshWater())) ? "Freshwater" : null,
(tile.IsWater() && !tile.isFreshWater) ? "Saltwater" : null,
(tile.IsLand() && tile.NeighborsOcean()) ? "Coastal" : null

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These special compound predicates could live in Tile as well: would make this code more readable as well.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, I had even thought about how to have a tile generically describe itself. But that could get messy when you consider modding/translation of text and potentially wanting to use the descriptions in different contexts. Maybe Tile should just have more comprehensive properties, and then some UI-layer mapping of property values to text.

}.Where(s => !string.IsNullOrEmpty(s)));
foodLabel.Text = $"Food: {tile.FoodYield(player).baseYield}";
shieldLabel.Text = $"Shields: {tile.ProductionYield(player).baseYield}";
goldLabel.Text = $"Gold: {tile.CommerceYield(player).baseYield}";

if (tile.baseTerrainType == tile.overlayTerrainType)
overlayLabel.Text = "";

if (tile.Resource != null && !player.KnowsAboutResource(tile.Resource) && !isObserverMode)
resourceLabel.Text = "";

} else {
terrainLabel.Text = "";
overlayLabel.Text = "No information available";
resourceLabel.Text = "";
resourceLabel.Text = "No information available";
featuresLabel.Text = "";
foodLabel.Text = "";
shieldLabel.Text = "";
goldLabel.Text = "";
Expand Down
Loading