Implement overall improvements for code stability, fallbacks and keyboard interactions

This commit is contained in:
2026-11-29 03:05:21 +01:00
parent fdde7f9d80
commit 7efc63d130
10 changed files with 1343 additions and 235 deletions
@@ -50,6 +50,7 @@ namespace KernelPanic.UI
private UnitDetailTab _unitDetailTab = UnitDetailTab.Overview;
private PackageSlot? _packagePickerSlot;
private bool _unitDetailReturnsToOverview = true;
private bool _unitDetailReadOnly;
private DistroDefinition _equipWindowUnit;
private PackageSlot _equipWindowSlot;
private int _selectedUnitIndex;
@@ -111,6 +112,7 @@ namespace KernelPanic.UI
{
ClosePackageEquipWindow();
_mode = CollectionMode.Units;
_unitDetailReadOnly = false;
CurrentTitle = "$ ls ~/collection";
CurrentHint = "[esc] back [left/right] tabs [tab] focus [up/down] select [enter] select";
RenderUnits();
@@ -238,6 +240,7 @@ namespace KernelPanic.UI
if (_mode == CollectionMode.UnitDetail && _units.Count > 0)
{
if (_unitDetailReadOnly) return;
DistroDefinition unit = _units[_selectedUnitIndex];
switch (_unitDetailTab)
{
@@ -257,7 +260,7 @@ namespace KernelPanic.UI
public void SwitchUnitDetailTabRelative(int delta)
{
if (_mode != CollectionMode.UnitDetail || _units.Count == 0)
if (_mode != CollectionMode.UnitDetail || _units.Count == 0 || _unitDetailReadOnly)
{
return;
}
@@ -270,10 +273,10 @@ namespace KernelPanic.UI
ViewChanged?.Invoke();
}
public void ShowUnitDetail(DistroDefinition unit, bool returnToOverview)
public void ShowUnitDetail(DistroDefinition unit, bool returnToOverview, bool readOnly = false)
{
SelectUnitById(unit?.Id);
OpenUnitDetail(unit, true, returnToOverview);
OpenUnitDetail(unit, true, returnToOverview, readOnly);
}
private void RenderUnits()
@@ -621,7 +624,7 @@ namespace KernelPanic.UI
string upgradeMarker = CanUpgradeUnit(unit) ? " *" : string.Empty;
string listing = LsText($"{"drwxr-xr-x",-12}{"player",-8}{$"{GetDistroStars(unit)}★",-6}{$"{version}/{GachaTuning.MaxVersion}",-6}{languages,-20}{unit.Id}/{upgradeMarker}");
Button row = new();
Button row = new() { name = $"CollectionUnit_{unit.Id}" };
row.AddToClassList("collection-row");
row.AddToClassList("unit-overview-row");
row.AddToClassList(RarityPresentation.ForStars(GetDistroStars(unit)).ClassName);
@@ -796,14 +799,14 @@ namespace KernelPanic.UI
_rows[selectedIndex].Focus();
}
private void OpenUnitDetail(DistroDefinition unit, bool notify, bool returnToOverview = true)
private void OpenUnitDetail(DistroDefinition unit, bool notify, bool returnToOverview = true, bool readOnly = false)
{
if (unit == null)
{
return;
}
if (_mode != CollectionMode.UnitDetail)
if (_mode != CollectionMode.UnitDetail || readOnly)
{
_unitDetailTab = UnitDetailTab.Overview;
_packagePickerSlot = null;
@@ -811,6 +814,7 @@ namespace KernelPanic.UI
}
_unitDetailReturnsToOverview = returnToOverview;
_unitDetailReadOnly = readOnly;
_mode = CollectionMode.UnitDetail;
CurrentTitle = $"$ cat /etc/distros/{unit.Id}.conf";
CurrentHint = GetUnitDetailHint();
@@ -834,12 +838,12 @@ namespace KernelPanic.UI
CurrentTitle = $"$ cat /etc/distros/{unit.Id}.conf";
CurrentHint = GetUnitDetailHint();
string identity = unit.Id + ":" + GetUnitVersion(unit);
string identity = unit.Id + ":" + GetUnitVersion(unit) + (_unitDetailReadOnly ? ":preview" : ":owned");
if (_headerIdentity != identity)
{
_contextHeader.Clear();
_contextHeader.Add(BuildUnitDetailHeader(unit));
_contextHeader.Add(BuildUnitDetailTabs(unit));
if (!_unitDetailReadOnly) _contextHeader.Add(BuildUnitDetailTabs(unit));
_headerIdentity = identity;
}
_contextHeader.RemoveFromClassList("hidden");
@@ -2135,6 +2139,7 @@ namespace KernelPanic.UI
private string GetUnitDetailHint()
{
if (_unitDetailReadOnly) return "[esc] back";
string action = _unitDetailTab switch
{
UnitDetailTab.Upgrade => "[enter] upgrade",
+321 -112
View File
@@ -52,6 +52,7 @@ namespace KernelPanic.UI
private Action _onChanged;
private Action _requestRootCreditExchange;
private Action<string, int, int> _requestPullCutscene;
private Action<DistroDefinition> _openDistroDetail;
private int _selectedBannerIndex;
private int _pendingPullCount;
private int _pendingMissingTokens;
@@ -64,7 +65,7 @@ namespace KernelPanic.UI
private readonly List<string> _resultRewardLines = new();
private readonly List<int> _resultRewardStars = new();
public void Bind(VisualElement root, DistroDatabase database, PackageDatabase packageDatabase, FontAsset artFont, GachaService service, PlayerCollection collection, EntropyWallet entropyWallet, Func<IReadOnlyList<DistroDefinition>, PullResolutionResult> pullResolver, Func<DistroDefinition, PackageDefinition, string> claimSelectorChoice, Action changedCallback, Action rootCreditExchangeCallback, Action<string, int, int> pullCutsceneCallback)
public void Bind(VisualElement root, DistroDatabase database, PackageDatabase packageDatabase, FontAsset artFont, GachaService service, PlayerCollection collection, EntropyWallet entropyWallet, Func<IReadOnlyList<DistroDefinition>, PullResolutionResult> pullResolver, Func<DistroDefinition, PackageDefinition, string> claimSelectorChoice, Action changedCallback, Action rootCreditExchangeCallback, Action<string, int, int> pullCutsceneCallback, Action<DistroDefinition> distroDetailCallback = null)
{
_root = root;
_distroDatabase = database;
@@ -78,6 +79,7 @@ namespace KernelPanic.UI
_onChanged = changedCallback;
_requestRootCreditExchange = rootCreditExchangeCallback;
_requestPullCutscene = pullCutsceneCallback;
_openDistroDetail = distroDetailCallback;
_bannerList = root.Q<VisualElement>("GachaBannerList");
_bannerDetail = root.Q<VisualElement>("GachaBannerDetail");
if (_pullHistoryButton != null) _pullHistoryButton.clicked -= OpenPullHistory;
@@ -89,7 +91,9 @@ namespace KernelPanic.UI
{
if (!_hasOpened)
{
_selectedBannerIndex = 0;
bool beginnerExhausted = _gachaService.BeginnerState.exhausted ||
_gachaService.BeginnerState.totalPulls >= GachaService.BeginnerMaxPulls;
_selectedBannerIndex = beginnerExhausted ? 1 : 0;
_hasOpened = true;
}
@@ -117,7 +121,7 @@ namespace KernelPanic.UI
_bannerRows.Clear();
_bannerList.Clear();
if (_pullHistoryButton != null)
_pullHistoryButton.text = $"git log --pulls\n{_gachaService.PullHistory.Count} saved";
_pullHistoryButton.text = $"git log --pulls · {_gachaService.PullHistory.Count} saved";
Label branchCommand = new("$ git branch --list");
branchCommand.AddToClassList("gacha-branch-command");
@@ -223,41 +227,29 @@ namespace KernelPanic.UI
private void RenderBeginnerBanner()
{
GachaBannerState state = _gachaService.BeginnerState;
bool closed = state.exhausted || state.totalPulls >= GachaService.BeginnerMaxPulls;
_bannerDetail.Add(BuildActiveBannerHeader(
GachaService.BeginnerBannerId,
"beginner install media",
closed ? "CLOSED" : $"OPEN · {GachaService.BeginnerMaxPulls - state.totalPulls} LEFT",
closed));
_bannerDetail.Add(BuildBannerHero("beginner install media"));
_bannerDetail.Add(BuildInfoLine("Entropy", _wallet == null ? "--" : _wallet.Balance.ToString()));
_bannerDetail.Add(BuildInfoLine("Commits", _gachaService.PullTokens.ToString()));
_bannerDetail.Add(BuildInfoLine("pulls", $"{state.totalPulls}/{GachaService.BeginnerMaxPulls}"));
_bannerDetail.Add(BuildInfoLine("4-star pity", $"{state.pityCounter}/{GachaService.FourStarHardPity}"));
_bannerDetail.Add(BuildInfoLine("cost", $"1 Commit / {GachaService.EntropyPerCommit} Entropy per pull"));
_bannerDetail.Add(BuildInfoLine("guarantees", FormatBeginnerGuarantees()));
VisualElement counters = BuildCounterGrid();
counters.Add(BuildProgressMetric("allocation", "allocation", $"{state.totalPulls}/{GachaService.BeginnerMaxPulls}", state.totalPulls, GachaService.BeginnerMaxPulls,
closed ? "install-media allocation complete" : "discounted pulls remaining"));
counters.Add(BuildProgressMetric("four-star", "4★ guarantee", $"{state.pityCounter}/{GachaService.FourStarHardPity}", state.pityCounter, GachaService.FourStarHardPity,
"resets on a 4★+ result"));
counters.Add(BuildProgressMetric("milestones", "milestones", "20 · 40 · 50", -1, 0, FormatBeginnerGuarantees()));
_bannerDetail.Add(counters);
Label rules = new("Base result is a 3-star package cache. A 4-star package cache or starter distro can appear early, with one 4-star+ result guaranteed every 10 pulls.");
rules.AddToClassList("gacha-rules");
_bannerDetail.Add(rules);
VisualElement actions = new();
actions.AddToClassList("gacha-actions");
Button singleButton = new(() => RequestPullSelectedBanner(1))
{
text = $"git pull --single\n1x {GachaService.FormatCurrencyName(GachaCurrencyType.StandardPull)}"
};
singleButton.AddToClassList("terminal-button");
singleButton.AddToClassList("gacha-action-button");
singleButton.SetEnabled(CanAttemptBeginnerPull(1));
actions.Add(singleButton);
Button tenButton = new(() => RequestPullSelectedBanner(10))
{
text = $"git pull --ten\n{_gachaService.GetBeginnerPullCost(10)}x {GachaService.FormatCurrencyName(GachaCurrencyType.StandardPull)}"
};
tenButton.AddToClassList("terminal-button");
tenButton.AddToClassList("gacha-action-button");
tenButton.SetEnabled(CanAttemptBeginnerPull(10));
actions.Add(tenButton);
_bannerDetail.Insert(_bannerDetail.IndexOf(rules), actions);
_bannerDetail.Add(BuildPullPanel(
GachaService.BeginnerSinglePullCost,
_gachaService.GetBeginnerPullCost(10),
CanAttemptBeginnerPull(1),
CanAttemptBeginnerPull(10),
"4★ base 7% · 5★ base 0.8% · fixed rewards at pulls 20, 40 and 50",
closed ? "remote: beginner allocation is complete; checkout stable to keep pulling." : null));
if (_pendingPullCount > 0)
{
@@ -274,42 +266,26 @@ namespace KernelPanic.UI
private void RenderStandardBanner()
{
GachaBannerState state = _gachaService.StandardState;
_bannerDetail.Add(BuildActiveBannerHeader(
GachaService.StandardBannerId,
"stable branch",
"PERMANENT",
false));
_bannerDetail.Add(BuildBannerHero("stable branch"));
_bannerDetail.Add(BuildInfoLine("Entropy", _wallet == null ? "--" : _wallet.Balance.ToString()));
_bannerDetail.Add(BuildInfoLine("Commits", _gachaService.PullTokens.ToString()));
_bannerDetail.Add(BuildInfoLine("pulls", state.totalPulls.ToString()));
_bannerDetail.Add(BuildInfoLine("4-star pity", $"{state.pityCounter}/{GachaService.FourStarHardPity}"));
_bannerDetail.Add(BuildInfoLine("5-star pity", $"{state.fiveStarPityCounter}/{GachaService.FiveStarHardPity}"));
_bannerDetail.Add(BuildInfoLine("5-star selector", $"{_gachaService.GetStandardFiveStarSelectorProgress()}/{GachaService.StandardFiveStarSelectorInterval}"));
_bannerDetail.Add(BuildInfoLine("cost", $"{GachaService.StandardSinglePullCost} Commit / {GachaService.StandardTenPullCost} for ten"));
VisualElement counters = BuildCounterGrid();
counters.Add(BuildProgressMetric("total-pulls", "pull history", state.totalPulls.ToString(), -1, 0, "lifetime pulls on stable"));
counters.Add(BuildProgressMetric("four-star", "4★ guarantee", $"{state.pityCounter}/{GachaService.FourStarHardPity}", state.pityCounter, GachaService.FourStarHardPity, "guaranteed by pull 10"));
counters.Add(BuildProgressMetric("five-star", "5★ pity", $"{state.fiveStarPityCounter}/{GachaService.FiveStarHardPity}", state.fiveStarPityCounter, GachaService.FiveStarHardPity, "odds rise after 65"));
counters.Add(BuildProgressMetric("selector", "5★ selector", $"{_gachaService.GetStandardFiveStarSelectorProgress()}/{GachaService.StandardFiveStarSelectorInterval}", _gachaService.GetStandardFiveStarSelectorProgress(), GachaService.StandardFiveStarSelectorInterval, "choose distro + package"));
_bannerDetail.Add(counters);
Label rules = new("Base result is a 3-star package cache. A 4-star package cache or install-media distro is guaranteed every 10 pulls; 5-star odds ramp up starting pull 66 of the pity cycle and are guaranteed by pull 80. Every 200 pulls, choose a standard 5-star character and a standard 5-star package outright.");
rules.AddToClassList("gacha-rules");
_bannerDetail.Add(rules);
VisualElement actions = new();
actions.AddToClassList("gacha-actions");
Button singleButton = new(() => RequestPullSelectedBanner(1))
{
text = $"git pull --single\n{GachaService.StandardSinglePullCost}x {GachaService.FormatCurrencyName(GachaCurrencyType.StandardPull)}"
};
singleButton.AddToClassList("terminal-button");
singleButton.AddToClassList("gacha-action-button");
singleButton.SetEnabled(CanAttemptStandardPull(1));
actions.Add(singleButton);
Button tenButton = new(() => RequestPullSelectedBanner(10))
{
text = $"git pull --ten\n{GachaService.StandardTenPullCost}x {GachaService.FormatCurrencyName(GachaCurrencyType.StandardPull)}"
};
tenButton.AddToClassList("terminal-button");
tenButton.AddToClassList("gacha-action-button");
tenButton.SetEnabled(CanAttemptStandardPull(10));
actions.Add(tenButton);
_bannerDetail.Insert(_bannerDetail.IndexOf(rules), actions);
_bannerDetail.Add(BuildPullPanel(
GachaService.StandardSinglePullCost,
GachaService.StandardTenPullCost,
CanAttemptStandardPull(1),
CanAttemptStandardPull(10),
"4★ base 7% · 5★ base 0.8% · soft pity +7% per pull from 66 · hard pity 80"));
if (_pendingPullCount > 0)
{
@@ -337,39 +313,26 @@ namespace KernelPanic.UI
private void RenderLimitedBanner()
{
GachaBannerState state = _gachaService.LimitedState;
_bannerDetail.Add(BuildActiveBannerHeader(
GachaService.LimitedBannerId,
"feature branch: NixOS",
state.featuredFiveStarGuaranteed ? "NIXOS GUARANTEED" : "FEATURED · NIXOS",
false));
_bannerDetail.Add(BuildBannerHero("feature branch: NixOS"));
_bannerDetail.Add(BuildInfoLine("Entropy", _wallet == null ? "--" : _wallet.Balance.ToString()));
_bannerDetail.Add(BuildInfoLine("Commits", _gachaService.PullTokens.ToString()));
_bannerDetail.Add(BuildInfoLine("pulls", state.totalPulls.ToString()));
_bannerDetail.Add(BuildInfoLine("4-star pity", $"{state.pityCounter}/{GachaService.FourStarHardPity}"));
_bannerDetail.Add(BuildInfoLine("5-star pity", $"{state.fiveStarPityCounter}/{GachaService.FiveStarHardPity}"));
_bannerDetail.Add(BuildInfoLine("featured guarantee", state.featuredFiveStarGuaranteed ? "armed" : "not armed"));
_bannerDetail.Add(BuildInfoLine("cost", $"{GachaService.LimitedSinglePullCost} Commit / {GachaService.LimitedTenPullCost} for ten"));
VisualElement counters = BuildCounterGrid();
counters.Add(BuildProgressMetric("total-pulls", "pull history", state.totalPulls.ToString(), -1, 0, "lifetime pulls on feature/nixos"));
counters.Add(BuildProgressMetric("four-star", "4★ guarantee", $"{state.pityCounter}/{GachaService.FourStarHardPity}", state.pityCounter, GachaService.FourStarHardPity, "guaranteed by pull 10"));
counters.Add(BuildProgressMetric("five-star", "5★ pity", $"{state.fiveStarPityCounter}/{GachaService.FiveStarHardPity}", state.fiveStarPityCounter, GachaService.FiveStarHardPity, "odds rise after 65"));
counters.Add(BuildProgressMetric("featured", "featured guarantee", state.featuredFiveStarGuaranteed ? "armed" : "not armed", -1, 0, state.featuredFiveStarGuaranteed ? "next distro hit is NixOS" : "lose once to arm"));
_bannerDetail.Add(counters);
Label rules = new("Featured 5-star distro: NixOS. A 4-star package or featured Fedora/Ubuntu is guaranteed every 10 pulls. Five-star odds ramp from pull 66 and guarantee by pull 80. A 5-star first splits between package and distro; a non-featured 5-star distro arms the next distro hit as guaranteed NixOS.");
rules.AddToClassList("gacha-rules");
_bannerDetail.Add(rules);
VisualElement actions = new();
actions.AddToClassList("gacha-actions");
Button singleButton = new(() => RequestPullSelectedBanner(1))
{
text = $"git pull --single\n{GachaService.LimitedSinglePullCost}x {GachaService.FormatCurrencyName(GachaCurrencyType.StandardPull)}"
};
singleButton.AddToClassList("terminal-button");
singleButton.AddToClassList("gacha-action-button");
singleButton.SetEnabled(CanAttemptLimitedPull(1));
actions.Add(singleButton);
Button tenButton = new(() => RequestPullSelectedBanner(10))
{
text = $"git pull --ten\n{GachaService.LimitedTenPullCost}x {GachaService.FormatCurrencyName(GachaCurrencyType.StandardPull)}"
};
tenButton.AddToClassList("terminal-button");
tenButton.AddToClassList("gacha-action-button");
tenButton.SetEnabled(CanAttemptLimitedPull(10));
actions.Add(tenButton);
_bannerDetail.Insert(_bannerDetail.IndexOf(rules), actions);
_bannerDetail.Add(BuildPullPanel(
GachaService.LimitedSinglePullCost,
GachaService.LimitedTenPullCost,
CanAttemptLimitedPull(1),
CanAttemptLimitedPull(10),
"4★ base 7% · 5★ base 0.8% · soft pity +7% per pull from 66 · hard pity 80"));
if (_pendingPullCount > 0) _bannerDetail.Add(BuildEntropyPrompt());
if (_resultBannerId == GachaService.LimitedBannerId &&
@@ -473,8 +436,26 @@ namespace KernelPanic.UI
{
_pullHistoryOverlay?.RemoveFromClassList("modal-open");
_pullHistoryOverlay?.AddToClassList("hidden");
if (_pullHistoryReturnFocus?.panel != null) _pullHistoryReturnFocus.Focus();
// The opener may have been removed or disabled while the history was open.
var selectedBanner = _selectedBannerIndex >= 0 && _selectedBannerIndex < _bannerRows.Count
? _bannerRows[_selectedBannerIndex] : null;
foreach (var candidate in new[] { _pullHistoryReturnFocus, _pullHistoryButton, selectedBanner })
{
if (!CanFocus(candidate)) continue;
candidate.Focus();
break;
}
_pullHistoryReturnFocus = null;
bool CanFocus(VisualElement element)
{
if (element == null || element.panel == null || element.panel != _root.panel ||
!element.focusable || !element.enabledInHierarchy || !element.visible) return false;
for (var parent = element; parent != null; parent = parent.parent)
if (parent.style.display == DisplayStyle.None || parent.resolvedStyle.display == DisplayStyle.None ||
parent.style.visibility == Visibility.Hidden) return false;
return true;
}
}
private void EnsureSelectorOverlay()
@@ -528,8 +509,26 @@ namespace KernelPanic.UI
_selectorOverlay?.AddToClassList("hidden");
_selectorChosenDistro = null;
_selectorResultText = null;
if (_selectorReturnFocus?.panel != null) _selectorReturnFocus.Focus();
// Claiming or refreshing can remove the button that opened the selector.
var selectedBanner = _selectedBannerIndex >= 0 && _selectedBannerIndex < _bannerRows.Count
? _bannerRows[_selectedBannerIndex] : null;
foreach (var candidate in new[] { _selectorReturnFocus, _pullHistoryButton, selectedBanner })
{
if (!CanFocus(candidate)) continue;
candidate.Focus();
break;
}
_selectorReturnFocus = null;
bool CanFocus(VisualElement element)
{
if (element == null || element.panel == null || element.panel != _root.panel ||
!element.focusable || !element.enabledInHierarchy || !element.visible) return false;
for (var parent = element; parent != null; parent = parent.parent)
if (parent.style.display == DisplayStyle.None || parent.resolvedStyle.display == DisplayStyle.None ||
parent.style.visibility == Visibility.Hidden) return false;
return true;
}
}
private void RenderFiveStarSelectorDialog()
@@ -988,6 +987,144 @@ namespace KernelPanic.UI
_pendingMissingTokens = 0;
}
private VisualElement BuildActiveBannerHeader(string bannerId, string title, string state, bool warning)
{
VisualElement header = new();
header.AddToClassList("gacha-active-header");
VisualElement copy = new();
copy.AddToClassList("gacha-active-copy");
Label command = new("$ git checkout " + GetBannerRef(bannerId)) { name = "GachaActiveCommand" };
command.AddToClassList("gacha-active-command");
copy.Add(command);
Label heading = new(title) { name = "GachaActiveTitle" };
heading.AddToClassList("gacha-active-title");
copy.Add(heading);
header.Add(copy);
Label status = new(state) { name = "GachaActiveStatus" };
status.AddToClassList("gacha-active-status");
if (warning) status.AddToClassList("warning");
header.Add(status);
return header;
}
private static VisualElement BuildCounterGrid()
{
VisualElement grid = new();
grid.AddToClassList("gacha-counter-grid");
return grid;
}
private static VisualElement BuildProgressMetric(string id, string label, string value, int progress, int maximum, string detail)
{
VisualElement metric = new() { name = "GachaMetric_" + id };
metric.AddToClassList("gacha-progress-metric");
Label metricLabel = new(label);
metricLabel.AddToClassList("gacha-progress-label");
metric.Add(metricLabel);
Label metricValue = new(value);
metricValue.AddToClassList("gacha-progress-value");
metric.Add(metricValue);
if (maximum > 0)
{
VisualElement track = new();
track.AddToClassList("gacha-progress-track");
VisualElement fill = new();
fill.AddToClassList("gacha-progress-fill");
float ratio = Mathf.Clamp01(progress / (float)maximum);
fill.style.width = Length.Percent(ratio * 100f);
track.Add(fill);
metric.Add(track);
if (progress >= maximum) metric.AddToClassList("complete");
}
if (!string.IsNullOrWhiteSpace(detail))
{
Label detailLabel = new(detail);
detailLabel.AddToClassList("gacha-progress-detail");
metric.Add(detailLabel);
}
return metric;
}
private VisualElement BuildPullPanel(int singleCost, int tenCost, bool canSingle, bool canTen, string oddsText, string unavailableMessage = null)
{
VisualElement panel = new();
panel.AddToClassList("gacha-pull-panel");
Label heading = new("[ pull commands ]");
heading.AddToClassList("gacha-pull-heading");
panel.Add(heading);
if (!string.IsNullOrWhiteSpace(unavailableMessage))
{
Label unavailable = new(unavailableMessage);
unavailable.AddToClassList("gacha-pull-unavailable");
panel.Add(unavailable);
return panel;
}
VisualElement actions = new();
actions.AddToClassList("gacha-actions");
Button singleButton = new(() => RequestPullSelectedBanner(1))
{
name = "GachaPullSingleButton",
text = "$ git pull --single\n" + FormatPullReadiness(singleCost, canSingle)
};
singleButton.AddToClassList("terminal-button");
singleButton.AddToClassList("gacha-action-button");
singleButton.AddToClassList("gacha-action-secondary");
singleButton.SetEnabled(canSingle);
actions.Add(singleButton);
Button tenButton = new(() => RequestPullSelectedBanner(10))
{
name = "GachaPullTenButton",
text = "$ git pull --ten\n" + FormatPullReadiness(tenCost, canTen)
};
tenButton.AddToClassList("terminal-button");
tenButton.AddToClassList("gacha-action-button");
tenButton.AddToClassList("gacha-action-primary");
tenButton.SetEnabled(canTen);
actions.Add(tenButton);
panel.Add(actions);
Foldout odds = new() { text = "inspect odds", value = false, name = "GachaOddsInspector" };
odds.AddToClassList("gacha-odds");
Label oddsCopy = new(oddsText);
oddsCopy.AddToClassList("gacha-odds-copy");
odds.Add(oddsCopy);
panel.Add(odds);
return panel;
}
private string FormatPullReadiness(int cost, bool canAttempt)
{
int commits = _gachaService?.PullTokens ?? 0;
int entropy = _wallet?.Balance ?? 0;
int entropyCost = cost * GachaService.EntropyPerCommit;
bool hasPaymentPath = commits >= cost || entropy >= entropyCost || (_gachaService?.RootCredits ?? 0) > 0;
if (!canAttempt && hasPaymentPath)
return "blocked · unavailable here";
if (commits >= cost)
return "ready · spend " + FormatCommitCost(cost);
if (entropy >= entropyCost)
return $"ready · confirm {entropyCost} Entropy";
if ((_gachaService?.RootCredits ?? 0) > 0)
return "exchange · Root Credit available";
return $"blocked · {Math.Max(0, entropyCost - entropy)} Entropy short";
}
private static string FormatCommitCost(int cost)
{
return cost == 1 ? "1 Commit" : $"{cost} Commits";
}
private VisualElement BuildBannerHero(string bannerTitle)
{
VisualElement hero = new();
@@ -998,14 +1135,19 @@ namespace KernelPanic.UI
IReadOnlyList<DistroDefinition> distros = _distroDatabase == null ? Array.Empty<DistroDefinition>() : _distroDatabase.AllDistros;
List<DistroDefinition> heroDistros = new();
if (bannerTitle.IndexOf("NixOS", StringComparison.OrdinalIgnoreCase) >= 0)
bool featuredSpotlight = bannerTitle.IndexOf("NixOS", StringComparison.OrdinalIgnoreCase) >= 0;
if (featuredSpotlight)
{
for (int i = 0; i < distros.Count; i++)
if (string.Equals(distros[i]?.Id, GachaService.LimitedFeaturedFiveStarDistroId, StringComparison.OrdinalIgnoreCase))
heroDistros.Add(distros[i]);
hero.AddToClassList("gacha-hero-single");
}
else
{
for (int i = 0; i < distros.Count && heroDistros.Count < 3; i++)
if (distros[i] != null && !heroDistros.Contains(distros[i])) heroDistros.Add(distros[i]);
}
for (int i = 0; i < distros.Count && heroDistros.Count < 3; i++)
if (distros[i] != null && !heroDistros.Contains(distros[i])) heroDistros.Add(distros[i]);
for (int i = 0; i < heroDistros.Count; i++) artRow.Add(BuildDistroArtCard(heroDistros[i]));
if (heroDistros.Count == 0)
@@ -1021,8 +1163,14 @@ namespace KernelPanic.UI
private VisualElement BuildDistroArtCard(DistroDefinition distro)
{
VisualElement card = new();
Button card = new(() => _openDistroDetail?.Invoke(distro))
{
name = "GachaDistroArt_" + (distro == null ? "unknown" : distro.Id),
tooltip = distro == null ? "Distro details unavailable" : $"Open {DistroPresentation.DisplayName(distro)} details"
};
card.AddToClassList("gacha-art-card");
card.AddToClassList("gacha-art-button");
card.SetEnabled(distro != null && _openDistroDetail != null);
VisualElement artShell = new();
artShell.AddToClassList("gacha-art-shell");
@@ -1043,17 +1191,74 @@ namespace KernelPanic.UI
artShell.Add(artLabel);
card.Add(artShell);
Label name = new(distro == null ? "--" : DistroPresentation.DisplayName(distro));
name.AddToClassList("gacha-art-name");
Label ownership = new(FormatDistroOwnership(distro));
ownership.AddToClassList("gacha-art-name");
ownership.AddToClassList("gacha-art-ownership");
if (distro != null)
{
name.style.color = new StyleColor(distro.AccentColor);
ownership.style.color = new StyleColor(distro.AccentColor);
}
card.Add(name);
Label inspect = new(distro == null ? "--" : $"[enter] cat /etc/distros/{distro.Id}.conf");
inspect.AddToClassList("gacha-art-name");
inspect.AddToClassList("gacha-art-inspect");
inspect.AddToClassList("hidden");
VisualElement cue = new();
cue.AddToClassList("gacha-art-cue");
cue.Add(ownership);
cue.Add(inspect);
card.Add(cue);
bool pointerInside = false;
bool keyboardFocused = false;
void RefreshCue()
{
bool showInspect = distro != null && _openDistroDetail != null && (pointerInside || keyboardFocused);
ownership.EnableInClassList("hidden", showInspect);
inspect.EnableInClassList("hidden", !showInspect);
}
card.RegisterCallback<PointerEnterEvent>(_ =>
{
pointerInside = true;
RefreshCue();
});
card.RegisterCallback<PointerLeaveEvent>(_ =>
{
pointerInside = false;
RefreshCue();
});
card.RegisterCallback<FocusInEvent>(_ =>
{
keyboardFocused = true;
RefreshCue();
});
card.RegisterCallback<FocusOutEvent>(_ =>
{
keyboardFocused = false;
RefreshCue();
});
return card;
}
private string FormatDistroOwnership(DistroDefinition distro)
{
if (distro == null)
{
return "--";
}
string displayName = DistroPresentation.DisplayName(distro);
if (_playerCollection == null || !_playerCollection.IsOwned(distro.Id))
{
return $"{displayName} · not installed";
}
int version = Mathf.Clamp(_playerCollection.GetVersion(distro.Id), 1, GachaTuning.MaxVersion);
return $"{displayName} · installed v{version}/{GachaTuning.MaxVersion}";
}
private string FormatBeginnerGuarantees()
{
IReadOnlyList<string> ids = _gachaService.BeginnerState.guaranteedDistroIds;
@@ -1077,11 +1282,15 @@ namespace KernelPanic.UI
{
return bannerId switch
{
GachaService.BeginnerBannerId => _gachaService.IsBeginnerBannerAvailable ? $"{_gachaService.BeginnerState.totalPulls}/{GachaService.BeginnerMaxPulls}" : "closed",
GachaService.StandardBannerId => _gachaService.PendingStandardFiveStarSelectors > 0 ? "selector ready" : $"{_gachaService.GetStandardFiveStarSelectorProgress()}/{GachaService.StandardFiveStarSelectorInterval}",
GachaService.BeginnerBannerId => _gachaService.BeginnerState.exhausted || _gachaService.BeginnerState.totalPulls >= GachaService.BeginnerMaxPulls
? $"closed · {_gachaService.BeginnerState.totalPulls}/{GachaService.BeginnerMaxPulls}"
: $"allocation {_gachaService.BeginnerState.totalPulls}/{GachaService.BeginnerMaxPulls}",
GachaService.StandardBannerId => _gachaService.PendingStandardFiveStarSelectors > 0
? "selector ready"
: $"selector {_gachaService.GetStandardFiveStarSelectorProgress()}/{GachaService.StandardFiveStarSelectorInterval}",
GachaService.LimitedBannerId => _gachaService.LimitedState.featuredFiveStarGuaranteed
? "featured guaranteed"
: $"{_gachaService.LimitedState.fiveStarPityCounter}/{GachaService.FiveStarHardPity}",
? "NixOS guaranteed"
: $"5★ pity {_gachaService.LimitedState.fiveStarPityCounter}/{GachaService.FiveStarHardPity}",
_ => "--"
};
}
+28 -2
View File
@@ -222,7 +222,7 @@ namespace KernelPanic.UI
featuredUnitPanel.Bind(_root, resolvedFont, GetBestWaveForUnit, OpenFeaturedUnitDetail);
collectionScreen.Bind(_root, resolvedFont, languageDeckDatabase, cardDatabase, _playerCollection, GetMergesBalance, UpgradeCollectionUnit, packageDatabase, _packageLoadout, SaveCurrentState, () => _saveData, UpgradeCollectionPackage, ScrapCollectionPackage);
collectionScreen.LanguageTrainingRequested += StartLanguageTraining;
gachaScreen.Bind(_root, distroDatabase, packageDatabase, resolvedFont, _gachaService, _playerCollection, _wallet, ResolvePulledDistros, ClaimStandardFiveStarSelector, HandleMetaStateChanged, OpenRootCreditExchange, StartGachaPullCutscene);
gachaScreen.Bind(_root, distroDatabase, packageDatabase, resolvedFont, _gachaService, _playerCollection, _wallet, ResolvePulledDistros, ClaimStandardFiveStarSelector, HandleMetaStateChanged, OpenRootCreditExchange, StartGachaPullCutscene, OpenGachaDistroDetail);
LoadMetaState();
_playerCollection.Changed += HandleMetaStateChanged;
_gachaService.Changed += HandleMetaStateChanged;
@@ -1120,6 +1120,32 @@ namespace KernelPanic.UI
ShowScreen(MenuScreen.Collection);
}
private void OpenGachaDistroDetail(DistroDefinition unit)
{
if (unit == null)
{
return;
}
_collectionTab = CollectionTopTab.Units;
ApplyCollectionTabButtons();
var previewUnits = new List<DistroDefinition>(_playerCollection.OwnedUnits);
bool alreadyListed = false;
for (int i = 0; i < previewUnits.Count; i++)
{
if (previewUnits[i] != null && string.Equals(previewUnits[i].Id, unit.Id, StringComparison.OrdinalIgnoreCase))
{
alreadyListed = true;
break;
}
}
if (!alreadyListed) previewUnits.Add(unit);
collectionScreen.RefreshUnits(previewUnits);
collectionScreen.ShowUnitDetail(unit, false, true);
SyncCollectionFrame();
ShowScreen(MenuScreen.Collection);
}
private void HandleStarterConfirmed(DistroDefinition picked, IReadOnlyList<DistroDefinition> remaining)
{
_playerCollection.Add(picked, 1);
@@ -2860,7 +2886,7 @@ namespace KernelPanic.UI
return;
}
ShowMainMenu();
NavigateBack();
}
private void ShowCollectionUnits()
+2 -1
View File
@@ -63,7 +63,8 @@ namespace KernelPanic.UI
if (_historyIndex > 0) _input.SetValueWithoutNotify(_history[--_historyIndex]);
break;
case KeyCode.DownArrow:
if (_historyIndex < _history.Count) _historyIndex++;
if (_historyIndex == _history.Count) break;
_historyIndex++;
_input.SetValueWithoutNotify(_historyIndex == _history.Count ? _draft : _history[_historyIndex]);
break;
case KeyCode.Tab:
+21 -3
View File
@@ -75,13 +75,31 @@ namespace KernelPanic.UI
region.schedule.Execute(() =>
{
if (focused.panel != null) return;
// A focus choice made since the rebuild takes precedence over restoration.
var current = region.focusController?.focusedElement as VisualElement;
if (current != null && current != focused) return;
bool CanRestoreTo(VisualElement element) => element != null && element.focusable && IsAvailable(element);
VisualElement replacement = string.IsNullOrEmpty(name) ? null : region.Q(name);
if (!CanRestoreTo(replacement)) replacement = null;
if (replacement == null && !string.IsNullOrEmpty(text))
replacement = region.Query<Button>().Where(button => button.text == text && button.enabledInHierarchy).First();
replacement ??= region.Query<Button>().Where(button => button.enabledInHierarchy).First();
replacement = region.Query<Button>().Where(button => button.text == text && CanRestoreTo(button)).First();
replacement ??= region.Query<Button>().Where(button => CanRestoreTo(button)).First();
if (replacement != null) replacement.Focus();
else { region.focusable = true; region.Focus(); }
else if (IsAvailable(region)) { region.focusable = true; region.Focus(); }
});
static bool IsAvailable(VisualElement element)
{
if (element.panel == null || !element.enabledInHierarchy || !element.visible) return false;
for (var parent = element; parent != null; parent = parent.parent)
{
// Inline changes may precede the next style/layout update.
if (parent.style.display == DisplayStyle.None || parent.resolvedStyle.display == DisplayStyle.None ||
parent.style.visibility == Visibility.Hidden) return false;
}
return true;
}
}
public static void ConstrainModalFocus(VisualElement overlay)