Project64-input: Remove duplicate mappings

This commit is contained in:
zilmar 2020-07-28 12:55:04 +09:30
parent 9d3bbe4659
commit f0f887ce86
9 changed files with 101 additions and 17 deletions

View File

@ -10,6 +10,8 @@
class CInputConfigUI; class CInputConfigUI;
CInputConfigUI * g_ConfigUI = nullptr;
class CControllerSettings : class CControllerSettings :
public CPropertyPageImpl<CControllerSettings> public CPropertyPageImpl<CControllerSettings>
{ {
@ -39,6 +41,7 @@ public:
CControllerSettings(uint32_t ControllerNumber); CControllerSettings(uint32_t ControllerNumber);
BOOL OnInitDialog(CWindow /*wndFocus*/, LPARAM /*lInitParam*/); BOOL OnInitDialog(CWindow /*wndFocus*/, LPARAM /*lInitParam*/);
HBRUSH OnCtlColorStatic(CDCHandle dc, CWindow wndStatic); HBRUSH OnCtlColorStatic(CDCHandle dc, CWindow wndStatic);
void RemoveMapping(const BUTTON & Button);
bool OnApply(); bool OnApply();
private: private:
@ -51,8 +54,8 @@ private:
void ItemChanged(UINT Code, int id, HWND ctl); void ItemChanged(UINT Code, int id, HWND ctl);
LRESULT ItemChangedNotify(NMHDR* /*pNMHDR*/); LRESULT ItemChangedNotify(NMHDR* /*pNMHDR*/);
void DisplayController(void); void DisplayController(void);
void ButtonChannged(void); void ButtonChannged(const BUTTON & Button);
static void stButtonChanged(size_t data) { ((CControllerSettings *)data)->ButtonChannged(); } static void stButtonChanged(size_t data, const BUTTON & Button) { ((CControllerSettings *)data)->ButtonChannged(Button); }
std::wstring m_Title; std::wstring m_Title;
uint32_t m_ControllerNumber; uint32_t m_ControllerNumber;
@ -71,6 +74,21 @@ private:
CScanButton m_ButtonAnalogU, m_ButtonAnalogD, m_ButtonAnalogL, m_ButtonAnalogR; CScanButton m_ButtonAnalogU, m_ButtonAnalogD, m_ButtonAnalogL, m_ButtonAnalogR;
}; };
class CInputConfigUI :
public CPropertySheetImpl<CInputConfigUI>
{
public:
CInputConfigUI();
~CInputConfigUI();
void UpdateDeviceMapping(void);
void RemoveMapping(const BUTTON & Button);
void OnSheetInitialized();
private:
CControllerSettings m_pgController0, m_pgController1, m_pgController2, m_pgController3;
};
CControllerSettings::CControllerSettings(uint32_t ControllerNumber) : CControllerSettings::CControllerSettings(uint32_t ControllerNumber) :
m_ControllerNumber(ControllerNumber), m_ControllerNumber(ControllerNumber),
m_ScanCount(0), m_ScanCount(0),
@ -249,27 +267,60 @@ void CControllerSettings::DisplayController(void)
GetDlgItem(IDC_BOUND_DEVICE).SetWindowText(g_InputPlugin->ControllerDevices(m_Controller).c_str()); GetDlgItem(IDC_BOUND_DEVICE).SetWindowText(g_InputPlugin->ControllerDevices(m_Controller).c_str());
} }
void CControllerSettings::ButtonChannged(void) void CControllerSettings::ButtonChannged(const BUTTON & Button)
{ {
if (g_ConfigUI != nullptr)
{
g_ConfigUI->RemoveMapping(Button);
}
GetDlgItem(IDC_BOUND_DEVICE).SetWindowText(g_InputPlugin->ControllerDevices(m_Controller).c_str()); GetDlgItem(IDC_BOUND_DEVICE).SetWindowText(g_InputPlugin->ControllerDevices(m_Controller).c_str());
CPropertySheetWindow(GetParent()).SetModified(m_hWnd); CPropertySheetWindow(GetParent()).SetModified(m_hWnd);
} }
class CInputConfigUI: void CControllerSettings::RemoveMapping(const BUTTON & Button)
public CPropertySheetImpl<CInputConfigUI>
{ {
public: if (!m_Controller.RemoveDuplicate)
CInputConfigUI(); {
~CInputConfigUI(); return;
}
BUTTON * buttons[] =
{
&m_Controller.U_DPAD, &m_Controller.D_DPAD, &m_Controller.L_DPAD, &m_Controller.R_DPAD,
&m_Controller.A_BUTTON, &m_Controller.B_BUTTON, &m_Controller.START_BUTTON, &m_Controller.Z_TRIG,
&m_Controller.U_CBUTTON, &m_Controller.D_CBUTTON, &m_Controller.L_CBUTTON, &m_Controller.R_CBUTTON,
&m_Controller.U_ANALOG, &m_Controller.D_ANALOG, &m_Controller.L_ANALOG, &m_Controller.R_ANALOG,
&m_Controller.R_TRIG, &m_Controller.L_TRIG,
};
void UpdateDeviceMapping(void); bool Changed = false;
void OnSheetInitialized(); BUTTON EmptyButton = { 0 };
for (size_t b = 0; b < (sizeof(buttons) / sizeof(buttons[0])); b++)
{
if (buttons[b]->Offset == Button.Offset &&
buttons[b]->AxisID == Button.AxisID &&
buttons[b]->BtnType == Button.BtnType &&
memcmp(&buttons[b]->DeviceGuid, &Button.DeviceGuid, sizeof(Button.DeviceGuid)) == 0)
{
*buttons[b] = EmptyButton;
Changed = true;
}
}
private: if (Changed)
CControllerSettings m_pgController0, m_pgController1, m_pgController2, m_pgController3; {
}; CScanButton * ScanButtons[] = {
&m_ButtonUDPad, &m_ButtonDDPad, &m_ButtonLDPad, &m_ButtonRDPad, &m_ButtonA, &m_ButtonB,
&m_ButtonCUp, &m_ButtonCDown, &m_ButtonCLeft, &m_ButtonCRight, &m_ButtonStart,
&m_ButtonZtrigger, &m_ButtonRTrigger, &m_ButtonLTrigger,
&m_ButtonAnalogU, &m_ButtonAnalogD, &m_ButtonAnalogL, &m_ButtonAnalogR
};
CInputConfigUI * g_ConfigUI = nullptr; for (size_t i = 0, n = sizeof(ScanButtons) / sizeof(ScanButtons[0]); i < n; i++)
{
ScanButtons[i]->DisplayButton();
}
}
}
void ConfigInput(void * hParent) void ConfigInput(void * hParent)
{ {
@ -321,6 +372,21 @@ void CInputConfigUI::UpdateDeviceMapping(void)
} }
} }
void CInputConfigUI::RemoveMapping(const BUTTON & Button)
{
CControllerSettings * Pages[] = {
&m_pgController0,
&m_pgController1,
&m_pgController2,
&m_pgController3
};
for (size_t i = 0, n = (sizeof(Pages) / sizeof(Pages[0])); i < n; i++)
{
Pages[i]->RemoveMapping(Button);
}
}
void ConfigUIDeviceAdded(void) void ConfigUIDeviceAdded(void)
{ {
if (g_ConfigUI != nullptr) if (g_ConfigUI != nullptr)

View File

@ -27,6 +27,7 @@ static const uint32_t Default_DeadZone = 25;
static const uint32_t Default_Range = 100; static const uint32_t Default_Range = 100;
static const uint32_t Default_Plugin = PLUGIN_MEMPAK; static const uint32_t Default_Plugin = PLUGIN_MEMPAK;
static const bool Default_RealN64Range = true; static const bool Default_RealN64Range = true;
static const bool Default_RemoveDuplicate = true;
CInputSettings::CInputSettings() CInputSettings::CInputSettings()
{ {
@ -82,6 +83,7 @@ void CInputSettings::LoadController(uint32_t ControlIndex, CONTROL & ControllerI
InputSettingID RangeSettings[] = { Set_Control0_Range }; InputSettingID RangeSettings[] = { Set_Control0_Range };
InputSettingID DeadZoneSettings[] = { Set_Control0_Deadzone }; InputSettingID DeadZoneSettings[] = { Set_Control0_Deadzone };
InputSettingID RealN64RangeSettings[] = { Set_Control0_RealN64Range }; InputSettingID RealN64RangeSettings[] = { Set_Control0_RealN64Range };
InputSettingID RemoveDuplicateSettings[] = { Set_Control0_RemoveDuplicate };
ControllerInfo.Present = ControlIndex < (sizeof(PresentSettings) / sizeof(PresentSettings[0])) ? GetSetting((short)PresentSettings[ControlIndex]) != 0 : 0; ControllerInfo.Present = ControlIndex < (sizeof(PresentSettings) / sizeof(PresentSettings[0])) ? GetSetting((short)PresentSettings[ControlIndex]) != 0 : 0;
ControllerInfo.Plugin = ControlIndex < (sizeof(PluginSettings) / sizeof(PluginSettings[0])) ? GetSetting((short)PluginSettings[ControlIndex]) : Default_Plugin; ControllerInfo.Plugin = ControlIndex < (sizeof(PluginSettings) / sizeof(PluginSettings[0])) ? GetSetting((short)PluginSettings[ControlIndex]) : Default_Plugin;
@ -91,6 +93,7 @@ void CInputSettings::LoadController(uint32_t ControlIndex, CONTROL & ControllerI
Controller.DeadZone = (uint8_t)(ControlIndex < (sizeof(DeadZoneSettings) / sizeof(DeadZoneSettings[0])) ? GetSetting((short)DeadZoneSettings[ControlIndex]) : Default_DeadZone); Controller.DeadZone = (uint8_t)(ControlIndex < (sizeof(DeadZoneSettings) / sizeof(DeadZoneSettings[0])) ? GetSetting((short)DeadZoneSettings[ControlIndex]) : Default_DeadZone);
if (Controller.DeadZone > 100) { Controller.DeadZone = 100; } if (Controller.DeadZone > 100) { Controller.DeadZone = 100; }
Controller.RealN64Range = (ControlIndex < (sizeof(RealN64RangeSettings) / sizeof(RealN64RangeSettings[0])) ? GetSetting((short)RealN64RangeSettings[ControlIndex]) != 0 : Default_RealN64Range); Controller.RealN64Range = (ControlIndex < (sizeof(RealN64RangeSettings) / sizeof(RealN64RangeSettings[0])) ? GetSetting((short)RealN64RangeSettings[ControlIndex]) != 0 : Default_RealN64Range);
Controller.RemoveDuplicate = (ControlIndex < (sizeof(RemoveDuplicateSettings) / sizeof(RemoveDuplicateSettings[0])) ? GetSetting((short)RemoveDuplicateSettings[ControlIndex]) != 0 : Default_RemoveDuplicate);
} }
void CInputSettings::SaveController(uint32_t ControlIndex, const CONTROL & ControllerInfo, const N64CONTROLLER & Controller) void CInputSettings::SaveController(uint32_t ControlIndex, const CONTROL & ControllerInfo, const N64CONTROLLER & Controller)
@ -128,6 +131,7 @@ void CInputSettings::SaveController(uint32_t ControlIndex, const CONTROL & Contr
InputSettingID RangeSettings[] = { Set_Control0_Range }; InputSettingID RangeSettings[] = { Set_Control0_Range };
InputSettingID DeadzoneSettings[] = { Set_Control0_Deadzone }; InputSettingID DeadzoneSettings[] = { Set_Control0_Deadzone };
InputSettingID RealN64RangeSettings[] = { Set_Control0_RealN64Range }; InputSettingID RealN64RangeSettings[] = { Set_Control0_RealN64Range };
InputSettingID RemoveDuplicateSettings[] = { Set_Control0_RemoveDuplicate };
for (size_t i = 0, n = sizeof(Buttons) / sizeof(Buttons[0]); i < n; i++) for (size_t i = 0, n = sizeof(Buttons) / sizeof(Buttons[0]); i < n; i++)
{ {
@ -160,6 +164,10 @@ void CInputSettings::SaveController(uint32_t ControlIndex, const CONTROL & Contr
{ {
SetSetting((short)RealN64RangeSettings[ControlIndex], Controller.RealN64Range ? 1 : 0); SetSetting((short)RealN64RangeSettings[ControlIndex], Controller.RealN64Range ? 1 : 0);
} }
if (ControlIndex < (sizeof(RemoveDuplicateSettings) / sizeof(RemoveDuplicateSettings[0])))
{
SetSetting((short)RemoveDuplicateSettings[ControlIndex], Controller.RemoveDuplicate ? 1 : 0);
}
FlushSettings(); FlushSettings();
} }
@ -242,6 +250,7 @@ void CInputSettings::RegisterSettings(void)
RegisterSetting(Set_Control0_Range, Data_DWORD_General, "Range", "Controller 1", Default_Range, nullptr); RegisterSetting(Set_Control0_Range, Data_DWORD_General, "Range", "Controller 1", Default_Range, nullptr);
RegisterSetting(Set_Control0_Deadzone, Data_DWORD_General, "Deadzone", "Controller 1", Default_DeadZone, nullptr); RegisterSetting(Set_Control0_Deadzone, Data_DWORD_General, "Deadzone", "Controller 1", Default_DeadZone, nullptr);
RegisterSetting(Set_Control0_RealN64Range, Data_DWORD_General, "RealN64Range", "Controller 1", Default_RealN64Range, nullptr); RegisterSetting(Set_Control0_RealN64Range, Data_DWORD_General, "RealN64Range", "Controller 1", Default_RealN64Range, nullptr);
RegisterSetting(Set_Control0_RemoveDuplicate, Data_DWORD_General, "Remove Duplicate", "Controller 1", Default_RemoveDuplicate, nullptr);
RegisterSetting(Set_Control0_U_DPAD, Data_String_General, "DPadUp", "Controller 1", 0, Control0_U_DPAD_Default); RegisterSetting(Set_Control0_U_DPAD, Data_String_General, "DPadUp", "Controller 1", 0, Control0_U_DPAD_Default);
RegisterSetting(Set_Control0_D_DPAD, Data_String_General, "DPadDown", "Controller 1", 0, Control0_D_DPAD_Default); RegisterSetting(Set_Control0_D_DPAD, Data_String_General, "DPadDown", "Controller 1", 0, Control0_D_DPAD_Default);
RegisterSetting(Set_Control0_L_DPAD, Data_String_General, "DPadLeft", "Controller 1", 0, Control0_L_DPAD_Default); RegisterSetting(Set_Control0_L_DPAD, Data_String_General, "DPadLeft", "Controller 1", 0, Control0_L_DPAD_Default);

View File

@ -7,6 +7,7 @@ enum InputSettingID
Set_Control0_Range, Set_Control0_Range,
Set_Control0_Deadzone, Set_Control0_Deadzone,
Set_Control0_RealN64Range, Set_Control0_RealN64Range,
Set_Control0_RemoveDuplicate,
Set_Control0_U_DPAD, Set_Control0_U_DPAD,
Set_Control0_D_DPAD, Set_Control0_D_DPAD,
Set_Control0_L_DPAD, Set_Control0_L_DPAD,

View File

@ -24,4 +24,5 @@ typedef struct
uint8_t Range; uint8_t Range;
uint8_t DeadZone; uint8_t DeadZone;
bool RealN64Range; bool RealN64Range;
bool RemoveDuplicate;
} N64CONTROLLER; } N64CONTROLLER;

View File

@ -27,6 +27,7 @@ public:
CenterWindow(GetParent()); CenterWindow(GetParent());
SetWindowText(stdstr_f("Options - Player %d", m_ControlIndex + 1).ToUTF16().c_str()); SetWindowText(stdstr_f("Options - Player %d", m_ControlIndex + 1).ToUTF16().c_str());
CButton(GetDlgItem(IDC_REAL_N64_RANGE)).SetCheck(m_Controller.RealN64Range ? BST_CHECKED : BST_UNCHECKED); CButton(GetDlgItem(IDC_REAL_N64_RANGE)).SetCheck(m_Controller.RealN64Range ? BST_CHECKED : BST_UNCHECKED);
CButton(GetDlgItem(IDC_REMOVE_DUPLICATE)).SetCheck(m_Controller.RemoveDuplicate ? BST_CHECKED : BST_UNCHECKED);
return TRUE; return TRUE;
} }
LRESULT OnOkCmd(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/) LRESULT OnOkCmd(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
@ -38,6 +39,12 @@ public:
m_Controller.RealN64Range = RealN64Range; m_Controller.RealN64Range = RealN64Range;
bChanged = true; bChanged = true;
} }
bool RemoveDuplicate = CButton(GetDlgItem(IDC_REMOVE_DUPLICATE)).GetCheck() == BST_CHECKED;
if (RemoveDuplicate != m_Controller.RemoveDuplicate)
{
m_Controller.RemoveDuplicate = RemoveDuplicate;
bChanged = true;
}
if (bChanged) if (bChanged)
{ {
GetParent().SendMessage(PSM_CHANGED); GetParent().SendMessage(PSM_CHANGED);

Binary file not shown.

View File

@ -60,11 +60,11 @@ void CScanButton::OnTimer(UINT_PTR nIDEvent)
CDirectInput::ScanResult Result = g_InputPlugin->ScanDevices(Button); CDirectInput::ScanResult Result = g_InputPlugin->ScanDevices(Button);
if (Result == CDirectInput::SCAN_SUCCEED && (Button.Offset != m_Button.Offset || Button.AxisID != m_Button.AxisID || Button.BtnType != m_Button.BtnType)) if (Result == CDirectInput::SCAN_SUCCEED && (Button.Offset != m_Button.Offset || Button.AxisID != m_Button.AxisID || Button.BtnType != m_Button.BtnType))
{ {
m_Button = Button;
if (m_ChangeCallback != nullptr) if (m_ChangeCallback != nullptr)
{ {
m_ChangeCallback(m_ChangeCallbackData); m_ChangeCallback(m_ChangeCallbackData, Button);
} }
m_Button = Button;
} }
if (Result == CDirectInput::SCAN_SUCCEED || Result == CDirectInput::SCAN_ESCAPE) if (Result == CDirectInput::SCAN_SUCCEED || Result == CDirectInput::SCAN_ESCAPE)
{ {

View File

@ -15,7 +15,7 @@ public:
WM_SCAN_SUCCESS = WM_USER + 0x140, WM_SCAN_SUCCESS = WM_USER + 0x140,
WM_SCAN_CANCELED = WM_USER + 0x141, WM_SCAN_CANCELED = WM_USER + 0x141,
}; };
typedef void(*ChangeCallback)(size_t Data); typedef void(*ChangeCallback)(size_t Data, const BUTTON & Button);
CScanButton(BUTTON & Button, int DisplayCtrlId, int ScanBtnId); CScanButton(BUTTON & Button, int DisplayCtrlId, int ScanBtnId);