using Godot; using Chessistics.Engine.Model; namespace Chessistics.Scripts.Board; public partial class CellView : Node2D { private ColorRect _background = null!; private ColorRect _highlight = null!; private ColorRect _innerShadow = null!; private Label _label = null!; // Hover outline (4 thin rects forming a border) private ColorRect _hoverTop = null!; private ColorRect _hoverBottom = null!; private ColorRect _hoverLeft = null!; private ColorRect _hoverRight = null!; public Coords Coords { get; private set; } // Warmer, more grounded palette private static readonly Color LightColor = new("#E8D5A8"); // warm parchment private static readonly Color DarkColor = new("#A07850"); // warm walnut private static readonly Color WallColor = new("#3A3A3A"); // charcoal private static readonly Color ProductionColor = new("#4A6E3A"); // deep forest private static readonly Color DemandColor = new("#B8942A"); // aged gold private static readonly Color TransformerColor = new("#8B4513"); // copper brown private static readonly Color HighlightColor = new("#44FF4444"); private static readonly Color HoverOutlineColor = new("#FFFFFF88"); private const int OutlineWidth = 2; public void Setup(Coords coords, CellType cellType, int cellSize) { Coords = coords; Position = new Vector2(coords.Col * cellSize, -coords.Row * cellSize); _background = new ColorRect { Size = new Vector2(cellSize, cellSize), Position = Vector2.Zero, MouseFilter = Control.MouseFilterEnum.Ignore }; var baseColor = coords.IsLight ? LightColor : DarkColor; _background.Color = cellType switch { CellType.Wall => WallColor, CellType.Production => ProductionColor, CellType.Demand => DemandColor, CellType.Transformer => TransformerColor, _ => baseColor }; AddChild(_background); // Subtle inner shadow for depth (top-left lit, bottom-right dark) _innerShadow = new ColorRect { Size = new Vector2(cellSize, cellSize), Position = Vector2.Zero, Color = new Color(0, 0, 0, 0.06f), Visible = cellType == CellType.Empty, MouseFilter = Control.MouseFilterEnum.Ignore }; AddChild(_innerShadow); _highlight = new ColorRect { Size = new Vector2(cellSize, cellSize), Position = Vector2.Zero, Color = HighlightColor, Visible = false, MouseFilter = Control.MouseFilterEnum.Ignore }; AddChild(_highlight); // Hover outline (4 border rects) _hoverTop = CreateBorderRect(new Vector2(cellSize, OutlineWidth), Vector2.Zero); _hoverBottom = CreateBorderRect(new Vector2(cellSize, OutlineWidth), new Vector2(0, cellSize - OutlineWidth)); _hoverLeft = CreateBorderRect(new Vector2(OutlineWidth, cellSize), Vector2.Zero); _hoverRight = CreateBorderRect(new Vector2(OutlineWidth, cellSize), new Vector2(cellSize - OutlineWidth, 0)); _label = new Label { Position = new Vector2(4, 3), Text = "", MouseFilter = Control.MouseFilterEnum.Ignore }; _label.AddThemeFontSizeOverride("font_size", 9); _label.AddThemeColorOverride("font_color", new Color(1, 1, 1, 0.7f)); AddChild(_label); } private ColorRect CreateBorderRect(Vector2 size, Vector2 pos) { var rect = new ColorRect { Size = size, Position = pos, Color = HoverOutlineColor, Visible = false, MouseFilter = Control.MouseFilterEnum.Ignore }; AddChild(rect); return rect; } public void SetLabel(string text) => _label.Text = text; public void SetHighlight(bool on) => _highlight.Visible = on; public void SetHover(bool on) { _hoverTop.Visible = on; _hoverBottom.Visible = on; _hoverLeft.Visible = on; _hoverRight.Visible = on; } public void SetHighlightColor(Color color) { _highlight.Color = color; _highlight.Visible = true; } /// /// Production pulse: warm glow that radiates outward. /// public void FlashProduce(float duration = 0.3f) { _highlight.Color = new Color(0.9f, 0.85f, 0.5f, 0.55f); // warm golden _highlight.Visible = true; var tween = CreateTween(); tween.TweenProperty(_highlight, "color", new Color(0.9f, 0.85f, 0.5f, 0f), duration) .SetEase(Tween.EaseType.Out).SetTrans(Tween.TransitionType.Cubic); tween.TweenCallback(Callable.From(() => _highlight.Visible = false)); } }