diff --git a/Source/Core/Core/HW/GCKeyboard.cpp b/Source/Core/Core/HW/GCKeyboard.cpp index e01b2eb6a9..0f5014c3a3 100644 --- a/Source/Core/Core/HW/GCKeyboard.cpp +++ b/Source/Core/Core/HW/GCKeyboard.cpp @@ -44,6 +44,11 @@ void LoadConfig() s_config.LoadConfig(true); } +ControllerEmu::ControlGroup* GetGroup(int port, KeyboardGroup group) +{ + return static_cast(s_config.GetController(port))->GetGroup(group); +} + KeyboardStatus GetStatus(int port) { return static_cast(s_config.GetController(port))->GetInput(); diff --git a/Source/Core/Core/HW/GCKeyboard.h b/Source/Core/Core/HW/GCKeyboard.h index 0547dcfa2f..6f254a9a85 100644 --- a/Source/Core/Core/HW/GCKeyboard.h +++ b/Source/Core/Core/HW/GCKeyboard.h @@ -5,8 +5,10 @@ #pragma once #include "Common/CommonTypes.h" +#include "InputCommon/ControllerEmu.h" class InputConfig; +enum class KeyboardGroup; struct KeyboardStatus; namespace Keyboard @@ -16,6 +18,7 @@ void Initialize(); void LoadConfig(); InputConfig* GetConfig(); +ControllerEmu::ControlGroup* GetGroup(int port, KeyboardGroup group); KeyboardStatus GetStatus(int port); } diff --git a/Source/Core/Core/HW/GCKeyboardEmu.cpp b/Source/Core/Core/HW/GCKeyboardEmu.cpp index ddf36d9350..f31dca91ca 100644 --- a/Source/Core/Core/HW/GCKeyboardEmu.cpp +++ b/Source/Core/Core/HW/GCKeyboardEmu.cpp @@ -4,6 +4,7 @@ #include "Core/HW/GCKeyboardEmu.h" #include "Common/Common.h" +#include "InputCommon/ControllerEmu.h" #include "InputCommon/KeyboardStatus.h" static const u16 keys0_bitmasks[] = {KEYMASK_HOME, KEYMASK_END, KEYMASK_PGUP, KEYMASK_PGDN, @@ -84,6 +85,29 @@ std::string GCKeyboard::GetName() const return std::string("GCKeyboard") + char('1' + m_index); } +ControllerEmu::ControlGroup* GCKeyboard::GetGroup(KeyboardGroup group) +{ + switch (group) + { + case KeyboardGroup::Kb0x: + return m_keys0x; + case KeyboardGroup::Kb1x: + return m_keys1x; + case KeyboardGroup::Kb2x: + return m_keys2x; + case KeyboardGroup::Kb3x: + return m_keys3x; + case KeyboardGroup::Kb4x: + return m_keys4x; + case KeyboardGroup::Kb5x: + return m_keys5x; + case KeyboardGroup::Options: + return m_options; + default: + return nullptr; + } +} + KeyboardStatus GCKeyboard::GetInput() const { auto lock = ControllerEmu::GetStateLock(); diff --git a/Source/Core/Core/HW/GCKeyboardEmu.h b/Source/Core/Core/HW/GCKeyboardEmu.h index 48451f3be2..6f48b465e3 100644 --- a/Source/Core/Core/HW/GCKeyboardEmu.h +++ b/Source/Core/Core/HW/GCKeyboardEmu.h @@ -10,12 +10,25 @@ struct KeyboardStatus; +enum class KeyboardGroup +{ + Kb0x, + Kb1x, + Kb2x, + Kb3x, + Kb4x, + Kb5x, + + Options +}; + class GCKeyboard : public ControllerEmu { public: GCKeyboard(const unsigned int index); KeyboardStatus GetInput() const; std::string GetName() const override; + ControlGroup* GetGroup(KeyboardGroup group); void LoadDefaults(const ControllerInterface& ciface) override; private: diff --git a/Source/Core/Core/HW/GCPad.cpp b/Source/Core/Core/HW/GCPad.cpp index 034d546557..6cb163780a 100644 --- a/Source/Core/Core/HW/GCPad.cpp +++ b/Source/Core/Core/HW/GCPad.cpp @@ -5,7 +5,6 @@ #include #include "Common/Common.h" -#include "Common/CommonTypes.h" #include "Core/HW/GCPad.h" #include "Core/HW/GCPadEmu.h" #include "InputCommon/GCPadStatus.h" @@ -48,6 +47,11 @@ GCPadStatus GetStatus(int pad_num) return static_cast(s_config.GetController(pad_num))->GetInput(); } +ControllerEmu::ControlGroup* GetGroup(int pad_num, PadGroup group) +{ + return static_cast(s_config.GetController(pad_num))->GetGroup(group); +} + void Rumble(const int pad_num, const ControlState strength) { static_cast(s_config.GetController(pad_num))->SetOutput(strength); diff --git a/Source/Core/Core/HW/GCPad.h b/Source/Core/Core/HW/GCPad.h index fab5609e0d..b330f44170 100644 --- a/Source/Core/Core/HW/GCPad.h +++ b/Source/Core/Core/HW/GCPad.h @@ -5,9 +5,11 @@ #pragma once #include "Common/CommonTypes.h" +#include "InputCommon/ControllerEmu.h" #include "InputCommon/ControllerInterface/Device.h" class InputConfig; +enum class PadGroup; struct GCPadStatus; namespace Pad @@ -19,6 +21,7 @@ void LoadConfig(); InputConfig* GetConfig(); GCPadStatus GetStatus(int pad_num); +ControllerEmu::ControlGroup* GetGroup(int pad_num, PadGroup group); void Rumble(int pad_num, ControlState strength); bool GetMicButton(int pad_num); diff --git a/Source/Core/Core/HW/GCPadEmu.cpp b/Source/Core/Core/HW/GCPadEmu.cpp index 7863fe0d74..7a533c3762 100644 --- a/Source/Core/Core/HW/GCPadEmu.cpp +++ b/Source/Core/Core/HW/GCPadEmu.cpp @@ -79,6 +79,29 @@ std::string GCPad::GetName() const return std::string("GCPad") + char('1' + m_index); } +ControllerEmu::ControlGroup* GCPad::GetGroup(PadGroup group) +{ + switch (group) + { + case PadGroup::Buttons: + return m_buttons; + case PadGroup::MainStick: + return m_main_stick; + case PadGroup::CStick: + return m_c_stick; + case PadGroup::DPad: + return m_dpad; + case PadGroup::Triggers: + return m_triggers; + case PadGroup::Rumble: + return m_rumble; + case PadGroup::Options: + return m_options; + default: + return nullptr; + } +} + GCPadStatus GCPad::GetInput() const { auto lock = ControllerEmu::GetStateLock(); diff --git a/Source/Core/Core/HW/GCPadEmu.h b/Source/Core/Core/HW/GCPadEmu.h index b407f7a81d..8969ef6333 100644 --- a/Source/Core/Core/HW/GCPadEmu.h +++ b/Source/Core/Core/HW/GCPadEmu.h @@ -8,6 +8,19 @@ #include "InputCommon/ControllerEmu.h" +class ControlGroup; + +enum class PadGroup +{ + Buttons, + MainStick, + CStick, + DPad, + Triggers, + Rumble, + Options +}; + class GCPad : public ControllerEmu { public: @@ -19,6 +32,8 @@ public: std::string GetName() const override; + ControlGroup* GetGroup(PadGroup group); + void LoadDefaults(const ControllerInterface& ciface) override; private: diff --git a/Source/Core/Core/HW/Wiimote.cpp b/Source/Core/Core/HW/Wiimote.cpp index 4611da4c15..03590ea48c 100644 --- a/Source/Core/Core/HW/Wiimote.cpp +++ b/Source/Core/Core/HW/Wiimote.cpp @@ -19,6 +19,37 @@ InputConfig* GetConfig() return &s_config; } +ControllerEmu::ControlGroup* GetWiimoteGroup(int number, WiimoteEmu::WiimoteGroup group) +{ + return static_cast(s_config.GetController(number))->GetWiimoteGroup(group); +} + +ControllerEmu::ControlGroup* GetNunchukGroup(int number, WiimoteEmu::NunchukGroup group) +{ + return static_cast(s_config.GetController(number))->GetNunchukGroup(group); +} + +ControllerEmu::ControlGroup* GetClassicGroup(int number, WiimoteEmu::ClassicGroup group) +{ + return static_cast(s_config.GetController(number))->GetClassicGroup(group); +} + +ControllerEmu::ControlGroup* GetGuitarGroup(int number, WiimoteEmu::GuitarGroup group) +{ + return static_cast(s_config.GetController(number))->GetGuitarGroup(group); +} + +ControllerEmu::ControlGroup* GetDrumsGroup(int number, WiimoteEmu::DrumsGroup group) +{ + return static_cast(s_config.GetController(number))->GetDrumsGroup(group); +} + +ControllerEmu::ControlGroup* GetTurntableGroup(int number, WiimoteEmu::TurntableGroup group) +{ + return static_cast(s_config.GetController(number)) + ->GetTurntableGroup(group); +} + void Shutdown() { s_config.ClearControllers(); diff --git a/Source/Core/Core/HW/Wiimote.h b/Source/Core/Core/HW/Wiimote.h index 9dee32ffb7..3f1dd1db06 100644 --- a/Source/Core/Core/HW/Wiimote.h +++ b/Source/Core/Core/HW/Wiimote.h @@ -6,9 +6,19 @@ #include "Common/Common.h" #include "Common/CommonTypes.h" +#include "InputCommon/ControllerEmu.h" class InputConfig; class PointerWrap; +namespace WiimoteEmu +{ +enum class WiimoteGroup; +enum class NunchukGroup; +enum class ClassicGroup; +enum class GuitarGroup; +enum class DrumsGroup; +enum class TurntableGroup; +} enum { @@ -52,6 +62,12 @@ unsigned int GetAttached(); void DoState(PointerWrap& p); void EmuStateChange(EMUSTATE_CHANGE newState); InputConfig* GetConfig(); +ControllerEmu::ControlGroup* GetWiimoteGroup(int number, WiimoteEmu::WiimoteGroup group); +ControllerEmu::ControlGroup* GetNunchukGroup(int number, WiimoteEmu::NunchukGroup group); +ControllerEmu::ControlGroup* GetClassicGroup(int number, WiimoteEmu::ClassicGroup group); +ControllerEmu::ControlGroup* GetGuitarGroup(int number, WiimoteEmu::GuitarGroup group); +ControllerEmu::ControlGroup* GetDrumsGroup(int number, WiimoteEmu::DrumsGroup group); +ControllerEmu::ControlGroup* GetTurntableGroup(int number, WiimoteEmu::TurntableGroup group); void ControlChannel(int _number, u16 _channelID, const void* _pData, u32 _Size); void InterruptChannel(int _number, u16 _channelID, const void* _pData, u32 _Size); diff --git a/Source/Core/Core/HW/WiimoteEmu/Attachment/Classic.cpp b/Source/Core/Core/HW/WiimoteEmu/Attachment/Classic.cpp index f3577937c6..4197322d24 100644 --- a/Source/Core/Core/HW/WiimoteEmu/Attachment/Classic.cpp +++ b/Source/Core/Core/HW/WiimoteEmu/Attachment/Classic.cpp @@ -2,6 +2,7 @@ // Licensed under GPLv2+ // Refer to the license.txt file included. +#include #include #include "Common/Common.h" @@ -134,4 +135,24 @@ bool Classic::IsButtonPressed() const m_triggers->GetState(&buttons, classic_trigger_bitmasks, trigs); return buttons != 0; } + +ControllerEmu::ControlGroup* Classic::GetGroup(ClassicGroup group) +{ + switch (group) + { + case ClassicGroup::Buttons: + return m_buttons; + case ClassicGroup::Triggers: + return m_triggers; + case ClassicGroup::DPad: + return m_dpad; + case ClassicGroup::LeftStick: + return m_left_stick; + case ClassicGroup::RightStick: + return m_right_stick; + default: + assert(false); + return nullptr; + } +} } diff --git a/Source/Core/Core/HW/WiimoteEmu/Attachment/Classic.h b/Source/Core/Core/HW/WiimoteEmu/Attachment/Classic.h index 0ab968bdcc..4d46c9f9cb 100644 --- a/Source/Core/Core/HW/WiimoteEmu/Attachment/Classic.h +++ b/Source/Core/Core/HW/WiimoteEmu/Attachment/Classic.h @@ -8,6 +8,7 @@ namespace WiimoteEmu { +enum class ClassicGroup; struct ExtensionReg; class Classic : public Attachment @@ -17,6 +18,8 @@ public: void GetState(u8* const data) override; bool IsButtonPressed() const override; + ControlGroup* GetGroup(ClassicGroup group); + enum { PAD_RIGHT = 0x80, diff --git a/Source/Core/Core/HW/WiimoteEmu/Attachment/Drums.cpp b/Source/Core/Core/HW/WiimoteEmu/Attachment/Drums.cpp index 46888214d1..6fd871b89a 100644 --- a/Source/Core/Core/HW/WiimoteEmu/Attachment/Drums.cpp +++ b/Source/Core/Core/HW/WiimoteEmu/Attachment/Drums.cpp @@ -2,6 +2,7 @@ // Licensed under GPLv2+ // Refer to the license.txt file included. +#include #include #include "Common/Common.h" @@ -81,4 +82,20 @@ bool Drums::IsButtonPressed() const m_pads->GetState(&buttons, drum_pad_bitmasks); return buttons != 0; } + +ControllerEmu::ControlGroup* Drums::GetGroup(DrumsGroup group) +{ + switch (group) + { + case DrumsGroup::Buttons: + return m_buttons; + case DrumsGroup::Pads: + return m_pads; + case DrumsGroup::Stick: + return m_stick; + default: + assert(false); + return nullptr; + } +} } diff --git a/Source/Core/Core/HW/WiimoteEmu/Attachment/Drums.h b/Source/Core/Core/HW/WiimoteEmu/Attachment/Drums.h index 36d22883a0..a01827b2ea 100644 --- a/Source/Core/Core/HW/WiimoteEmu/Attachment/Drums.h +++ b/Source/Core/Core/HW/WiimoteEmu/Attachment/Drums.h @@ -8,6 +8,7 @@ namespace WiimoteEmu { +enum class DrumsGroup; struct ExtensionReg; class Drums : public Attachment @@ -17,6 +18,8 @@ public: void GetState(u8* const data) override; bool IsButtonPressed() const override; + ControlGroup* GetGroup(DrumsGroup group); + enum { BUTTON_PLUS = 0x04, diff --git a/Source/Core/Core/HW/WiimoteEmu/Attachment/Guitar.cpp b/Source/Core/Core/HW/WiimoteEmu/Attachment/Guitar.cpp index aac7f5e325..04a949c23f 100644 --- a/Source/Core/Core/HW/WiimoteEmu/Attachment/Guitar.cpp +++ b/Source/Core/Core/HW/WiimoteEmu/Attachment/Guitar.cpp @@ -2,6 +2,7 @@ // Licensed under GPLv2+ // Refer to the license.txt file included. +#include #include #include "Common/Common.h" @@ -102,4 +103,24 @@ bool Guitar::IsButtonPressed() const m_strum->GetState(&buttons, guitar_strum_bitmasks); return buttons != 0; } + +ControllerEmu::ControlGroup* Guitar::GetGroup(GuitarGroup group) +{ + switch (group) + { + case GuitarGroup::Buttons: + return m_buttons; + case GuitarGroup::Frets: + return m_frets; + case GuitarGroup::Strum: + return m_strum; + case GuitarGroup::Whammy: + return m_whammy; + case GuitarGroup::Stick: + return m_stick; + default: + assert(false); + return nullptr; + } +} } diff --git a/Source/Core/Core/HW/WiimoteEmu/Attachment/Guitar.h b/Source/Core/Core/HW/WiimoteEmu/Attachment/Guitar.h index 9d9a4d4130..6076e8ebc4 100644 --- a/Source/Core/Core/HW/WiimoteEmu/Attachment/Guitar.h +++ b/Source/Core/Core/HW/WiimoteEmu/Attachment/Guitar.h @@ -8,6 +8,7 @@ namespace WiimoteEmu { +enum class GuitarGroup; struct ExtensionReg; class Guitar : public Attachment @@ -17,6 +18,8 @@ public: void GetState(u8* const data) override; bool IsButtonPressed() const override; + ControlGroup* GetGroup(GuitarGroup group); + enum { BUTTON_PLUS = 0x04, diff --git a/Source/Core/Core/HW/WiimoteEmu/Attachment/Nunchuk.cpp b/Source/Core/Core/HW/WiimoteEmu/Attachment/Nunchuk.cpp index 91a27ed99d..527e2cbd6a 100644 --- a/Source/Core/Core/HW/WiimoteEmu/Attachment/Nunchuk.cpp +++ b/Source/Core/Core/HW/WiimoteEmu/Attachment/Nunchuk.cpp @@ -2,6 +2,7 @@ // Licensed under GPLv2+ // Refer to the license.txt file included. +#include #include #include "Common/Common.h" @@ -114,6 +115,26 @@ bool Nunchuk::IsButtonPressed() const return buttons != 0; } +ControllerEmu::ControlGroup* Nunchuk::GetGroup(NunchukGroup group) +{ + switch (group) + { + case NunchukGroup::Buttons: + return m_buttons; + case NunchukGroup::Stick: + return m_stick; + case NunchukGroup::Tilt: + return m_tilt; + case NunchukGroup::Swing: + return m_swing; + case NunchukGroup::Shake: + return m_shake; + default: + assert(false); + return nullptr; + } +} + void Nunchuk::LoadDefaults(const ControllerInterface& ciface) { // Stick diff --git a/Source/Core/Core/HW/WiimoteEmu/Attachment/Nunchuk.h b/Source/Core/Core/HW/WiimoteEmu/Attachment/Nunchuk.h index 236163eecb..f9e904466e 100644 --- a/Source/Core/Core/HW/WiimoteEmu/Attachment/Nunchuk.h +++ b/Source/Core/Core/HW/WiimoteEmu/Attachment/Nunchuk.h @@ -8,6 +8,7 @@ namespace WiimoteEmu { +enum class NunchukGroup; struct ExtensionReg; class Nunchuk : public Attachment @@ -18,6 +19,8 @@ public: void GetState(u8* const data) override; bool IsButtonPressed() const override; + ControlGroup* GetGroup(NunchukGroup group); + enum { BUTTON_C = 0x02, diff --git a/Source/Core/Core/HW/WiimoteEmu/Attachment/Turntable.cpp b/Source/Core/Core/HW/WiimoteEmu/Attachment/Turntable.cpp index ed0678951d..3fcf8e7f15 100644 --- a/Source/Core/Core/HW/WiimoteEmu/Attachment/Turntable.cpp +++ b/Source/Core/Core/HW/WiimoteEmu/Attachment/Turntable.cpp @@ -2,6 +2,7 @@ // Licensed under GPLv2+ // Refer to the license.txt file included. +#include #include #include "Common/Common.h" @@ -131,4 +132,26 @@ bool Turntable::IsButtonPressed() const m_buttons->GetState(&buttons, turntable_button_bitmasks); return buttons != 0; } + +ControllerEmu::ControlGroup* Turntable::GetGroup(TurntableGroup group) +{ + switch (group) + { + case TurntableGroup::Buttons: + return m_buttons; + case TurntableGroup::Stick: + return m_stick; + case TurntableGroup::EffectDial: + return m_effect_dial; + case TurntableGroup::LeftTable: + return m_left_table; + case TurntableGroup::RightTable: + return m_right_table; + case TurntableGroup::Crossfade: + return m_crossfade; + default: + assert(false); + return nullptr; + } +} } diff --git a/Source/Core/Core/HW/WiimoteEmu/Attachment/Turntable.h b/Source/Core/Core/HW/WiimoteEmu/Attachment/Turntable.h index ed037e5f28..cf085fb8b6 100644 --- a/Source/Core/Core/HW/WiimoteEmu/Attachment/Turntable.h +++ b/Source/Core/Core/HW/WiimoteEmu/Attachment/Turntable.h @@ -8,6 +8,7 @@ namespace WiimoteEmu { +enum class TurntableGroup; struct ExtensionReg; class Turntable : public Attachment @@ -17,6 +18,8 @@ public: void GetState(u8* const data) override; bool IsButtonPressed() const override; + ControlGroup* GetGroup(TurntableGroup group); + enum { BUTTON_EUPHORIA = 0x1000, diff --git a/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.cpp b/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.cpp index 69a3a7341e..6fa9ab5802 100644 --- a/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.cpp +++ b/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.cpp @@ -2,6 +2,7 @@ // Licensed under GPLv2+ // Refer to the license.txt file included. +#include #include #include @@ -315,6 +316,61 @@ std::string Wiimote::GetName() const return std::string("Wiimote") + char('1' + m_index); } +ControllerEmu::ControlGroup* Wiimote::GetWiimoteGroup(WiimoteGroup group) +{ + switch (group) + { + case WiimoteGroup::Buttons: + return m_buttons; + case WiimoteGroup::DPad: + return m_dpad; + case WiimoteGroup::Shake: + return m_shake; + case WiimoteGroup::IR: + return m_ir; + case WiimoteGroup::Tilt: + return m_tilt; + case WiimoteGroup::Swing: + return m_swing; + case WiimoteGroup::Rumble: + return m_rumble; + case WiimoteGroup::Extension: + return m_extension; + case WiimoteGroup::Options: + return m_options; + case WiimoteGroup::Hotkeys: + return m_hotkeys; + default: + assert(false); + return nullptr; + } +} + +ControllerEmu::ControlGroup* Wiimote::GetNunchukGroup(NunchukGroup group) +{ + return static_cast(m_extension->attachments[EXT_NUNCHUK].get())->GetGroup(group); +} + +ControllerEmu::ControlGroup* Wiimote::GetClassicGroup(ClassicGroup group) +{ + return static_cast(m_extension->attachments[EXT_CLASSIC].get())->GetGroup(group); +} + +ControllerEmu::ControlGroup* Wiimote::GetGuitarGroup(GuitarGroup group) +{ + return static_cast(m_extension->attachments[EXT_GUITAR].get())->GetGroup(group); +} + +ControllerEmu::ControlGroup* Wiimote::GetDrumsGroup(DrumsGroup group) +{ + return static_cast(m_extension->attachments[EXT_DRUMS].get())->GetGroup(group); +} + +ControllerEmu::ControlGroup* Wiimote::GetTurntableGroup(TurntableGroup group) +{ + return static_cast(m_extension->attachments[EXT_TURNTABLE].get())->GetGroup(group); +} + bool Wiimote::Step() { // TODO: change this a bit diff --git a/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.h b/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.h index b1e4a9522c..11719ad1ee 100644 --- a/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.h +++ b/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.h @@ -26,7 +26,77 @@ class Wiimote; } namespace WiimoteEmu { +enum class WiimoteGroup +{ + Buttons, + DPad, + Shake, + IR, + Tilt, + Swing, + Rumble, + Extension, + + Options, + Hotkeys +}; + +enum +{ + EXT_NONE, + + EXT_NUNCHUK, + EXT_CLASSIC, + EXT_GUITAR, + EXT_DRUMS, + EXT_TURNTABLE +}; + +enum class NunchukGroup +{ + Buttons, + Stick, + Tilt, + Swing, + Shake +}; + +enum class ClassicGroup +{ + Buttons, + Triggers, + DPad, + LeftStick, + RightStick +}; + +enum class GuitarGroup +{ + Buttons, + Frets, + Strum, + Whammy, + Stick +}; + +enum class DrumsGroup +{ + Buttons, + Pads, + Stick +}; + +enum class TurntableGroup +{ + Buttons, + Stick, + EffectDial, + LeftTable, + RightTable, + Crossfade +}; #pragma pack(push, 1) + struct ReportFeatures { u8 core, accel, ir, ext, size; @@ -105,6 +175,12 @@ public: Wiimote(const unsigned int index); std::string GetName() const override; + ControlGroup* GetWiimoteGroup(WiimoteGroup group); + ControlGroup* GetNunchukGroup(NunchukGroup group); + ControllerEmu::ControlGroup* GetClassicGroup(ClassicGroup group); + ControllerEmu::ControlGroup* GetGuitarGroup(GuitarGroup group); + ControllerEmu::ControlGroup* GetDrumsGroup(DrumsGroup group); + ControllerEmu::ControlGroup* GetTurntableGroup(TurntableGroup group); void Update(); void InterruptChannel(const u16 _channelID, const void* _pData, u32 _Size); diff --git a/Source/Core/Core/HotkeyManager.cpp b/Source/Core/Core/HotkeyManager.cpp index 05ee715ea1..ee16a46e2d 100644 --- a/Source/Core/Core/HotkeyManager.cpp +++ b/Source/Core/Core/HotkeyManager.cpp @@ -14,10 +14,21 @@ const std::string hotkey_labels[] = { _trans("Open"), _trans("Change Disc"), _trans("Refresh List"), - _trans("Toggle Pause"), _trans("Stop"), _trans("Reset"), + _trans("Toggle Fullscreen"), + _trans("Take Screenshot"), + _trans("Exit"), + + _trans("Volume Down"), + _trans("Volume Up"), + _trans("Volume Toggle Mute"), + + _trans("Decrease Emulation Speed"), + _trans("Increase Emulation Speed"), + _trans("Disable Emulation Speed Limit"), + _trans("Frame Advance"), _trans("Frame Advance Decrease Speed"), _trans("Frame Advance Increase Speed"), @@ -28,10 +39,6 @@ const std::string hotkey_labels[] = { _trans("Export Recording"), _trans("Read-only mode"), - _trans("Toggle Fullscreen"), - _trans("Take Screenshot"), - _trans("Exit"), - _trans("Press Sync Button"), _trans("Connect Wii Remote 1"), _trans("Connect Wii Remote 2"), @@ -39,21 +46,14 @@ const std::string hotkey_labels[] = { _trans("Connect Wii Remote 4"), _trans("Connect Balance Board"), - _trans("Volume Down"), - _trans("Volume Up"), - _trans("Volume Toggle Mute"), - - _trans("Increase IR"), - _trans("Decrease IR"), - _trans("Toggle Crop"), _trans("Toggle Aspect Ratio"), _trans("Toggle EFB Copies"), _trans("Toggle Fog"), - _trans("Disable Emulation Speed Limit"), _trans("Toggle Custom Textures"), - _trans("Decrease Emulation Speed"), - _trans("Increase Emulation Speed"), + + _trans("Increase IR"), + _trans("Decrease IR"), _trans("Freelook Decrease Speed"), _trans("Freelook Increase Speed"), @@ -70,7 +70,6 @@ const std::string hotkey_labels[] = { _trans("Toggle 3D Top-bottom"), _trans("Toggle 3D Anaglyph"), _trans("Toggle 3D Vision"), - _trans("Decrease Depth"), _trans("Increase Depth"), _trans("Decrease Convergence"), @@ -108,7 +107,6 @@ const std::string hotkey_labels[] = { _trans("Select State Slot 8"), _trans("Select State Slot 9"), _trans("Select State Slot 10"), - _trans("Save to selected slot"), _trans("Load from selected slot"), @@ -134,7 +132,7 @@ static_assert(NUM_HOTKEYS == sizeof(hotkey_labels) / sizeof(hotkey_labels[0]), namespace HotkeyManagerEmu { -static u32 s_hotkeyDown[(NUM_HOTKEYS + 31) / 32]; +static u32 s_hotkeyDown[NUM_HOTKEY_GROUPS]; static HotkeyStatus s_hotkey; static bool s_enabled; @@ -163,20 +161,21 @@ void Enable(bool enable_toggle) s_enabled = enable_toggle; } -bool IsPressed(int Id, bool held) +bool IsPressed(int id, bool held) { - unsigned int set = Id / 32; - unsigned int setKey = Id % 32; - if (s_hotkey.button[set] & (1 << setKey)) + unsigned int group = static_cast(s_config.GetController(0))->FindGroupByID(id); + unsigned int group_key = + static_cast(s_config.GetController(0))->GetIndexForGroup(group, id); + if (s_hotkey.button[group] & (1 << group_key)) { - bool pressed = !!(s_hotkeyDown[set] & (1 << setKey)); - s_hotkeyDown[set] |= (1 << setKey); + bool pressed = !!(s_hotkeyDown[group] & (1 << group_key)); + s_hotkeyDown[group] |= (1 << group_key); if (!pressed || held) return true; } else { - s_hotkeyDown[set] &= ~(1 << setKey); + s_hotkeyDown[group] &= ~(1 << group_key); } return false; @@ -203,22 +202,50 @@ void LoadConfig() s_config.LoadConfig(true); } +ControllerEmu::ControlGroup* GetHotkeyGroup(HotkeyGroup group) +{ + return static_cast(s_config.GetController(0))->GetHotkeyGroup(group); +} + +ControllerEmu::ControlGroup* GetOptionsGroup() +{ + return static_cast(s_config.GetController(0))->GetOptionsGroup(); +} + void Shutdown() { s_config.ClearControllers(); } } +const std::array groups_info = { + {{"General", HK_OPEN, HK_EXIT}, + {"Volume", HK_VOLUME_DOWN, HK_VOLUME_TOGGLE_MUTE}, + {"Emulation speed", HK_DECREASE_EMULATION_SPEED, HK_TOGGLE_THROTTLE}, + {"Frame advance", HK_FRAME_ADVANCE, HK_FRAME_ADVANCE_RESET_SPEED}, + {"Movie", HK_START_RECORDING, HK_READ_ONLY_MODE}, + {"Wii", HK_TRIGGER_SYNC_BUTTON, HK_BALANCEBOARD_CONNECT}, + {"Graphics toggles", HK_TOGGLE_CROP, HK_TOGGLE_TEXTURES}, + {"Internal Resolution", HK_INCREASE_IR, HK_DECREASE_IR}, + {"Freelook", HK_FREELOOK_DECREASE_SPEED, HK_FREELOOK_RESET}, + {"3D", HK_TOGGLE_STEREO_SBS, HK_TOGGLE_STEREO_3DVISION}, + {"3D depth", HK_DECREASE_DEPTH, HK_INCREASE_CONVERGENCE}, + {"Load state", HK_LOAD_STATE_SLOT_1, HK_LOAD_STATE_SLOT_SELECTED}, + {"Save state", HK_SAVE_STATE_SLOT_1, HK_SAVE_STATE_SLOT_SELECTED}, + {"Select state", HK_SELECT_STATE_SLOT_1, HK_SELECT_STATE_SLOT_10}, + {"Load last state", HK_LOAD_LAST_STATE_1, HK_LOAD_LAST_STATE_10}, + {"Other state hotkeys", HK_SAVE_FIRST_STATE, HK_LOAD_STATE_FILE}}}; + HotkeyManager::HotkeyManager() { - for (int key = 0; key < NUM_HOTKEYS; key++) + for (int group = 0; group < NUM_HOTKEY_GROUPS; group++) { - int set = key / 32; - - if (key % 32 == 0) - groups.emplace_back(m_keys[set] = new Buttons(_trans("Keys"))); - - m_keys[set]->controls.emplace_back(new ControlGroup::Input(hotkey_labels[key])); + m_hotkey_groups[group] = (m_keys[group] = new Buttons("Keys", _trans(groups_info[group].name))); + groups.emplace_back(m_hotkey_groups[group]); + for (int key = groups_info[group].first; key <= groups_info[group].last; key++) + { + m_keys[group]->controls.emplace_back(new ControlGroup::Input(hotkey_labels[key])); + } } groups.emplace_back(m_options = new ControlGroup(_trans("Options"))); @@ -240,17 +267,41 @@ std::string HotkeyManager::GetName() const void HotkeyManager::GetInput(HotkeyStatus* const kb) { auto lock = ControllerEmu::GetStateLock(); - for (int set = 0; set < (NUM_HOTKEYS + 31) / 32; set++) + for (int group = 0; group < NUM_HOTKEY_GROUPS; group++) { - std::vector bitmasks; - for (int key = 0; key < std::min(32, NUM_HOTKEYS - set * 32); key++) - bitmasks.push_back(1 << key); + const int group_count = (groups_info[group].last - groups_info[group].first) + 1; + std::vector bitmasks(group_count); + for (size_t key = 0; key < bitmasks.size(); key++) + bitmasks[key] = static_cast(1 << key); - kb->button[set] = 0; - m_keys[set]->GetState(&kb->button[set], bitmasks.data()); + kb->button[group] = 0; + m_keys[group]->GetState(&kb->button[group], bitmasks.data()); } } +ControllerEmu::ControlGroup* HotkeyManager::GetHotkeyGroup(HotkeyGroup group) const +{ + return m_hotkey_groups[group]; +} + +ControllerEmu::ControlGroup* HotkeyManager::GetOptionsGroup() const +{ + return m_options; +} + +int HotkeyManager::FindGroupByID(int id) const +{ + const auto i = std::find_if(groups_info.begin(), groups_info.end(), + [id](const auto& entry) { return entry.last >= id; }); + + return static_cast(std::distance(groups_info.begin(), i)); +} + +int HotkeyManager::GetIndexForGroup(int group, int id) const +{ + return id - groups_info[group].first; +} + void HotkeyManager::LoadDefaults(const ControllerInterface& ciface) { ControllerEmu::LoadDefaults(ciface); @@ -268,7 +319,9 @@ void HotkeyManager::LoadDefaults(const ControllerInterface& ciface) #endif auto set_key_expression = [this](int index, const std::string& expression) { - m_keys[index / 32]->controls[index % 32]->control_ref->expression = expression; + m_keys[FindGroupByID(index)] + ->controls[GetIndexForGroup(FindGroupByID(index), index)] + ->control_ref->expression = expression; }; // General hotkeys diff --git a/Source/Core/Core/HotkeyManager.h b/Source/Core/Core/HotkeyManager.h index a53f57bb14..d538c902eb 100644 --- a/Source/Core/Core/HotkeyManager.h +++ b/Source/Core/Core/HotkeyManager.h @@ -4,7 +4,9 @@ #pragma once +#include #include + #include "InputCommon/ControllerEmu.h" #include "InputCommon/InputConfig.h" @@ -13,10 +15,21 @@ enum Hotkey HK_OPEN, HK_CHANGE_DISC, HK_REFRESH_LIST, - HK_PLAY_PAUSE, HK_STOP, HK_RESET, + HK_FULLSCREEN, + HK_SCREENSHOT, + HK_EXIT, + + HK_VOLUME_DOWN, + HK_VOLUME_UP, + HK_VOLUME_TOGGLE_MUTE, + + HK_DECREASE_EMULATION_SPEED, + HK_INCREASE_EMULATION_SPEED, + HK_TOGGLE_THROTTLE, + HK_FRAME_ADVANCE, HK_FRAME_ADVANCE_DECREASE_SPEED, HK_FRAME_ADVANCE_INCREASE_SPEED, @@ -27,10 +40,6 @@ enum Hotkey HK_EXPORT_RECORDING, HK_READ_ONLY_MODE, - HK_FULLSCREEN, - HK_SCREENSHOT, - HK_EXIT, - HK_TRIGGER_SYNC_BUTTON, HK_WIIMOTE1_CONNECT, HK_WIIMOTE2_CONNECT, @@ -38,22 +47,14 @@ enum Hotkey HK_WIIMOTE4_CONNECT, HK_BALANCEBOARD_CONNECT, - HK_VOLUME_DOWN, - HK_VOLUME_UP, - HK_VOLUME_TOGGLE_MUTE, - - HK_INCREASE_IR, - HK_DECREASE_IR, - HK_TOGGLE_CROP, HK_TOGGLE_AR, HK_TOGGLE_EFBCOPIES, HK_TOGGLE_FOG, - HK_TOGGLE_THROTTLE, HK_TOGGLE_TEXTURES, - HK_DECREASE_EMULATION_SPEED, - HK_INCREASE_EMULATION_SPEED, + HK_INCREASE_IR, + HK_DECREASE_IR, HK_FREELOOK_DECREASE_SPEED, HK_FREELOOK_INCREASE_SPEED, @@ -86,6 +87,7 @@ enum Hotkey HK_LOAD_STATE_SLOT_8, HK_LOAD_STATE_SLOT_9, HK_LOAD_STATE_SLOT_10, + HK_LOAD_STATE_SLOT_SELECTED, HK_SAVE_STATE_SLOT_1, HK_SAVE_STATE_SLOT_2, @@ -97,6 +99,7 @@ enum Hotkey HK_SAVE_STATE_SLOT_8, HK_SAVE_STATE_SLOT_9, HK_SAVE_STATE_SLOT_10, + HK_SAVE_STATE_SLOT_SELECTED, HK_SELECT_STATE_SLOT_1, HK_SELECT_STATE_SLOT_2, @@ -109,9 +112,6 @@ enum Hotkey HK_SELECT_STATE_SLOT_9, HK_SELECT_STATE_SLOT_10, - HK_SAVE_STATE_SLOT_SELECTED, - HK_LOAD_STATE_SLOT_SELECTED, - HK_LOAD_LAST_STATE_1, HK_LOAD_LAST_STATE_2, HK_LOAD_LAST_STATE_3, @@ -132,9 +132,38 @@ enum Hotkey NUM_HOTKEYS, }; +enum HotkeyGroup : int +{ + HKGP_GENERAL, + HKGP_VOLUME, + HKGP_SPEED, + HKGP_FRANE_ADVANCE, + HKGP_MOVIE, + HKGP_WII, + HKGP_GRAPHICS_TOGGLES, + HKGP_IR, + HKGP_FREELOOK, + HKGP_3D_TOGGLE, + HKGP_3D_DEPTH, + HKGP_LOAD_STATE, + HKGP_SAVE_STATE, + HKGP_SELECT_STATE, + HKGP_LOAD_LAST_STATE, + HKGP_STATE_MISC, + + NUM_HOTKEY_GROUPS, +}; + +struct HotkeyGroupInfo +{ + std::string name; + Hotkey first; + Hotkey last; +}; + struct HotkeyStatus { - u32 button[(NUM_HOTKEYS + 31) / 32]; + u32 button[NUM_HOTKEY_GROUPS]; s8 err; }; @@ -146,10 +175,15 @@ public: void GetInput(HotkeyStatus* const hk); std::string GetName() const override; + ControlGroup* GetHotkeyGroup(HotkeyGroup group) const; + ControlGroup* GetOptionsGroup() const; + int FindGroupByID(int id) const; + int GetIndexForGroup(int group, int id) const; void LoadDefaults(const ControllerInterface& ciface) override; private: - Buttons* m_keys[(NUM_HOTKEYS + 31) / 32]; + Buttons* m_keys[NUM_HOTKEY_GROUPS]; + std::array m_hotkey_groups; ControlGroup* m_options; }; @@ -160,6 +194,8 @@ void Shutdown(); void LoadConfig(); InputConfig* GetConfig(); +ControllerEmu::ControlGroup* GetHotkeyGroup(HotkeyGroup group); +ControllerEmu::ControlGroup* GetOptionsGroup(); void GetStatus(); bool IsEnabled(); void Enable(bool enable_toggle); diff --git a/Source/Core/InputCommon/ControllerEmu.cpp b/Source/Core/InputCommon/ControllerEmu.cpp index 84f511f822..43ce66412b 100644 --- a/Source/Core/InputCommon/ControllerEmu.cpp +++ b/Source/Core/InputCommon/ControllerEmu.cpp @@ -187,7 +187,14 @@ ControllerEmu::AnalogStick::AnalogStick(const char* const _name, const char* con numeric_settings.emplace_back(std::make_unique(_trans("Dead Zone"), 0, 0, 50)); } -ControllerEmu::Buttons::Buttons(const std::string& _name) : ControlGroup(_name, GROUP_TYPE_BUTTONS) +ControllerEmu::Buttons::Buttons(const std::string& _name) + : ControlGroup(_name, _name, GROUP_TYPE_BUTTONS) +{ + numeric_settings.emplace_back(std::make_unique(_trans("Threshold"), 0.5)); +} + +ControllerEmu::Buttons::Buttons(const std::string& _name, const std::string& _ui_name) + : ControlGroup(_name, _ui_name, GROUP_TYPE_BUTTONS) { numeric_settings.emplace_back(std::make_unique(_trans("Threshold"), 0.5)); } diff --git a/Source/Core/InputCommon/ControllerEmu.h b/Source/Core/InputCommon/ControllerEmu.h index 90247d699e..ef07be3e5d 100644 --- a/Source/Core/InputCommon/ControllerEmu.h +++ b/Source/Core/InputCommon/ControllerEmu.h @@ -204,6 +204,7 @@ public: { public: Buttons(const std::string& _name); + Buttons(const std::string& _name, const std::string& _ui_name); template void GetState(C* const buttons, const C* bitmasks)