Rebalance most languages and revamp main game loop

This commit is contained in:
2026-10-25 23:50:04 +01:00
parent 53f831d91e
commit a4109f5be0
76 changed files with 4198 additions and 573 deletions
+6 -1
View File
@@ -53,6 +53,11 @@ namespace KernelPanic.UI
public static VisualElement BuildBrowser(string initialPile,
IReadOnlyDictionary<string, IReadOnlyList<CardInstance>> inventories, Action close,
Func<CardInstance, string> costDetails = null)
=> BuildBrowser(initialPile, inventories, close, costDetails, CardEffectFactory.GetRulesText);
public static VisualElement BuildBrowser(string initialPile,
IReadOnlyDictionary<string, IReadOnlyList<CardInstance>> inventories, Action close,
Func<CardInstance, string> costDetails, Func<CardInstance, string> rulesText)
{
var piles = inventories.ToDictionary(pair => pair.Key,
pair => (pair.Value ?? Array.Empty<CardInstance>()).Where(card => card?.Definition != null).ToArray());
@@ -180,7 +185,7 @@ namespace KernelPanic.UI
var card = copies[0];
var face = new VisualElement { name = "PileCard", userData = copies.Length };
face.AddToClassList("pile-card");
SoftwareCardView.Populate(face, card, CombatManager.GetCardCost(card));
SoftwareCardView.Populate(face, card, CombatManager.GetCardCost(card), rulesText(card));
face.Q<Label>(className: "software-cost").text = $"{CombatManager.GetCardCost(card)}c stored";
// The full rules remain inline; no hover is required for keyboard or touch readers.
face.tooltip = string.Empty;
@@ -1795,7 +1795,7 @@ namespace KernelPanic.UI
summary.Add(meta);
row.Add(summary);
Label description = new(GetCardCollectionDescription(entry.Card));
Label description = new(GetOwnedCardRules(entry.Card));
description.AddToClassList("package-description");
row.Add(description);
return row;
@@ -1810,7 +1810,7 @@ namespace KernelPanic.UI
if (card == null) return;
var manifest = new VisualElement();
manifest.AddToClassList("collection-manifest");
SoftwareCardView.Populate(manifest, new CardInstance(card), card.CycleCost);
SoftwareCardView.Populate(manifest, new CardInstance(card), card.CycleCost, GetOwnedCardRules(card));
_detail.Add(manifest);
if (!string.IsNullOrWhiteSpace(card.FlavorText))
{
@@ -1820,6 +1820,13 @@ namespace KernelPanic.UI
}
}
private string GetOwnedCardRules(CardDefinition card)
{
var distro = _units.FirstOrDefault(unit => unit.ExclusiveCards.Contains(card));
return distro == null ? GetCardCollectionDescription(card)
: CardEffectFactory.GetRulesText(new CardInstance(card), distro.Id, GetUnitVersion(distro));
}
private static string GetCardCollectionDescription(CardDefinition card)
{
if (card == null)
@@ -1827,11 +1834,6 @@ namespace KernelPanic.UI
return "--";
}
if (!string.IsNullOrWhiteSpace(card.Description))
{
return card.Description;
}
string rulesText = CardEffectFactory.GetRulesText(new CardInstance(card));
return string.IsNullOrWhiteSpace(rulesText) || rulesText == "effect not authored." ? "--" : rulesText;
}
+189 -25
View File
@@ -117,6 +117,7 @@ namespace KernelPanic.UI
private string _saveError;
private string _checkpointError;
private bool _routeSelectionOpen;
private bool _routeEventOpen;
private DailyQuestTracker _dailyQuestTracker;
private IVisualElementScheduledItem _dailyQuestSaveSchedule;
private CombatRunTelemetry _runTelemetry;
@@ -500,7 +501,11 @@ namespace KernelPanic.UI
_lazyStackPile.name = "TutorialStack";
_queueView = new ExecutionTrackView(_interpreterStrip, false);
_stackView = new ExecutionTrackView(_lazyStackPile, true);
_tokenArea = AddTrackZone(scheduler, "|| goroutines", "no active runtime", "track-zone-token");
_tokenArea = AddTrackZone(scheduler, "py automation", "2 script slots / expires at wave end", "track-zone-token");
_tokenArea.name = "PythonAutomationReadout";
_tokenArea.style.flexDirection = FlexDirection.Column;
_tokenArea.style.alignItems = Align.Stretch;
_tokenArea.style.width = Length.Percent(100);
_root.Add(scheduler);
VisualElement bottom = new();
@@ -648,7 +653,7 @@ namespace KernelPanic.UI
header.Add(subtitleLabel);
zone.Add(header);
var scroll = new ScrollView(className == "track-zone-stack" ? ScrollViewMode.Vertical : ScrollViewMode.Horizontal);
var scroll = new ScrollView(className == "track-zone-queue" ? ScrollViewMode.Horizontal : ScrollViewMode.Vertical);
scroll.AddToClassList("track-scroll");
VisualElement contents = new();
contents.AddToClassList("track-contents");
@@ -747,10 +752,10 @@ namespace KernelPanic.UI
}
RunConfig config = _runManager.CurrentConfig;
_waveLabel.text = _runManager.Journey.campaign && !_runManager.Journey.endless
? $"{Math.Min(RunJourney.BossWave, _runManager.CurrentWaveNumber)}/{RunJourney.BossWave}"
? $"{Math.Min(_runManager.Journey.FinalWave, _runManager.CurrentWaveNumber)}/{_runManager.Journey.FinalWave}"
: _runManager.CurrentWaveNumber.ToString();
_waveLabel.tooltip = _runManager.Journey.campaign && !_runManager.Journey.endless
? "Clear five waves, defeat the Kernel Overseer, then finish or continue into endless mode."
? $"Clear {_runManager.Journey.FinalWave} waves, defeat the Kernel Overseer, then finish or continue into endless mode."
: "Endless mode";
if (config?.IsTutorial == true)
{
@@ -866,10 +871,19 @@ namespace KernelPanic.UI
_stackView.EndExecution();
}
_tokenArea.Clear();
_tokenArea.Add(EmptyState("inactive"));
((VisualElement)_tokenArea.userData).EnableInClassList("track-idle", true);
bool pythonIdle = _combatManager.Python.AutomationCount == 0
&& _combatManager.Python.RepeatCount == 0 && _combatManager.Python.AreaCount == 0;
IEnumerable<string> pythonReadout = pythonIdle ? new[] { "0 / 2 slots" } : _combatManager.Python.Readout;
foreach (string line in pythonReadout)
{
var label = new Label(line);
label.style.whiteSpace = WhiteSpace.Normal;
_tokenArea.Add(label);
}
((VisualElement)_tokenArea.userData).EnableInClassList("track-idle", _combatManager.Python.AutomationCount == 0);
_root.Q(className: "scheduler").EnableInClassList("scheduler-idle",
_combatManager.InterpreterQueue.Count == 0 && _combatManager.LazyStack.Count == 0);
_combatManager.InterpreterQueue.Count == 0 && _combatManager.LazyStack.Count == 0
&& _combatManager.Python.AutomationCount == 0 && _combatManager.Python.RepeatCount == 0 && _combatManager.Python.AreaCount == 0);
((VisualElement)_interpreterStrip.userData).EnableInClassList("track-resolving", _combatManager.CurrentPhase == TurnPhase.Interpret);
}
@@ -1163,7 +1177,8 @@ namespace KernelPanic.UI
["exhaust"] = new List<CardInstance>(_combatManager.DeckController.ExhaustPile)
};
inventories[pile] = new List<CardInstance>(cards);
_overlay.Add(CardPileView.BuildBrowser(pile, inventories, ClosePileInspector, _combatManager.GetPileCostDetails));
_overlay.Add(CardPileView.BuildBrowser(pile, inventories, ClosePileInspector, _combatManager.GetPileCostDetails,
card => CardEffectFactory.GetRulesText(card, _combatManager.RunConfig)));
_overlay.style.display = DisplayStyle.Flex;
_overlay.Q<TextField>("PileSearch")?.Focus();
}
@@ -1204,7 +1219,7 @@ namespace KernelPanic.UI
victory = _combatManager.RunCompleted
};
_runTelemetry?.FillReport(entry);
if (entry.victory) entry.cause = "Kernel Overseer defeated. Five-wave campaign complete.";
if (entry.victory) entry.cause = $"Kernel Overseer defeated. {_runManager.Journey.FinalWave}-wave campaign complete.";
entry.cause ??= entry.surrendered ? "Shutdown signal accepted." : "Uptime reached 0; no damaging action recorded.";
_runHistoryEntry = entry;
return entry;
@@ -1287,6 +1302,75 @@ namespace KernelPanic.UI
return;
}
if (_combatManager.Python.HasChoice && !_combatManager.RunFinished)
{
_pileInspectorOpen = false;
_overlay.RemoveFromClassList("pile-overlay");
TerminalTheme.PreserveFocus(_overlay);
_overlay.Clear();
_overlay.style.display = DisplayStyle.Flex;
_overlay.AddToClassList("python-choice-overlay");
var dialog = new VisualElement { name = "PythonChoiceDialog" };
dialog.AddToClassList("python-choice-dialog");
dialog.Add(SoftwareCardView.Text("[ python / select one ]", "python-choice-eyebrow"));
string heading = _combatManager.Python.ChoiceTitle;
int separator = heading.IndexOf(':');
dialog.Add(SoftwareCardView.Text(separator < 0 ? heading : heading.Substring(0, separator), "python-choice-title"));
if (separator >= 0)
dialog.Add(SoftwareCardView.Text(heading.Substring(separator + 1).Trim(), "python-choice-description"));
var choices = new ScrollView(ScrollViewMode.Vertical) { name = "PythonChoiceScroll" };
choices.AddToClassList("python-choice-scroll");
choices.horizontalScrollerVisibility = ScrollerVisibility.Hidden;
choices.contentContainer.AddToClassList("python-choice-grid");
for (int i = 0; i < _combatManager.Python.Choices.Count; i++)
{
int index = i;
var option = _combatManager.Python.Choices[i];
var button = new Button(() => _combatManager.Python.Choose(index)) { name = $"PythonChoice{index}" };
if (option.Card != null)
SoftwareCardView.Populate(button, option.Card, option.Cost,
CardEffectFactory.GetRulesText(option.Card, _combatManager.RunConfig));
else
button.Add(SoftwareCardView.Text(option.Label, "python-choice-description"));
button.AddToClassList("python-choice-option");
// These choices already show the complete rules; a repeated tooltip
// would cover the dialog header on small screens.
button.tooltip = null;
button.Add(SoftwareCardView.Text(option.ActionLabel ?? "> replace script", "python-choice-action"));
button.SetEnabled(option.Enabled);
choices.Add(button);
}
dialog.Add(choices);
dialog.Add(SoftwareCardView.Text("Tab / Shift+Tab to browse · Enter to select", "python-choice-hint"));
// Intercept focus before ScrollView tracks it: its automatic scrolling
// aligns oversized cards to their bottom, hiding the card's name.
dialog.RegisterCallback<FocusInEvent>(evt =>
{
if (evt.target is not Button focused || !focused.ClassListContains("python-choice-option")) return;
evt.StopPropagation();
void RevealChoice()
{
if (focused.worldBound.height > choices.contentViewport.worldBound.height)
choices.scrollOffset = new Vector2(0, Mathf.Max(0,
focused.worldBound.yMin - choices.contentContainer.worldBound.yMin));
else choices.ScrollTo(focused);
}
RevealChoice();
// Repeat after layout for newly attached cards, but never scroll back
// to a stale selection after the player has moved focus again.
choices.schedule.Execute(() =>
{
if (dialog.focusController?.focusedElement == focused) RevealChoice();
});
}, TrickleDown.TrickleDown);
TerminalTheme.ConstrainModalFocus(dialog);
_overlay.Add(dialog);
choices.Query<Button>().ToList().Find(b => b.enabledSelf)?.Focus();
return;
}
_overlay.RemoveFromClassList("python-choice-overlay");
if (_pileInspectorOpen && !_combatManager.RunFinished && !_combatManager.AwaitingWaveContinue
&& _combatManager.CurrentPhase == TurnPhase.Execute) return;
_pileInspectorOpen = false;
@@ -1298,6 +1382,7 @@ namespace KernelPanic.UI
if (_combatManager.RunFinished)
{
_routeSelectionOpen = false;
_routeEventOpen = false;
SettleRunRewardsIfNeeded();
_overlay.style.display = DisplayStyle.Flex;
_overlay.Add(BuildRunEndOverlay());
@@ -1322,6 +1407,7 @@ namespace KernelPanic.UI
}
_routeSelectionOpen = false;
_routeEventOpen = false;
_overlay.style.display = DisplayStyle.None;
}
@@ -1528,25 +1614,33 @@ namespace KernelPanic.UI
private void SetRouteSelectionOpen(bool open)
{
_routeSelectionOpen = open;
_routeEventOpen = false;
RefreshOverlay();
_overlay.Q<Button>(open ? "BackToRepositoryButton" : "BootNextWaveButton")?.Focus();
}
private VisualElement BuildRouteSelectionView()
{
var screen = new VisualElement { name = "RouteSelectionScreen" };
bool reward = _runManager.BuildRewardPending;
bool eventScreen = !reward && _routeEventOpen && !_runManager.CampaignChoicePending;
bool committed = eventScreen && !_runManager.RouteEventPending;
var screen = new VisualElement { name = reward ? "BuildRewardScreen" : eventScreen ? "RouteEventScreen" : "RouteSelectionScreen" };
screen.AddToClassList("repository");
screen.AddToClassList("screen-frame");
screen.AddToClassList("route-map-screen");
var header = new VisualElement();
header.AddToClassList("repository-header");
header.AddToClassList("screen-frame-header");
var copy = new VisualElement();
copy.AddToClassList("repository-header-copy");
var title = new Label(_runManager.CampaignChoicePending ? "campaign complete" : "choose your route");
var title = new Label(_runManager.CampaignChoicePending ? "campaign complete" : reward ? "claim your build reward"
: eventScreen ? RunRouteMap.Title(_runManager.Journey.selectedRoute) : "choose your route");
title.AddToClassList("screen-frame-title");
copy.Add(title);
var subtitle = new Label(_runManager.CampaignChoicePending
? "bank your rewards or continue into endless"
: reward ? "1 / claim reward > 2 / choose route > 3 / enter stop"
: eventScreen ? committed ? "stop complete / ready for battle" : "choose your cards / nothing changes until you confirm"
: $"preparing wave {_runManager.CurrentWaveNumber} / {_runManager.Bits} bits remaining");
subtitle.AddToClassList("repository-subtitle");
copy.Add(subtitle);
@@ -1556,29 +1650,99 @@ namespace KernelPanic.UI
var body = new ScrollView(ScrollViewMode.Vertical);
body.AddToClassList("repository-body");
body.AddToClassList("screen-frame-content");
body.Add(RunRouteView.Build(_runManager, _combatManager));
body.Add(reward ? RunRouteView.BuildReward(_runManager)
: eventScreen ? RunMapView.BuildEvent(_runManager) : RunRouteView.Build(_runManager, _combatManager));
if (!reward && !eventScreen && !_runManager.CampaignChoicePending)
{
body.AddToClassList("route-map-body");
body.contentViewport.RegisterCallback<GeometryChangedEvent>(evt =>
{
var mapScroll = body.Q<ScrollView>("RouteMapScroll");
if (mapScroll != null)
mapScroll.style.height = Mathf.Max(260, evt.newRect.height - 20);
});
}
if (committed)
{
var save = new Button(SaveAndExitRun) { name = "SaveAndExitRunButton", text = "save and exit / keep this result" };
save.AddToClassList("secondary-action"); body.Add(save);
}
screen.Add(body);
var footer = new VisualElement();
footer.AddToClassList("screen-frame-footer");
footer.style.flexDirection = FlexDirection.Column;
footer.style.alignItems = Align.Stretch;
var back = new Button(() => SetRouteSelectionOpen(false))
{ name = "BackToRepositoryButton", text = "< back to repository" };
back.AddToClassList("primary-action");
footer.Add(back);
if (!_runManager.CampaignChoicePending)
footer.AddToClassList("route-map-footer");
var back = new Button(() =>
{
var confirm = new Button(() => _combatManager.ContinueToNextWave())
if (!eventScreen) SetRouteSelectionOpen(false);
else if (_runManager.RouteEventPending)
{
_routeEventOpen = false; RefreshOverlay();
_overlay.Q<Button>("ConfirmRouteButton")?.Focus();
}
})
{ name = eventScreen ? "BackToRouteButton" : "BackToRepositoryButton",
text = committed ? "stop committed" : eventScreen ? "< back to map" : "< back to repository" };
back.SetEnabled(!committed);
back.AddToClassList("primary-action");
back.AddToClassList("route-map-back");
footer.Add(back);
screen.RegisterCallback<KeyDownEvent>(evt =>
{
if (evt.keyCode != KeyCode.Escape || !back.enabledSelf) return;
using var submit = NavigationSubmitEvent.GetPooled();
submit.target = back; back.SendEvent(submit); evt.StopPropagation();
});
void MoveAction(string name, string caption = null)
{
var button = body.Q<Button>(name);
if (button == null) return;
button.RemoveFromHierarchy();
if (caption != null) button.text = caption;
if (name == "ResolveRouteEventButton")
{
string fullCaption = button.text;
button.RegisterCallback<GeometryChangedEvent>(evt => button.text = evt.newRect.width < 160 ? "apply" : fullCaption);
}
button.AddToClassList("primary-action");
button.AddToClassList(name is "ClaimBuildRewardButton" or "ResolveRouteEventButton" ? "route-map-continue" : "route-map-back");
footer.Add(button);
}
if (reward)
{
back.text = "< back"; back.tooltip = "Back to repository";
MoveAction("RewardBits", $"{RunManager.BuildRewardBits} Bits");
MoveAction("ClaimBuildRewardButton", "claim");
}
else if (eventScreen && !committed)
{
back.text = "< map";
MoveAction("SkipRouteEventButton", "pass");
MoveAction("ResolveRouteEventButton");
}
else if (!_runManager.CampaignChoicePending)
{
var confirm = new Button(() =>
{
if (_runManager.RouteEventPending && !eventScreen)
{
_routeEventOpen = true; RefreshOverlay();
_overlay.Q<Button>("BackToRouteButton")?.Focus();
}
else _combatManager.ContinueToNextWave();
})
{
name = "ConfirmRouteButton",
text = _runManager.BuildRewardPending ? "choose a build reward to continue" : "> depart / boot next-wave"
text = eventScreen ? committed ? "> continue to battle" : "confirm or pass above"
: _runManager.RouteEventPending ? "> enter stop" : "> continue to battle"
};
confirm.AddToClassList("primary-action");
confirm.SetEnabled(!_runManager.BuildRewardPending && !_runManager.IsSuspended);
confirm.AddToClassList("route-map-continue");
confirm.SetEnabled((!eventScreen || committed) && !_runManager.IsSuspended);
footer.Add(confirm);
}
screen.Add(footer);
if (committed) screen.schedule.Execute(() => screen.Q<Button>("ConfirmRouteButton")?.Focus());
return screen;
}
@@ -1810,13 +1974,13 @@ namespace KernelPanic.UI
{
VisualElement face = new();
face.AddToClassList("hand-card");
SoftwareCardView.Populate(face, card, GetDisplayCardCost(card));
SoftwareCardView.Populate(face, card, GetDisplayCardCost(card), CardEffectFactory.GetRulesText(card, _combatManager.RunConfig));
return face;
}
private void PopulateCardFace(VisualElement target, CardInstance card)
{
SoftwareCardView.Populate(target, card, GetDisplayCardCost(card));
SoftwareCardView.Populate(target, card, GetDisplayCardCost(card), CardEffectFactory.GetRulesText(card, _combatManager.RunConfig));
var preview = CardPreviewService.Build(_combatManager, card);
if (!string.IsNullOrEmpty(preview.Summary) && !preview.Summary.StartsWith("Utility", StringComparison.Ordinal))
{
@@ -2158,7 +2322,7 @@ namespace KernelPanic.UI
{
VisualElement chip = CardChip(cards[i]);
chip.Insert(0, SoftwareCardView.Text($"{i + 1:00} >", "execution-order"));
chip.tooltip = CardEffectFactory.GetRulesText(cards[i]);
chip.tooltip = CardEffectFactory.GetRulesText(cards[i], _combatManager.RunConfig);
if (target == _interpreterStrip)
{
_queueChipElements[cards[i]] = chip;
+174
View File
@@ -0,0 +1,174 @@
using System;
using KernelPanic.Meta;
using UnityEngine;
using UnityEngine.UIElements;
namespace KernelPanic.UI
{
public static class DailyQuestView
{
public static Button BuildWidget(DailyQuestState state, DateTime utcNow, Action open)
{
var widget = new Button(open) { name = "DailyQuestWidget", tooltip = "Open daily quests (Enter)" };
widget.AddToClassList("daily-quest-widget");
var counts = Counts(state);
var heading = new VisualElement();
heading.AddToClassList("daily-service-summary");
heading.Add(TerminalLayout.Heading("[ cron.daily ]", className: "daily-service-title"));
var reward = TerminalLayout.BodyText(counts.Ready == 1 ? "1 reward ready" : $"{counts.Ready} rewards ready",
"DailyQuestRewardReady", "daily-reward-ready");
reward.style.display = counts.Ready > 0 ? DisplayStyle.Flex : DisplayStyle.None;
heading.Add(reward);
widget.Add(heading);
widget.Add(TerminalLayout.BodyText(DailyQuests.Countdown(state, utcNow), "DailyQuestCountdown", "daily-service-meta"));
var summary = new VisualElement();
summary.AddToClassList("daily-service-summary");
summary.Add(TerminalLayout.BodyText($"{counts.Completed}/{DailyQuests.Count} completed", "DailyQuestCompleted", "daily-service-meta"));
summary.Add(TerminalLayout.BodyText($"{counts.Claimed} claimed", "DailyQuestClaimed", "daily-service-meta"));
widget.Add(summary);
foreach (var kind in DailyQuests.Active(state))
{
var row = new VisualElement();
row.AddToClassList("daily-service-entry");
row.EnableInClassList("daily-service-ready", !DailyQuests.Claimed(state, kind)
&& DailyQuests.Progress(state, kind) >= DailyQuests.Target(kind));
row.EnableInClassList("daily-service-claimed", DailyQuests.Claimed(state, kind));
row.Add(TerminalLayout.BodyText(ShortName(kind), className: "daily-service-name"));
row.Add(TerminalLayout.BodyText($"{DailyQuests.Progress(state, kind)}/{DailyQuests.Target(kind)}", className: "daily-service-progress"));
widget.Add(row);
}
widget.Add(TerminalLayout.BodyText(counts.Ready > 0 ? "> claim available rewards" : "> inspect tasks",
"DailyQuestInspect", "daily-service-command"));
widget.EnableInClassList("daily-has-rewards", counts.Ready > 0);
// Child copy is part of one button, not additional focus targets.
widget.Query<VisualElement>().ForEach(child => { if (child != widget) child.pickingMode = PickingMode.Ignore; });
widget.RegisterCallback<KeyDownEvent>(evt =>
{
if (evt.keyCode == KeyCode.Escape)
{
widget.Blur();
widget.panel?.focusController.IgnoreEvent(evt);
evt.StopImmediatePropagation();
return;
}
if (evt.keyCode != KeyCode.Return && evt.keyCode != KeyCode.KeypadEnter) return;
open();
widget.panel?.focusController.IgnoreEvent(evt);
evt.StopImmediatePropagation();
});
return widget;
}
private static (int Completed, int Claimed, int Ready) Counts(DailyQuestState state)
{
int completed = 0, claimed = 0, ready = 0;
foreach (var kind in DailyQuests.Active(state))
{
bool complete = DailyQuests.Progress(state, kind) >= DailyQuests.Target(kind);
if (complete) completed++;
if (DailyQuests.Claimed(state, kind)) claimed++;
else if (complete) ready++;
}
return (completed, claimed, ready);
}
public static void RefreshHeader(VisualElement overlay, DailyQuestState state, DateTime utcNow)
{
overlay.Q<Label>("DailyQuestDetailCountdown").text = DailyQuests.Countdown(state, utcNow).Replace("refresh in ", "reset ");
overlay.Q<Label>("DailyQuestDetailSummary").text = $"{DailyQuests.Count} tasks / {Counts(state).Completed} completed";
}
private static string ShortName(DailyQuestKind kind) => kind switch
{
DailyQuestKind.Waves => "Waves cleared",
DailyQuestKind.Cards => "Cards played",
DailyQuestKind.Damage => "Uptime damage",
DailyQuestKind.BlockDamage => "Damage blocked",
DailyQuestKind.NativeCards => "Native cards",
DailyQuestKind.ShieldDamage => "Enemy Shield damage",
DailyQuestKind.SurviveRounds => "Rounds survived",
DailyQuestKind.WaveFive => "Wave 5 cleared",
_ => DailyQuests.Description(kind)
};
public static VisualElement BuildOverlay(DailyQuestState state, DateTime utcNow,
Action<DailyQuestKind, long> claim, Action close)
{
var overlay = new VisualElement { name = "DailyQuestOverlay" };
overlay.AddToClassList("modal-overlay");
overlay.AddToClassList("modal-open");
overlay.AddToClassList("daily-quest-overlay");
var dialog = new VisualElement { name = "DailyQuestDialog" };
dialog.AddToClassList("daily-quest-dialog");
var header = new VisualElement { name = "DailyQuestHeader" };
header.AddToClassList("daily-detail-header");
header.Add(TerminalLayout.BodyText("$ cat /etc/cron.daily/quests", className: "daily-detail-command"));
var titleRow = new VisualElement();
titleRow.AddToClassList("daily-service-summary");
titleRow.Add(TerminalLayout.Heading("DAILY TASKS", className: "daily-service-title"));
titleRow.Add(TerminalLayout.BodyText("", "DailyQuestDetailCountdown", "daily-service-meta"));
header.Add(titleRow);
header.Add(TerminalLayout.BodyText("", "DailyQuestDetailSummary", "daily-service-meta"));
dialog.Add(header);
var scroll = new ScrollView(ScrollViewMode.Vertical) { name = "DailyQuestDetailScroll" };
scroll.AddToClassList("daily-quest-detail-scroll");
scroll.horizontalScrollerVisibility = ScrollerVisibility.Hidden;
scroll.Add(Build(state, utcNow, claim));
dialog.Add(scroll);
var feedback = TerminalLayout.BodyText("", "DailyQuestFeedback", "daily-quest-feedback");
feedback.style.display = DisplayStyle.None;
dialog.Add(feedback);
var dismiss = new Button(close) { name = "CloseDailyQuests", text = "[ Esc ] close" };
dismiss.AddToClassList("terminal-button");
dialog.Add(dismiss);
overlay.Add(dialog);
RefreshHeader(overlay, state, utcNow);
overlay.RegisterCallback<KeyDownEvent>(evt =>
{
if (evt.keyCode == KeyCode.Escape) { close(); evt.StopImmediatePropagation(); }
});
TerminalTheme.ConstrainModalFocus(overlay);
return overlay;
}
public static VisualElement Build(DailyQuestState state, DateTime utcNow, Action<DailyQuestKind, long> claim)
{
var panel = new VisualElement { name = "DailyQuestsPanel" };
panel.AddToClassList("daily-quests");
var quests = new VisualElement();
quests.AddToClassList("daily-quest-list");
panel.Add(quests);
long period = state.refreshAtUtcTicks;
foreach (var kind in DailyQuests.Active(state))
{
var row = new VisualElement { name = "DailyQuest" + kind };
row.AddToClassList("daily-quest");
int progress = DailyQuests.Progress(state, kind);
bool claimed = DailyQuests.Claimed(state, kind);
bool complete = progress >= DailyQuests.Target(kind);
row.EnableInClassList("daily-quest-complete", complete);
row.EnableInClassList("daily-quest-claimed", claimed);
row.Add(TerminalLayout.BodyText(DailyQuests.Description(kind), className: "daily-quest-name"));
int filled = progress * 10 / DailyQuests.Target(kind);
var progressRow = new VisualElement();
progressRow.AddToClassList("daily-detail-progress-row");
progressRow.Add(TerminalLayout.BodyText($"[{new string('#', filled)}{new string('.', 10 - filled)}]",
className: "daily-detail-progress"));
progressRow.Add(TerminalLayout.BodyText($"{progress}/{DailyQuests.Target(kind)}", className: "daily-detail-values"));
row.Add(progressRow);
var reward = DailyQuests.Reward(kind);
row.Add(TerminalLayout.BodyText($"+{reward.Bandwidth} Bandwidth / +{reward.Entropy} Entropy"));
var button = new Button(() => claim(kind, period))
{ name = "ClaimDailyQuest" + kind, text = claimed ? "[ CLAIMED ]" : complete ? "> CLAIM REWARD" : "[ in progress ]" };
button.AddToClassList("terminal-button");
button.AddToClassList("daily-claim-action");
button.EnableInClassList("daily-claim-ready", !claimed && complete);
button.EnableInClassList("daily-claim-done", claimed);
button.SetEnabled(!claimed && complete);
row.Add(button);
quests.Add(row);
}
return panel;
}
}
}
+1 -1
View File
@@ -81,7 +81,7 @@ namespace KernelPanic.UI
{
if (_disposed) return;
foreach (var card in pending)
Chip(card).tooltip = CardEffectFactory.GetRulesText(card) + "\n\n" + CardPreviewService.Build(combat, card).Details;
Chip(card).tooltip = CardEffectFactory.GetRulesText(card, combat.RunConfig) + "\n\n" + CardPreviewService.Build(combat, card).Details;
}
public void Resolving(CardInstance card)
+1 -1
View File
@@ -71,7 +71,7 @@ namespace KernelPanic.UI
_tracks.Add(_resources);
AddTrack("NOW / Native", "Executes when played.");
if (config?.PrimaryLanguage == Language.Python || config?.SecondaryLanguage == Language.Python)
AddTrack("1 / Python queue", "End turn: oldest first.");
AddTrack("1 / Python pipeline", "Preparation acts immediately. End turn: scripts run, then FIFO modifiers and payloads. Loops repeat; zip spreads damage. Two script slots, cleared each wave.");
if (config?.PrimaryLanguage == Language.Haskell || config?.SecondaryLanguage == Language.Haskell)
AddTrack("2 / Haskell stack", "After the queue: newest first. Entry multiplier scales damage and Shield.");
AddTrack("LAST / Enemies", "Surviving enemies carry out their intents.");
+4 -5
View File
@@ -2,6 +2,7 @@ using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using KernelPanic.Combat;
using KernelPanic.Core;
using KernelPanic.Data;
using KernelPanic.Meta;
@@ -2123,11 +2124,9 @@ namespace KernelPanic.UI
summary.ElementAt(2).AddToClassList("package-meta");
row.Add(summary);
if (!string.IsNullOrWhiteSpace(card.Description))
{
row.Add(new Label(card.Description) { name = "RunSetupCardDescription" });
row.ElementAt(1).AddToClassList("package-description");
}
row.Add(new Label(CardEffectFactory.GetRulesText(new CardInstance(card), unit.Id,
_playerCollection?.GetVersion(unit.Id) ?? 1)) { name = "RunSetupCardDescription" });
row.ElementAt(1).AddToClassList("package-description");
if (!string.IsNullOrWhiteSpace(card.FlavorText))
{
+362
View File
@@ -0,0 +1,362 @@
using System;
using System.Collections.Generic;
using System.Linq;
using KernelPanic.Combat;
using KernelPanic.Run;
using UnityEngine;
using UnityEngine.UIElements;
namespace KernelPanic.UI
{
internal static class RunMapView
{
public static VisualElement Build(RunManager run)
{
var layout = new VisualElement { name = "RunMap" };
layout.AddToClassList("route-map-layout");
var map = new VisualElement { name = "RouteGraph" };
map.AddToClassList("route-map-graph");
if (run.Journey.mapStartWave > 2)
map.Add(Text("Earlier decisions are unavailable for this older save. Your map starts here.", "route-map-legend"));
int current = run.CurrentWaveNumber, seed = run.CurrentConfig.RunSeed;
int revision = run.Journey.mapRevision, startWave = run.Journey.mapStartWave;
int first = run.Journey.endless ? Math.Max(startWave, current - 3) : startWave;
int last = run.Journey.endless ? current + 5 : run.Journey.FinalWave;
IReadOnlyList<RouteNode> Row(int wave) => RunRouteMap.Row(seed, wave, startWave, revision);
bool Connected(RouteNode a, RouteNode b) => RunRouteMap.Connected(seed, a, b, startWave, revision);
var detail = new VisualElement { name = "RouteDetails" };
detail.AddToClassList("route-map-detail");
var preview = new VisualElement { name = "RoutePreview" };
detail.Add(preview);
void Preview(RouteNode node)
{
if (node == null) return;
preview.Clear();
bool boss = node.Wave == run.Journey.FinalWave && !run.Journey.endless;
string phase = run.Journey.endless ? "SURVIVAL" : node.Wave <= 3 ? "BOOT SECTOR"
: node.Wave <= 6 ? "ESCALATION" : boss ? "FINAL ENCOUNTER" : "KERNEL PERIMETER";
preview.Add(Text($"{node.Wave:00} / {(run.Journey.endless ? "ENDLESS" : run.Journey.FinalWave.ToString("00"))} {phase}", "route-map-eyebrow"));
string state = node.Wave < current ? run.Journey.visits.Any(v => v.nodeId == node.Id) ? "CLEARED" : "NOT TAKEN"
: node.Wave > current ? "FUTURE STOP" : node.Id == run.Journey.selectedNodeId ? "SELECTED DESTINATION"
: run.AvailableRouteNodes.Any(n => n.Id == node.Id) ? "AVAILABLE / select to take this path" : "UNREACHABLE FROM HERE";
preview.Add(Text(state, "route-preview-state"));
preview.Add(Text(boss ? "Kernel Overseer" : RunRouteMap.Title(node.Route), "route-detail-title"));
preview.Add(Text(boss ? "Defeat the Overseer to complete the route. Bank your rewards, or continue this build in endless survival."
: RunRouteMap.Detail(node.Route), "route-detail-copy"));
var encounter = EncounterDirector.Plan(node.Wave, node.Route, seed, run.Journey.encounterRevision);
preview.Add(Text("BATTLE / " + encounter.Title, "route-map-eyebrow"));
preview.Add(Text(encounter.Advice, "route-detail-copy"));
if (node.Wave == current && run.Journey.resolvedEventWave == current && node.Id == run.Journey.selectedNodeId)
preview.Add(Text("[ resolved ]\n" + run.Journey.eventOutcome, "route-map-history"));
}
void SelectedPreview() => Preview(Row(current).FirstOrDefault(n => n.Id == run.Journey.selectedNodeId));
var available = run.AvailableRouteNodes.Select(n => n.Id).ToHashSet();
var chosen = run.Journey.visits.ToDictionary(v => v.wave, v => v.nodeId);
chosen[current] = run.Journey.selectedNodeId;
var potential = new HashSet<int> { run.Journey.selectedNodeId };
var lit = new HashSet<int>(potential);
for (int wave = current + 1; wave <= last; wave++)
{
var before = Row(wave - 1);
var after = Row(wave);
potential = after.Where(to => before.Any(from => potential.Contains(from.Id)
&& Connected(from, to))).Select(n => n.Id).ToHashSet();
lit.UnionWith(potential);
}
// One coordinate space for both nodes and trails. Future is up; travelled ground is below.
bool origin = first == startWave;
int bottom = origin ? first - 1 : first;
const float pitch = 96, radius = 30, top = 48;
var scroll = new ScrollView(ScrollViewMode.Vertical) { name = "RouteMapScroll" };
scroll.AddToClassList("route-map-scroll");
scroll.horizontalScrollerVisibility = ScrollerVisibility.Hidden;
var canvas = new VisualElement { name = "RouteCanvas" };
canvas.AddToClassList("route-map-canvas");
canvas.style.height = top + (last - bottom) * pitch + 62;
var nodesById = new Dictionary<int, VisualElement>();
var points = new Dictionary<int, Vector2>();
var rows = new Dictionary<int, IReadOnlyList<RouteNode>>();
void AddMarker(int id, int wave, float position, VisualElement marker)
{
marker.style.position = Position.Absolute;
marker.style.top = top + (last - wave) * pitch - radius;
marker.style.left = new Length(12 + position * 76, LengthUnit.Percent);
marker.style.marginLeft = -radius;
marker.userData = id;
nodesById.Add(id, marker); canvas.Add(marker);
}
for (int wave = first; wave <= last; wave++)
{
var nodes = Row(wave);
rows.Add(wave, nodes);
var waveLabel = Text(wave.ToString("00"), "route-map-wave");
waveLabel.style.top = top + (last - wave) * pitch - 42;
canvas.Add(waveLabel);
foreach (var node in nodes)
{
bool selected = chosen.TryGetValue(wave, out int id) && id == node.Id;
bool reachable = wave == current ? available.Contains(node.Id) : wave > current && lit.Contains(node.Id);
VisualElement tile;
if (wave == current)
{
var button = new Button(() => run.SelectRouteNode(node.Id)) { name = "Route" + node.Route };
button.SetEnabled(reachable && run.Journey.resolvedEventWave != current);
tile = button;
}
else tile = new VisualElement { name = "MapNode" + node.Id };
tile.AddToClassList("route-map-node");
tile.EnableInClassList("map-choice", wave == current && reachable);
tile.EnableInClassList("map-selected", wave == current && selected);
tile.EnableInClassList("map-taken", wave < current && selected);
tile.EnableInClassList("map-muted", !selected && !reachable);
tile.EnableInClassList("map-future", wave > current);
tile.EnableInClassList("map-boss", wave == run.Journey.FinalWave && !run.Journey.endless);
tile.Add(Glyph(node.Route));
tile.Add(Text(wave == run.Journey.FinalWave && !run.Journey.endless ? "BOSS" : CompactTitle(node.Route), "route-map-name"));
tile.tooltip = $"Wave {wave} / {RunRouteMap.Title(node.Route)}\n{RunRouteMap.Detail(node.Route)}";
tile.RegisterCallback<MouseEnterEvent>(_ => Preview(node));
tile.RegisterCallback<MouseLeaveEvent>(_ => SelectedPreview());
tile.RegisterCallback<FocusInEvent>(_ => Preview(node));
tile.RegisterCallback<FocusOutEvent>(_ => SelectedPreview());
AddMarker(node.Id, wave, nodes.Count == 1 ? .5f : (float)nodes.ToList().IndexOf(node) / (nodes.Count - 1), tile);
if (selected && wave == current - 1)
{
tile.name = "CurrentMapPosition";
var here = Text("YOU ARE HERE", "route-map-here"); tile.Add(here);
}
}
}
if (origin)
{
var start = new VisualElement { name = current == startWave ? "CurrentMapPosition" : "RouteStart" };
start.AddToClassList("route-map-node"); start.AddToClassList("map-taken");
start.Add(Text("OK", "route-map-symbol")); start.Add(Text("Cleared", "route-map-name"));
if (current == startWave) start.Add(Text("YOU ARE HERE", "route-map-here"));
start.tooltip = $"Wave {startWave - 1} cleared. The route begins here.";
AddMarker(-1, bottom, .5f, start);
}
var edges = new List<(int from, int to, bool taken, bool active, bool future)>();
foreach (var row in rows)
{
if (!rows.TryGetValue(row.Key + 1, out var next)) continue;
foreach (var a in row.Value)
foreach (var b in next)
{
if (!Connected(a, b)) continue;
bool taken = b.Wave < current && chosen.TryGetValue(a.Wave, out int aId) && aId == a.Id
&& chosen.TryGetValue(b.Wave, out int bId) && bId == b.Id;
bool active = a.Wave == current - 1 ? chosen.GetValueOrDefault(a.Wave) == a.Id && b.Id == run.Journey.selectedNodeId
: a.Wave >= current && lit.Contains(a.Id);
edges.Add((a.Id, b.Id, taken, active, a.Wave >= current));
}
}
if (origin) foreach (var node in rows[first])
edges.Add((-1, node.Id, first < current && chosen.GetValueOrDefault(first) == node.Id,
first == current && node.Id == run.Journey.selectedNodeId, false));
canvas.generateVisualContent += context =>
{
points.Clear();
foreach (var entry in nodesById)
points[entry.Key] = entry.Value.layout.center;
var painter = context.painter2D;
// Muted trails first, then the player's path. At crossings the active trail stays legible.
foreach (var edge in edges.OrderBy(e => e.taken || e.active))
{
Vector2 a = points[edge.from], b = points[edge.to];
var direction = (b - a).normalized;
a += direction * radius; b -= direction * radius;
Color color = edge.taken ? new Color(.48f, .76f, .59f) : edge.active ? new Color(.91f, .72f, .43f) : new Color(.24f, .33f, .28f);
// A dark under-stroke separates real crossings without inventing junctions.
Trail(painter, a, b, new Color(.055f, .085f, .067f), 7, false);
Trail(painter, a, b, color, edge.active || edge.taken ? 2.5f : 1.5f, edge.future);
}
};
canvas.RegisterCallback<GeometryChangedEvent>(_ => canvas.MarkDirtyRepaint());
scroll.Add(canvas); map.Add(scroll);
bool positioned = false;
scroll.RegisterCallback<GeometryChangedEvent>(_ =>
{
if (positioned || scroll.contentViewport.layout.height < 20) return;
positioned = true;
scroll.schedule.Execute(() =>
{
var here = canvas.Q("CurrentMapPosition");
if (here != null)
scroll.scrollOffset = new Vector2(0, Mathf.Max(0, here.layout.yMax + 36 - scroll.contentViewport.layout.height));
});
});
var choices = nodesById.Values.OfType<Button>().Where(b => b.enabledSelf).OrderBy(b => (int)b.userData).ToList();
void MoveFocus(int direction)
{
if (choices.Count == 0) return;
int index = choices.FindIndex(b => b == layout.focusController?.focusedElement);
var next = choices[(index + direction + choices.Count) % choices.Count];
next.Focus(); scroll.ScrollTo(next);
}
canvas.RegisterCallback<NavigationMoveEvent>(evt =>
{
if (evt.direction is not (NavigationMoveEvent.Direction.Left or NavigationMoveEvent.Direction.Right
or NavigationMoveEvent.Direction.Up or NavigationMoveEvent.Direction.Down)) return;
MoveFocus(evt.direction is NavigationMoveEvent.Direction.Left or NavigationMoveEvent.Direction.Up ? -1 : 1);
evt.StopPropagation(); evt.PreventDefault();
});
canvas.RegisterCallback<KeyDownEvent>(evt =>
{
if (evt.keyCode is not (KeyCode.W or KeyCode.A or KeyCode.S or KeyCode.D)) return;
MoveFocus(evt.keyCode is KeyCode.W or KeyCode.A ? -1 : 1);
evt.StopPropagation();
});
if (run.Journey.visits.Count > 0)
{
var history = new Foldout { text = "Travel journal / " + run.Journey.visits.Count + " decisions", value = false, name = "RouteHistory" };
history.AddToClassList("route-map-journal");
foreach (var visit in run.Journey.visits)
history.Add(Text($"Wave {visit.wave} / {RunRouteMap.Title(visit.route)}\n{visit.outcome}", "route-map-history"));
detail.Add(history);
}
layout.Add(map);
SelectedPreview();
layout.Add(detail);
return layout;
}
private static void Trail(Painter2D painter, Vector2 a, Vector2 b, Color color, float width, bool dotted)
{
painter.strokeColor = color; painter.lineWidth = width;
if (!dotted)
{
painter.BeginPath(); painter.MoveTo(a); painter.LineTo(b); painter.Stroke();
return;
}
float length = Vector2.Distance(a, b);
for (float offset = 0; offset < length; offset += 10)
{
painter.BeginPath(); painter.MoveTo(Vector2.Lerp(a, b, offset / length));
painter.LineTo(Vector2.Lerp(a, b, Mathf.Min(offset + 4, length) / length)); painter.Stroke();
}
}
private static VisualElement Glyph(WaveRoute route)
{
var glyph = new VisualElement { pickingMode = PickingMode.Ignore };
glyph.AddToClassList("route-map-glyph");
glyph.generateVisualContent += context =>
{
var p = context.painter2D; p.strokeColor = glyph.resolvedStyle.color; p.lineWidth = 1.8f;
void Line(params Vector2[] points)
{
p.BeginPath(); p.MoveTo(points[0]); foreach (var point in points.Skip(1)) p.LineTo(point); p.Stroke();
}
switch (route)
{
case WaveRoute.Repair:
Line(new(12, 3), new(12, 21)); Line(new(3, 12), new(21, 12)); break;
case WaveRoute.Challenge:
Line(new(4, 3), new(20, 3), new(20, 13), new(12, 22), new(4, 13), new(4, 3));
Line(new(12, 7), new(12, 13)); Line(new(12, 16), new(12, 17)); break;
case WaveRoute.Cache:
Line(new(3, 8), new(12, 3), new(21, 8), new(21, 20), new(3, 20), new(3, 8), new(21, 8));
Line(new(12, 9), new(12, 14)); break;
case WaveRoute.Forge:
Line(new(5, 19), new(16, 8)); Line(new(10, 4), new(14, 2), new(22, 10), new(19, 14), new(10, 4)); break;
case WaveRoute.Sacrifice:
Line(new(12, 2), new(18, 9), new(12, 16), new(6, 9), new(12, 2));
Line(new(3, 21), new(5, 17), new(19, 17), new(21, 21), new(3, 21)); break;
case WaveRoute.Recycle:
Line(new(4, 8), new(9, 3), new(19, 3), new(21, 8)); Line(new(16, 8), new(21, 8), new(21, 2));
Line(new(20, 16), new(15, 21), new(5, 21), new(3, 16)); Line(new(8, 16), new(3, 16), new(3, 22)); break;
default:
Line(new(6, 14), new(12, 8), new(18, 14)); Line(new(6, 21), new(12, 15), new(18, 21)); break;
}
};
return glyph;
}
public static VisualElement BuildEvent(RunManager run)
{
var content = new VisualElement { name = "RouteEventContent" };
content.AddToClassList("departure-content");
content.Add(Text(RunRouteMap.Detail(run.Journey.selectedRoute), "route-detail-copy"));
if (run.RouteEventPending) content.Add(Event(run));
else content.Add(Text("STOP COMPLETE\n" + run.Journey.eventOutcome, "route-event-result"));
return content;
}
private static VisualElement Event(RunManager run)
{
var panel = new VisualElement { name = "RouteEvent" }; panel.AddToClassList("route-event");
var selectors = new VisualElement(); selectors.AddToClassList("departure-selectors"); panel.Add(selectors);
bool remove = run.Journey.selectedRoute is WaveRoute.Sacrifice or WaveRoute.Recycle;
bool upgrade = run.Journey.selectedRoute is WaveRoute.Sacrifice or WaveRoute.Forge;
int amount = run.Journey.selectedRoute == WaveRoute.Sacrifice ? 4 : 2;
var donors = run.RunDeck.Where(c => c.Definition != null && !c.Definition.IsToken
&& (run.Journey.selectedRoute != WaveRoute.Sacrifice || !c.Definition.IsJunk)).ToList();
var targets = run.RunDeck.Where(run.CanImproveRouteCard).ToList();
int donorIndex = 0, targetIndex = Math.Max(0, targets.FindIndex(c => !remove || donors.Count == 0 || c != donors[0]));
var previews = new VisualElement(); previews.AddToClassList("departure-previews");
var result = Text("", "route-event-result");
var commit = new Button { name = "ResolveRouteEventButton", text = run.Journey.selectedRoute switch
{ WaveRoute.Sacrifice => "sacrifice & empower", WaveRoute.Forge => "apply patch", _ => "recycle card" } };
commit.AddToClassList("primary-action");
CardInstance Donor() => remove && donors.Count > 0 ? donors[donorIndex] : null;
CardInstance Target() => upgrade && targets.Count > 0 ? targets[targetIndex] : null;
void Refresh()
{
previews.Clear();
var donor = Donor(); var target = Target();
if (donor != null) previews.Add(Preview(donor, run, "REMOVE FROM THIS RUN"));
if (target != null)
{
previews.Add(Preview(target, run, "BEFORE UPGRADE"));
var after = target.CopyForCombat(); after.ApplyMagnitudeUpgrade(amount);
previews.Add(Preview(after, run, $"AFTER / +{amount} EFFECT"));
}
bool valid = (!remove || (donor != null && run.RunDeck.Count > 1)) && (!upgrade || target != null)
&& (!remove || !upgrade || donor != target);
result.text = !valid ? run.Journey.selectedRoute == WaveRoute.Sacrifice
? "Choose two different cards, or pass if there are no eligible cards. Your deck must keep at least one card."
: "No eligible card is selected. You may pass; your deck must keep at least one card."
: remove ? $"{donor.Definition.DisplayName} will leave this run's deck. " + (upgrade ? $"{target.Definition.DisplayName}: +{target.MagnitudeBonus} -> +{target.MagnitudeBonus + amount} effect." : "Receive 4 Bits.")
: $"{target.Definition.DisplayName}: +{target.MagnitudeBonus} -> +{target.MagnitudeBonus + amount} effect.";
if (run.BuildRewardPending) result.text = "Choose your build reward first, then resolve this stop.";
commit.SetEnabled(valid && !run.BuildRewardPending);
}
if (remove && donors.Count > 0)
{
var picker = new DropdownField("Card to remove", donors.Select((c, i) => $"{i + 1}. {c.Definition.DisplayName}").ToList(), donorIndex) { name = "RouteDonor" };
picker.RegisterValueChangedCallback(_ => { donorIndex = picker.index; Refresh(); }); selectors.Add(picker);
}
if (upgrade && targets.Count > 0)
{
var picker = new DropdownField("Card to empower", targets.Select((c, i) => $"{i + 1}. {c.Definition.DisplayName}").ToList(), targetIndex) { name = "RouteTarget" };
picker.RegisterValueChangedCallback(_ => { targetIndex = picker.index; Refresh(); }); selectors.Add(picker);
}
panel.Add(Text("Run only; your collection is unaffected. Confirm or pass to commit this path.", "route-detail-copy"));
panel.Add(previews); panel.Add(result);
commit.clicked += () => run.ResolveRouteEvent(Donor(), Target());
panel.Add(commit);
var skip = new Button(() => run.ResolveRouteEvent(skip: true)) { text = "pass / keep my deck", name = "SkipRouteEventButton" };
skip.AddToClassList("secondary-action"); skip.SetEnabled(!run.BuildRewardPending); panel.Add(skip);
Refresh();
return panel;
}
private static VisualElement Preview(CardInstance card, RunManager run, string heading)
{
var holder = new VisualElement(); holder.AddToClassList("route-event-card"); holder.AddToClassList("departure-card");
holder.Add(Text(heading, "route-map-eyebrow"));
var face = new VisualElement();
SoftwareCardView.Populate(face, card, CombatManager.GetCardCost(card), CardEffectFactory.GetRulesText(card, run.CurrentConfig));
holder.Add(face); return holder;
}
private static Label Text(string text, string style) => SoftwareCardView.Text(text, style);
private static string CompactTitle(WaveRoute route) => route switch
{
WaveRoute.Repair => "Repair", WaveRoute.Challenge => "Elite", WaveRoute.Cache => "Cache",
WaveRoute.Forge => "Patch", WaveRoute.Sacrifice => "Altar", WaveRoute.Recycle => "Scrap", _ => "Path"
};
}
}
+76 -35
View File
@@ -11,45 +11,21 @@ namespace KernelPanic.UI
{
public static VisualElement Build(RunManager run, CombatManager combat)
{
var section = TerminalLayout.Section(run.CampaignChoicePending ? "KERNEL SECURED" : "Route", "RunRouteChoices");
var section = run.Journey.mapRevision > 0 && !run.CampaignChoicePending
? new VisualElement { name = "RunRouteChoices" }
: TerminalLayout.Section(run.CampaignChoicePending ? "KERNEL SECURED" : "Route", "RunRouteChoices");
section.AddToClassList("run-route-section");
if (!string.IsNullOrEmpty(run.Journey.lastReward)) section.Add(TerminalLayout.BodyText(run.Journey.lastReward));
if (run.BuildRewardPending)
{
section.Add(TerminalLayout.BodyText("Build reward / choose one before departure. Upgrade a card for this run, or take Bits to spend freely."));
var cards = run.RunDeck.Where(card => card.Definition != null && !card.Definition.IsToken && !card.Definition.IsJunk).ToList();
if (cards.Count > 0)
{
int selected = 0;
var target = TerminalLayout.BodyText("", "BuildRewardTarget");
section.Add(target);
var navigation = new VisualElement();
navigation.AddToClassList("reward-target-navigation");
section.Add(navigation);
section.Add(Action($"Upgrade effect +{CombatTuning.UpgradeMagnitudeBonus}", "RewardMagnitude",
() => run.ClaimBuildReward(cards[selected], CardUpgradeKind.MagnitudeUp)));
var draw = Action("Add draw 1 on resolution", "RewardDraw",
() => run.ClaimBuildReward(cards[selected], CardUpgradeKind.DrawRider));
void Select(int offset)
{
selected = (selected + offset + cards.Count) % cards.Count;
var card = cards[selected];
target.text = $"Target {selected + 1}/{cards.Count}: {card.Definition.DisplayName}\n+{card.MagnitudeBonus} effect / +{card.DrawRider} draw";
draw.SetEnabled(card.DrawRider == 0);
}
navigation.Add(Action("Previous card", "RewardPrevious", () => Select(-1)));
navigation.Add(Action("Next card", "RewardNext", () => Select(1)));
Select(0);
section.Add(draw);
}
section.Add(Action($"Take {RunManager.BuildRewardBits} Bits", "RewardBits",
() => run.ClaimBuildReward(null, CardUpgradeKind.MagnitudeUp, true)));
}
if (run.BuildRewardPending) return BuildReward(run);
if (run.CampaignChoicePending)
{
section.Add(TerminalLayout.BodyText("Five waves cleared. Finish this campaign and bank your rewards, or keep this build running in endless mode. Rewards are saved when the run ends."));
section.Add(TerminalLayout.BodyText($"All {run.Journey.FinalWave} waves cleared. Kernel Overseer defeated. Finish and bank your rewards, or carry this deck and remaining Uptime into endless survival. Rewards are saved when the run ends."));
section.Add(Action("Finish campaign", "FinishCampaignButton", () => combat.CompleteCampaign()));
section.Add(Action("Continue into endless", "ContinueEndlessButton", () => combat.ContinueEndless()));
section.Add(Action("Continue into endless", "ContinueEndlessButton", () => run.EnterEndless()));
return section;
}
if (run.Journey.mapRevision > 0)
{
section.Add(RunMapView.Build(run));
return section;
}
var plan = EncounterDirector.Plan(run.CurrentWaveNumber, run.Journey.selectedRoute,
@@ -66,6 +42,71 @@ namespace KernelPanic.UI
return section;
}
public static VisualElement BuildReward(RunManager run)
{
var content = new VisualElement { name = "BuildRewardChoices" };
content.AddToClassList("departure-content");
content.Add(TerminalLayout.BodyText($"Upgrade one card, or take {RunManager.BuildRewardBits} Bits."));
var cards = run.RunDeck.Where(c => c.Definition != null && !c.Definition.IsToken && !c.Definition.IsJunk).ToList();
if (cards.Count > 0)
{
int index = 0;
CardUpgradeKind kind = run.CanImproveRouteCard(cards[0]) ? CardUpgradeKind.MagnitudeUp : CardUpgradeKind.DrawRider;
var picker = new DropdownField("Card to upgrade", cards.Select((c, i) => $"{i + 1}. {c.Definition.DisplayName}").ToList(), 0)
{ name = "BuildRewardCard" };
content.Add(picker);
var target = TerminalLayout.BodyText("", "BuildRewardTarget");
var modes = new VisualElement(); modes.AddToClassList("departure-actions"); content.Add(modes);
var beforeAfter = new VisualElement { name = "BuildRewardPreviews" };
beforeAfter.AddToClassList("departure-previews"); content.Add(beforeAfter);
var effect = new Button { name = "RewardMagnitude", text = $"Effect +{CombatTuning.UpgradeMagnitudeBonus}" };
var draw = new Button { name = "RewardDraw", text = "Draw +1 on resolution" };
effect.AddToClassList("primary-action"); draw.AddToClassList("primary-action");
modes.Add(effect); modes.Add(draw);
var claim = Action("claim upgrade / open map", "ClaimBuildRewardButton", () => run.ClaimBuildReward(cards[index], kind));
content.Add(claim);
void Refresh()
{
var card = cards[index];
bool canEffect = run.CanImproveRouteCard(card);
bool canDraw = card.DrawRider == 0 && card.UpgradeLevel < int.MaxValue;
effect.SetEnabled(canEffect); draw.SetEnabled(canDraw);
if (kind == CardUpgradeKind.MagnitudeUp && !canEffect && canDraw) kind = CardUpgradeKind.DrawRider;
if (kind == CardUpgradeKind.DrawRider && !canDraw && canEffect) kind = CardUpgradeKind.MagnitudeUp;
bool valid = kind == CardUpgradeKind.MagnitudeUp ? canEffect : canDraw;
target.text = valid ? "" : "No eligible upgrade. Choose another card or take Bits.";
effect.EnableInClassList("departure-selected", kind == CardUpgradeKind.MagnitudeUp);
draw.EnableInClassList("departure-selected", kind == CardUpgradeKind.DrawRider);
beforeAfter.Clear(); beforeAfter.Add(CardPreview(card, run, "BEFORE"));
var after = card.CopyForCombat();
if (valid)
{
if (kind == CardUpgradeKind.MagnitudeUp) after.ApplyMagnitudeUpgrade(CombatTuning.UpgradeMagnitudeBonus);
else after.ApplyDrawRider(1);
}
beforeAfter.Add(CardPreview(after, run, valid ? "AFTER UPGRADE" : "UNCHANGED"));
claim.SetEnabled(valid);
}
picker.RegisterValueChangedCallback(_ => { index = picker.index; Refresh(); });
effect.clicked += () => { kind = CardUpgradeKind.MagnitudeUp; Refresh(); };
draw.clicked += () => { kind = CardUpgradeKind.DrawRider; Refresh(); };
Refresh();
content.Add(target);
}
content.Add(Action($"take {RunManager.BuildRewardBits} Bits instead / open map", "RewardBits",
() => run.ClaimBuildReward(null, CardUpgradeKind.MagnitudeUp, true)));
return content;
}
private static VisualElement CardPreview(CardInstance card, RunManager run, string title)
{
var panel = new VisualElement(); panel.AddToClassList("departure-card");
panel.Add(SoftwareCardView.Text(title, "route-map-eyebrow"));
var face = new VisualElement();
SoftwareCardView.Populate(face, card, CombatManager.GetCardCost(card), CardEffectFactory.GetRulesText(card, run.CurrentConfig));
panel.Add(face); return panel;
}
private static void AddChoice(VisualElement parent, RunManager run, WaveRoute route, string title, string detail)
{
var card = new VisualElement();
+3 -1
View File
@@ -15,6 +15,9 @@ namespace KernelPanic.UI
};
public static void Populate(VisualElement target, CardInstance card, int cost)
=> Populate(target, card, cost, CardEffectFactory.GetRulesText(card));
public static void Populate(VisualElement target, CardInstance card, int cost, string rules)
{
if (card?.Definition == null) return;
var definition = card.Definition;
@@ -33,7 +36,6 @@ namespace KernelPanic.UI
target.Add(Text(string.IsNullOrWhiteSpace(definition.DisplayName) ? definition.name : definition.DisplayName, "software-name"));
target.Add(Text(TrackName(definition.ResolutionTrack), "software-track"));
string rules = CardEffectFactory.GetRulesText(card);
if (card.DrawRider > 0) rules += $" Draw {card.DrawRider}.";
target.tooltip = rules;
if (card.IsBroken) target.tooltip += "\n\n" + CardPreviewService.CorruptionDetails(card);