Revamp UI a whole lot
This commit is contained in:
@@ -19,6 +19,7 @@ namespace KernelPanic.UI
|
||||
{
|
||||
internal static class TerminalFontResolver
|
||||
{
|
||||
private const string BundledFontResourcePath = "Fonts/JetBrainsMono-Regular";
|
||||
private static readonly string[] PreferredMonospaceFontFamilies =
|
||||
{
|
||||
"Consolas",
|
||||
@@ -46,8 +47,12 @@ namespace KernelPanic.UI
|
||||
return _runtimeMonospaceFont;
|
||||
}
|
||||
|
||||
Font dynamicFont = Font.CreateDynamicFontFromOSFont(PreferredMonospaceFontFamilies, 16);
|
||||
if (dynamicFont == null)
|
||||
// Keep metrics and ASCII alignment identical on every supported platform.
|
||||
// The OS lookup remains as a recovery path for development projects that
|
||||
// deliberately remove the bundled font.
|
||||
Font sourceFont = Resources.Load<Font>(BundledFontResourcePath);
|
||||
sourceFont ??= Font.CreateDynamicFontFromOSFont(PreferredMonospaceFontFamilies, 16);
|
||||
if (sourceFont == null)
|
||||
{
|
||||
if (!_warnedMissingFont)
|
||||
{
|
||||
@@ -58,7 +63,7 @@ namespace KernelPanic.UI
|
||||
return null;
|
||||
}
|
||||
|
||||
_runtimeMonospaceFont = FontAsset.CreateFontAsset(dynamicFont);
|
||||
_runtimeMonospaceFont = FontAsset.CreateFontAsset(sourceFont);
|
||||
return _runtimeMonospaceFont;
|
||||
}
|
||||
}
|
||||
@@ -229,12 +234,12 @@ namespace KernelPanic.UI
|
||||
TerminalTheme.ConstrainModalFocus(_root.Q("RootCreditExchangeModal"));
|
||||
Toggle motion = _root.Q<Toggle>("ReducedMotionToggle");
|
||||
motion.SetValueWithoutNotify(UIPreferences.ReducedMotion);
|
||||
motion.text = UIPreferences.ReducedMotion ? "[ true ]" : "[ false ]";
|
||||
motion.text = UIPreferences.ReducedMotion ? "true" : "false";
|
||||
motion.RegisterValueChangedCallback(evt =>
|
||||
{
|
||||
UIPreferences.ReducedMotion = evt.newValue;
|
||||
UIPreferences.Save();
|
||||
motion.text = evt.newValue ? "[ true ]" : "[ false ]";
|
||||
motion.text = evt.newValue ? "true" : "false";
|
||||
_root.EnableInClassList("reduced-motion", evt.newValue);
|
||||
_shellRoot.EnableInClassList("reduced-motion", evt.newValue);
|
||||
if (evt.newValue && !_bootIntroPanel.ClassListContains(HiddenClassName)) CompleteBootIntro();
|
||||
@@ -242,12 +247,13 @@ namespace KernelPanic.UI
|
||||
});
|
||||
Button textSize = _root.Q<Button>("TextSizeButton");
|
||||
Button density = _root.Q<Button>("DensityButton");
|
||||
_root.Q<Button>("SoundVolumeButton").clicked += () =>
|
||||
SliderInt soundVolume = _root.Q<SliderInt>("SoundVolumeSlider");
|
||||
soundVolume.RegisterValueChangedCallback(evt =>
|
||||
{
|
||||
UIPreferences.SoundVolume = (UIPreferences.SoundVolume / 25 + 1) % 5 * 25;
|
||||
UIPreferences.SoundVolume = evt.newValue;
|
||||
UIPreferences.Save();
|
||||
RefreshPreferenceControls();
|
||||
};
|
||||
RefreshSoundVolumeControl();
|
||||
});
|
||||
textSize.clicked += () =>
|
||||
{
|
||||
UIPreferences.TextSize = UIPreferences.TextSize == UITextSize.Standard ? UITextSize.Large : UITextSize.Standard;
|
||||
@@ -267,10 +273,20 @@ namespace KernelPanic.UI
|
||||
{
|
||||
Toggle motion = _root.Q<Toggle>("ReducedMotionToggle");
|
||||
motion.SetValueWithoutNotify(UIPreferences.ReducedMotion);
|
||||
motion.text = UIPreferences.ReducedMotion ? "[ true ]" : "[ false ]";
|
||||
_root.Q<Button>("TextSizeButton").text = UIPreferences.TextSize == UITextSize.Large ? "[ large ]" : "[ standard ]";
|
||||
_root.Q<Button>("DensityButton").text = UIPreferences.Density == UILayoutDensity.Comfortable ? "[ comfortable ]" : "[ compact ]";
|
||||
_root.Q<Button>("SoundVolumeButton").text = UIPreferences.SoundVolume == 0 ? "[ muted ]" : $"[ {UIPreferences.SoundVolume}% ]";
|
||||
motion.text = UIPreferences.ReducedMotion ? "true" : "false";
|
||||
_root.Q<Button>("TextSizeButton").text = UIPreferences.TextSize == UITextSize.Large ? "large" : "standard";
|
||||
_root.Q<Button>("DensityButton").text = UIPreferences.Density == UILayoutDensity.Comfortable ? "comfortable" : "compact";
|
||||
RefreshSoundVolumeControl();
|
||||
}
|
||||
|
||||
private void RefreshSoundVolumeControl()
|
||||
{
|
||||
SliderInt slider = _root.Q<SliderInt>("SoundVolumeSlider");
|
||||
slider.SetValueWithoutNotify(UIPreferences.SoundVolume);
|
||||
int filled = Mathf.RoundToInt(UIPreferences.SoundVolume / 10f);
|
||||
string meter = new string('#', filled) + new string('-', 10 - filled);
|
||||
_root.Q<Label>("SoundVolumeValue").text = UIPreferences.SoundVolume == 0
|
||||
? "[----------] muted" : $"[{meter}] {UIPreferences.SoundVolume}%";
|
||||
}
|
||||
|
||||
private void ComposeMetaServices()
|
||||
@@ -285,6 +301,10 @@ namespace KernelPanic.UI
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
// A script import can re-enable the scene component before Awake has rebound the
|
||||
// UIDocument. The next normal Play-mode enable follows the usual Awake -> OnEnable
|
||||
// order; this guard only protects that editor/domain-reload edge.
|
||||
if (_root == null) return;
|
||||
RegisterCallbacks();
|
||||
_root.Focus();
|
||||
_root.EnableInClassList("reduced-motion", UIPreferences.ReducedMotion);
|
||||
@@ -322,7 +342,7 @@ namespace KernelPanic.UI
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
UnregisterCallbacks();
|
||||
if (_root != null) UnregisterCallbacks();
|
||||
_blinkSchedule?.Pause();
|
||||
_backgroundLog?.Stop();
|
||||
_bootIntroSchedule?.Pause();
|
||||
@@ -926,9 +946,15 @@ namespace KernelPanic.UI
|
||||
private void ClaimDailyQuest(DailyQuestKind kind, long period)
|
||||
{
|
||||
if (PersistenceBlocked || _runLaunchPending) return;
|
||||
bool completionBonusWasClaimed = DailyQuests.CompletionBonusClaimed(_saveData.dailyQuests);
|
||||
bool claimed = DailyQuests.Claim(_saveData, kind, period, DateTime.UtcNow);
|
||||
bool completionBonusAwarded = claimed && !completionBonusWasClaimed
|
||||
&& DailyQuests.CompletionBonusClaimed(_saveData.dailyQuests);
|
||||
if (claimed)
|
||||
{
|
||||
_wallet.SetBalance(_saveData.entropyBalance);
|
||||
_gachaService.SetCurrencyBalance(GachaCurrencyType.StandardPull, _saveData.commitsBalance);
|
||||
}
|
||||
// Balances and the claim bit are committed in the same atomic save.
|
||||
// On failure the existing recovery dialog blocks spending until retry succeeds.
|
||||
SaveCurrentState();
|
||||
@@ -939,7 +965,12 @@ namespace KernelPanic.UI
|
||||
if (feedback != null && claimed && !PersistenceBlocked)
|
||||
{
|
||||
var reward = DailyQuests.Reward(kind);
|
||||
feedback.text = $"[ OK ] Daily task completed.\n[ OK ] +{reward.Bandwidth} Bandwidth, +{reward.Entropy} Entropy deposited.";
|
||||
int commits = DailyQuests.CommitReward(kind);
|
||||
string commitText = commits > 0 ? $" +{commits} Commit{(commits == 1 ? string.Empty : "s")} deposited." : string.Empty;
|
||||
feedback.text = $"[ OK ] Daily task completed.\n[ OK ] +{reward.Bandwidth} Bandwidth, +{reward.Entropy} Entropy deposited.{commitText}";
|
||||
if (completionBonusAwarded)
|
||||
feedback.text += $"\n[ BONUS ] All {DailyQuests.Count} tasks: +{DailyQuests.CompletionBonusBandwidth} Bandwidth, "
|
||||
+ $"+{DailyQuests.CompletionBonusEntropy} Entropy, +{DailyQuests.CompletionBonusCommits} Commits.";
|
||||
feedback.style.display = DisplayStyle.Flex;
|
||||
}
|
||||
else if (feedback != null && PersistenceBlocked) feedback.style.display = DisplayStyle.None;
|
||||
@@ -2543,6 +2574,12 @@ namespace KernelPanic.UI
|
||||
_dailyQuestReturnToPrompt = true;
|
||||
return;
|
||||
}
|
||||
if (index == 7)
|
||||
{
|
||||
ShowGacha();
|
||||
gachaScreen.OpenPullHistory();
|
||||
return;
|
||||
}
|
||||
_commandEntries[index].Activate();
|
||||
_root.Focus();
|
||||
}
|
||||
@@ -2587,24 +2624,58 @@ namespace KernelPanic.UI
|
||||
string detail = valid
|
||||
? $"{DistroPresentation.DisplayName(distro)} v{last.distroVersion}; {string.Join(" + ", last.languages)}. Uses the saved build and upgrade levels."
|
||||
: string.IsNullOrWhiteSpace(last?.distroId) ? "No previous build saved. Start a run to enable retries." : failure;
|
||||
actions.Add(TerminalLayout.Heading("[last build]"));
|
||||
actions.Add(TerminalLayout.BodyText(detail, "LastRunBuildSummary", "run-archive-summary"));
|
||||
actions.Add(TerminalLayout.Heading("$ history --runs --format=table"));
|
||||
var columns = TerminalLayout.BodyText("# TIMESTAMP DISTRO SEED WAVE EXIT", className: "run-archive-columns");
|
||||
actions.Add(columns);
|
||||
if (_saveData?.recentRuns == null || _saveData.recentRuns.Count == 0)
|
||||
{
|
||||
actions.Add(TerminalLayout.BodyText("history: no completed runs (exit 1)", "RunArchiveEmpty", "run-archive-empty"));
|
||||
}
|
||||
else
|
||||
{
|
||||
int visible = Mathf.Min(RunHistory.Capacity, _saveData.recentRuns.Count);
|
||||
for (int i = 0; i < visible; i++)
|
||||
actions.Add(TerminalLayout.BodyText(FormatRunHistoryRow(i + 1, _saveData.recentRuns[i]),
|
||||
$"RunArchiveRow{i}", "run-archive-table-row"));
|
||||
}
|
||||
|
||||
actions.Add(TerminalLayout.BodyText("# saved build", className: "run-archive-section-label"));
|
||||
actions.Add(TerminalLayout.BodyText((valid ? "ready: " : "unavailable: ") + detail,
|
||||
"LastRunBuildSummary", "run-archive-summary"));
|
||||
var commandsRow = new VisualElement();
|
||||
commandsRow.AddToClassList("run-archive-commands");
|
||||
var same = new Button(() => RetryLastRun(true))
|
||||
{
|
||||
name = "RetrySameSeedButton", text = "retry last run / same seed",
|
||||
name = "RetrySameSeedButton", text = "$ retry --build=last --seed=same",
|
||||
tooltip = valid && !last.hasRunSeed ? "The previous run has no saved seed. Repeat the build with a new seed instead." : detail
|
||||
};
|
||||
same.AddToClassList("terminal-button");
|
||||
same.AddToClassList("run-archive-command");
|
||||
same.SetEnabled(valid && last.hasRunSeed);
|
||||
actions.Add(same);
|
||||
var fresh = new Button(() => RetryLastRun(false)) { name = "RetryNewSeedButton", text = "repeat build / new seed", tooltip = detail };
|
||||
commandsRow.Add(same);
|
||||
var fresh = new Button(() => RetryLastRun(false)) { name = "RetryNewSeedButton", text = "$ retry --build=last --seed=random", tooltip = detail };
|
||||
fresh.AddToClassList("terminal-button");
|
||||
fresh.AddToClassList("run-archive-command");
|
||||
fresh.SetEnabled(valid);
|
||||
actions.Add(fresh);
|
||||
commandsRow.Add(fresh);
|
||||
|
||||
var history = new Button(OpenRunHistory) { name = "RecentRunsButton", text = "recent runs" };
|
||||
var history = new Button(OpenRunHistory) { name = "RecentRunsButton", text = "$ history --runs --inspect" };
|
||||
history.AddToClassList("terminal-button");
|
||||
actions.Add(history);
|
||||
history.AddToClassList("run-archive-command");
|
||||
commandsRow.Add(history);
|
||||
actions.Add(commandsRow);
|
||||
}
|
||||
|
||||
private static string FormatRunHistoryRow(int index, RunHistoryEntry entry)
|
||||
{
|
||||
if (entry == null) return $"{index,2} <corrupt entry>";
|
||||
string timestamp = DateTimeOffset.TryParse(entry.endedUtc, out var ended)
|
||||
? ended.ToLocalTime().ToString("yyyy-MM-dd HH:mm", CultureInfo.InvariantCulture)
|
||||
: "unknown";
|
||||
string distro = entry.distroName ?? entry.distroId ?? "unknown";
|
||||
if (distro.Length > 16) distro = distro.Substring(0, 15) + "~";
|
||||
string exit = entry.victory ? "0" : entry.surrendered ? "130" : "1";
|
||||
return $"{index,2} {timestamp,-16} {distro,-16} {entry.seed,10} {entry.waveReached,4} {exit}";
|
||||
}
|
||||
|
||||
private void AddResumeRunControl(VisualElement actions)
|
||||
|
||||
Reference in New Issue
Block a user