Add tutorial and QoL improvements
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using KernelPanic.Combat;
|
||||
using KernelPanic.Core;
|
||||
using KernelPanic.Data;
|
||||
@@ -742,7 +743,7 @@ namespace KernelPanic.UI
|
||||
|
||||
private static int GetDistroStars(DistroDefinition unit)
|
||||
{
|
||||
return unit != null && string.Equals(unit.Id, "arch", StringComparison.OrdinalIgnoreCase) ? 5 : 4;
|
||||
return DistroRarity.Stars(unit);
|
||||
}
|
||||
|
||||
private static Color GetLanguageColor(Language language)
|
||||
@@ -948,14 +949,14 @@ namespace KernelPanic.UI
|
||||
|
||||
private void AddUnitOverviewTab(VisualElement target, DistroDefinition unit)
|
||||
{
|
||||
Label identityTitle = new("identity");
|
||||
identityTitle.AddToClassList("detail-section-title");
|
||||
target.Add(identityTitle);
|
||||
target.Add(BuildDetailLine("lang", DistroPresentation.FormatLanguages(unit)));
|
||||
VisualElement identity = TerminalLayout.Section("identity",
|
||||
sectionClass: "unit-info-section unit-identity-section", headingClass: "detail-section-title");
|
||||
identity.Add(BuildDetailLine("lang", DistroPresentation.FormatLanguages(unit)));
|
||||
|
||||
Label description = new(string.IsNullOrWhiteSpace(unit.Description) ? "--" : unit.Description);
|
||||
description.AddToClassList("collection-detail-description");
|
||||
target.Add(description);
|
||||
Label description = TerminalLayout.BodyText(string.IsNullOrWhiteSpace(unit.Description) ? "--" : unit.Description,
|
||||
className: "collection-detail-description");
|
||||
identity.Add(description);
|
||||
target.Add(identity);
|
||||
AddPassiveDetails(target, unit);
|
||||
|
||||
VisualElement readout = new();
|
||||
@@ -1147,8 +1148,7 @@ namespace KernelPanic.UI
|
||||
return;
|
||||
}
|
||||
|
||||
PackageEffectData effect = package.EffectFor(unit.Id);
|
||||
if (package.Slot == PackageSlot.Kernel && IsStatPackageEffect(effect.Kind))
|
||||
if (package.Slot == PackageSlot.Kernel && package.EffectsFor(unit.Id).All(e => IsStatPackageEffect(e.Kind)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -1838,17 +1838,7 @@ namespace KernelPanic.UI
|
||||
|
||||
private static VisualElement BuildDetailLine(string key, string value)
|
||||
{
|
||||
VisualElement row = new();
|
||||
row.AddToClassList("kv-row");
|
||||
|
||||
Label keyLabel = new(key);
|
||||
keyLabel.AddToClassList("kv-key");
|
||||
Label valueLabel = new(value);
|
||||
valueLabel.AddToClassList("kv-value");
|
||||
|
||||
row.Add(keyLabel);
|
||||
row.Add(valueLabel);
|
||||
return row;
|
||||
return TerminalLayout.StatRow(key, value, rowClass: "kv-row", keyClass: "kv-key", valueClass: "kv-value");
|
||||
}
|
||||
|
||||
private static VisualElement BuildPackagePreviewLine(string key, string value)
|
||||
@@ -1923,20 +1913,17 @@ namespace KernelPanic.UI
|
||||
return;
|
||||
}
|
||||
|
||||
Label passiveTitle = new(unit.Passive.Name);
|
||||
passiveTitle.AddToClassList("detail-section-title");
|
||||
target.Add(passiveTitle);
|
||||
|
||||
Label passiveRules = new(unit.Passive.RulesText);
|
||||
passiveRules.AddToClassList("collection-detail-description");
|
||||
target.Add(passiveRules);
|
||||
VisualElement passive = TerminalLayout.Section(unit.Passive.Name,
|
||||
sectionClass: "unit-info-section unit-passive-section", headingClass: "detail-section-title");
|
||||
Label passiveRules = TerminalLayout.BodyText(unit.Passive.RulesText, className: "collection-detail-description");
|
||||
passive.Add(passiveRules);
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(unit.Passive.FlavorText))
|
||||
{
|
||||
Label passiveFlavor = new(unit.Passive.FlavorText);
|
||||
passiveFlavor.AddToClassList("flavor-text");
|
||||
target.Add(passiveFlavor);
|
||||
Label passiveFlavor = TerminalLayout.BodyText(unit.Passive.FlavorText, className: "flavor-text");
|
||||
passive.Add(passiveFlavor);
|
||||
}
|
||||
target.Add(passive);
|
||||
}
|
||||
|
||||
private static IReadOnlyList<CardEntry> BuildUnitCardEntries(DistroDefinition unit)
|
||||
@@ -2065,7 +2052,7 @@ namespace KernelPanic.UI
|
||||
return "--";
|
||||
}
|
||||
|
||||
string summary = FormatEffectSummary(package.EffectFor(distroId), upgradeLevel);
|
||||
string summary = string.Join("; ", package.EffectsFor(distroId).Select(e => FormatEffectSummary(e, upgradeLevel)).Where(s => !string.IsNullOrWhiteSpace(s)));
|
||||
if (!string.IsNullOrWhiteSpace(summary))
|
||||
{
|
||||
return summary;
|
||||
@@ -2081,7 +2068,7 @@ namespace KernelPanic.UI
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
string text = FormatEffectSummary(package.EffectFor(distroId), upgradeLevel);
|
||||
string text = FormatPackageEffect(package, upgradeLevel, distroId);
|
||||
if (string.IsNullOrWhiteSpace(text) && !string.IsNullOrWhiteSpace(package.Description))
|
||||
{
|
||||
text = package.Description.Trim();
|
||||
@@ -2103,6 +2090,11 @@ namespace KernelPanic.UI
|
||||
return effect.Kind switch
|
||||
{
|
||||
PackageEffectKind.None => string.Empty,
|
||||
PackageEffectKind.PortageWaveStartShield => $"+{Math.Max(4, amount)} Shield once at wave start",
|
||||
PackageEffectKind.FirstCardEachRoundDiscountAndShield => "first accepted card each round costs 1 less" + (amount > 0 ? $"; +{amount} Shield on its successful play" : string.Empty),
|
||||
PackageEffectKind.CompilationAdvancedPreviousRoundCycle => $"+{amount} Cycle at round start if Compilation advanced last round",
|
||||
PackageEffectKind.AfterFirstRoundShield => $"+{amount} Shield at each round start after the first",
|
||||
PackageEffectKind.AfterFirstRoundCompilation => $"+{amount} Compilation at each round start after the first (version cap; no increase hooks)",
|
||||
PackageEffectKind.MaxUptime => $"+{amount} max Uptime",
|
||||
PackageEffectKind.MaxCycles => $"+{amount} max Cycles",
|
||||
PackageEffectKind.MaxRam => $"+{amount} max RAM",
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using KernelPanic.Combat;
|
||||
using KernelPanic.Core;
|
||||
using KernelPanic.Data;
|
||||
@@ -51,6 +52,12 @@ namespace KernelPanic.UI
|
||||
private VisualElement _enemyRow;
|
||||
private VisualElement _handRow;
|
||||
private VisualElement _turnResourceGrid;
|
||||
private VisualElement _packageReadinessStrip;
|
||||
private Label _packageActivationLabel;
|
||||
private readonly Dictionary<string, VisualElement> _packageReadinessChips = new();
|
||||
private int _packageActivationVersion;
|
||||
private int _packageActivationFrame = -1;
|
||||
private readonly Queue<string> _packageActivationMessages = new();
|
||||
private VisualElement _journalEntries;
|
||||
private Foldout _journal;
|
||||
private Button _endTurnButton;
|
||||
@@ -60,6 +67,8 @@ namespace KernelPanic.UI
|
||||
private ScrollView _journalScroll;
|
||||
private ExecutionTrackView _queueView;
|
||||
private ExecutionTrackView _stackView;
|
||||
private ExecutionPreviewView _executionPreview;
|
||||
private Label _encounterBrief;
|
||||
private float _journalStartedAt;
|
||||
private readonly Dictionary<EnemyInstance, Button> _enemyCards = new();
|
||||
private readonly HashSet<EnemyInstance> _restartingEnemies = new();
|
||||
@@ -101,6 +110,15 @@ namespace KernelPanic.UI
|
||||
private bool _runEndedBySurrender;
|
||||
private bool _runEndOverlayPresented;
|
||||
private bool _playerFeedbackAnchorTracked;
|
||||
private FirstBattleGuide _firstBattleGuide;
|
||||
private TutorialFlow _tutorial;
|
||||
private SaveData _lastKnownSave;
|
||||
private string _saveError;
|
||||
private string _checkpointError;
|
||||
private CombatRunTelemetry _runTelemetry;
|
||||
private RunHistoryEntry _runHistoryEntry;
|
||||
private bool _pileInspectorOpen;
|
||||
private string _inspectedPile;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
@@ -129,11 +147,17 @@ namespace KernelPanic.UI
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
_runTelemetry?.Dispose();
|
||||
_runTelemetry = new CombatRunTelemetry(() => _combatManager.PlayerState, DescribeDamageSource)
|
||||
{
|
||||
SurrenderRequested = () => _combatManager.RunEndedBySurrender
|
||||
};
|
||||
_queueView ??= new ExecutionTrackView(_interpreterStrip, false);
|
||||
_stackView ??= new ExecutionTrackView(_lazyStackPile, true);
|
||||
_root?.EnableInClassList("reduced-motion", UIPreferences.ReducedMotion);
|
||||
_combatManager.StateChanged += Refresh;
|
||||
_combatManager.CombatLog += HandleCombatLog;
|
||||
_combatManager.PackageActivated += HandlePackageActivated;
|
||||
_runManager.RepositoryChanged += Refresh;
|
||||
GameEvents.CardPlayed += HandleCardPlayed;
|
||||
GameEvents.CardResolving += HandleCardResolving;
|
||||
@@ -156,7 +180,9 @@ namespace KernelPanic.UI
|
||||
|
||||
private void Start()
|
||||
{
|
||||
if (!TryBuildRunConfig(out RunConfig config))
|
||||
bool resuming = RunContext.TryTakeResume(out ResolvedRunCheckpoint resume);
|
||||
RunConfig config = resume?.Config;
|
||||
if (!resuming && !TryBuildRunConfig(out config))
|
||||
{
|
||||
HandleMissingRunConfig();
|
||||
return;
|
||||
@@ -165,7 +191,31 @@ namespace KernelPanic.UI
|
||||
_distroAccent = config.Distro == null ? Color.white : config.Distro.AccentColor;
|
||||
TerminalTheme.SetDistro(_root, config.Distro);
|
||||
_combatManager.SetGeneratedCardPool(BuildGeneratedCardPool());
|
||||
_runManager.StartRun(config);
|
||||
if (config.IsTutorial)
|
||||
{
|
||||
_tutorial = new TutorialFlow(_overlay, _runManager, _combatManager, cardDatabase, languageDeckDatabase,
|
||||
_saveService, config, () => SceneLoader.LoadMainMenu(_root));
|
||||
_tutorial.SetRefresh(Refresh);
|
||||
}
|
||||
if (resuming)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!config.IsTutorial) RunCheckpointService.Consume(_saveService, resume);
|
||||
_runManager.RestoreCheckpoint(resume);
|
||||
_combatManager.RestoreBoundaryState(config, resume.Snapshot.combat);
|
||||
_tutorial?.ResumeSecondWave();
|
||||
}
|
||||
catch (Exception ex) when (ex is IOException || ex is InvalidDataException || ex is UnauthorizedAccessException)
|
||||
{
|
||||
_overlay.Clear();
|
||||
_overlay.style.display = DisplayStyle.Flex;
|
||||
_overlay.Add(TerminalLayout.BodyText("Resume could not complete: " + ex.Message));
|
||||
_overlay.Add(new Button(() => SceneLoader.LoadMainMenu(_root)) { text = "return to menu" });
|
||||
return;
|
||||
}
|
||||
}
|
||||
else _runManager.StartRun(config);
|
||||
Refresh();
|
||||
}
|
||||
|
||||
@@ -191,8 +241,10 @@ namespace KernelPanic.UI
|
||||
{
|
||||
Time.timeScale = 1f;
|
||||
SettleRunRewardsIfNeeded();
|
||||
_tutorial?.Dispose();
|
||||
_combatManager.StateChanged -= Refresh;
|
||||
_combatManager.CombatLog -= HandleCombatLog;
|
||||
_combatManager.PackageActivated -= HandlePackageActivated;
|
||||
_runManager.RepositoryChanged -= Refresh;
|
||||
GameEvents.CardPlayed -= HandleCardPlayed;
|
||||
GameEvents.CardResolving -= HandleCardResolving;
|
||||
@@ -218,10 +270,29 @@ namespace KernelPanic.UI
|
||||
_queueView = null;
|
||||
_stackView = null;
|
||||
_feedbackLayer?.Clear();
|
||||
_runTelemetry?.Dispose();
|
||||
_runTelemetry = null;
|
||||
}
|
||||
|
||||
private void HandleKeyDown(KeyDownEvent evt)
|
||||
{
|
||||
if (_tutorial?.Guide.Active == true)
|
||||
{
|
||||
if (evt.keyCode == KeyCode.E && _tutorial.Guide.CanEndTurn) _combatManager.EndPlayerTurn();
|
||||
evt.StopPropagation(); return;
|
||||
}
|
||||
if (_executionPreview?.IsOpen == true)
|
||||
{
|
||||
if (evt.keyCode == KeyCode.Escape) _executionPreview.Close();
|
||||
evt.StopPropagation();
|
||||
return;
|
||||
}
|
||||
if (_pileInspectorOpen)
|
||||
{
|
||||
if (evt.keyCode == KeyCode.Escape) ClosePileInspector();
|
||||
evt.StopPropagation();
|
||||
return;
|
||||
}
|
||||
if (!_surrenderConfirming)
|
||||
{
|
||||
if (_overlay.resolvedStyle.display != DisplayStyle.None) return;
|
||||
@@ -359,6 +430,12 @@ namespace KernelPanic.UI
|
||||
var workspace = new ScrollView(ScrollViewMode.Vertical);
|
||||
workspace.AddToClassList("combat-workspace");
|
||||
_root.Add(workspace);
|
||||
_firstBattleGuide = new FirstBattleGuide();
|
||||
workspace.Add(_firstBattleGuide.Element);
|
||||
_encounterBrief = TerminalLayout.BodyText("", "EncounterBrief");
|
||||
workspace.Add(_encounterBrief);
|
||||
_executionPreview = new ExecutionPreviewView();
|
||||
workspace.Add(_executionPreview.Element);
|
||||
VisualElement main = new();
|
||||
main.AddToClassList("main-layout");
|
||||
workspace.Add(main);
|
||||
@@ -376,6 +453,17 @@ namespace KernelPanic.UI
|
||||
_enemyRow.AddToClassList("enemy-row");
|
||||
enemiesPanel.Add(_enemyRow);
|
||||
|
||||
var packages = new VisualElement { name = "CombatPackages" };
|
||||
packages.AddToClassList("combat-packages");
|
||||
_packageReadinessStrip = new VisualElement { name = "PackageReadiness" };
|
||||
_packageReadinessStrip.AddToClassList("package-readiness-strip");
|
||||
_packageReadinessChips.Clear();
|
||||
packages.Add(_packageReadinessStrip);
|
||||
_packageActivationLabel = SoftwareCardView.Text("", "package-activation");
|
||||
_packageActivationLabel.name = "PackageActivation";
|
||||
packages.Add(_packageActivationLabel);
|
||||
workspace.Add(packages);
|
||||
|
||||
VisualElement scheduler = new();
|
||||
scheduler.AddToClassList("scheduler");
|
||||
VisualElement schedulerHeader = PanelHeader("execution scheduler", "");
|
||||
@@ -384,7 +472,9 @@ namespace KernelPanic.UI
|
||||
_schedulerActivity.text = "No operations dispatched.";
|
||||
scheduler.Add(schedulerHeader);
|
||||
_interpreterStrip = AddTrackZone(scheduler, "queue / FIFO", "Interpreter: resolves in order during the interpret phase", "track-zone-queue");
|
||||
_lazyStackPile = AddTrackZone(scheduler, "stack / LIFO", "Lazy stack: newest operation first when forced", "track-zone-stack");
|
||||
_lazyStackPile = AddTrackZone(scheduler, "stack / LIFO", "After FIFO: newest first. Captured multiplier scales damage and explicit Shield only.", "track-zone-stack");
|
||||
_interpreterStrip.name = "TutorialQueue";
|
||||
_lazyStackPile.name = "TutorialStack";
|
||||
_queueView = new ExecutionTrackView(_interpreterStrip, false);
|
||||
_stackView = new ExecutionTrackView(_lazyStackPile, true);
|
||||
_tokenArea = AddTrackZone(scheduler, "|| goroutines", "no active runtime", "track-zone-token");
|
||||
@@ -407,11 +497,22 @@ namespace KernelPanic.UI
|
||||
commandPanel.AddToClassList("turn-panel");
|
||||
bottom.Add(commandPanel);
|
||||
_turnResourceGrid = new();
|
||||
_turnResourceGrid.name = "TutorialPiles";
|
||||
_turnResourceGrid.AddToClassList("turn-resource-grid");
|
||||
commandPanel.Add(_turnResourceGrid);
|
||||
_endTurnButton = new(() => _combatManager.EndPlayerTurn()) { text = "[E] end turn" };
|
||||
_endTurnButton.name = "TutorialEndTurn";
|
||||
_endTurnButton.AddToClassList("primary-action");
|
||||
commandPanel.Add(_endTurnButton);
|
||||
var guideButton = new Button(() =>
|
||||
{
|
||||
if (_tutorial != null) _tutorial.Review();
|
||||
else _firstBattleGuide.Begin(_runManager.CurrentConfig, true);
|
||||
}) { text = "? guide", name = "ReplayBattleGuide" };
|
||||
guideButton.tooltip = "Battle guide: replay the first-battle tips";
|
||||
guideButton.AddToClassList("battle-guide-toggle");
|
||||
commandPanel.Q<Label>(className: "panel-subtitle")?.RemoveFromHierarchy();
|
||||
commandPanel.Q(className: "panel-header").Add(guideButton);
|
||||
_surrenderButton = new(HandleSurrenderClicked) { text = "> shutdown -r run" };
|
||||
_surrenderButton.AddToClassList("secondary-action");
|
||||
_surrenderButton.AddToClassList("surrender-action");
|
||||
@@ -534,20 +635,97 @@ namespace KernelPanic.UI
|
||||
return;
|
||||
}
|
||||
|
||||
_tutorial?.UpdateState();
|
||||
RefreshStatus();
|
||||
RefreshPlayer();
|
||||
RefreshTracks();
|
||||
RefreshEnemies();
|
||||
RefreshHand();
|
||||
RefreshTurnPanel();
|
||||
RefreshPackageReadiness();
|
||||
RefreshOverlay();
|
||||
_executionPreview?.Refresh(_combatManager);
|
||||
if (_encounterBrief != null)
|
||||
{
|
||||
// Encounter advice belongs to onboarding, not every battle's workspace.
|
||||
_encounterBrief.text = "";
|
||||
_encounterBrief.style.display = DisplayStyle.None;
|
||||
}
|
||||
_firstBattleGuide?.Refresh(_combatManager.AwaitingWaveContinue, _combatManager.RunFinished);
|
||||
}
|
||||
|
||||
private void RefreshPackageReadiness()
|
||||
{
|
||||
if (_packageReadinessStrip == null) return;
|
||||
var readouts = _combatManager.GetPackageReadouts();
|
||||
var currentIds = new HashSet<string>();
|
||||
foreach (var readout in readouts)
|
||||
{
|
||||
string id = readout.Definition.Id;
|
||||
currentIds.Add(id);
|
||||
if (!_packageReadinessChips.TryGetValue(id, out var chip))
|
||||
{
|
||||
chip = new VisualElement { name = "Readiness_" + id, focusable = true, tabIndex = 0 };
|
||||
chip.AddToClassList("package-readiness-chip");
|
||||
chip.Add(RarityPresentation.CreatePackageBadge(readout.Definition.Rarity));
|
||||
chip.Add(SoftwareCardView.Text(readout.Definition.DisplayName, "package-readiness-name"));
|
||||
chip.Add(SoftwareCardView.Text("", "package-readiness-state"));
|
||||
_packageReadinessChips[id] = chip;
|
||||
_packageReadinessStrip.Add(chip);
|
||||
}
|
||||
chip.Q<Label>(className: "package-readiness-state").text = readout.State;
|
||||
chip.tooltip = readout.Definition.DisplayName + "\n" + readout.Details;
|
||||
}
|
||||
foreach (var id in new List<string>(_packageReadinessChips.Keys))
|
||||
{
|
||||
if (currentIds.Contains(id)) continue;
|
||||
_packageReadinessChips[id].RemoveFromHierarchy();
|
||||
_packageReadinessChips.Remove(id);
|
||||
}
|
||||
_packageReadinessStrip.parent.style.display = readouts.Count > 0 ? DisplayStyle.Flex : DisplayStyle.None;
|
||||
}
|
||||
|
||||
private void HandlePackageActivated(PackageActivation activation)
|
||||
{
|
||||
if (_packageActivationLabel == null) return;
|
||||
if (_packageActivationFrame != Time.frameCount) _packageActivationMessages.Clear();
|
||||
_packageActivationFrame = Time.frameCount;
|
||||
if (_packageActivationMessages.Count == 3) _packageActivationMessages.Dequeue();
|
||||
_packageActivationMessages.Enqueue(activation.Name + ": " + activation.Message);
|
||||
_packageActivationLabel.text = string.Join(" | ", _packageActivationMessages);
|
||||
int version = ++_packageActivationVersion;
|
||||
// Feedback only: readiness and effects always use real combat state.
|
||||
ScheduleFeedback(() =>
|
||||
{
|
||||
if (version == _packageActivationVersion) _packageActivationLabel.text = "";
|
||||
}, 3500);
|
||||
}
|
||||
|
||||
private void RefreshStatus()
|
||||
{
|
||||
SaveData data = _saveService.Load();
|
||||
SaveData data;
|
||||
try
|
||||
{
|
||||
data = _lastKnownSave = _saveService.Load();
|
||||
if (_runManager.RewardsSettled) _saveError = null;
|
||||
}
|
||||
catch (Exception ex) when (ex is IOException || ex is InvalidDataException || ex is UnauthorizedAccessException)
|
||||
{
|
||||
_saveError = ex.Message;
|
||||
data = _lastKnownSave ?? new SaveData();
|
||||
}
|
||||
RunConfig config = _runManager.CurrentConfig;
|
||||
_waveLabel.text = _runManager.CurrentWaveNumber.ToString();
|
||||
_waveLabel.text = _runManager.Journey.campaign && !_runManager.Journey.endless
|
||||
? $"{Math.Min(RunJourney.BossWave, _runManager.CurrentWaveNumber)}/{RunJourney.BossWave}"
|
||||
: _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."
|
||||
: "Endless mode";
|
||||
if (config?.IsTutorial == true)
|
||||
{
|
||||
_waveLabel.text = $"training {config.TutorialLesson}/{TutorialCampaign.LessonCount}";
|
||||
_waveLabel.tooltip = "Clear both training waves for a one-time Bandwidth and Entropy reward.";
|
||||
}
|
||||
_phaseLabel.text = PhaseText(_combatManager.CurrentPhase);
|
||||
_bitsLabel.text = _runManager.Bits.ToString();
|
||||
_entropyLabel.text = FormatWalletWithAccrual(data.entropyBalance, _runManager.AccruedEntropy);
|
||||
@@ -564,7 +742,8 @@ namespace KernelPanic.UI
|
||||
_combatantElements[_combatManager.PlayerState] = _playerPanel;
|
||||
var distro = _runManager.CurrentConfig.Distro;
|
||||
_playerPanel.Add(PanelHeader(DisplayName(distro), "HOST"));
|
||||
var identity = SoftwareCardView.Text(DistroPresentation.FormatLanguages(distro), "host-languages");
|
||||
var config = _runManager.CurrentConfig;
|
||||
var identity = SoftwareCardView.Text($"{config.PrimaryLanguage} / {config.SecondaryLanguage}", "host-languages");
|
||||
identity.tooltip = distro.Passive == null ? "" : distro.Passive.RulesText;
|
||||
_playerPanel.Add(identity);
|
||||
ApplyAccent(_playerPanel);
|
||||
@@ -575,8 +754,10 @@ namespace KernelPanic.UI
|
||||
ApplyStatusStateClasses(_playerPanel, state);
|
||||
if (uptimeMeter == null) uptimeMeter = MeterBlock("uptime", state.CurrentUptime, state.MaxUptime, MeterTone.Uptime);
|
||||
else UpdateMeter(uptimeMeter, state.CurrentUptime, state.MaxUptime);
|
||||
uptimeMeter.name = "TutorialUptime";
|
||||
_playerPanel.Add(uptimeMeter);
|
||||
_playerPanel.Add(TurnStat("shield", state.Shield.ToString()));
|
||||
var shieldStat = TurnStat("shield", state.Shield.ToString());
|
||||
shieldStat.name = "TutorialShield"; _playerPanel.Add(shieldStat);
|
||||
_playerPanel.Add(CycleBlock(state.Cycles, state.MaxCycles));
|
||||
|
||||
Label ram = new($"ram hand cap {_combatManager.HandController.UsedRam}/{_combatManager.HandController.RamCapacity}");
|
||||
@@ -592,6 +773,33 @@ namespace KernelPanic.UI
|
||||
|
||||
_playerPanel.Add(StatusBlock(state, true));
|
||||
|
||||
var compilation = _combatManager.Compilation;
|
||||
if (compilation.Active)
|
||||
{
|
||||
VisualElement panel = new();
|
||||
panel.AddToClassList("compilation-panel");
|
||||
panel.tooltip = "emerge --world: Compilation advances after each completed round and resets each wave.";
|
||||
VisualElement heading = new();
|
||||
heading.AddToClassList("compilation-heading");
|
||||
heading.Add(SoftwareCardView.Text("Compilation", "compilation-title"));
|
||||
heading.Add(SoftwareCardView.Text($"{compilation.Level}/{compilation.Maximum}", "compilation-level"));
|
||||
panel.Add(heading);
|
||||
VisualElement progress = new();
|
||||
progress.AddToClassList("compilation-progress");
|
||||
for (int level = 0; level < compilation.Maximum; level++)
|
||||
{
|
||||
VisualElement step = new();
|
||||
step.AddToClassList("compilation-step");
|
||||
step.EnableInClassList("compilation-step-filled", level < compilation.Level);
|
||||
progress.Add(step);
|
||||
}
|
||||
panel.Add(progress);
|
||||
panel.Add(CompilationModifier("card damage", $"{compilation.DamagePercent - 100:+0;-0;0}%"));
|
||||
if (config.DistroVersion >= 4)
|
||||
panel.Add(CompilationModifier("card shield", $"+{compilation.ShieldPercent - 100}%"));
|
||||
_playerPanel.Add(panel);
|
||||
}
|
||||
|
||||
if (IsDistro("fedora"))
|
||||
{
|
||||
_playerPanel.Add(FedoraRiskMeter(_combatManager.FedoraCrashChance));
|
||||
@@ -608,11 +816,20 @@ namespace KernelPanic.UI
|
||||
return string.Equals(_runManager?.CurrentConfig?.Distro?.Id, id, StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
private static VisualElement CompilationModifier(string label, string value)
|
||||
{
|
||||
return TerminalLayout.StatRow(label, value, rowClass: "compilation-modifier",
|
||||
keyClass: "compilation-label", valueClass: "compilation-value");
|
||||
}
|
||||
|
||||
private void RefreshTracks()
|
||||
{
|
||||
_queueView.Sync(_combatManager.InterpreterQueue.Cards);
|
||||
_stackView.Sync(_combatManager.LazyStack.Cards);
|
||||
if (_combatManager.AwaitingWaveContinue || _combatManager.RunLost)
|
||||
_stackView.SyncMultipliers(_combatManager.LazyStack.Entries);
|
||||
_queueView.SyncPreviews(_combatManager, _combatManager.InterpreterQueue.Cards);
|
||||
_stackView.SyncPreviews(_combatManager, _combatManager.LazyStack.Cards);
|
||||
if (_combatManager.AwaitingWaveContinue || _combatManager.RunFinished)
|
||||
{
|
||||
_queueView.EndExecution();
|
||||
_stackView.EndExecution();
|
||||
@@ -699,7 +916,7 @@ namespace KernelPanic.UI
|
||||
bool holdDeathDisplay = deathPending && !deathBeatStarted;
|
||||
int displayedUptime = enemy.CurrentUptime;
|
||||
card.EnableInClassList("enemy-card-defeated-hold", deathPending && deathBeatStarted);
|
||||
card.SetEnabled(!enemy.State.IsDefeated || holdDeathDisplay);
|
||||
card.SetEnabled((!enemy.State.IsDefeated || holdDeathDisplay) && _combatManager.TutorialGuide?.AllowsEnemy(enemy) != false);
|
||||
card.EnableInClassList("enemy-targetable", _combatManager.PendingTargetCard != null && !deathPending && !enemy.State.IsDefeated);
|
||||
card.AddToClassList("process-" + enemy.ArchetypeId.Replace('_', '-'));
|
||||
card.Q<Label>(className: "process-state").text = $"{(_combatManager.SelectedEnemyIndex == index ? "> " : " ")}{EnemyProcessPresentation.Symbol(enemy.ArchetypeId)} {EnemyProcessPresentation.Lifecycle(enemy)}";
|
||||
@@ -708,6 +925,8 @@ namespace KernelPanic.UI
|
||||
card.EnableInClassList("enemy-card-targeted", highlighted);
|
||||
card.Q<Label>(className: "enemy-name").text = enemy.Name;
|
||||
card.tooltip = enemy.Name + " / " + IntentText(enemy.DisplayIntent);
|
||||
if (enemy.HasBehavior(EnemyBehaviorFlags.LeavesOrphan))
|
||||
card.tooltip += $"\n{CombatTuning.OrphanSpawnChancePercent}% chance to leave an orphan on permanent death.";
|
||||
card.Q<Label>(className: "process-behavior").text = EnemyProcessPresentation.Behavior(enemy);
|
||||
var signals = card.Q("ProcessSignals");
|
||||
signals.Clear();
|
||||
@@ -853,12 +1072,14 @@ namespace KernelPanic.UI
|
||||
face.style.marginRight = i == hand.Count - 1 ? 0 : 10;
|
||||
face.EnableInClassList("hand-card-unaffordable", GetDisplayCardCost(card) > _combatManager.PlayerState.Cycles);
|
||||
var stateLabel = face.Q<Label>(className: "software-state");
|
||||
string reason = card.IsBroken ? "[!] CORRUPTED" : card.IsLocked ? $"[L] UNLOCK {EnemyArchetypeCatalog.DrmUnlockCycleCost}c"
|
||||
string reason = card.IsBroken ? (card.CorruptionRoundsRemaining > 0
|
||||
? $"[!] RECOVER {card.CorruptionRoundsRemaining} ROUNDS" : "[!] CORRUPTED") : card.IsLocked ? $"[L] UNLOCK {EnemyArchetypeCatalog.DrmUnlockCycleCost}c"
|
||||
: card.Definition.IsToken ? "TOKEN / NOT EXECUTABLE"
|
||||
: GetDisplayCardCost(card) > _combatManager.PlayerState.Cycles ? $"NEEDS {GetDisplayCardCost(card)} CYCLES"
|
||||
: _combatManager.PendingTargetCard == card ? "> SELECT TARGET" : "";
|
||||
if (!string.IsNullOrEmpty(reason)) { stateLabel.text = reason; face.tooltip += "\n" + reason; }
|
||||
face.SetEnabled(!_combatManager.RunLost && _combatManager.CurrentPhase == TurnPhase.Execute && !card.IsBroken);
|
||||
face.SetEnabled(!_combatManager.RunFinished && _combatManager.CurrentPhase == TurnPhase.Execute && !card.IsBroken
|
||||
&& _combatManager.TutorialGuide?.AllowsCard(card) != false);
|
||||
_handCardElements[card] = face;
|
||||
if (added) PlayElementBeat(face, "hand-card-drawn", 180);
|
||||
}
|
||||
@@ -869,15 +1090,91 @@ namespace KernelPanic.UI
|
||||
_turnResourceGrid.Clear();
|
||||
CombatantState state = _combatManager.PlayerState;
|
||||
IReadOnlyList<CardInstance> hand = _combatManager.HandController.Cards;
|
||||
_turnResourceGrid.Add(TurnStat("cycles", $"{state.Cycles}/{state.MaxCycles}"));
|
||||
_turnResourceGrid.Add(TurnStat("hand", $"{_combatManager.HandController.UsedRam}/{_combatManager.HandController.RamCapacity}"));
|
||||
_turnResourceGrid.Add(TurnStat("draw", _combatManager.DeckController.DrawPile.Count.ToString()));
|
||||
_turnResourceGrid.Add(TurnStat("discard", _combatManager.DeckController.DiscardPile.Count.ToString()));
|
||||
_turnResourceGrid.Add(TurnStat("exhaust", _combatManager.DeckController.ExhaustPile.Count.ToString()));
|
||||
_endTurnButton.SetEnabled(_combatManager.CanSurrenderRun);
|
||||
var cyclesStat = TurnStat("cycles", $"{state.Cycles}/{state.MaxCycles}");
|
||||
cyclesStat.name = "TutorialCycles"; _turnResourceGrid.Add(cyclesStat);
|
||||
var handStat = TurnStat("hand", $"{_combatManager.HandController.UsedRam}/{_combatManager.HandController.RamCapacity}");
|
||||
handStat.name = "TutorialRam"; _turnResourceGrid.Add(handStat);
|
||||
_turnResourceGrid.Add(PileStat("draw", _combatManager.DeckController.DrawPile));
|
||||
_turnResourceGrid.Add(PileStat("discard", _combatManager.DeckController.DiscardPile));
|
||||
_turnResourceGrid.Add(PileStat("exhaust", _combatManager.DeckController.ExhaustPile));
|
||||
_endTurnButton.SetEnabled(_combatManager.CanSurrenderRun && _combatManager.TutorialGuide?.CanEndTurn != false);
|
||||
RefreshSurrenderCommand();
|
||||
}
|
||||
|
||||
private VisualElement PileStat(string pile, IReadOnlyList<CardInstance> cards)
|
||||
{
|
||||
var button = new Button(() => OpenPileInspector(pile, cards))
|
||||
{
|
||||
name = "InspectPile_" + pile,
|
||||
text = $"{pile} {cards.Count} [inspect]",
|
||||
tooltip = $"Inspect {pile} cards, including upgrades. Draw order is hidden."
|
||||
};
|
||||
button.AddToClassList("pile-stat-button");
|
||||
button.SetEnabled(_combatManager.CanSurrenderRun);
|
||||
return button;
|
||||
}
|
||||
|
||||
private void OpenPileInspector(string pile, IReadOnlyList<CardInstance> cards)
|
||||
{
|
||||
if (!_combatManager.CanSurrenderRun || _surrenderConfirming) return;
|
||||
_inspectedPile = pile;
|
||||
_pileInspectorOpen = true;
|
||||
_overlay.Clear();
|
||||
_overlay.AddToClassList("pile-overlay");
|
||||
var inventories = new Dictionary<string, IReadOnlyList<CardInstance>>
|
||||
{
|
||||
["draw"] = new List<CardInstance>(_combatManager.DeckController.DrawPile),
|
||||
["discard"] = new List<CardInstance>(_combatManager.DeckController.DiscardPile),
|
||||
["exhaust"] = new List<CardInstance>(_combatManager.DeckController.ExhaustPile)
|
||||
};
|
||||
inventories[pile] = new List<CardInstance>(cards);
|
||||
_overlay.Add(CardPileView.BuildBrowser(pile, inventories, ClosePileInspector, _combatManager.GetPileCostDetails));
|
||||
_overlay.style.display = DisplayStyle.Flex;
|
||||
_overlay.Q<TextField>("PileSearch")?.Focus();
|
||||
}
|
||||
|
||||
private void ClosePileInspector()
|
||||
{
|
||||
_pileInspectorOpen = false;
|
||||
// Move focus before clearing; modal refresh must not schedule focus back into a hidden overlay.
|
||||
_turnResourceGrid.Q<Button>("InspectPile_" + _inspectedPile)?.Focus();
|
||||
RefreshOverlay();
|
||||
}
|
||||
|
||||
private string DescribeDamageSource(CombatantState source)
|
||||
{
|
||||
if (ReferenceEquals(source, _combatManager.PlayerState)) return "Self-inflicted damage";
|
||||
foreach (var enemy in _combatManager.Enemies)
|
||||
if (ReferenceEquals(enemy.State, source)) return $"{enemy.Name}: {enemy.CurrentIntent.DisplayLabel}";
|
||||
return "Unattributed system damage";
|
||||
}
|
||||
|
||||
private RunHistoryEntry GetRunHistoryEntry()
|
||||
{
|
||||
if (_runHistoryEntry != null && _runHistoryEntry.runId == _runManager.RunId) return _runHistoryEntry;
|
||||
var config = _runManager.CurrentConfig;
|
||||
var entry = new RunHistoryEntry
|
||||
{
|
||||
runId = _runManager.RunId,
|
||||
endedUtc = DateTimeOffset.UtcNow.ToString("O"),
|
||||
distroId = config?.Distro?.Id,
|
||||
distroName = config?.Distro == null ? "Unknown distro" : DisplayName(config.Distro),
|
||||
distroVersion = config?.DistroVersion ?? 1,
|
||||
languages = $"{config?.PrimaryLanguage} + {config?.SecondaryLanguage}",
|
||||
seed = config?.RunSeed ?? 0,
|
||||
build = RunHistory.CaptureBuild(config),
|
||||
waveReached = _combatManager.RunCompleted ? _runManager.WavesCleared : _runManager.CurrentWaveNumber,
|
||||
wavesCleared = _runManager.WavesCleared,
|
||||
surrendered = _runEndedBySurrender || _combatManager.RunEndedBySurrender,
|
||||
victory = _combatManager.RunCompleted
|
||||
};
|
||||
_runTelemetry?.FillReport(entry);
|
||||
if (entry.victory) entry.cause = "Kernel Overseer defeated. Five-wave campaign complete.";
|
||||
entry.cause ??= entry.surrendered ? "Shutdown signal accepted." : "Uptime reached 0; no damaging action recorded.";
|
||||
_runHistoryEntry = entry;
|
||||
return entry;
|
||||
}
|
||||
|
||||
private void RefreshSurrenderCommand()
|
||||
{
|
||||
bool canSurrender = _combatManager.CanSurrenderRun;
|
||||
@@ -932,6 +1229,7 @@ namespace KernelPanic.UI
|
||||
|
||||
_surrenderConfirming = false;
|
||||
_runEndedBySurrender = true;
|
||||
_runTelemetry?.MarkSurrender();
|
||||
_combatManager.SurrenderRun();
|
||||
}
|
||||
|
||||
@@ -954,10 +1252,15 @@ namespace KernelPanic.UI
|
||||
return;
|
||||
}
|
||||
|
||||
if (_pileInspectorOpen && !_combatManager.RunFinished && !_combatManager.AwaitingWaveContinue
|
||||
&& _combatManager.CurrentPhase == TurnPhase.Execute) return;
|
||||
_pileInspectorOpen = false;
|
||||
if (_tutorial != null) { _overlay.RemoveFromClassList("pile-overlay"); _tutorial.Refresh(); return; }
|
||||
TerminalTheme.PreserveFocus(_overlay);
|
||||
_overlay.RemoveFromClassList("pile-overlay");
|
||||
bool wasVisible = _overlay.style.display == DisplayStyle.Flex;
|
||||
_overlay.Clear();
|
||||
if (_combatManager.RunLost)
|
||||
if (_combatManager.RunFinished)
|
||||
{
|
||||
SettleRunRewardsIfNeeded();
|
||||
_overlay.style.display = DisplayStyle.Flex;
|
||||
@@ -987,13 +1290,16 @@ namespace KernelPanic.UI
|
||||
|
||||
private VisualElement BuildRunEndOverlay()
|
||||
{
|
||||
_runEndedBySurrender |= _combatManager.RunEndedBySurrender;
|
||||
VisualElement screen = new();
|
||||
screen.AddToClassList("death-overlay");
|
||||
screen.EnableInClassList("death-surrender", _runEndedBySurrender);
|
||||
screen.EnableInClassList("run-victory", _combatManager.RunCompleted);
|
||||
|
||||
if (!_runEndOverlayPresented)
|
||||
{
|
||||
_runEndOverlayPresented = true;
|
||||
if (!UIPreferences.ReducedMotion)
|
||||
if (!UIPreferences.ReducedMotion && !_combatManager.RunCompleted)
|
||||
{
|
||||
VisualElement beat = new();
|
||||
beat.AddToClassList("death-crash-beat");
|
||||
@@ -1006,35 +1312,74 @@ namespace KernelPanic.UI
|
||||
VisualElement content = new();
|
||||
content.AddToClassList("death-content");
|
||||
|
||||
content.Add(OverlayTitle("KERNEL PANIC"));
|
||||
var config = _runManager.CurrentConfig;
|
||||
VisualElement reportHeader = new();
|
||||
reportHeader.AddToClassList("death-report-header");
|
||||
reportHeader.Add(SoftwareCardView.Text("RUN REPORT", "death-eyebrow"));
|
||||
reportHeader.Add(SoftwareCardView.Text($"seed {config?.RunSeed ?? 0}", "death-seed"));
|
||||
content.Add(reportHeader);
|
||||
content.Add(OverlayTitle(_combatManager.RunCompleted ? "KERNEL SECURED" : _runEndedBySurrender ? "SYSTEM HALTED" : "KERNEL PANIC"));
|
||||
|
||||
string cause = _runEndedBySurrender ? "fatal: shutdown signal accepted" : "fatal: player uptime reached 0";
|
||||
var report = GetRunHistoryEntry();
|
||||
string cause = report.cause;
|
||||
Label causeLabel = OverlayLine(cause);
|
||||
causeLabel.AddToClassList("death-cause");
|
||||
content.Add(causeLabel);
|
||||
if (config?.Distro != null)
|
||||
content.Add(SoftwareCardView.Text($"{DisplayName(config.Distro)} V{config.DistroVersion} / {config.PrimaryLanguage} + {config.SecondaryLanguage}", "death-session"));
|
||||
|
||||
VisualElement summary = new();
|
||||
summary.AddToClassList("death-section");
|
||||
summary.AddToClassList("death-summary");
|
||||
summary.Add(DeathStat("wave reached", _runManager.CurrentWaveNumber.ToString()));
|
||||
summary.AddToClassList("death-wave-stats");
|
||||
summary.Add(DeathStat("wave reached", report.waveReached.ToString()));
|
||||
summary.Add(DeathStat("waves cleared", _runManager.WavesCleared.ToString()));
|
||||
summary.Add(DeathStat("seed", (_runManager.CurrentConfig?.RunSeed ?? 0).ToString()));
|
||||
content.Add(summary);
|
||||
|
||||
bool recapUnavailable = report.victory && report.finalRound == 0;
|
||||
content.Add(SoftwareCardView.Text(recapUnavailable ? "COMBAT RECAP" : $"FINAL ROUND {report.finalRound}", "death-eyebrow"));
|
||||
var recap = new VisualElement();
|
||||
recap.AddToClassList("death-section");
|
||||
recap.Add(OverlayLine(recapUnavailable ? "Combat recap unavailable after resuming this checkpoint."
|
||||
: $"{report.damageDealt} uptime dealt / {report.damageTaken} uptime lost / {report.shieldBlocked} blocked by shield"));
|
||||
if (report.finalHits.Count > 0)
|
||||
{
|
||||
var hits = new Foldout { text = "Last incoming hits (up to 8)", value = false };
|
||||
foreach (string hit in report.finalHits) hits.Add(OverlayLine(hit));
|
||||
recap.Add(hits);
|
||||
}
|
||||
content.Add(recap);
|
||||
|
||||
content.Add(SoftwareCardView.Text("RECOVERED RESOURCES", "death-eyebrow"));
|
||||
VisualElement rewards = new();
|
||||
rewards.AddToClassList("death-section");
|
||||
rewards.AddToClassList("death-rewards");
|
||||
rewards.Add(RewardReadout("#", _runManager.AccruedBandwidth, "bandwidth", false));
|
||||
rewards.Add(RewardReadout("*", _runManager.AccruedEntropy, "entropy", _runManager.AccruedEntropy <= 0));
|
||||
content.Add(rewards);
|
||||
content.Add(SoftwareCardView.Text("Return to your collection to prepare the next run.", "death-next-run"));
|
||||
|
||||
Button returnButton = new(() => SceneLoader.LoadMainMenu(_root)) { text = "> return to menu" };
|
||||
returnButton.AddToClassList("primary-action");
|
||||
returnButton.AddToClassList("death-return-action");
|
||||
if (!string.IsNullOrEmpty(_saveError))
|
||||
{
|
||||
content.Add(OverlayLine((_runManager.RewardsSettled ? "Could not reload saved progress: " : "Rewards are not saved yet: ") + _saveError));
|
||||
var retrySave = new Button(() => { SettleRunRewardsIfNeeded(); Refresh(); }) { text = "Retry saving rewards" };
|
||||
content.Add(retrySave);
|
||||
returnButton.SetEnabled(_runManager.RewardsSettled);
|
||||
}
|
||||
content.Add(returnButton);
|
||||
|
||||
var scroll = new ScrollView(ScrollViewMode.Vertical);
|
||||
scroll.AddToClassList("death-scroll");
|
||||
scroll.horizontalScrollerVisibility = ScrollerVisibility.Hidden;
|
||||
// Center within the actual viewport, including Unity's internal ScrollView wrapper.
|
||||
// A minimum (not fixed) height lets short windows scroll the entire report.
|
||||
scroll.contentContainer.style.alignItems = Align.Center;
|
||||
scroll.contentContainer.style.justifyContent = Justify.Center;
|
||||
scroll.contentViewport.RegisterCallback<GeometryChangedEvent>(evt =>
|
||||
scroll.contentContainer.style.minHeight = evt.newRect.height);
|
||||
scroll.Add(content);
|
||||
screen.Add(scroll);
|
||||
return screen;
|
||||
@@ -1042,21 +1387,35 @@ namespace KernelPanic.UI
|
||||
|
||||
private void SettleRunRewardsIfNeeded()
|
||||
{
|
||||
if (_runManager == null || _saveService == null)
|
||||
if (_runManager?.CurrentConfig?.IsTutorial == true) return;
|
||||
if (_runManager == null || _saveService == null || _runManager.IsSuspended || _runManager.CurrentConfig == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!_runManager.TrySettleRunRewards(out int bandwidth, out int entropy))
|
||||
if (_runManager.RewardsSettled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
SaveData data = _saveService.Load();
|
||||
data.bandwidthBalance = Math.Max(0, data.bandwidthBalance) + bandwidth;
|
||||
data.entropyBalance = Math.Max(0, data.entropyBalance) + entropy;
|
||||
data.RecordRunStats(_runManager.CurrentConfig?.Distro?.Id, _runManager.CurrentWaveNumber);
|
||||
_saveService.Save(data);
|
||||
try
|
||||
{
|
||||
SaveData data = _saveService.Load();
|
||||
data.bandwidthBalance = Math.Max(0, data.bandwidthBalance) + _runManager.AccruedBandwidth;
|
||||
data.entropyBalance = Math.Max(0, data.entropyBalance) + _runManager.AccruedEntropy;
|
||||
data.RecordRunStats(_runManager.CurrentConfig?.Distro?.Id,
|
||||
_combatManager.RunCompleted ? _runManager.WavesCleared : _runManager.CurrentWaveNumber);
|
||||
if (_combatManager.RunFinished) RunHistory.Record(data.recentRuns, GetRunHistoryEntry());
|
||||
if (data.activeRun?.runId == _runManager.RunId) data.activeRun = null;
|
||||
_saveService.Save(data);
|
||||
_lastKnownSave = data;
|
||||
_runManager.MarkRunRewardsSettled();
|
||||
_saveError = null;
|
||||
}
|
||||
catch (Exception ex) when (ex is IOException || ex is InvalidDataException || ex is UnauthorizedAccessException)
|
||||
{
|
||||
_saveError = ex.Message;
|
||||
}
|
||||
}
|
||||
|
||||
private VisualElement BuildRepositoryView()
|
||||
@@ -1069,6 +1428,7 @@ namespace KernelPanic.UI
|
||||
ScrollView body = new(ScrollViewMode.Vertical);
|
||||
body.AddToClassList("repository-body");
|
||||
body.AddToClassList("screen-frame-content");
|
||||
if (_runManager.Journey.campaign) body.Add(RunRouteView.Build(_runManager, _combatManager));
|
||||
|
||||
VisualElement offers = new();
|
||||
offers.AddToClassList("repository-offers");
|
||||
@@ -1105,6 +1465,8 @@ namespace KernelPanic.UI
|
||||
Button leave = new(() => _combatManager.ContinueToNextWave()) { text = "> boot next-wave" };
|
||||
leave.AddToClassList("primary-action");
|
||||
leave.AddToClassList("repository-leave-action");
|
||||
leave.SetEnabled(!_runManager.CampaignChoicePending);
|
||||
if (_runManager.CampaignChoicePending) leave.text = "Choose finish or endless above";
|
||||
VisualElement leaveBlock = new();
|
||||
leaveBlock.AddToClassList("repository-leave-block");
|
||||
leaveBlock.Add(leave);
|
||||
@@ -1112,11 +1474,35 @@ namespace KernelPanic.UI
|
||||
banked.AddToClassList("repository-banked-hint");
|
||||
banked.AddToClassList("screen-frame-hint");
|
||||
leaveBlock.Add(banked);
|
||||
var suspend = new Button(SaveAndExitRun) { name = "SaveAndExitRunButton", text = "save & exit" };
|
||||
suspend.AddToClassList("primary-action");
|
||||
suspend.AddToClassList("repository-leave-action");
|
||||
suspend.SetEnabled(!_runManager.IsSuspended);
|
||||
leaveBlock.Add(suspend);
|
||||
if (!string.IsNullOrEmpty(_checkpointError))
|
||||
leaveBlock.Add(TerminalLayout.BodyText("Save failed: " + _checkpointError + " Stay here and retry.", className: "screen-frame-hint"));
|
||||
footer.Add(leaveBlock);
|
||||
repo.Add(footer);
|
||||
return repo;
|
||||
}
|
||||
|
||||
private void SaveAndExitRun()
|
||||
{
|
||||
if (_runManager.IsSuspended || !_combatManager.AwaitingWaveContinue) return;
|
||||
try
|
||||
{
|
||||
RunCheckpointService.SaveAndSuspend(_saveService, _runManager, _combatManager);
|
||||
_checkpointError = null;
|
||||
_overlay.SetEnabled(false);
|
||||
SceneLoader.LoadMainMenu(_root);
|
||||
}
|
||||
catch (Exception ex) when (ex is IOException || ex is InvalidDataException || ex is UnauthorizedAccessException)
|
||||
{
|
||||
_checkpointError = ex.Message;
|
||||
Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
private VisualElement BuildRepositoryHeader()
|
||||
{
|
||||
VisualElement header = new();
|
||||
@@ -1300,6 +1686,7 @@ namespace KernelPanic.UI
|
||||
PlayCardWithFeedback(card);
|
||||
});
|
||||
button.text = string.Empty;
|
||||
button.userData = card;
|
||||
button.AddToClassList("hand-card");
|
||||
if (_combatManager.PendingTargetCard == card)
|
||||
{
|
||||
@@ -1325,13 +1712,25 @@ namespace KernelPanic.UI
|
||||
{
|
||||
VisualElement face = new();
|
||||
face.AddToClassList("hand-card");
|
||||
PopulateCardFace(face, card);
|
||||
SoftwareCardView.Populate(face, card, GetDisplayCardCost(card));
|
||||
return face;
|
||||
}
|
||||
|
||||
private void PopulateCardFace(VisualElement target, CardInstance card)
|
||||
{
|
||||
SoftwareCardView.Populate(target, card, GetDisplayCardCost(card));
|
||||
var preview = CardPreviewService.Build(_combatManager, card);
|
||||
if (!string.IsNullOrEmpty(preview.Summary) && !preview.Summary.StartsWith("Utility", StringComparison.Ordinal))
|
||||
{
|
||||
string timing = card.Definition.ResolutionTrack == ResolutionTrack.Native ? "now: " : "preview: ";
|
||||
var label = SoftwareCardView.Text(timing + preview.Summary + (preview.IsConditional ? " *" : ""), "software-live-preview");
|
||||
target.Q(className: "software-body")?.Add(label);
|
||||
}
|
||||
// Rules are already printed on the card. Keep hover help contextual and brief.
|
||||
target.tooltip = card.IsBroken ? CardPreviewService.CorruptionDetails(card)
|
||||
: card.IsLocked ? "Unlock for 1 Cycle before playing."
|
||||
: preview.IsConditional ? "Current estimate; targets, defenses and later effects can change the result."
|
||||
: "";
|
||||
}
|
||||
|
||||
private static VisualElement IntentPanel(EnemyIntent intent)
|
||||
@@ -1729,6 +2128,8 @@ namespace KernelPanic.UI
|
||||
}
|
||||
|
||||
_schedulerActivity.text = $"> {DisplayName(payload.Card.Definition)} dispatched / {SoftwareCardView.TrackName(payload.Track)}";
|
||||
_firstBattleGuide?.CardPlayed(payload.Track, DisplayName(payload.Card.Definition));
|
||||
_tutorial?.ObserveCard(payload.Track);
|
||||
VisualElement source = _handCardElements.TryGetValue(payload.Card, out VisualElement cardElement) ? cardElement : null;
|
||||
VisualElement destination = payload.Track switch
|
||||
{
|
||||
@@ -1754,6 +2155,8 @@ namespace KernelPanic.UI
|
||||
}
|
||||
|
||||
_executionSequence++;
|
||||
_firstBattleGuide?.CardResolved(DisplayName(payload.Card.Definition), payload.Track);
|
||||
_tutorial?.ObserveResolved(payload.Track);
|
||||
_schedulerActivity.text = $"[{_executionSequence:00} OK] {DisplayName(payload.Card.Definition)} / {SoftwareCardView.TrackName(payload.Track)}";
|
||||
AppendCombatLog($"{DisplayName(payload.Card.Definition)} resolved / {SoftwareCardView.TrackName(payload.Track)}.", "journal-operation");
|
||||
if (payload.Track == ResolutionTrack.InterpreterQueue)
|
||||
@@ -1778,6 +2181,8 @@ namespace KernelPanic.UI
|
||||
|
||||
private void HandlePhaseChanged(PhaseChangedEvent payload)
|
||||
{
|
||||
_firstBattleGuide?.PhaseChanged(payload.NextPhase);
|
||||
_tutorial?.ObservePhase(payload.NextPhase);
|
||||
if (payload.NextPhase == TurnPhase.Interpret)
|
||||
{
|
||||
_executionSequence = 0;
|
||||
@@ -2980,42 +3385,24 @@ namespace KernelPanic.UI
|
||||
|
||||
private static VisualElement TurnStat(string labelText, string valueText)
|
||||
{
|
||||
VisualElement row = new();
|
||||
row.AddToClassList("turn-stat-row");
|
||||
Label label = new(labelText);
|
||||
label.AddToClassList("turn-stat-label");
|
||||
Label value = new(valueText);
|
||||
value.AddToClassList("turn-stat-value");
|
||||
row.Add(label);
|
||||
row.Add(value);
|
||||
return row;
|
||||
return TerminalLayout.StatRow(labelText, valueText, rowClass: "turn-stat-row",
|
||||
keyClass: "turn-stat-label", valueClass: "turn-stat-value");
|
||||
}
|
||||
|
||||
private static Label OverlayTitle(string text)
|
||||
{
|
||||
Label label = new(text);
|
||||
label.AddToClassList("overlay-title");
|
||||
return label;
|
||||
return TerminalLayout.Heading(text, className: "overlay-title");
|
||||
}
|
||||
|
||||
private static Label OverlayLine(string text)
|
||||
{
|
||||
Label label = new(text);
|
||||
label.AddToClassList("overlay-line");
|
||||
return label;
|
||||
return TerminalLayout.BodyText(text, className: "overlay-line");
|
||||
}
|
||||
|
||||
private static VisualElement DeathStat(string labelText, string valueText)
|
||||
{
|
||||
VisualElement row = new();
|
||||
row.AddToClassList("death-stat-row");
|
||||
Label label = new(labelText);
|
||||
label.AddToClassList("death-stat-label");
|
||||
Label value = new(valueText);
|
||||
value.AddToClassList("death-stat-value");
|
||||
row.Add(label);
|
||||
row.Add(value);
|
||||
return row;
|
||||
return TerminalLayout.StatRow(labelText, valueText, rowClass: "death-stat-row",
|
||||
keyClass: "death-stat-label", valueClass: "death-stat-value");
|
||||
}
|
||||
|
||||
private static VisualElement RewardReadout(string iconText, int amount, string currencyName, bool subdued)
|
||||
|
||||
@@ -4,7 +4,7 @@ namespace KernelPanic.UI
|
||||
{
|
||||
/// <summary>
|
||||
/// Maps number-row/keypad digits to menu slot indices. Shared by the command menu and the
|
||||
/// starter-selection modal so both keep the same 1-5 shortcut behavior.
|
||||
/// starter-selection modal. Callers only accept slots present in their own menu.
|
||||
/// </summary>
|
||||
internal static class CommandKeyBindings
|
||||
{
|
||||
@@ -17,6 +17,7 @@ namespace KernelPanic.UI
|
||||
KeyCode.Alpha3 or KeyCode.Keypad3 => 2,
|
||||
KeyCode.Alpha4 or KeyCode.Keypad4 => 3,
|
||||
KeyCode.Alpha5 or KeyCode.Keypad5 => 4,
|
||||
KeyCode.Alpha6 or KeyCode.Keypad6 => 5,
|
||||
_ => -1
|
||||
};
|
||||
}
|
||||
|
||||
@@ -10,15 +10,18 @@ namespace KernelPanic.UI
|
||||
"daemon" => "<?>", "firewalld" => "[#]", "cron_job" => "[@]",
|
||||
"orphan_process" => "[.]", "segfault" => "[!]", "race_condition" => "[~]",
|
||||
"rootkit" => "[?]", "kernel_panic" => "[!!]", "telemetry_collector" => "[::]",
|
||||
"drm_guardian" => "[$]", _ => "[>]"
|
||||
"drm_guardian" => "[$]", "kernel_overseer" => "[K]", _ => "[>]"
|
||||
};
|
||||
|
||||
public static string Lifecycle(EnemyInstance enemy) => enemy.PendingRevive ? "RESTART PENDING"
|
||||
: enemy.State.IsDefeated || enemy.DefeatedPendingRemoval ? "TERMINATED"
|
||||
: enemy.Archetype.Tier == EnemyTier.Boss ? "BOSS PROCESS"
|
||||
: enemy.HasRevived ? "RUNNING / RESTART USED" : enemy.HasEliteSignal ? "ELITE PROCESS" : "RUNNING";
|
||||
|
||||
public static string Behavior(EnemyInstance enemy)
|
||||
{
|
||||
if (enemy.HasBehavior(EnemyBehaviorFlags.BossCycle))
|
||||
return "Shield > probe > heavy interrupt / next attacks +3 below half uptime";
|
||||
if (enemy.HasBehavior(EnemyBehaviorFlags.Revive))
|
||||
return enemy.PendingRevive ? "Revives next exchange" : enemy.HasRevived ? "Revival spent" : "Revival available / can be reaped";
|
||||
if (enemy.HasBehavior(EnemyBehaviorFlags.Grow))
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace KernelPanic.UI
|
||||
private VisualElement Chip(CardInstance card)
|
||||
{
|
||||
if (_chips.TryGetValue(card, out var chip)) return chip;
|
||||
chip = new VisualElement { userData = card, tooltip = CardEffectFactory.GetRulesText(card) };
|
||||
chip = new VisualElement { userData = card, tooltip = CardEffectFactory.GetRulesText(card), focusable = true, tabIndex = 0 };
|
||||
chip.AddToClassList("card-chip");
|
||||
chip.Add(SoftwareCardView.Text("", "execution-order"));
|
||||
chip.Add(SoftwareCardView.Text(card.Definition.DisplayName, "card-chip-name"));
|
||||
@@ -60,6 +60,30 @@ namespace KernelPanic.UI
|
||||
UpdateIdle();
|
||||
}
|
||||
|
||||
public void SyncMultipliers(IReadOnlyList<LazyStackEntry> pending)
|
||||
{
|
||||
if (_disposed) return;
|
||||
foreach (var entry in pending)
|
||||
{
|
||||
var chip = Chip(entry.Card);
|
||||
var multiplier = chip.Q<Label>(className: "execution-multiplier");
|
||||
if (multiplier == null)
|
||||
{
|
||||
multiplier = SoftwareCardView.Text(entry.MultiplierLabel, "execution-multiplier");
|
||||
chip.Add(multiplier);
|
||||
}
|
||||
multiplier.text = entry.MultiplierLabel;
|
||||
chip.tooltip = CardEffectFactory.GetRulesText(entry.Card) + $"\nCaptured {entry.MultiplierLabel}: damage and explicit Shield only.";
|
||||
}
|
||||
}
|
||||
|
||||
public void SyncPreviews(CombatManager combat, IReadOnlyList<CardInstance> pending)
|
||||
{
|
||||
if (_disposed) return;
|
||||
foreach (var card in pending)
|
||||
Chip(card).tooltip = CardEffectFactory.GetRulesText(card) + "\n\n" + CardPreviewService.Build(combat, card).Details;
|
||||
}
|
||||
|
||||
public void Resolving(CardInstance card)
|
||||
{
|
||||
if (_disposed || card?.Definition == null) return;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -36,6 +36,7 @@ namespace KernelPanic.UI
|
||||
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);
|
||||
var body = new VisualElement();
|
||||
body.AddToClassList("software-body");
|
||||
// Break at a sentence boundary only. Never reinterpret effect amounts or conditions.
|
||||
@@ -46,7 +47,10 @@ namespace KernelPanic.UI
|
||||
|
||||
var footer = new VisualElement();
|
||||
footer.AddToClassList("software-footer");
|
||||
string state = card.IsBroken ? "[!] CORRUPTED" : card.IsLocked ? $"[L] UNLOCK {EnemyArchetypeCatalog.DrmUnlockCycleCost}c"
|
||||
string state = card.IsBroken
|
||||
? card.CorruptionRoundsRemaining > 0
|
||||
? $"[!] RECOVER {card.CorruptionRoundsRemaining} {(card.CorruptionRoundsRemaining == 1 ? "ROUND" : "ROUNDS")}" : "[!] CORRUPTED"
|
||||
: card.IsLocked ? $"[L] UNLOCK {EnemyArchetypeCatalog.DrmUnlockCycleCost}c"
|
||||
: card.IsUpgraded ? $"[+] PATCH {card.UpgradeLevel}" : definition.IsToken ? "TOKEN" : definition.DistroExclusive ? "DISTRO" : "";
|
||||
footer.Add(Text(state, "software-state"));
|
||||
footer.Add(Text(definition.Rarity.ToString(), "software-rarity"));
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace KernelPanic.UI
|
||||
{
|
||||
internal static readonly string[] Commands =
|
||||
{
|
||||
"./start_run", "ls ~/collection", "curl gacha.sh | sh", "dpkg-reconfigure", "shutdown -h now"
|
||||
"./start_run", "ls ~/collection", "curl gacha.sh | sh", "dpkg-reconfigure", "history --runs", "shutdown -h now"
|
||||
};
|
||||
private readonly List<string> _history = new();
|
||||
private readonly TextField _input;
|
||||
|
||||
@@ -16,13 +16,15 @@ namespace KernelPanic.UI
|
||||
if (font != null) root.style.unityFontDefinition = new StyleFontDefinition(font);
|
||||
StyleSheet sheet = Resources.Load<StyleSheet>("KernelTheme");
|
||||
if (sheet != null) root.styleSheets.Add(sheet);
|
||||
StyleSheet readability = Resources.Load<StyleSheet>("Readability");
|
||||
if (readability != null) root.styleSheets.Add(readability);
|
||||
root.RegisterCallback<GeometryChangedEvent>(evt =>
|
||||
{
|
||||
root.EnableInClassList("compact", evt.newRect.width < 1100);
|
||||
root.EnableInClassList("narrow", evt.newRect.width < 760);
|
||||
root.EnableInClassList("short-screen", evt.newRect.height < 760);
|
||||
});
|
||||
root.EnableInClassList("reduced-motion", UIPreferences.ReducedMotion);
|
||||
AttachPreferences(root);
|
||||
root.RegisterCallback<FocusInEvent>(evt =>
|
||||
{
|
||||
if (evt.target is not VisualElement control) return;
|
||||
@@ -36,6 +38,31 @@ namespace KernelPanic.UI
|
||||
AttachHints(root);
|
||||
}
|
||||
|
||||
private static void AttachPreferences(VisualElement root)
|
||||
{
|
||||
bool listening = false;
|
||||
void Apply()
|
||||
{
|
||||
root.EnableInClassList("reduced-motion", UIPreferences.ReducedMotion);
|
||||
root.EnableInClassList("text-large", UIPreferences.TextSize == UITextSize.Large);
|
||||
root.EnableInClassList("density-comfortable", UIPreferences.Density == UILayoutDensity.Comfortable);
|
||||
}
|
||||
void Subscribe()
|
||||
{
|
||||
if (!listening) UIPreferences.Changed += Apply;
|
||||
listening = true;
|
||||
Apply();
|
||||
}
|
||||
root.RegisterCallback<AttachToPanelEvent>(_ => Subscribe());
|
||||
root.RegisterCallback<DetachFromPanelEvent>(_ =>
|
||||
{
|
||||
if (listening) UIPreferences.Changed -= Apply;
|
||||
listening = false;
|
||||
});
|
||||
Apply();
|
||||
if (root.panel != null) Subscribe();
|
||||
}
|
||||
|
||||
public static void PreserveFocus(VisualElement region)
|
||||
{
|
||||
var focused = region?.focusController?.focusedElement as VisualElement;
|
||||
@@ -56,14 +83,16 @@ namespace KernelPanic.UI
|
||||
|
||||
public static void ConstrainModalFocus(VisualElement overlay)
|
||||
{
|
||||
overlay.RegisterCallback<KeyDownEvent>(evt =>
|
||||
// Tab produces a NavigationMoveEvent in both editor and runtime panels.
|
||||
// Handling KeyDown as well would move focus twice for a single key.
|
||||
overlay.RegisterCallback<NavigationMoveEvent>(evt =>
|
||||
{
|
||||
if (evt.keyCode != KeyCode.Tab) return;
|
||||
if (evt.direction != NavigationMoveEvent.Direction.Next && evt.direction != NavigationMoveEvent.Direction.Previous) return;
|
||||
var controls = new List<VisualElement>();
|
||||
overlay.Query<VisualElement>().ForEach(element =>
|
||||
{
|
||||
if (!element.focusable || !element.enabledInHierarchy || !element.visible || element.tabIndex < 0) return;
|
||||
if (element is not Button && element is not Toggle && element is not TextField) return;
|
||||
if (element is not Button && element is not Toggle && element is not TextField && element is not DropdownField) return;
|
||||
for (var p = element; p != overlay; p = p.parent)
|
||||
if (p == null || p.resolvedStyle.display == DisplayStyle.None) return;
|
||||
controls.Add(element);
|
||||
@@ -71,9 +100,9 @@ namespace KernelPanic.UI
|
||||
if (controls.Count == 0) return;
|
||||
var focused = overlay.focusController.focusedElement as VisualElement;
|
||||
int index = controls.FindIndex(control => control == focused || control.Contains(focused));
|
||||
controls[(index + (evt.shiftKey ? -1 : 1) + controls.Count) % controls.Count].Focus();
|
||||
overlay.panel.focusController.IgnoreEvent(evt);
|
||||
evt.StopImmediatePropagation();
|
||||
controls[(index + (evt.direction == NavigationMoveEvent.Direction.Previous ? -1 : 1) + controls.Count) % controls.Count].Focus();
|
||||
}, TrickleDown.TrickleDown);
|
||||
}
|
||||
|
||||
@@ -81,39 +110,81 @@ namespace KernelPanic.UI
|
||||
// Use the same tooltip strings for pointer and keyboard inspection at runtime.
|
||||
private static void AttachHints(VisualElement root)
|
||||
{
|
||||
var hint = new Label { pickingMode = PickingMode.Ignore, enableRichText = false };
|
||||
var hint = new ScrollView(ScrollViewMode.Vertical) { focusable = false };
|
||||
hint.AddToClassList("runtime-hint");
|
||||
hint.style.display = DisplayStyle.None;
|
||||
hint.horizontalScrollerVisibility = ScrollerVisibility.Hidden;
|
||||
hint.verticalScrollerVisibility = ScrollerVisibility.Auto;
|
||||
hint.contentContainer.focusable = false;
|
||||
hint.contentViewport.focusable = false;
|
||||
foreach (var control in new VisualElement[] { hint.verticalScroller, hint.verticalScroller.slider,
|
||||
hint.verticalScroller.lowButton, hint.verticalScroller.highButton })
|
||||
control.focusable = false;
|
||||
var body = new Label { pickingMode = PickingMode.Ignore, enableRichText = false, name = "RuntimeHintText" };
|
||||
body.style.whiteSpace = WhiteSpace.Normal;
|
||||
body.style.flexShrink = 0;
|
||||
hint.Add(body);
|
||||
VisualElement owner = null;
|
||||
IVisualElementScheduledItem pending = null;
|
||||
IVisualElementScheduledItem pendingHide = null;
|
||||
IVisualElementScheduledItem refresh = null;
|
||||
|
||||
bool InsideHint(VisualElement element) => element == hint || (element != null && hint.Contains(element));
|
||||
|
||||
void Hide()
|
||||
{
|
||||
pending?.Pause();
|
||||
pendingHide?.Pause();
|
||||
refresh?.Pause();
|
||||
owner = null;
|
||||
hint.style.display = DisplayStyle.None;
|
||||
}
|
||||
|
||||
void RefreshVisible()
|
||||
{
|
||||
if (owner?.panel == null || owner.resolvedStyle.display == DisplayStyle.None || string.IsNullOrWhiteSpace(owner.tooltip))
|
||||
{ Hide(); return; }
|
||||
body.text = owner.tooltip;
|
||||
float width = Mathf.Max(1, Mathf.Min(380, root.layout.width - 24));
|
||||
float heightLimit = Mathf.Max(1, root.layout.height - 24);
|
||||
// Reserve the vertical scrollbar in the measurement so long descriptions wrap
|
||||
// inside the viewport instead of growing the popup beyond the window edge.
|
||||
float measured = body.MeasureTextSize(body.text, Mathf.Max(1, width - 44),
|
||||
VisualElement.MeasureMode.Exactly, 0, VisualElement.MeasureMode.Undefined).y;
|
||||
float height = Mathf.Min(heightLimit, Mathf.Max(44, measured + 24));
|
||||
hint.style.width = width;
|
||||
hint.style.maxWidth = width;
|
||||
hint.style.height = height;
|
||||
hint.style.maxHeight = heightLimit;
|
||||
Vector2 point = root.WorldToLocal(owner.worldBound.min);
|
||||
hint.style.left = Mathf.Clamp(point.x, 12, Mathf.Max(12, root.layout.width - width - 12));
|
||||
hint.style.top = Mathf.Clamp(point.y - height - 8, 12, Mathf.Max(12, root.layout.height - height - 12));
|
||||
}
|
||||
|
||||
void Inspect(VisualElement element)
|
||||
{
|
||||
pendingHide?.Pause();
|
||||
if (InsideHint(element)) return;
|
||||
while (element != null && element != root && string.IsNullOrWhiteSpace(element.tooltip)) element = element.parent;
|
||||
if (element == null || element == root) { Hide(); return; }
|
||||
if (element == null || element == root)
|
||||
{
|
||||
// Allow the pointer to cross the small gap from the inspected item to its popup.
|
||||
pendingHide = root.schedule.Execute(Hide).StartingIn(180);
|
||||
return;
|
||||
}
|
||||
if (owner == element) return;
|
||||
Hide();
|
||||
owner = element;
|
||||
pending = root.schedule.Execute(() =>
|
||||
{
|
||||
if (owner?.panel == null || owner.resolvedStyle.display == DisplayStyle.None) { Hide(); return; }
|
||||
hint.text = owner.tooltip;
|
||||
if (hint.parent == null) root.Add(hint);
|
||||
hint.BringToFront();
|
||||
hint.style.display = DisplayStyle.Flex;
|
||||
Vector2 point = root.WorldToLocal(owner.worldBound.min);
|
||||
hint.style.maxWidth = Mathf.Min(380, root.layout.width - 24);
|
||||
hint.style.left = Mathf.Clamp(point.x, 12, Mathf.Max(12, root.layout.width - 392));
|
||||
hint.style.top = Mathf.Max(8, point.y - 8);
|
||||
// Position above the inspected control once text has been measured.
|
||||
hint.schedule.Execute(() => hint.style.top = Mathf.Clamp(point.y - hint.layout.height - 8, 8, Mathf.Max(8, root.layout.height - hint.layout.height - 8)));
|
||||
hint.scrollOffset = Vector2.zero;
|
||||
RefreshVisible();
|
||||
refresh ??= root.schedule.Execute(RefreshVisible).Every(100);
|
||||
refresh.Resume();
|
||||
}).StartingIn(450);
|
||||
}
|
||||
|
||||
@@ -121,14 +192,29 @@ namespace KernelPanic.UI
|
||||
root.RegisterCallback<FocusInEvent>(evt => Inspect(evt.target as VisualElement));
|
||||
root.RegisterCallback<PointerLeaveEvent>(_ => Hide());
|
||||
root.RegisterCallback<FocusOutEvent>(_ => Hide());
|
||||
root.RegisterCallback<PointerDownEvent>(_ => Hide(), TrickleDown.TrickleDown);
|
||||
root.RegisterCallback<WheelEvent>(_ => Hide(), TrickleDown.TrickleDown);
|
||||
root.RegisterCallback<KeyDownEvent>(_ => Hide(), TrickleDown.TrickleDown);
|
||||
root.RegisterCallback<PointerDownEvent>(evt => { if (!InsideHint(evt.target as VisualElement)) Hide(); }, TrickleDown.TrickleDown);
|
||||
root.RegisterCallback<WheelEvent>(evt => { if (!InsideHint(evt.target as VisualElement)) Hide(); }, TrickleDown.TrickleDown);
|
||||
root.RegisterCallback<KeyDownEvent>(evt =>
|
||||
{
|
||||
var focused = root.focusController?.focusedElement as VisualElement;
|
||||
if (owner != null && hint.style.display.value != DisplayStyle.None &&
|
||||
(focused == owner || (focused != null && owner.Contains(focused))) &&
|
||||
(evt.keyCode == KeyCode.PageDown || evt.keyCode == KeyCode.PageUp))
|
||||
{
|
||||
float direction = evt.keyCode == KeyCode.PageDown ? 1 : -1;
|
||||
hint.scrollOffset = new Vector2(0, Mathf.Clamp(hint.scrollOffset.y + direction * hint.contentViewport.layout.height * 0.8f,
|
||||
0, hint.verticalScroller.highValue));
|
||||
evt.StopImmediatePropagation();
|
||||
return;
|
||||
}
|
||||
Hide();
|
||||
}, TrickleDown.TrickleDown);
|
||||
root.RegisterCallback<DetachFromPanelEvent>(_ => Hide());
|
||||
}
|
||||
|
||||
public static void SetDistro(VisualElement root, DistroDefinition distro)
|
||||
{
|
||||
foreach (string id in new[] { "arch", "ubuntu", "fedora", "mint" })
|
||||
foreach (string id in new[] { "arch", "ubuntu", "fedora", "mint", "gentoo" })
|
||||
root.EnableInClassList("distro-" + id, distro != null && distro.Id == id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,103 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace KernelPanic.UI
|
||||
{
|
||||
/// <summary>
|
||||
/// Stores UI-level accessibility preferences for runtime presentation.
|
||||
/// </summary>
|
||||
public enum UITextSize { Standard, Large }
|
||||
public enum UILayoutDensity { Compact, Comfortable }
|
||||
|
||||
/// <summary>Presentation preferences are device-local and independent of progression saves.</summary>
|
||||
public static class UIPreferences
|
||||
{
|
||||
public static bool ReducedMotion { get; set; } // TODO: Persist with settings once settings storage exists.
|
||||
private const string StorageKey = "KernelPanic.UI.Preferences.v1";
|
||||
private static bool _reducedMotion;
|
||||
private static UITextSize _textSize;
|
||||
private static UILayoutDensity _density;
|
||||
|
||||
public static event Action Changed;
|
||||
|
||||
static UIPreferences() => Load();
|
||||
|
||||
public static bool ReducedMotion
|
||||
{
|
||||
get => _reducedMotion;
|
||||
set
|
||||
{
|
||||
if (_reducedMotion == value) return;
|
||||
_reducedMotion = value;
|
||||
Changed?.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
public static UITextSize TextSize
|
||||
{
|
||||
get => _textSize;
|
||||
set
|
||||
{
|
||||
value = value == UITextSize.Large ? UITextSize.Large : UITextSize.Standard;
|
||||
if (_textSize == value) return;
|
||||
_textSize = value;
|
||||
Changed?.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
public static UILayoutDensity Density
|
||||
{
|
||||
get => _density;
|
||||
set
|
||||
{
|
||||
value = value == UILayoutDensity.Comfortable ? UILayoutDensity.Comfortable : UILayoutDensity.Compact;
|
||||
if (_density == value) return;
|
||||
_density = value;
|
||||
Changed?.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
// Also reload when entering Play mode with domain reload disabled.
|
||||
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
|
||||
public static void Load() => LoadFromKey(StorageKey);
|
||||
|
||||
// Setters only affect the current presentation. User settings explicitly commit changes,
|
||||
// so combat fixtures and temporary presentation overrides never change saved preferences.
|
||||
public static void Save() => SaveToKey(StorageKey);
|
||||
|
||||
internal static void LoadFromKey(string key)
|
||||
{
|
||||
StoredPreferences stored = null;
|
||||
if (PlayerPrefs.HasKey(key))
|
||||
{
|
||||
try { stored = JsonUtility.FromJson<StoredPreferences>(PlayerPrefs.GetString(key)); }
|
||||
catch (ArgumentException) { /* Invalid or incomplete preferences use safe defaults. */ }
|
||||
}
|
||||
if (stored == null || stored.version != 1) stored = new StoredPreferences();
|
||||
bool motion = stored.reducedMotion;
|
||||
var size = stored.textSize == (int)UITextSize.Large ? UITextSize.Large : UITextSize.Standard;
|
||||
var density = stored.density == (int)UILayoutDensity.Comfortable ? UILayoutDensity.Comfortable : UILayoutDensity.Compact;
|
||||
bool changed = motion != _reducedMotion || size != _textSize || density != _density;
|
||||
_reducedMotion = motion;
|
||||
_textSize = size;
|
||||
_density = density;
|
||||
if (changed) Changed?.Invoke();
|
||||
}
|
||||
|
||||
internal static void SaveToKey(string key)
|
||||
{
|
||||
PlayerPrefs.SetString(key, JsonUtility.ToJson(new StoredPreferences
|
||||
{
|
||||
reducedMotion = _reducedMotion,
|
||||
textSize = (int)_textSize,
|
||||
density = (int)_density
|
||||
}));
|
||||
PlayerPrefs.Save();
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
private sealed class StoredPreferences
|
||||
{
|
||||
public int version = 1;
|
||||
public bool reducedMotion;
|
||||
public int textSize;
|
||||
public int density;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user