From eaadd507d3d253f44674495002bc70fe3023aa7e Mon Sep 17 00:00:00 2001 From: diquoks Date: Tue, 24 Jun 2025 19:15:02 +0300 Subject: [PATCH] Add custom keybinds to tips in `Main menu` --- osu.Game/Localisation/MenuTipStrings.cs | 32 ++++++++++++------------- osu.Game/Screens/Menu/MenuTipDisplay.cs | 22 ++++++++++------- 2 files changed, 30 insertions(+), 24 deletions(-) diff --git a/osu.Game/Localisation/MenuTipStrings.cs b/osu.Game/Localisation/MenuTipStrings.cs index 9d398e8e64..9a52f2e279 100644 --- a/osu.Game/Localisation/MenuTipStrings.cs +++ b/osu.Game/Localisation/MenuTipStrings.cs @@ -10,14 +10,14 @@ namespace osu.Game.Localisation private const string prefix = @"osu.Game.Resources.Localisation.MenuTip"; /// - /// "Press Ctrl-T anywhere in the game to toggle the toolbar!" + /// "Press {0} anywhere in the game to toggle the toolbar!" /// - public static LocalisableString ToggleToolbarShortcut => new TranslatableString(getKey(@"toggle_toolbar_shortcut"), @"Press Ctrl-T anywhere in the game to toggle the toolbar!"); + public static LocalisableString ToggleToolbarShortcut(LocalisableString keybind) => new TranslatableString(getKey(@"toggle_toolbar_shortcut"), @"Press {0} anywhere in the game to toggle the toolbar!", keybind); /// - /// "Press Ctrl-O anywhere in the game to access settings!" + /// "Press {0} anywhere in the game to access settings!" /// - public static LocalisableString GameSettingsShortcut => new TranslatableString(getKey(@"game_settings_shortcut"), @"Press Ctrl-O anywhere in the game to access settings!"); + public static LocalisableString GameSettingsShortcut(LocalisableString keybind) => new TranslatableString(getKey(@"game_settings_shortcut"), @"Press {0} anywhere in the game to access settings!", keybind); /// /// "All settings are dynamic and take effect in real-time. Try changing the skin while watching autoplay!" @@ -40,9 +40,9 @@ namespace osu.Game.Localisation public static LocalisableString ScreenScalingSettings => new TranslatableString(getKey(@"screen_scaling_settings"), @"Try adjusting the ""Screen Scaling"" mode to change your gameplay or UI area, even in fullscreen!"); /// - /// "What used to be "osu!direct" is available to all users just like on the website. You can access it anywhere using Ctrl-B!" + /// "What used to be "osu!direct" is available to all users just like on the website. You can access it anywhere using {0}!" /// - public static LocalisableString FreeOsuDirect => new TranslatableString(getKey(@"free_osu_direct"), @"What used to be ""osu!direct"" is available to all users just like on the website. You can access it anywhere using Ctrl-B!"); + public static LocalisableString FreeOsuDirect(LocalisableString keybind) => new TranslatableString(getKey(@"free_osu_direct"), @"What used to be ""osu!direct"" is available to all users just like on the website. You can access it anywhere using {0}!", keybind); /// /// "Seeking in replays is available by dragging on the progress bar at the bottom of the screen or by using the left and right arrow keys!" @@ -75,9 +75,9 @@ namespace osu.Game.Localisation public static LocalisableString ToggleAdvancedFPSCounter => new TranslatableString(getKey(@"toggle_advanced_fps_counter"), @"Toggle advanced frame / thread statistics with Ctrl-F11!"); /// - /// "You can pause during a replay by pressing Space!" + /// "You can pause during a replay by pressing {0}!" /// - public static LocalisableString ReplayPausing => new TranslatableString(getKey(@"replay_pausing"), @"You can pause during a replay by pressing Space!"); + public static LocalisableString ReplayPausing(LocalisableString keybind) => new TranslatableString(getKey(@"replay_pausing"), @"You can pause during a replay by pressing {0}!", keybind); /// /// "Most of the hotkeys in the game are configurable and can be changed to anything you want. Check the bindings panel under input settings!" @@ -85,9 +85,9 @@ namespace osu.Game.Localisation public static LocalisableString ConfigurableHotkeys => new TranslatableString(getKey(@"configurable_hotkeys"), @"Most of the hotkeys in the game are configurable and can be changed to anything you want. Check the bindings panel under input settings!"); /// - /// "Your gameplay HUD can be customised by using the skin layout editor. Open it at any time via Ctrl-Shift-S!" + /// "Your gameplay HUD can be customised by using the skin layout editor. Open it at any time via {0}!" /// - public static LocalisableString SkinEditor => new TranslatableString(getKey(@"skin_editor"), @"Your gameplay HUD can be customised by using the skin layout editor. Open it at any time via Ctrl-Shift-S!"); + public static LocalisableString SkinEditor(LocalisableString keybind) => new TranslatableString(getKey(@"skin_editor"), @"Your gameplay HUD can be customised by using the skin layout editor. Open it at any time via {0}!", keybind); /// /// "You can create mod presets to make toggling your favourite mod combinations easier!" @@ -100,14 +100,14 @@ namespace osu.Game.Localisation public static LocalisableString ModCustomisationSettings => new TranslatableString(getKey(@"mod_customisation_settings"), @"Many mods have customisation settings that drastically change how they function. Click the Customise button in mod select to view settings!"); /// - /// "Press Ctrl-Shift-R to switch to a random skin!" + /// "Press {0} to switch to a random skin!" /// - public static LocalisableString RandomSkinShortcut => new TranslatableString(getKey(@"random_skin_shortcut"), @"Press Ctrl-Shift-R to switch to a random skin!"); + public static LocalisableString RandomSkinShortcut(LocalisableString keybind) => new TranslatableString(getKey(@"random_skin_shortcut"), @"Press {0} to switch to a random skin!", keybind); /// - /// "While watching a replay, press Ctrl-H to toggle replay settings!" + /// "While watching a replay, press {0} to toggle replay settings!" /// - public static LocalisableString ToggleReplaySettingsShortcut => new TranslatableString(getKey(@"toggle_replay_settings_shortcut"), @"While watching a replay, press Ctrl-H to toggle replay settings!"); + public static LocalisableString ToggleReplaySettingsShortcut(LocalisableString keybind) => new TranslatableString(getKey(@"toggle_replay_settings_shortcut"), @"While watching a replay, press {0} to toggle replay settings!", keybind); /// /// "You can easily copy the mods from scores on a leaderboard by right-clicking on them!" @@ -140,9 +140,9 @@ namespace osu.Game.Localisation public static LocalisableString GlobalStatisticsShortcut => new TranslatableString(getKey(@"global_statistics_shortcut"), @"Take a look under the hood at performance counters and enable verbose performance logging with Ctrl-F2!"); /// - /// "When your gameplay HUD is hidden, you can press and hold Ctrl to view it temporarily!" + /// "When your gameplay HUD is hidden, you can press and hold {0} to view it temporarily!" /// - public static LocalisableString PeekHUDWhenHidden => new TranslatableString(getKey(@"peek_hud_when_hidden"), @"When your gameplay HUD is hidden, you can press and hold Ctrl to view it temporarily!"); + public static LocalisableString PeekHUDWhenHidden(LocalisableString keybind) => new TranslatableString(getKey(@"peek_hud_when_hidden"), @"When your gameplay HUD is hidden, you can press and hold {0} to view it temporarily!", keybind); /// /// "Drag and drop any image into the skin editor to load it in quickly!" diff --git a/osu.Game/Screens/Menu/MenuTipDisplay.cs b/osu.Game/Screens/Menu/MenuTipDisplay.cs index 283528d22a..f1464fcba7 100644 --- a/osu.Game/Screens/Menu/MenuTipDisplay.cs +++ b/osu.Game/Screens/Menu/MenuTipDisplay.cs @@ -1,6 +1,7 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +using System.Linq; using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Graphics; @@ -12,6 +13,8 @@ using osu.Framework.Utils; using osu.Game.Configuration; using osu.Game.Graphics; using osu.Game.Graphics.Containers; +using osu.Game.Input; +using osu.Game.Input.Bindings; using osuTK; using osuTK.Graphics; using osu.Game.Localisation; @@ -27,6 +30,9 @@ namespace osu.Game.Screens.Menu private Bindable showMenuTips = null!; + [Resolved] + private RealmKeyBindingStore keyBindingStore { get; set; } = null!; + [BackgroundDependencyLoader] private void load() { @@ -101,13 +107,13 @@ namespace osu.Game.Screens.Menu { LocalisableString[] tips = { - MenuTipStrings.ToggleToolbarShortcut, - MenuTipStrings.GameSettingsShortcut, + MenuTipStrings.ToggleToolbarShortcut(keyBindingStore.GetReadableKeyCombinationsFor(GlobalAction.ToggleToolbar).FirstOrDefault("Ctrl+T")), + MenuTipStrings.GameSettingsShortcut(keyBindingStore.GetReadableKeyCombinationsFor(GlobalAction.ToggleSettings).FirstOrDefault("Ctrl+O")), MenuTipStrings.DynamicSettings, MenuTipStrings.NewFeaturesAreComingOnline, MenuTipStrings.UIScalingSettings, MenuTipStrings.ScreenScalingSettings, - MenuTipStrings.FreeOsuDirect, + MenuTipStrings.FreeOsuDirect(keyBindingStore.GetReadableKeyCombinationsFor(GlobalAction.ToggleBeatmapListing).FirstOrDefault("Ctrl+B")), MenuTipStrings.ReplaySeeking, MenuTipStrings.MultithreadingSupport, MenuTipStrings.TryNewMods, @@ -117,15 +123,15 @@ namespace osu.Game.Screens.Menu MenuTipStrings.DiscoverPlaylists, MenuTipStrings.ToggleAdvancedFPSCounter, MenuTipStrings.GlobalStatisticsShortcut, - MenuTipStrings.ReplayPausing, + MenuTipStrings.ReplayPausing(keyBindingStore.GetReadableKeyCombinationsFor(GlobalAction.TogglePauseReplay).FirstOrDefault("Space")), MenuTipStrings.ConfigurableHotkeys, - MenuTipStrings.PeekHUDWhenHidden, - MenuTipStrings.SkinEditor, + MenuTipStrings.PeekHUDWhenHidden(keyBindingStore.GetReadableKeyCombinationsFor(GlobalAction.HoldForHUD).FirstOrDefault("Ctrl")), + MenuTipStrings.SkinEditor(keyBindingStore.GetReadableKeyCombinationsFor(GlobalAction.ToggleSkinEditor).FirstOrDefault("Ctrl+Shift+S")), MenuTipStrings.DragAndDropImageInSkinEditor, MenuTipStrings.ModPresets, MenuTipStrings.ModCustomisationSettings, - MenuTipStrings.RandomSkinShortcut, - MenuTipStrings.ToggleReplaySettingsShortcut, + MenuTipStrings.RandomSkinShortcut(keyBindingStore.GetReadableKeyCombinationsFor(GlobalAction.RandomSkin).FirstOrDefault("Ctrl+Shift+R")), + MenuTipStrings.ToggleReplaySettingsShortcut(keyBindingStore.GetReadableKeyCombinationsFor(GlobalAction.ToggleReplaySettings).FirstOrDefault("Ctrl+H")), MenuTipStrings.CopyModsFromScore, MenuTipStrings.AutoplayBeatmapShortcut, MenuTipStrings.LazerIsNotAWord