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.
139 lines
4.4 KiB
C#
139 lines
4.4 KiB
C#
using Godot;
|
|
using System;
|
|
using Chessistics.Engine.Model;
|
|
|
|
namespace Chessistics.Scripts.UI;
|
|
|
|
public partial class ControlBar : HBoxContainer
|
|
{
|
|
[Signal]
|
|
public delegate void PlayPressedEventHandler();
|
|
[Signal]
|
|
public delegate void PausePressedEventHandler();
|
|
[Signal]
|
|
public delegate void StepPressedEventHandler();
|
|
// Stop removed in campaign mode
|
|
[Signal]
|
|
public delegate void SpeedChangedEventHandler(float speed);
|
|
|
|
private Button _playButton = null!;
|
|
private Button _pauseButton = null!;
|
|
private Button _stepButton = null!;
|
|
// _stopButton removed
|
|
private OptionButton _speedSelect = null!;
|
|
private Label _turnLabel = null!;
|
|
|
|
private static readonly Color BtnBg = new("#2A2A2E");
|
|
private static readonly Color BtnHover = new("#3A3A40");
|
|
private static readonly Color BtnPressed = new("#1A1A1E");
|
|
private static readonly Color BtnDisabled = new("#1E1E20");
|
|
private static readonly Color BtnBorder = new("#444448");
|
|
|
|
public override void _Ready()
|
|
{
|
|
AddThemeConstantOverride("separation", 8);
|
|
|
|
_playButton = CreateStyledButton("PLAY");
|
|
_playButton.Pressed += () => EmitSignal(SignalName.PlayPressed);
|
|
AddChild(_playButton);
|
|
|
|
_pauseButton = CreateStyledButton("PAUSE");
|
|
_pauseButton.Pressed += () => EmitSignal(SignalName.PausePressed);
|
|
AddChild(_pauseButton);
|
|
|
|
_stepButton = CreateStyledButton("STEP");
|
|
_stepButton.Pressed += () => EmitSignal(SignalName.StepPressed);
|
|
AddChild(_stepButton);
|
|
|
|
// Stop button removed in campaign mode
|
|
|
|
// Spacer
|
|
AddChild(new Control { CustomMinimumSize = new Vector2(12, 0) });
|
|
|
|
_speedSelect = new OptionButton { CustomMinimumSize = new Vector2(60, 30) };
|
|
_speedSelect.AddItem("x1", 0);
|
|
_speedSelect.AddItem("x2", 1);
|
|
_speedSelect.AddItem("x4", 2);
|
|
_speedSelect.ItemSelected += OnSpeedSelected;
|
|
AddChild(_speedSelect);
|
|
|
|
// Spacer
|
|
AddChild(new Control { SizeFlagsHorizontal = SizeFlags.ExpandFill });
|
|
|
|
_turnLabel = new Label { Text = "Coup: --" };
|
|
_turnLabel.AddThemeFontSizeOverride("font_size", 13);
|
|
_turnLabel.AddThemeColorOverride("font_color", new Color("#999999"));
|
|
AddChild(_turnLabel);
|
|
|
|
UpdateForPhase(SimPhase.Paused);
|
|
}
|
|
|
|
private static Button CreateStyledButton(string text)
|
|
{
|
|
var btn = new Button
|
|
{
|
|
Text = text,
|
|
CustomMinimumSize = new Vector2(70, 30),
|
|
FocusMode = FocusModeEnum.None
|
|
};
|
|
btn.AddThemeFontSizeOverride("font_size", 11);
|
|
|
|
var normal = MakeStyle(BtnBg);
|
|
var hover = MakeStyle(BtnHover);
|
|
var pressed = MakeStyle(BtnPressed);
|
|
var disabled = MakeStyle(BtnDisabled);
|
|
disabled.BorderColor = new Color("#2A2A2E");
|
|
|
|
btn.AddThemeStyleboxOverride("normal", normal);
|
|
btn.AddThemeStyleboxOverride("hover", hover);
|
|
btn.AddThemeStyleboxOverride("pressed", pressed);
|
|
btn.AddThemeStyleboxOverride("disabled", disabled);
|
|
btn.AddThemeColorOverride("font_disabled_color", new Color("#555555"));
|
|
|
|
return btn;
|
|
}
|
|
|
|
private static StyleBoxFlat MakeStyle(Color bg)
|
|
{
|
|
return new StyleBoxFlat
|
|
{
|
|
BgColor = bg,
|
|
BorderColor = BtnBorder,
|
|
BorderWidthBottom = 1, BorderWidthTop = 1,
|
|
BorderWidthLeft = 1, BorderWidthRight = 1,
|
|
CornerRadiusTopLeft = 4, CornerRadiusTopRight = 4,
|
|
CornerRadiusBottomLeft = 4, CornerRadiusBottomRight = 4,
|
|
ContentMarginLeft = 10, ContentMarginRight = 10,
|
|
ContentMarginTop = 4, ContentMarginBottom = 4
|
|
};
|
|
}
|
|
|
|
private void OnSpeedSelected(long index)
|
|
{
|
|
float speed = index switch
|
|
{
|
|
0 => 1.0f,
|
|
1 => 0.5f,
|
|
2 => 0.25f,
|
|
_ => 1.0f
|
|
};
|
|
EmitSignal(SignalName.SpeedChanged, speed);
|
|
}
|
|
|
|
public void UpdateForPhase(SimPhase phase)
|
|
{
|
|
_playButton.Disabled = phase != SimPhase.Paused && phase != SimPhase.MissionComplete;
|
|
_pauseButton.Disabled = phase != SimPhase.Running;
|
|
_stepButton.Disabled = phase == SimPhase.Running;
|
|
}
|
|
|
|
public void UpdateTurn(int turn)
|
|
{
|
|
_turnLabel.Text = $"Coup: {turn}";
|
|
}
|
|
|
|
public void ResetTurn()
|
|
{
|
|
_turnLabel.Text = "Coup: --";
|
|
}
|
|
}
|