Overhaul UI and overall QoL
This commit is contained in:
@@ -173,6 +173,7 @@ namespace KernelPanic.UI
|
||||
private Action _rootCreditExchangePlusHundredClicked;
|
||||
private IVisualElementScheduledItem _blinkSchedule;
|
||||
private IVisualElementScheduledItem _bootIntroSchedule;
|
||||
private TerminalCommandLine _commandLine;
|
||||
private MenuScreen _activeScreen = MenuScreen.Main;
|
||||
|
||||
public void Initialize(EntropyWallet initializedWallet)
|
||||
@@ -188,6 +189,9 @@ namespace KernelPanic.UI
|
||||
BindElements();
|
||||
LoadSharedStyles();
|
||||
BindCommandEntries();
|
||||
TerminalTheme.Attach(_root);
|
||||
_commandLine = new TerminalCommandLine(_root, ActivateCommand, () => _activeScreen == MenuScreen.Main && !starterSelection.IsActive && !_rootCreditExchangeOpen);
|
||||
BindPreferences();
|
||||
RegisterCommandEntryCallbacks();
|
||||
BindScreenFrames();
|
||||
starterSelection.Bind(_root, distroDatabase, HandleStarterConfirmed);
|
||||
@@ -201,6 +205,23 @@ namespace KernelPanic.UI
|
||||
ApplyOptionalFont(resolvedFont);
|
||||
}
|
||||
|
||||
private void BindPreferences()
|
||||
{
|
||||
TerminalTheme.ConstrainModalFocus(_root.Q("RootCreditExchangeModal"));
|
||||
Toggle motion = _root.Q<Toggle>("ReducedMotionToggle");
|
||||
motion.SetValueWithoutNotify(UIPreferences.ReducedMotion);
|
||||
motion.text = UIPreferences.ReducedMotion ? "[ true ]" : "[ false ]";
|
||||
motion.RegisterValueChangedCallback(evt =>
|
||||
{
|
||||
UIPreferences.ReducedMotion = evt.newValue;
|
||||
motion.text = evt.newValue ? "[ true ]" : "[ false ]";
|
||||
_root.EnableInClassList("reduced-motion", evt.newValue);
|
||||
_shellRoot.EnableInClassList("reduced-motion", evt.newValue);
|
||||
if (evt.newValue && !_bootIntroPanel.ClassListContains(HiddenClassName)) CompleteBootIntro();
|
||||
StartAmbientSchedules();
|
||||
});
|
||||
}
|
||||
|
||||
private void ComposeMetaServices()
|
||||
{
|
||||
_saveService = new SaveService();
|
||||
@@ -275,7 +296,7 @@ namespace KernelPanic.UI
|
||||
_rootCreditsToEntropyButton = _root.Q<Button>("RootCreditsToEntropyButton");
|
||||
if (_rootCreditsToEntropyButton != null)
|
||||
{
|
||||
_rootCreditsToEntropyButton.focusable = false;
|
||||
_rootCreditsToEntropyButton.focusable = true;
|
||||
}
|
||||
|
||||
_rootCreditExchangeModal = _root.Q<VisualElement>("RootCreditExchangeModal");
|
||||
@@ -314,9 +335,9 @@ namespace KernelPanic.UI
|
||||
|
||||
private void BindScreenFrames()
|
||||
{
|
||||
_runSetupFrame.Bind(_runSetupPanel, "$ ./start_run --configure", "[esc] back [arrows] navigate [enter] select [b] boot run", ShowMainMenu);
|
||||
_collectionFrame.Bind(_collectionPanel, "$ ls ~/collection", "[esc] back [left/right] tabs [tab] tabs [arrows] navigate [enter] select", HandleCollectionBack);
|
||||
_gachaFrame.Bind(_gachaPanel, "$ curl gacha.sh | sh", "[esc] back click banner click pull", ShowMainMenu);
|
||||
_runSetupFrame.Bind(_runSetupPanel, "$ ./start_run --configure", "[esc] back [up/down] distro [tab/enter] select [B] boot", ShowMainMenu);
|
||||
_collectionFrame.Bind(_collectionPanel, "$ ls ~/collection", "[esc] back [left/right] tabs [tab] focus [arrows] navigate [enter] select", HandleCollectionBack);
|
||||
_gachaFrame.Bind(_gachaPanel, "$ curl gacha.sh | sh", "[esc] back [up/down] banner [tab/enter] actions", ShowMainMenu);
|
||||
_settingsFrame.Bind(_settingsPanel, "$ dpkg-reconfigure kernel-panic", "[esc] back", ShowMainMenu);
|
||||
}
|
||||
|
||||
@@ -415,9 +436,9 @@ namespace KernelPanic.UI
|
||||
}
|
||||
|
||||
collectionScreen.ViewChanged += SyncCollectionFrame;
|
||||
_collectionUnitsButton.RegisterCallback<ClickEvent>(HandleCollectionUnitsTabClicked);
|
||||
_collectionLanguagesButton.RegisterCallback<ClickEvent>(HandleCollectionLanguagesTabClicked);
|
||||
_collectionPackagesButton.RegisterCallback<ClickEvent>(HandleCollectionPackagesTabClicked);
|
||||
_collectionUnitsButton.clicked += ShowCollectionUnits;
|
||||
_collectionLanguagesButton.clicked += ShowCollectionLanguages;
|
||||
_collectionPackagesButton.clicked += ShowCollectionPackages;
|
||||
}
|
||||
|
||||
private void UnregisterCallbacks()
|
||||
@@ -485,9 +506,9 @@ namespace KernelPanic.UI
|
||||
}
|
||||
|
||||
collectionScreen.ViewChanged -= SyncCollectionFrame;
|
||||
_collectionUnitsButton.UnregisterCallback<ClickEvent>(HandleCollectionUnitsTabClicked);
|
||||
_collectionLanguagesButton.UnregisterCallback<ClickEvent>(HandleCollectionLanguagesTabClicked);
|
||||
_collectionPackagesButton.UnregisterCallback<ClickEvent>(HandleCollectionPackagesTabClicked);
|
||||
_collectionUnitsButton.clicked -= ShowCollectionUnits;
|
||||
_collectionLanguagesButton.clicked -= ShowCollectionLanguages;
|
||||
_collectionPackagesButton.clicked -= ShowCollectionPackages;
|
||||
}
|
||||
|
||||
private void HandleRootCreditsToEntropyClicked()
|
||||
@@ -1090,6 +1111,8 @@ namespace KernelPanic.UI
|
||||
for (int i = 0; i < _commandEntries.Count; i++)
|
||||
{
|
||||
int index = i;
|
||||
_commandEntries[i].Row.focusable = true;
|
||||
_commandEntries[i].Row.RegisterCallback<FocusInEvent>(_ => SelectCommand(index));
|
||||
_commandEntries[i].Row.RegisterCallback<PointerEnterEvent>(_ => SelectCommand(index));
|
||||
_commandEntries[i].Row.RegisterCallback<ClickEvent>(_ => HandleCommandClicked(index));
|
||||
}
|
||||
@@ -1106,8 +1129,9 @@ namespace KernelPanic.UI
|
||||
_rootCreditsToEntropyButton?.SetEnabled(true);
|
||||
bool showPullTokens = IsGachaVisible();
|
||||
_pullTokensLabel.text = showPullTokens
|
||||
? $"Commits={_gachaService.PullTokens} Root Credits={_gachaService.RootCredits} Bandwidth={_saveData.bandwidthBalance} Cache={_saveData.cacheBalance} Merges={GetTotalDistroMerges()}"
|
||||
? $"Commits={_gachaService.PullTokens}"
|
||||
: string.Empty;
|
||||
_rootCreditsToEntropyButton.tooltip = $"Exchange Root Credits ({_gachaService.RootCredits})\nBandwidth {_saveData.bandwidthBalance} / Cache {_saveData.cacheBalance} / Merges {GetTotalDistroMerges()}";
|
||||
_pullTokensLabel.EnableInClassList(HiddenClassName, !showPullTokens);
|
||||
}
|
||||
|
||||
@@ -1243,7 +1267,7 @@ namespace KernelPanic.UI
|
||||
return;
|
||||
}
|
||||
|
||||
if (evt.keyCode == KeyCode.Return || evt.keyCode == KeyCode.KeypadEnter)
|
||||
if ((evt.keyCode == KeyCode.Return || evt.keyCode == KeyCode.KeypadEnter) && evt.target is not Button)
|
||||
{
|
||||
ConfirmRootCreditExchange();
|
||||
evt.StopPropagation();
|
||||
@@ -1253,6 +1277,19 @@ namespace KernelPanic.UI
|
||||
return;
|
||||
}
|
||||
|
||||
if (_commandLine.Contains(evt.target)) return;
|
||||
if (evt.keyCode == KeyCode.Tab) return; // Native focus traversal; completion belongs to the prompt.
|
||||
if ((evt.target is Button || evt.target is Toggle) &&
|
||||
(evt.keyCode == KeyCode.Return || evt.keyCode == KeyCode.KeypadEnter || evt.keyCode == KeyCode.Space)) return;
|
||||
if (_activeScreen == MenuScreen.Main && evt.keyCode == KeyCode.Slash)
|
||||
{
|
||||
_commandLine.Focus();
|
||||
_root.panel?.focusController.IgnoreEvent(evt);
|
||||
evt.StopPropagation();
|
||||
return;
|
||||
}
|
||||
if (_activeScreen == MenuScreen.Settings && evt.keyCode != KeyCode.Escape) return;
|
||||
|
||||
if (evt.keyCode == KeyCode.Escape && IsCollectionVisible() && collectionScreen.BackFromSubview())
|
||||
{
|
||||
SyncCollectionFrame();
|
||||
@@ -1269,6 +1306,8 @@ namespace KernelPanic.UI
|
||||
|
||||
if (IsRunSetupVisible())
|
||||
{
|
||||
var target = evt.target as VisualElement;
|
||||
if (evt.keyCode != KeyCode.B && target != null && _runSetupDetail.Contains(target)) return;
|
||||
if (evt.keyCode == KeyCode.UpArrow)
|
||||
{
|
||||
SelectPackage(_selectedPackageIndex - 1);
|
||||
@@ -1293,19 +1332,30 @@ namespace KernelPanic.UI
|
||||
|
||||
if (IsCollectionVisible())
|
||||
{
|
||||
if (collectionScreen.IsUnitDetail &&
|
||||
(evt.keyCode == KeyCode.LeftArrow || evt.keyCode == KeyCode.RightArrow || evt.keyCode == KeyCode.Tab))
|
||||
bool primaryTabFocused = evt.target == _collectionUnitsButton ||
|
||||
evt.target == _collectionLanguagesButton || evt.target == _collectionPackagesButton;
|
||||
if (collectionScreen.IsUnitDetail && !primaryTabFocused &&
|
||||
(evt.keyCode == KeyCode.LeftArrow || evt.keyCode == KeyCode.RightArrow))
|
||||
{
|
||||
collectionScreen.SwitchUnitDetailTabRelative(evt.keyCode == KeyCode.LeftArrow ? -1 : 1);
|
||||
SyncCollectionFrame();
|
||||
_root.Q(className: "unit-detail-tabs")?.Q<Button>(className: "selected")?.Focus();
|
||||
evt.StopPropagation();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!collectionScreen.IsPushedSubview &&
|
||||
(evt.keyCode == KeyCode.LeftArrow || evt.keyCode == KeyCode.RightArrow || evt.keyCode == KeyCode.Tab))
|
||||
if ((!collectionScreen.IsPushedSubview || primaryTabFocused) &&
|
||||
(evt.keyCode == KeyCode.LeftArrow || evt.keyCode == KeyCode.RightArrow))
|
||||
{
|
||||
ToggleCollectionTab();
|
||||
if (evt.keyCode == KeyCode.LeftArrow)
|
||||
{
|
||||
if (_collectionTab == CollectionTopTab.Units) ShowCollectionPackages();
|
||||
else if (_collectionTab == CollectionTopTab.Languages) ShowCollectionUnits();
|
||||
else ShowCollectionLanguages();
|
||||
}
|
||||
else ToggleCollectionTab();
|
||||
(_collectionTab == CollectionTopTab.Units ? _collectionUnitsButton :
|
||||
_collectionTab == CollectionTopTab.Languages ? _collectionLanguagesButton : _collectionPackagesButton).Focus();
|
||||
evt.StopPropagation();
|
||||
return;
|
||||
}
|
||||
@@ -1360,7 +1410,7 @@ namespace KernelPanic.UI
|
||||
return;
|
||||
}
|
||||
|
||||
if (evt.keyCode == KeyCode.Tab)
|
||||
if (evt.keyCode == KeyCode.F2)
|
||||
{
|
||||
featuredUnitPanel.SelectNext();
|
||||
evt.StopPropagation();
|
||||
@@ -1426,10 +1476,10 @@ namespace KernelPanic.UI
|
||||
{
|
||||
int index = i;
|
||||
DistroDefinition unit = _playerCollection.OwnedUnits[i];
|
||||
VisualElement row = new();
|
||||
Button row = new();
|
||||
row.AddToClassList("package-row");
|
||||
row.RegisterCallback<PointerEnterEvent>(_ => SelectPackage(index));
|
||||
row.RegisterCallback<ClickEvent>(_ => SelectPackage(index));
|
||||
row.RegisterCallback<FocusInEvent>(_ => SelectPackage(index));
|
||||
row.clicked += () => SelectPackage(index);
|
||||
|
||||
VisualElement summary = new();
|
||||
summary.AddToClassList("package-summary");
|
||||
@@ -1467,7 +1517,9 @@ namespace KernelPanic.UI
|
||||
return;
|
||||
}
|
||||
|
||||
_selectedPackageIndex = (index + _packageRows.Count) % _packageRows.Count;
|
||||
int nextIndex = (index + _packageRows.Count) % _packageRows.Count;
|
||||
if (_selectedPackageIndex == nextIndex) return;
|
||||
_selectedPackageIndex = nextIndex;
|
||||
_cardLoadout.ClearLoadout(_playerCollection.OwnedUnits[_selectedPackageIndex]);
|
||||
_selectedRunLanguages.Clear();
|
||||
_runSetupPackageScroll = null;
|
||||
@@ -1477,17 +1529,23 @@ namespace KernelPanic.UI
|
||||
|
||||
private void RefreshPackageSelection()
|
||||
{
|
||||
var focused = _root.focusController?.focusedElement as VisualElement;
|
||||
bool listHasFocus = focused != null && _runSetupList.Contains(focused);
|
||||
for (int i = 0; i < _packageRows.Count; i++)
|
||||
{
|
||||
_packageRows[i].EnableInClassList(SelectedClassName, i == _selectedPackageIndex);
|
||||
}
|
||||
|
||||
if (_runSetupList is ScrollView list && _packageRows.Count > 0)
|
||||
list.ScrollTo(_packageRows[_selectedPackageIndex]);
|
||||
RenderSelectedPackageDetail();
|
||||
if (listHasFocus && _packageRows.Count > 0) _packageRows[_selectedPackageIndex].Focus();
|
||||
}
|
||||
|
||||
private void RenderSelectedPackageDetail()
|
||||
{
|
||||
Vector2 previousScrollOffset = _runSetupPackageScroll == null ? Vector2.zero : _runSetupPackageScroll.scrollOffset;
|
||||
TerminalTheme.PreserveFocus(_runSetupDetail);
|
||||
_runSetupDetail?.Clear();
|
||||
_loadoutRows.Clear();
|
||||
if (_runSetupDetail == null || _selectedPackageIndex < 0 || _selectedPackageIndex >= _playerCollection.OwnedUnits.Count)
|
||||
@@ -1496,11 +1554,12 @@ namespace KernelPanic.UI
|
||||
}
|
||||
|
||||
DistroDefinition unit = _playerCollection.OwnedUnits[_selectedPackageIndex];
|
||||
_runSetupDetail.Add(BuildRunSetupReadout(unit));
|
||||
AddRunSetupPassive(unit, _runSetupDetail);
|
||||
TerminalTheme.SetDistro(_runSetupDetail, unit);
|
||||
|
||||
ScrollView packageScroll = new(ScrollViewMode.Vertical);
|
||||
packageScroll.AddToClassList("package-scroll");
|
||||
_runSetupDetail.Add(BuildRunSetupReadout(unit));
|
||||
AddRunSetupPassive(unit, _runSetupDetail);
|
||||
|
||||
VisualElement packageList = new();
|
||||
packageList.AddToClassList("package-list");
|
||||
@@ -1553,6 +1612,11 @@ namespace KernelPanic.UI
|
||||
|
||||
packageScroll.Add(packageList);
|
||||
_runSetupDetail.Add(packageScroll);
|
||||
var readiness = new Label($"Cards {equippedCardIds.Count}/{CardLoadout.MaxEquippedCards} / Languages {_selectedRunLanguages.Count}/2");
|
||||
readiness.name = "RunSetupReadiness";
|
||||
readiness.AddToClassList("run-setup-readiness");
|
||||
readiness.EnableInClassList("ready", CanBootRun(equippedCardIds));
|
||||
_runSetupDetail.Add(readiness);
|
||||
_runSetupDetail.Add(BuildBootRow(unit, CanBootRun(equippedCardIds)));
|
||||
_runSetupPackageScroll = packageScroll;
|
||||
RestoreRunSetupPackageScroll(previousScrollOffset);
|
||||
@@ -1640,11 +1704,11 @@ namespace KernelPanic.UI
|
||||
|
||||
private VisualElement BuildCardLoadoutRow(DistroDefinition unit, CardDefinition card, bool equipped)
|
||||
{
|
||||
VisualElement row = new();
|
||||
Button row = new() { name = "loadout-" + card.Id };
|
||||
row.AddToClassList("package-row");
|
||||
row.AddToClassList("loadout-card-row");
|
||||
row.EnableInClassList("equipped", equipped);
|
||||
row.RegisterCallback<ClickEvent>(_ => ToggleCardInSelectedLoadout(unit, card));
|
||||
row.clicked += () => ToggleCardInSelectedLoadout(unit, card);
|
||||
|
||||
VisualElement summary = new();
|
||||
summary.AddToClassList("package-summary");
|
||||
@@ -1704,11 +1768,11 @@ namespace KernelPanic.UI
|
||||
|
||||
private VisualElement BuildRunLanguageRow(LanguageCatalogEntry language, bool selected)
|
||||
{
|
||||
VisualElement row = new();
|
||||
Button row = new() { name = "language-" + language.Language };
|
||||
row.AddToClassList("package-row");
|
||||
row.AddToClassList("run-language-row");
|
||||
row.EnableInClassList("equipped", selected);
|
||||
row.RegisterCallback<ClickEvent>(_ => ToggleRunLanguage(language.Language));
|
||||
row.clicked += () => ToggleRunLanguage(language.Language);
|
||||
|
||||
VisualElement summary = new();
|
||||
summary.AddToClassList("package-summary");
|
||||
@@ -1833,17 +1897,18 @@ namespace KernelPanic.UI
|
||||
|
||||
private VisualElement BuildBootRow(DistroDefinition unit, bool enabled)
|
||||
{
|
||||
VisualElement row = new();
|
||||
Button row = new() { name = "BootRunButton" };
|
||||
row.SetEnabled(enabled);
|
||||
row.AddToClassList("command-row");
|
||||
row.AddToClassList("boot-command-row");
|
||||
row.EnableInClassList("disabled-row", !enabled);
|
||||
row.RegisterCallback<ClickEvent>(_ => BootSelectedPackage());
|
||||
row.clicked += () => BootSelectedPackage();
|
||||
|
||||
row.Add(new Label(">") { name = "BootCommandCursor" });
|
||||
row.ElementAt(0).AddToClassList("command-cursor");
|
||||
row.Add(new Label($"./boot --distro={unit.Id}") { name = "BootCommandText" });
|
||||
row.ElementAt(1).AddToClassList("command-text");
|
||||
row.Add(new Label("start run") { name = "BootCommandDescription" });
|
||||
row.Add(new Label(enabled ? "ready / start run" : "select cards and 2 languages") { name = "BootCommandDescription" });
|
||||
row.ElementAt(2).AddToClassList("command-description");
|
||||
return row;
|
||||
}
|
||||
@@ -1915,7 +1980,7 @@ namespace KernelPanic.UI
|
||||
|
||||
private void HandlePointerDown(PointerDownEvent evt)
|
||||
{
|
||||
_root.Focus();
|
||||
if (evt.target == _root || evt.target == _shellRoot) _root.Focus();
|
||||
_suppressNextClick = SkipBootIntro();
|
||||
}
|
||||
|
||||
@@ -1930,7 +1995,9 @@ namespace KernelPanic.UI
|
||||
|
||||
private void ActivateCommand(int index)
|
||||
{
|
||||
_commandLine.Echo(index);
|
||||
_commandEntries[index].Activate();
|
||||
_root.Focus();
|
||||
}
|
||||
|
||||
private void HandleCommandClicked(int index)
|
||||
@@ -2098,8 +2165,15 @@ namespace KernelPanic.UI
|
||||
_gachaPanel.EnableInClassList(HiddenClassName, _gachaPanel != activePanel);
|
||||
_settingsPanel.EnableInClassList(HiddenClassName, _settingsPanel != activePanel);
|
||||
|
||||
foreach (var panel in new[] { _collectionPanel, _gachaPanel, _settingsPanel })
|
||||
if (panel.parent is TemplateContainer template)
|
||||
template.EnableInClassList(HiddenClassName, panel != activePanel);
|
||||
|
||||
bool showingMainMenu = _mainMenuPanel == activePanel;
|
||||
_motdBlock.EnableInClassList(HiddenClassName, !showingMainMenu || string.IsNullOrWhiteSpace(motdBody));
|
||||
_motdBlock.AddToClassList(HiddenClassName);
|
||||
_root.Q<TextField>("CommandInput").SetEnabled(showingMainMenu);
|
||||
_root.Q(className: "footer-bar").EnableInClassList(HiddenClassName, !showingMainMenu);
|
||||
_root.Focus();
|
||||
|
||||
if (showingMainMenu)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user