Chessistics/Scripts/Board/CellView.cs
Samuel Bouchet 2d2375e569 Polish transformer visuals with copper flash and new cargo colors
CellView gains FlashTransform: bright copper pulse + brief scale punch
(0.45s) on CargoConvertedEvent, distinct from the warmer golden
FlashProduce used by productions. EventAnimator routes transformer
conversions through the new phase so the flash reads as a conversion
moment rather than a second production tick.

PieceView picks up cargo colors for Tools (copper), Arms (deep red),
and Gold, matching the cargo-slide particle palette — pieces carrying
those transformed cargoes now render the correct indicator instead of
defaulting to white.
2026-04-17 22:42:03 +02:00

157 lines
5.7 KiB
C#

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;
}
/// <summary>
/// Production pulse: warm glow that radiates outward.
/// </summary>
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));
}
/// <summary>
/// Transformer conversion flash: bright copper pulse + scale punch.
/// Uses a distinct color from production so the two phases read apart.
/// </summary>
public void FlashTransform(float duration = 0.45f)
{
_highlight.Color = new Color(1f, 0.5f, 0.15f, 0.7f); // bright copper
_highlight.Visible = true;
var tween = CreateTween();
tween.SetParallel(true);
tween.TweenProperty(_highlight, "color", new Color(1f, 0.5f, 0.15f, 0f), duration)
.SetEase(Tween.EaseType.Out).SetTrans(Tween.TransitionType.Cubic);
tween.TweenProperty(_background, "scale", new Vector2(1.08f, 1.08f), duration * 0.45f)
.SetEase(Tween.EaseType.Out);
tween.Chain().TweenProperty(_background, "scale", Vector2.One, duration * 0.55f)
.SetEase(Tween.EaseType.InOut);
tween.Chain().TweenCallback(Callable.From(() => _highlight.Visible = false));
}
}