Overhaul UI and overall QoL
This commit is contained in:
@@ -36,6 +36,7 @@ namespace KernelPanic.UI
|
||||
private VisualElement _bannerDetail;
|
||||
private VisualElement _selectorOverlay;
|
||||
private VisualElement _selectorDialog;
|
||||
private VisualElement _selectorReturnFocus;
|
||||
private DistroDatabase _distroDatabase;
|
||||
private PackageDatabase _packageDatabase;
|
||||
private FontAsset _monospaceFont;
|
||||
@@ -58,7 +59,6 @@ namespace KernelPanic.UI
|
||||
private string _resultText;
|
||||
private readonly List<string> _resultRewardLines = new();
|
||||
private readonly List<int> _resultRewardStars = new();
|
||||
private bool _resultRevealed;
|
||||
|
||||
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)
|
||||
{
|
||||
@@ -103,7 +103,7 @@ namespace KernelPanic.UI
|
||||
{
|
||||
int index = i;
|
||||
VisualElement row = BuildBannerRow(_bannerIds[i]);
|
||||
row.RegisterCallback<ClickEvent>(_ => SelectBanner(index));
|
||||
((Button)row).clicked += () => SelectBanner(index);
|
||||
_bannerList.Add(row);
|
||||
_bannerRows.Add(row);
|
||||
}
|
||||
@@ -114,12 +114,20 @@ namespace KernelPanic.UI
|
||||
|
||||
public void HandleKeyDown(KeyDownEvent evt)
|
||||
{
|
||||
// Pulls are deliberately click-only to avoid accidental currency spend.
|
||||
// Arrow keys select available banners only. Currency actions require focused activation.
|
||||
if (_selectorOverlay != null && !_selectorOverlay.ClassListContains("hidden")) return;
|
||||
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);
|
||||
_bannerRows[_selectedBannerIndex].Focus();
|
||||
evt.StopPropagation();
|
||||
}
|
||||
|
||||
private VisualElement BuildBannerRow(string bannerId)
|
||||
{
|
||||
VisualElement row = new();
|
||||
Button row = new();
|
||||
row.SetEnabled(bannerId != GachaService.LimitedBannerId);
|
||||
row.AddToClassList("gacha-banner-row");
|
||||
|
||||
row.Add(new Label(">") { name = $"GachaBannerCursor_{bannerId}" });
|
||||
@@ -141,7 +149,10 @@ namespace KernelPanic.UI
|
||||
return;
|
||||
}
|
||||
|
||||
_selectedBannerIndex = (index + _bannerRows.Count) % _bannerRows.Count;
|
||||
if (index < 0 || index >= _bannerRows.Count || !_bannerRows[index].enabledSelf) return;
|
||||
_pendingPullCount = 0;
|
||||
_pendingMissingTokens = 0;
|
||||
_selectedBannerIndex = index;
|
||||
ApplySelectedBanner();
|
||||
}
|
||||
|
||||
@@ -159,6 +170,7 @@ namespace KernelPanic.UI
|
||||
|
||||
private void RenderSelectedBanner()
|
||||
{
|
||||
TerminalTheme.PreserveFocus(_bannerDetail);
|
||||
_bannerDetail.Clear();
|
||||
string bannerId = _bannerIds[_selectedBannerIndex];
|
||||
if (bannerId == GachaService.BeginnerBannerId)
|
||||
@@ -217,7 +229,7 @@ namespace KernelPanic.UI
|
||||
tenButton.SetEnabled(CanAttemptBeginnerPull(10));
|
||||
actions.Add(tenButton);
|
||||
|
||||
_bannerDetail.Add(actions);
|
||||
_bannerDetail.Insert(_bannerDetail.IndexOf(rules), actions);
|
||||
|
||||
if (_pendingPullCount > 0)
|
||||
{
|
||||
@@ -273,7 +285,7 @@ namespace KernelPanic.UI
|
||||
tenButton.SetEnabled(CanAttemptStandardPull(10));
|
||||
actions.Add(tenButton);
|
||||
|
||||
_bannerDetail.Add(actions);
|
||||
_bannerDetail.Insert(_bannerDetail.IndexOf(rules), actions);
|
||||
|
||||
if (_pendingPullCount > 0)
|
||||
{
|
||||
@@ -306,11 +318,20 @@ namespace KernelPanic.UI
|
||||
}
|
||||
|
||||
_selectorOverlay = new VisualElement();
|
||||
TerminalTheme.ConstrainModalFocus(_selectorOverlay);
|
||||
_selectorOverlay.AddToClassList("modal-overlay");
|
||||
_selectorOverlay.AddToClassList("five-star-selector-overlay");
|
||||
_selectorOverlay.AddToClassList("hidden");
|
||||
_selectorDialog = new VisualElement();
|
||||
_selectorOverlay.RegisterCallback<KeyDownEvent>(evt => evt.StopPropagation());
|
||||
_selectorOverlay.RegisterCallback<KeyDownEvent>(evt =>
|
||||
{
|
||||
if (evt.keyCode != KeyCode.Escape) return;
|
||||
CloseFiveStarSelector();
|
||||
evt.StopImmediatePropagation();
|
||||
}, TrickleDown.TrickleDown);
|
||||
_selectorDialog = new ScrollView(ScrollViewMode.Vertical);
|
||||
_selectorDialog.AddToClassList("five-star-selector-dialog");
|
||||
_selectorDialog.AddToClassList("dialog-scroll");
|
||||
_selectorOverlay.Add(_selectorDialog);
|
||||
_root.Add(_selectorOverlay);
|
||||
}
|
||||
@@ -329,6 +350,8 @@ namespace KernelPanic.UI
|
||||
RenderFiveStarSelectorDialog();
|
||||
_selectorOverlay.RemoveFromClassList("hidden");
|
||||
_selectorOverlay.AddToClassList("modal-open");
|
||||
_selectorReturnFocus = _root.focusController?.focusedElement as VisualElement;
|
||||
_selectorDialog.Q<Button>()?.Focus();
|
||||
}
|
||||
|
||||
private void CloseFiveStarSelector()
|
||||
@@ -337,6 +360,8 @@ namespace KernelPanic.UI
|
||||
_selectorOverlay?.AddToClassList("hidden");
|
||||
_selectorChosenDistro = null;
|
||||
_selectorResultText = null;
|
||||
if (_selectorReturnFocus?.panel != null) _selectorReturnFocus.Focus();
|
||||
_selectorReturnFocus = null;
|
||||
}
|
||||
|
||||
private void RenderFiveStarSelectorDialog()
|
||||
@@ -346,6 +371,7 @@ namespace KernelPanic.UI
|
||||
return;
|
||||
}
|
||||
|
||||
TerminalTheme.PreserveFocus(_selectorDialog);
|
||||
_selectorDialog.Clear();
|
||||
|
||||
VisualElement header = new();
|
||||
@@ -359,7 +385,7 @@ namespace KernelPanic.UI
|
||||
Label title = new(stepTitle);
|
||||
title.AddToClassList("gacha-detail-title");
|
||||
header.Add(title);
|
||||
Button close = new(CloseFiveStarSelector) { text = "x", focusable = false };
|
||||
Button close = new(CloseFiveStarSelector) { text = "x", focusable = true };
|
||||
close.AddToClassList("modal-close-button");
|
||||
header.Add(close);
|
||||
_selectorDialog.Add(header);
|
||||
@@ -454,7 +480,7 @@ namespace KernelPanic.UI
|
||||
_bannerDetail.Add(BuildInfoLine("pull currency", $"Commits or Entropy ({GachaService.EntropyPerCommit}:1)"));
|
||||
_bannerDetail.Add(BuildInfoLine("status", "not implemented yet"));
|
||||
_bannerDetail.Add(BuildInfoLine("pity", "own counter, 10-pull 4-star+ guarantee"));
|
||||
_bannerDetail.Add(new Label("Use the beginner implementation as the template: define the banner pool, persist a separate GachaBannerState, then route single/ten pulls through GachaService.") { name = "FutureBannerHint" });
|
||||
_bannerDetail.Add(new Label("This banner is not available yet.") { name = "FutureBannerHint" });
|
||||
_bannerDetail.ElementAt(_bannerDetail.childCount - 1).AddToClassList("gacha-rules");
|
||||
|
||||
if (_resultBannerId == bannerId && !string.IsNullOrWhiteSpace(_resultText))
|
||||
@@ -534,7 +560,6 @@ namespace KernelPanic.UI
|
||||
|
||||
_resultBannerId = bannerId;
|
||||
_resultText = string.Join("\n", header);
|
||||
_resultRevealed = false;
|
||||
_onChanged?.Invoke();
|
||||
Refresh();
|
||||
}
|
||||
@@ -560,7 +585,6 @@ namespace KernelPanic.UI
|
||||
_resultRewardStars.Add(result.RewardStars[i]);
|
||||
}
|
||||
|
||||
_resultRevealed = true;
|
||||
|
||||
int bannerIndex = Array.IndexOf(_bannerIds, result.BannerId);
|
||||
if (bannerIndex >= 0)
|
||||
@@ -578,8 +602,10 @@ namespace KernelPanic.UI
|
||||
|
||||
private VisualElement BuildPullResultReveal()
|
||||
{
|
||||
VisualElement container = new();
|
||||
VisualElement container = _resultRewardLines.Count == 0 ? new VisualElement()
|
||||
: new Foldout { text = $"last pull / {_resultRewardLines.Count} objects (session only)", value = false };
|
||||
container.AddToClassList("gacha-result-block");
|
||||
container.AddToClassList("gacha-last-pull");
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(_resultText))
|
||||
{
|
||||
@@ -593,48 +619,22 @@ namespace KernelPanic.UI
|
||||
return container;
|
||||
}
|
||||
|
||||
VisualElement list = new();
|
||||
var list = new ScrollView(ScrollViewMode.Vertical);
|
||||
list.AddToClassList("gacha-result-list");
|
||||
container.Add(list);
|
||||
|
||||
bool animate = !_resultRevealed && !UIPreferences.ReducedMotion;
|
||||
for (int i = 0; i < _resultRewardLines.Count; i++)
|
||||
{
|
||||
int stars = _resultRewardStars[i];
|
||||
VisualElement card = new();
|
||||
card.AddToClassList("gacha-result-card");
|
||||
card.AddToClassList(RarityClassForStars(stars));
|
||||
// The saved display line already includes pull index and star rarity.
|
||||
card.Add(new Label(_resultRewardLines[i]));
|
||||
|
||||
if (!animate)
|
||||
{
|
||||
card.AddToClassList("gacha-result-card-shown");
|
||||
if (stars >= 5)
|
||||
{
|
||||
card.AddToClassList("gacha-result-card-flash");
|
||||
}
|
||||
|
||||
list.Add(card);
|
||||
continue;
|
||||
}
|
||||
|
||||
card.AddToClassList("gacha-result-card-hidden");
|
||||
card.AddToClassList("gacha-result-card-shown");
|
||||
list.Add(card);
|
||||
// Scheduled off _bannerDetail (already attached to the panel) rather than the
|
||||
// freshly created card, which has no panel to tick a scheduler on until this
|
||||
// whole tree is attached by the caller.
|
||||
_bannerDetail.schedule.Execute(() =>
|
||||
{
|
||||
card.RemoveFromClassList("gacha-result-card-hidden");
|
||||
card.AddToClassList("gacha-result-card-shown");
|
||||
if (stars >= 5)
|
||||
{
|
||||
card.AddToClassList("gacha-result-card-flash");
|
||||
}
|
||||
}).StartingIn(90 * i + 60);
|
||||
}
|
||||
|
||||
_resultRevealed = true;
|
||||
return container;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user