Chessistics/Scripts/UI/DetailPanel.cs

85 lines
3 KiB
C#
Raw Normal View History

using Godot;
using Chessistics.Engine.Model;
using Chessistics.Scripts.Pieces;
namespace Chessistics.Scripts.UI;
public partial class DetailPanel : PanelContainer
{
[Signal]
public delegate void RemoveRequestedEventHandler(int pieceId);
private Label _infoLabel = null!;
private Button _removeButton = null!;
private int _currentPieceId;
public override void _Ready()
{
var style = new StyleBoxFlat
{
BgColor = new Color(0.14f, 0.14f, 0.16f, 0.95f),
BorderColor = new Color("#444448"),
BorderWidthTop = 1,
CornerRadiusTopLeft = 4, CornerRadiusTopRight = 4,
ContentMarginLeft = 12, ContentMarginRight = 12,
ContentMarginTop = 8, ContentMarginBottom = 8
};
AddThemeStyleboxOverride("panel", style);
var vbox = new VBoxContainer();
vbox.AddThemeConstantOverride("separation", 4);
var title = new Label { Text = "DETAIL" };
title.AddThemeFontSizeOverride("font_size", 13);
title.AddThemeColorOverride("font_color", new Color("#B8942A"));
vbox.AddChild(title);
_infoLabel = new Label { Text = "" };
_infoLabel.AddThemeFontSizeOverride("font_size", 11);
_infoLabel.AddThemeColorOverride("font_color", new Color("#CCCCCC"));
vbox.AddChild(_infoLabel);
_removeButton = new Button { Text = "Retirer", CustomMinimumSize = new Vector2(80, 26) };
_removeButton.AddThemeFontSizeOverride("font_size", 11);
var btnStyle = new StyleBoxFlat
{
BgColor = new Color("#5A2A2A"),
CornerRadiusTopLeft = 4, CornerRadiusTopRight = 4,
CornerRadiusBottomLeft = 4, CornerRadiusBottomRight = 4,
ContentMarginLeft = 8, ContentMarginRight = 8,
ContentMarginTop = 2, ContentMarginBottom = 2
};
_removeButton.AddThemeStyleboxOverride("normal", btnStyle);
_removeButton.Pressed += () => EmitSignal(SignalName.RemoveRequested, _currentPieceId);
vbox.AddChild(_removeButton);
AddChild(vbox);
Visible = false;
}
public void ShowPiece(PieceSnapshot piece)
{
_currentPieceId = piece.Id;
var kindName = piece.Kind switch
{
PieceKind.Pawn => "Pion",
PieceKind.Rook => "Tour II",
PieceKind.Bishop => "Fou II",
PieceKind.Knight => "Cavalier",
PieceKind.Queen => "Dame",
_ => piece.Kind.ToString()
};
var cargoText = piece.Cargo != null ? piece.Cargo.Value.ToString() : "aucun";
_infoLabel.Text = $"{kindName} (ID: {piece.Id})\n" +
$"Trajet: {piece.StartCell} ↔ {piece.EndCell}\n" +
$"Statut social: {piece.SocialStatus}\n" +
$"Porte: {cargoText}";
Visible = true;
}
public new void Hide() => Visible = false;
public int? CurrentPieceId => Visible ? _currentPieceId : null;
}