diff --git a/Source/Plugins/Plugin_PadSimple/Src/GUI/ConfigDlg.cpp b/Source/Plugins/Plugin_PadSimple/Src/GUI/ConfigDlg.cpp index fc4bdcb95c..7c70242ff9 100644 --- a/Source/Plugins/Plugin_PadSimple/Src/GUI/ConfigDlg.cpp +++ b/Source/Plugins/Plugin_PadSimple/Src/GUI/ConfigDlg.cpp @@ -30,10 +30,11 @@ BEGIN_EVENT_TABLE(ConfigDialog,wxDialog) EVT_CLOSE(ConfigDialog::OnClose) EVT_BUTTON(ID_CLOSE,ConfigDialog::OnCloseClick) EVT_BUTTON(ID_PAD_ABOUT,ConfigDialog::DllAbout) - EVT_CHOICE(ID_DEVICENAME,ConfigDialog::DeviceChanged) - EVT_CHECKBOX(ID_ATTACHED,ConfigDialog::AttachedCheck) - EVT_CHECKBOX(ID_DISABLE,ConfigDialog::DisableCheck) - EVT_CHECKBOX(ID_RUMBLE,ConfigDialog::RumbleCheck) + EVT_CHECKBOX(ID_ATTACHED,ConfigDialog::ControllerSettingsChanged) + EVT_CHECKBOX(ID_X360PAD,ConfigDialog::ControllerSettingsChanged) + EVT_CHOICE(ID_X360PAD_CHOICE,ConfigDialog::ControllerSettingsChanged) + EVT_CHECKBOX(ID_RUMBLE,ConfigDialog::ControllerSettingsChanged) + EVT_CHECKBOX(ID_DISABLE,ConfigDialog::ControllerSettingsChanged) EVT_BUTTON(CTL_A,ConfigDialog::OnButtonClick) EVT_BUTTON(CTL_B,ConfigDialog::OnButtonClick) EVT_BUTTON(CTL_X,ConfigDialog::OnButtonClick) @@ -128,44 +129,57 @@ void ConfigDialog::CreateGUIControls() this->SetSizer(sMain); this->Layout(); - wxArrayString arrayStringFor_DeviceName; +#ifdef _WIN32 + // Add connected XPads + for (int x = 0; x < 4; x++) + { + XINPUT_STATE xstate; + DWORD xresult = XInputGetState(x, &xstate); + if (xresult == ERROR_SUCCESS) + { + arrayStringFor_X360Pad.Add(wxString::Format("%i", x+1)); + } + } +#endif + for(int i = 0; i < 4; i++) { - sDevice[i] = new wxStaticBoxSizer(wxVERTICAL, m_Controller[i], wxT("Controller:")); - sDeviceTop[i] = new wxBoxSizer(wxHORIZONTAL); - sDeviceBottom[i] = new wxBoxSizer(wxHORIZONTAL); - m_DeviceName[i] = new wxChoice(m_Controller[i], ID_DEVICENAME, wxDefaultPosition, wxDefaultSize, arrayStringFor_DeviceName, 0, wxDefaultValidator); + sbDevice[i] = new wxStaticBoxSizer(wxVERTICAL, m_Controller[i], wxT("Controller Settings")); + sDevice[i] = new wxBoxSizer(wxHORIZONTAL); m_Attached[i] = new wxCheckBox(m_Controller[i], ID_ATTACHED, wxT("Controller attached"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator); - m_Disable[i] = new wxCheckBox(m_Controller[i], ID_DISABLE, wxT("Disable when Dolphin is not in focus"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator); + m_X360Pad[i] = new wxCheckBox(m_Controller[i], ID_X360PAD, wxT("Use X360Pad"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator); + m_X360PadC[i] = new wxChoice(m_Controller[i], ID_X360PAD_CHOICE, wxDefaultPosition, wxDefaultSize, arrayStringFor_X360Pad, 0, wxDefaultValidator); m_Rumble[i] = new wxCheckBox(m_Controller[i], ID_RUMBLE, wxT("Enable rumble"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator); - m_Attached[i]->SetValue(pad[i].attached); - m_Disable[i]->SetValue(pad[i].disable); - m_Rumble[i]->SetValue(pad[i].rumble); - m_Rumble[i]->Enable(!pad[i].keyboard); - - m_DeviceName[i]->Append(_("Keyboard")); -#ifdef _WIN32 - // Add connected XPads - for (int x = 0; x < 4; x++) + m_Disable[i] = new wxCheckBox(m_Controller[i], ID_DISABLE, wxT("Disable when Dolphin is not in focus"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator); + m_Attached[i]->SetValue(pad[i].bAttached); + if (arrayStringFor_X360Pad.IsEmpty()) { - XINPUT_STATE xstate; - DWORD xresult = XInputGetState(x, &xstate); - - if (xresult == ERROR_SUCCESS) - { - m_DeviceName[i]->Append(wxString::Format("XPad %i", x+1)); - } + m_X360Pad[i]->SetLabel(wxT("Use X360Pad - No pad connected")); + m_X360Pad[i]->SetValue(false); + m_X360Pad[i]->Enable(false); + pad[i].bEnableXPad = false; + m_X360PadC[i]->Hide(); + m_Rumble[i]->Hide(); } -#endif - sDeviceTop[i]->Add(m_DeviceName[i], 1, wxEXPAND|wxALL, 1); - sDeviceTop[i]->Add(m_Attached[i], 0, wxEXPAND|wxALL, 1); - sDeviceBottom[i]->AddStretchSpacer(1); - sDeviceBottom[i]->Add(m_Disable[i], 0, wxEXPAND|wxALL, 1); - sDeviceBottom[i]->Add(m_Rumble[i], 0, wxEXPAND|wxALL, 1); - sDeviceBottom[i]->AddStretchSpacer(1); - sDevice[i]->Add(sDeviceTop[i], 0, wxEXPAND|wxALL, 1); - sDevice[i]->Add(sDeviceBottom[i], 0, wxEXPAND|wxALL, 1); + else + { + m_X360Pad[i]->SetValue(pad[i].bEnableXPad); + m_X360PadC[i]->SetSelection(pad[i].XPadPlayer); + m_X360PadC[i]->Enable(m_X360Pad[i]->IsChecked()); + m_Rumble[i]->SetValue(pad[i].bRumble); + m_Rumble[i]->Enable(m_X360Pad[i]->IsChecked()); + } + m_Disable[i]->SetValue(pad[i].bDisable); + + sDevice[i]->Add(m_Attached[i], 0, wxEXPAND|wxALL, 1); + sDevice[i]->AddStretchSpacer(); + sDevice[i]->Add(m_X360Pad[i], 0, wxEXPAND|wxALL, 1); + sDevice[i]->Add(m_X360PadC[i], 0, wxEXPAND|wxALL, 1); + sDevice[i]->Add(m_Rumble[i], 0, wxEXPAND|wxALL, 1); + sDevice[i]->AddStretchSpacer(); + sDevice[i]->Add(m_Disable[i], 0, wxEXPAND|wxALL, 1); + sbDevice[i]->Add(sDevice[i], 0, wxEXPAND|wxALL, 1); sButtons[i] = new wxStaticBoxSizer(wxVERTICAL, m_Controller[i], wxT("Buttons:")); @@ -209,7 +223,7 @@ void ConfigDialog::CreateGUIControls() sPage[i] = new wxGridBagSizer(0, 0); sPage[i]->SetFlexibleDirection(wxBOTH); sPage[i]->SetNonFlexibleGrowMode(wxFLEX_GROWMODE_SPECIFIED); - sPage[i]->Add(sDevice[i], wxGBPosition(0, 0), wxGBSpan(1, 5), wxEXPAND|wxALL, 1); + sPage[i]->Add(sbDevice[i], wxGBPosition(0, 0), wxGBSpan(1, 5), wxEXPAND|wxALL, 1); sPage[i]->Add(sButtons[i], wxGBPosition(1, 0), wxGBSpan(2, 1), wxALL, 1); sPage[i]->Add(sTriggers[i], wxGBPosition(1, 1), wxGBSpan(1, 1), wxEXPAND|wxALL, 1); sPage[i]->Add(sModifiers[i], wxGBPosition(2, 1), wxGBSpan(1, 1), wxALL, 1); @@ -218,17 +232,6 @@ void ConfigDialog::CreateGUIControls() sPage[i]->Add(sCStick[i], wxGBPosition(1, 4), wxGBSpan(2, 1), wxALL, 1); m_Controller[i]->SetSizer(sPage[i]); sPage[i]->Layout(); - - if (pad[i].keyboard) - { - m_DeviceName[i]->SetSelection(0); - EnableKeyboardConfig(i, true); - } - else - { - m_DeviceName[i]->SetSelection(pad[i].xpadplayer + 1); - EnableKeyboardConfig(i, false); - } } SetIcon(wxNullIcon); @@ -278,68 +281,30 @@ void ConfigDialog::OnCloseClick(wxCommandEvent& event) Close(); } -void ConfigDialog::DeviceChanged(wxCommandEvent& event) +void ConfigDialog::ControllerSettingsChanged(wxCommandEvent& event) { int page = m_Notebook->GetSelection(); - if(event.GetSelection() == 0) + switch (event.GetId()) { - // Keyboard - pad[page].keyboard = true; - m_Rumble[page]->Disable(); - EnableKeyboardConfig(page, true); + case ID_ATTACHED: + pad[page].bAttached = m_Attached[page]->GetValue(); + break; + case ID_X360PAD: + pad[page].bEnableXPad = event.IsChecked(); + m_Rumble[page]->Enable(event.IsChecked()); + m_X360PadC[page]->Enable(event.IsChecked()); + break; + case ID_X360PAD_CHOICE: + pad[page].XPadPlayer = event.GetSelection(); + break; + case ID_RUMBLE: + pad[page].bRumble = m_Rumble[page]->GetValue(); + break; + case ID_DISABLE: + pad[page].bDisable = m_Disable[page]->GetValue(); + break; } - else - { - // XPad, so also set xpadplayer - pad[page].keyboard = false; - pad[page].xpadplayer = event.GetSelection() - 1; - m_Rumble[page]->Enable(); - EnableKeyboardConfig(page, false); - } -} - -void ConfigDialog::EnableKeyboardConfig(int page, bool a) -{ - m_ButtonA[page]->Enable(a); - m_ButtonB[page]->Enable(a); - m_ButtonX[page]->Enable(a); - m_ButtonY[page]->Enable(a); - m_ButtonZ[page]->Enable(a); - m_ButtonStart[page]->Enable(a); - m_ButtonL[page]->Enable(a); - m_ButtonR[page]->Enable(a); - m_HalfPress[page]->Enable(a); - m_StickUp[page]->Enable(a); - m_StickDown[page]->Enable(a); - m_StickLeft[page]->Enable(a); - m_StickRight[page]->Enable(a); - m_CStickUp[page]->Enable(a); - m_CStickDown[page]->Enable(a); - m_CStickLeft[page]->Enable(a); - m_CStickRight[page]->Enable(a); - m_DPadUp[page]->Enable(a); - m_DPadDown[page]->Enable(a); - m_DPadLeft[page]->Enable(a); - m_DPadRight[page]->Enable(a); -} - -void ConfigDialog::AttachedCheck(wxCommandEvent& event) -{ - int page = m_Notebook->GetSelection(); - pad[page].attached = m_Attached[page]->GetValue(); -} - -void ConfigDialog::DisableCheck(wxCommandEvent& event) -{ - int page = m_Notebook->GetSelection(); - pad[page].disable = m_Disable[page]->GetValue(); -} - -void ConfigDialog::RumbleCheck(wxCommandEvent& event) -{ - int page = m_Notebook->GetSelection(); - pad[page].rumble = m_Rumble[page]->GetValue(); } void ConfigDialog::OnButtonClick(wxCommandEvent& event) diff --git a/Source/Plugins/Plugin_PadSimple/Src/GUI/ConfigDlg.h b/Source/Plugins/Plugin_PadSimple/Src/GUI/ConfigDlg.h index d7f270b5d4..f35e5d015a 100644 --- a/Source/Plugins/Plugin_PadSimple/Src/GUI/ConfigDlg.h +++ b/Source/Plugins/Plugin_PadSimple/Src/GUI/ConfigDlg.h @@ -24,7 +24,7 @@ #include #include #include -#include +#include #include #include #include @@ -54,9 +54,8 @@ class ConfigDialog : public wxDialog wxButton *m_About; wxButton *m_Close; - wxStaticBoxSizer *sDevice[4]; - wxBoxSizer *sDeviceTop[4]; - wxBoxSizer *sDeviceBottom[4]; + wxStaticBoxSizer *sbDevice[4]; + wxBoxSizer *sDevice[4]; wxGridBagSizer *sPage[4]; wxStaticBoxSizer *sButtons[4]; wxStaticBoxSizer *sTriggers[4]; @@ -65,7 +64,9 @@ class ConfigDialog : public wxDialog wxStaticBoxSizer *sCStick[4]; wxStaticBoxSizer *sDPad[4]; - wxChoice *m_DeviceName[4]; + wxArrayString arrayStringFor_X360Pad; + wxCheckBox *m_X360Pad[4]; + wxChoice *m_X360PadC[4]; wxCheckBox *m_Attached[4]; wxCheckBox *m_Disable[4]; wxCheckBox *m_Rumble[4]; @@ -102,24 +103,19 @@ class ConfigDialog : public wxDialog ID_CONTROLLERPAGE3, ID_CONTROLLERPAGE4, - ID_DEVICENAME, + ID_X360PAD_CHOICE, + ID_X360PAD, ID_ATTACHED, ID_DISABLE, ID_RUMBLE, - ID_PAD_ABOUT, - - ID_DUMMY_VALUE_ //don't remove this value unless you have other enum values + ID_PAD_ABOUT }; void OnClose(wxCloseEvent& event); void CreateGUIControls(); void OnCloseClick(wxCommandEvent& event); void OnKeyDown(wxKeyEvent& event); - void DeviceChanged(wxCommandEvent& event); - void EnableKeyboardConfig(int page, bool a); - void AttachedCheck(wxCommandEvent& event); - void DisableCheck(wxCommandEvent& event); - void RumbleCheck(wxCommandEvent& event); + void ControllerSettingsChanged(wxCommandEvent& event); void OnButtonClick(wxCommandEvent& event); void DllAbout(wxCommandEvent& event); diff --git a/Source/Plugins/Plugin_PadSimple/Src/PadSimple.cpp b/Source/Plugins/Plugin_PadSimple/Src/PadSimple.cpp index 1b55d32101..47c2b1a75e 100644 --- a/Source/Plugins/Plugin_PadSimple/Src/PadSimple.cpp +++ b/Source/Plugins/Plugin_PadSimple/Src/PadSimple.cpp @@ -288,11 +288,11 @@ void DInput_Read(int _numPAD, SPADStatus* _pPADStatus) if (dinput.diks[pad[_numPAD].keyForControl[CTL_START]] & 0xFF){_pPADStatus->button |= PAD_BUTTON_START;} } -bool XInput_Read(int xpadplayer, SPADStatus* _pPADStatus) +bool XInput_Read(int XPadPlayer, SPADStatus* _pPADStatus) { const int base = 0x80; XINPUT_STATE xstate; - DWORD xresult = XInputGetState(xpadplayer, &xstate); + DWORD xresult = XInputGetState(XPadPlayer, &xstate); // Let's .. yes, let's use XINPUT! if (xresult == ERROR_SUCCESS) @@ -495,28 +495,15 @@ void PAD_GetStatus(u8 _numPAD, SPADStatus* _pPADStatus) #ifdef _WIN32 // Just update pad on focus // TODO fix g_PADInitialize.hWnd != DolphinWX frame - if (pad[_numPAD].disable) + if (pad[_numPAD].bDisable) { if (g_PADInitialize.hWnd != GetForegroundWindow()) return; } - - if (pad[_numPAD].keyboard) - { - // Keyboard, so we assume it's ok - _pPADStatus->err = PAD_ERR_NONE; - DInput_Read(_numPAD, _pPADStatus); - } - else - { - // It's an xpad, so error if it's not connected - // shuffle2: pretty sure this does nothing for now, dolphin - // seems to ignore changes to the connected mask after init... - if (XInput_Read(pad[_numPAD].xpadplayer, _pPADStatus)) - _pPADStatus->err = PAD_ERR_NONE; - else - _pPADStatus->err = PAD_ERR_NO_CONTROLLER; - } + // Dolphin doesn't really care about the pad error codes anyways... + _pPADStatus->err = PAD_ERR_NONE; + if (pad[_numPAD].bEnableXPad) XInput_Read(pad[_numPAD].XPadPlayer, _pPADStatus); + DInput_Read(_numPAD, _pPADStatus); #elif defined(__linux__) _pPADStatus->err = PAD_ERR_NONE; X11_Read(_numPAD, _pPADStatus); @@ -532,7 +519,7 @@ void PAD_GetStatus(u8 _numPAD, SPADStatus* _pPADStatus) void PAD_Rumble(u8 _numPAD, unsigned int _uType, unsigned int _uStrength) { #ifdef _WIN32 - if (!pad[_numPAD].keyboard) + if (pad[_numPAD].bEnableXPad) { static int a = 0; @@ -547,7 +534,7 @@ void PAD_Rumble(u8 _numPAD, unsigned int _uType, unsigned int _uStrength) a = int ((float)a * 0.96f); - if (!pad[_numPAD].rumble) + if (!pad[_numPAD].bRumble) { a = 0; } @@ -555,7 +542,7 @@ void PAD_Rumble(u8 _numPAD, unsigned int _uType, unsigned int _uStrength) XINPUT_VIBRATION vib; vib.wLeftMotorSpeed = a; //_uStrength*100; vib.wRightMotorSpeed = a; //_uStrength*100; - XInputSetState(pad[_numPAD].xpadplayer, &vib); + XInputSetState(pad[_numPAD].XPadPlayer, &vib); } #endif } @@ -566,13 +553,13 @@ unsigned int PAD_GetAttachedPads() LoadConfig(); - if(pad[0].attached) + if(pad[0].bAttached) connected |= 1; - if(pad[1].attached) + if(pad[1].bAttached) connected |= 2; - if(pad[2].attached) + if(pad[2].bAttached) connected |= 4; - if(pad[3].attached) + if(pad[3].bAttached) connected |= 8; return connected; @@ -648,11 +635,11 @@ void LoadConfig() char SectionName[32]; sprintf(SectionName, "PAD%i", i+1); - file.Get(SectionName, "Keyboard", &pad[i].keyboard, true); - file.Get(SectionName, "Attached", &pad[i].attached, i==0); - file.Get(SectionName, "DisableOnBackground", &pad[i].disable, false); - file.Get(SectionName, "Rumble", &pad[i].rumble, true); - file.Get(SectionName, "XPad#", &pad[i].xpadplayer); + file.Get(SectionName, "UseXPad", &pad[i].bEnableXPad, true); + file.Get(SectionName, "Attached", &pad[i].bAttached, i==0); + file.Get(SectionName, "DisableOnBackground", &pad[i].bDisable, false); + file.Get(SectionName, "Rumble", &pad[i].bRumble, true); + file.Get(SectionName, "XPad#", &pad[i].XPadPlayer); for (int x = 0; x < NUMCONTROLS; x++) { @@ -678,11 +665,11 @@ void SaveConfig() char SectionName[32]; sprintf(SectionName, "PAD%i", i+1); - file.Set(SectionName, "Keyboard", pad[i].keyboard); - file.Set(SectionName, "Attached", pad[i].attached); - file.Set(SectionName, "DisableOnBackground", pad[i].disable); - file.Set(SectionName, "Rumble", pad[i].rumble); - file.Set(SectionName, "XPad#", pad[i].xpadplayer); + file.Set(SectionName, "UseXPad", pad[i].bEnableXPad); + file.Set(SectionName, "Attached", pad[i].bAttached); + file.Set(SectionName, "DisableOnBackground", pad[i].bDisable); + file.Set(SectionName, "Rumble", pad[i].bRumble); + file.Set(SectionName, "XPad#", pad[i].XPadPlayer); for (int x = 0; x < NUMCONTROLS; x++) { diff --git a/Source/Plugins/Plugin_PadSimple/Src/PadSimple.h b/Source/Plugins/Plugin_PadSimple/Src/PadSimple.h index 8282302a69..8644217420 100644 --- a/Source/Plugins/Plugin_PadSimple/Src/PadSimple.h +++ b/Source/Plugins/Plugin_PadSimple/Src/PadSimple.h @@ -74,11 +74,11 @@ static const char* controlNames[] = }; struct SPads { - bool keyboard; // Is it a keyboard? - bool attached; // Pad is "attached" to the gamecube/wii - bool disable; // Disabled when dolphin isn't in focus - bool rumble; // Rumble for xpad - int xpadplayer; // Player# of the xpad + bool bEnableXPad; // Use an XPad in addition to the keyboard? + bool bAttached; // Pad is "attached" to the gamecube/wii + bool bDisable; // Disabled when dolphin isn't in focus + bool bRumble; // Rumble for xpad + int XPadPlayer; // Player# of the xpad unsigned int keyForControl[NUMCONTROLS];// Keyboard mapping };