diff --git a/Source/Plugins/Plugin_nJoy_SDL/Src/Config.cpp b/Source/Plugins/Plugin_nJoy_SDL/Src/Config.cpp index 09f8abc77c..cbb66d2f94 100644 --- a/Source/Plugins/Plugin_nJoy_SDL/Src/Config.cpp +++ b/Source/Plugins/Plugin_nJoy_SDL/Src/Config.cpp @@ -30,21 +30,23 @@ ////////////////////////////////////////////////////////////////////////////////////////// -//////////////////////// +/////////////////////////////////////////////////////////////////////// // Include // ŻŻŻŻŻŻŻŻŻ #include "nJoy.h" #include "Common.h" Config g_Config; +extern ConfigBox* m_frame; +////////////////////////////////// + +// Run when created +// ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ Config::Config() { - //memset(this, 0, sizeof(Config)); // Clear the memory - - bSaveByID.resize(4); // Set vector size - bSquareToCircle.resize(4); - SDiagonal.resize(4); + // Clear the memory + //memset(this, 0, sizeof(Config)); } @@ -88,147 +90,83 @@ void DEBUG_QUIT() } -/* Check for duplicate Joypad names. If we find a duplicate notify the user about it. */ -// ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ -int Config::CheckForDuplicateJoypads(bool OK) -{ - // Count the number of duplicate names - int NumDuplicates = 0, Duplicate = 0; - for(u32 i = 0; i < 4; i++) - { - for(u32 j = 0; j < 4; j++) - { - // Avoid potential crash - if(joysticks[i].ID >= SDL_NumJoysticks() || joysticks[j].ID >= SDL_NumJoysticks()) continue; - - if (i == j) continue; // Don't compare to itself - if (! memcmp(&joyinfo[joysticks[i].ID], &joyinfo[joysticks[j].ID], sizeof(joyinfo))) - { - // If one of them is not enabled, then there is no problem - if(!joysticks[i].enabled || !joysticks[j].enabled) continue; - - // If oen of them don't save by ID, then there is no problem - if(!g_Config.bSaveByID.at(i) || !g_Config.bSaveByID.at(j)) continue; - - //PanicAlert("%i %i", i, j); - NumDuplicates++; - Duplicate = i; - } - } - } - - ///////////////////////////////////////////////////////////////////////// - // Notify the user about the multiple devices - // ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ - if(NumDuplicates > 0) - { - std::string ExtendedText; - std::string MainText = - "You have selected SaveByID for several identical joypads with the name '%s', because nJoy" - " has no way of separating between them the settings for the last one will now be saved." - " This may not be the settings you have intended to save. It is therefore recommended" - " that you either unselect SaveByID for all but one of the identical joypads" - " or disable them entirely." - " If you are aware of this issue and want to keep the same settings for the identical" - " pads you can ignore this message."; - - if (OK) // We got here from the OK button - { - ExtendedText = - "\n\n[Select 'OK' to return to the configuration window. Select 'Cancel' to ignore this" - " message and close the configuration window and don't show this message again.]"; - } - else - { - ExtendedText = - "\n\n[Select 'Cancel' if you don't want to see this information again.]"; - } - - bool ret = PanicYesNo((MainText + ExtendedText).c_str(), joyinfo[joysticks[Duplicate].ID].Name); - - if (ret) - g_Config.bSaveByIDNotice = false; - - return ret ? 4 : 16; - } - - return -1; -} - - +///////////////////////////////////////////////////////////////////////////////////// // Save settings to file // ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ -void Config::Save(bool CheckedForDuplicates) +void Config::Save(int Slot) { // Load ini file IniFile file; file.Load("nJoy.ini"); - // Show potential warning - if(!CheckedForDuplicates && g_Config.bSaveByIDNotice) CheckForDuplicateJoypads(false); - + // ================================================================== + // Global settings + // ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ file.Set("General", "ShowAdvanced", g_Config.bShowAdvanced); - file.Set("General", "SaveByIDNotice", g_Config.bSaveByIDNotice); + file.Set("General", "SaveByID", g_Config.bSaveByID); + // ======================== for (int i = 0; i < 4; i++) { + // Should we save this slot? + if (Slot != -1 && Slot != i) continue; + + // ================================================================== + // Slot specific settings only + // ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ std::string SectionName = StringFromFormat("PAD%i", i+1); - file.Set(SectionName.c_str(), "enabled", joysticks[i].enabled); + file.Set(SectionName.c_str(), "enabled", PadMapping[i].enabled); // Save the physical device ID - file.Set(SectionName.c_str(), "joy_id", joysticks[i].ID); - file.Set(SectionName.c_str(), "SaveByID", g_Config.bSaveByID.at(i)); - - /* Don't save anything more from the disabled joypads, if a joypad is enabled we can run - this again after any settings are changed for it */ - if(!joysticks[i].enabled) continue; + file.Set(SectionName.c_str(), "joy_id", PadMapping[i].ID); + // =================== - ////////////////////////////////////// - // Save joypad specific settings + // ================================================================== + // Joypad or slot specific settings // ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ - // Current joypad device ID: joysticks[i].ID - // Current joypad name: joyinfo[joysticks[i].ID].Name - if(g_Config.bSaveByID.at(i)) + // Current joypad device ID: PadMapping[i].ID + // Current joypad name: joyinfo[PadMapping[i].ID].Name + if(g_Config.bSaveByID) { - /* Save joypad specific settings. Check for "joysticks[i].ID < SDL_NumJoysticks()" to + /* Save joypad specific settings. Check for "PadMapping[i].ID < SDL_NumJoysticks()" to avoid reading a joyinfo that does't exist */ - if(joysticks[i].ID >= SDL_NumJoysticks()) continue; - - //PanicAlert("%i", m_frame->m_Joyname[0]->GetSelection()); - //if(i == 0) PanicAlert("%i", joysticks[i].buttons[CTL_START]); - //PanicAlert("%s", joyinfo[joysticks[i].ID].Name); + if(PadMapping[i].ID >= SDL_NumJoysticks()) continue; // Create a new section name after the joypad name - SectionName = joyinfo[joysticks[i].ID].Name; + SectionName = joyinfo[PadMapping[i].ID].Name; } - file.Set(SectionName.c_str(), "l_shoulder", joysticks[i].buttons[CTL_L_SHOULDER]); - file.Set(SectionName.c_str(), "r_shoulder", joysticks[i].buttons[CTL_R_SHOULDER]); - file.Set(SectionName.c_str(), "a_button", joysticks[i].buttons[CTL_A_BUTTON]); - file.Set(SectionName.c_str(), "b_button", joysticks[i].buttons[CTL_B_BUTTON]); - file.Set(SectionName.c_str(), "x_button", joysticks[i].buttons[CTL_X_BUTTON]); - file.Set(SectionName.c_str(), "y_button", joysticks[i].buttons[CTL_Y_BUTTON]); - file.Set(SectionName.c_str(), "z_trigger", joysticks[i].buttons[CTL_Z_TRIGGER]); - file.Set(SectionName.c_str(), "start_button", joysticks[i].buttons[CTL_START]); - file.Set(SectionName.c_str(), "dpad", joysticks[i].dpad); - file.Set(SectionName.c_str(), "dpad_up", joysticks[i].dpad2[CTL_D_PAD_UP]); - file.Set(SectionName.c_str(), "dpad_down", joysticks[i].dpad2[CTL_D_PAD_DOWN]); - file.Set(SectionName.c_str(), "dpad_left", joysticks[i].dpad2[CTL_D_PAD_LEFT]); - file.Set(SectionName.c_str(), "dpad_right", joysticks[i].dpad2[CTL_D_PAD_RIGHT]); - file.Set(SectionName.c_str(), "main_x", joysticks[i].axis[CTL_MAIN_X]); - file.Set(SectionName.c_str(), "main_y", joysticks[i].axis[CTL_MAIN_Y]); - file.Set(SectionName.c_str(), "sub_x", joysticks[i].axis[CTL_SUB_X]); - file.Set(SectionName.c_str(), "sub_y", joysticks[i].axis[CTL_SUB_Y]); + file.Set(SectionName.c_str(), "l_shoulder", PadMapping[i].buttons[CTL_L_SHOULDER]); + file.Set(SectionName.c_str(), "r_shoulder", PadMapping[i].buttons[CTL_R_SHOULDER]); + file.Set(SectionName.c_str(), "a_button", PadMapping[i].buttons[CTL_A_BUTTON]); + file.Set(SectionName.c_str(), "b_button", PadMapping[i].buttons[CTL_B_BUTTON]); + file.Set(SectionName.c_str(), "x_button", PadMapping[i].buttons[CTL_X_BUTTON]); + file.Set(SectionName.c_str(), "y_button", PadMapping[i].buttons[CTL_Y_BUTTON]); + file.Set(SectionName.c_str(), "z_trigger", PadMapping[i].buttons[CTL_Z_TRIGGER]); + file.Set(SectionName.c_str(), "start_button", PadMapping[i].buttons[CTL_START]); + file.Set(SectionName.c_str(), "dpad", PadMapping[i].dpad); + file.Set(SectionName.c_str(), "dpad_up", PadMapping[i].dpad2[CTL_D_PAD_UP]); + file.Set(SectionName.c_str(), "dpad_down", PadMapping[i].dpad2[CTL_D_PAD_DOWN]); + file.Set(SectionName.c_str(), "dpad_left", PadMapping[i].dpad2[CTL_D_PAD_LEFT]); + file.Set(SectionName.c_str(), "dpad_right", PadMapping[i].dpad2[CTL_D_PAD_RIGHT]); + file.Set(SectionName.c_str(), "main_x", PadMapping[i].axis[CTL_MAIN_X]); + file.Set(SectionName.c_str(), "main_y", PadMapping[i].axis[CTL_MAIN_Y]); + file.Set(SectionName.c_str(), "sub_x", PadMapping[i].axis[CTL_SUB_X]); + file.Set(SectionName.c_str(), "sub_y", PadMapping[i].axis[CTL_SUB_Y]); - file.Set(SectionName.c_str(), "deadzone", joysticks[i].deadzone); - file.Set(SectionName.c_str(), "halfpress", joysticks[i].halfpress); + file.Set(SectionName.c_str(), "deadzone", PadMapping[i].deadzone); + file.Set(SectionName.c_str(), "halfpress", PadMapping[i].halfpress); - file.Set(SectionName.c_str(), "controllertype", joysticks[i].controllertype); - file.Set(SectionName.c_str(), "TriggerType", joysticks[i].triggertype); - file.Set(SectionName.c_str(), "eventnum", joysticks[i].eventnum); + file.Set(SectionName.c_str(), "controllertype", PadMapping[i].controllertype); + file.Set(SectionName.c_str(), "TriggerType", PadMapping[i].triggertype); + file.Set(SectionName.c_str(), "eventnum", PadMapping[i].eventnum); - file.Set(SectionName.c_str(), "Diagonal", g_Config.SDiagonal.at(i).c_str()); - file.Set(SectionName.c_str(), "SquareToCircle", g_Config.bSquareToCircle.at(i)); + file.Set(SectionName.c_str(), "Diagonal", PadMapping[i].SDiagonal); + file.Set(SectionName.c_str(), "SquareToCircle", PadMapping[i].bSquareToCircle); + // ====================================== + + // Debugging + //if(m_frame) m_frame->LogMsg("Saved: %s %i\n", SectionName.c_str(), PadMapping[i].triggertype); } file.Save("nJoy.ini"); @@ -236,74 +174,82 @@ void Config::Save(bool CheckedForDuplicates) // Load settings from file // ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ -void Config::Load(bool config) +void Config::Load(bool ChangePad, bool ChangeSaveByID) { + // Load file IniFile file; file.Load("nJoy.ini"); - std::vector Duplicates; + bool Tmp; // Tmp storage + // ================================================================== + // Global settings + // ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ file.Get("General", "ShowAdvanced", &g_Config.bShowAdvanced, false); - file.Get("General", "SaveByIDNotice", &g_Config.bSaveByIDNotice, true); + if(!ChangeSaveByID) + { + file.Get("General", "SaveByID", &Tmp, false); g_Config.bSaveByID = Tmp; + } + // ============= for (int i = 0; i < 4; i++) { std::string SectionName = StringFromFormat("PAD%i", i+1); // Don't update this when we are loading settings from the ConfigBox - if(!config) + if(!ChangePad) { - file.Get(SectionName.c_str(), "joy_id", &joysticks[i].ID, 0); - file.Get(SectionName.c_str(), "enabled", &joysticks[i].enabled, 1); + file.Get(SectionName.c_str(), "joy_id", &PadMapping[i].ID, 0); + file.Get(SectionName.c_str(), "enabled", &PadMapping[i].enabled, 1); } - bool Tmp; - file.Get(SectionName.c_str(), "SaveByID", &Tmp, false); - g_Config.bSaveByID.at(i) = Tmp; - - ////////////////////////////////////// - // Load joypad specific settings + // ================================================================== + // Joypad or slot specific settings // ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ - // Current joypad device ID: joysticks[i].ID - // Current joypad name: joyinfo[joysticks[i].ID].Name - if(g_Config.bSaveByID.at(i)) + // Current joypad device ID: PadMapping[i].ID + // Current joypad name: joyinfo[PadMapping[i].ID].Name + if(g_Config.bSaveByID) { /* Prevent a crash from illegal access to joyinfo that will only have values for - the current amount of connected joysticks */ - if(joysticks[i].ID >= SDL_NumJoysticks()) continue; + the current amount of connected PadMapping */ + if(PadMapping[i].ID >= SDL_NumJoysticks()) continue; - //PanicAlert("%i %i",joysticks[i].ID, SDL_NumJoysticks()); - //PanicAlert("%s", joyinfo[joysticks[i].ID].Name); + //PanicAlert("%i %i",PadMapping[i].ID, SDL_NumJoysticks()); + //PanicAlert("%s", joyinfo[PadMapping[i].ID].Name); // Create a section name - SectionName = joyinfo[joysticks[i].ID].Name; + SectionName = joyinfo[PadMapping[i].ID].Name; } - file.Get(SectionName.c_str(), "l_shoulder", &joysticks[i].buttons[CTL_L_SHOULDER], 4); - file.Get(SectionName.c_str(), "r_shoulder", &joysticks[i].buttons[CTL_R_SHOULDER], 5); - file.Get(SectionName.c_str(), "a_button", &joysticks[i].buttons[CTL_A_BUTTON], 0); - file.Get(SectionName.c_str(), "b_button", &joysticks[i].buttons[CTL_B_BUTTON], 1); - file.Get(SectionName.c_str(), "x_button", &joysticks[i].buttons[CTL_X_BUTTON], 3); - file.Get(SectionName.c_str(), "y_button", &joysticks[i].buttons[CTL_Y_BUTTON], 2); - file.Get(SectionName.c_str(), "z_trigger", &joysticks[i].buttons[CTL_Z_TRIGGER], 7); - file.Get(SectionName.c_str(), "start_button", &joysticks[i].buttons[CTL_START], 9); - file.Get(SectionName.c_str(), "dpad", &joysticks[i].dpad, 0); - file.Get(SectionName.c_str(), "dpad_up", &joysticks[i].dpad2[CTL_D_PAD_UP], 0); - file.Get(SectionName.c_str(), "dpad_down", &joysticks[i].dpad2[CTL_D_PAD_DOWN], 0); - file.Get(SectionName.c_str(), "dpad_left", &joysticks[i].dpad2[CTL_D_PAD_LEFT], 0); - file.Get(SectionName.c_str(), "dpad_right", &joysticks[i].dpad2[CTL_D_PAD_RIGHT], 0); - file.Get(SectionName.c_str(), "main_x", &joysticks[i].axis[CTL_MAIN_X], 0); - file.Get(SectionName.c_str(), "main_y", &joysticks[i].axis[CTL_MAIN_Y], 1); - file.Get(SectionName.c_str(), "sub_x", &joysticks[i].axis[CTL_SUB_X], 2); - file.Get(SectionName.c_str(), "sub_y", &joysticks[i].axis[CTL_SUB_Y], 3); + file.Get(SectionName.c_str(), "l_shoulder", &PadMapping[i].buttons[CTL_L_SHOULDER], 4); + file.Get(SectionName.c_str(), "r_shoulder", &PadMapping[i].buttons[CTL_R_SHOULDER], 5); + file.Get(SectionName.c_str(), "a_button", &PadMapping[i].buttons[CTL_A_BUTTON], 0); + file.Get(SectionName.c_str(), "b_button", &PadMapping[i].buttons[CTL_B_BUTTON], 1); + file.Get(SectionName.c_str(), "x_button", &PadMapping[i].buttons[CTL_X_BUTTON], 3); + file.Get(SectionName.c_str(), "y_button", &PadMapping[i].buttons[CTL_Y_BUTTON], 2); + file.Get(SectionName.c_str(), "z_trigger", &PadMapping[i].buttons[CTL_Z_TRIGGER], 7); + file.Get(SectionName.c_str(), "start_button", &PadMapping[i].buttons[CTL_START], 9); + file.Get(SectionName.c_str(), "dpad", &PadMapping[i].dpad, 0); + file.Get(SectionName.c_str(), "dpad_up", &PadMapping[i].dpad2[CTL_D_PAD_UP], 0); + file.Get(SectionName.c_str(), "dpad_down", &PadMapping[i].dpad2[CTL_D_PAD_DOWN], 0); + file.Get(SectionName.c_str(), "dpad_left", &PadMapping[i].dpad2[CTL_D_PAD_LEFT], 0); + file.Get(SectionName.c_str(), "dpad_right", &PadMapping[i].dpad2[CTL_D_PAD_RIGHT], 0); + file.Get(SectionName.c_str(), "main_x", &PadMapping[i].axis[CTL_MAIN_X], 0); + file.Get(SectionName.c_str(), "main_y", &PadMapping[i].axis[CTL_MAIN_Y], 1); + file.Get(SectionName.c_str(), "sub_x", &PadMapping[i].axis[CTL_SUB_X], 2); + file.Get(SectionName.c_str(), "sub_y", &PadMapping[i].axis[CTL_SUB_Y], 3); - file.Get(SectionName.c_str(), "deadzone", &joysticks[i].deadzone, 9); - file.Get(SectionName.c_str(), "halfpress", &joysticks[i].halfpress, -1); - file.Get(SectionName.c_str(), "controllertype", &joysticks[i].controllertype, 0); - file.Get(SectionName.c_str(), "TriggerType", &joysticks[i].triggertype, 0); - file.Get(SectionName.c_str(), "eventnum", &joysticks[i].eventnum, 0); + file.Get(SectionName.c_str(), "deadzone", &PadMapping[i].deadzone, 9); + file.Get(SectionName.c_str(), "halfpress", &PadMapping[i].halfpress, -1); + file.Get(SectionName.c_str(), "controllertype", &PadMapping[i].controllertype, 0); + file.Get(SectionName.c_str(), "TriggerType", &PadMapping[i].triggertype, 0); + file.Get(SectionName.c_str(), "eventnum", &PadMapping[i].eventnum, 0); - file.Get(SectionName.c_str(), "Diagonal", &g_Config.SDiagonal.at(i), "100%"); - file.Get(SectionName.c_str(), "SquareToCircle", &Tmp, false); g_Config.bSquareToCircle.at(i) = Tmp; + file.Get(SectionName.c_str(), "Diagonal", &PadMapping[i].SDiagonal, "100%"); + file.Get(SectionName.c_str(), "SquareToCircle", &Tmp, false); PadMapping[i].bSquareToCircle = Tmp; + // ============================= + + // Debugging + //if(m_frame) m_frame->LogMsg("%i: Load triggertype: %s %i\n", i, SectionName.c_str(), PadMapping[i].triggertype); } } diff --git a/Source/Plugins/Plugin_nJoy_SDL/Src/Config.h b/Source/Plugins/Plugin_nJoy_SDL/Src/Config.h index c59b8a7e6b..f7002ff66a 100644 --- a/Source/Plugins/Plugin_nJoy_SDL/Src/Config.h +++ b/Source/Plugins/Plugin_nJoy_SDL/Src/Config.h @@ -21,17 +21,13 @@ struct Config { Config(); - void Load(bool Config = false); - void Save(bool CheckedForDuplicates = false); + void Load(bool ChangePad = false, bool ChangeSaveByID = false); + void Save(int Slot = -1); int CheckForDuplicateJoypads(bool OK); // General bool bShowAdvanced; // Only allow one of these - std::vector bSaveByID; bool bSaveByIDNotice; - - // Joystick - std::vector SDiagonal; - std::vector bSquareToCircle; + bool bSaveByID; }; extern Config g_Config; diff --git a/Source/Plugins/Plugin_nJoy_SDL/Src/GUI/ConfigAdvanced.cpp b/Source/Plugins/Plugin_nJoy_SDL/Src/GUI/ConfigAdvanced.cpp index 09407de94b..7cd803cc87 100644 --- a/Source/Plugins/Plugin_nJoy_SDL/Src/GUI/ConfigAdvanced.cpp +++ b/Source/Plugins/Plugin_nJoy_SDL/Src/GUI/ConfigAdvanced.cpp @@ -50,7 +50,7 @@ bool StrangeHack = true; void ConfigBox::PadGetStatus() { // Return if it's not detected - if(joysticks[notebookpage].ID >= SDL_NumJoysticks()) + if(PadMapping[notebookpage].ID >= SDL_NumJoysticks()) { m_TStatusIn[notebookpage]->SetLabel(wxT("Not connected")); m_TStatusOut[notebookpage]->SetLabel(wxT("Not connected")); @@ -59,7 +59,7 @@ void ConfigBox::PadGetStatus() } // Return if it's not enabled - if (!joysticks[notebookpage].enabled) + if (!PadMapping[notebookpage].enabled) { m_TStatusIn[notebookpage]->SetLabel(wxT("Not enabled")); m_TStatusOut[notebookpage]->SetLabel(wxT("Not enabled")); @@ -68,8 +68,8 @@ void ConfigBox::PadGetStatus() } // Get physical device status - int PhysicalDevice = joysticks[notebookpage].ID; - int TriggerType = joysticks[notebookpage].triggertype; + int PhysicalDevice = PadMapping[notebookpage].ID; + int TriggerType = PadMapping[notebookpage].triggertype; // Get pad status GetJoyState(notebookpage); @@ -78,8 +78,8 @@ void ConfigBox::PadGetStatus() // Analog stick // ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ // Set Deadzones perhaps out of function - //int deadzone = (int)(((float)(128.00/100.00)) * (float)(joysticks[_numPAD].deadzone+1)); - //int deadzone2 = (int)(((float)(-128.00/100.00)) * (float)(joysticks[_numPAD].deadzone+1)); + //int deadzone = (int)(((float)(128.00/100.00)) * (float)(PadMapping[_numPAD].deadzone+1)); + //int deadzone2 = (int)(((float)(-128.00/100.00)) * (float)(PadMapping[_numPAD].deadzone+1)); // Get original values int main_x = joystate[notebookpage].axis[CTL_MAIN_X]; @@ -89,7 +89,7 @@ void ConfigBox::PadGetStatus() // Get adjusted values int main_x_after = main_x, main_y_after = main_y; - if(g_Config.bSquareToCircle.at(notebookpage)) + if(PadMapping[notebookpage].bSquareToCircle) { std::vector main_xy = Pad_Square_to_Circle(main_x, main_y, notebookpage); main_x_after = main_xy.at(0); @@ -143,7 +143,7 @@ void ConfigBox::PadGetStatus() int TriggerRight = joystate[notebookpage].axis[CTL_R_SHOULDER]; // Convert the triggers values - if (joysticks[notebookpage].triggertype == CTL_TRIGGER_SDL) + if (PadMapping[notebookpage].triggertype == CTL_TRIGGER_SDL) { TriggerLeft = Pad_Convert(TriggerLeft); TriggerRight = Pad_Convert(TriggerRight); @@ -169,19 +169,19 @@ void ConfigBox::PadGetStatus() std::string ShowStatus(int VirtualController) { // Check if it's enabled - if (!joysticks[VirtualController].enabled) return "Disabled"; + if (!PadMapping[VirtualController].enabled) return StringFromFormat("%i disabled", VirtualController); // Save the physical device - int PhysicalDevice = joysticks[VirtualController].ID; + int PhysicalDevice = PadMapping[VirtualController].ID; // Make local shortcut SDL_Joystick *joy = joystate[VirtualController].joy; // Make shortcuts for all pads - SDL_Joystick *joy0 = joystate[joysticks[0].ID].joy; - SDL_Joystick *joy1 = joystate[joysticks[1].ID].joy; - SDL_Joystick *joy2 = joystate[joysticks[2].ID].joy; - SDL_Joystick *joy3 = joystate[joysticks[3].ID].joy; + SDL_Joystick *joy0 = joystate[PadMapping[0].ID].joy; + SDL_Joystick *joy1 = joystate[PadMapping[1].ID].joy; + SDL_Joystick *joy2 = joystate[PadMapping[2].ID].joy; + SDL_Joystick *joy3 = joystate[PadMapping[3].ID].joy; // Temporary storage std::string StrAxes, StrHats, StrBut; @@ -193,10 +193,6 @@ std::string ShowStatus(int VirtualController) int Hats = joyinfo[PhysicalDevice].NumHats; int Buttons = joyinfo[PhysicalDevice].NumButtons; - // More status - int controllertype = joysticks[VirtualController].controllertype; - int triggertype = joysticks[VirtualController].triggertype; - // Update the internal values SDL_JoystickUpdate(); @@ -218,20 +214,25 @@ std::string ShowStatus(int VirtualController) } return StringFromFormat( - "joysticks.ID: %i %i %i %i\n" - "joysticks.controllertype, triggertype: %i %i\n" + "PadMapping\n" + "ID: %i %i %i %i\n" + "Controllertype: %i %i %i %i\n" + "SquareToCircle: %i %i %i %i\n\n" "Handles: %i %i %i %i\n" + "XInput: %i %i %i\n" "Axes: %s\n" "Hats: %s\n" "But: %s\n" "Device: Ax: %i Balls:%i But:%i Hats:%i", - joysticks[0].ID, joysticks[1].ID, joysticks[2].ID, joysticks[3].ID, - controllertype, triggertype, + PadMapping[0].ID, PadMapping[1].ID, PadMapping[2].ID, PadMapping[3].ID, + PadMapping[0].controllertype, PadMapping[1].controllertype, PadMapping[2].controllertype, PadMapping[3].controllertype, + PadMapping[0].bSquareToCircle, PadMapping[1].bSquareToCircle, PadMapping[2].bSquareToCircle, PadMapping[3].bSquareToCircle, joy0, joy1, joy2, joy3, -#ifdef _WIN32 - XInput::IsConnected(0), XInput::GetXI(0, XI_TRIGGER_L), XInput::GetXI(0, XI_TRIGGER_R), -#endif + + #ifdef _WIN32 + XInput::IsConnected(0), XInput::GetXI(0, XI_TRIGGER_L), XInput::GetXI(0, XI_TRIGGER_R), + #endif StrAxes.c_str(), StrHats.c_str(), StrBut.c_str(), Axes, Balls, Hats, Buttons ); diff --git a/Source/Plugins/Plugin_nJoy_SDL/Src/GUI/ConfigBox.cpp b/Source/Plugins/Plugin_nJoy_SDL/Src/GUI/ConfigBox.cpp index 6674e4e8e8..4837869cb2 100644 --- a/Source/Plugins/Plugin_nJoy_SDL/Src/GUI/ConfigBox.cpp +++ b/Source/Plugins/Plugin_nJoy_SDL/Src/GUI/ConfigBox.cpp @@ -40,7 +40,7 @@ #include "Images/controller.xpm" extern CONTROLLER_INFO *joyinfo; -//extern CONTROLLER_MAPPING joysticks[4]; +//extern CONTROLLER_MAPPING PadMapping[4]; extern bool emulator_running; // D-Pad type @@ -70,17 +70,20 @@ BEGIN_EVENT_TABLE(ConfigBox,wxDialog) EVT_NOTEBOOK_PAGE_CHANGED(ID_NOTEBOOK, ConfigBox::NotebookPageChanged) // Change and enable or disable gamepad - EVT_COMBOBOX(IDC_JOYNAME, ConfigBox::ChangeJoystick) - EVT_CHECKBOX(IDC_JOYATTACH, ConfigBox::EnableDisable) + EVT_COMBOBOX(IDC_JOYNAME, ConfigBox::ChangeSettings) + EVT_CHECKBOX(IDC_JOYATTACH, ConfigBox::ChangeSettings) - // Settings + // Other settings EVT_CHECKBOX(IDC_SAVEBYID, ConfigBox::ChangeSettings) - EVT_CHECKBOX(IDC_SAVEBYIDNOTICE, ConfigBox::ChangeSettings) EVT_CHECKBOX(IDC_SHOWADVANCED, ConfigBox::ChangeSettings) EVT_COMBOBOX(IDCB_MAINSTICK_DIAGONAL, ConfigBox::ChangeSettings) + EVT_COMBOBOX(IDC_CONTROLTYPE, ConfigBox::ChangeSettings) + EVT_COMBOBOX(IDC_TRIGGERTYPE, ConfigBox::ChangeSettings) + EVT_COMBOBOX(IDC_DEADZONE, ConfigBox::ChangeSettings) + + // Advanced settings + EVT_COMBOBOX(IDCB_MAINSTICK_DIAGONAL, ConfigBox::ChangeSettings) EVT_CHECKBOX(IDCB_MAINSTICK_S_TO_C, ConfigBox::ChangeSettings) - EVT_COMBOBOX(IDC_CONTROLTYPE, ConfigBox::ChangeControllertype) - EVT_COMBOBOX(IDC_TRIGGERTYPE, ConfigBox::ChangeControllertype) EVT_BUTTON(IDB_SHOULDER_L, ConfigBox::GetButtons) EVT_BUTTON(IDB_SHOULDER_R, ConfigBox::GetButtons) @@ -113,6 +116,9 @@ ConfigBox::ConfigBox(wxWindow *parent, wxWindowID id, const wxString &title, // Define values notebookpage = 0; g_Pressed = 0; + Debugging = false; + m_TCDebugging = NULL; + ControlsCreated = false; // Create controls CreateGUIControls(); @@ -185,16 +191,9 @@ void ConfigBox::OKClick(wxCommandEvent& event) { if (event.GetId() == ID_OK) { - // Check for duplicate joypads - if(g_Config.bSaveByIDNotice) - { - int Tmp = g_Config.CheckForDuplicateJoypads(true); - if (Tmp == wxOK) return; else if (Tmp == wxNO) g_Config.bSaveByIDNotice = false; - } - - for(int i = 0; i < 4; i++) SaveButtonMapping(i); // Update joysticks array - DoSave(false, true); // Save settings - g_Config.Load(); // Reload settings + DoSave(); // Save settings + g_Config.Load(); // Reload settings to PadMapping + if(Debugging) PanicAlert("Done"); Close(); // Call OnClose() } } @@ -205,11 +204,34 @@ void ConfigBox::CancelClick(wxCommandEvent& event) { if (event.GetId() == ID_CANCEL) { - g_Config.Load(); // Reload settings + // Forget all potential changes to PadMapping by loading the last saved settings + g_Config.Load(); + Close(); // Call OnClose() } } +// Debugging +// ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ +void ConfigBox::LogMsg(const char* format, ...) +{ + if(Debugging) + { + const int MaxMsgSize = 1024*2; + char buffer[MaxMsgSize]; + va_list args; + va_start(args, format); + CharArrayFromFormatV(buffer, MaxMsgSize, format, args); + va_end(args); + + // Add timestamp + std::string StrTmp = buffer; + //StrTmp += Common::Timer::GetTimeFormatted(); + + if(m_TCDebugging) m_TCDebugging->AppendText(StrTmp.c_str()); + } +} + ////////////////////////////////////// // Save Settings @@ -219,9 +241,10 @@ void ConfigBox::CancelClick(wxCommandEvent& event) 1. Closing the configuration window 2. Changing the gamepad - 3. When the gamepad is enabled or disbled */ - -void ConfigBox::DoSave(bool ChangePad, bool CheckedForDuplicates) + 3. When the gamepad is enabled or disbled + 4. When we change saving mode (by Id or by slot) +*/ +void ConfigBox::DoSave(bool ChangePad, int Slot) { // Replace "" with "-1" before we are saving ToBlank(false); @@ -230,55 +253,64 @@ void ConfigBox::DoSave(bool ChangePad, bool CheckedForDuplicates) { // Since we are selecting the pad to save to by the Id we can't update it when we change the pad for(int i = 0; i < 4; i++) SaveButtonMapping(i, true); - g_Config.Save(CheckedForDuplicates); + //LogMsg("Old Id: %s | %i %i\n", joyinfo[PadMapping[notebookpage].ID].Name.c_str(), notebookpage, Slot); + g_Config.Save(Slot); // Now we can update the ID - joysticks[notebookpage].ID = m_Joyname[notebookpage]->GetSelection(); + PadMapping[notebookpage].ID = m_Joyname[notebookpage]->GetSelection(); + //LogMsg("New Id: %s\n", joyinfo[PadMapping[notebookpage].ID].Name.c_str()); } else { for(int i = 0; i < 4; i++) SaveButtonMapping(i); - g_Config.Save(CheckedForDuplicates); + g_Config.Save(Slot); } // Then change it back ToBlank(); } -// Enable or disable joystick and update the GUI +// OnSaveById // ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ -void ConfigBox::EnableDisable(wxCommandEvent& event) +void ConfigBox::OnSaveById() { - // We will enable this device - joysticks[notebookpage].enabled = !joysticks[notebookpage].enabled; + // Save current settings + DoSave(false, notebookpage); - // Update the GUI + // Update the setting and load the settings + g_Config.bSaveByID = m_CBSaveByID[notebookpage]->IsChecked(); + g_Config.Load(false, true); + + // Update GUI and PadMapping[] UpdateGUI(notebookpage); + SaveButtonMapping(notebookpage); } // Change Joystick // ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ -/* Function: When changing the joystick we save and load the settings and update the joysticks +/* Function: When changing the joystick we save and load the settings and update the PadMapping and joystate array */ void ConfigBox::DoChangeJoystick() { - // Before changing the pad we save potential changes (to support SaveByID) + // Close the current pad + if (PadMapping[notebookpage].enabled) PadClose(notebookpage); + + // Before changing the pad we save potential changes to the current pad (to support SaveByID) DoSave(true); // Load the settings for the new Id g_Config.Load(true); UpdateGUI(notebookpage); // Update the GUI - // Remap the controller - if (joysticks[notebookpage].enabled) - { - //Console::Print("Id: %i\n", joysticks[notebookpage].ID); - if (SDL_JoystickOpened(joysticks[notebookpage].ID)) SDL_JoystickClose(joystate[notebookpage].joy); - joystate[notebookpage].joy = SDL_JoystickOpen(joysticks[notebookpage].ID); - } + // Open the new pad + if (PadMapping[notebookpage].enabled) PadOpen(notebookpage); } -void ConfigBox::ChangeJoystick(wxCommandEvent& event) +void ConfigBox::PadOpen(int Open) // Open for slot 1, 2, 3 or 4 { - DoChangeJoystick(); + joystate[Open].joy = SDL_JoystickOpen(PadMapping[Open].ID); +} +void ConfigBox::PadClose(int Close) // Close for slot 1, 2, 3 or 4 +{ + if (SDL_JoystickOpened(PadMapping[Close].ID)) SDL_JoystickClose(joystate[Close].joy); } // Notebook page changed @@ -287,13 +319,14 @@ void ConfigBox::NotebookPageChanged(wxNotebookEvent& event) { int oldnotebookpage = notebookpage; notebookpage = event.GetSelection(); - int OldId = joysticks[oldnotebookpage].ID; - int NewId = joysticks[notebookpage].ID; + int OldId = PadMapping[oldnotebookpage].ID; + int NewId = PadMapping[notebookpage].ID; // Check if it has changed. If it has save the old Id and load the new Id - if(OldId != NewId) - DoChangeJoystick(); + if(OldId != NewId) DoChangeJoystick(); + // Update GUI + if(ControlsCreated) UpdateGUI(notebookpage); } // Replace the harder to understand -1 with "" for the sake of user friendliness @@ -318,18 +351,26 @@ void ConfigBox::ToBlank(bool ToBlank) ////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////////// // Change settings // ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ +void ConfigBox::UpdateAllSlots(int Slot) +{ + for (int i = 0; i < 4; i++) + { + if (joyinfo[PadMapping[i].ID].Name == joyinfo[PadMapping[Slot].ID].Name) + SaveButtonMapping(i, false, Slot); + //LogMsg("%i: %s\n", i, joyinfo[PadMapping[i].ID].Name.c_str()); + UpdateGUI(i); + }; +} void ConfigBox::ChangeSettings( wxCommandEvent& event ) { switch(event.GetId()) { case IDC_SAVEBYID: - g_Config.bSaveByID.at(notebookpage) = m_CBSaveByID[notebookpage]->IsChecked(); - break; - case IDC_SAVEBYIDNOTICE: - g_Config.bSaveByIDNotice = m_CBSaveByIDNotice[notebookpage]->IsChecked(); - break; + OnSaveById(); + break; case IDC_SHOWADVANCED: g_Config.bShowAdvanced = m_CBShowAdvanced[notebookpage]->IsChecked(); @@ -341,35 +382,52 @@ void ConfigBox::ChangeSettings( wxCommandEvent& event ) SizeWindow(); break; - case IDCB_MAINSTICK_DIAGONAL: - g_Config.SDiagonal.at(notebookpage) = m_CoBDiagonal[notebookpage]->GetLabel().mb_str(); + case IDC_CONTROLTYPE: + case IDC_TRIGGERTYPE: + SaveButtonMapping(notebookpage); + UpdateGUI(notebookpage); break; - case IDCB_MAINSTICK_S_TO_C: - g_Config.bSquareToCircle.at(notebookpage) = m_CBS_to_C[notebookpage]->IsChecked(); + case IDC_JOYNAME: + DoChangeJoystick(); break; + + case IDC_JOYATTACH: + // We will enable this device + int Enable = PadMapping[notebookpage].enabled = !PadMapping[notebookpage].enabled; + // Close or open pad handle + if(Enable) PadOpen(notebookpage); else PadClose(notebookpage); + // Update the GUI + UpdateGUI(notebookpage); + return; // Don't save this for all slots } + + // Update all slots that use this device + if(g_Config.bSaveByID) UpdateAllSlots(notebookpage); } +/////////////////////////////// +/////////////////////////////////////////////////////////////////////////////////// // Update GUI // ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ -// Called from: ChangeControllertype() +// Called from: CreateGUIControls(), ChangeControllertype() void ConfigBox::UpdateGUI(int _notebookpage) { - // Update the GUI from joysticks[] + // Update the GUI from PadMapping[] UpdateGUIKeys(_notebookpage); - // Controller type settings - bool Hat = (joysticks[_notebookpage].controllertype == CTL_DPAD_HAT); + // Collect status + bool Hat = (PadMapping[_notebookpage].controllertype == CTL_DPAD_HAT); long Left, Right; m_JoyShoulderL[_notebookpage]->GetValue().ToLong(&Left); m_JoyShoulderR[_notebookpage]->GetValue().ToLong(&Right); bool AnalogTrigger = (Left >= 1000 || Right >= 1000); -#ifdef _WIN32 - bool XInput = XInput::IsConnected(0); -#endif + #ifdef _WIN32 + bool XInput = XInput::IsConnected(0); + #endif + // Hat type selection m_JoyDpadUp[_notebookpage]->Show(!Hat); m_JoyDpadLeft[_notebookpage]->Show(!Hat); m_JoyDpadRight[_notebookpage]->Show(!Hat); @@ -387,23 +445,13 @@ void ConfigBox::UpdateGUI(int _notebookpage) wxT("Select a hat by pressing the hat in any direction") : wxT("")); // General settings - m_CBSaveByID[_notebookpage]->SetValue(g_Config.bSaveByID.at(_notebookpage)); - m_CBSaveByIDNotice[_notebookpage]->SetValue(g_Config.bSaveByIDNotice); + m_CBSaveByID[_notebookpage]->SetValue(g_Config.bSaveByID); m_CBShowAdvanced[_notebookpage]->SetValue(g_Config.bShowAdvanced); - // Controller type values -#ifdef _WIN32 - if (!XInput) m_TriggerType[_notebookpage]->SetSelection(CTL_TRIGGER_SDL); -#else - m_TriggerType[_notebookpage]->SetSelection(CTL_TRIGGER_SDL); -#endif - - // Advanced settings - m_CoBDiagonal[_notebookpage]->SetValue(wxString::FromAscii(g_Config.SDiagonal.at(_notebookpage).c_str())); - m_CBS_to_C[_notebookpage]->SetValue(g_Config.bSquareToCircle.at(_notebookpage)); + LogMsg("Update: %i\n", g_Config.bSaveByID); // Disabled pages - bool Enabled = joysticks[_notebookpage].enabled; + bool Enabled = PadMapping[_notebookpage].enabled; // There is no FindItem in linux so this doesn't work #ifdef _WIN32 // Enable or disable all buttons @@ -423,8 +471,10 @@ void ConfigBox::UpdateGUI(int _notebookpage) // Repaint the background m_Controller[_notebookpage]->Refresh(); } +/////////////////////////////// -// Populate the config window + +// Paint the background // ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ void ConfigBox::OnPaint( wxPaintEvent &event ) { @@ -432,7 +482,7 @@ void ConfigBox::OnPaint( wxPaintEvent &event ) wxPaintDC dcWin(m_pKeys[notebookpage]); PrepareDC( dcWin ); - if(joysticks[notebookpage].enabled) + if(PadMapping[notebookpage].enabled) dcWin.DrawBitmap( WxStaticBitmap1_BITMAP, 94, 0, true ); else dcWin.DrawBitmap( WxStaticBitmap1_BITMAPGray, 94, 0, true ); @@ -497,7 +547,7 @@ void ConfigBox::CreateGUIControls() { for(int x = 0; x < SDL_NumJoysticks(); x++) { - arrayStringFor_Joyname.Add(wxString::FromAscii(joyinfo[x].Name)); + arrayStringFor_Joyname.Add(wxString::FromAscii(joyinfo[x].Name.c_str())); } } else @@ -709,14 +759,10 @@ void ConfigBox::CreateGUIControls() // Create objects for general settings 3 m_gGenSettingsID[i] = new wxStaticBoxSizer( wxVERTICAL, m_Controller[i], wxT("Settings") ); m_CBSaveByID[i] = new wxCheckBox(m_Controller[i], IDC_SAVEBYID, wxT("Save by ID"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator); - m_CBSaveByIDNotice[i] = new wxCheckBox(m_Controller[i], IDC_SAVEBYIDNOTICE, wxT("Notify"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator); m_CBShowAdvanced[i] = new wxCheckBox(m_Controller[i], IDC_SHOWADVANCED, wxT("Show advanced settings"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator); // Populate general settings 3 - m_sSaveByID[i] = new wxBoxSizer(wxHORIZONTAL); - m_sSaveByID[i]->Add(m_CBSaveByID[i], 0, wxEXPAND | wxALL, 0); - m_sSaveByID[i]->Add(m_CBSaveByIDNotice[i], 0, wxEXPAND | wxLEFT, 2); - m_gGenSettingsID[i]->Add(m_sSaveByID[i], 0, wxEXPAND | wxALL, 3); + m_gGenSettingsID[i]->Add(m_CBSaveByID[i], 0, wxEXPAND | wxALL, 3); m_gGenSettingsID[i]->Add(m_CBShowAdvanced[i], 0, wxEXPAND | wxALL, 3); // Create tooltips @@ -728,13 +774,10 @@ void ConfigBox::CreateGUIControls() )); m_CBSaveByID[i]->SetToolTip(wxString::Format(wxT( "Map these settings to the selected controller device instead of to the" - "\nselected controller number (%i). This may be a more convenient way" + "\nselected slot (1, 2, 3 or 4). This may be a more convenient way" "\nto save your settings if you have multiple controllers.") , i+1 - )); - m_CBSaveByIDNotice[i]->SetToolTip(wxString::Format(wxT( - "Show a notification message if you have selected this option for multiple identical joypads.") - )); + )); // Populate settings m_sSettings[i] = new wxBoxSizer ( wxHORIZONTAL ); @@ -846,9 +889,6 @@ void ConfigBox::CreateGUIControls() m_ControlType[i]->Enable(false); } - // Set dialog items from saved values - //UpdateGUIKeys(i); - // Update GUI UpdateGUI(i); } // end of loop @@ -875,15 +915,23 @@ void ConfigBox::CreateGUIControls() // -------------------------------------------------------------------- // Debugging // ----------------------------- - //m_pStatusBar = new wxStaticText(this, IDT_DEBUGGING, wxT("Debugging"), wxPoint(150, 100), wxDefaultSize); - //m_pStatusBar2 = new wxStaticText(this, IDT_DEBUGGING2, wxT("Debugging2"), wxPoint(150, 200), wxDefaultSize); + /*m_pStatusBar = new wxStaticText(this, IDT_DEBUGGING, wxT("Debugging"), wxPoint(135, 100), wxDefaultSize); + //m_pStatusBar2 = new wxStaticText(this, IDT_DEBUGGING2, wxT("Debugging2"), wxPoint(125, 200), wxDefaultSize); //m_pStatusBar->SetLabel(wxString::Format("Debugging text")); + m_TCDebugging = new wxTextCtrl(this, IDT_DEBUGGING3, _T(""), wxDefaultPosition, wxSize(400, 400), + wxTE_RICH | wxTE_MULTILINE | wxTE_DONTWRAP | wxNO_BORDER); + wxBoxSizer * m_LogSizer = new wxBoxSizer(wxVERTICAL); + m_LogSizer->Add(m_TCDebugging, 0, wxEXPAND | (wxALL), 0); + m_MainSizer->Add(m_LogSizer, 0, wxEXPAND | ( wxLEFT | wxRIGHT | wxBOTTOM), 5);*/ // -------------------------------------------------------------------- // Set window size // ----------------------------- SizeWindow(); Center(); + + // All done + ControlsCreated = true; } void ConfigBox::SizeWindow() diff --git a/Source/Plugins/Plugin_nJoy_SDL/Src/GUI/ConfigBox.h b/Source/Plugins/Plugin_nJoy_SDL/Src/GUI/ConfigBox.h index 85d48967c4..c08c8b337a 100644 --- a/Source/Plugins/Plugin_nJoy_SDL/Src/GUI/ConfigBox.h +++ b/Source/Plugins/Plugin_nJoy_SDL/Src/GUI/ConfigBox.h @@ -69,6 +69,9 @@ class ConfigBox : public wxDialog // Debugging wxStaticText* m_pStatusBar, * m_pStatusBar2; + wxTextCtrl* m_TCDebugging; + bool Debugging; + void LogMsg(const char* format, ...); // Status window int BoxW, BoxH; @@ -107,10 +110,9 @@ class ConfigBox : public wxDialog wxBoxSizer* m_sSettings[4]; // General settings 2 wxStaticBoxSizer *m_gGenSettings[4]; - wxBoxSizer *m_sSaveByID[4]; wxStaticBoxSizer *m_gGenSettingsID[4]; wxGridBagSizer * m_gGBGenSettings[4]; - wxCheckBox *m_CBSaveByID[4], *m_CBSaveByIDNotice[4], *m_CBShowAdvanced[4]; + wxCheckBox *m_CBSaveByID[4], *m_CBShowAdvanced[4]; wxStaticText *m_TSControltype[4], *m_TSTriggerType[4]; wxStaticBoxSizer *m_gStatusIn[4], *m_gStatusInSettings[4]; // Advanced settings @@ -185,7 +187,8 @@ class ConfigBox : public wxDialog wxStaticBitmap *m_controllerimage[4], *m_bmpSquare[4], *m_bmpDot[4], *m_bmpSquareOut[4], *m_bmpDotOut[4]; - int notebookpage; + int notebookpage; bool ControlsCreated; + private: enum { @@ -207,7 +210,7 @@ class ConfigBox : public wxDialog IDG_CONTROLLERTYPE, IDC_CONTROLTYPE, IDC_TRIGGERTYPE, // Controller type - IDC_SAVEBYID, IDC_SAVEBYIDNOTICE, IDC_SHOWADVANCED, // Settings + IDC_SAVEBYID, IDC_SHOWADVANCED, // Settings ID_INSTATUS1, ID_INSTATUS2, ID_INSTATUS3, ID_INSTATUS4, // Advanced status ID_STATUSBMP1, ID_STATUSBMP2, ID_STATUSBMP3, ID_STATUSBMP4, @@ -290,7 +293,7 @@ class ConfigBox : public wxDialog IDT_DPADTYPE, IDT_TRIGGERTYPE, IDT_WEBSITE, - IDT_DEBUGGING, IDT_DEBUGGING2, + IDT_DEBUGGING, IDT_DEBUGGING2, IDT_DEBUGGING3, // ============ ID_DUMMY_VALUE_ //don't remove this value unless you have other enum values @@ -300,13 +303,12 @@ class ConfigBox : public wxDialog void AboutClick(wxCommandEvent& event); void OKClick(wxCommandEvent& event); void CancelClick(wxCommandEvent& event); - void DoSave(bool ChangePad = false, bool CheckedForDuplicates = false); + void DoSave(bool ChangePad = false, int Slot = -1); - void ChangeJoystick(wxCommandEvent& event); void DoChangeJoystick(); - void ChangeControllertype(wxCommandEvent& event); - void EnableDisable(wxCommandEvent& event); void UpdateGUI(int _notebookpage); + void DoChangeJoystick(); void PadOpen(int Open); void PadClose(int Close); + void UpdateGUI(int _notebookpage); - void ChangeSettings(wxCommandEvent& event); // Settings + void ChangeSettings(wxCommandEvent& event); void UpdateAllSlots(int Slot); // Settings void ComboChange(wxCommandEvent& event); void OnClose(wxCloseEvent& event); @@ -316,8 +318,9 @@ class ConfigBox : public wxDialog void PadGetStatus(); void Update(); void UpdateGUIKeys(int controller); - void SaveButtonMapping(int controller, bool DontChangeId = false); + void SaveButtonMapping(int controller, bool DontChangeId = false, int FromSlot = -1); void ToBlank(bool ToBlank = true); + void OnSaveById(); void NotebookPageChanged(wxNotebookEvent& event); diff --git a/Source/Plugins/Plugin_nJoy_SDL/Src/GUI/ConfigJoypad.cpp b/Source/Plugins/Plugin_nJoy_SDL/Src/GUI/ConfigJoypad.cpp index 9e4d6c0e1e..1e17eaf215 100644 --- a/Source/Plugins/Plugin_nJoy_SDL/Src/GUI/ConfigJoypad.cpp +++ b/Source/Plugins/Plugin_nJoy_SDL/Src/GUI/ConfigJoypad.cpp @@ -40,7 +40,7 @@ #include "Images/controller.xpm" extern CONTROLLER_INFO *joyinfo; -//extern CONTROLLER_MAPPING joysticks[4]; +//extern CONTROLLER_MAPPING PadMapping[4]; extern bool emulator_running; //////////////////////// @@ -53,115 +53,115 @@ void ConfigBox::UpdateGUIKeys(int controller) wxString tmp; // Update selected gamepad - m_Joyname[controller]->SetSelection(joysticks[controller].ID); + m_Joyname[controller]->SetSelection(PadMapping[controller].ID); // Update the enabled checkbox - m_Joyattach[controller]->SetValue(joysticks[controller].enabled); + m_Joyattach[controller]->SetValue(PadMapping[controller].enabled); - tmp << joysticks[controller].buttons[CTL_L_SHOULDER]; m_JoyShoulderL[controller]->SetValue(tmp); tmp.clear(); - tmp << joysticks[controller].buttons[CTL_R_SHOULDER]; m_JoyShoulderR[controller]->SetValue(tmp); tmp.clear(); + tmp << PadMapping[controller].buttons[CTL_L_SHOULDER]; m_JoyShoulderL[controller]->SetValue(tmp); tmp.clear(); + tmp << PadMapping[controller].buttons[CTL_R_SHOULDER]; m_JoyShoulderR[controller]->SetValue(tmp); tmp.clear(); - tmp << joysticks[controller].buttons[CTL_A_BUTTON]; m_JoyButtonA[controller]->SetValue(tmp); tmp.clear(); - tmp << joysticks[controller].buttons[CTL_B_BUTTON]; m_JoyButtonB[controller]->SetValue(tmp); tmp.clear(); - tmp << joysticks[controller].buttons[CTL_X_BUTTON]; m_JoyButtonX[controller]->SetValue(tmp); tmp.clear(); - tmp << joysticks[controller].buttons[CTL_Y_BUTTON]; m_JoyButtonY[controller]->SetValue(tmp); tmp.clear(); - tmp << joysticks[controller].buttons[CTL_Z_TRIGGER]; m_JoyButtonZ[controller]->SetValue(tmp); tmp.clear(); + tmp << PadMapping[controller].buttons[CTL_A_BUTTON]; m_JoyButtonA[controller]->SetValue(tmp); tmp.clear(); + tmp << PadMapping[controller].buttons[CTL_B_BUTTON]; m_JoyButtonB[controller]->SetValue(tmp); tmp.clear(); + tmp << PadMapping[controller].buttons[CTL_X_BUTTON]; m_JoyButtonX[controller]->SetValue(tmp); tmp.clear(); + tmp << PadMapping[controller].buttons[CTL_Y_BUTTON]; m_JoyButtonY[controller]->SetValue(tmp); tmp.clear(); + tmp << PadMapping[controller].buttons[CTL_Z_TRIGGER]; m_JoyButtonZ[controller]->SetValue(tmp); tmp.clear(); - tmp << joysticks[controller].buttons[CTL_START]; m_JoyButtonStart[controller]->SetValue(tmp); tmp.clear(); - tmp << joysticks[controller].halfpress; m_JoyButtonHalfpress[controller]->SetValue(tmp); tmp.clear(); + tmp << PadMapping[controller].buttons[CTL_START]; m_JoyButtonStart[controller]->SetValue(tmp); tmp.clear(); + tmp << PadMapping[controller].halfpress; m_JoyButtonHalfpress[controller]->SetValue(tmp); tmp.clear(); - tmp << joysticks[controller].axis[CTL_MAIN_X]; m_JoyAnalogMainX[controller]->SetValue(tmp); tmp.clear(); - tmp << joysticks[controller].axis[CTL_MAIN_Y]; m_JoyAnalogMainY[controller]->SetValue(tmp); tmp.clear(); - tmp << joysticks[controller].axis[CTL_SUB_X]; m_JoyAnalogSubX[controller]->SetValue(tmp); tmp.clear(); - tmp << joysticks[controller].axis[CTL_SUB_Y]; m_JoyAnalogSubY[controller]->SetValue(tmp); tmp.clear(); + tmp << PadMapping[controller].axis[CTL_MAIN_X]; m_JoyAnalogMainX[controller]->SetValue(tmp); tmp.clear(); + tmp << PadMapping[controller].axis[CTL_MAIN_Y]; m_JoyAnalogMainY[controller]->SetValue(tmp); tmp.clear(); + tmp << PadMapping[controller].axis[CTL_SUB_X]; m_JoyAnalogSubX[controller]->SetValue(tmp); tmp.clear(); + tmp << PadMapping[controller].axis[CTL_SUB_Y]; m_JoyAnalogSubY[controller]->SetValue(tmp); tmp.clear(); // Update the deadzone and controller type controls - m_ControlType[controller]->SetSelection(joysticks[controller].controllertype); - m_TriggerType[controller]->SetSelection(joysticks[controller].triggertype); - m_Deadzone[controller]->SetSelection(joysticks[controller].deadzone); + m_ControlType[controller]->SetSelection(PadMapping[controller].controllertype); + m_TriggerType[controller]->SetSelection(PadMapping[controller].triggertype); + m_Deadzone[controller]->SetSelection(PadMapping[controller].deadzone); + m_CoBDiagonal[controller]->SetValue(wxString::FromAscii(PadMapping[controller].SDiagonal.c_str())); + m_CBS_to_C[controller]->SetValue(PadMapping[controller].bSquareToCircle); + + LogMsg("bSquareToCircle: %i\n", PadMapping[controller].bSquareToCircle); // Update D-Pad - if(joysticks[controller].controllertype == CTL_DPAD_HAT) + if(PadMapping[controller].controllertype == CTL_DPAD_HAT) { - tmp << joysticks[controller].dpad; m_JoyDpadUp[controller]->SetValue(tmp); tmp.clear(); + tmp << PadMapping[controller].dpad; m_JoyDpadUp[controller]->SetValue(tmp); tmp.clear(); } else { - tmp << joysticks[controller].dpad2[CTL_D_PAD_UP]; m_JoyDpadUp[controller]->SetValue(tmp); tmp.clear(); - tmp << joysticks[controller].dpad2[CTL_D_PAD_DOWN]; m_JoyDpadDown[controller]->SetValue(tmp); tmp.clear(); - tmp << joysticks[controller].dpad2[CTL_D_PAD_LEFT]; m_JoyDpadLeft[controller]->SetValue(tmp); tmp.clear(); - tmp << joysticks[controller].dpad2[CTL_D_PAD_RIGHT]; m_JoyDpadRight[controller]->SetValue(tmp); tmp.clear(); + tmp << PadMapping[controller].dpad2[CTL_D_PAD_UP]; m_JoyDpadUp[controller]->SetValue(tmp); tmp.clear(); + tmp << PadMapping[controller].dpad2[CTL_D_PAD_DOWN]; m_JoyDpadDown[controller]->SetValue(tmp); tmp.clear(); + tmp << PadMapping[controller].dpad2[CTL_D_PAD_LEFT]; m_JoyDpadLeft[controller]->SetValue(tmp); tmp.clear(); + tmp << PadMapping[controller].dpad2[CTL_D_PAD_RIGHT]; m_JoyDpadRight[controller]->SetValue(tmp); tmp.clear(); } } -/* Populate the joysticks array with the dialog items settings, for example - selected joystick, enabled or disabled status and so on */ +/* Populate the PadMapping array with the dialog items settings (for example + selected joystick, enabled or disabled status and so on) */ // ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ -void ConfigBox::SaveButtonMapping(int controller, bool DontChangeId) +void ConfigBox::SaveButtonMapping(int controller, bool DontChangeId, int FromSlot) { // Temporary storage wxString tmp; long value; + // Save from or to the same or different slots + if (FromSlot == -1) FromSlot = controller; + // Replace "" with "-1" ToBlank(false); // Set enabled or disable status and other settings - if(!DontChangeId) joysticks[controller].ID = m_Joyname[controller]->GetSelection(); - joysticks[controller].enabled = m_Joyattach[controller]->GetValue(); - joysticks[controller].controllertype = m_ControlType[controller]->GetSelection(); - joysticks[controller].triggertype = m_TriggerType[controller]->GetSelection(); - joysticks[controller].deadzone = m_Deadzone[controller]->GetSelection(); + if(!DontChangeId) PadMapping[controller].ID = m_Joyname[FromSlot]->GetSelection(); + if(FromSlot == controller) PadMapping[controller].enabled = m_Joyattach[FromSlot]->GetValue(); // Only enable one + PadMapping[controller].controllertype = m_ControlType[FromSlot]->GetSelection(); + PadMapping[controller].triggertype = m_TriggerType[FromSlot]->GetSelection(); + PadMapping[controller].deadzone = m_Deadzone[FromSlot]->GetSelection(); + PadMapping[controller].SDiagonal = m_CoBDiagonal[FromSlot]->GetLabel().mb_str(); + PadMapping[controller].bSquareToCircle = m_CBS_to_C[FromSlot]->IsChecked(); // The analog buttons - m_JoyAnalogMainX[controller]->GetValue().ToLong(&value); joysticks[controller].axis[CTL_MAIN_X] = value; tmp.clear(); - m_JoyAnalogMainY[controller]->GetValue().ToLong(&value); joysticks[controller].axis[CTL_MAIN_Y] = value; tmp.clear(); - m_JoyAnalogSubX[controller]->GetValue().ToLong(&value); joysticks[controller].axis[CTL_SUB_X] = value; tmp.clear(); - m_JoyAnalogSubY[controller]->GetValue().ToLong(&value); joysticks[controller].axis[CTL_SUB_Y] = value; tmp.clear(); + m_JoyAnalogMainX[FromSlot]->GetValue().ToLong(&value); PadMapping[controller].axis[CTL_MAIN_X] = value; tmp.clear(); + m_JoyAnalogMainY[FromSlot]->GetValue().ToLong(&value); PadMapping[controller].axis[CTL_MAIN_Y] = value; tmp.clear(); + m_JoyAnalogSubX[FromSlot]->GetValue().ToLong(&value); PadMapping[controller].axis[CTL_SUB_X] = value; tmp.clear(); + m_JoyAnalogSubY[FromSlot]->GetValue().ToLong(&value); PadMapping[controller].axis[CTL_SUB_Y] = value; tmp.clear(); // The shoulder buttons - m_JoyShoulderL[controller]->GetValue().ToLong(&value); joysticks[controller].buttons[CTL_L_SHOULDER] = value; - m_JoyShoulderR[controller]->GetValue().ToLong(&value); joysticks[controller].buttons[CTL_R_SHOULDER] = value; + m_JoyShoulderL[FromSlot]->GetValue().ToLong(&value); PadMapping[controller].buttons[CTL_L_SHOULDER] = value; + m_JoyShoulderR[FromSlot]->GetValue().ToLong(&value); PadMapping[controller].buttons[CTL_R_SHOULDER] = value; // The digital buttons - m_JoyButtonA[controller]->GetValue().ToLong(&value); joysticks[controller].buttons[CTL_A_BUTTON] = value; tmp.clear(); - m_JoyButtonB[controller]->GetValue().ToLong(&value); joysticks[controller].buttons[CTL_B_BUTTON] = value; tmp.clear(); - m_JoyButtonX[controller]->GetValue().ToLong(&value); joysticks[controller].buttons[CTL_X_BUTTON] = value; tmp.clear(); - m_JoyButtonY[controller]->GetValue().ToLong(&value); joysticks[controller].buttons[CTL_Y_BUTTON] = value; tmp.clear(); - m_JoyButtonZ[controller]->GetValue().ToLong(&value); joysticks[controller].buttons[CTL_Z_TRIGGER] = value; tmp.clear(); - m_JoyButtonStart[controller]->GetValue().ToLong(&value); joysticks[controller].buttons[CTL_START] = value; tmp.clear(); + m_JoyButtonA[FromSlot]->GetValue().ToLong(&value); PadMapping[controller].buttons[CTL_A_BUTTON] = value; tmp.clear(); + m_JoyButtonB[FromSlot]->GetValue().ToLong(&value); PadMapping[controller].buttons[CTL_B_BUTTON] = value; tmp.clear(); + m_JoyButtonX[FromSlot]->GetValue().ToLong(&value); PadMapping[controller].buttons[CTL_X_BUTTON] = value; tmp.clear(); + m_JoyButtonY[FromSlot]->GetValue().ToLong(&value); PadMapping[controller].buttons[CTL_Y_BUTTON] = value; tmp.clear(); + m_JoyButtonZ[FromSlot]->GetValue().ToLong(&value); PadMapping[controller].buttons[CTL_Z_TRIGGER] = value; tmp.clear(); + m_JoyButtonStart[FromSlot]->GetValue().ToLong(&value); PadMapping[controller].buttons[CTL_START] = value; tmp.clear(); + + LogMsg("SaveButtonMapping: Key:%i From:%i To:%i\n", m_TriggerType[FromSlot]->GetSelection(), FromSlot, controller); // The halfpress button - m_JoyButtonHalfpress[controller]->GetValue().ToLong(&value); joysticks[controller].halfpress = value; tmp.clear(); + m_JoyButtonHalfpress[FromSlot]->GetValue().ToLong(&value); PadMapping[controller].halfpress = value; tmp.clear(); // The digital pad - if(joysticks[controller].controllertype == CTL_DPAD_HAT) + if(PadMapping[controller].controllertype == CTL_DPAD_HAT) { - m_JoyDpadUp[controller]->GetValue().ToLong(&value); joysticks[controller].dpad = value; tmp.clear(); + m_JoyDpadUp[FromSlot]->GetValue().ToLong(&value); PadMapping[controller].dpad = value; tmp.clear(); } else { - m_JoyDpadUp[controller]->GetValue().ToLong(&value); joysticks[controller].dpad2[CTL_D_PAD_UP] = value; tmp.clear(); - m_JoyDpadDown[controller]->GetValue().ToLong(&value); joysticks[controller].dpad2[CTL_D_PAD_DOWN] = value; tmp.clear(); - m_JoyDpadLeft[controller]->GetValue().ToLong(&value); joysticks[controller].dpad2[CTL_D_PAD_LEFT] = value; tmp.clear(); - m_JoyDpadRight[controller]->GetValue().ToLong(&value); joysticks[controller].dpad2[CTL_D_PAD_RIGHT] = value; tmp.clear(); + m_JoyDpadUp[FromSlot]->GetValue().ToLong(&value); PadMapping[controller].dpad2[CTL_D_PAD_UP] = value; tmp.clear(); + m_JoyDpadDown[FromSlot]->GetValue().ToLong(&value); PadMapping[controller].dpad2[CTL_D_PAD_DOWN] = value; tmp.clear(); + m_JoyDpadLeft[FromSlot]->GetValue().ToLong(&value); PadMapping[controller].dpad2[CTL_D_PAD_LEFT] = value; tmp.clear(); + m_JoyDpadRight[FromSlot]->GetValue().ToLong(&value); PadMapping[controller].dpad2[CTL_D_PAD_RIGHT] = value; tmp.clear(); } // Replace "-1" with "" ToBlank(); } - -// Change controller type -// ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ -// Called from: When the controller type is changed -void ConfigBox::ChangeControllertype(wxCommandEvent& event) -{ - SaveButtonMapping(notebookpage); - UpdateGUI(notebookpage); -} - - // Update the textbox for the buttons // ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ void ConfigBox::SetButtonText(int id, char text[128]) @@ -271,8 +271,8 @@ void ConfigBox::DoGetButtons(int GetId) int Controller = notebookpage; // Get the controller and trigger type - int ControllerType = joysticks[Controller].controllertype; - int TriggerType = joysticks[Controller].triggertype; + int ControllerType = PadMapping[Controller].controllertype; + int TriggerType = PadMapping[Controller].triggertype; // Collect the accepted buttons for this slot bool LeftRight = (GetId == IDB_SHOULDER_L || GetId == IDB_SHOULDER_R); @@ -287,11 +287,11 @@ void ConfigBox::DoGetButtons(int GetId) || (GetId >= IDB_DPAD_UP && GetId <= IDB_DPAD_RIGHT && ControllerType == CTL_DPAD_CUSTOM); // Or the custom hat mode bool Hat = (GetId >= IDB_DPAD_UP && GetId <= IDB_DPAD_RIGHT) // All DPads - && (joysticks[Controller].controllertype == CTL_DPAD_HAT); // Not with the hat option defined + && (PadMapping[Controller].controllertype == CTL_DPAD_HAT); // Not with the hat option defined /* Open a new joystick. Joysticks[controller].GetId is the system GetId of the physical joystick - that is mapped to controller, for example 0, 1, 2, 3 for the first four joysticks */ - SDL_Joystick *joy = SDL_JoystickOpen(joysticks[Controller].ID); + that is mapped to controller, for example 0, 1, 2, 3 for the first four PadMapping */ + SDL_Joystick *joy = SDL_JoystickOpen(PadMapping[Controller].ID); // Get the number of axes, hats and buttons int buttons = SDL_JoystickNumButtons(joy); @@ -475,6 +475,13 @@ void ConfigBox::DoGetButtons(int GetId) // Update the button mapping and GUI SaveButtonMapping(Controller); UpdateGUI(Controller); + + /* Update the button mapping for all slots that use this device. (It doesn't make sense to have several slots + controlled by the same device, but several DirectInput instances of different but identical devices may possible + have the same id, I don't know. So we have to do this. The user may also have selected the same device for + several disabled slots. */ + if(g_Config.bSaveByID) UpdateAllSlots(Controller); + } // If we got a bad button @@ -491,7 +498,7 @@ void ConfigBox::DoGetButtons(int GetId) // ======================== Process results // We don't need this gamepad handle any more - if(SDL_JoystickOpened(joysticks[Controller].ID)) SDL_JoystickClose(joy); + if(SDL_JoystickOpened(PadMapping[Controller].ID)) SDL_JoystickClose(joy); // Debugging //Console::Print("IsRunning: %i\n", m_ButtonMappingTimer->IsRunning()); diff --git a/Source/Plugins/Plugin_nJoy_SDL/Src/Rumble.cpp b/Source/Plugins/Plugin_nJoy_SDL/Src/Rumble.cpp index a3e593b767..5a4991785d 100644 --- a/Source/Plugins/Plugin_nJoy_SDL/Src/Rumble.cpp +++ b/Source/Plugins/Plugin_nJoy_SDL/Src/Rumble.cpp @@ -172,7 +172,7 @@ void Pad_Use_Rumble(u8 _numPAD, SPADStatus* _pPADStatus) #elif defined(__linux__) if (!fd) { - sprintf(device_file_name, "/dev/input/event%d", joysticks[_numPAD].eventnum); //TODO: Make dynamic // + sprintf(device_file_name, "/dev/input/event%d", PadMapping[_numPAD].eventnum); //TODO: Make dynamic // /* Open device */ fd = open(device_file_name, O_RDWR); diff --git a/Source/Plugins/Plugin_nJoy_SDL/Src/nJoy.cpp b/Source/Plugins/Plugin_nJoy_SDL/Src/nJoy.cpp index b3218466db..558b2f01b5 100644 --- a/Source/Plugins/Plugin_nJoy_SDL/Src/nJoy.cpp +++ b/Source/Plugins/Plugin_nJoy_SDL/Src/nJoy.cpp @@ -47,18 +47,18 @@ // Variables guide /* ŻŻŻŻŻŻŻŻŻ - Joyinfo: A hardcoded struct of with gamepad info that is populate by Search_Devices() - Joysticks: A custom struct with the button mapping - Joystate: A custom struct with the current button states + Joyinfo[1, 2, 3, 4, ..., number of attached devices]: Gamepad info that is populate by Search_Devices() + PadMapping[1, 2, 3 and 4]: The button mapping + Joystate[1, 2, 3 and 4]: The current button states - The arrays joysticks[] and joystate[] are numbered 0 to 3 for the four different virtual + The arrays PadMapping[] and joystate[] are numbered 0 to 3 for the four different virtual controllers. Joysticks[].ID will have the number of the physical input device mapped to that controller (this value range between 0 and the total number of connected physical devices). The mapping of a certain physical device to joystate[].joy is initially done by Initialize(), but for the configuration we can remap that, like in ConfigBox::ChangeJoystick(). The joyinfo[] array holds the physical gamepad info for a certain physical device. It's therefore - used as joyinfo[joysticks[controller].ID] if we want to get the joyinfo for a certain joystick. + used as joyinfo[PadMapping[controller].ID] if we want to get the joyinfo for a certain joystick. ////////////////////////*/ @@ -86,7 +86,7 @@ FILE *pFile; HINSTANCE nJoy_hInst = NULL; CONTROLLER_INFO *joyinfo = 0; CONTROLLER_STATE joystate[4]; -CONTROLLER_MAPPING joysticks[4]; +CONTROLLER_MAPPING PadMapping[4]; bool emulator_running = FALSE; HWND m_hWnd; // Handle to window @@ -264,15 +264,15 @@ void Initialize(void *init) #endif Search_Devices(); // Populate joyinfo for all attached devices - g_Config.Load(); // Load joystick mapping, joysticks[].ID etc - if (joysticks[0].enabled) - joystate[0].joy = SDL_JoystickOpen(joysticks[0].ID); - if (joysticks[1].enabled) - joystate[1].joy = SDL_JoystickOpen(joysticks[1].ID); - if (joysticks[2].enabled) - joystate[2].joy = SDL_JoystickOpen(joysticks[2].ID); - if (joysticks[3].enabled) - joystate[3].joy = SDL_JoystickOpen(joysticks[3].ID); + g_Config.Load(); // Load joystick mapping, PadMapping[].ID etc + if (PadMapping[0].enabled) + joystate[0].joy = SDL_JoystickOpen(PadMapping[0].ID); + if (PadMapping[1].enabled) + joystate[1].joy = SDL_JoystickOpen(PadMapping[1].ID); + if (PadMapping[2].enabled) + joystate[2].joy = SDL_JoystickOpen(PadMapping[2].ID); + if (PadMapping[3].enabled) + joystate[3].joy = SDL_JoystickOpen(PadMapping[3].ID); } @@ -297,7 +297,7 @@ int Search_Devices() joyinfo = new CONTROLLER_INFO [numjoy]; } - // Warn the user if no joysticks are detected + // Warn the user if no PadMapping are detected if (numjoy == 0) { #ifdef _WIN32 @@ -348,13 +348,13 @@ int Search_Devices() Called from: The Dolphin Core, ConfigBox::OnClose() */ void Shutdown() { - if (joysticks[0].enabled && SDL_JoystickOpened(joysticks[0].ID)) + if (PadMapping[0].enabled && SDL_JoystickOpened(PadMapping[0].ID)) SDL_JoystickClose(joystate[0].joy); - if (joysticks[1].enabled && SDL_JoystickOpened(joysticks[1].ID)) + if (PadMapping[1].enabled && SDL_JoystickOpened(PadMapping[1].ID)) SDL_JoystickClose(joystate[1].joy); - if (joysticks[2].enabled && SDL_JoystickOpened(joysticks[2].ID)) + if (PadMapping[2].enabled && SDL_JoystickOpened(PadMapping[2].ID)) SDL_JoystickClose(joystate[2].joy); - if (joysticks[3].enabled && SDL_JoystickOpened(joysticks[3].ID)) + if (PadMapping[3].enabled && SDL_JoystickOpened(PadMapping[3].ID)) SDL_JoystickClose(joystate[3].joy); SDL_Quit(); @@ -386,13 +386,13 @@ void PAD_Input(u16 _Key, u8 _UpDown) { for(int j = CTL_L_SHOULDER; j <= CTL_START; j++) { - if (joysticks[i].buttons[j] == _Key) + if (PadMapping[i].buttons[j] == _Key) { joystate[i].buttons[j] = _UpDown; break; } } for(int j = CTL_D_PAD_UP; j <= CTL_D_PAD_RIGHT; j++) { - if (joysticks[i].dpad2[j] == _Key) + if (PadMapping[i].dpad2[j] == _Key) { joystate[i].dpad2[j] = _UpDown; break; } } } @@ -413,7 +413,7 @@ void DoState(unsigned char **ptr, int mode) {} // Function: Gives the current pad status to the Core void PAD_GetStatus(u8 _numPAD, SPADStatus* _pPADStatus) { - if (!joysticks[_numPAD].enabled) + if (!PadMapping[_numPAD].enabled) return; // Clear pad status @@ -423,7 +423,7 @@ void PAD_GetStatus(u8 _numPAD, SPADStatus* _pPADStatus) GetJoyState(_numPAD); // Get type - int TriggerType = joysticks[_numPAD].triggertype; + int TriggerType = PadMapping[_numPAD].triggertype; /////////////////////////////////////////////////// // The analog controls @@ -438,7 +438,7 @@ void PAD_GetStatus(u8 _numPAD, SPADStatus* _pPADStatus) int TriggerRight = joystate[_numPAD].axis[CTL_R_SHOULDER]; // Check if we should make adjustments - if(g_Config.bSquareToCircle.at(_numPAD)) + if(PadMapping[_numPAD].bSquareToCircle) { std::vector main_xy = Pad_Square_to_Circle(i_main_stick_x, i_main_stick_y, _numPAD); i_main_stick_x = main_xy.at(0); @@ -452,15 +452,15 @@ void PAD_GetStatus(u8 _numPAD, SPADStatus* _pPADStatus) u8 sub_stick_y = Pad_Convert(i_sub_stick_y); // Convert the triggers values - if(joysticks[_numPAD].triggertype == CTL_TRIGGER_SDL) + if(PadMapping[_numPAD].triggertype == CTL_TRIGGER_SDL) { TriggerLeft = Pad_Convert(TriggerLeft); TriggerRight = Pad_Convert(TriggerRight); } // Set Deadzones (perhaps out of function?) - int deadzone = (int)(((float)(128.00/100.00)) * (float)(joysticks[_numPAD].deadzone + 1)); - int deadzone2 = (int)(((float)(-128.00/100.00)) * (float)(joysticks[_numPAD].deadzone + 1)); + int deadzone = (int)(((float)(128.00/100.00)) * (float)(PadMapping[_numPAD].deadzone + 1)); + int deadzone2 = (int)(((float)(-128.00/100.00)) * (float)(PadMapping[_numPAD].deadzone + 1)); // Send values to Dolpin if they are outside the deadzone if ((main_stick_x < deadzone2) || (main_stick_x > deadzone)) _pPADStatus->stickX = main_stick_x; @@ -519,7 +519,7 @@ void PAD_GetStatus(u8 _numPAD, SPADStatus* _pPADStatus) /////////////////////////////////////////////////// // The D-pad // ----------- - if (joysticks[_numPAD].controllertype == CTL_DPAD_HAT) + if (PadMapping[_numPAD].controllertype == CTL_DPAD_HAT) { if (joystate[_numPAD].dpad == SDL_HAT_LEFTUP || joystate[_numPAD].dpad == SDL_HAT_UP || joystate[_numPAD].dpad == SDL_HAT_RIGHTUP ) _pPADStatus->button|=PAD_BUTTON_UP; if (joystate[_numPAD].dpad == SDL_HAT_LEFTUP || joystate[_numPAD].dpad == SDL_HAT_LEFT || joystate[_numPAD].dpad == SDL_HAT_LEFTDOWN ) _pPADStatus->button|=PAD_BUTTON_LEFT; @@ -549,9 +549,9 @@ void PAD_GetStatus(u8 _numPAD, SPADStatus* _pPADStatus) Console::Print( "Trigger type: %s Left:%04x Right:%04x Value:%i\n" "D-Pad type: %s L:%i R:%i U:%i D:%i", - (joysticks[_numPAD].triggertype ? "CTL_TRIGGER_XINPUT" : "CTL_TRIGGER_SDL"), + (PadMapping[_numPAD].triggertype ? "CTL_TRIGGER_XINPUT" : "CTL_TRIGGER_SDL"), TriggerLeft, TriggerRight, TriggerValue, - (joysticks[_numPAD].controllertype ? "CTL_DPAD_CUSTOM" : "CTL_DPAD_HAT"), + (PadMapping[_numPAD].controllertype ? "CTL_DPAD_CUSTOM" : "CTL_DPAD_HAT"), 0, 0, 0, 0 );*/ } @@ -565,10 +565,10 @@ unsigned int PAD_GetAttachedPads() g_Config.Load(); - if (joysticks[0].enabled) connected |= 1; - if (joysticks[1].enabled) connected |= 2; - if (joysticks[2].enabled) connected |= 4; - if (joysticks[3].enabled) connected |= 8; + if (PadMapping[0].enabled) connected |= 1; + if (PadMapping[1].enabled) connected |= 2; + if (PadMapping[2].enabled) connected |= 4; + if (PadMapping[3].enabled) connected |= 8; return connected; } @@ -648,7 +648,7 @@ std::vector Pad_Square_to_Circle(int _x, int _y, int _pad) // ==================================== // Convert to circle // ----------- - int Tmp = atoi (g_Config.SDiagonal.at(_pad).substr(0, g_Config.SDiagonal.at(_pad).length() - 1).c_str()); + int Tmp = atoi (PadMapping[_pad].SDiagonal.substr(0, PadMapping[_pad].SDiagonal.length() - 1).c_str()); float Diagonal = Tmp / 100.0; // First make a perfect square in case we don't have one already @@ -695,7 +695,7 @@ std::vector Pad_Square_to_Circle(int _x, int _y, int _pad) // Read current joystick status /* ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ - The value joysticks[].buttons[] is the number of the assigned joypad button, + The value PadMapping[].buttons[] is the number of the assigned joypad button, joystate[].buttons[] is the status of the button, it becomes 0 (no pressed) or 1 (pressed) */ @@ -703,8 +703,8 @@ std::vector Pad_Square_to_Circle(int _x, int _y, int _pad) // ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ void ReadButton(int controller, int button) { - int ctl_button = joysticks[controller].buttons[button]; - if (ctl_button < joyinfo[joysticks[controller].ID].NumButtons) + int ctl_button = PadMapping[controller].buttons[button]; + if (ctl_button < joyinfo[PadMapping[controller].ID].NumButtons) { joystate[controller].buttons[button] = SDL_JoystickGetButton(joystate[controller].joy, ctl_button); } @@ -722,27 +722,27 @@ void GetJoyState(int controller) SDL_JoystickUpdate(); // Save the number of buttons - int Buttons = joyinfo[joysticks[controller].ID].NumButtons; + int Buttons = joyinfo[PadMapping[controller].ID].NumButtons; // Update axis states. It doesn't hurt much if we happen to ask for nonexisting axises here. - joystate[controller].axis[CTL_MAIN_X] = SDL_JoystickGetAxis(joystate[controller].joy, joysticks[controller].axis[CTL_MAIN_X]); - joystate[controller].axis[CTL_MAIN_Y] = SDL_JoystickGetAxis(joystate[controller].joy, joysticks[controller].axis[CTL_MAIN_Y]); - joystate[controller].axis[CTL_SUB_X] = SDL_JoystickGetAxis(joystate[controller].joy, joysticks[controller].axis[CTL_SUB_X]); - joystate[controller].axis[CTL_SUB_Y] = SDL_JoystickGetAxis(joystate[controller].joy, joysticks[controller].axis[CTL_SUB_Y]); + joystate[controller].axis[CTL_MAIN_X] = SDL_JoystickGetAxis(joystate[controller].joy, PadMapping[controller].axis[CTL_MAIN_X]); + joystate[controller].axis[CTL_MAIN_Y] = SDL_JoystickGetAxis(joystate[controller].joy, PadMapping[controller].axis[CTL_MAIN_Y]); + joystate[controller].axis[CTL_SUB_X] = SDL_JoystickGetAxis(joystate[controller].joy, PadMapping[controller].axis[CTL_SUB_X]); + joystate[controller].axis[CTL_SUB_Y] = SDL_JoystickGetAxis(joystate[controller].joy, PadMapping[controller].axis[CTL_SUB_Y]); // Update trigger axises #ifdef _WIN32 - if (joysticks[controller].triggertype == CTL_TRIGGER_SDL) + if (PadMapping[controller].triggertype == CTL_TRIGGER_SDL) { #endif - joystate[controller].axis[CTL_L_SHOULDER] = SDL_JoystickGetAxis(joystate[controller].joy, joysticks[controller].buttons[CTL_L_SHOULDER] - 1000); - joystate[controller].axis[CTL_R_SHOULDER] = SDL_JoystickGetAxis(joystate[controller].joy, joysticks[controller].buttons[CTL_R_SHOULDER] - 1000); + joystate[controller].axis[CTL_L_SHOULDER] = SDL_JoystickGetAxis(joystate[controller].joy, PadMapping[controller].buttons[CTL_L_SHOULDER] - 1000); + joystate[controller].axis[CTL_R_SHOULDER] = SDL_JoystickGetAxis(joystate[controller].joy, PadMapping[controller].buttons[CTL_R_SHOULDER] - 1000); #ifdef _WIN32 } else { - joystate[controller].axis[CTL_L_SHOULDER] = XInput::GetXI(0, joysticks[controller].buttons[CTL_L_SHOULDER] - 1000); - joystate[controller].axis[CTL_R_SHOULDER] = XInput::GetXI(0, joysticks[controller].buttons[CTL_R_SHOULDER] - 1000); + joystate[controller].axis[CTL_L_SHOULDER] = XInput::GetXI(0, PadMapping[controller].buttons[CTL_L_SHOULDER] - 1000); + joystate[controller].axis[CTL_R_SHOULDER] = XInput::GetXI(0, PadMapping[controller].buttons[CTL_R_SHOULDER] - 1000); } #endif @@ -752,8 +752,8 @@ void GetJoyState(int controller) "Controller and handle: %i %i\n" "Triggers:%i %i %i %i %i\n", controller, (int)joystate[controller].joy, - joysticks[controller].triggertype, - joysticks[controller].buttons[CTL_L_SHOULDER], joysticks[controller].buttons[CTL_R_SHOULDER], + PadMapping[controller].triggertype, + PadMapping[controller].buttons[CTL_L_SHOULDER], PadMapping[controller].buttons[CTL_R_SHOULDER], joystate[controller].axis[CTL_L_SHOULDER], joystate[controller].axis[CTL_R_SHOULDER] ); */ @@ -767,26 +767,26 @@ void GetJoyState(int controller) ReadButton(controller, CTL_START); // - if (joysticks[controller].halfpress < joyinfo[controller].NumButtons) - joystate[controller].halfpress = SDL_JoystickGetButton(joystate[controller].joy, joysticks[controller].halfpress); + if (PadMapping[controller].halfpress < joyinfo[controller].NumButtons) + joystate[controller].halfpress = SDL_JoystickGetButton(joystate[controller].joy, PadMapping[controller].halfpress); // Check if we have an analog or digital joypad - if (joysticks[controller].controllertype == CTL_DPAD_HAT) + if (PadMapping[controller].controllertype == CTL_DPAD_HAT) { - joystate[controller].dpad = SDL_JoystickGetHat(joystate[controller].joy, joysticks[controller].dpad); + joystate[controller].dpad = SDL_JoystickGetHat(joystate[controller].joy, PadMapping[controller].dpad); } else { /* Only do this if the assigned button is in range (to allow for the current way of saving keyboard keys in the same array) */ - if(joysticks[controller].dpad2[CTL_D_PAD_UP] <= Buttons) - joystate[controller].dpad2[CTL_D_PAD_UP] = SDL_JoystickGetButton(joystate[controller].joy, joysticks[controller].dpad2[CTL_D_PAD_UP]); - if(joysticks[controller].dpad2[CTL_D_PAD_DOWN] <= Buttons) - joystate[controller].dpad2[CTL_D_PAD_DOWN] = SDL_JoystickGetButton(joystate[controller].joy, joysticks[controller].dpad2[CTL_D_PAD_DOWN]); - if(joysticks[controller].dpad2[CTL_D_PAD_LEFT] <= Buttons) - joystate[controller].dpad2[CTL_D_PAD_LEFT] = SDL_JoystickGetButton(joystate[controller].joy, joysticks[controller].dpad2[CTL_D_PAD_LEFT]); - if(joysticks[controller].dpad2[CTL_D_PAD_RIGHT] <= Buttons) - joystate[controller].dpad2[CTL_D_PAD_RIGHT] = SDL_JoystickGetButton(joystate[controller].joy, joysticks[controller].dpad2[CTL_D_PAD_RIGHT]); + if(PadMapping[controller].dpad2[CTL_D_PAD_UP] <= Buttons) + joystate[controller].dpad2[CTL_D_PAD_UP] = SDL_JoystickGetButton(joystate[controller].joy, PadMapping[controller].dpad2[CTL_D_PAD_UP]); + if(PadMapping[controller].dpad2[CTL_D_PAD_DOWN] <= Buttons) + joystate[controller].dpad2[CTL_D_PAD_DOWN] = SDL_JoystickGetButton(joystate[controller].joy, PadMapping[controller].dpad2[CTL_D_PAD_DOWN]); + if(PadMapping[controller].dpad2[CTL_D_PAD_LEFT] <= Buttons) + joystate[controller].dpad2[CTL_D_PAD_LEFT] = SDL_JoystickGetButton(joystate[controller].joy, PadMapping[controller].dpad2[CTL_D_PAD_LEFT]); + if(PadMapping[controller].dpad2[CTL_D_PAD_RIGHT] <= Buttons) + joystate[controller].dpad2[CTL_D_PAD_RIGHT] = SDL_JoystickGetButton(joystate[controller].joy, PadMapping[controller].dpad2[CTL_D_PAD_RIGHT]); } } ////////////////////////////////////////////////////////////////////////////////////////// diff --git a/Source/Plugins/Plugin_nJoy_SDL/Src/nJoy.h b/Source/Plugins/Plugin_nJoy_SDL/Src/nJoy.h index 88b053767c..655cc0c742 100644 --- a/Source/Plugins/Plugin_nJoy_SDL/Src/nJoy.h +++ b/Source/Plugins/Plugin_nJoy_SDL/Src/nJoy.h @@ -51,6 +51,7 @@ #include "pluginspecs_pad.h" #include "IniFile.h" //#include "ConsoleWindow.h" +//#include "Timer.h" #include "Config.h" // Local #include "XInput.h" @@ -134,6 +135,8 @@ struct CONTROLLER_MAPPING // GC PAD MAPPING int ID; // SDL joystick device ID int controllertype; // Hat: Hat or custom buttons int triggertype; // Triggers range + std::string SDiagonal; + bool bSquareToCircle; int eventnum; // Linux Event Number, Can't be found dynamically yet }; @@ -143,7 +146,7 @@ struct CONTROLLER_INFO // CONNECTED WINDOWS DEVICES INFO int NumButtons; // Amount of Buttons int NumBalls; // Amount of Balls int NumHats; // Amount of Hats (POV) - const char *Name; // Joypad/stickname + std::string Name; // Joypad/stickname int ID; // SDL joystick device ID SDL_Joystick *joy; // SDL joystick device }; @@ -226,7 +229,7 @@ extern std::vector Keys; extern FILE *pFile; extern CONTROLLER_INFO *joyinfo; extern CONTROLLER_STATE joystate[4]; - extern CONTROLLER_MAPPING joysticks[4]; + extern CONTROLLER_MAPPING PadMapping[4]; extern HWND m_hWnd; // Handle to window #endif