Project64-input: Add reset button

This commit is contained in:
zilmar 2020-07-15 21:08:48 +09:30
parent bdb670f48c
commit 22adc2e782
5 changed files with 92 additions and 15 deletions

View File

@ -119,3 +119,16 @@ bool CProject64Input::SaveController(uint32_t ControlIndex)
m_DirectInput->MapControllerDevice(m_Controllers[ControlIndex]); m_DirectInput->MapControllerDevice(m_Controllers[ControlIndex]);
return true; return true;
} }
bool CProject64Input::ResetController(uint32_t ControlIndex)
{
CGuard guard(m_CS);
if (ControlIndex >= sizeof(m_Controllers) / sizeof(m_Controllers[0]))
{
return false;
}
g_Settings->ResetController(ControlIndex, m_ControlInfo.Controls[ControlIndex], m_Controllers[ControlIndex]);
m_DirectInput->MapControllerDevice(m_Controllers[ControlIndex]);
return true;
}

View File

@ -19,6 +19,7 @@ public:
CDirectInput::ScanResult ScanDevices(BUTTON & Button); CDirectInput::ScanResult ScanDevices(BUTTON & Button);
std::wstring ButtonAssignment(BUTTON & Button); std::wstring ButtonAssignment(BUTTON & Button);
bool SaveController(uint32_t ControlIndex); bool SaveController(uint32_t ControlIndex);
bool ResetController(uint32_t ControlIndex);
inline HINSTANCE hInst(void) const { return m_hinst; } inline HINSTANCE hInst(void) const { return m_hinst; }
inline bool IsScanning(void) const { return m_Scanning; } inline bool IsScanning(void) const { return m_Scanning; }

View File

@ -20,6 +20,7 @@ public:
BEGIN_MSG_MAP(CControllerSettings) BEGIN_MSG_MAP(CControllerSettings)
MSG_WM_INITDIALOG(OnInitDialog) MSG_WM_INITDIALOG(OnInitDialog)
MSG_WM_CTLCOLORSTATIC(OnCtlColorStatic) MSG_WM_CTLCOLORSTATIC(OnCtlColorStatic)
COMMAND_HANDLER_EX(IDC_BTN_DEFAULTS, BN_CLICKED, DefaultBtnClicked)
COMMAND_HANDLER_EX(IDC_BTN_SETUP, BN_CLICKED, SetupBtnClicked) COMMAND_HANDLER_EX(IDC_BTN_SETUP, BN_CLICKED, SetupBtnClicked)
COMMAND_HANDLER_EX(IDC_CHK_PLUGGED_IN, BN_CLICKED, ItemChanged) COMMAND_HANDLER_EX(IDC_CHK_PLUGGED_IN, BN_CLICKED, ItemChanged)
COMMAND_HANDLER_EX(IDC_CMB_DEVICE, CBN_SELCHANGE, ItemChanged) COMMAND_HANDLER_EX(IDC_CMB_DEVICE, CBN_SELCHANGE, ItemChanged)
@ -39,9 +40,11 @@ private:
LRESULT OnScroll(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); LRESULT OnScroll(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
LRESULT OnScanSuccess(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); LRESULT OnScanSuccess(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
LRESULT OnScanCanceled(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); LRESULT OnScanCanceled(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
void DefaultBtnClicked(UINT Code, int id, HWND ctl);
void SetupBtnClicked(UINT Code, int id, HWND ctl); void SetupBtnClicked(UINT Code, int id, HWND ctl);
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 ButtonChannged(void); void ButtonChannged(void);
static void stButtonChanged(size_t data) { ((CControllerSettings *)data)->ButtonChannged(); } static void stButtonChanged(size_t data) { ((CControllerSettings *)data)->ButtonChannged(); }
@ -89,32 +92,17 @@ CControllerSettings::CControllerSettings(uint32_t ControllerNumber) :
BOOL CControllerSettings::OnInitDialog(CWindow /*wndFocus*/, LPARAM /*lInitParam*/) BOOL CControllerSettings::OnInitDialog(CWindow /*wndFocus*/, LPARAM /*lInitParam*/)
{ {
N64CONTROLLER & Controller = g_InputPlugin->Controllers(m_ControllerNumber);
CONTROL & ControlInfo = g_InputPlugin->ControlInfo(m_ControllerNumber);
GetDlgItem(IDC_BTN_DEFAULTS).EnableWindow(false);
GetDlgItem(IDC_BTN_LOAD).EnableWindow(false); GetDlgItem(IDC_BTN_LOAD).EnableWindow(false);
GetDlgItem(IDC_BTN_SAVE).EnableWindow(false); GetDlgItem(IDC_BTN_SAVE).EnableWindow(false);
m_Range.Attach(GetDlgItem(IDC_SLIDER_RANGE)); m_Range.Attach(GetDlgItem(IDC_SLIDER_RANGE));
m_Range.SetTicFreq(1); m_Range.SetTicFreq(1);
m_Range.SetRangeMin(1); m_Range.SetRangeMin(1);
m_Range.SetRangeMax(100); m_Range.SetRangeMax(100);
m_Range.SetPos(Controller.Range);
CWindow(GetDlgItem(IDC_LABEL_RANGE)).SetWindowText(stdstr_f("%d%%", m_Range.GetPos()).ToUTF16().c_str());
m_PluggedIn.Attach(GetDlgItem(IDC_CHK_PLUGGED_IN)); m_PluggedIn.Attach(GetDlgItem(IDC_CHK_PLUGGED_IN));
m_PluggedIn.SetCheck(ControlInfo.Present != 0 ? BST_CHECKED : BST_UNCHECKED);
m_cmbDevice.Attach(GetDlgItem(IDC_CMB_DEVICE)); m_cmbDevice.Attach(GetDlgItem(IDC_CMB_DEVICE));
m_cmbDevice.SetItemData(m_cmbDevice.AddString(L"None"), PLUGIN_NONE); m_cmbDevice.SetItemData(m_cmbDevice.AddString(L"None"), PLUGIN_NONE);
m_cmbDevice.SetItemData(m_cmbDevice.AddString(L"Mem Pak"), PLUGIN_MEMPAK); m_cmbDevice.SetItemData(m_cmbDevice.AddString(L"Mem Pak"), PLUGIN_MEMPAK);
m_cmbDevice.SetItemData(m_cmbDevice.AddString(L"Rumble Pak"), PLUGIN_RUMBLE_PAK); m_cmbDevice.SetItemData(m_cmbDevice.AddString(L"Rumble Pak"), PLUGIN_RUMBLE_PAK);
m_cmbDevice.SetCurSel(0);
for (DWORD i = 0, n = m_cmbDevice.GetCount(); i < n; i++)
{
if (m_cmbDevice.GetItemData(i) == (DWORD)ControlInfo.Plugin)
{
m_cmbDevice.SetCurSel(i);
break;
}
}
m_ControllerImg.SubclassWindow(GetDlgItem(IDC_BMP_CONTROLLER)); m_ControllerImg.SubclassWindow(GetDlgItem(IDC_BMP_CONTROLLER));
m_ControllerImg.SetBitmap(MAKEINTRESOURCE(IDB_CONTROLLER)); m_ControllerImg.SetBitmap(MAKEINTRESOURCE(IDB_CONTROLLER));
@ -130,6 +118,7 @@ BOOL CControllerSettings::OnInitDialog(CWindow /*wndFocus*/, LPARAM /*lInitParam
Buttons[i]->SubclassWindow(m_hWnd); Buttons[i]->SubclassWindow(m_hWnd);
Buttons[i]->SetChangeCallback(stButtonChanged, (size_t)this); Buttons[i]->SetChangeCallback(stButtonChanged, (size_t)this);
} }
DisplayController();
return TRUE; return TRUE;
} }
@ -196,6 +185,13 @@ LRESULT CControllerSettings::OnScanCanceled(UINT /*uMsg*/, WPARAM /*wParam*/, LP
return 0; return 0;
} }
void CControllerSettings::DefaultBtnClicked(UINT Code, int id, HWND ctl)
{
g_InputPlugin->ResetController(m_ControllerNumber);
DisplayController();
SendMessage(GetParent(), PSM_CHANGED, (WPARAM)m_hWnd, 0);
}
void CControllerSettings::SetupBtnClicked(UINT /*Code*/, int /*id*/, HWND /*ctl*/) void CControllerSettings::SetupBtnClicked(UINT /*Code*/, int /*id*/, HWND /*ctl*/)
{ {
m_SetupIndex = 0; m_SetupIndex = 0;
@ -213,6 +209,35 @@ LRESULT CControllerSettings::ItemChangedNotify(NMHDR* /*pNMHDR*/)
return 0; return 0;
} }
void CControllerSettings::DisplayController(void)
{
N64CONTROLLER & Controller = g_InputPlugin->Controllers(m_ControllerNumber);
CONTROL & ControlInfo = g_InputPlugin->ControlInfo(m_ControllerNumber);
m_cmbDevice.SetCurSel(0);
for (DWORD i = 0, n = m_cmbDevice.GetCount(); i < n; i++)
{
if (m_cmbDevice.GetItemData(i) == (DWORD)ControlInfo.Plugin)
{
m_cmbDevice.SetCurSel(i);
break;
}
}
m_PluggedIn.SetCheck(ControlInfo.Present != 0 ? BST_CHECKED : BST_UNCHECKED);
m_Range.SetPos(Controller.Range);
CWindow(GetDlgItem(IDC_LABEL_RANGE)).SetWindowText(stdstr_f("%d%%", m_Range.GetPos()).ToUTF16().c_str());
CScanButton * Buttons[] = {
&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
};
for (size_t i = 0, n = sizeof(Buttons) / sizeof(Buttons[0]); i < n; i++)
{
Buttons[i]->DisplayButton();
}
}
void CControllerSettings::ButtonChannged(void) void CControllerSettings::ButtonChannged(void)
{ {
CPropertySheetWindow(GetParent()).SetModified(m_hWnd); CPropertySheetWindow(GetParent()).SetModified(m_hWnd);

View File

@ -121,6 +121,43 @@ void CInputSettings::SaveController(uint32_t ControlIndex, const CONTROL & Contr
FlushSettings(); FlushSettings();
} }
void CInputSettings::ResetController(uint32_t ControlIndex, CONTROL & ControllerInfo, N64CONTROLLER & Controller)
{
struct {
const BUTTON & Button;
InputSettingID SettingId;
uint32_t ControlIndex;
}
Buttons[] =
{
{ Controller.U_DPAD, Set_Control0_U_DPAD, 0 },
{ Controller.D_DPAD, Set_Control0_D_DPAD, 0 },
{ Controller.L_DPAD, Set_Control0_L_DPAD, 0 },
{ Controller.R_DPAD, Set_Control0_R_DPAD, 0 },
{ Controller.A_BUTTON, Set_Control0_A_BUTTON, 0 },
{ Controller.B_BUTTON, Set_Control0_B_BUTTON, 0 },
{ Controller.U_CBUTTON, Set_Control0_U_CBUTTON, 0 },
{ Controller.D_CBUTTON, Set_Control0_D_CBUTTON, 0 },
{ Controller.L_CBUTTON, Set_Control0_L_CBUTTON, 0 },
{ Controller.R_CBUTTON, Set_Control0_R_CBUTTON, 0 },
{ Controller.START_BUTTON, Set_Control0_START_BUTTON, 0 },
{ Controller.Z_TRIG, Set_Control0_Z_TRIG, 0 },
{ Controller.R_TRIG, Set_Control0_R_TRIG, 0 },
{ Controller.L_TRIG, Set_Control0_L_TRIG, 0 },
{ Controller.U_ANALOG, Set_Control0_U_ANALOG, 0 },
{ Controller.D_ANALOG, Set_Control0_D_ANALOG, 0 },
{ Controller.L_ANALOG, Set_Control0_L_ANALOG, 0 },
{ Controller.R_ANALOG, Set_Control0_R_ANALOG, 0 },
};
for (size_t i = 0, n = sizeof(Buttons) / sizeof(Buttons[0]); i < n; i++)
{
SetSettingSz((short)Buttons[i].SettingId, NULL);
}
FlushSettings();
LoadController(ControlIndex, ControllerInfo, Controller);
}
BUTTON CInputSettings::StrToButton(const char * Buffer) BUTTON CInputSettings::StrToButton(const char * Buffer)
{ {
BUTTON Button = { 0 }; BUTTON Button = { 0 };

View File

@ -12,6 +12,7 @@ public:
void LoadController(uint32_t ControlIndex, CONTROL & ControllerInfo, N64CONTROLLER & Controller); void LoadController(uint32_t ControlIndex, CONTROL & ControllerInfo, N64CONTROLLER & Controller);
void SaveController(uint32_t ControlIndex, const CONTROL & ControllerInfo, const N64CONTROLLER & Controller); void SaveController(uint32_t ControlIndex, const CONTROL & ControllerInfo, const N64CONTROLLER & Controller);
void ResetController(uint32_t ControlIndex, CONTROL & ControllerInfo, N64CONTROLLER & Controller);
private: private:
CInputSettings(const CInputSettings&); CInputSettings(const CInputSettings&);