Files
linuxdistro-roguelite/Assets/Scripts/UI/CombatSceneController.NixGo.cs
T

106 lines
6.7 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using KernelPanic.Combat;
using KernelPanic.Core;
using UnityEngine.UIElements;
namespace KernelPanic.UI
{
public sealed partial class CombatSceneController
{
private VisualElement _goScheduler, _governorPanel;
private Label _goHeading, _governorCost;
private Button _governorShortcut;
private ScrollView _goRows;
private readonly Dictionary<NixGovernor, Button> _governorButtons = new();
private readonly Dictionary<long, Button> _goroutineButtons = new();
private void RefreshGovernorPanel()
{
var nix = _combatManager.Nix;
if (!nix.Active) return;
if (_governorPanel == null)
{
_governorPanel = new VisualElement { name = "NixGovernorPanel" };
_governorPanel.AddToClassList("nix-governor-panel");
_governorPanel.Add(SoftwareCardView.Text("CPU GOVERNOR", "nix-heading"));
foreach (NixGovernor governor in Enum.GetValues(typeof(NixGovernor)))
{
var choice = governor;
var button = new Button(() => _combatManager.TrySwitchGovernor(choice)) { name = "Governor" + choice };
button.AddToClassList("nix-governor-choice");
_governorButtons.Add(choice, button); _governorPanel.Add(button);
}
_governorCost = SoftwareCardView.Text("", "nix-switch-cost"); _governorPanel.Add(_governorCost);
_governorShortcut = new Button(() =>
{
_playerPanel.GetFirstAncestorOfType<ScrollView>()?.ScrollTo(_governorPanel);
_governorButtons.Values.FirstOrDefault(button => button.enabledInHierarchy)?.Focus();
}) { name = "GovernorShortcut" };
_governorShortcut.AddToClassList("nix-governor-shortcut");
}
_playerPanel.Add(_governorPanel);
_playerPanel.Insert(1, _governorShortcut);
_governorShortcut.text = $"governor: {nix.Governor.ToString().ToLowerInvariant()} >";
_governorShortcut.tooltip = "Inspect CPU governor policies and switch cost. Scrolls to the configuration controls.";
foreach (var pair in _governorButtons)
{
bool active = pair.Key == nix.Governor;
pair.Value.text = (active ? "> " : " ") + pair.Key.ToString().ToLowerInvariant() + (active ? " ACTIVE" : "")
+ $"\n{nix.DamageFor(pair.Key) - 100:+0;-0;0}% DMG / {nix.ShieldFor(pair.Key) - 100:+0;-0;0}% SHIELD";
pair.Value.EnableInClassList("nix-governor-active", active);
var reason = _combatManager.GetGovernorSwitchBlockReason(pair.Key);
pair.Value.SetEnabled(reason == NixGovernorSwitchBlockReason.None);
pair.Value.tooltip = $"powerManagement.cpuFreqGovernor = \"{pair.Key.ToString().ToLowerInvariant()}\";\nOnce per turn. Applies to card effects when they resolve."
+ (nix.Version >= 5 ? "\nSpecialisation: performance deals 5 to the selected living enemy (first living enemy if none selected); powersave grants 6 Shield; schedutil draws 1." : "")
+ (reason == NixGovernorSwitchBlockReason.None ? "" : $"\nUnavailable: {reason.GetMessage()}.");
}
_governorCost.text = nix.LastSwitchRound == _combatManager.RoundNumber ? "switched this turn"
: nix.SwitchCost == 0 ? "switch cost: FREE / first this wave" : "switch cost: 1 Cycle";
}
private void BuildGoScheduler(VisualElement scheduler)
{
_goScheduler = new VisualElement { name = "GoroutineScheduler" };
_goScheduler.style.display = DisplayStyle.None;
_goScheduler.AddToClassList("goroutine-scheduler");
_goHeading = SoftwareCardView.Text("", "go-heading"); _goScheduler.Add(_goHeading);
_goRows = new ScrollView(ScrollViewMode.Vertical); _goRows.AddToClassList("goroutine-rows");
_goScheduler.Add(_goRows); scheduler.Add(_goScheduler);
}
private void RefreshGoScheduler()
{
if (_goScheduler == null) return;
var combat = _combatManager;
bool visible = combat.Go.Count > 0 || combat.RunConfig?.PrimaryLanguage == Language.Go
|| combat.RunConfig?.SecondaryLanguage == Language.Go
|| combat.HandController.Cards.Any(c => c.Definition.ResolutionTrack == ResolutionTrack.Goroutine);
_goScheduler.style.display = visible ? DisplayStyle.Flex : DisplayStyle.None;
_goHeading.text = $"GOROUTINES / {combat.Go.Count} OF 3 ACTIVE"
+ (combat.PendingGoroutineCard != null ? " / select a PID [Esc] cancel" : "");
foreach (long id in _goroutineButtons.Keys.Where(id => !combat.Go.Active.Any(g => g.Id == id)).ToArray())
{ _goroutineButtons[id].RemoveFromHierarchy(); _goroutineButtons.Remove(id); }
foreach (var work in combat.Go.Active)
{
if (!_goroutineButtons.TryGetValue(work.Id, out var button))
{
long id = work.Id;
button = new Button(() => combat.SelectGoroutine(id)) { name = "Goroutine" + id };
button.AddToClassList("goroutine-row"); _goroutineButtons.Add(id, button); _goRows.Add(button);
}
int damage = combat.DamagePipeline.PreviewIncomingDamage(DamageRequest.PreviewCard(combat.PlayerState,
work.Target, combat.GoroutineDamageAmount(work), Language.Go, false, true, 100, combat.Compilation.DamagePercent));
var enemy = combat.Enemies.FirstOrDefault(e => e.State == work.Target && !e.State.IsDefeated && e.State.CurrentUptime > 0);
string target = enemy?.Name ?? "first living enemy on tick";
string next = work.Resolving ? "RUNNING" : work.DeploymentRound >= combat.RoundNumber ? "starts next round"
: work.LastTickRound >= combat.RoundNumber ? "next round" : "next Interpret";
button.text = $"{(combat.SelectedGoroutine == work ? ">" : " ")} PID {work.Id:000} {work.SourceCard.Definition.DisplayName} {damage} dmg/tick {work.RemainingTicks} ticks\n -> {target} / {next}";
button.userData = work;
button.SetEnabled(combat.CanSurrenderRun && (combat.PendingGoroutineCard == null || combat.IsEligibleGoSelection(work, combat.PendingGoroutineCard)));
button.EnableInClassList("goroutine-running", work.Resolving);
button.EnableInClassList("goroutine-selected", combat.SelectedGoroutine == work);
}
}
}
}