nJoy: Improvements to the configuration, the SaveById option should now be simpler and better

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@1977 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
John Peterson
2009-01-21 18:09:31 +00:00
parent 1b12bc38ac
commit 7f9dc55fbc
9 changed files with 439 additions and 435 deletions

View File

@ -30,21 +30,23 @@
//////////////////////////////////////////////////////////////////////////////////////////
////////////////////////
///////////////////////////////////////////////////////////////////////
// Include
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
#include "nJoy.h"
#include "Common.h"
Config g_Config;
extern ConfigBox* m_frame;
//////////////////////////////////
// Run when created
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
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. */
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
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
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
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
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
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
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
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
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
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
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// 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
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
void Config::Load(bool config)
void Config::Load(bool ChangePad, bool ChangeSaveByID)
{
// Load file
IniFile file;
file.Load("nJoy.ini");
std::vector<std::string> Duplicates;
bool Tmp; // Tmp storage
// ==================================================================
// Global settings
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
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
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// 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);
}
}