Skip to content
Open
Show file tree
Hide file tree
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
33 changes: 31 additions & 2 deletions C7/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ private void InitializeMapView() {

mapView.cameraZoom = (float)1.0;
mapView.gridLayer.visible = PreferencesSettings.GetShowGrid();
mapView.ApplyCleanMapPreferences();

if (!cameraLocation.HasValue) {
// Set initial camera location. If the UI controller has any cities, focus on their capital. Otherwise, focus on their
Expand Down Expand Up @@ -919,6 +920,22 @@ private void HandleKeyboardInput(InputEventKey eventKeyDown) {
return;
}

if (eventKeyDown.Keycode == Godot.Key.M
&& eventKeyDown.IsCommandOrControlPressed()
&& eventKeyDown.ShiftPressed
&& !eventKeyDown.AltPressed) {
ToggleCleanMap();
return;
}

if (eventKeyDown.Keycode == Godot.Key.N
&& eventKeyDown.IsCommandOrControlPressed()
&& eventKeyDown.ShiftPressed
&& !eventKeyDown.AltPressed) {
EmitCleanMapPreferencesSignal();
return;
}

if (eventKeyDown.Keycode == Godot.Key.F1) {
EmitSignal(SignalName.ShowSpecificAdvisor, C7Action.ShowDomesticAdvisor);
}
Expand Down Expand Up @@ -954,8 +971,8 @@ private void HandleKeyboardInput(InputEventKey eventKeyDown) {
EmitSignal(SignalName.ShowGameView, C7Action.ShowDemographicsView);
}

if (eventKeyDown.Keycode == Godot.Key.C && HasCurrentlySelectedUnit()) {
mapView.centerCameraOnTile(CurrentlySelectedUnit.location);
if (eventKeyDown.Keycode == Godot.Key.C) {
CenterScreenOnActiveUnit();
}
if (eventKeyDown.Keycode == Godot.Key.H) {
City capital = controller.cities.Find(c => c.IsCapital());
Expand Down Expand Up @@ -1037,6 +1054,18 @@ private void ToggleGridCoordinates() {
});
}

private void CenterScreenOnActiveUnit() {
if (mapView == null || !HasCurrentlySelectedUnit()) {
return;
}
mapView.centerCameraOnTile(CurrentlySelectedUnit.location);
}

private void ToggleCleanMap() {
CleanMapSettings.Enabled = !CleanMapSettings.Enabled;
mapView?.ApplyCleanMapPreferences();
}

private void ToggleCameraZoom() {
if (mapView == null) {
return;
Expand Down
51 changes: 49 additions & 2 deletions C7/Game_EmitMessages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -780,10 +780,28 @@ public void EmitMapMenuSignal(int selectedOption = 0) {
}
}));

int zoomPercent = mapView != null ? Mathf.RoundToInt(mapView.cameraZoom * 100) : 100;
options.Add(CreateMapMenuToggle(
1,
selectedOption,
"Center Screen (C)",
CenterScreenOnActiveUnit));

options.Add(CreateMapMenuToggle(
2,
selectedOption,
$"Clean Map (Ctrl+Shift+M): {(CleanMapSettings.Enabled ? "On" : "Off")}",
ToggleCleanMap));

var cleanMapPreferencesBtn = new ButtonAction() {
message = "Clean Map Preferences (Ctrl+Shift+N)",
action = () => EmitCleanMapPreferencesSignal(),
};
options.Add(cleanMapPreferencesBtn);

int zoomPercent = mapView != null ? Mathf.RoundToInt(mapView.cameraZoom * 100) : 100;
options.Add(CreateMapMenuToggle(
4,
selectedOption,
$"Zoom (Z): {zoomPercent}%",
ToggleCameraZoom));

Expand All @@ -807,7 +825,7 @@ public void EmitMapMenuSignal(int selectedOption = 0) {
options,
Advisor.None,
Mood.None,
hSize: 350,
hSize: 400,
margins: new Margins(top: 100)
)
));
Expand All @@ -824,6 +842,35 @@ private ButtonAction CreateMapMenuToggle(int optionIndex, int selectedOption, st
};
}

public void EmitCleanMapPreferencesSignal() {
List<CheckboxOption> checkboxOptions = new List<CheckboxOption>();
foreach (CleanMapOptionDefinition option in CleanMapSettings.Options) {
CleanMapToggle toggle = option.Toggle;
checkboxOptions.Add(new CheckboxOption() {
message = option.Label,
pressed = CleanMapSettings.Get(toggle),
action = value => {
CleanMapSettings.Set(toggle, value);
mapView?.ApplyCleanMapPreferences();
},
});
}

EmitSignal(SignalName.InteractivePopUp, new ParameterWrapper<InteractablePopUp>(
new OptionsPopUp(
controller.id,
"Clean Map Preferences",
null,
new List<ButtonAction>(),
Advisor.None,
Mood.None,
hSize: 400,
margins: new Margins(top: 100),
checkboxActions: checkboxOptions
)
));
}

public void EmitWorldSettingsSignal() {
WorldCharacteristics settings = EngineStorage.gameData.worldCharacteristics;
int seed = EngineStorage.gameData.seed;
Expand Down
17 changes: 16 additions & 1 deletion C7/Map/CityLayer.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,30 @@
using System.Collections.Generic;
using System.Linq;
using C7.UIElements;
using C7GameData;
using Godot;

namespace C7.Map;

public class CityLayer : LooseLayer {
private Dictionary<City, CityScene> citySceneLookup = new();
private bool mapVisible = true;

public CityLayer() {
}

public void SetMapVisible(bool visible) {
if (mapVisible == visible) {
return;
}
mapVisible = visible;
if (!visible) {
foreach (City city in citySceneLookup.Keys.ToList()) {
EraseCity(city);
}
}
}

public void UpdateAfterCityDestruction(City city) {
EraseCity(city);
}
Expand All @@ -22,7 +37,7 @@ private void EraseCity(City city) {
}

public override void drawObject(LooseView looseView, GameData gameData, Tile tile, Vector2 tileCenter) {
if (tile.cityAtTile is null) {
if (!mapVisible || tile.cityAtTile is null) {
return;
}

Expand Down
16 changes: 13 additions & 3 deletions C7/Map/HillsLayer.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using C7.UIElements;
using C7GameData;
using Godot;
using static C7GameData.TileRandom;
Expand Down Expand Up @@ -34,6 +35,8 @@ public HillsLayer() {

public override void drawObject(LooseView looseView, GameData gameData, Tile tile, Vector2 tileCenter) {
if (!tile.overlayTerrainType.isHilly()) return;
if (CleanMapSettings.IsHiding(CleanMapToggle.HideMountains) && (tile.IsMountains() || tile.IsVolcano())) return;
if (CleanMapSettings.IsHiding(CleanMapToggle.HideHills) && tile.IsHills()) return;

int pcxIndex = GetMountainIndex(tile);

Expand All @@ -47,7 +50,7 @@ public override void drawObject(LooseView looseView, GameData gameData, Tile til
if (tile.isSnowCapped) {
mountainGraphics = snowMountainTexture;
} else {
TerrainType dominantVegetation = GetDominantVegetationNearHillyTile(tile);
TerrainType dominantVegetation = DominantVegetationForHillyTile(tile);
if (dominantVegetation.isForest()) {
mountainGraphics = forestMountainTexture;
} else if (dominantVegetation.isJungle()) {
Expand All @@ -61,7 +64,7 @@ public override void drawObject(LooseView looseView, GameData gameData, Tile til
Rect2 hillsRectangle = new Rect2(column * hillsSize.X, row * hillsSize.Y, hillsSize);
Rect2 screenTarget = new Rect2(tileCenter - (float)0.5 * hillsSize + new Vector2(0, -4), hillsSize);
ImageTexture hillGraphics;
TerrainType dominantVegetation = GetDominantVegetationNearHillyTile(tile);
TerrainType dominantVegetation = DominantVegetationForHillyTile(tile);
if (dominantVegetation.isForest()) {
hillGraphics = forestHillsTexture;
} else if (dominantVegetation.isJungle()) {
Expand All @@ -74,7 +77,7 @@ public override void drawObject(LooseView looseView, GameData gameData, Tile til
Rect2 volcanoRectangle = new Rect2(column * volcanoSize.X, row * volcanoSize.Y, volcanoSize);
Rect2 screenTarget = new Rect2(tileCenter - (float)0.5 * volcanoSize + new Vector2(0, -12), volcanoSize);
ImageTexture volcanoGraphics;
TerrainType dominantVegetation = GetDominantVegetationNearHillyTile(tile);
TerrainType dominantVegetation = DominantVegetationForHillyTile(tile);
if (dominantVegetation.isForest()) {
volcanoGraphics = forestVolcanoTexture;
} else if (dominantVegetation.isJungle()) {
Expand All @@ -87,6 +90,13 @@ public override void drawObject(LooseView looseView, GameData gameData, Tile til

}

private TerrainType DominantVegetationForHillyTile(Tile center) {
if (CleanMapSettings.IsHiding(CleanMapToggle.HideForestsJungles)) {
return TerrainType.NONE;
}
return GetDominantVegetationNearHillyTile(center);
}

private TerrainType GetDominantVegetationNearHillyTile(Tile center) {
TerrainType northeastType = center.neighbors[TileDirection.NORTHEAST].overlayTerrainType;
TerrainType northwestType = center.neighbors[TileDirection.NORTHWEST].overlayTerrainType;
Expand Down
4 changes: 3 additions & 1 deletion C7/Map/TileAssignmentLayer.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Linq;
using System.Collections.Generic;
using C7.UIElements;
using C7GameData;
using Godot;

Expand Down Expand Up @@ -50,7 +51,8 @@ public override void drawObject(LooseView looseView, GameData gameData, Tile til
}

// Only draw yields for our citizens.
if (tile.personWorkingTile?.city != city && tile.cityAtTile != city) {
if (CleanMapSettings.IsHiding(CleanMapToggle.HideFoodShieldIcons)
|| (tile.personWorkingTile?.city != city && tile.cityAtTile != city)) {
return;
}

Expand Down
22 changes: 22 additions & 0 deletions C7/Map/TileOverlayLayer.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using C7.UIElements;
using C7Engine;
using C7GameData;
using Godot;
Expand Down Expand Up @@ -63,6 +64,10 @@ public override void drawObject(LooseView looseView, GameData gameData, Tile til
var improvements = RenderableTerrainImprovements(tile);

foreach (TerrainImprovement ti in improvements.OrderBy(ti => ti.zIndex)) {
if (ShouldHideImprovement(ti.key)) {
continue;
}

switch (ti.key) {
case IRRIGATION:
DrawIrrigation(looseView, tile, screenTarget);
Expand Down Expand Up @@ -92,6 +97,23 @@ public override void drawObject(LooseView looseView, GameData gameData, Tile til
}
}

private static bool ShouldHideImprovement(string key) {
if (CleanMapSettings.IsHiding(CleanMapToggle.HideRoadsRailroads) && (key == ROAD || key == RAILROAD)) {
return true;
}
if (CleanMapSettings.IsHiding(CleanMapToggle.HideIrrigation) && key == IRRIGATION) {
return true;
}
if (CleanMapSettings.IsHiding(CleanMapToggle.HidePollution) && (key == POLLUTION || key == CRATERS)) {
return true;
}
if (CleanMapSettings.IsHiding(CleanMapToggle.HideTerrainBuildings)
&& key != ROAD && key != RAILROAD && key != IRRIGATION && key != POLLUTION && key != CRATERS) {
return true;
}
return false;
}

private List<TerrainImprovement> RenderableTerrainImprovements(Tile tile) {
if (EngineStorage.gameData.observerMode) return tile.overlays.GetImprovements().ToList();

Expand Down
5 changes: 5 additions & 0 deletions C7/Map/UnitLayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using C7.Textures;
using C7.UIElements;
using C7GameData;
using Godot;

Expand Down Expand Up @@ -249,6 +250,10 @@ public MapUnit selectUnitToDisplay(LooseView looseView, Tile tile, List<MapUnit>
}

public override void drawObject(LooseView looseView, GameData gameData, Tile tile, Vector2 tileCenter) {
if (CleanMapSettings.IsHiding(CleanMapToggle.HideUnits)) {
return;
}

if (!UnitsVisible(gameData, looseView.mapView.game.controller, tile)) {
return;
}
Expand Down
34 changes: 29 additions & 5 deletions C7/MapView.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Collections.Generic;
using System;
using C7.Map;
using C7.UIElements;
using Godot;
using C7GameData;

Expand Down Expand Up @@ -68,6 +69,11 @@ public int getRowStartX(int y) {
public GridLayer gridLayer { get; private set; }
public CityLayer cityLayer { get; private set; }
public TileAssignmentLayer tileAssignmentLayer { get; private set; }
public RiverLayer riverLayer { get; private set; }
public ForestLayer forestLayer { get; private set; }
public TileOverlayLayer tileOverlayLayer { get; private set; }
public ResourceLayer resourceLayer { get; private set; }
public BorderLayer borderLayer { get; private set; }

const float MIN_SCALE = 0.1f;
const float MAX_SCALE = 4.0f;
Expand Down Expand Up @@ -139,16 +145,21 @@ public MapView(Game game, int mapWidth, int mapHeight, bool wrapHorizontally, bo
// be drawn behind cities (which are child nodes).
LooseView terrainView = new(this);
terrainView.layers.Add(new TerrainLayer());
terrainView.layers.Add(new RiverLayer());
terrainView.layers.Add(new ForestLayer());
this.riverLayer = new RiverLayer();
terrainView.layers.Add(this.riverLayer);
this.forestLayer = new ForestLayer();
terrainView.layers.Add(this.forestLayer);
terrainView.layers.Add(new MarshLayer());
terrainView.layers.Add(new HillsLayer());
terrainView.layers.Add(new TntLayer());
terrainView.layers.Add(new TileOverlayLayer());
terrainView.layers.Add(new ResourceLayer());
this.tileOverlayLayer = new TileOverlayLayer();
terrainView.layers.Add(this.tileOverlayLayer);
this.resourceLayer = new ResourceLayer();
terrainView.layers.Add(this.resourceLayer);
this.gridLayer = new GridLayer();
terrainView.layers.Add(this.gridLayer);
terrainView.layers.Add(new BorderLayer());
this.borderLayer = new BorderLayer();
terrainView.layers.Add(this.borderLayer);

LooseView cityView = new(this);
this.cityLayer = new();
Expand Down Expand Up @@ -185,6 +196,19 @@ public MapView(Game game, int mapWidth, int mapHeight, bool wrapHorizontally, bo
looseViews.Add(otherView);
}

public void ApplyCleanMapPreferences() {
this.riverLayer.visible = !CleanMapSettings.IsHiding(CleanMapToggle.HideRiversFloodPlains);
this.forestLayer.visible = !CleanMapSettings.IsHiding(CleanMapToggle.HideForestsJungles);
this.borderLayer.visible = !CleanMapSettings.IsHiding(CleanMapToggle.HideTerritoryBoundaries);
this.resourceLayer.visible = !CleanMapSettings.IsHiding(CleanMapToggle.HideNaturalResources);
this.tileOverlayLayer.visible =
!CleanMapSettings.IsHiding(CleanMapToggle.HideRoadsRailroads)
&& !CleanMapSettings.IsHiding(CleanMapToggle.HideIrrigation)
&& !CleanMapSettings.IsHiding(CleanMapToggle.HideTerrainBuildings)
&& !CleanMapSettings.IsHiding(CleanMapToggle.HidePollution);
this.cityLayer.SetMapVisible(!CleanMapSettings.IsHiding(CleanMapToggle.HideCities));
}

public override void _Process(double delta) {
// Redraw everything. This is necessary so that animations play. Maybe we could only update the unit layer but long term I think it's
// better to redraw everything every frame like a typical modern video game.
Expand Down
Loading
Loading