Implement overall improvements for code stability, fallbacks and keyboard interactions
This commit is contained in:
@@ -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}",
|
||||
_ => "--"
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user