76 lines
4.0 KiB
C#
76 lines
4.0 KiB
C#
using System;
|
|
using System.Linq;
|
|
using KernelPanic.Combat;
|
|
using UnityEngine;
|
|
using UnityEngine.UIElements;
|
|
|
|
namespace KernelPanic.UI
|
|
{
|
|
internal sealed class TurnResolutionView : IDisposable
|
|
{
|
|
public Foldout Element { get; } = new() { text = "Turn resolution / actual results", name = "TurnResolution", value = true };
|
|
private readonly Label _sequence = new() { name = "ResolutionSequence", enableRichText = false };
|
|
private readonly ScrollView _actions = new(ScrollViewMode.Vertical) { name = "ResolutionActions" };
|
|
private CombatExecutionTrace _trace;
|
|
public TurnResolutionView()
|
|
{
|
|
Element.AddToClassList("execution-preview");
|
|
_sequence.style.whiteSpace = WhiteSpace.Normal;
|
|
_sequence.text = "Go > Python automation > Python FIFO > Haskell LIFO > Enemies > Cleanup";
|
|
_actions.style.maxHeight = 160;
|
|
_actions.horizontalScrollerVisibility = ScrollerVisibility.Hidden;
|
|
Element.Add(_sequence); Element.Add(_actions);
|
|
Element.RegisterValueChangedCallback(_ => { Refresh(); FitRows(); });
|
|
Element.RegisterCallback<GeometryChangedEvent>(_ => FitRows());
|
|
_sequence.RegisterCallback<GeometryChangedEvent>(_ => FitRows());
|
|
}
|
|
private void FitRows()
|
|
{
|
|
var workspace = Element.GetFirstAncestorOfType<ScrollView>();
|
|
if (workspace == null) return;
|
|
float available = workspace.contentViewport.resolvedStyle.height;
|
|
float heading = Element.Q<Toggle>()?.resolvedStyle.height ?? 24;
|
|
float sequence = _sequence.resolvedStyle.height;
|
|
if (float.IsNaN(available) || float.IsNaN(heading) || float.IsNaN(sequence) || available <= 0) return;
|
|
_actions.style.maxHeight = Math.Max(20, Math.Min(160, available - heading - sequence - 20));
|
|
}
|
|
public void Bind(CombatExecutionTrace trace)
|
|
{
|
|
if (_trace != null) _trace.Changed -= Refresh;
|
|
_trace = trace;
|
|
if (_trace != null) _trace.Changed += Refresh;
|
|
Refresh();
|
|
}
|
|
private void Refresh()
|
|
{
|
|
string stage = _trace?.Stage ?? "Native";
|
|
Element.text = "Turn resolution / " + (stage == "Native" ? "planning & immediate cards" : stage);
|
|
_sequence.text = string.Join(" > ", new[] { "Go", "Automation", "FIFO", "LIFO", "Enemies", "Cleanup" }
|
|
.Select(s => s == stage ? "[ " + s + " ]" : s));
|
|
if (!Element.value) return;
|
|
_actions.Clear();
|
|
if (_trace == null || _trace.Actions.Count == 0)
|
|
_actions.Add(TerminalLayout.BodyText("Play a card or end your turn to see actual results. Hidden intents and random outcomes are revealed only when combat reveals them."));
|
|
else foreach (var action in _trace.Actions)
|
|
{
|
|
var row = new VisualElement();
|
|
row.style.marginBottom = 6;
|
|
var title = TerminalLayout.BodyText($"{(action.Complete ? "done" : "> resolving")} / {action.Stage} / {action.Label}");
|
|
if (!action.Complete) title.style.color = new Color(1f, .75f, .35f);
|
|
row.Add(title);
|
|
row.Add(TerminalLayout.BodyText($"{action.UptimeDamage} Uptime damage / {action.ShieldDamage} Shield damage / +{action.ShieldGranted} Shield"));
|
|
if (action.PlayerUptimeLost > 0 || action.PlayerShieldBlocked > 0)
|
|
row.Add(TerminalLayout.BodyText($"Host: {action.PlayerUptimeLost} Uptime lost / {action.PlayerShieldBlocked} blocked by Shield"));
|
|
foreach (var detail in action.Details) row.Add(TerminalLayout.BodyText(detail));
|
|
_actions.Add(row);
|
|
}
|
|
if (_actions.childCount > 0)
|
|
{
|
|
var latest = _actions[_actions.childCount - 1];
|
|
_actions.schedule.Execute(() => { if (latest.parent != null && Element.value) _actions.ScrollTo(latest); });
|
|
}
|
|
}
|
|
public void Dispose() => Bind(null);
|
|
}
|
|
}
|