Qt/Core: Implement GBA Hotkeys

This commit is contained in:
Bonta 2021-07-04 13:26:47 +02:00
parent d6f86e1754
commit b73d16a71a
9 changed files with 193 additions and 8 deletions

View File

@ -23,7 +23,7 @@
#include "InputCommon/GCPadStatus.h"
// clang-format off
constexpr std::array<const char*, 126> s_hotkey_labels{{
constexpr std::array<const char*, NUM_HOTKEYS> s_hotkey_labels{{
_trans("Open"),
_trans("Change Disc"),
_trans("Eject Disc"),
@ -178,6 +178,19 @@ constexpr std::array<const char*, 126> s_hotkey_labels{{
_trans("Undo Save State"),
_trans("Save State"),
_trans("Load State"),
_trans("Load ROM"),
_trans("Unload ROM"),
_trans("Reset"),
_trans("Volume Down"),
_trans("Volume Up"),
_trans("Volume Toggle Mute"),
_trans("1x"),
_trans("2x"),
_trans("3x"),
_trans("4x"),
}};
// clang-format on
static_assert(NUM_HOTKEYS == s_hotkey_labels.size(), "Wrong count of hotkey_labels");
@ -195,10 +208,10 @@ InputConfig* GetConfig()
return &s_config;
}
void GetStatus()
void GetStatus(bool ignore_focus)
{
// Get input
static_cast<HotkeyManager*>(s_config.GetController(0))->GetInput(&s_hotkey);
static_cast<HotkeyManager*>(s_config.GetController(0))->GetInput(&s_hotkey, ignore_focus);
}
bool IsEnabled()
@ -307,6 +320,7 @@ struct HotkeyGroupInfo
const char* name;
Hotkey first;
Hotkey last;
bool ignore_focus = false;
};
constexpr std::array<HotkeyGroupInfo, NUM_HOTKEY_GROUPS> s_groups_info = {
@ -334,7 +348,10 @@ constexpr std::array<HotkeyGroupInfo, NUM_HOTKEY_GROUPS> s_groups_info = {
{_trans("Save State"), HK_SAVE_STATE_SLOT_1, HK_SAVE_STATE_SLOT_SELECTED},
{_trans("Select State"), HK_SELECT_STATE_SLOT_1, HK_SELECT_STATE_SLOT_10},
{_trans("Load Last State"), HK_LOAD_LAST_STATE_1, HK_LOAD_LAST_STATE_10},
{_trans("Other State Hotkeys"), HK_SAVE_FIRST_STATE, HK_LOAD_STATE_FILE}}};
{_trans("Other State Hotkeys"), HK_SAVE_FIRST_STATE, HK_LOAD_STATE_FILE},
{_trans("GBA Core"), HK_GBA_LOAD, HK_GBA_RESET, true},
{_trans("GBA Volume"), HK_GBA_VOLUME_DOWN, HK_GBA_TOGGLE_MUTE, true},
{_trans("GBA Window Size"), HK_GBA_1X, HK_GBA_4X, true}}};
HotkeyManager::HotkeyManager()
{
@ -359,11 +376,14 @@ std::string HotkeyManager::GetName() const
return "Hotkeys";
}
void HotkeyManager::GetInput(HotkeyStatus* const kb)
void HotkeyManager::GetInput(HotkeyStatus* kb, bool ignore_focus)
{
const auto lock = GetStateLock();
for (std::size_t group = 0; group < s_groups_info.size(); group++)
{
if (s_groups_info[group].ignore_focus != ignore_focus)
continue;
const int group_count = (s_groups_info[group].last - s_groups_info[group].first) + 1;
std::vector<u32> bitmasks(group_count);
for (size_t key = 0; key < bitmasks.size(); key++)
@ -441,4 +461,30 @@ void HotkeyManager::LoadDefaults(const ControllerInterface& ciface)
}
set_key_expression(HK_UNDO_LOAD_STATE, "F12");
set_key_expression(HK_UNDO_SAVE_STATE, hotkey_string({"Shift", "F12"}));
// GBA
set_key_expression(HK_GBA_LOAD, hotkey_string({"`Shift`", "`O`"}));
set_key_expression(HK_GBA_UNLOAD, hotkey_string({"`Shift`", "`W`"}));
set_key_expression(HK_GBA_RESET, hotkey_string({"`Shift`", "`R`"}));
#ifdef _WIN32
set_key_expression(HK_GBA_VOLUME_DOWN, "`SUBTRACT`");
set_key_expression(HK_GBA_VOLUME_UP, "`ADD`");
#else
set_key_expression(HK_GBA_VOLUME_DOWN, "`KP_Subtract`");
set_key_expression(HK_GBA_VOLUME_UP, "`KP_Add`");
#endif
set_key_expression(HK_GBA_TOGGLE_MUTE, "`M`");
#ifdef _WIN32
set_key_expression(HK_GBA_1X, "`NUMPAD1`");
set_key_expression(HK_GBA_2X, "`NUMPAD2`");
set_key_expression(HK_GBA_3X, "`NUMPAD3`");
set_key_expression(HK_GBA_4X, "`NUMPAD4`");
#else
set_key_expression(HK_GBA_1X, "`KP_1`");
set_key_expression(HK_GBA_2X, "`KP_2`");
set_key_expression(HK_GBA_3X, "`KP_3`");
set_key_expression(HK_GBA_4X, "`KP_4`");
#endif
}

View File

@ -164,6 +164,19 @@ enum Hotkey
HK_SAVE_STATE_FILE,
HK_LOAD_STATE_FILE,
HK_GBA_LOAD,
HK_GBA_UNLOAD,
HK_GBA_RESET,
HK_GBA_VOLUME_DOWN,
HK_GBA_VOLUME_UP,
HK_GBA_TOGGLE_MUTE,
HK_GBA_1X,
HK_GBA_2X,
HK_GBA_3X,
HK_GBA_4X,
NUM_HOTKEYS,
};
@ -192,6 +205,9 @@ enum HotkeyGroup : int
HKGP_SELECT_STATE,
HKGP_LOAD_LAST_STATE,
HKGP_STATE_MISC,
HKGP_GBA_CORE,
HKGP_GBA_VOLUME,
HKGP_GBA_SIZE,
NUM_HOTKEY_GROUPS,
};
@ -208,7 +224,7 @@ public:
HotkeyManager();
~HotkeyManager();
void GetInput(HotkeyStatus* const hk);
void GetInput(HotkeyStatus* hk, bool ignore_focus);
std::string GetName() const override;
ControllerEmu::ControlGroup* GetHotkeyGroup(HotkeyGroup group) const;
int FindGroupByID(int id) const;
@ -228,7 +244,7 @@ void LoadConfig();
InputConfig* GetConfig();
ControllerEmu::ControlGroup* GetHotkeyGroup(HotkeyGroup group);
void GetStatus();
void GetStatus(bool ignore_focus);
bool IsEnabled();
void Enable(bool enable_toggle);
bool IsPressed(int Id, bool held);

View File

@ -140,6 +140,8 @@ add_executable(dolphin-emu
Config/Mapping/HotkeyControllerProfile.h
Config/Mapping/HotkeyDebugging.cpp
Config/Mapping/HotkeyDebugging.h
Config/Mapping/HotkeyGBA.cpp
Config/Mapping/HotkeyGBA.h
Config/Mapping/HotkeyGeneral.cpp
Config/Mapping/HotkeyGeneral.h
Config/Mapping/HotkeyGraphics.cpp

View File

@ -0,0 +1,43 @@
// Copyright 2021 Dolphin Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include "DolphinQt/Config/Mapping/HotkeyGBA.h"
#include <QGroupBox>
#include <QHBoxLayout>
#include "Core/HotkeyManager.h"
HotkeyGBA::HotkeyGBA(MappingWindow* window) : MappingWidget(window)
{
CreateMainLayout();
}
void HotkeyGBA::CreateMainLayout()
{
m_main_layout = new QHBoxLayout();
m_main_layout->addWidget(
CreateGroupBox(tr("Core"), HotkeyManagerEmu::GetHotkeyGroup(HKGP_GBA_CORE)));
m_main_layout->addWidget(
CreateGroupBox(tr("Volume"), HotkeyManagerEmu::GetHotkeyGroup(HKGP_GBA_VOLUME)));
m_main_layout->addWidget(
CreateGroupBox(tr("Window Size"), HotkeyManagerEmu::GetHotkeyGroup(HKGP_GBA_SIZE)));
setLayout(m_main_layout);
}
InputConfig* HotkeyGBA::GetConfig()
{
return HotkeyManagerEmu::GetConfig();
}
void HotkeyGBA::LoadSettings()
{
HotkeyManagerEmu::LoadConfig();
}
void HotkeyGBA::SaveSettings()
{
HotkeyManagerEmu::GetConfig()->SaveConfig();
}

View File

@ -0,0 +1,25 @@
// Copyright 2021 Dolphin Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include "DolphinQt/Config/Mapping/MappingWidget.h"
class QHBoxLayout;
class HotkeyGBA final : public MappingWidget
{
Q_OBJECT
public:
explicit HotkeyGBA(MappingWindow* window);
InputConfig* GetConfig() override;
private:
void LoadSettings() override;
void SaveSettings() override;
void CreateMainLayout();
// Main
QHBoxLayout* m_main_layout;
};

View File

@ -30,6 +30,7 @@
#include "DolphinQt/Config/Mapping/Hotkey3D.h"
#include "DolphinQt/Config/Mapping/HotkeyControllerProfile.h"
#include "DolphinQt/Config/Mapping/HotkeyDebugging.h"
#include "DolphinQt/Config/Mapping/HotkeyGBA.h"
#include "DolphinQt/Config/Mapping/HotkeyGeneral.h"
#include "DolphinQt/Config/Mapping/HotkeyGraphics.h"
#include "DolphinQt/Config/Mapping/HotkeyStates.h"
@ -435,6 +436,7 @@ void MappingWindow::SetMappingType(MappingWindow::Type type)
AddWidget(tr("3D"), new Hotkey3D(this));
AddWidget(tr("Save and Load State"), new HotkeyStates(this));
AddWidget(tr("Other State Management"), new HotkeyStatesOther(this));
AddWidget(tr("GameBoy Advance"), new HotkeyGBA(this));
setWindowTitle(tr("Hotkey Settings"));
break;
}

View File

@ -90,6 +90,7 @@
<ClCompile Include="Config\Mapping\HotkeyControllerProfile.cpp" />
<ClCompile Include="Config\Mapping\HotkeyDebugging.cpp" />
<ClCompile Include="Config\Mapping\HotkeyGeneral.cpp" />
<ClCompile Include="Config\Mapping\HotkeyGBA.cpp" />
<ClCompile Include="Config\Mapping\HotkeyGraphics.cpp" />
<ClCompile Include="Config\Mapping\HotkeyStates.cpp" />
<ClCompile Include="Config\Mapping\HotkeyStatesOther.cpp" />
@ -268,6 +269,7 @@
<QtMoc Include="Config\Mapping\Hotkey3D.h" />
<QtMoc Include="Config\Mapping\HotkeyControllerProfile.h" />
<QtMoc Include="Config\Mapping\HotkeyDebugging.h" />
<QtMoc Include="Config\Mapping\HotkeyGBA.h" />
<QtMoc Include="Config\Mapping\HotkeyGeneral.h" />
<QtMoc Include="Config\Mapping\HotkeyGraphics.h" />
<QtMoc Include="Config\Mapping\HotkeyStates.h" />

View File

@ -7,6 +7,7 @@
#include <cmath>
#include <thread>
#include <QApplication>
#include <QCoreApplication>
#include "AudioCommon/AudioCommon.h"
@ -28,6 +29,10 @@
#include "Core/State.h"
#include "Core/WiiUtils.h"
#ifdef HAS_LIBMGBA
#include "DolphinQt/GBAWidget.h"
#endif
#include "DolphinQt/QtUtils/QueueOnObject.h"
#include "DolphinQt/Settings.h"
#include "InputCommon/ControlReference/ControlReference.h"
@ -157,11 +162,13 @@ void HotkeyScheduler::Run()
// Obey window focus (config permitting) before checking hotkeys.
Core::UpdateInputGate(Config::Get(Config::MAIN_FOCUSED_HOTKEYS));
HotkeyManagerEmu::GetStatus();
HotkeyManagerEmu::GetStatus(false);
// Everything else on the host thread (controller config dialog) should always get input.
ControlReference::SetInputGate(true);
HotkeyManagerEmu::GetStatus(true);
if (!Core::IsRunningAndStarted())
continue;
@ -520,6 +527,8 @@ void HotkeyScheduler::Run()
Config::SetCurrent(Config::GFX_ENHANCE_POST_SHADER, "");
}
}
CheckGBAHotkeys();
}
const auto stereo_depth = Config::Get(Config::GFX_STEREO_DEPTH);
@ -607,3 +616,42 @@ void HotkeyScheduler::CheckDebuggingHotkeys()
if (IsHotkey(HK_BP_ADD))
emit AddBreakpoint();
}
void HotkeyScheduler::CheckGBAHotkeys()
{
#ifdef HAS_LIBMGBA
GBAWidget* gba_widget = qobject_cast<GBAWidget*>(QApplication::activeWindow());
if (!gba_widget)
return;
if (IsHotkey(HK_GBA_LOAD))
QueueOnObject(gba_widget, [gba_widget] { gba_widget->LoadROM(); });
if (IsHotkey(HK_GBA_UNLOAD))
QueueOnObject(gba_widget, [gba_widget] { gba_widget->UnloadROM(); });
if (IsHotkey(HK_GBA_RESET))
QueueOnObject(gba_widget, [gba_widget] { gba_widget->ResetCore(); });
if (IsHotkey(HK_GBA_VOLUME_DOWN))
QueueOnObject(gba_widget, [gba_widget] { gba_widget->VolumeDown(); });
if (IsHotkey(HK_GBA_VOLUME_UP))
QueueOnObject(gba_widget, [gba_widget] { gba_widget->VolumeUp(); });
if (IsHotkey(HK_GBA_TOGGLE_MUTE))
QueueOnObject(gba_widget, [gba_widget] { gba_widget->ToggleMute(); });
if (IsHotkey(HK_GBA_1X))
QueueOnObject(gba_widget, [gba_widget] { gba_widget->Resize(1); });
if (IsHotkey(HK_GBA_2X))
QueueOnObject(gba_widget, [gba_widget] { gba_widget->Resize(2); });
if (IsHotkey(HK_GBA_3X))
QueueOnObject(gba_widget, [gba_widget] { gba_widget->Resize(3); });
if (IsHotkey(HK_GBA_4X))
QueueOnObject(gba_widget, [gba_widget] { gba_widget->Resize(4); });
#endif
}

View File

@ -65,6 +65,7 @@ signals:
private:
void Run();
void CheckDebuggingHotkeys();
void CheckGBAHotkeys();
Common::Flag m_stop_requested;
std::thread m_thread;