Skip to content
Closed
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
9 changes: 4 additions & 5 deletions C7/UIElements/NewGame/PlayerSetup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ public partial class PlayerSetup : Control {
SaveGame save;
GameSetup gameSetup = new();

// TODO: read this from the rules based on the world size
const int NUM_OPPONENTS = 7;

// Called when the node enters the scene tree for the first time.
public override void _Ready() {
save = GetSave();
Expand Down Expand Up @@ -106,7 +103,9 @@ private void BackToMainMenu() {

private void AddOpponentSelectors() {
// TODO: The number of opponents should come from the rule set.
for (int i = 0; i < NUM_OPPONENTS; ++i) {
int num_opponents = GetNode<GlobalSingleton>("/root/GlobalSingleton").WorldCharacteristics.worldSize.numberOfCivs - 1;

for (int i = 0; i < num_opponents; ++i) {
OptionButton optionButton = new();
StyleBoxFlat styleBox = new() {
BorderColor = Color.Color8(150, 150, 150, 220),
Expand Down Expand Up @@ -134,7 +133,7 @@ private void AddOpponentSelectors() {
opponentListContainer.AddChild(container);
container.AddChild(optionButton);

container.CustomMinimumSize = new Vector2(312.0f / opponentListContainer.Columns, 315.0f / NUM_OPPONENTS);
container.CustomMinimumSize = new Vector2(312.0f / opponentListContainer.Columns, 315.0f / num_opponents);
optionButton.CustomMinimumSize = new Vector2(290.0f / opponentListContainer.Columns, optionButton.CustomMinimumSize.Y);

foreach (Civilization civ in save.Civilizations) {
Expand Down
96 changes: 80 additions & 16 deletions C7/UIElements/NewGame/WorldSetup.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Godot;
using System;
using System.Threading;
using System.Collections.Generic;
using C7GameData;
using C7Engine;
using C7GameData.Save;
Expand Down Expand Up @@ -76,6 +77,60 @@ public partial class WorldSetup : Control {
WorldCharacteristics.Temperature temp = WorldCharacteristics.Temperature.Temperate;
WorldCharacteristics.Climate clim = WorldCharacteristics.Climate.Normal;

// Maybe we refactor all this data later into a separate JSON/config file?
// I wasn't sure if it fit well into the MapGenerator.cs enum-style since it's a lot of integer data to store

private int sizeSelected = 2; // Correlates to standard size being default
private readonly Random sizeRandomizer = new Random();
private readonly List<WorldSize> sizeOptions = new List<WorldSize>
{
// Tiny, index 0
new WorldSize() {
width = 60,
height = 60,
numberOfCivs = 4,
distanceBetweenCivs = 11,
techRate = 160,
optimalNumberOfCities = 14,
},
// Small, index 1
new WorldSize() {
width = 80,
height = 80,
numberOfCivs = 6,
distanceBetweenCivs = 11,
techRate = 200,
optimalNumberOfCities = 17,
},
// Standard, index 2
new WorldSize() {
width = 100,
height = 100,
numberOfCivs = 8,
distanceBetweenCivs = 12,
techRate = 240,
optimalNumberOfCities = 20,
},
// Large, index 3
new WorldSize() {
width = 130,
height = 130,
numberOfCivs = 12,
distanceBetweenCivs = 18,
techRate = 320,
optimalNumberOfCities = 28,
},
// Huge, index 4
new WorldSize() {
width = 160,
height = 160,
numberOfCivs = 16,
distanceBetweenCivs = 24,
techRate = 400,
optimalNumberOfCities = 36,
},
};

// Called when the node enters the scene tree for the first time.
public override void _Ready() {
background.Texture = TextureLoader.Load("world_setup.background");
Expand Down Expand Up @@ -267,14 +322,30 @@ public override void _Ready() {
billion4Large.Visible = true;
billion4.ButtonPressed = true;

// TODO: handle different map sizes properly (including loading the
// optimal city number, etc)
tinySize.Visible = false;
smallSize.Visible = false;
standardSize.Visible = false;
largeSize.Visible = false;
hugeSize.Visible = false;
randomSize.Visible = false;
tinySize.Pressed += () => {
sizeSelected = 0;
};

smallSize.Pressed += () => {
sizeSelected = 1;
};

standardSize.Pressed += () => {
sizeSelected = 2;
};

largeSize.Pressed += () => {
sizeSelected = 3;
};

hugeSize.Pressed += () => {
sizeSelected = 4;
};

randomSize.Pressed += () => {
sizeSelected = sizeRandomizer.Next(sizeOptions.Count);
};

}

private void ResetLandformGraphics() {
Expand Down Expand Up @@ -322,14 +393,7 @@ private void CreateGame() {
age = age,
climate = clim,
temperature = temp,
worldSize = new WorldSize() {
width = 100,
height = 100,
numberOfCivs = 8,
distanceBetweenCivs = 12,
techRate = 240,
optimalNumberOfCities = 20,
},
worldSize = sizeOptions[sizeSelected],
terrainTypes = save.TerrainTypes,
resources = save.Resources,
defaultGovernment = save.Governments.Find(x => x.defaultType),
Expand Down
12 changes: 6 additions & 6 deletions C7/UIElements/NewGame/world_setup.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ text = "WORLD SIZE"
horizontal_alignment = 1

[node name="TinySize" type="CheckButton" parent="Background"]
visible = false
visible = true
layout_mode = 0
offset_left = 167.0
offset_top = 115.0
Expand All @@ -130,7 +130,7 @@ text = "Tiny"
alignment = 2

[node name="SmallSize" type="CheckButton" parent="Background"]
visible = false
visible = true
layout_mode = 0
offset_left = 160.0
offset_top = 137.0
Expand All @@ -148,7 +148,7 @@ text = "Small"
alignment = 2

[node name="StandardSize" type="CheckButton" parent="Background"]
visible = false
visible = true
layout_mode = 0
offset_left = 136.0
offset_top = 159.0
Expand All @@ -167,7 +167,7 @@ text = "Standard"
alignment = 2

[node name="LargeSize" type="CheckButton" parent="Background"]
visible = false
visible = true
layout_mode = 0
offset_left = 162.0
offset_top = 183.0
Expand All @@ -185,7 +185,7 @@ text = "Large"
alignment = 2

[node name="HugeSize" type="CheckButton" parent="Background"]
visible = false
visible = true
layout_mode = 0
offset_left = 163.0
offset_top = 208.0
Expand All @@ -203,7 +203,7 @@ text = "Huge"
alignment = 2

[node name="RandomSize" type="CheckButton" parent="Background"]
visible = false
visible = true
layout_mode = 0
offset_left = 140.0
offset_top = 231.0
Expand Down