diff --git a/CollapseLauncher/XAMLs/MainApp/MainPage.xaml.cs b/CollapseLauncher/XAMLs/MainApp/MainPage.xaml.cs index 3dae8ddb2..d01893ce2 100644 --- a/CollapseLauncher/XAMLs/MainApp/MainPage.xaml.cs +++ b/CollapseLauncher/XAMLs/MainApp/MainPage.xaml.cs @@ -1387,6 +1387,13 @@ private void CreateKeyboardShortcutHandlers() KeyboardHandler.KeyboardAccelerators.Add(keystroke); } + KeyboardAccelerator keystrokeF5 = new KeyboardAccelerator() + { + Key = VirtualKey.F5 + }; + keystrokeF5.Invoked += RefreshPage_Invoked; + KeyboardHandler.KeyboardAccelerators.Add(keystrokeF5); + List actions = new() { // General @@ -1403,7 +1410,9 @@ private void CreateKeyboardShortcutHandlers() GoGameRepir_Invoked, GoGameSettings_Invoked, - GoGameCaches_Invoked + GoGameCaches_Invoked, + + RefreshPage_Invoked }; foreach (KeybindAction func in actions) @@ -1425,6 +1434,29 @@ private void CreateKeyboardShortcutHandlers() } } + private void RefreshPage_Invoked(KeyboardAccelerator sender, KeyboardAcceleratorInvokedEventArgs args) + { + if (IsKbShortcutCannotChange || !(IsLoadRegionComplete || IsExplicitCancel)) + return; + + switch (PreviousTag) + { + case "launcher": + RestoreCurrentRegion(); + ChangeRegionNoWarning(IsShowRegionChangeWarning ? ChangeRegionConfirmBtn : ChangeRegionConfirmBtnNoWarning, null); + return; + case "settings": + return; + default: + string Tag = PreviousTag; + PreviousTag = "Empty"; + NavigateInnerSwitch(Tag); + LauncherFrame.BackStack.RemoveAt(LauncherFrame.BackStack.Count - 1); + PreviousTagString.RemoveAt(PreviousTagString.Count - 1); + return; + } + } + private void DeleteKeyboardShortcutHandlers() => KeyboardHandler.KeyboardAccelerators.Clear(); private async void ChangeTimer(int time = 500) @@ -1438,10 +1470,27 @@ private async void ChangeTimer(int time = 500) catch { } } + private void RestoreCurrentRegion() + { + string GameCategory = GetAppConfigValue("GameCategory").ToString(); + + if (!GetConfigV2Regions(GameCategory)) + GameCategory = ConfigV2GameCategory.FirstOrDefault(); + + int IndexCategory = ConfigV2GameCategory.IndexOf(GameCategory); + if (IndexCategory < 0) IndexCategory = 0; + + int IndexRegion = GetPreviousGameRegion(GameCategory); + + ComboBoxGameCategory.SelectedIndex = IndexCategory; + ComboBoxGameRegion.SelectedIndex = IndexRegion; + } + private void KeyboardGameShortcut_Invoked(KeyboardAccelerator sender, KeyboardAcceleratorInvokedEventArgs args) { int index = (int)sender.Key; index -= index < 96 ? 49 : 97; + RestoreCurrentRegion(); if (IsKbShortcutCannotChange || !(IsLoadRegionComplete || IsExplicitCancel) || index >= ComboBoxGameCategory.Items.Count) return; @@ -1460,6 +1509,7 @@ private void KeyboardGameRegionShortcut_Invoked(KeyboardAccelerator sender, Keyb { int index = (int)sender.Key; index -= index < 96 ? 49 : 97; + RestoreCurrentRegion(); if (IsKbShortcutCannotChange || !(IsLoadRegionComplete || IsExplicitCancel) || index >= ComboBoxGameRegion.Items.Count) return; diff --git a/CollapseLauncher/XAMLs/MainApp/Pages/Dialogs/KeyboardShortcuts.cs b/CollapseLauncher/XAMLs/MainApp/Pages/Dialogs/KeyboardShortcuts.cs index 6acc20cea..e0e742064 100644 --- a/CollapseLauncher/XAMLs/MainApp/Pages/Dialogs/KeyboardShortcuts.cs +++ b/CollapseLauncher/XAMLs/MainApp/Pages/Dialogs/KeyboardShortcuts.cs @@ -41,6 +41,7 @@ public static async Task Dialog_ShowKbShortcuts(UIElement C genStack.Children.Add(GenerateShortcutBlock(keys[3], Lang._KbShortcuts.General_GoHome)); genStack.Children.Add(GenerateShortcutBlock(keys[4], Lang._KbShortcuts.General_GoSettings)); genStack.Children.Add(GenerateShortcutBlock(keys[5], Lang._KbShortcuts.General_OpenNotifTray)); + genStack.Children.Add(GenerateShortcutBlock(keys[13], Lang._KbShortcuts.General_ReloadRegion, Lang._KbShortcuts.General_ReloadRegion_Desc)); genStack.Children.Add(new MenuFlyoutSeparator() { Margin = new Thickness(0, 10, 0, 8) }); pageNum++; @@ -48,7 +49,7 @@ public static async Task Dialog_ShowKbShortcuts(UIElement C StackPanel changeStack = new StackPanel() { Orientation = Orientation.Vertical, Visibility = Visibility.Collapsed }; changeStack.Children.Add(new TextBlock { Text = Lang._KbShortcuts.Switch_Title, FontSize = 16, FontWeight = FontWeights.Bold, Margin = new Thickness(0, 0, 0, 2) }); changeStack.Children.Add(new TextBlock { Text = Lang._KbShortcuts.Switch_Subtitle, FontSize = 11.5 }); - + string gameMod = keys[0][0]; string regionMod = keys[1][0]; @@ -180,9 +181,10 @@ private static Grid GenerateShortcutBlock(List kbKeys, string descriptio Orientation = Orientation.Horizontal }; - List dataKeys = new List { kbKeys[0], kbKeys[1], description, pageNum.ToString() }; - if (enableSwapButton) + + if (enableSwapButton && kbKeys.Count > 1) { + List dataKeys = new List { kbKeys[0], kbKeys[1], description, pageNum.ToString() }; Button shortcutSwap = new Button() { Content = new TextBlock() { Text = "", FontSize = 12, Margin = new Thickness(-5, 0, -5, 0), FontFamily = Application.Current.Resources["FontAwesomeSolid"] as FontFamily }, @@ -555,7 +557,7 @@ private static bool ValidKeyCombination(List keys) new List { "Ctrl", "1 - 3" }, // Game selection new List { "Shift", "1 - 6" }, // Region selection - new List { "Ctrl", "Tab" }, // Keybind menu + new List { "Ctrl", "Tab" }, // Keyboard shortcuts menu new List { "Ctrl", "H" }, // Home page new List { "Ctrl", "S" }, // Settings page new List { "Ctrl", "Q" }, // Notification panel @@ -567,7 +569,9 @@ private static bool ValidKeyCombination(List keys) new List { "Shift", "R" }, // Repair page new List { "Shift", "S" }, // Game settings page - new List { "Shift", "C" } // Caches page + new List { "Shift", "C" }, // Caches page + + new List { "Ctrl", "R" } // Reload region }; @@ -602,7 +606,9 @@ public static List> KeyList if (resultList.Count < defaultKeyList.Count) { - resultList.InsertRange(resultList.Count, defaultKeyList.GetRange(resultList.Count, defaultKeyList.Count - resultList.Count)); + int newKeyCount = defaultKeyList.Count - resultList.Count; + resultList.InsertRange(resultList.Count, defaultKeyList.GetRange(resultList.Count, newKeyCount)); + KeyList = resultList; } return resultList; diff --git a/Hi3Helper.Core/Lang/Locale/LangKeyboardShortcuts.cs b/Hi3Helper.Core/Lang/Locale/LangKeyboardShortcuts.cs index 3472339f8..8ac275a0a 100644 --- a/Hi3Helper.Core/Lang/Locale/LangKeyboardShortcuts.cs +++ b/Hi3Helper.Core/Lang/Locale/LangKeyboardShortcuts.cs @@ -21,6 +21,8 @@ public sealed class LangKeyboardShortcuts public string General_GoHome { get; set; } = LangFallback?._KbShortcuts.General_GoHome; public string General_GoSettings { get; set; } = LangFallback?._KbShortcuts.General_GoSettings; public string General_OpenNotifTray { get; set; } = LangFallback?._KbShortcuts.General_OpenNotifTray; + public string General_ReloadRegion { get; set; } = LangFallback?._KbShortcuts.General_ReloadRegion; + public string General_ReloadRegion_Desc { get; set; } = LangFallback?._KbShortcuts.General_ReloadRegion_Desc; public string Switch_Title { get; set; } = LangFallback?._KbShortcuts.Switch_Title; public string Switch_Subtitle { get; set; } = LangFallback?._KbShortcuts.Switch_Subtitle; diff --git a/Hi3Helper.Core/Lang/en_US.json b/Hi3Helper.Core/Lang/en_US.json index 8cd16561b..750788bc8 100644 --- a/Hi3Helper.Core/Lang/en_US.json +++ b/Hi3Helper.Core/Lang/en_US.json @@ -939,6 +939,8 @@ "General_GoHome": "Go to the Home page", "General_GoSettings": "Go to the Settings page", "General_OpenNotifTray": "Open the Notification Tray", + "General_ReloadRegion": "Reload current page", + "General_ReloadRegion_Desc": "Pressing F5 is an alternative to this shortcut.\nPlease note that reloading the Home Page will reload the region.", "Switch_Title": "Quick Game/Region change", "Switch_Subtitle": "Note: The keybinds follow the selector order.",