nJoy: Fixed a bug that would sometimes cause settings to not be saved correctly
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@2010 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
parent
ac2fd1b17e
commit
c9ca6ef55a
|
@ -170,6 +170,8 @@ void Config::Save(int Slot)
|
|||
//if(m_frame) m_frame->LogMsg("Saved: %s %i\n", SectionName.c_str(), PadMapping[i].triggertype);
|
||||
}
|
||||
|
||||
//Console::Print("%i: Save: %i\n", 0, PadMapping[0].halfpress);
|
||||
|
||||
file.Save("nJoy.ini");
|
||||
}
|
||||
|
||||
|
@ -250,8 +252,9 @@ void Config::Load(bool ChangePad, bool ChangeSaveByID)
|
|||
// =============================
|
||||
|
||||
// Debugging
|
||||
if(m_frame) m_frame->LogMsg("%i: Enabled: %i\n", i, PadMapping[i].buttons[CTL_X_BUTTON]);
|
||||
//Console::Print("%i: Enabled: %i\n", i, PadMapping[i].buttons[CTL_X_BUTTON]);
|
||||
//if(m_frame) m_frame->LogMsg("%i: Enabled: %i\n", i, PadMapping[i].buttons[CTL_X_BUTTON]);
|
||||
}
|
||||
|
||||
//Console::Print("%i: Load: %i\n", 0, PadMapping[0].halfpress);
|
||||
}
|
||||
|
||||
|
|
|
@ -190,7 +190,7 @@ void ConfigBox::OKClick(wxCommandEvent& event)
|
|||
if (event.GetId() == ID_OK)
|
||||
{
|
||||
DoSave(); // Save settings
|
||||
g_Config.Load(); // Reload settings to PadMapping
|
||||
//g_Config.Load(); // Reload settings to PadMapping
|
||||
if(Debugging) PanicAlert("Done");
|
||||
Close(); // Call OnClose()
|
||||
}
|
||||
|
@ -243,6 +243,9 @@ void ConfigBox::LogMsg(const char* format, ...)
|
|||
2. Changing the gamepad
|
||||
3. When the gamepad is enabled or disbled
|
||||
4. When we change saving mode (by Id or by slot)
|
||||
|
||||
Input: ChangePad needs to be used when we change the pad for a slot. Slot needs to be used when
|
||||
we only want to save changes to one slot.
|
||||
*/
|
||||
void ConfigBox::DoSave(bool ChangePad, int Slot)
|
||||
{
|
||||
|
@ -253,19 +256,19 @@ void ConfigBox::DoSave(bool ChangePad, int Slot)
|
|||
{
|
||||
// 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);
|
||||
//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
|
||||
PadMapping[notebookpage].ID = m_Joyname[notebookpage]->GetSelection();
|
||||
//LogMsg("New Id: %s\n", joyinfo[PadMapping[notebookpage].ID].Name.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
// Update PadMapping[] from the GUI controls
|
||||
for(int i = 0; i < 4; i++) SaveButtonMapping(i);
|
||||
g_Config.Save(Slot);
|
||||
}
|
||||
|
||||
// Then change it back
|
||||
// Then change it back to ""
|
||||
ToBlank();
|
||||
}
|
||||
|
||||
|
@ -296,7 +299,7 @@ void ConfigBox::DoChangeJoystick()
|
|||
|
||||
// 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
|
||||
|
@ -324,15 +327,15 @@ void ConfigBox::PadClose(int Close) // Close for slot 1, 2, 3 or 4
|
|||
// Notebook page changed
|
||||
// ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
|
||||
void ConfigBox::NotebookPageChanged(wxNotebookEvent& event)
|
||||
{
|
||||
int oldnotebookpage = notebookpage;
|
||||
{
|
||||
//int oldnotebookpage = notebookpage;
|
||||
notebookpage = event.GetSelection();
|
||||
int OldId = PadMapping[oldnotebookpage].ID;
|
||||
int NewId = PadMapping[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 && NumGoodPads > 0) DoChangeJoystick();
|
||||
|
||||
// Update GUI
|
||||
if(ControlsCreated) UpdateGUI(notebookpage);
|
||||
}
|
||||
|
@ -341,20 +344,25 @@ void ConfigBox::NotebookPageChanged(wxNotebookEvent& event)
|
|||
// ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
|
||||
void ConfigBox::ToBlank(bool ToBlank)
|
||||
{
|
||||
if(ToBlank)
|
||||
if (!ControlsCreated) return;
|
||||
|
||||
for (int j = 0; j < 4; j++)
|
||||
{
|
||||
for(int i = IDB_ANALOG_MAIN_X; i <= IDB_BUTTONHALFPRESS; i++)
|
||||
if(ToBlank)
|
||||
{
|
||||
for(int i = IDB_ANALOG_MAIN_X; i <= IDB_BUTTONHALFPRESS; i++)
|
||||
#ifndef _WIN32
|
||||
if(GetButtonText(i).ToAscii() == "-1") SetButtonText(i, "");
|
||||
if(GetButtonText(i, j).ToAscii() == "-1") SetButtonText(i, "", j);
|
||||
#else
|
||||
if(GetButtonText(i) == "-1") SetButtonText(i, "");
|
||||
if(GetButtonText(i, j) == "-1") SetButtonText(i, "", j);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
for(int i = IDB_ANALOG_MAIN_X; i <= IDB_BUTTONHALFPRESS; i++)
|
||||
if(GetButtonText(i).IsEmpty()) SetButtonText(i, "-1");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for(int i = IDB_ANALOG_MAIN_X; i <= IDB_BUTTONHALFPRESS; i++)
|
||||
if(GetButtonText(i, j).IsEmpty()) SetButtonText(i, "-1", j);
|
||||
}
|
||||
}
|
||||
}
|
||||
//////////////////////////////////
|
||||
|
||||
|
@ -362,16 +370,22 @@ void ConfigBox::ToBlank(bool ToBlank)
|
|||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// Change settings
|
||||
// ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
|
||||
void ConfigBox::UpdateAllSlots(int Slot)
|
||||
void ConfigBox::SetButtonTextAll(int id, char text[128])
|
||||
{
|
||||
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);
|
||||
if (joyinfo[PadMapping[i].ID].Name == joyinfo[PadMapping[notebookpage].ID].Name)
|
||||
SetButtonText(id, text, i);
|
||||
};
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
}
|
||||
void ConfigBox::ChangeSettings( wxCommandEvent& event )
|
||||
{
|
||||
switch(event.GetId())
|
||||
|
@ -411,7 +425,7 @@ void ConfigBox::ChangeSettings( wxCommandEvent& event )
|
|||
}
|
||||
|
||||
// Update all slots that use this device
|
||||
if(g_Config.bSaveByID) UpdateAllSlots(notebookpage);
|
||||
if(g_Config.bSaveByID) SaveButtonMappingAll(notebookpage);
|
||||
}
|
||||
///////////////////////////////
|
||||
|
||||
|
@ -944,7 +958,8 @@ void ConfigBox::CreateGUIControls()
|
|||
// All done
|
||||
ControlsCreated = true;
|
||||
|
||||
Console::Print("CreateGUIControls() end\n");
|
||||
// Replace the harder to understand -1 with "" for the sake of user friendliness
|
||||
ToBlank();
|
||||
}
|
||||
|
||||
void ConfigBox::SizeWindow()
|
||||
|
|
|
@ -308,7 +308,7 @@ class ConfigBox : public wxDialog
|
|||
void DoChangeJoystick(); void PadOpen(int Open); void PadClose(int Close);
|
||||
void UpdateGUI(int _notebookpage);
|
||||
|
||||
void ChangeSettings(wxCommandEvent& event); void UpdateAllSlots(int Slot); // Settings
|
||||
void ChangeSettings(wxCommandEvent& event);
|
||||
void ComboChange(wxCommandEvent& event);
|
||||
|
||||
void OnClose(wxCloseEvent& event);
|
||||
|
@ -319,6 +319,7 @@ class ConfigBox : public wxDialog
|
|||
|
||||
void UpdateGUIKeys(int controller);
|
||||
void SaveButtonMapping(int controller, bool DontChangeId = false, int FromSlot = -1);
|
||||
void SaveButtonMappingAll(int Slot);
|
||||
void ToBlank(bool ToBlank = true);
|
||||
void OnSaveById();
|
||||
|
||||
|
@ -330,8 +331,8 @@ class ConfigBox : public wxDialog
|
|||
|
||||
void OnPaint(wxPaintEvent &event);
|
||||
|
||||
void SetButtonText(int id, char text[128]);
|
||||
wxString GetButtonText(int id);
|
||||
void SetButtonText(int id, char text[128], int Page = -1); void SetButtonTextAll(int id, char text[128]);
|
||||
wxString GetButtonText(int id, int Page = -1);
|
||||
void OnKeyDown(wxKeyEvent& event);
|
||||
};
|
||||
|
||||
|
|
|
@ -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("bSquareToCircle: %i\n", PadMapping[controller].bSquareToCircle);
|
||||
|
||||
// Update D-Pad
|
||||
if(PadMapping[controller].controllertype == CTL_DPAD_HAT)
|
||||
|
@ -94,6 +94,9 @@ void ConfigBox::UpdateGUIKeys(int controller)
|
|||
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();
|
||||
}
|
||||
|
||||
// Replace "-1" with "" in the GUI controls
|
||||
//if(ControlsCreated) ToBlank();
|
||||
}
|
||||
|
||||
/* Populate the PadMapping array with the dialog items settings (for example
|
||||
|
@ -108,7 +111,7 @@ void ConfigBox::SaveButtonMapping(int controller, bool DontChangeId, int FromSlo
|
|||
// Save from or to the same or different slots
|
||||
if (FromSlot == -1) FromSlot = controller;
|
||||
|
||||
// Replace "" with "-1"
|
||||
// Replace "" with "-1" in the GUI controls
|
||||
ToBlank(false);
|
||||
|
||||
// Set enabled or disable status and other settings
|
||||
|
@ -138,7 +141,7 @@ 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("SaveButtonMapping: Key:%i From:%i To:%i\n", m_TriggerType[FromSlot]->GetSelection(), FromSlot, controller);
|
||||
|
||||
// The halfpress button
|
||||
m_JoyButtonHalfpress[FromSlot]->GetValue().ToLong(&value); PadMapping[controller].halfpress = value; tmp.clear();
|
||||
|
@ -162,9 +165,11 @@ void ConfigBox::SaveButtonMapping(int controller, bool DontChangeId, int FromSlo
|
|||
|
||||
// Update the textbox for the buttons
|
||||
// ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
|
||||
void ConfigBox::SetButtonText(int id, char text[128])
|
||||
void ConfigBox::SetButtonText(int id, char text[128], int Page)
|
||||
{
|
||||
int controller = notebookpage;
|
||||
// Set controller value
|
||||
int controller;
|
||||
if (Page == -1) controller = notebookpage; else controller = Page;
|
||||
|
||||
switch(id)
|
||||
{
|
||||
|
@ -195,9 +200,11 @@ void ConfigBox::SetButtonText(int id, char text[128])
|
|||
|
||||
// Get the text in the textbox for the buttons
|
||||
// ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
|
||||
wxString ConfigBox::GetButtonText(int id)
|
||||
wxString ConfigBox::GetButtonText(int id, int Page)
|
||||
{
|
||||
int controller = notebookpage;
|
||||
// Set controller value
|
||||
int controller;
|
||||
if (Page == -1) controller = notebookpage; else controller = Page;
|
||||
|
||||
switch(id)
|
||||
{
|
||||
|
@ -436,6 +443,7 @@ void ConfigBox::DoGetButtons(int GetId)
|
|||
}
|
||||
// ========================= Check for keys
|
||||
|
||||
|
||||
// ===============================================
|
||||
// Process results
|
||||
// ----------------
|
||||
|
@ -459,7 +467,7 @@ void ConfigBox::DoGetButtons(int GetId)
|
|||
{
|
||||
Stop = true;
|
||||
// Leave a blank mapping
|
||||
SetButtonText(GetId, "-1");
|
||||
if(g_Config.bSaveByID) SetButtonTextAll(GetId, "-1"); else SetButtonText(GetId, "-1");
|
||||
}
|
||||
|
||||
// If we got a button
|
||||
|
@ -468,7 +476,7 @@ void ConfigBox::DoGetButtons(int GetId)
|
|||
Stop = true;
|
||||
// Write the number of the pressed button to the text box
|
||||
sprintf(format, "%d", pressed);
|
||||
SetButtonText(GetId, format);
|
||||
if(g_Config.bSaveByID) SetButtonTextAll(GetId, format); else SetButtonText(GetId, format);
|
||||
}
|
||||
|
||||
// Stop the timer
|
||||
|
@ -477,22 +485,18 @@ void ConfigBox::DoGetButtons(int GetId)
|
|||
m_ButtonMappingTimer->Stop();
|
||||
GetButtonWaitingTimer = 0;
|
||||
|
||||
// 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(g_Config.bSaveByID) SaveButtonMappingAll(Controller); else SaveButtonMapping(Controller);
|
||||
}
|
||||
|
||||
// If we got a bad button
|
||||
if(g_Pressed == -1)
|
||||
{
|
||||
SetButtonText(GetId, "-1"); // Update text
|
||||
// Update text
|
||||
if(g_Config.bSaveByID) SetButtonTextAll(GetId, "-1"); else SetButtonText(GetId, "-1");
|
||||
|
||||
// Notify the user
|
||||
wxMessageBox(wxString::Format(wxT(
|
||||
|
@ -506,7 +510,11 @@ void ConfigBox::DoGetButtons(int GetId)
|
|||
if(SDL_JoystickOpened(PadMapping[Controller].ID)) SDL_JoystickClose(joy);
|
||||
|
||||
// Debugging
|
||||
//Console::Print("IsRunning: %i\n", m_ButtonMappingTimer->IsRunning());
|
||||
/*
|
||||
Console::Print("Change: %i %i %i %i '%s' '%s' '%s' '%s'\n",
|
||||
PadMapping[0].halfpress, PadMapping[1].halfpress, PadMapping[2].halfpress, PadMapping[3].halfpress,
|
||||
m_JoyButtonHalfpress[0]->GetValue().c_str(), m_JoyButtonHalfpress[1]->GetValue().c_str(), m_JoyButtonHalfpress[2]->GetValue().c_str(), m_JoyButtonHalfpress[3]->GetValue().c_str()
|
||||
);*/
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////// Configure button mapping
|
||||
|
|
Loading…
Reference in New Issue