Merge pull request #1188 from ggrtk/popn-controller

DigitalController: Add option to force as Pop'n Controller
This commit is contained in:
Connor McLaughlin 2020-12-11 00:31:32 +10:00 committed by GitHub
commit 591f69f771
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 1 deletions

View file

@ -234,6 +234,9 @@ Controller::SettingList Controller::GetSettings(ControllerType type)
{
switch (type)
{
case ControllerType::DigitalController:
return DigitalController::StaticGetSettings();
case ControllerType::AnalogController:
return AnalogController::StaticGetSettings();

View file

@ -96,7 +96,7 @@ bool DigitalController::Transfer(const u8 data_in, u8* data_out)
case TransferState::ButtonsLSB:
{
*data_out = Truncate8(m_button_state);
*data_out = Truncate8(m_button_state) & GetButtonsLSBMask();
m_transfer_state = TransferState::ButtonsMSB;
return true;
}
@ -181,3 +181,26 @@ u32 DigitalController::StaticGetVibrationMotorCount()
{
return 0;
}
Controller::SettingList DigitalController::StaticGetSettings()
{
static constexpr std::array<SettingInfo, 1> settings = {
{{SettingInfo::Type::Boolean, "ForcePopnControllerMode",
TRANSLATABLE("DigitalController", "Force Pop'n Controller Mode"),
TRANSLATABLE("DigitalController", "Forces the Digital Controller to act as a Pop'n Controller."), "false"}}};
return SettingList(settings.begin(), settings.end());
}
void DigitalController::LoadSettings(const char* section)
{
Controller::LoadSettings(section);
m_popn_controller_mode = g_host_interface->GetBoolSettingValue(section, "ForcePopnControllerMode", false);
}
u8 DigitalController::GetButtonsLSBMask() const
{
constexpr u8 popn_controller_mask =
~(u8(1) << static_cast<u8>(Button::Right) | u8(1) << static_cast<u8>(Button::Down) |
u8(1) << static_cast<u8>(Button::Left));
return m_popn_controller_mode ? popn_controller_mask : 0xFF;
}

View file

@ -37,6 +37,7 @@ public:
static AxisList StaticGetAxisNames();
static ButtonList StaticGetButtonNames();
static u32 StaticGetVibrationMotorCount();
static SettingList StaticGetSettings();
ControllerType GetType() const override;
std::optional<s32> GetAxisCodeByName(std::string_view axis_name) const override;
@ -54,6 +55,8 @@ public:
void SetButtonState(Button button, bool pressed);
void LoadSettings(const char* section) override;
private:
enum class TransferState : u8
{
@ -67,4 +70,8 @@ private:
u16 m_button_state = UINT16_C(0xFFFF);
TransferState m_transfer_state = TransferState::Idle;
bool m_popn_controller_mode = false;
u8 GetButtonsLSBMask() const;
};