Rebalance most languages and revamp main game loop
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user