Bundles in-flight work on the campaign/missions system (CampaignDef, MissionDef, TerrainPatch, TransformerDef, MissionChecker, CampaignLoader, FlavorBanner, transformer rules), plan files, and matching tests. Baseline commit so the upcoming automation testing harness lands on a clean tree.
99 lines
3.5 KiB
C#
99 lines
3.5 KiB
C#
using Godot;
|
|
using System.Collections.Generic;
|
|
using Chessistics.Engine.Model;
|
|
|
|
namespace Chessistics.Scripts.UI;
|
|
|
|
public partial class ObjectivePanel : VBoxContainer
|
|
{
|
|
private readonly Dictionary<Coords, (Label label, ProgressBar bar, bool completed)> _entries = new();
|
|
|
|
public void Setup(IReadOnlyList<DemandDef> demands)
|
|
{
|
|
foreach (var child in GetChildren())
|
|
child.QueueFree();
|
|
_entries.Clear();
|
|
|
|
var title = new Label { Text = "OBJECTIFS" };
|
|
title.AddThemeFontSizeOverride("font_size", 16);
|
|
title.AddThemeColorOverride("font_color", new Color("#B8942A")); // aged gold
|
|
AddChild(title);
|
|
|
|
AddChild(new HSeparator());
|
|
|
|
foreach (var demand in demands)
|
|
{
|
|
var vbox = new VBoxContainer();
|
|
vbox.AddThemeConstantOverride("separation", 2);
|
|
|
|
var label = new Label { Text = $"{demand.Name}: 0/{demand.Amount} {demand.Cargo}" };
|
|
label.AddThemeFontSizeOverride("font_size", 12);
|
|
label.AddThemeColorOverride("font_color", new Color("#CCCCCC"));
|
|
vbox.AddChild(label);
|
|
|
|
var bar = new ProgressBar
|
|
{
|
|
MinValue = 0,
|
|
MaxValue = demand.Amount,
|
|
Value = 0,
|
|
CustomMinimumSize = new Vector2(180, 14),
|
|
ShowPercentage = false
|
|
};
|
|
|
|
// Style the progress bar
|
|
var bgStyle = new StyleBoxFlat
|
|
{
|
|
BgColor = new Color(0.2f, 0.2f, 0.22f),
|
|
CornerRadiusTopLeft = 3, CornerRadiusTopRight = 3,
|
|
CornerRadiusBottomLeft = 3, CornerRadiusBottomRight = 3
|
|
};
|
|
var fillStyle = new StyleBoxFlat
|
|
{
|
|
BgColor = new Color("#3D6B8E"), // teal fill
|
|
CornerRadiusTopLeft = 3, CornerRadiusTopRight = 3,
|
|
CornerRadiusBottomLeft = 3, CornerRadiusBottomRight = 3
|
|
};
|
|
bar.AddThemeStyleboxOverride("background", bgStyle);
|
|
bar.AddThemeStyleboxOverride("fill", fillStyle);
|
|
vbox.AddChild(bar);
|
|
|
|
AddChild(vbox);
|
|
_entries[demand.Position] = (label, bar, false);
|
|
}
|
|
}
|
|
|
|
public void UpdateProgress(Coords demandCell, string name, int current, int required)
|
|
{
|
|
if (!_entries.TryGetValue(demandCell, out var entry)) return;
|
|
|
|
// Once completed, stop updating
|
|
if (entry.completed) return;
|
|
|
|
// Cap display at required value
|
|
int displayCurrent = Math.Min(current, required);
|
|
entry.label.Text = $"{name}: {displayCurrent}/{required}";
|
|
|
|
// Animate the progress bar value
|
|
var tween = entry.bar.CreateTween();
|
|
tween.TweenProperty(entry.bar, "value", (double)displayCurrent, 0.2f)
|
|
.SetEase(Tween.EaseType.Out).SetTrans(Tween.TransitionType.Cubic);
|
|
|
|
if (current >= required)
|
|
{
|
|
entry.label.Text = $"{name}: {required}/{required}";
|
|
entry.label.AddThemeColorOverride("font_color", new Color("#5AAC5A")); // warm green
|
|
|
|
// Flash the progress bar green
|
|
var fillStyle = new StyleBoxFlat
|
|
{
|
|
BgColor = new Color("#5AAC5A"),
|
|
CornerRadiusTopLeft = 3, CornerRadiusTopRight = 3,
|
|
CornerRadiusBottomLeft = 3, CornerRadiusBottomRight = 3
|
|
};
|
|
entry.bar.AddThemeStyleboxOverride("fill", fillStyle);
|
|
|
|
// Mark as completed — no further updates
|
|
_entries[demandCell] = (entry.label, entry.bar, true);
|
|
}
|
|
}
|
|
}
|