Implement more QoL features and rebalances
This commit is contained in:
@@ -158,6 +158,10 @@ namespace KernelPanic.UI
|
||||
private bool _loadingMetaState;
|
||||
private VisualElement _saveRecoveryOverlay;
|
||||
private VisualElement _runHistoryOverlay;
|
||||
private VisualElement _dailyQuestOverlay;
|
||||
private bool _dailyQuestReturnToPrompt;
|
||||
private VisualElement _dailyQuestPreviousFocus;
|
||||
private bool _dailyQuestOpenedWithPointer;
|
||||
private EntropyWallet _wallet;
|
||||
private GachaService _gachaService;
|
||||
private PlayerCollection _playerCollection;
|
||||
@@ -185,6 +189,7 @@ namespace KernelPanic.UI
|
||||
private Action _rootCreditExchangePlusHundredClicked;
|
||||
private IVisualElementScheduledItem _blinkSchedule;
|
||||
private IVisualElementScheduledItem _bootIntroSchedule;
|
||||
private IVisualElementScheduledItem _dailyQuestSchedule;
|
||||
private TerminalCommandLine _commandLine;
|
||||
private MenuScreen _activeScreen = MenuScreen.Main;
|
||||
|
||||
@@ -202,7 +207,7 @@ namespace KernelPanic.UI
|
||||
LoadSharedStyles();
|
||||
BindCommandEntries();
|
||||
TerminalTheme.Attach(_root);
|
||||
_commandLine = new TerminalCommandLine(_root, ActivateCommand, () => _activeScreen == MenuScreen.Main && !starterSelection.IsActive && !_rootCreditExchangeOpen && _runHistoryOverlay == null && !CheckpointModalOpen && !_runLaunchPending && !PersistenceBlocked);
|
||||
_commandLine = new TerminalCommandLine(_root, ActivateCommand, () => _activeScreen == MenuScreen.Main && !starterSelection.IsActive && !_rootCreditExchangeOpen && _runHistoryOverlay == null && _dailyQuestOverlay == null && !CheckpointModalOpen && !_runLaunchPending && !PersistenceBlocked);
|
||||
BindPreferences();
|
||||
RegisterCommandEntryCallbacks();
|
||||
BindScreenFrames();
|
||||
@@ -235,6 +240,12 @@ namespace KernelPanic.UI
|
||||
});
|
||||
Button textSize = _root.Q<Button>("TextSizeButton");
|
||||
Button density = _root.Q<Button>("DensityButton");
|
||||
_root.Q<Button>("SoundVolumeButton").clicked += () =>
|
||||
{
|
||||
UIPreferences.SoundVolume = (UIPreferences.SoundVolume / 25 + 1) % 5 * 25;
|
||||
UIPreferences.Save();
|
||||
RefreshPreferenceControls();
|
||||
};
|
||||
textSize.clicked += () =>
|
||||
{
|
||||
UIPreferences.TextSize = UIPreferences.TextSize == UITextSize.Standard ? UITextSize.Large : UITextSize.Standard;
|
||||
@@ -257,6 +268,7 @@ namespace KernelPanic.UI
|
||||
motion.text = UIPreferences.ReducedMotion ? "[ true ]" : "[ false ]";
|
||||
_root.Q<Button>("TextSizeButton").text = UIPreferences.TextSize == UITextSize.Large ? "[ large ]" : "[ standard ]";
|
||||
_root.Q<Button>("DensityButton").text = UIPreferences.Density == UILayoutDensity.Comfortable ? "[ comfortable ]" : "[ compact ]";
|
||||
_root.Q<Button>("SoundVolumeButton").text = UIPreferences.SoundVolume == 0 ? "[ muted ]" : $"[ {UIPreferences.SoundVolume}% ]";
|
||||
}
|
||||
|
||||
private void ComposeMetaServices()
|
||||
@@ -294,6 +306,8 @@ namespace KernelPanic.UI
|
||||
|
||||
StartAmbientSchedules();
|
||||
PlayBootIntroIfNeeded();
|
||||
RefreshDailyQuestPanel();
|
||||
_dailyQuestSchedule = _root.schedule.Execute(TickDailyQuests).Every(1000);
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
@@ -302,6 +316,7 @@ namespace KernelPanic.UI
|
||||
_blinkSchedule?.Pause();
|
||||
_backgroundLog?.Stop();
|
||||
_bootIntroSchedule?.Pause();
|
||||
_dailyQuestSchedule?.Pause();
|
||||
starterSelection.PauseSchedules();
|
||||
}
|
||||
|
||||
@@ -797,8 +812,109 @@ namespace KernelPanic.UI
|
||||
_loadingMetaState = false;
|
||||
}
|
||||
|
||||
DailyQuests.Refresh(_saveData.dailyQuests, DateTime.UtcNow);
|
||||
SaveCurrentState();
|
||||
RefreshRunActions();
|
||||
RefreshDailyQuestPanel();
|
||||
}
|
||||
|
||||
private void RefreshDailyQuestPanel()
|
||||
{
|
||||
var host = _root?.Q("DailyQuestsHost");
|
||||
if (host == null || _saveData == null) return;
|
||||
TerminalTheme.PreserveFocus(host);
|
||||
host.Clear();
|
||||
var widget = DailyQuestView.BuildWidget(_saveData.dailyQuests, DateTime.UtcNow, () => OpenDailyQuestDetails());
|
||||
// Mouse focus is incidental; only keyboard activation should restore the widget's focus ring.
|
||||
widget.RegisterCallback<PointerDownEvent>(_ => _dailyQuestOpenedWithPointer = true, TrickleDown.TrickleDown);
|
||||
widget.RegisterCallback<KeyDownEvent>(_ => _dailyQuestOpenedWithPointer = false, TrickleDown.TrickleDown);
|
||||
widget.RegisterCallback<NavigationSubmitEvent>(_ => _dailyQuestOpenedWithPointer = false, TrickleDown.TrickleDown);
|
||||
host.Add(widget);
|
||||
if (_dailyQuestOverlay != null)
|
||||
{
|
||||
var scroll = _dailyQuestOverlay.Q<ScrollView>("DailyQuestDetailScroll");
|
||||
var offset = scroll.scrollOffset;
|
||||
var focused = _root.focusController?.focusedElement as VisualElement;
|
||||
bool restoreFocus = focused != null && _dailyQuestOverlay.Contains(focused);
|
||||
string name = focused?.name;
|
||||
scroll.Clear();
|
||||
scroll.Add(DailyQuestView.Build(_saveData.dailyQuests, DateTime.UtcNow, ClaimDailyQuest));
|
||||
DailyQuestView.RefreshHeader(_dailyQuestOverlay, _saveData.dailyQuests, DateTime.UtcNow);
|
||||
scroll.scrollOffset = offset;
|
||||
if (restoreFocus)
|
||||
{
|
||||
var replacement = string.IsNullOrEmpty(name) ? null : _dailyQuestOverlay.Q<Button>(name);
|
||||
if (replacement?.enabledInHierarchy != true)
|
||||
replacement = _dailyQuestOverlay.Q<Button>("CloseDailyQuests");
|
||||
replacement?.Focus();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OpenDailyQuestDetails()
|
||||
{
|
||||
if (PersistenceBlocked || _runLaunchPending || _dailyQuestOverlay != null || _activeScreen != MenuScreen.Main
|
||||
|| starterSelection.IsActive || _rootCreditExchangeOpen || _runHistoryOverlay != null || CheckpointModalOpen) return;
|
||||
_dailyQuestPreviousFocus = _root.focusController?.focusedElement as VisualElement;
|
||||
TickDailyQuests();
|
||||
if (PersistenceBlocked) return;
|
||||
_dailyQuestReturnToPrompt = false;
|
||||
_dailyQuestOverlay = DailyQuestView.BuildOverlay(_saveData.dailyQuests, DateTime.UtcNow, ClaimDailyQuest, CloseDailyQuestDetails);
|
||||
_root.Add(_dailyQuestOverlay);
|
||||
_shellRoot?.SetEnabled(false);
|
||||
_dailyQuestOverlay.Query<Button>().Where(button => button.enabledInHierarchy).First()?.Focus();
|
||||
}
|
||||
|
||||
private void CloseDailyQuestDetails()
|
||||
{
|
||||
_dailyQuestOverlay?.RemoveFromHierarchy();
|
||||
_dailyQuestOverlay = null;
|
||||
_shellRoot?.SetEnabled(!PersistenceBlocked);
|
||||
if (_dailyQuestReturnToPrompt) _commandLine?.Focus();
|
||||
else if (_dailyQuestOpenedWithPointer) (_root?.Q("Root") ?? _root)?.Focus();
|
||||
else if (_dailyQuestPreviousFocus?.panel != null && _dailyQuestPreviousFocus.enabledInHierarchy)
|
||||
_dailyQuestPreviousFocus.Focus();
|
||||
else _root?.Q<Button>("DailyQuestWidget")?.Focus();
|
||||
_dailyQuestPreviousFocus = null;
|
||||
_dailyQuestOpenedWithPointer = false;
|
||||
}
|
||||
|
||||
private void TickDailyQuests()
|
||||
{
|
||||
if (_saveData == null || PersistenceBlocked || _runLaunchPending) return;
|
||||
var now = DateTime.UtcNow;
|
||||
if (DailyQuests.Refresh(_saveData.dailyQuests, now))
|
||||
{
|
||||
var feedback = _dailyQuestOverlay?.Q<Label>("DailyQuestFeedback");
|
||||
if (feedback != null) feedback.style.display = DisplayStyle.None;
|
||||
SaveCurrentState();
|
||||
RefreshDailyQuestPanel();
|
||||
}
|
||||
var countdown = _root?.Q<Label>("DailyQuestCountdown");
|
||||
if (countdown != null) countdown.text = DailyQuests.Countdown(_saveData.dailyQuests, now);
|
||||
if (_dailyQuestOverlay != null) DailyQuestView.RefreshHeader(_dailyQuestOverlay, _saveData.dailyQuests, now);
|
||||
}
|
||||
|
||||
private void ClaimDailyQuest(DailyQuestKind kind, long period)
|
||||
{
|
||||
if (PersistenceBlocked || _runLaunchPending) return;
|
||||
bool claimed = DailyQuests.Claim(_saveData, kind, period, DateTime.UtcNow);
|
||||
if (claimed)
|
||||
_wallet.SetBalance(_saveData.entropyBalance);
|
||||
// Balances and the claim bit are committed in the same atomic save.
|
||||
// On failure the existing recovery dialog blocks spending until retry succeeds.
|
||||
SaveCurrentState();
|
||||
RefreshDailyQuestPanel();
|
||||
RefreshCurrencyReadouts();
|
||||
gachaScreen.Refresh();
|
||||
var feedback = _dailyQuestOverlay?.Q<Label>("DailyQuestFeedback");
|
||||
if (feedback != null && claimed && !PersistenceBlocked)
|
||||
{
|
||||
var reward = DailyQuests.Reward(kind);
|
||||
feedback.text = $"[ OK ] Daily task completed.\n[ OK ] +{reward.Bandwidth} Bandwidth, +{reward.Entropy} Entropy deposited.";
|
||||
feedback.style.display = DisplayStyle.Flex;
|
||||
}
|
||||
else if (feedback != null && PersistenceBlocked) feedback.style.display = DisplayStyle.None;
|
||||
}
|
||||
|
||||
private bool PersistenceBlocked => _saveLoadFailed || _saveWriteFailed;
|
||||
@@ -850,7 +966,7 @@ namespace KernelPanic.UI
|
||||
{
|
||||
_saveRecoveryOverlay?.RemoveFromHierarchy();
|
||||
_saveRecoveryOverlay = null;
|
||||
_shellRoot?.SetEnabled(true);
|
||||
_shellRoot?.SetEnabled(_dailyQuestOverlay == null);
|
||||
_root.Q("StarterModal")?.SetEnabled(true);
|
||||
_rootCreditExchangeModal?.SetEnabled(true);
|
||||
}
|
||||
@@ -970,12 +1086,13 @@ namespace KernelPanic.UI
|
||||
if (_saveData.tutorialCheckpoint != null)
|
||||
{
|
||||
var checkpoint = _saveData.tutorialCheckpoint;
|
||||
RunCheckpoint.Require(checkpoint.wave == 2 && checkpoint.wavesCleared == 1
|
||||
RunCheckpoint.Require(checkpoint.wave >= 2 && checkpoint.wave <= TutorialCampaign.LessonCount
|
||||
&& checkpoint.wavesCleared == checkpoint.wave - 1
|
||||
&& checkpoint.journey?.campaign == false && checkpoint.packages?.Count == 0
|
||||
&& checkpoint.offers?.Exists(offer => offer != null && offer.sold) == true,
|
||||
"Training checkpoint is not a purchased first-wave shop.");
|
||||
&& (checkpoint.wave > 2 || checkpoint.offers?.Exists(offer => offer != null && offer.sold) == true),
|
||||
"Training checkpoint is not a completed lesson boundary.");
|
||||
var resume = _saveData.tutorialCheckpoint.Resolve(distroDatabase, cardDatabase, languageDeckDatabase, packageDatabase);
|
||||
resume.Config.TutorialLesson = 2;
|
||||
resume.Config.TutorialLesson = TutorialCampaign.Lesson(_saveData);
|
||||
RunContext.SetResume(resume);
|
||||
}
|
||||
else RunContext.SetTutorial(TutorialCampaign.CreateConfig(distro, cardDatabase, 1));
|
||||
@@ -1365,7 +1482,16 @@ namespace KernelPanic.UI
|
||||
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<PointerEnterEvent>(_ =>
|
||||
{
|
||||
SelectCommand(index);
|
||||
// Hover selects a primary command; Enter must no longer target the side widget.
|
||||
if (_dailyQuestOverlay == null && _root.focusController?.focusedElement == _root.Q<Button>("DailyQuestWidget"))
|
||||
{
|
||||
_root.Q<Button>("DailyQuestWidget").Blur();
|
||||
(_root.Q("Root") ?? _root).Focus();
|
||||
}
|
||||
});
|
||||
_commandEntries[i].Row.RegisterCallback<ClickEvent>(_ => HandleCommandClicked(index));
|
||||
}
|
||||
}
|
||||
@@ -1515,6 +1641,12 @@ namespace KernelPanic.UI
|
||||
return;
|
||||
}
|
||||
if (PersistenceBlocked) return;
|
||||
if (_dailyQuestOverlay != null)
|
||||
{
|
||||
if (evt.keyCode == KeyCode.Escape) CloseDailyQuestDetails();
|
||||
evt.StopPropagation();
|
||||
return;
|
||||
}
|
||||
if (_runHistoryOverlay != null)
|
||||
{
|
||||
if (evt.keyCode == KeyCode.Escape) CloseRunHistory();
|
||||
@@ -1670,6 +1802,8 @@ namespace KernelPanic.UI
|
||||
if (evt.keyCode == KeyCode.UpArrow)
|
||||
{
|
||||
SelectCommand(_selectedCommandIndex - 1);
|
||||
_commandEntries[_selectedCommandIndex].Row.Focus();
|
||||
_root.panel?.focusController.IgnoreEvent(evt);
|
||||
evt.StopPropagation();
|
||||
return;
|
||||
}
|
||||
@@ -1677,6 +1811,8 @@ namespace KernelPanic.UI
|
||||
if (evt.keyCode == KeyCode.DownArrow)
|
||||
{
|
||||
SelectCommand(_selectedCommandIndex + 1);
|
||||
_commandEntries[_selectedCommandIndex].Row.Focus();
|
||||
_root.panel?.focusController.IgnoreEvent(evt);
|
||||
evt.StopPropagation();
|
||||
return;
|
||||
}
|
||||
@@ -2355,6 +2491,14 @@ namespace KernelPanic.UI
|
||||
{
|
||||
if (PersistenceBlocked) return;
|
||||
_commandLine.Echo(index);
|
||||
// Prompt-only alias; the six primary navigation commands retain their indices.
|
||||
if (index == 6)
|
||||
{
|
||||
_dailyQuestOpenedWithPointer = false;
|
||||
OpenDailyQuestDetails();
|
||||
_dailyQuestReturnToPrompt = true;
|
||||
return;
|
||||
}
|
||||
_commandEntries[index].Activate();
|
||||
_root.Focus();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user