Add the ability to get partial input group

For hotkeys, changed HotkeyManager to allow to get and make partial groups of hotkeys.

Also preserved the old configuration naming scheme for the ini, this is done to preserve compatibility with the older groups structure.

Add the ability to get GCPad control groups

Used like the HotkeyManager methods, this is used for the new GCPad configuration dialog.

Add the ability to get groups of Keyboard input

Same reasons as the previous ones.

Add ability to get groups of Wiimote input

Add the ability to get extensions group

This needed to pass to 3 classes.  Will be used for their respective dialogs.
This commit is contained in:
aldelaro5 2016-11-10 22:07:40 -05:00
parent 6c16f1be8a
commit 7e99d03b7f
26 changed files with 545 additions and 61 deletions

View File

@ -44,6 +44,11 @@ void LoadConfig()
s_config.LoadConfig(true); s_config.LoadConfig(true);
} }
ControllerEmu::ControlGroup* GetGroup(int port, KeyboardGroup group)
{
return static_cast<GCKeyboard*>(s_config.GetController(port))->GetGroup(group);
}
KeyboardStatus GetStatus(int port) KeyboardStatus GetStatus(int port)
{ {
return static_cast<GCKeyboard*>(s_config.GetController(port))->GetInput(); return static_cast<GCKeyboard*>(s_config.GetController(port))->GetInput();

View File

@ -5,8 +5,10 @@
#pragma once #pragma once
#include "Common/CommonTypes.h" #include "Common/CommonTypes.h"
#include "InputCommon/ControllerEmu.h"
class InputConfig; class InputConfig;
enum class KeyboardGroup;
struct KeyboardStatus; struct KeyboardStatus;
namespace Keyboard namespace Keyboard
@ -16,6 +18,7 @@ void Initialize();
void LoadConfig(); void LoadConfig();
InputConfig* GetConfig(); InputConfig* GetConfig();
ControllerEmu::ControlGroup* GetGroup(int port, KeyboardGroup group);
KeyboardStatus GetStatus(int port); KeyboardStatus GetStatus(int port);
} }

View File

@ -4,6 +4,7 @@
#include "Core/HW/GCKeyboardEmu.h" #include "Core/HW/GCKeyboardEmu.h"
#include "Common/Common.h" #include "Common/Common.h"
#include "InputCommon/ControllerEmu.h"
#include "InputCommon/KeyboardStatus.h" #include "InputCommon/KeyboardStatus.h"
static const u16 keys0_bitmasks[] = {KEYMASK_HOME, KEYMASK_END, KEYMASK_PGUP, KEYMASK_PGDN, 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); 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 KeyboardStatus GCKeyboard::GetInput() const
{ {
auto lock = ControllerEmu::GetStateLock(); auto lock = ControllerEmu::GetStateLock();

View File

@ -10,12 +10,25 @@
struct KeyboardStatus; struct KeyboardStatus;
enum class KeyboardGroup
{
Kb0x,
Kb1x,
Kb2x,
Kb3x,
Kb4x,
Kb5x,
Options
};
class GCKeyboard : public ControllerEmu class GCKeyboard : public ControllerEmu
{ {
public: public:
GCKeyboard(const unsigned int index); GCKeyboard(const unsigned int index);
KeyboardStatus GetInput() const; KeyboardStatus GetInput() const;
std::string GetName() const override; std::string GetName() const override;
ControlGroup* GetGroup(KeyboardGroup group);
void LoadDefaults(const ControllerInterface& ciface) override; void LoadDefaults(const ControllerInterface& ciface) override;
private: private:

View File

@ -5,7 +5,6 @@
#include <cstring> #include <cstring>
#include "Common/Common.h" #include "Common/Common.h"
#include "Common/CommonTypes.h"
#include "Core/HW/GCPad.h" #include "Core/HW/GCPad.h"
#include "Core/HW/GCPadEmu.h" #include "Core/HW/GCPadEmu.h"
#include "InputCommon/GCPadStatus.h" #include "InputCommon/GCPadStatus.h"
@ -48,6 +47,11 @@ GCPadStatus GetStatus(int pad_num)
return static_cast<GCPad*>(s_config.GetController(pad_num))->GetInput(); return static_cast<GCPad*>(s_config.GetController(pad_num))->GetInput();
} }
ControllerEmu::ControlGroup* GetGroup(int pad_num, PadGroup group)
{
return static_cast<GCPad*>(s_config.GetController(pad_num))->GetGroup(group);
}
void Rumble(const int pad_num, const ControlState strength) void Rumble(const int pad_num, const ControlState strength)
{ {
static_cast<GCPad*>(s_config.GetController(pad_num))->SetOutput(strength); static_cast<GCPad*>(s_config.GetController(pad_num))->SetOutput(strength);

View File

@ -5,9 +5,11 @@
#pragma once #pragma once
#include "Common/CommonTypes.h" #include "Common/CommonTypes.h"
#include "InputCommon/ControllerEmu.h"
#include "InputCommon/ControllerInterface/Device.h" #include "InputCommon/ControllerInterface/Device.h"
class InputConfig; class InputConfig;
enum class PadGroup;
struct GCPadStatus; struct GCPadStatus;
namespace Pad namespace Pad
@ -19,6 +21,7 @@ void LoadConfig();
InputConfig* GetConfig(); InputConfig* GetConfig();
GCPadStatus GetStatus(int pad_num); GCPadStatus GetStatus(int pad_num);
ControllerEmu::ControlGroup* GetGroup(int pad_num, PadGroup group);
void Rumble(int pad_num, ControlState strength); void Rumble(int pad_num, ControlState strength);
bool GetMicButton(int pad_num); bool GetMicButton(int pad_num);

View File

@ -79,6 +79,29 @@ std::string GCPad::GetName() const
return std::string("GCPad") + char('1' + m_index); 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 GCPadStatus GCPad::GetInput() const
{ {
auto lock = ControllerEmu::GetStateLock(); auto lock = ControllerEmu::GetStateLock();

View File

@ -8,6 +8,19 @@
#include "InputCommon/ControllerEmu.h" #include "InputCommon/ControllerEmu.h"
class ControlGroup;
enum class PadGroup
{
Buttons,
MainStick,
CStick,
DPad,
Triggers,
Rumble,
Options
};
class GCPad : public ControllerEmu class GCPad : public ControllerEmu
{ {
public: public:
@ -19,6 +32,8 @@ public:
std::string GetName() const override; std::string GetName() const override;
ControlGroup* GetGroup(PadGroup group);
void LoadDefaults(const ControllerInterface& ciface) override; void LoadDefaults(const ControllerInterface& ciface) override;
private: private:

View File

@ -19,6 +19,37 @@ InputConfig* GetConfig()
return &s_config; return &s_config;
} }
ControllerEmu::ControlGroup* GetWiimoteGroup(int number, WiimoteEmu::WiimoteGroup group)
{
return static_cast<WiimoteEmu::Wiimote*>(s_config.GetController(number))->GetWiimoteGroup(group);
}
ControllerEmu::ControlGroup* GetNunchukGroup(int number, WiimoteEmu::NunchukGroup group)
{
return static_cast<WiimoteEmu::Wiimote*>(s_config.GetController(number))->GetNunchukGroup(group);
}
ControllerEmu::ControlGroup* GetClassicGroup(int number, WiimoteEmu::ClassicGroup group)
{
return static_cast<WiimoteEmu::Wiimote*>(s_config.GetController(number))->GetClassicGroup(group);
}
ControllerEmu::ControlGroup* GetGuitarGroup(int number, WiimoteEmu::GuitarGroup group)
{
return static_cast<WiimoteEmu::Wiimote*>(s_config.GetController(number))->GetGuitarGroup(group);
}
ControllerEmu::ControlGroup* GetDrumsGroup(int number, WiimoteEmu::DrumsGroup group)
{
return static_cast<WiimoteEmu::Wiimote*>(s_config.GetController(number))->GetDrumsGroup(group);
}
ControllerEmu::ControlGroup* GetTurntableGroup(int number, WiimoteEmu::TurntableGroup group)
{
return static_cast<WiimoteEmu::Wiimote*>(s_config.GetController(number))
->GetTurntableGroup(group);
}
void Shutdown() void Shutdown()
{ {
s_config.ClearControllers(); s_config.ClearControllers();

View File

@ -6,9 +6,19 @@
#include "Common/Common.h" #include "Common/Common.h"
#include "Common/CommonTypes.h" #include "Common/CommonTypes.h"
#include "InputCommon/ControllerEmu.h"
class InputConfig; class InputConfig;
class PointerWrap; class PointerWrap;
namespace WiimoteEmu
{
enum class WiimoteGroup;
enum class NunchukGroup;
enum class ClassicGroup;
enum class GuitarGroup;
enum class DrumsGroup;
enum class TurntableGroup;
}
enum enum
{ {
@ -52,6 +62,12 @@ unsigned int GetAttached();
void DoState(PointerWrap& p); void DoState(PointerWrap& p);
void EmuStateChange(EMUSTATE_CHANGE newState); void EmuStateChange(EMUSTATE_CHANGE newState);
InputConfig* GetConfig(); 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 ControlChannel(int _number, u16 _channelID, const void* _pData, u32 _Size);
void InterruptChannel(int _number, u16 _channelID, const void* _pData, u32 _Size); void InterruptChannel(int _number, u16 _channelID, const void* _pData, u32 _Size);

View File

@ -2,6 +2,7 @@
// Licensed under GPLv2+ // Licensed under GPLv2+
// Refer to the license.txt file included. // Refer to the license.txt file included.
#include <cassert>
#include <cstring> #include <cstring>
#include "Common/Common.h" #include "Common/Common.h"
@ -134,4 +135,24 @@ bool Classic::IsButtonPressed() const
m_triggers->GetState(&buttons, classic_trigger_bitmasks, trigs); m_triggers->GetState(&buttons, classic_trigger_bitmasks, trigs);
return buttons != 0; 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;
}
}
} }

View File

@ -8,6 +8,7 @@
namespace WiimoteEmu namespace WiimoteEmu
{ {
enum class ClassicGroup;
struct ExtensionReg; struct ExtensionReg;
class Classic : public Attachment class Classic : public Attachment
@ -17,6 +18,8 @@ public:
void GetState(u8* const data) override; void GetState(u8* const data) override;
bool IsButtonPressed() const override; bool IsButtonPressed() const override;
ControlGroup* GetGroup(ClassicGroup group);
enum enum
{ {
PAD_RIGHT = 0x80, PAD_RIGHT = 0x80,

View File

@ -2,6 +2,7 @@
// Licensed under GPLv2+ // Licensed under GPLv2+
// Refer to the license.txt file included. // Refer to the license.txt file included.
#include <cassert>
#include <cstring> #include <cstring>
#include "Common/Common.h" #include "Common/Common.h"
@ -81,4 +82,20 @@ bool Drums::IsButtonPressed() const
m_pads->GetState(&buttons, drum_pad_bitmasks); m_pads->GetState(&buttons, drum_pad_bitmasks);
return buttons != 0; 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;
}
}
} }

View File

@ -8,6 +8,7 @@
namespace WiimoteEmu namespace WiimoteEmu
{ {
enum class DrumsGroup;
struct ExtensionReg; struct ExtensionReg;
class Drums : public Attachment class Drums : public Attachment
@ -17,6 +18,8 @@ public:
void GetState(u8* const data) override; void GetState(u8* const data) override;
bool IsButtonPressed() const override; bool IsButtonPressed() const override;
ControlGroup* GetGroup(DrumsGroup group);
enum enum
{ {
BUTTON_PLUS = 0x04, BUTTON_PLUS = 0x04,

View File

@ -2,6 +2,7 @@
// Licensed under GPLv2+ // Licensed under GPLv2+
// Refer to the license.txt file included. // Refer to the license.txt file included.
#include <cassert>
#include <cstring> #include <cstring>
#include "Common/Common.h" #include "Common/Common.h"
@ -102,4 +103,24 @@ bool Guitar::IsButtonPressed() const
m_strum->GetState(&buttons, guitar_strum_bitmasks); m_strum->GetState(&buttons, guitar_strum_bitmasks);
return buttons != 0; 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;
}
}
} }

View File

@ -8,6 +8,7 @@
namespace WiimoteEmu namespace WiimoteEmu
{ {
enum class GuitarGroup;
struct ExtensionReg; struct ExtensionReg;
class Guitar : public Attachment class Guitar : public Attachment
@ -17,6 +18,8 @@ public:
void GetState(u8* const data) override; void GetState(u8* const data) override;
bool IsButtonPressed() const override; bool IsButtonPressed() const override;
ControlGroup* GetGroup(GuitarGroup group);
enum enum
{ {
BUTTON_PLUS = 0x04, BUTTON_PLUS = 0x04,

View File

@ -2,6 +2,7 @@
// Licensed under GPLv2+ // Licensed under GPLv2+
// Refer to the license.txt file included. // Refer to the license.txt file included.
#include <cassert>
#include <cstring> #include <cstring>
#include "Common/Common.h" #include "Common/Common.h"
@ -114,6 +115,26 @@ bool Nunchuk::IsButtonPressed() const
return buttons != 0; 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) void Nunchuk::LoadDefaults(const ControllerInterface& ciface)
{ {
// Stick // Stick

View File

@ -8,6 +8,7 @@
namespace WiimoteEmu namespace WiimoteEmu
{ {
enum class NunchukGroup;
struct ExtensionReg; struct ExtensionReg;
class Nunchuk : public Attachment class Nunchuk : public Attachment
@ -18,6 +19,8 @@ public:
void GetState(u8* const data) override; void GetState(u8* const data) override;
bool IsButtonPressed() const override; bool IsButtonPressed() const override;
ControlGroup* GetGroup(NunchukGroup group);
enum enum
{ {
BUTTON_C = 0x02, BUTTON_C = 0x02,

View File

@ -2,6 +2,7 @@
// Licensed under GPLv2+ // Licensed under GPLv2+
// Refer to the license.txt file included. // Refer to the license.txt file included.
#include <cassert>
#include <cstring> #include <cstring>
#include "Common/Common.h" #include "Common/Common.h"
@ -131,4 +132,26 @@ bool Turntable::IsButtonPressed() const
m_buttons->GetState(&buttons, turntable_button_bitmasks); m_buttons->GetState(&buttons, turntable_button_bitmasks);
return buttons != 0; 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;
}
}
} }

View File

@ -8,6 +8,7 @@
namespace WiimoteEmu namespace WiimoteEmu
{ {
enum class TurntableGroup;
struct ExtensionReg; struct ExtensionReg;
class Turntable : public Attachment class Turntable : public Attachment
@ -17,6 +18,8 @@ public:
void GetState(u8* const data) override; void GetState(u8* const data) override;
bool IsButtonPressed() const override; bool IsButtonPressed() const override;
ControlGroup* GetGroup(TurntableGroup group);
enum enum
{ {
BUTTON_EUPHORIA = 0x1000, BUTTON_EUPHORIA = 0x1000,

View File

@ -2,6 +2,7 @@
// Licensed under GPLv2+ // Licensed under GPLv2+
// Refer to the license.txt file included. // Refer to the license.txt file included.
#include <cassert>
#include <cmath> #include <cmath>
#include <cstring> #include <cstring>
@ -315,6 +316,61 @@ std::string Wiimote::GetName() const
return std::string("Wiimote") + char('1' + m_index); 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<Nunchuk*>(m_extension->attachments[EXT_NUNCHUK].get())->GetGroup(group);
}
ControllerEmu::ControlGroup* Wiimote::GetClassicGroup(ClassicGroup group)
{
return static_cast<Classic*>(m_extension->attachments[EXT_CLASSIC].get())->GetGroup(group);
}
ControllerEmu::ControlGroup* Wiimote::GetGuitarGroup(GuitarGroup group)
{
return static_cast<Guitar*>(m_extension->attachments[EXT_GUITAR].get())->GetGroup(group);
}
ControllerEmu::ControlGroup* Wiimote::GetDrumsGroup(DrumsGroup group)
{
return static_cast<Drums*>(m_extension->attachments[EXT_DRUMS].get())->GetGroup(group);
}
ControllerEmu::ControlGroup* Wiimote::GetTurntableGroup(TurntableGroup group)
{
return static_cast<Turntable*>(m_extension->attachments[EXT_TURNTABLE].get())->GetGroup(group);
}
bool Wiimote::Step() bool Wiimote::Step()
{ {
// TODO: change this a bit // TODO: change this a bit

View File

@ -26,7 +26,77 @@ class Wiimote;
} }
namespace WiimoteEmu 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) #pragma pack(push, 1)
struct ReportFeatures struct ReportFeatures
{ {
u8 core, accel, ir, ext, size; u8 core, accel, ir, ext, size;
@ -105,6 +175,12 @@ public:
Wiimote(const unsigned int index); Wiimote(const unsigned int index);
std::string GetName() const override; 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 Update();
void InterruptChannel(const u16 _channelID, const void* _pData, u32 _Size); void InterruptChannel(const u16 _channelID, const void* _pData, u32 _Size);

View File

@ -14,10 +14,21 @@ const std::string hotkey_labels[] = {
_trans("Open"), _trans("Open"),
_trans("Change Disc"), _trans("Change Disc"),
_trans("Refresh List"), _trans("Refresh List"),
_trans("Toggle Pause"), _trans("Toggle Pause"),
_trans("Stop"), _trans("Stop"),
_trans("Reset"), _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"),
_trans("Frame Advance Decrease Speed"), _trans("Frame Advance Decrease Speed"),
_trans("Frame Advance Increase Speed"), _trans("Frame Advance Increase Speed"),
@ -28,10 +39,6 @@ const std::string hotkey_labels[] = {
_trans("Export Recording"), _trans("Export Recording"),
_trans("Read-only mode"), _trans("Read-only mode"),
_trans("Toggle Fullscreen"),
_trans("Take Screenshot"),
_trans("Exit"),
_trans("Press Sync Button"), _trans("Press Sync Button"),
_trans("Connect Wii Remote 1"), _trans("Connect Wii Remote 1"),
_trans("Connect Wii Remote 2"), _trans("Connect Wii Remote 2"),
@ -39,21 +46,14 @@ const std::string hotkey_labels[] = {
_trans("Connect Wii Remote 4"), _trans("Connect Wii Remote 4"),
_trans("Connect Balance Board"), _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 Crop"),
_trans("Toggle Aspect Ratio"), _trans("Toggle Aspect Ratio"),
_trans("Toggle EFB Copies"), _trans("Toggle EFB Copies"),
_trans("Toggle Fog"), _trans("Toggle Fog"),
_trans("Disable Emulation Speed Limit"),
_trans("Toggle Custom Textures"), _trans("Toggle Custom Textures"),
_trans("Decrease Emulation Speed"),
_trans("Increase Emulation Speed"), _trans("Increase IR"),
_trans("Decrease IR"),
_trans("Freelook Decrease Speed"), _trans("Freelook Decrease Speed"),
_trans("Freelook Increase Speed"), _trans("Freelook Increase Speed"),
@ -70,7 +70,6 @@ const std::string hotkey_labels[] = {
_trans("Toggle 3D Top-bottom"), _trans("Toggle 3D Top-bottom"),
_trans("Toggle 3D Anaglyph"), _trans("Toggle 3D Anaglyph"),
_trans("Toggle 3D Vision"), _trans("Toggle 3D Vision"),
_trans("Decrease Depth"), _trans("Decrease Depth"),
_trans("Increase Depth"), _trans("Increase Depth"),
_trans("Decrease Convergence"), _trans("Decrease Convergence"),
@ -108,7 +107,6 @@ const std::string hotkey_labels[] = {
_trans("Select State Slot 8"), _trans("Select State Slot 8"),
_trans("Select State Slot 9"), _trans("Select State Slot 9"),
_trans("Select State Slot 10"), _trans("Select State Slot 10"),
_trans("Save to selected slot"), _trans("Save to selected slot"),
_trans("Load from selected slot"), _trans("Load from selected slot"),
@ -134,7 +132,7 @@ static_assert(NUM_HOTKEYS == sizeof(hotkey_labels) / sizeof(hotkey_labels[0]),
namespace HotkeyManagerEmu namespace HotkeyManagerEmu
{ {
static u32 s_hotkeyDown[(NUM_HOTKEYS + 31) / 32]; static u32 s_hotkeyDown[NUM_HOTKEY_GROUPS];
static HotkeyStatus s_hotkey; static HotkeyStatus s_hotkey;
static bool s_enabled; static bool s_enabled;
@ -163,20 +161,21 @@ void Enable(bool enable_toggle)
s_enabled = 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 group = static_cast<HotkeyManager*>(s_config.GetController(0))->FindGroupByID(id);
unsigned int setKey = Id % 32; unsigned int group_key =
if (s_hotkey.button[set] & (1 << setKey)) static_cast<HotkeyManager*>(s_config.GetController(0))->GetIndexForGroup(group, id);
if (s_hotkey.button[group] & (1 << group_key))
{ {
bool pressed = !!(s_hotkeyDown[set] & (1 << setKey)); bool pressed = !!(s_hotkeyDown[group] & (1 << group_key));
s_hotkeyDown[set] |= (1 << setKey); s_hotkeyDown[group] |= (1 << group_key);
if (!pressed || held) if (!pressed || held)
return true; return true;
} }
else else
{ {
s_hotkeyDown[set] &= ~(1 << setKey); s_hotkeyDown[group] &= ~(1 << group_key);
} }
return false; return false;
@ -203,22 +202,50 @@ void LoadConfig()
s_config.LoadConfig(true); s_config.LoadConfig(true);
} }
ControllerEmu::ControlGroup* GetHotkeyGroup(HotkeyGroup group)
{
return static_cast<HotkeyManager*>(s_config.GetController(0))->GetHotkeyGroup(group);
}
ControllerEmu::ControlGroup* GetOptionsGroup()
{
return static_cast<HotkeyManager*>(s_config.GetController(0))->GetOptionsGroup();
}
void Shutdown() void Shutdown()
{ {
s_config.ClearControllers(); s_config.ClearControllers();
} }
} }
const std::array<HotkeyGroupInfo, NUM_HOTKEY_GROUPS> 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() HotkeyManager::HotkeyManager()
{ {
for (int key = 0; key < NUM_HOTKEYS; key++) for (int group = 0; group < NUM_HOTKEY_GROUPS; group++)
{ {
int set = key / 32; m_hotkey_groups[group] = (m_keys[group] = new Buttons("Keys", _trans(groups_info[group].name)));
groups.emplace_back(m_hotkey_groups[group]);
if (key % 32 == 0) for (int key = groups_info[group].first; key <= groups_info[group].last; key++)
groups.emplace_back(m_keys[set] = new Buttons(_trans("Keys"))); {
m_keys[group]->controls.emplace_back(new ControlGroup::Input(hotkey_labels[key]));
m_keys[set]->controls.emplace_back(new ControlGroup::Input(hotkey_labels[key])); }
} }
groups.emplace_back(m_options = new ControlGroup(_trans("Options"))); groups.emplace_back(m_options = new ControlGroup(_trans("Options")));
@ -240,17 +267,41 @@ std::string HotkeyManager::GetName() const
void HotkeyManager::GetInput(HotkeyStatus* const kb) void HotkeyManager::GetInput(HotkeyStatus* const kb)
{ {
auto lock = ControllerEmu::GetStateLock(); 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<u32> bitmasks; const int group_count = (groups_info[group].last - groups_info[group].first) + 1;
for (int key = 0; key < std::min(32, NUM_HOTKEYS - set * 32); key++) std::vector<u32> bitmasks(group_count);
bitmasks.push_back(1 << key); for (size_t key = 0; key < bitmasks.size(); key++)
bitmasks[key] = static_cast<u32>(1 << key);
kb->button[set] = 0; kb->button[group] = 0;
m_keys[set]->GetState(&kb->button[set], bitmasks.data()); 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<int>(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) void HotkeyManager::LoadDefaults(const ControllerInterface& ciface)
{ {
ControllerEmu::LoadDefaults(ciface); ControllerEmu::LoadDefaults(ciface);
@ -268,7 +319,9 @@ void HotkeyManager::LoadDefaults(const ControllerInterface& ciface)
#endif #endif
auto set_key_expression = [this](int index, const std::string& expression) { 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 // General hotkeys

View File

@ -4,7 +4,9 @@
#pragma once #pragma once
#include <array>
#include <string> #include <string>
#include "InputCommon/ControllerEmu.h" #include "InputCommon/ControllerEmu.h"
#include "InputCommon/InputConfig.h" #include "InputCommon/InputConfig.h"
@ -13,10 +15,21 @@ enum Hotkey
HK_OPEN, HK_OPEN,
HK_CHANGE_DISC, HK_CHANGE_DISC,
HK_REFRESH_LIST, HK_REFRESH_LIST,
HK_PLAY_PAUSE, HK_PLAY_PAUSE,
HK_STOP, HK_STOP,
HK_RESET, 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,
HK_FRAME_ADVANCE_DECREASE_SPEED, HK_FRAME_ADVANCE_DECREASE_SPEED,
HK_FRAME_ADVANCE_INCREASE_SPEED, HK_FRAME_ADVANCE_INCREASE_SPEED,
@ -27,10 +40,6 @@ enum Hotkey
HK_EXPORT_RECORDING, HK_EXPORT_RECORDING,
HK_READ_ONLY_MODE, HK_READ_ONLY_MODE,
HK_FULLSCREEN,
HK_SCREENSHOT,
HK_EXIT,
HK_TRIGGER_SYNC_BUTTON, HK_TRIGGER_SYNC_BUTTON,
HK_WIIMOTE1_CONNECT, HK_WIIMOTE1_CONNECT,
HK_WIIMOTE2_CONNECT, HK_WIIMOTE2_CONNECT,
@ -38,22 +47,14 @@ enum Hotkey
HK_WIIMOTE4_CONNECT, HK_WIIMOTE4_CONNECT,
HK_BALANCEBOARD_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_CROP,
HK_TOGGLE_AR, HK_TOGGLE_AR,
HK_TOGGLE_EFBCOPIES, HK_TOGGLE_EFBCOPIES,
HK_TOGGLE_FOG, HK_TOGGLE_FOG,
HK_TOGGLE_THROTTLE,
HK_TOGGLE_TEXTURES, HK_TOGGLE_TEXTURES,
HK_DECREASE_EMULATION_SPEED, HK_INCREASE_IR,
HK_INCREASE_EMULATION_SPEED, HK_DECREASE_IR,
HK_FREELOOK_DECREASE_SPEED, HK_FREELOOK_DECREASE_SPEED,
HK_FREELOOK_INCREASE_SPEED, HK_FREELOOK_INCREASE_SPEED,
@ -86,6 +87,7 @@ enum Hotkey
HK_LOAD_STATE_SLOT_8, HK_LOAD_STATE_SLOT_8,
HK_LOAD_STATE_SLOT_9, HK_LOAD_STATE_SLOT_9,
HK_LOAD_STATE_SLOT_10, HK_LOAD_STATE_SLOT_10,
HK_LOAD_STATE_SLOT_SELECTED,
HK_SAVE_STATE_SLOT_1, HK_SAVE_STATE_SLOT_1,
HK_SAVE_STATE_SLOT_2, HK_SAVE_STATE_SLOT_2,
@ -97,6 +99,7 @@ enum Hotkey
HK_SAVE_STATE_SLOT_8, HK_SAVE_STATE_SLOT_8,
HK_SAVE_STATE_SLOT_9, HK_SAVE_STATE_SLOT_9,
HK_SAVE_STATE_SLOT_10, HK_SAVE_STATE_SLOT_10,
HK_SAVE_STATE_SLOT_SELECTED,
HK_SELECT_STATE_SLOT_1, HK_SELECT_STATE_SLOT_1,
HK_SELECT_STATE_SLOT_2, HK_SELECT_STATE_SLOT_2,
@ -109,9 +112,6 @@ enum Hotkey
HK_SELECT_STATE_SLOT_9, HK_SELECT_STATE_SLOT_9,
HK_SELECT_STATE_SLOT_10, HK_SELECT_STATE_SLOT_10,
HK_SAVE_STATE_SLOT_SELECTED,
HK_LOAD_STATE_SLOT_SELECTED,
HK_LOAD_LAST_STATE_1, HK_LOAD_LAST_STATE_1,
HK_LOAD_LAST_STATE_2, HK_LOAD_LAST_STATE_2,
HK_LOAD_LAST_STATE_3, HK_LOAD_LAST_STATE_3,
@ -132,9 +132,38 @@ enum Hotkey
NUM_HOTKEYS, 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 struct HotkeyStatus
{ {
u32 button[(NUM_HOTKEYS + 31) / 32]; u32 button[NUM_HOTKEY_GROUPS];
s8 err; s8 err;
}; };
@ -146,10 +175,15 @@ public:
void GetInput(HotkeyStatus* const hk); void GetInput(HotkeyStatus* const hk);
std::string GetName() const override; 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; void LoadDefaults(const ControllerInterface& ciface) override;
private: private:
Buttons* m_keys[(NUM_HOTKEYS + 31) / 32]; Buttons* m_keys[NUM_HOTKEY_GROUPS];
std::array<ControlGroup*, NUM_HOTKEY_GROUPS> m_hotkey_groups;
ControlGroup* m_options; ControlGroup* m_options;
}; };
@ -160,6 +194,8 @@ void Shutdown();
void LoadConfig(); void LoadConfig();
InputConfig* GetConfig(); InputConfig* GetConfig();
ControllerEmu::ControlGroup* GetHotkeyGroup(HotkeyGroup group);
ControllerEmu::ControlGroup* GetOptionsGroup();
void GetStatus(); void GetStatus();
bool IsEnabled(); bool IsEnabled();
void Enable(bool enable_toggle); void Enable(bool enable_toggle);

View File

@ -187,7 +187,14 @@ ControllerEmu::AnalogStick::AnalogStick(const char* const _name, const char* con
numeric_settings.emplace_back(std::make_unique<NumericSetting>(_trans("Dead Zone"), 0, 0, 50)); numeric_settings.emplace_back(std::make_unique<NumericSetting>(_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<NumericSetting>(_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<NumericSetting>(_trans("Threshold"), 0.5)); numeric_settings.emplace_back(std::make_unique<NumericSetting>(_trans("Threshold"), 0.5));
} }

View File

@ -204,6 +204,7 @@ public:
{ {
public: public:
Buttons(const std::string& _name); Buttons(const std::string& _name);
Buttons(const std::string& _name, const std::string& _ui_name);
template <typename C> template <typename C>
void GetState(C* const buttons, const C* bitmasks) void GetState(C* const buttons, const C* bitmasks)