Make some overall changes to utilities

This commit is contained in:
2026-10-26 22:09:36 +01:00
parent a4109f5be0
commit 881b61a66d
22 changed files with 376 additions and 790 deletions
+33 -5
View File
@@ -520,6 +520,26 @@ namespace KernelPanic.UI
_handRow = new();
_handRow.AddToClassList("hand-row");
_handScroll.Add(_handRow);
_handScroll.contentViewport.RegisterCallback<GeometryChangedEvent>(_ => FitHandCardsToViewport());
// ScrollView aligns oversized focused cards to the bottom, hiding identity/cost.
// Handle focus before it reaches the scroller and reveal the top of tall cards.
handPanel.RegisterCallback<FocusInEvent>(evt =>
{
if (evt.target is not Button face || !face.ClassListContains("hand-card")) return;
evt.StopPropagation();
void RevealCard()
{
// Reveal the identity region itself: requesting the full face lets
// ScrollView's deferred layout scroll back down to its bottom edge.
_handScroll.ScrollTo(face.Q(className: "software-name"));
_handScroll.ScrollTo(face.Q(className: "software-header"));
}
RevealCard();
_handScroll.schedule.Execute(() =>
{
if (handPanel.focusController?.focusedElement == face) RevealCard();
});
}, TrickleDown.TrickleDown);
VisualElement commandPanel = CreatePanel("dispatch", "turn controls", 0);
commandPanel.AddToClassList("turn-panel");
@@ -1080,6 +1100,14 @@ namespace KernelPanic.UI
}
}
private void FitHandCardsToViewport()
{
float width = _handScroll.contentViewport.contentRect.width;
if (width <= 0) return;
foreach (var face in _retainedHandCards.Values)
face.style.maxWidth = Mathf.Max(1, width - face.resolvedStyle.marginLeft - face.resolvedStyle.marginRight);
}
private void RefreshHand()
{
TerminalTheme.PreserveFocus(_handRow);
@@ -1106,7 +1134,6 @@ namespace KernelPanic.UI
if (added)
{
face = CardFace(card);
face.RegisterCallback<FocusInEvent>(_ => _handScroll.ScrollTo(face));
_retainedHandCards[card] = face;
_handRow.Add(face);
}
@@ -1130,6 +1157,7 @@ namespace KernelPanic.UI
_handCardElements[card] = face;
if (added) PlayElementBeat(face, "hand-card-drawn", 180);
}
FitHandCardsToViewport();
}
private void RefreshTurnPanel()
@@ -1639,9 +1667,9 @@ namespace KernelPanic.UI
copy.Add(title);
var subtitle = new Label(_runManager.CampaignChoicePending
? "bank your rewards or continue into endless"
: reward ? "1 / claim reward > 2 / choose route > 3 / enter stop"
: eventScreen ? committed ? "stop complete / ready for battle" : "choose your cards / nothing changes until you confirm"
: $"preparing wave {_runManager.CurrentWaveNumber} / {_runManager.Bits} bits remaining");
: reward ? "1. claim reward > 2. choose route > 3. enter stop"
: eventScreen ? committed ? "stop complete. ready for battle" : "choose your cards. nothing changes until you confirm"
: $"preparing wave {_runManager.CurrentWaveNumber} {_runManager.Bits} bits remaining");
subtitle.AddToClassList("repository-subtitle");
copy.Add(subtitle);
header.Add(copy);
@@ -1664,7 +1692,7 @@ namespace KernelPanic.UI
}
if (committed)
{
var save = new Button(SaveAndExitRun) { name = "SaveAndExitRunButton", text = "save and exit / keep this result" };
var save = new Button(SaveAndExitRun) { name = "SaveAndExitRunButton", text = "save and exit" };
save.AddToClassList("secondary-action"); body.Add(save);
}
screen.Add(body);