Revamp UI a whole lot
This commit is contained in:
@@ -37,6 +37,10 @@ namespace KernelPanic.UI
|
||||
private VisualElement _selectorOverlay;
|
||||
private VisualElement _selectorDialog;
|
||||
private VisualElement _selectorReturnFocus;
|
||||
private Button _pullHistoryButton;
|
||||
private VisualElement _pullHistoryOverlay;
|
||||
private ScrollView _pullHistoryDialog;
|
||||
private VisualElement _pullHistoryReturnFocus;
|
||||
private DistroDatabase _distroDatabase;
|
||||
private PackageDatabase _packageDatabase;
|
||||
private FontAsset _monospaceFont;
|
||||
@@ -76,6 +80,9 @@ namespace KernelPanic.UI
|
||||
_requestPullCutscene = pullCutsceneCallback;
|
||||
_bannerList = root.Q<VisualElement>("GachaBannerList");
|
||||
_bannerDetail = root.Q<VisualElement>("GachaBannerDetail");
|
||||
if (_pullHistoryButton != null) _pullHistoryButton.clicked -= OpenPullHistory;
|
||||
_pullHistoryButton = root.Q<Button>("GachaPullHistoryButton");
|
||||
if (_pullHistoryButton != null) _pullHistoryButton.clicked += OpenPullHistory;
|
||||
}
|
||||
|
||||
public void Open()
|
||||
@@ -89,6 +96,17 @@ namespace KernelPanic.UI
|
||||
Refresh();
|
||||
}
|
||||
|
||||
public void OpenPullHistory()
|
||||
{
|
||||
if (_root == null || _gachaService == null) return;
|
||||
EnsurePullHistoryOverlay();
|
||||
_pullHistoryReturnFocus = _root.focusController?.focusedElement as VisualElement;
|
||||
RenderPullHistory();
|
||||
_pullHistoryOverlay.RemoveFromClassList("hidden");
|
||||
_pullHistoryOverlay.AddToClassList("modal-open");
|
||||
_pullHistoryDialog.Q<Button>("ClosePullHistory")?.Focus();
|
||||
}
|
||||
|
||||
public void Refresh()
|
||||
{
|
||||
if (_bannerList == null || _bannerDetail == null || _gachaService == null)
|
||||
@@ -98,6 +116,12 @@ namespace KernelPanic.UI
|
||||
|
||||
_bannerRows.Clear();
|
||||
_bannerList.Clear();
|
||||
if (_pullHistoryButton != null)
|
||||
_pullHistoryButton.text = $"git log --pulls\n{_gachaService.PullHistory.Count} saved";
|
||||
|
||||
Label branchCommand = new("$ git branch --list");
|
||||
branchCommand.AddToClassList("gacha-branch-command");
|
||||
_bannerList.Add(branchCommand);
|
||||
|
||||
for (int i = 0; i < _bannerIds.Length; i++)
|
||||
{
|
||||
@@ -119,7 +143,7 @@ namespace KernelPanic.UI
|
||||
for (var target = evt.target as VisualElement; target != null && target != _root; target = target.parent)
|
||||
if (target.ClassListContains("gacha-last-pull")) return;
|
||||
if (evt.keyCode != KeyCode.UpArrow && evt.keyCode != KeyCode.DownArrow) return;
|
||||
SelectBanner((_selectedBannerIndex + 1) % 2);
|
||||
SelectBanner((_selectedBannerIndex + 1) % _bannerRows.Count);
|
||||
_bannerRows[_selectedBannerIndex].Focus();
|
||||
evt.StopPropagation();
|
||||
}
|
||||
@@ -127,13 +151,13 @@ namespace KernelPanic.UI
|
||||
private VisualElement BuildBannerRow(string bannerId)
|
||||
{
|
||||
Button row = new();
|
||||
row.SetEnabled(bannerId != GachaService.LimitedBannerId);
|
||||
row.SetEnabled(true);
|
||||
row.AddToClassList("gacha-banner-row");
|
||||
|
||||
row.Add(new Label(">") { name = $"GachaBannerCursor_{bannerId}" });
|
||||
row.Add(new Label(" ") { name = $"GachaBannerCursor_{bannerId}" });
|
||||
row.ElementAt(0).AddToClassList("command-cursor");
|
||||
|
||||
row.Add(new Label(GetBannerTitle(bannerId)) { name = $"GachaBannerName_{bannerId}" });
|
||||
row.Add(new Label(GetBannerRef(bannerId)) { name = $"GachaBannerName_{bannerId}" });
|
||||
row.ElementAt(1).AddToClassList("command-text");
|
||||
|
||||
row.Add(new Label(GetBannerStatus(bannerId)) { name = $"GachaBannerStatus_{bannerId}" });
|
||||
@@ -162,7 +186,9 @@ namespace KernelPanic.UI
|
||||
{
|
||||
bool selected = i == _selectedBannerIndex;
|
||||
_bannerRows[i].EnableInClassList(SelectedClassName, selected);
|
||||
_bannerRows[i].Q<Label>(className: "command-cursor").visible = selected;
|
||||
Label cursor = _bannerRows[i].Q<Label>(className: "command-cursor");
|
||||
cursor.visible = true;
|
||||
cursor.text = selected ? "*" : " ";
|
||||
}
|
||||
|
||||
RenderSelectedBanner();
|
||||
@@ -185,6 +211,12 @@ namespace KernelPanic.UI
|
||||
return;
|
||||
}
|
||||
|
||||
if (bannerId == GachaService.LimitedBannerId)
|
||||
{
|
||||
RenderLimitedBanner();
|
||||
return;
|
||||
}
|
||||
|
||||
RenderFutureBanner(bannerId);
|
||||
}
|
||||
|
||||
@@ -193,10 +225,6 @@ namespace KernelPanic.UI
|
||||
GachaBannerState state = _gachaService.BeginnerState;
|
||||
_bannerDetail.Add(BuildBannerHero("beginner install media"));
|
||||
|
||||
Label title = new("beginner install media");
|
||||
title.AddToClassList("gacha-detail-title");
|
||||
_bannerDetail.Add(title);
|
||||
|
||||
_bannerDetail.Add(BuildInfoLine("Entropy", _wallet == null ? "--" : _wallet.Balance.ToString()));
|
||||
_bannerDetail.Add(BuildInfoLine("Commits", _gachaService.PullTokens.ToString()));
|
||||
_bannerDetail.Add(BuildInfoLine("pulls", $"{state.totalPulls}/{GachaService.BeginnerMaxPulls}"));
|
||||
@@ -248,10 +276,6 @@ namespace KernelPanic.UI
|
||||
GachaBannerState state = _gachaService.StandardState;
|
||||
_bannerDetail.Add(BuildBannerHero("stable branch"));
|
||||
|
||||
Label title = new("stable branch");
|
||||
title.AddToClassList("gacha-detail-title");
|
||||
_bannerDetail.Add(title);
|
||||
|
||||
_bannerDetail.Add(BuildInfoLine("Entropy", _wallet == null ? "--" : _wallet.Balance.ToString()));
|
||||
_bannerDetail.Add(BuildInfoLine("Commits", _gachaService.PullTokens.ToString()));
|
||||
_bannerDetail.Add(BuildInfoLine("pulls", state.totalPulls.ToString()));
|
||||
@@ -310,6 +334,149 @@ namespace KernelPanic.UI
|
||||
}
|
||||
}
|
||||
|
||||
private void RenderLimitedBanner()
|
||||
{
|
||||
GachaBannerState state = _gachaService.LimitedState;
|
||||
_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"));
|
||||
|
||||
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);
|
||||
|
||||
if (_pendingPullCount > 0) _bannerDetail.Add(BuildEntropyPrompt());
|
||||
if (_resultBannerId == GachaService.LimitedBannerId &&
|
||||
(_resultRewardLines.Count > 0 || !string.IsNullOrWhiteSpace(_resultText)))
|
||||
_bannerDetail.Add(BuildPullResultReveal());
|
||||
}
|
||||
|
||||
private void RenderPullHistory()
|
||||
{
|
||||
if (_pullHistoryDialog == null) return;
|
||||
TerminalTheme.PreserveFocus(_pullHistoryDialog);
|
||||
_pullHistoryDialog.Clear();
|
||||
bool emptyHistory = _gachaService.PullHistory.Count == 0;
|
||||
_pullHistoryDialog.EnableInClassList("is-empty", emptyHistory);
|
||||
|
||||
VisualElement header = new();
|
||||
header.AddToClassList("package-equip-header");
|
||||
header.AddToClassList("terminal-pane-titlebar");
|
||||
Label title = new("[ git log --pulls ]");
|
||||
title.AddToClassList("gacha-detail-title");
|
||||
header.Add(title);
|
||||
Button close = new(ClosePullHistory) { name = "ClosePullHistory", text = "x", focusable = true };
|
||||
close.AddToClassList("modal-close-button");
|
||||
header.Add(close);
|
||||
_pullHistoryDialog.Add(header);
|
||||
if (emptyHistory)
|
||||
{
|
||||
Label command = new("$ git log --pulls --all");
|
||||
command.AddToClassList("gacha-history-command");
|
||||
_pullHistoryDialog.Add(command);
|
||||
|
||||
Label empty = new("fatal: no committed pulls found\n" +
|
||||
"hint: completed pull receipts appear after rewards are committed");
|
||||
empty.AddToClassList("gacha-rules");
|
||||
empty.AddToClassList("gacha-history-empty");
|
||||
_pullHistoryDialog.Add(empty);
|
||||
return;
|
||||
}
|
||||
|
||||
_pullHistoryDialog.Add(BuildInfoLine("retention", $"latest {GachaService.MaxPullHistoryEntries} transactions"));
|
||||
_pullHistoryDialog.Add(BuildInfoLine("entries", _gachaService.PullHistory.Count.ToString()));
|
||||
|
||||
for (int i = 0; i < _gachaService.PullHistory.Count; i++)
|
||||
{
|
||||
GachaPullHistoryEntry entry = _gachaService.PullHistory[i];
|
||||
string payment = entry.entropySpent > 0 ? $"{entry.entropySpent} Entropy" : $"{entry.currencySpent} Commits";
|
||||
string timestamp = DateTime.TryParse(entry.pulledUtc, out DateTime parsed)
|
||||
? parsed.ToLocalTime().ToString("yyyy-MM-dd HH:mm")
|
||||
: entry.pulledUtc;
|
||||
Foldout transaction = new()
|
||||
{
|
||||
text = $"{timestamp} {GetBannerTitle(entry.bannerId)} [{entry.rewards.Count}] -{payment}",
|
||||
value = i == 0
|
||||
};
|
||||
transaction.AddToClassList("gacha-result-block");
|
||||
for (int rewardIndex = 0; rewardIndex < entry.rewards.Count; rewardIndex++)
|
||||
{
|
||||
GachaPullHistoryRewardEntry reward = entry.rewards[rewardIndex];
|
||||
string duplicateUnit = reward.rewardType == GachaRewardType.Package ? "Cache" : "Merges";
|
||||
string status = reward.outcomeKind switch
|
||||
{
|
||||
PullOutcomeKind.Granted => " NEW",
|
||||
PullOutcomeKind.Dupe => $" +{reward.duplicateValue} {duplicateUnit}",
|
||||
PullOutcomeKind.DupeOverflow => $" +{reward.duplicateValue} {duplicateUnit}",
|
||||
_ => reward.guaranteed ? " guaranteed" : reward.pityTriggered ? " pity" : string.Empty
|
||||
};
|
||||
Label line = new($"{rewardIndex + 1:00}: {reward.stars}★ {reward.displayName}{status}");
|
||||
line.AddToClassList("gacha-result-card");
|
||||
line.AddToClassList(RarityClassForStars(reward.stars));
|
||||
transaction.Add(line);
|
||||
}
|
||||
_pullHistoryDialog.Add(transaction);
|
||||
}
|
||||
}
|
||||
|
||||
private void EnsurePullHistoryOverlay()
|
||||
{
|
||||
if (_root == null || _pullHistoryOverlay != null) return;
|
||||
_pullHistoryOverlay = new VisualElement { name = "GachaPullHistoryOverlay" };
|
||||
TerminalTheme.ConstrainModalFocus(_pullHistoryOverlay);
|
||||
_pullHistoryOverlay.AddToClassList("modal-overlay");
|
||||
_pullHistoryOverlay.AddToClassList("gacha-pull-history-overlay");
|
||||
_pullHistoryOverlay.AddToClassList("hidden");
|
||||
_pullHistoryOverlay.RegisterCallback<KeyDownEvent>(evt => evt.StopPropagation());
|
||||
_pullHistoryOverlay.RegisterCallback<KeyDownEvent>(evt =>
|
||||
{
|
||||
if (evt.keyCode != KeyCode.Escape) return;
|
||||
ClosePullHistory();
|
||||
evt.StopImmediatePropagation();
|
||||
}, TrickleDown.TrickleDown);
|
||||
_pullHistoryDialog = new ScrollView(ScrollViewMode.Vertical) { name = "GachaPullHistoryDialog" };
|
||||
_pullHistoryDialog.horizontalScrollerVisibility = ScrollerVisibility.Hidden;
|
||||
_pullHistoryDialog.AddToClassList("gacha-pull-history-dialog");
|
||||
_pullHistoryDialog.AddToClassList("dialog-scroll");
|
||||
_pullHistoryDialog.AddToClassList("terminal-pane");
|
||||
_pullHistoryOverlay.Add(_pullHistoryDialog);
|
||||
_root.Add(_pullHistoryOverlay);
|
||||
}
|
||||
|
||||
private void ClosePullHistory()
|
||||
{
|
||||
_pullHistoryOverlay?.RemoveFromClassList("modal-open");
|
||||
_pullHistoryOverlay?.AddToClassList("hidden");
|
||||
if (_pullHistoryReturnFocus?.panel != null) _pullHistoryReturnFocus.Focus();
|
||||
_pullHistoryReturnFocus = null;
|
||||
}
|
||||
|
||||
private void EnsureSelectorOverlay()
|
||||
{
|
||||
if (_root == null || _selectorOverlay != null)
|
||||
@@ -332,6 +499,7 @@ namespace KernelPanic.UI
|
||||
_selectorDialog = new ScrollView(ScrollViewMode.Vertical);
|
||||
_selectorDialog.AddToClassList("five-star-selector-dialog");
|
||||
_selectorDialog.AddToClassList("dialog-scroll");
|
||||
_selectorDialog.AddToClassList("terminal-pane");
|
||||
_selectorOverlay.Add(_selectorDialog);
|
||||
_root.Add(_selectorOverlay);
|
||||
}
|
||||
@@ -376,13 +544,14 @@ namespace KernelPanic.UI
|
||||
|
||||
VisualElement header = new();
|
||||
header.AddToClassList("package-equip-header");
|
||||
header.AddToClassList("terminal-pane-titlebar");
|
||||
string stepTitle = _selectorStep switch
|
||||
{
|
||||
SelectorStep.Character => "5-star selector: choose a standard character",
|
||||
SelectorStep.Equipment => "5-star selector: choose standard equipment",
|
||||
_ => "5-star selector"
|
||||
};
|
||||
Label title = new(stepTitle);
|
||||
Label title = new($"[ {stepTitle} ]");
|
||||
title.AddToClassList("gacha-detail-title");
|
||||
header.Add(title);
|
||||
Button close = new(CloseFiveStarSelector) { text = "x", focusable = true };
|
||||
@@ -500,7 +669,8 @@ namespace KernelPanic.UI
|
||||
return;
|
||||
}
|
||||
|
||||
if (bannerId != GachaService.BeginnerBannerId && bannerId != GachaService.StandardBannerId)
|
||||
if (bannerId != GachaService.BeginnerBannerId && bannerId != GachaService.StandardBannerId
|
||||
&& bannerId != GachaService.LimitedBannerId)
|
||||
{
|
||||
_resultBannerId = bannerId;
|
||||
_resultText = $"git pull origin {bannerId}: remote not implemented yet";
|
||||
@@ -511,9 +681,13 @@ namespace KernelPanic.UI
|
||||
}
|
||||
|
||||
PullPaymentSource source = entropyTokenCount > 0 ? PullPaymentSource.Entropy : PullPaymentSource.Commits;
|
||||
GachaPullResult result = bannerId == GachaService.BeginnerBannerId
|
||||
? _gachaService.PerformBeginnerPull(pullCount, _wallet, source)
|
||||
: _gachaService.PerformStandardPull(pullCount, _wallet, source);
|
||||
GachaPullResult result = bannerId switch
|
||||
{
|
||||
GachaService.BeginnerBannerId => _gachaService.PerformBeginnerPull(pullCount, _wallet, source),
|
||||
GachaService.StandardBannerId => _gachaService.PerformStandardPull(pullCount, _wallet, source),
|
||||
GachaService.LimitedBannerId => _gachaService.PerformLimitedPull(pullCount, _wallet, source),
|
||||
_ => GachaPullResult.Failed(bannerId, "remote not implemented yet")
|
||||
};
|
||||
if (!result.Success)
|
||||
{
|
||||
_resultBannerId = bannerId;
|
||||
@@ -683,7 +857,8 @@ namespace KernelPanic.UI
|
||||
private void RequestPullSelectedBanner(int pullCount)
|
||||
{
|
||||
string bannerId = _bannerIds[_selectedBannerIndex];
|
||||
if (bannerId != GachaService.BeginnerBannerId && bannerId != GachaService.StandardBannerId)
|
||||
if (bannerId != GachaService.BeginnerBannerId && bannerId != GachaService.StandardBannerId
|
||||
&& bannerId != GachaService.LimitedBannerId)
|
||||
{
|
||||
PullSelectedBanner(pullCount, 0);
|
||||
return;
|
||||
@@ -796,6 +971,17 @@ namespace KernelPanic.UI
|
||||
_gachaService.RootCredits > 0);
|
||||
}
|
||||
|
||||
private bool CanAttemptLimitedPull(int pullCount)
|
||||
{
|
||||
if (_gachaService.CanAffordPull(pullCount, _wallet, PullPaymentSource.Commits, GachaService.LimitedBannerId, out _))
|
||||
return true;
|
||||
int cost = _gachaService.GetPullCost(GachaService.LimitedBannerId, pullCount);
|
||||
int missingTokens = _gachaService.GetMissingPullTokens(GachaCurrencyType.StandardPull, cost);
|
||||
return missingTokens > 0 &&
|
||||
((_wallet != null && _wallet.Balance >= cost * GachaService.EntropyPerCommit) ||
|
||||
_gachaService.RootCredits > 0);
|
||||
}
|
||||
|
||||
private void ClearEntropyPrompt()
|
||||
{
|
||||
_pendingPullCount = 0;
|
||||
@@ -811,24 +997,25 @@ namespace KernelPanic.UI
|
||||
artRow.AddToClassList("gacha-hero-art-row");
|
||||
|
||||
IReadOnlyList<DistroDefinition> distros = _distroDatabase == null ? Array.Empty<DistroDefinition>() : _distroDatabase.AllDistros;
|
||||
int artCount = Mathf.Min(3, distros.Count);
|
||||
for (int i = 0; i < artCount; i++)
|
||||
List<DistroDefinition> heroDistros = new();
|
||||
if (bannerTitle.IndexOf("NixOS", StringComparison.OrdinalIgnoreCase) >= 0)
|
||||
{
|
||||
artRow.Add(BuildDistroArtCard(distros[i]));
|
||||
for (int i = 0; i < distros.Count; i++)
|
||||
if (string.Equals(distros[i]?.Id, GachaService.LimitedFeaturedFiveStarDistroId, StringComparison.OrdinalIgnoreCase))
|
||||
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 (artCount == 0)
|
||||
if (heroDistros.Count == 0)
|
||||
{
|
||||
Label empty = new("ascii art unavailable");
|
||||
empty.AddToClassList("gacha-rules");
|
||||
artRow.Add(empty);
|
||||
}
|
||||
|
||||
Label title = new(bannerTitle);
|
||||
title.AddToClassList("gacha-hero-title");
|
||||
|
||||
hero.Add(artRow);
|
||||
hero.Add(title);
|
||||
return hero;
|
||||
}
|
||||
|
||||
@@ -892,7 +1079,9 @@ namespace KernelPanic.UI
|
||||
{
|
||||
GachaService.BeginnerBannerId => _gachaService.IsBeginnerBannerAvailable ? $"{_gachaService.BeginnerState.totalPulls}/{GachaService.BeginnerMaxPulls}" : "closed",
|
||||
GachaService.StandardBannerId => _gachaService.PendingStandardFiveStarSelectors > 0 ? "selector ready" : $"{_gachaService.GetStandardFiveStarSelectorProgress()}/{GachaService.StandardFiveStarSelectorInterval}",
|
||||
GachaService.LimitedBannerId => "soon",
|
||||
GachaService.LimitedBannerId => _gachaService.LimitedState.featuredFiveStarGuaranteed
|
||||
? "featured guaranteed"
|
||||
: $"{_gachaService.LimitedState.fiveStarPityCounter}/{GachaService.FiveStarHardPity}",
|
||||
_ => "--"
|
||||
};
|
||||
}
|
||||
@@ -907,5 +1096,16 @@ namespace KernelPanic.UI
|
||||
_ => bannerId
|
||||
};
|
||||
}
|
||||
|
||||
private static string GetBannerRef(string bannerId)
|
||||
{
|
||||
return bannerId switch
|
||||
{
|
||||
GachaService.BeginnerBannerId => "beginner",
|
||||
GachaService.StandardBannerId => "stable",
|
||||
GachaService.LimitedBannerId => "feature/nixos",
|
||||
_ => "remote/" + bannerId
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user