GUI: Implement custom hotkeys

- This will show `default hotkeys` from `PCSX2_keys.ini.default` or based on the `copy of PCSX2_keys.ini` that the user itself added to `inis folder` for changing it `for custom hotkeys`.
This commit is contained in:
RedDevilus 2020-12-11 04:06:09 +01:00 committed by refractionpcsx2
parent 5583a75eac
commit ee54396670
6 changed files with 74 additions and 43 deletions

View File

@ -107,7 +107,12 @@ struct KeyAcceleratorCode
return wxEmptyString;
wxString lastToken = tokens.at(tokens.size() - 1);
tokens.at(tokens.size() - 1) = lastToken[0] = wxToupper(lastToken[0]);
// If the final token is a key that is multiple characters. For example 'Tab' or 'Esc'. There is no need to modify it
// Otherwise, it could be a normal letter key, so we capitalize it for stylistic reasons.
if (lastToken.Length() == 1)
{
tokens.at(tokens.size() - 1) = lastToken[0] = wxToupper(lastToken[0]);
}
wxString modifiedKeyCode;
for (int i = 0; i < (int)tokens.size(); i++)
{

View File

@ -865,6 +865,7 @@ void AcceleratorDictionary::Map(const KeyAcceleratorCode& _acode, const char* se
KeyAcceleratorCode acode = _acode;
wxString overrideStr;
wxAcceleratorEntry codeParser; //Provides string parsing capabilities
wxString ye = GetUiKeysFilename();
wxFileConfig cfg(L"", L"", L"", GetUiKeysFilename(), wxCONFIG_USE_GLOBAL_FILE);
if (cfg.Read(wxString::FromUTF8(searchfor), &overrideStr))
{
@ -1012,15 +1013,23 @@ void Pcsx2App::InitDefaultGlobalAccelerators()
GlobalAccels->Map(AAC(WXK_F4), "Framelimiter_MasterToggle");
GlobalAccels->Map(AAC(WXK_F4).Shift(), "Frameskip_Toggle");
/*GlobalAccels->Map( AAC( WXK_ESCAPE ), "Sys_Suspend");
GlobalAccels->Map( AAC( WXK_F8 ), "Sys_TakeSnapshot");
GlobalAccels->Map( AAC( WXK_F8 ).Shift(), "Sys_TakeSnapshot");
GlobalAccels->Map( AAC( WXK_F8 ).Shift().Cmd(),"Sys_TakeSnapshot");
GlobalAccels->Map( AAC( WXK_F9 ), "Sys_RenderswitchToggle");
// Doesn't read from the ini file at this point because `AppConfig::GetUiKeysFilename` is blank at this point!
// Used for custom hotkeys in the GUI.
// It will read from the PCSX2_keys.ini in the ini folder based on PCSX2_keys.ini.default which get overridden
GlobalAccels->Map(AAC(WXK_TAB), "Framelimiter_TurboToggle");
GlobalAccels->Map(AAC(WXK_TAB).Shift(), "Framelimiter_SlomoToggle");
GlobalAccels->Map( AAC( WXK_F10 ), "Sys_LoggingToggle");
GlobalAccels->Map( AAC( WXK_F11 ), "Sys_FreezeGS");
GlobalAccels->Map( AAC( WXK_F12 ), "Sys_RecordingToggle");
GlobalAccels->Map(AAC(WXK_F6), "GSwindow_CycleAspectRatio");
GlobalAccels->Map(AAC(WXK_RETURN).Alt(), "FullscreenToggle");
GlobalAccels->Map( AAC( WXK_RETURN ).Alt(), "FullscreenToggle" );*/
GlobalAccels->Map(AAC(WXK_ESCAPE), "Sys_SuspendResume");
GlobalAccels->Map(AAC( WXK_F8 ),"Sys_TakeSnapshot");
GlobalAccels->Map(AAC( WXK_F8 ).Shift(), "Sys_TakeSnapshot");
GlobalAccels->Map(AAC( WXK_F8 ).Shift().Cmd(),"Sys_TakeSnapshot");
GlobalAccels->Map(AAC( WXK_F9 ), "Sys_RenderswitchToggle");
// GlobalAccels->Map(AAC(WXK_F10), "Sys_LoggingToggle");
// GlobalAccels->Map(AAC(WXK_F11), "Sys_FreezeGS");
GlobalAccels->Map(AAC(WXK_F12), "Sys_RecordingToggle");
}

View File

@ -403,9 +403,12 @@ void MainEmuFrame::CreatePcsx2Menu()
m_GameSettingsSubmenu.Append(MenuId_Debug_CreateBlockdump, _("Create &Blockdump"), _("Creates a block dump for debugging purposes."), wxITEM_CHECK);
m_menuSys.AppendSeparator();
m_menuSys.Append(MenuId_Sys_LoadStates, _("&Load state"), &m_LoadStatesSubmenu);
m_menuSys.Append(MenuId_Sys_SaveStates, _("&Save state"), &m_SaveStatesSubmenu);
// Implement custom hotkeys (F3) with translatable string intact + not blank in GUI.
wxMenuItem* MainLoadStateLabel = m_menuSys.Append(MenuId_Sys_LoadStates, _("&Load state"), &m_LoadStatesSubmenu);
AppendShortcutToMenuOption(*MainLoadStateLabel, wxGetApp().GlobalAccels->findKeycodeWithCommandId("States_DefrostCurrentSlot").toTitleizedString());
// Implement custom hotkeys (F1) with translatable string intact + not blank in GUI.
wxMenuItem* MainSaveStateLabel = m_menuSys.Append(MenuId_Sys_SaveStates, _("&Save state"), &m_SaveStatesSubmenu);
AppendShortcutToMenuOption(*MainSaveStateLabel, wxGetApp().GlobalAccels->findKeycodeWithCommandId("States_FreezeCurrentSlot").toTitleizedString());
m_menuSys.Append(MenuId_EnableBackupStates, _("&Backup before save"), wxEmptyString, wxITEM_CHECK);
@ -475,11 +478,14 @@ void MainEmuFrame::CreateWindowsMenu()
void MainEmuFrame::CreateCaptureMenu()
{
m_menuCapture.Append(MenuId_Capture_Video, _("Video"), &m_submenuVideoCapture);
m_submenuVideoCapture.Append(MenuId_Capture_Video_Record, _("Start Screenrecorder"));
// Implement custom hotkeys (F12) with translatable string intact + not blank in GUI.
wxMenuItem* MainVideoCaptureLabel = m_submenuVideoCapture.Append(MenuId_Capture_Video_Record, _("Start Screenrecorder"));
AppendShortcutToMenuOption(*MainVideoCaptureLabel, wxGetApp().GlobalAccels->findKeycodeWithCommandId("Sys_RecordingToggle").toTitleizedString());
m_submenuVideoCapture.Append(MenuId_Capture_Video_Stop, _("Stop Screenrecorder"))->Enable(false);
// Implement custom hotkeys (F8) + (Shift + F8) + (Ctrl + Shift + F8) with translatable string intact + not blank in GUI.
m_menuCapture.Append(MenuId_Capture_Screenshot, _("Screenshot"), &m_submenuScreenshot);
m_submenuScreenshot.Append(MenuId_Capture_Screenshot_Screenshot, _("Screenshot"));
wxMenuItem* MainScreenShotLabel = m_submenuScreenshot.Append(MenuId_Capture_Screenshot_Screenshot, _("Take Screenshot"));
AppendShortcutToMenuOption(*MainScreenShotLabel, wxGetApp().GlobalAccels->findKeycodeWithCommandId("Sys_TakeSnapshot").toTitleizedString());
m_submenuScreenshot.Append(MenuId_Capture_Screenshot_Screenshot_As, _("Screenshot As..."));
}
@ -651,7 +657,6 @@ MainEmuFrame::MainEmuFrame(wxWindow* parent, const wxString& title)
ApplyCoreStatus();
ApplySettings();
AppendKeycodeNamesToMenuOptions();
}
MainEmuFrame::~MainEmuFrame()
@ -729,6 +734,8 @@ void MainEmuFrame::ApplyCoreStatus()
susres->SetHelp(_("No emulation state is active; cannot suspend or resume."));
}
}
// Re-init keybinding after changing the label
AppendShortcutToMenuOption(*susres, wxGetApp().GlobalAccels->findKeycodeWithCommandId("Sys_SuspendResume").toTitleizedString());
}
const CDVD_SourceType Source = g_Conf->CdvdSource;
@ -804,18 +811,15 @@ void MainEmuFrame::CommitPreset_noTrigger()
g_Conf->EmuOptions.EnablePatches = menubar.IsChecked(MenuId_EnablePatches);
}
static void AppendShortcutToMenuOption(wxMenuItem& item, wxString keyCodeStr)
void MainEmuFrame::AppendShortcutToMenuOption(wxMenuItem& item, wxString keyCodeStr)
{
wxString text = item.GetItemLabel();
const size_t tabPos = text.rfind(L'\t');
item.SetItemLabel(text.Mid(0, tabPos) + L"\t" + keyCodeStr);
}
void MainEmuFrame::AppendKeycodeNamesToMenuOptions()
{
AppendShortcutToMenuOption(*m_menuSys.FindChildItem(MenuId_Sys_LoadStates), wxGetApp().GlobalAccels->findKeycodeWithCommandId("States_DefrostCurrentSlot").toTitleizedString());
AppendShortcutToMenuOption(*m_menuSys.FindChildItem(MenuId_Sys_SaveStates), wxGetApp().GlobalAccels->findKeycodeWithCommandId("States_FreezeCurrentSlot").toTitleizedString());
if (&item == nullptr)
{
return;
}
wxString text = item.GetItemLabel();
const size_t tabPos = text.rfind(L'\t');
item.SetItemLabel(text.Mid(0, tabPos) + L"\t" + keyCodeStr);
}
#ifndef DISABLE_RECORDING

View File

@ -169,7 +169,7 @@ public:
void ApplyConfigToGui(AppConfig& configToApply, int flags = 0);
void CommitPreset_noTrigger();
void AppendKeycodeNamesToMenuOptions();
void AppendShortcutToMenuOption(wxMenuItem& item, wxString keyCodeStr);
void UpdateStatusBar();
#ifndef DISABLE_RECORDING
void initializeRecordingMenuItem(MenuIdentifiers menuId, wxString keyCodeStr, bool enable = true);

View File

@ -16,6 +16,10 @@
#include "PrecompiledHeader.h"
#include "ConfigurationPanels.h"
#include "fmt/core.h"
#include "App.h"
#include "AppAccelerators.h"
using namespace pxSizerFlags;
// --------------------------------------------------------------------------------------
@ -67,7 +71,8 @@ Panels::GSWindowSettingsPanel::GSWindowSettingsPanel( wxWindow* parent )
m_check_SizeLock = new pxCheckBox( this, _("Disable window resize border") );
m_check_HideMouse = new pxCheckBox( this, _("Always hide mouse cursor") );
m_check_CloseGS = new pxCheckBox( this, _("Hide window when paused") );
m_check_Fullscreen = new pxCheckBox( this, _("Default to fullscreen mode on open") );
// Implement custom hotkeys (Alt + Enter) with translatable string intact + not blank in GUI.
m_check_Fullscreen = new pxCheckBox( this, _("Start in fullscreen mode by default") + wxString(" (") + wxGetApp().GlobalAccels->findKeycodeWithCommandId("FullscreenToggle").toTitleizedString()+ wxString(")") );
m_check_DclickFullscreen = new pxCheckBox( this, _("Double-click toggles fullscreen mode") );
m_combo_FMVAspectRatioSwitch->SetToolTip( pxEt( L"Off: Disables temporary aspect ratio switch. (It will use the above setting from Aspect Ratio instead of FMV Aspect Ratio Override.)\n\n"
@ -108,7 +113,8 @@ Panels::GSWindowSettingsPanel::GSWindowSettingsPanel( wxWindow* parent )
//s_AspectRatio.AddGrowableCol( 0 );
s_AspectRatio.AddGrowableCol( 1 );
s_AspectRatio += Label(_("Aspect Ratio (F6):")) | pxMiddle;
// Implement custom hotkeys (F6) with translatable string intact + not blank in GUI.
s_AspectRatio += Label(_("Aspect Ratio:") + wxString(" ") + fmt::format("({})", wxGetApp().GlobalAccels->findKeycodeWithCommandId("GSwindow_CycleAspectRatio").toTitleizedString())) | pxMiddle;
s_AspectRatio += m_combo_AspectRatio | pxAlignRight;
s_AspectRatio += Label(_("FMV Aspect Ratio Override:")) | pxMiddle;
s_AspectRatio += m_combo_FMVAspectRatioSwitch | pxAlignRight;

View File

@ -15,10 +15,12 @@
#include "PrecompiledHeader.h"
#include "App.h"
#include "AppAccelerators.h"
#include "Dialogs/ConfigurationDialog.h"
#include "ConfigurationPanels.h"
#include <wx/spinctrl.h>
#include "fmt/core.h"
using namespace pxSizerFlags;
@ -29,8 +31,9 @@ using namespace pxSizerFlags;
Panels::FramelimiterPanel::FramelimiterPanel( wxWindow* parent )
: BaseApplicableConfigPanel_SpecificConfig( parent )
{
m_check_LimiterDisable = new pxCheckBox( this, _("Disable Framelimiting (F4)"),
_("Uncaps FPS. Useful for running benchmarks." ) );
// Implement custom hotkeys (F4) with translatable string intact + not blank in GUI.
m_check_LimiterDisable = new pxCheckBox( this, _("Disable Framelimiting") + wxString(" (") + wxGetApp().GlobalAccels->findKeycodeWithCommandId("Framelimiter_MasterToggle").toTitleizedString()+ wxString(")"),
_("Uncaps FPS. Useful for running benchmarks.") );
m_check_LimiterDisable->SetToolTip( pxEt( L"Note that when Framelimiting is disabled, Turbo and SlowMotion modes will not be available either."
) );
@ -60,17 +63,21 @@ Panels::FramelimiterPanel::FramelimiterPanel( wxWindow* parent )
s_spins += Label(L"%") | StdExpand();
s_spins += 5;
s_spins += Label(_("Slow Motion Adjust (Shift + Tab):")) | StdExpand();
// Implement custom hotkeys (Shift + Tab) with translatable string intact + not blank in GUI.
s_spins += Label(_("Slow Motion Adjust:") + wxString(" ") + fmt::format("({})", wxGetApp().GlobalAccels->findKeycodeWithCommandId("Framelimiter_SlomoToggle").toTitleizedString())) | StdExpand();
s_spins += 5;
s_spins += m_spin_SlomoPct | pxBorder(wxTOP, 3);
s_spins += Label(L"%") | StdExpand();
s_spins += 5;
s_spins += Label(_("Turbo Adjust (Tab):")) | StdExpand();
s_spins += 5;
s_spins += m_spin_TurboPct | pxBorder(wxTOP, 3);
s_spins += Label(L"%" ) | StdExpand();
s_spins += 5;
// Implement custom hotkeys (Tab) with translatable string intact + not blank in GUI.
s_spins += Label(_("Turbo Adjust:") + wxString(" ") + fmt::format("({})", wxGetApp().GlobalAccels->findKeycodeWithCommandId("Framelimiter_TurboToggle").toTitleizedString())) | StdExpand();
s_spins += 5;
s_spins += m_spin_TurboPct | pxBorder(wxTOP, 3);
s_spins += Label(L"%") | StdExpand();
s_spins += 5;
wxFlexGridSizer& s_fps( *new wxFlexGridSizer( 5 ) );
s_fps.AddGrowableCol( 0 );
@ -175,13 +182,13 @@ Panels::FrameSkipPanel::FrameSkipPanel( wxWindow* parent )
RadioPanelItem(
_("Disabled [default]")
),
// Implement custom hotkeys (Tab) with translatable string intact + not blank in GUI.
RadioPanelItem(
_("Skip when on Turbo only (TAB to enable)")
_("Skip only on Turbo, to enable press") + fmt::format("{} ({})", " ", wxGetApp().GlobalAccels->findKeycodeWithCommandId("Framelimiter_TurboToggle").toTitleizedString())
),
// Implement custom hotkeys (Shift + F4) with translatable string intact + not blank in GUI.
RadioPanelItem(
_("Constant skipping (Shift + F4)"),
_("Constant skipping") + fmt::format("{} ({})", " ", wxGetApp().GlobalAccels->findKeycodeWithCommandId("Frameskip_Toggle").toTitleizedString()),
wxEmptyString,
_("Normal and Turbo limit rates skip frames. Slow motion mode will still disable frameskipping.")
),