2026-04-10 14:58:03 +02:00
|
|
|
using Godot;
|
|
|
|
|
using System;
|
|
|
|
|
|
|
|
|
|
namespace Chessistics.Scripts.UI;
|
|
|
|
|
|
|
|
|
|
public partial class LevelSelectScreen : Control
|
|
|
|
|
{
|
|
|
|
|
[Signal]
|
|
|
|
|
public delegate void LevelSelectedEventHandler(int levelIndex);
|
|
|
|
|
|
|
|
|
|
private readonly (string name, string desc)[] _levels =
|
|
|
|
|
[
|
|
|
|
|
("Premier Convoi", "Acheminez du bois de la scierie au depot."),
|
|
|
|
|
("Deux Clients", "Fournissez deux destinations depuis une seule scierie."),
|
2026-04-10 22:39:06 +02:00
|
|
|
("Le Col", "Franchissez le mur et gerez deux types de cargaison."),
|
|
|
|
|
("Le Carrefour", "Deux productions, deux demandes, et un carrefour au centre."),
|
|
|
|
|
("Le Labyrinthe", "Un couloir etroit serpente a travers les murs."),
|
2026-04-10 23:24:14 +02:00
|
|
|
("Trois Royaumes", "Trois productions, trois demandes. Gerez un reseau complet."),
|
|
|
|
|
("La Dame Blanche", "La Dame entre en jeu. Portee supreme sur 8 directions."),
|
|
|
|
|
("Le Grand Reseau", "Quatre productions, quatre demandes. Reseau complet.")
|
2026-04-10 14:58:03 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
public override void _Ready()
|
|
|
|
|
{
|
2026-04-10 21:44:12 +02:00
|
|
|
// Full-screen dark background
|
|
|
|
|
var bg = new PanelContainer();
|
|
|
|
|
bg.SetAnchorsPreset(LayoutPreset.FullRect);
|
|
|
|
|
var bgStyle = new StyleBoxFlat { BgColor = new Color(0.12f, 0.12f, 0.14f) };
|
|
|
|
|
bg.AddThemeStyleboxOverride("panel", bgStyle);
|
|
|
|
|
bg.MouseFilter = MouseFilterEnum.Ignore;
|
|
|
|
|
AddChild(bg);
|
|
|
|
|
|
|
|
|
|
// Outer margin
|
2026-04-10 14:58:03 +02:00
|
|
|
var margin = new MarginContainer();
|
2026-04-10 21:44:12 +02:00
|
|
|
margin.SetAnchorsPreset(LayoutPreset.FullRect);
|
|
|
|
|
margin.AddThemeConstantOverride("margin_left", 80);
|
|
|
|
|
margin.AddThemeConstantOverride("margin_right", 80);
|
2026-04-10 14:58:03 +02:00
|
|
|
margin.AddThemeConstantOverride("margin_top", 60);
|
|
|
|
|
margin.AddThemeConstantOverride("margin_bottom", 60);
|
2026-04-10 21:44:12 +02:00
|
|
|
margin.MouseFilter = MouseFilterEnum.Ignore;
|
2026-04-10 14:58:03 +02:00
|
|
|
|
2026-04-10 21:44:12 +02:00
|
|
|
var outerVBox = new VBoxContainer();
|
|
|
|
|
outerVBox.AddThemeConstantOverride("separation", 0);
|
|
|
|
|
outerVBox.MouseFilter = MouseFilterEnum.Ignore;
|
|
|
|
|
|
|
|
|
|
// --- Header section ---
|
|
|
|
|
var headerBox = new VBoxContainer();
|
|
|
|
|
headerBox.AddThemeConstantOverride("separation", 4);
|
|
|
|
|
headerBox.MouseFilter = MouseFilterEnum.Ignore;
|
2026-04-10 14:58:03 +02:00
|
|
|
|
|
|
|
|
var title = new Label
|
|
|
|
|
{
|
|
|
|
|
Text = "CHESSISTICS",
|
|
|
|
|
HorizontalAlignment = HorizontalAlignment.Center
|
|
|
|
|
};
|
2026-04-10 21:44:12 +02:00
|
|
|
title.AddThemeFontSizeOverride("font_size", 48);
|
2026-04-10 14:58:03 +02:00
|
|
|
title.AddThemeColorOverride("font_color", new Color("#FFD700"));
|
2026-04-10 21:44:12 +02:00
|
|
|
headerBox.AddChild(title);
|
2026-04-10 14:58:03 +02:00
|
|
|
|
|
|
|
|
var subtitle = new Label
|
|
|
|
|
{
|
2026-04-10 21:44:12 +02:00
|
|
|
Text = "Selectionnez un niveau",
|
2026-04-10 14:58:03 +02:00
|
|
|
HorizontalAlignment = HorizontalAlignment.Center
|
|
|
|
|
};
|
2026-04-10 21:44:12 +02:00
|
|
|
subtitle.AddThemeFontSizeOverride("font_size", 15);
|
|
|
|
|
subtitle.AddThemeColorOverride("font_color", new Color("#777777"));
|
|
|
|
|
headerBox.AddChild(subtitle);
|
2026-04-10 14:58:03 +02:00
|
|
|
|
2026-04-10 21:44:12 +02:00
|
|
|
outerVBox.AddChild(headerBox);
|
2026-04-10 14:58:03 +02:00
|
|
|
|
2026-04-10 21:44:12 +02:00
|
|
|
// Spacer
|
|
|
|
|
outerVBox.AddChild(new Control { CustomMinimumSize = new Vector2(0, 48) });
|
|
|
|
|
|
2026-04-10 22:39:06 +02:00
|
|
|
// --- Level cards in a scrollable grid ---
|
|
|
|
|
var scroll = new ScrollContainer
|
|
|
|
|
{
|
|
|
|
|
SizeFlagsVertical = SizeFlags.ExpandFill,
|
|
|
|
|
HorizontalScrollMode = ScrollContainer.ScrollMode.Disabled
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var grid = new GridContainer
|
|
|
|
|
{
|
|
|
|
|
Columns = 3,
|
|
|
|
|
SizeFlagsHorizontal = SizeFlags.ShrinkCenter,
|
|
|
|
|
MouseFilter = MouseFilterEnum.Ignore
|
|
|
|
|
};
|
|
|
|
|
grid.AddThemeConstantOverride("h_separation", 28);
|
|
|
|
|
grid.AddThemeConstantOverride("v_separation", 28);
|
2026-04-10 14:58:03 +02:00
|
|
|
|
|
|
|
|
for (int i = 0; i < _levels.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
var (name, desc) = _levels[i];
|
2026-04-10 22:39:06 +02:00
|
|
|
grid.AddChild(CreateLevelCard(i, name, desc));
|
2026-04-10 14:58:03 +02:00
|
|
|
}
|
|
|
|
|
|
2026-04-10 22:39:06 +02:00
|
|
|
scroll.AddChild(grid);
|
|
|
|
|
outerVBox.AddChild(scroll);
|
2026-04-10 21:44:12 +02:00
|
|
|
|
|
|
|
|
margin.AddChild(outerVBox);
|
|
|
|
|
AddChild(margin);
|
2026-04-10 14:58:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Control CreateLevelCard(int index, string name, string description)
|
|
|
|
|
{
|
|
|
|
|
var card = new PanelContainer
|
|
|
|
|
{
|
2026-04-10 21:44:12 +02:00
|
|
|
CustomMinimumSize = new Vector2(300, 240),
|
|
|
|
|
SizeFlagsVertical = SizeFlags.ShrinkCenter
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var cardStyle = new StyleBoxFlat
|
|
|
|
|
{
|
|
|
|
|
BgColor = new Color(0.17f, 0.17f, 0.19f),
|
|
|
|
|
BorderColor = new Color(0.28f, 0.28f, 0.32f),
|
|
|
|
|
BorderWidthBottom = 1,
|
|
|
|
|
BorderWidthTop = 1,
|
|
|
|
|
BorderWidthLeft = 1,
|
|
|
|
|
BorderWidthRight = 1,
|
|
|
|
|
CornerRadiusTopLeft = 8,
|
|
|
|
|
CornerRadiusTopRight = 8,
|
|
|
|
|
CornerRadiusBottomLeft = 8,
|
|
|
|
|
CornerRadiusBottomRight = 8,
|
|
|
|
|
ContentMarginLeft = 24,
|
|
|
|
|
ContentMarginRight = 24,
|
|
|
|
|
ContentMarginTop = 24,
|
|
|
|
|
ContentMarginBottom = 24
|
2026-04-10 14:58:03 +02:00
|
|
|
};
|
2026-04-10 21:44:12 +02:00
|
|
|
card.AddThemeStyleboxOverride("panel", cardStyle);
|
2026-04-10 14:58:03 +02:00
|
|
|
|
|
|
|
|
var vbox = new VBoxContainer();
|
2026-04-10 21:44:12 +02:00
|
|
|
vbox.AddThemeConstantOverride("separation", 10);
|
2026-04-10 14:58:03 +02:00
|
|
|
|
2026-04-10 21:44:12 +02:00
|
|
|
// Level number
|
2026-04-10 14:58:03 +02:00
|
|
|
var numLabel = new Label
|
|
|
|
|
{
|
|
|
|
|
Text = $"Niveau {index + 1}",
|
|
|
|
|
HorizontalAlignment = HorizontalAlignment.Center
|
|
|
|
|
};
|
|
|
|
|
numLabel.AddThemeFontSizeOverride("font_size", 12);
|
2026-04-10 21:44:12 +02:00
|
|
|
numLabel.AddThemeColorOverride("font_color", new Color("#666666"));
|
2026-04-10 14:58:03 +02:00
|
|
|
vbox.AddChild(numLabel);
|
|
|
|
|
|
2026-04-10 21:44:12 +02:00
|
|
|
// Level name
|
2026-04-10 14:58:03 +02:00
|
|
|
var nameLabel = new Label
|
|
|
|
|
{
|
|
|
|
|
Text = name,
|
|
|
|
|
HorizontalAlignment = HorizontalAlignment.Center
|
|
|
|
|
};
|
2026-04-10 21:44:12 +02:00
|
|
|
nameLabel.AddThemeFontSizeOverride("font_size", 22);
|
|
|
|
|
nameLabel.AddThemeColorOverride("font_color", new Color("#EEEEEE"));
|
2026-04-10 14:58:03 +02:00
|
|
|
vbox.AddChild(nameLabel);
|
|
|
|
|
|
2026-04-10 21:44:12 +02:00
|
|
|
// Thin separator
|
|
|
|
|
var sep = new HSeparator { CustomMinimumSize = new Vector2(0, 4) };
|
|
|
|
|
vbox.AddChild(sep);
|
|
|
|
|
|
|
|
|
|
// Description
|
2026-04-10 14:58:03 +02:00
|
|
|
var descLabel = new Label
|
|
|
|
|
{
|
|
|
|
|
Text = description,
|
|
|
|
|
HorizontalAlignment = HorizontalAlignment.Center,
|
2026-04-10 21:44:12 +02:00
|
|
|
AutowrapMode = TextServer.AutowrapMode.Word,
|
|
|
|
|
CustomMinimumSize = new Vector2(240, 0)
|
2026-04-10 14:58:03 +02:00
|
|
|
};
|
2026-04-10 21:44:12 +02:00
|
|
|
descLabel.AddThemeFontSizeOverride("font_size", 13);
|
|
|
|
|
descLabel.AddThemeColorOverride("font_color", new Color("#999999"));
|
2026-04-10 14:58:03 +02:00
|
|
|
vbox.AddChild(descLabel);
|
|
|
|
|
|
2026-04-10 21:44:12 +02:00
|
|
|
// Flexible spacer
|
|
|
|
|
vbox.AddChild(new Control { SizeFlagsVertical = SizeFlags.ExpandFill });
|
|
|
|
|
|
|
|
|
|
// Play button
|
2026-04-10 14:58:03 +02:00
|
|
|
var playBtn = new Button
|
|
|
|
|
{
|
|
|
|
|
Text = "Jouer",
|
2026-04-10 21:44:12 +02:00
|
|
|
CustomMinimumSize = new Vector2(120, 38),
|
|
|
|
|
SizeFlagsHorizontal = SizeFlags.ShrinkCenter
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var btnNormal = new StyleBoxFlat
|
|
|
|
|
{
|
|
|
|
|
BgColor = new Color("#8B6914"),
|
|
|
|
|
CornerRadiusTopLeft = 6,
|
|
|
|
|
CornerRadiusTopRight = 6,
|
|
|
|
|
CornerRadiusBottomLeft = 6,
|
|
|
|
|
CornerRadiusBottomRight = 6,
|
|
|
|
|
ContentMarginLeft = 24,
|
|
|
|
|
ContentMarginRight = 24,
|
|
|
|
|
ContentMarginTop = 8,
|
|
|
|
|
ContentMarginBottom = 8
|
2026-04-10 14:58:03 +02:00
|
|
|
};
|
2026-04-10 21:44:12 +02:00
|
|
|
var btnHover = new StyleBoxFlat
|
|
|
|
|
{
|
|
|
|
|
BgColor = new Color("#B8860B"),
|
|
|
|
|
CornerRadiusTopLeft = 6,
|
|
|
|
|
CornerRadiusTopRight = 6,
|
|
|
|
|
CornerRadiusBottomLeft = 6,
|
|
|
|
|
CornerRadiusBottomRight = 6,
|
|
|
|
|
ContentMarginLeft = 24,
|
|
|
|
|
ContentMarginRight = 24,
|
|
|
|
|
ContentMarginTop = 8,
|
|
|
|
|
ContentMarginBottom = 8
|
|
|
|
|
};
|
|
|
|
|
var btnPressed = new StyleBoxFlat
|
|
|
|
|
{
|
|
|
|
|
BgColor = new Color("#6B5010"),
|
|
|
|
|
CornerRadiusTopLeft = 6,
|
|
|
|
|
CornerRadiusTopRight = 6,
|
|
|
|
|
CornerRadiusBottomLeft = 6,
|
|
|
|
|
CornerRadiusBottomRight = 6,
|
|
|
|
|
ContentMarginLeft = 24,
|
|
|
|
|
ContentMarginRight = 24,
|
|
|
|
|
ContentMarginTop = 8,
|
|
|
|
|
ContentMarginBottom = 8
|
|
|
|
|
};
|
|
|
|
|
playBtn.AddThemeStyleboxOverride("normal", btnNormal);
|
|
|
|
|
playBtn.AddThemeStyleboxOverride("hover", btnHover);
|
|
|
|
|
playBtn.AddThemeStyleboxOverride("pressed", btnPressed);
|
|
|
|
|
playBtn.AddThemeFontSizeOverride("font_size", 15);
|
|
|
|
|
|
2026-04-10 14:58:03 +02:00
|
|
|
var idx = index;
|
|
|
|
|
playBtn.Pressed += () => EmitSignal(SignalName.LevelSelected, idx);
|
|
|
|
|
vbox.AddChild(playBtn);
|
|
|
|
|
|
|
|
|
|
card.AddChild(vbox);
|
|
|
|
|
return card;
|
|
|
|
|
}
|
|
|
|
|
}
|