|
2 | 2 | using System; |
3 | 3 | using C7Engine; |
4 | 4 | using C7Engine.Lua; |
| 5 | +using C7GameData; |
5 | 6 | using C7GameData.Save; |
6 | 7 | using Serilog; |
7 | 8 |
|
8 | 9 | [Tool] |
9 | 10 | public partial class WorldSetup : Control { |
10 | | - private static ILogger log = LogManager.ForContext<WorldSetup>(); |
| 11 | + private ILogger log = LogManager.ForContext<WorldSetup>(); |
11 | 12 |
|
12 | 13 | [Export] TextureRect background; |
13 | 14 |
|
@@ -57,24 +58,25 @@ public partial class WorldSetup : Control { |
57 | 58 | [Export] TextureRect billion4Large; |
58 | 59 | [Export] TextureRect billion5Large; |
59 | 60 |
|
60 | | - [Export] CheckButton tinySize; |
61 | | - [Export] CheckButton smallSize; |
62 | | - [Export] CheckButton standardSize; |
63 | | - [Export] CheckButton largeSize; |
64 | | - [Export] CheckButton hugeSize; |
65 | | - [Export] CheckButton randomSize; |
66 | | - |
67 | 61 | [Export] TextureButton confirm; |
68 | 62 | [Export] TextureButton cancel; |
69 | 63 |
|
70 | 64 | [Export] LineEdit seedInput; |
71 | 65 |
|
| 66 | + [Export] VBoxContainer worldSizeButtonsContainer; |
| 67 | + |
72 | 68 | WorldCharacteristics.Landform landform = WorldCharacteristics.Landform.Pangaea; |
73 | 69 | WorldCharacteristics.OceanCoverage ocean = WorldCharacteristics.OceanCoverage.Percent_70; |
74 | 70 | WorldCharacteristics.Age age = WorldCharacteristics.Age.Billion_4; |
75 | 71 | WorldCharacteristics.Temperature temp = WorldCharacteristics.Temperature.Temperate; |
76 | 72 | WorldCharacteristics.Climate clim = WorldCharacteristics.Climate.Normal; |
77 | 73 |
|
| 74 | + private WorldSize _worldSize = WorldSize.Generic(); |
| 75 | + |
| 76 | + private int GameSeed => int.Parse(seedInput.Text); |
| 77 | + |
| 78 | + private SaveGame _saveGame; |
| 79 | + |
78 | 80 | // Called when the node enters the scene tree for the first time. |
79 | 81 | public override void _Ready() { |
80 | 82 | background.Texture = TextureLoader.Load("world_setup.background"); |
@@ -266,14 +268,54 @@ public override void _Ready() { |
266 | 268 | billion4Large.Visible = true; |
267 | 269 | billion4.ButtonPressed = true; |
268 | 270 |
|
269 | | - // TODO: handle different map sizes properly (including loading the |
270 | | - // optimal city number, etc) |
271 | | - tinySize.Visible = false; |
272 | | - smallSize.Visible = false; |
273 | | - standardSize.Visible = false; |
274 | | - largeSize.Visible = false; |
275 | | - hugeSize.Visible = false; |
276 | | - randomSize.Visible = false; |
| 271 | + _saveGame = GameModeLoader.Load(GamePaths.GameModesDir, GamePaths.GameMode); |
| 272 | + |
| 273 | + InitMapSizes(); |
| 274 | + } |
| 275 | + |
| 276 | + private void InitMapSizes() { |
| 277 | + var sizeRandom = new Random(); |
| 278 | + |
| 279 | + var worldSizeButtonGroup = new ButtonGroup() { ResourceName = "WorldSizeButtonGroup" }; |
| 280 | + var randomSizeButton = new Civ3MenuButton |
| 281 | + { |
| 282 | + Text = "Random", |
| 283 | + textPosition = Civ3MenuButton.TextPosition.TextRightOfIcon, |
| 284 | + FontSize = 0, |
| 285 | + ButtonGroup = worldSizeButtonGroup, |
| 286 | + ToggleMode = true |
| 287 | + }; |
| 288 | + |
| 289 | + randomSizeButton.Pressed += () => { |
| 290 | + var wss = _saveGame?.WorldSizes ?? []; |
| 291 | + _worldSize = wss.Count > 0 ? wss[sizeRandom.Next(wss.Count)] : WorldSize.Generic(); |
| 292 | + }; |
| 293 | + |
| 294 | + try { |
| 295 | + // Dynamically create a new button for each world size in the game |
| 296 | + foreach (var ws in _saveGame.WorldSizes) { |
| 297 | + var worldSizeButton = new Civ3MenuButton |
| 298 | + { |
| 299 | + Text = ws.name, |
| 300 | + textPosition = Civ3MenuButton.TextPosition.TextRightOfIcon, |
| 301 | + FontSize = 0, |
| 302 | + ButtonGroup = worldSizeButtonGroup, |
| 303 | + ToggleMode = true, |
| 304 | + ButtonPressed = ws.isDefault |
| 305 | + }; |
| 306 | + worldSizeButton.Pressed += () => _worldSize = ws; |
| 307 | + worldSizeButtonsContainer.AddChild(worldSizeButton); |
| 308 | + |
| 309 | + // apply the default immediately (last isDefault=true wins) |
| 310 | + if (ws.isDefault) |
| 311 | + _worldSize = ws; |
| 312 | + } |
| 313 | + |
| 314 | + // Move random as last in the list and drop default map option and |
| 315 | + worldSizeButtonsContainer.AddChild(randomSizeButton); |
| 316 | + } catch (Exception ex) { |
| 317 | + log.Warning(ex, "Failed to load map sizes from game mode."); |
| 318 | + } |
277 | 319 | } |
278 | 320 |
|
279 | 321 | private void ResetLandformGraphics() { |
@@ -313,26 +355,18 @@ private void ResetAgeGraphics() { |
313 | 355 | private void CreateGame() { |
314 | 356 | GlobalSingleton Global = GetNode<GlobalSingleton>("/root/GlobalSingleton"); |
315 | 357 | Global.ResetLoadGameFields(); |
316 | | - SaveGame save = GameModeLoader.Load(GamePaths.GameModesDir, GamePaths.GameMode); |
317 | 358 |
|
318 | | - Global.WorldCharacteristics = new WorldCharacteristics(save) { |
| 359 | + Global.WorldCharacteristics = new WorldCharacteristics(_saveGame) { |
319 | 360 | landform = landform, |
320 | 361 | oceanCoverage = ocean, |
321 | 362 | age = age, |
322 | 363 | climate = clim, |
323 | 364 | temperature = temp, |
324 | | - worldSize = new WorldSize() { |
325 | | - width = 100, |
326 | | - height = 100, |
327 | | - numberOfCivs = 8, |
328 | | - distanceBetweenCivs = 12, |
329 | | - techRate = 240, |
330 | | - optimalNumberOfCities = 20, |
331 | | - }, |
332 | | - mapSeed = Int32.Parse(seedInput.Text), |
| 365 | + worldSize = _worldSize, |
| 366 | + mapSeed = GameSeed, |
333 | 367 | }; |
334 | 368 |
|
335 | | - Global.SaveGame = save; |
| 369 | + Global.SaveGame = _saveGame; |
336 | 370 |
|
337 | 371 | GetTree().ChangeSceneToFile("res://UIElements/NewGame/player_setup.tscn"); |
338 | 372 | } |
|
0 commit comments