From eb91942fd612f66b6c3f4ce7f4eb3c247219316c Mon Sep 17 00:00:00 2001 From: John Peterson Date: Mon, 2 Feb 2009 03:16:59 +0000 Subject: [PATCH] nJoy: Fixed bugs in settings saving and loading git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@2069 8ced0084-cf51-0410-be5f-012b33b47a6e --- Source/Plugins/Plugin_nJoy_SDL/Src/Config.cpp | 3 -- .../Plugin_nJoy_SDL/Src/GUI/ConfigBox.cpp | 46 ++++++++++++------- .../Plugin_nJoy_SDL/Src/GUI/ConfigBox.h | 1 + .../Plugin_nJoy_SDL/Src/GUI/ConfigJoypad.cpp | 5 +- 4 files changed, 33 insertions(+), 22 deletions(-) diff --git a/Source/Plugins/Plugin_nJoy_SDL/Src/Config.cpp b/Source/Plugins/Plugin_nJoy_SDL/Src/Config.cpp index 5fbe59f226..a425e7576a 100644 --- a/Source/Plugins/Plugin_nJoy_SDL/Src/Config.cpp +++ b/Source/Plugins/Plugin_nJoy_SDL/Src/Config.cpp @@ -216,9 +216,6 @@ void Config::Load(bool ChangePad, bool ChangeSaveByID) the current amount of connected PadMapping */ if(PadMapping[i].ID >= SDL_NumJoysticks()) continue; - //PanicAlert("%i %i",PadMapping[i].ID, SDL_NumJoysticks()); - //PanicAlert("%s", joyinfo[PadMapping[i].ID].Name); - // Create a section name SectionName = joyinfo[PadMapping[i].ID].Name; } diff --git a/Source/Plugins/Plugin_nJoy_SDL/Src/GUI/ConfigBox.cpp b/Source/Plugins/Plugin_nJoy_SDL/Src/GUI/ConfigBox.cpp index f34fec2ed1..dfba6e4d3b 100644 --- a/Source/Plugins/Plugin_nJoy_SDL/Src/GUI/ConfigBox.cpp +++ b/Source/Plugins/Plugin_nJoy_SDL/Src/GUI/ConfigBox.cpp @@ -272,20 +272,19 @@ void ConfigBox::DoSave(bool ChangePad, int Slot) ToBlank(); } -// OnSaveById +// On changing the SaveById option we update all pages // ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ void ConfigBox::OnSaveById() { // Save current settings DoSave(false, notebookpage); - // Update the setting and load the settings + // Update the SaveByID 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); + // Update the GUI from the now updated PadMapping[] + UpdateGUIAll(-1); } // Change Joystick @@ -328,14 +327,12 @@ void ConfigBox::PadClose(int Close) // Close for slot 1, 2, 3 or 4 // ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ void ConfigBox::NotebookPageChanged(wxNotebookEvent& event) { - //int oldnotebookpage = notebookpage; - notebookpage = event.GetSelection(); - //int OldId = PadMapping[oldnotebookpage].ID; - //int NewId = PadMapping[notebookpage].ID; + // Save current settings now, don't wait for OK + if(ControlsCreated && !g_Config.bSaveByID) DoSave(false, notebookpage); + + // Update the global variable + notebookpage = event.GetSelection(); - // Check if it has changed. If it has save the old Id and load the new Id - //if(OldId != NewId && NumGoodPads > 0) DoChangeJoystick(); - // Update GUI if(ControlsCreated) UpdateGUI(notebookpage); } @@ -383,9 +380,24 @@ void ConfigBox::SaveButtonMappingAll(int Slot) { for (int i = 0; i < 4; i++) if (joyinfo[PadMapping[i].ID].Name == joyinfo[PadMapping[Slot].ID].Name) - SaveButtonMapping(i, false); + SaveButtonMapping(i, false, Slot); } + +void ConfigBox::UpdateGUIAll(int Slot) +{ + if(Slot == -1) + { + for (int i = 0; i < 4; i++) UpdateGUI(i); + } + else + { + for (int i = 0; i < 4; i++) + if (joyinfo[PadMapping[i].ID].Name == joyinfo[PadMapping[Slot].ID].Name) + UpdateGUI(i); + } +} + void ConfigBox::ChangeSettings( wxCommandEvent& event ) { switch(event.GetId()) @@ -404,10 +416,9 @@ void ConfigBox::ChangeSettings( wxCommandEvent& event ) SizeWindow(); break; - case IDC_CONTROLTYPE: - case IDC_TRIGGERTYPE: - SaveButtonMapping(notebookpage); - UpdateGUI(notebookpage); + case IDC_CONTROLTYPE: + case IDC_TRIGGERTYPE: + //UpdateGUI(notebookpage); break; case IDC_JOYNAME: @@ -426,6 +437,7 @@ void ConfigBox::ChangeSettings( wxCommandEvent& event ) // Update all slots that use this device if(g_Config.bSaveByID) SaveButtonMappingAll(notebookpage); + if(g_Config.bSaveByID) UpdateGUIAll(notebookpage); } /////////////////////////////// diff --git a/Source/Plugins/Plugin_nJoy_SDL/Src/GUI/ConfigBox.h b/Source/Plugins/Plugin_nJoy_SDL/Src/GUI/ConfigBox.h index a8f4c29cd2..fa1f953e19 100644 --- a/Source/Plugins/Plugin_nJoy_SDL/Src/GUI/ConfigBox.h +++ b/Source/Plugins/Plugin_nJoy_SDL/Src/GUI/ConfigBox.h @@ -320,6 +320,7 @@ class ConfigBox : public wxDialog void UpdateGUIKeys(int controller); void SaveButtonMapping(int controller, bool DontChangeId = false, int FromSlot = -1); void SaveButtonMappingAll(int Slot); + void UpdateGUIAll(int Slot); void ToBlank(bool ToBlank = true); void OnSaveById(); diff --git a/Source/Plugins/Plugin_nJoy_SDL/Src/GUI/ConfigJoypad.cpp b/Source/Plugins/Plugin_nJoy_SDL/Src/GUI/ConfigJoypad.cpp index 9262cdeaf1..faeadff75b 100644 --- a/Source/Plugins/Plugin_nJoy_SDL/Src/GUI/ConfigJoypad.cpp +++ b/Source/Plugins/Plugin_nJoy_SDL/Src/GUI/ConfigJoypad.cpp @@ -80,7 +80,7 @@ void ConfigBox::UpdateGUIKeys(int controller) 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); + //LogMsg("m_TriggerType[%i] = %i\n", controller, PadMapping[controller].triggertype); // Update D-Pad if(PadMapping[controller].controllertype == CTL_DPAD_HAT) @@ -141,7 +141,8 @@ void ConfigBox::SaveButtonMapping(int controller, bool DontChangeId, int FromSlo 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); + //LogMsg("PadMapping[%i].triggertype = %i, m_TriggerType[%i]->GetSelection() = %i\n", + // controller, PadMapping[controller].triggertype, FromSlot, m_TriggerType[FromSlot]->GetSelection()); // The halfpress button m_JoyButtonHalfpress[FromSlot]->GetValue().ToLong(&value); PadMapping[controller].halfpress = value; tmp.clear();