revert to r4531, but keep the changes from the following revisions: 4533,4550-4551,4556-4559

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4566 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
Shawn Hoffman
2009-11-14 17:08:32 +00:00
parent 18305c7c49
commit 06aa62504c
66 changed files with 2170 additions and 1570 deletions

View File

@ -46,7 +46,6 @@ Config::Config()
{
// Clear the memory
//memset(this, 0, sizeof(Config));
Loaded = false;
}
@ -96,7 +95,7 @@ void DEBUG_QUIT()
void Config::Save(int Slot)
{
// If there are no good pads don't save
if (NumPads == 0) return;
if (NumGoodPads == 0) return;
// Load ini file
IniFile file;
@ -128,27 +127,22 @@ void Config::Save(int Slot)
// Save the physical device ID
file.Set(SectionName.c_str(), "joy_id", PadMapping[i].ID);
file.Set(SectionName.c_str(), "joy_name", PadMapping[i].Name);
// ===================
// ==================================================================
// Joypad or slot specific settings
// -----------------
// Current joypad device ID: PadMapping[i].ID
// Current joypad name: IDToName(PadMapping[i].ID])
// 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 "PadMapping[i].ID < SDL_NumJoysticks()" to
avoid reading a joyinfo that does't exist */
if((u32)PadMapping[i].ID >= joyinfo.size()) continue;
// Create a new section name after the joypad name
SectionName = IDToName(PadMapping[i].ID);
// Don't save a blank name
if (SectionName == "")
{
ERROR_LOG(PAD, "ID %i has no name, will not save", PadMapping[i].ID);
continue;
}
SectionName = joyinfo[PadMapping[i].ID].Name;
}
NOTICE_LOG(PAD, "Save settings for ID %i '%s' from PadMapping[%i]", PadMapping[i].ID, SectionName.c_str(), i);
file.Set(SectionName.c_str(), "l_shoulder", PadMapping[i].buttons[InputCommon::CTL_L_SHOULDER]);
file.Set(SectionName.c_str(), "r_shoulder", PadMapping[i].buttons[InputCommon::CTL_R_SHOULDER]);
@ -186,6 +180,8 @@ void Config::Save(int Slot)
file.Set(SectionName.c_str(), "SquareToCircleC", PadMapping[i].bSquareToCircleC);
}
INFO_LOG(CONSOLE, "%i: Save: %i\n", 0, PadMapping[0].halfpress);
file.Save(FULL_CONFIG_DIR "nJoy.ini");
}
@ -193,7 +189,8 @@ void Config::Save(int Slot)
// -----------------------
void Config::Load(bool ChangePad, bool ChangeSaveByID)
{
Loaded = true;
// If there are no good pads don't load
if (NumGoodPads == 0) return;
// Load file
IniFile file;
@ -214,9 +211,6 @@ void Config::Load(bool ChangePad, bool ChangeSaveByID)
}
// =============
// If there are no good pads don't load anymore
if (NumPads == 0) return;
for (int i = 0; i < 4; i++)
{
std::string SectionName = StringFromFormat("PAD%i", i+1);
@ -225,32 +219,23 @@ void Config::Load(bool ChangePad, bool ChangeSaveByID)
if (!ChangePad)
{
file.Get(SectionName.c_str(), "joy_id", &PadMapping[i].ID, 0);
file.Get(SectionName.c_str(), "joy_name", &PadMapping[i].Name, "");
}
// ==================================================================
// Joypad or slot specific settings
// -----------------
// Current joypad device ID: PadMapping[i].ID
// Current joypad name: IDToName(PadMapping[i].ID)
if (g_Config.bSaveByID)
// 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 pads
if((u32)PadMapping[i].ID >= joyinfo.size()) continue;
// Create a section name
SectionName = PadMapping[i].Name;
// Don't load settings for a non-connected device
if (!IsConnected(SectionName))
{
ERROR_LOG(PAD, "Slot %i: The device '%s' is not connected, will not load settings", SectionName.c_str());
continue;
}
// Don't load a blank ID
if (SectionName == "")
{
ERROR_LOG(PAD, "Slot %i has no device name, will not load settings", i);
continue;
}
SectionName = joyinfo[PadMapping[i].ID].Name;
}
file.Get(SectionName.c_str(), "l_shoulder", &PadMapping[i].buttons[InputCommon::CTL_L_SHOULDER], 4);
file.Get(SectionName.c_str(), "r_shoulder", &PadMapping[i].buttons[InputCommon::CTL_R_SHOULDER], 5);
file.Get(SectionName.c_str(), "a_button", &PadMapping[i].buttons[InputCommon::CTL_A_BUTTON], 0);
@ -284,11 +269,8 @@ void Config::Load(bool ChangePad, bool ChangeSaveByID)
file.Get(SectionName.c_str(), "RadiusOnOffC", &Tmp, false); PadMapping[i].bRadiusOnOffC = Tmp;
file.Get(SectionName.c_str(), "DiagonalC", &PadMapping[i].SDiagonalC, "100%");
file.Get(SectionName.c_str(), "SquareToCircleC", &Tmp, false); PadMapping[i].bSquareToCircleC = Tmp;
NOTICE_LOG(PAD, "Slot %i: Load settings for ID %i '%s'", i, PadMapping[i].ID, SectionName.c_str());
}
//INFO_LOG(PAD, "%i: Load: %i\n", 0, PadMapping[0].halfpress);
INFO_LOG(CONSOLE, "%i: Load: %i\n", 0, PadMapping[0].halfpress);
}

View File

@ -23,10 +23,9 @@ struct Config
Config();
void Load(bool ChangePad = false, bool ChangeSaveByID = false);
void Save(int Slot = -1);
bool Loaded;
int CheckForDuplicateJoypads(bool OK);
// Settings
// General
bool bShowAdvanced; // Only allow one of these
bool bSaveByID;
bool bCheckFocus;

View File

@ -1,3 +1,4 @@
// Project description
// -------------------
// Name: nJoy
@ -31,15 +32,14 @@
// ---------
#include "ConfigBox.h"
#include "../nJoy.h"
#include "LogManager.h"
#include "Images/controller.xpm"
extern bool g_EmulatorRunning;
// Set PAD status
// --------------
void PADConfigDialognJoy::PadShowStatus()
{
void PADConfigDialognJoy::PadGetStatus()
{
// Return if it's not detected. The ID should never be less than zero here, it can only be that
// because of a manual ini file change, but we make that check anway.
if(PadMapping[notebookpage].ID < 0 || PadMapping[notebookpage].ID >= SDL_NumJoysticks())
@ -51,7 +51,7 @@ void PADConfigDialognJoy::PadShowStatus()
}
// Get physical device status
int ID = PadMapping[notebookpage].ID;
int PhysicalDevice = PadMapping[notebookpage].ID;
int TriggerType = PadMapping[notebookpage].triggertype;
// Get original values
@ -105,6 +105,7 @@ void PADConfigDialognJoy::PadShowStatus()
m_bmpDotOutC[notebookpage]->SetPosition(wxPoint(sub_x_out, sub_y_out));
///////////////////// Analog stick
// Triggers
// -----------------
@ -142,12 +143,84 @@ void PADConfigDialognJoy::PadShowStatus()
///////////////////// Triggers
}
// Update the advanced tab
// Show the current pad status
// -----------------
std::string ShowStatus(int VirtualController)
{
// Save the physical device
int PhysicalDevice = PadMapping[VirtualController].ID;
// Make local shortcut
SDL_Joystick *joy = PadState[VirtualController].joy;
// Make shortcuts for all pads
SDL_Joystick *joy0 = PadState[0].joy;
SDL_Joystick *joy1 = PadState[1].joy;
SDL_Joystick *joy2 = PadState[2].joy;
SDL_Joystick *joy3 = PadState[3].joy;
// Temporary storage
std::string StrAxes, StrHats, StrBut;
int value;
// Get status
int Axes = joyinfo[PhysicalDevice].NumAxes;
int Balls = joyinfo[PhysicalDevice].NumBalls;
int Hats = joyinfo[PhysicalDevice].NumHats;
int Buttons = joyinfo[PhysicalDevice].NumButtons;
// Update the internal values
SDL_JoystickUpdate();
// Go through all axes and read out their values
for(int i = 0; i < Axes; i++)
{
value = SDL_JoystickGetAxis(joy, i);
StrAxes += StringFromFormat(" %i:%06i", i, value);
}
for(int i = 0;i < Hats; i++)
{
value = SDL_JoystickGetHat(joy, i);
StrHats += StringFromFormat(" %i:%i", i, value);
}
for(int i = 0;i < Buttons; i++)
{
value = SDL_JoystickGetButton(joy, i);
StrBut += StringFromFormat(" %i:%i", i+1, value);
}
return StringFromFormat(
"All pads:\n"
"ID: %i %i %i %i\n"
"Controllertype: %i %i %i %i\n"
"SquareToCircle: %i %i %i %i\n\n"
#ifdef _WIN32
"Handles: %i %i %i %i\n"
"XInput: %i %i %i\n"
#endif
"This pad:\n"
"Axes: %s\n"
"Hats: %s\n"
"But: %s\n"
"Device: Ax: %i Balls:%i Hats:%i But:%i",
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,
#ifdef _WIN32
joy0, joy1, joy2, joy3,
//PadState[PadMapping[0].ID].joy, PadState[PadMapping[1].ID].joy, PadState[PadMapping[2].ID].joy, PadState[PadMapping[3].ID].joy,
XInput::IsConnected(0), XInput::GetXI(0, InputCommon::XI_TRIGGER_L), XInput::GetXI(0, InputCommon::XI_TRIGGER_R),
#endif
StrAxes.c_str(), StrHats.c_str(), StrBut.c_str(),
Axes, Balls, Hats, Buttons
);
}
// Populate the advanced tab
// -----------------
void PADConfigDialognJoy::Update()
{
if (!IsPolling()) return;
{
// Check that Dolphin is in focus, otherwise don't update the pad status
/* If the emulator is running and unpaused GetJoyState() is run a little more often than needed,
but I allow that since it can confuse the user if the input status in the configuration window
@ -155,46 +228,17 @@ void PADConfigDialognJoy::Update()
if (g_Config.bCheckFocus || IsFocus()) // && !g_EmulatorRunning)
{
for (int i = 0; (u32)i < joyinfo.size(); i++)
InputCommon::GetJoyState(PadState[notebookpage], PadMapping[notebookpage]);
PadShowStatus();
InputCommon::GetJoyState(PadState[i], PadMapping[i], i, joyinfo[PadMapping[i].ID].NumButtons);
}
// Show the current status in a window in the wxPanel
#ifdef SHOW_PAD_STATUS
m_pStatusBar->SetLabel(wxString::FromAscii(InputCommon::ShowStatus(
notebookpage, m_Joyname[notebookpage]->GetSelection(),
PadMapping, PadState, joyinfo
).c_str()));
m_pStatusBar->SetLabel(wxString::Format(
"%s", ShowStatus(notebookpage).c_str()
));
#endif
}
// Search for devices
void PADConfigDialognJoy::UpdateSlow()
{
if (!LiveUpdates) return;
// Don't run this the first time
int OldNumDIDevices;
if (NumDIDevices == -1)
OldNumDIDevices = InputCommon::SearchDIDevices();
else
// Search for connected devices and update dialog
OldNumDIDevices = NumDIDevices;
NumDIDevices = InputCommon::SearchDIDevices();
// Update if a pad has been connected/disconnected. Todo: Add a better check that also takes into consideration the pad id
// and other things to better ensure that nothing has changed
//DEBUG_LOG(PAD, "Found %i devices", NumDIDevices);
//DEBUG_LOG(PAD, "UpdateSlow: %i %i", OldNumPads, NumPads);
if (OldNumDIDevices != NumDIDevices)
{
WARN_LOG(PAD, "\n---- %s ----", (NumDIDevices > OldNumDIDevices) ? "Pad connected" : "Pad disconnected");
LocalSearchDevicesReset(joyinfo, NumPads);
UpdateDeviceList();
// Enable controls again, if disabled
UpdateGUIAll();
}
}
// Populate the advanced tab
// -----------------
@ -324,5 +368,6 @@ wxBitmap PADConfigDialognJoy::CreateBitmapArea(int Max, int Diagonal)
Points[7].x = (int)(-Diagonal * Adj + iAdj); Points[7].y = (int)(Diagonal * Adj + iAdj);
// Draw polygon
dc.DrawPolygon(8, Points);
return bitmap;
}

View File

@ -103,7 +103,6 @@ BEGIN_EVENT_TABLE(PADConfigDialognJoy,wxDialog)
EVT_BUTTON(IDB_ANALOG_SUB_Y, PADConfigDialognJoy::GetButtons)
#if wxUSE_TIMER
EVT_TIMER(IDTM_SLOW, PADConfigDialognJoy::OnSlowTimer)
EVT_TIMER(IDTM_CONSTANT, PADConfigDialognJoy::OnTimer)
EVT_TIMER(IDTM_BUTTON, PADConfigDialognJoy::OnButtonTimer)
#endif
@ -113,34 +112,26 @@ PADConfigDialognJoy::PADConfigDialognJoy(wxWindow *parent, wxWindowID id, const
const wxPoint &position, const wxSize& size, long style)
: wxDialog(parent, id, title, position, size, style)
{
// Initialize values
// Define values
notebookpage = 0;
g_Pressed = 0;
g_Pressed = 0;
Debugging = false;
m_TCDebugging = NULL;
ControlsCreated = false;
// Settings
Debugging = false;
// Create controls
CreateGUIControls();
// Update GUI
UpdateGUIAll();
// Update device list
UpdateDeviceList();
#if wxUSE_TIMER
m_SlowTimer = new wxTimer(this, IDTM_SLOW);
m_ConstantTimer = new wxTimer(this, IDTM_CONSTANT);
m_ButtonMappingTimer = new wxTimer(this, IDTM_BUTTON);
// Reset values
GetButtonWaitingID = 0; GetButtonWaitingTimer = 0;
// Start timers
StartTimer();
// Start the constant timer
int TimesPerSecond = 30;
m_ConstantTimer->Start( floor((double)(1000 / TimesPerSecond)) );
#endif
// wxEVT_KEY_DOWN is blocked for enter, tab and the directional keys
@ -157,24 +148,6 @@ PADConfigDialognJoy::~PADConfigDialognJoy()
#endif
}
void PADConfigDialognJoy::DoShow()
{
// Start timers
StartTimer();
// Show
ShowModal();
}
void PADConfigDialognJoy::StartTimer()
{
// Start the slow timer
double TimesPerSecond = 2;
m_SlowTimer->Start( floor((double)(1000.0 / TimesPerSecond)) );
// Start the constant timer
TimesPerSecond = 30;
m_ConstantTimer->Start( floor((double)(1000 / TimesPerSecond)) );
}
void PADConfigDialognJoy::OnKeyDown(wxKeyEvent& event)
{
g_Pressed = event.GetKeyCode();
@ -187,9 +160,7 @@ void PADConfigDialognJoy::OnClose(wxCloseEvent& event)
event.Skip();
// Stop the timer
m_SlowTimer->Stop();
m_ConstantTimer->Stop();
m_ButtonMappingTimer->Stop();
// Close pads, unless we are running a game
if (!g_EmulatorRunning) Shutdown();
@ -285,7 +256,7 @@ void PADConfigDialognJoy::DoSave(bool ChangePad, int Slot)
g_Config.Save(Slot);
// Now we can update the ID
UpdateID();
PadMapping[notebookpage].ID = m_Joyname[notebookpage]->GetSelection();
}
else
{
@ -297,21 +268,6 @@ void PADConfigDialognJoy::DoSave(bool ChangePad, int Slot)
// Then change it back to ""
ToBlank();
}
void PADConfigDialognJoy::UpdateID()
{
INFO_LOG(PAD, "Slot %i: Changed PadMapping ID from %i to %i", notebookpage, PadMapping[notebookpage].ID, m_Joyname[notebookpage]->GetSelection());
PadMapping[notebookpage].ID = joyinfo.at(m_Joyname[notebookpage]->GetSelection()).ID;
PadMapping[notebookpage].Name = joyinfo.at(m_Joyname[notebookpage]->GetSelection()).Name;
// Update all handles
for(int i = 0; i < 4; i++)
{
if (PadMapping[i].Name == PadMapping[notebookpage].Name)
{
if (m_Joyname[i]->GetSelection() >= 0 && joyinfo.size() > m_Joyname[i]->GetSelection())
PadState[i].joy = joyinfo.at(m_Joyname[i]->GetSelection()).joy;
}
}
}
// On changing the SaveById option we update all pages
void PADConfigDialognJoy::OnSaveById()
@ -334,52 +290,11 @@ void PADConfigDialognJoy::OnSaveById()
void PADConfigDialognJoy::DoChangeJoystick()
{
// Before changing the pad we save potential changes to the current pad (to support SaveByID)
WARN_LOG(PAD, "\n--- DoChangeJoystick ----");
WARN_LOG(PAD, "DoSave");
DoSave(true);
// Load the settings for the new ID
WARN_LOG(PAD, "Load");
// Load the settings for the new Id
g_Config.Load(true);
// Update the GUI
WARN_LOG(PAD, "UpdateGUI");
UpdateGUI(notebookpage);
WARN_LOG(PAD, "");
}
// Pads have been connected/disconnected
void PADConfigDialognJoy::UpdateDeviceList()
{
if (!ControlsCreated) return;
DEBUG_LOG(PAD, "UpdateDeviceList");
for (int i = 0; i < 4; i++)
{
// Save current selection
//std::string CurrentSel = m_Joyname[i]->GetValue().mb_str();
m_Joyname[i]->Clear();
// Search for devices and add them to the device list
if (joyinfo.size() > 0)
{
for (int j = 0; j < joyinfo.size(); j++)
m_Joyname[i]->Append(wxString::FromAscii(joyinfo.at(j).Name.c_str()));
// Set selection
//PanicAlert("%s", PadMapping[i].Name.c_str());
for (int j = 0; j < joyinfo.size(); j++)
{
if (joyinfo.at(j).Name == PadMapping[i].Name) m_Joyname[i]->SetSelection(j);
}
if (m_Joyname[i]->GetSelection() == -1) m_Joyname[i]->SetSelection(0);
// Load settings
DoChangeJoystick();
}
else
{
m_Joyname[i]->Append(wxString::FromAscii("<No Gamepad Detected>"));
m_Joyname[i]->SetSelection(0);
}
}
UpdateGUI(notebookpage); // Update the GUI
}
// Notebook page changed
@ -388,7 +303,7 @@ void PADConfigDialognJoy::NotebookPageChanged(wxNotebookEvent& event)
// Save current settings now, don't wait for OK
if (ControlsCreated && !g_Config.bSaveByID) DoSave(false, notebookpage);
// Update the global variable
// Update the global variable
notebookpage = event.GetSelection();
// Update GUI
@ -420,28 +335,28 @@ void PADConfigDialognJoy::ToBlank(bool ToBlank)
}
// Change settings for all slots that have this pad selected
// -----------------------
// Change settings
void PADConfigDialognJoy::SetButtonTextAll(int id, const char *text)
{
for (int i = 0; i < 4; i++)
{
if (IDToName(PadMapping[i].ID) == IDToName(PadMapping[notebookpage].ID))
{
SetButtonText(id, text, i);
DEBUG_LOG(PAD, "Updated button text for slot %i", i);
}
// Safety check to avoid crash
if (joyinfo.size() > (u32)PadMapping[i].ID)
if (joyinfo[PadMapping[i].ID].Name == joyinfo[PadMapping[notebookpage].ID].Name)
SetButtonText(id, text, i);
};
}
void PADConfigDialognJoy::SaveButtonMappingAll(int Slot)
{
for (int i = 0; i < 4; i++)
{
if (PadMapping[i].Name.length() > 0 && PadMapping[i].Name == PadMapping[Slot].Name)
SaveButtonMapping(i, false, Slot);
// This can occur when no gamepad is detected
if (joyinfo.size() > (u32)PadMapping[i].ID)
if (joyinfo[PadMapping[i].ID].Name == joyinfo[PadMapping[Slot].ID].Name)
SaveButtonMapping(i, false, Slot);
}
}
// -----------------------
void PADConfigDialognJoy::UpdateGUIAll(int Slot)
{
@ -453,8 +368,10 @@ void PADConfigDialognJoy::UpdateGUIAll(int Slot)
{
for (int i = 0; i < 4; i++)
{
if (IDToName(PadMapping[i].ID) == IDToName(PadMapping[Slot].ID))
UpdateGUI(i);
// Safety check to avoid crash
if (joyinfo.size() > (u32)PadMapping[i].ID)
if (joyinfo[PadMapping[i].ID].Name == joyinfo[PadMapping[Slot].ID].Name)
UpdateGUI(i);
}
}
}
@ -521,10 +438,8 @@ void PADConfigDialognJoy::ChangeSettings( wxCommandEvent& event )
}
// Update all slots that use this device
//if(g_Config.bSaveByID)
SaveButtonMappingAll(notebookpage);
//if(g_Config.bSaveByID)
UpdateGUIAll(notebookpage);
if(g_Config.bSaveByID) SaveButtonMappingAll(notebookpage);
if(g_Config.bSaveByID) UpdateGUIAll(notebookpage);
}
@ -532,18 +447,12 @@ void PADConfigDialognJoy::ChangeSettings( wxCommandEvent& event )
// Called from: CreateGUIControls(), ChangeControllertype()
void PADConfigDialognJoy::UpdateGUI(int _notebookpage)
{
DEBUG_LOG(PAD, "UpdateGUI for slot %i, %i pads connected", _notebookpage, NumPads);
// If there are no good pads disable the entire notebook
if (NumPads == 0)
if (NumGoodPads == 0)
{
m_Notebook->Enable(false);
return;
}
else
{
m_Notebook->Enable(true);
}
// Update the GUI from PadMapping[]
UpdateGUIButtonMapping(_notebookpage);
@ -596,8 +505,6 @@ void PADConfigDialognJoy::UpdateGUI(int _notebookpage)
else m_CoBRadiusC[_notebookpage]->Enable(false);
if (PadMapping[_notebookpage].bSquareToCircleC) m_CoBDiagonalC[_notebookpage]->Enable(true);
else m_CoBDiagonalC[_notebookpage]->Enable(false);
DEBUG_LOG(PAD, "Main radius %s", PadMapping[_notebookpage].bRadiusOnOff ? "enabled" : "disabled");
}
// Repaint the background
@ -658,9 +565,24 @@ void PADConfigDialognJoy::CreateGUIControls()
m_Controller[3] = new wxPanel(m_Notebook, ID_CONTROLLERPAGE4, wxDefaultPosition, wxDefaultSize);
m_Notebook->AddPage(m_Controller[3], wxT("Controller 4"));
// Define bitmap for EVT_PAINT
WxStaticBitmap1_BITMAP = wxBitmap(ConfigBox_WxStaticBitmap1_XPM);
// Search for devices and add them to the device list
wxArrayString arrayStringFor_Joyname; // The string array
if (NumGoodPads > 0)
{
for(int x = 0; (u32)x < joyinfo.size(); x++)
{
arrayStringFor_Joyname.Add(wxString::FromAscii(joyinfo[x].Name.c_str()));
}
}
else
{
arrayStringFor_Joyname.Add(wxString::FromAscii("<No Gamepad Detected>"));
}
// Populate the DPad type and Trigger type list
wxArrayString wxAS_DPadType;
wxAS_DPadType.Add(wxString::FromAscii(DPadType[InputCommon::CTL_DPAD_HAT]));
@ -799,9 +721,9 @@ void PADConfigDialognJoy::CreateGUIControls()
// Populate Controller sizer
// Groups
#ifdef _WIN32
m_Joyname[i] = new wxComboBox(m_Controller[i], IDC_JOYNAME, wxEmptyString, wxDefaultPosition, wxSize(476, 21), 0, NULL, wxCB_READONLY);
m_Joyname[i] = new wxComboBox(m_Controller[i], IDC_JOYNAME, arrayStringFor_Joyname[0], wxDefaultPosition, wxSize(476, 21), arrayStringFor_Joyname, wxCB_READONLY);
#else
m_Joyname[i] = new wxComboBox(m_Controller[i], IDC_JOYNAME, wxEmptyString, wxDefaultPosition, wxSize(450, 25), 0, NULL, wxCB_READONLY);
m_Joyname[i] = new wxComboBox(m_Controller[i], IDC_JOYNAME, arrayStringFor_Joyname[0], wxDefaultPosition, wxSize(450, 25), arrayStringFor_Joyname, 0, wxDefaultValidator, wxT("m_Joyname"));
#endif
m_gJoyname[i] = new wxStaticBoxSizer (wxHORIZONTAL, m_Controller[i], wxT("Controller"));
@ -1032,6 +954,9 @@ void PADConfigDialognJoy::CreateGUIControls()
// Show or hide it. We have to do this after we add it to its sizer
m_sMainRight[i]->Show(g_Config.bShowAdvanced);
// Update GUI
UpdateGUI(i);
} // end of loop
// Populate buttons sizer.
@ -1050,7 +975,7 @@ void PADConfigDialognJoy::CreateGUIControls()
// Debugging
#ifdef SHOW_PAD_STATUS
m_pStatusBar = new wxStaticText(this, IDT_DEBUGGING, wxT("Debugging"), wxPoint(135, 100), wxSize(200, -1));
m_pStatusBar = new wxStaticText(this, IDT_DEBUGGING, wxT("Debugging"), wxPoint(135, 100), wxDefaultSize);
#endif
// Set window size

View File

@ -62,17 +62,12 @@ class PADConfigDialognJoy : public wxDialog
long style = wxDEFAULT_DIALOG_STYLE);
virtual ~PADConfigDialognJoy();
// Timers
#if wxUSE_TIMER
void OnSlowTimer(wxTimerEvent& WXUNUSED(event)) { UpdateSlow(); }
void OnTimer(wxTimerEvent& WXUNUSED(event)) { Update(); }
void OnButtonTimer(wxTimerEvent& WXUNUSED(event)) { DoGetButtons(GetButtonWaitingID); }
wxTimer *m_SlowTimer, *m_ConstantTimer, *m_ButtonMappingTimer;
wxTimer *m_ConstantTimer, *m_ButtonMappingTimer;
#endif
// Functions
void DoShow();
// Debugging
wxStaticText* m_pStatusBar, * m_pStatusBar2;
wxTextCtrl* m_TCDebugging;
@ -200,10 +195,7 @@ class PADConfigDialognJoy : public wxDialog
*m_bmpSquare[4], *m_bmpDot[4], *m_bmpSquareOut[4], *m_bmpDotOut[4], *m_bmpAreaOut[4],
*m_bmpSquareC[4], *m_bmpDotC[4], *m_bmpSquareOutC[4], *m_bmpDotOutC[4], *m_bmpAreaOutC[4];
// Settings
int notebookpage;
bool ControlsCreated;
bool LiveUpdates;
int notebookpage; bool ControlsCreated;
private:
enum
@ -241,7 +233,7 @@ class PADConfigDialognJoy : public wxDialog
IDT_TRIGGERS, IDCB_CHECKFOCUS, IDCB_FILTER_SETTINGS,
// Timers
IDTM_SLOW, IDTM_CONSTANT, IDTM_BUTTON,
IDTM_CONSTANT, IDTM_BUTTON,
// ==============================================
@ -324,8 +316,6 @@ class PADConfigDialognJoy : public wxDialog
void OKClick(wxCommandEvent& event);
void CancelClick(wxCommandEvent& event);
void DoSave(bool ChangePad = false, int Slot = -1);
void UpdateID();
void StartTimer();
void DoChangeJoystick();
@ -333,22 +323,20 @@ class PADConfigDialognJoy : public wxDialog
void ChangeSettings(wxCommandEvent& event);
void ComboChange(wxCommandEvent& event);
void OnClose(wxCloseEvent& event);
void UpdateDeviceList();
void CreateGUIControls();
void CreateAdvancedControls(int i);
wxBitmap CreateBitmap();
wxBitmap CreateBitmapDot();
wxBitmap CreateBitmapArea(int,int);
void PadShowStatus();
void UpdateSlow();
void PadGetStatus();
void Update();
void UpdateGUIButtonMapping(int controller);
void SaveButtonMapping(int controller, bool DontChangeId = false, int FromSlot = -1);
void SaveButtonMappingAll(int Slot);
void UpdateGUIAll(int Slot = -1);
void UpdateGUIAll(int Slot);
void ToBlank(bool ToBlank = true);
void OnSaveById();

View File

@ -50,11 +50,8 @@ void PADConfigDialognJoy::UpdateGUIButtonMapping(int controller)
// http://wiki.wxwidgets.org/Converting_everything_to_and_from_wxString
wxString tmp;
// Assert
//if (!ControlsCreated[i]) return;
// Update selected gamepad
m_Joyname[controller]->SetValue(wxString::FromAscii(PadMapping[controller].Name.c_str()));
m_Joyname[controller]->SetSelection(PadMapping[controller].ID);
tmp << PadMapping[controller].buttons[InputCommon::CTL_L_SHOULDER]; m_JoyShoulderL[controller]->SetValue(tmp); tmp.clear();
tmp << PadMapping[controller].buttons[InputCommon::CTL_R_SHOULDER]; m_JoyShoulderR[controller]->SetValue(tmp); tmp.clear();
@ -102,8 +99,7 @@ void PADConfigDialognJoy::UpdateGUIButtonMapping(int controller)
tmp << PadMapping[controller].dpad2[InputCommon::CTL_D_PAD_LEFT]; m_JoyDpadLeft[controller]->SetValue(tmp); tmp.clear();
tmp << PadMapping[controller].dpad2[InputCommon::CTL_D_PAD_RIGHT]; m_JoyDpadRight[controller]->SetValue(tmp); tmp.clear();
}
NOTICE_LOG(PAD, "Loaded from PadMapping[%i] to slot %i", controller, controller);
}
/* Populate the PadMapping array with the dialog items settings (for example
@ -121,21 +117,7 @@ void PADConfigDialognJoy::SaveButtonMapping(int controller, bool DontChangeId, i
ToBlank(false);
// Set other settings
if(!DontChangeId)
{
if (joyinfo.size() > m_Joyname[FromSlot]->GetSelection())
{
INFO_LOG(PAD, "%i: Changed PadMapping ID from %i to %i", controller, PadMapping[controller].ID, joyinfo.at(m_Joyname[FromSlot]->GetSelection()).ID);
PadMapping[controller].ID = joyinfo.at(m_Joyname[FromSlot]->GetSelection()).ID;
}
//else
// Assert
PadMapping[controller].Name = m_Joyname[FromSlot]->GetValue().mb_str();
}
NOTICE_LOG(PAD, "Saved PadMapping[%i] from slot %i", controller, FromSlot);
// Settings
if(!DontChangeId) PadMapping[controller].ID = m_Joyname[FromSlot]->GetSelection();
PadMapping[controller].controllertype = m_ControlType[FromSlot]->GetSelection();
PadMapping[controller].triggertype = m_TriggerType[FromSlot]->GetSelection();
PadMapping[controller].deadzone = m_Deadzone[FromSlot]->GetSelection();
@ -282,13 +264,6 @@ void PADConfigDialognJoy::GetButtons(wxCommandEvent& event)
void PADConfigDialognJoy::DoGetButtons(int GetId)
{
//INFO_LOG(PAD, "DoGetButtons: %i", GetId);
if (!SDLPolling || SDL_JoystickEventState(SDL_QUERY) == SDL_ENABLE) return;
// Turn off live updates because the change the joy handles
LiveUpdates = false;
// =============================================
// Collect the starting values
// ----------------
@ -305,7 +280,7 @@ void PADConfigDialognJoy::DoGetButtons(int GetId)
int Axes = SDL_JoystickNumAxes(joy);
int Hats = SDL_JoystickNumHats(joy);
//NOTICE_LOG(PAD, "PadID: %i Axes: %i Handle: %i\n", PadID, joyinfo[PadID].NumAxes, joyinfo[PadID].joy);
INFO_LOG(CONSOLE, "PadID: %i Axes: %i\n", PadID, joyinfo[PadID].NumAxes, joyinfo[PadID].joy);
// Get the controller and trigger type
int ControllerType = PadMapping[Controller].controllertype;
@ -368,8 +343,6 @@ void PADConfigDialognJoy::DoGetButtons(int GetId)
#if wxUSE_TIMER
m_ButtonMappingTimer->Start( floor((double)(1000 / TimesPerSecond)) );
#endif
//INFO_LOG(PAD, "Timer started");
}
// ===============================================
@ -380,7 +353,7 @@ void PADConfigDialognJoy::DoGetButtons(int GetId)
else
{
InputCommon::GetButton(
joy, PadID,
joy, PadID, Buttons, Axes, Hats,
g_Pressed, value, type, pressed, Succeed, Stop,
LeftRight, Axis, XInput, Button, Hat, NoTriggerFilter);
}
@ -395,7 +368,7 @@ void PADConfigDialognJoy::DoGetButtons(int GetId)
GetButtonWaitingTimer++;
// This is run every second
if (GetButtonWaitingTimer % TimesPerSecond == 0)
if(GetButtonWaitingTimer % TimesPerSecond == 0)
{
// Current time
int TmpTime = Seconds - (GetButtonWaitingTimer / TimesPerSecond);
@ -406,7 +379,7 @@ void PADConfigDialognJoy::DoGetButtons(int GetId)
}
// Time's up
if ( (GetButtonWaitingTimer / TimesPerSecond) >= Seconds )
if( (GetButtonWaitingTimer / TimesPerSecond) >= Seconds )
{
Stop = true;
// Leave a blank mapping
@ -414,10 +387,8 @@ void PADConfigDialognJoy::DoGetButtons(int GetId)
}
// If we got a button
if (Succeed)
if(Succeed)
{
//INFO_LOG(PAD, "Button mapping succeeded: %i", pressed);
Stop = true;
// Write the number of the pressed button to the text box
sprintf(format, "%d", pressed);
@ -425,12 +396,10 @@ void PADConfigDialognJoy::DoGetButtons(int GetId)
}
// Stop the timer
if (Stop)
if(Stop)
{
m_ButtonMappingTimer->Stop();
GetButtonWaitingTimer = 0;
LiveUpdates = true;
//INFO_LOG(PAD, "Timer stopped");
/* 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

View File

@ -48,13 +48,7 @@ std::vector<InputCommon::CONTROLLER_INFO> joyinfo;
InputCommon::CONTROLLER_STATE PadState[4];
InputCommon::CONTROLLER_MAPPING PadMapping[4];
bool g_EmulatorRunning = false;
bool SDLPolling = true;
#ifdef _WIN32
bool LiveUpdates = false;
#else
bool LiveUpdates = false;
#endif
int NumPads = 0, NumDIDevices = -1, LastPad = 0;
int NumPads = 0, NumGoodPads = 0, LastPad = 0;
#ifdef _WIN32
HWND m_hWnd = NULL, m_hConsole = NULL; // Handle to window
#endif
@ -160,9 +154,11 @@ void SetDllGlobals(PLUGIN_GLOBALS* _pPluginGlobals)
// ------------------
void DllConfig(HWND _hParent)
{
// Init Joystick + Haptic (force feedback) subsystem on SDL 1.3
// Populate joyinfo for all attached devices
LocalSearchDevices(joyinfo, NumPads);
//g_Config.Load(); // load settings
Search_Devices(joyinfo, NumPads, NumGoodPads);
g_Config.Load(); // load settings
#if defined(HAVE_WX) && HAVE_WX
if (!m_ConfigFrame)
@ -172,9 +168,9 @@ void DllConfig(HWND _hParent)
// Only allow one open at a time
if (!m_ConfigFrame->IsShown())
m_ConfigFrame->DoShow();
m_ConfigFrame->ShowModal();
else
m_ConfigFrame->Hide();
m_ConfigFrame->Hide();
#endif
}
@ -198,7 +194,7 @@ void Initialize(void *init)
#endif
// Populate joyinfo for all attached devices
LocalSearchDevices(joyinfo, NumPads);
Search_Devices(joyinfo, NumPads, NumGoodPads);
}
// Shutdown PAD (stop emulation)
@ -225,16 +221,18 @@ void Shutdown()
for (int i = 0; i < 4; i++)
{
if (joyinfo.size() > (u32)PadMapping[i].ID)
if(SDL_JoystickOpened(PadMapping[i].ID))
{
SDL_JoystickClose(PadState[i].joy);
PadState[i].joy = NULL;
}
if (joyinfo.at(PadMapping[i].ID).Good)
if(SDL_JoystickOpened(PadMapping[i].ID))
{
SDL_JoystickClose(PadState[i].joy);
PadState[i].joy = NULL;
}
}
// Clear the physical device info
joyinfo.clear();
NumPads = 0;
NumGoodPads = 0;
// Finally close SDL
SDL_Quit();
@ -285,12 +283,6 @@ void DoState(unsigned char **ptr, int mode)
// Function: Gives the current pad status to the Core
void PAD_GetStatus(u8 _numPAD, SPADStatus* _pPADStatus)
{
if (!IsPolling()) return;
// Update joyinfo handles. This is in case the Wiimote plugin has restarted SDL after a pad was conencted/disconnected
// so that the handles are updated.
if (LiveUpdates) LocalSearchDevices(joyinfo, NumPads);
// Check if the pad is avaliable, currently we don't disable pads just because they are
// disconnected
if (!PadState[_numPAD].joy) return;
@ -300,7 +292,7 @@ void PAD_GetStatus(u8 _numPAD, SPADStatus* _pPADStatus)
// Check that Dolphin is in focus, otherwise don't update the pad status
if (g_Config.bCheckFocus || IsFocus())
GetJoyState(PadState[_numPAD], PadMapping[_numPAD]);
GetJoyState(PadState[_numPAD], PadMapping[_numPAD], _numPAD, joyinfo[PadMapping[_numPAD].ID].NumButtons);
// Get type
int TriggerType = PadMapping[_numPAD].triggertype;
@ -447,127 +439,29 @@ void PAD_GetStatus(u8 _numPAD, SPADStatus* _pPADStatus)
// Search for SDL devices
// ----------------
bool LocalSearchDevices(std::vector<InputCommon::CONTROLLER_INFO> &_joyinfo, int &_NumPads)
bool Search_Devices(std::vector<InputCommon::CONTROLLER_INFO> &_joyinfo, int &_NumPads, int &_NumGoodPads)
{
//DEBUG_LOG(PAD, "LocalSearchDevices");
bool Success = InputCommon::SearchDevices(_joyinfo, _NumPads);
DoLocalSearchDevices(_joyinfo, _NumPads);
return Success;
}
bool Success = InputCommon::SearchDevices(_joyinfo, _NumPads, _NumGoodPads);
bool LocalSearchDevicesReset(std::vector<InputCommon::CONTROLLER_INFO> &_joyinfo, int &_NumPads)
{
//DEBUG_LOG(PAD, "LocalSearchDevicesUpdate: %i", IsPolling());
// Turn off device polling while resetting
EnablePolling(false);
bool Success = InputCommon::SearchDevicesReset(_joyinfo, _NumPads);
DoLocalSearchDevices(_joyinfo, _NumPads);
EnablePolling(true);
return Success;
}
bool DoLocalSearchDevices(std::vector<InputCommon::CONTROLLER_INFO> &_joyinfo, int &_NumPads)
{
// Don't warn the user if no gamepads are detected. If the pad doesn't respond he will open the configuration and fix it.
// Also, if he's using a Wii game he may not care that the gamepad is turned off.
if (_NumPads == 0 && g_EmulatorRunning)
// Warn the user if no gamepads are detected
if (_NumGoodPads == 0 && g_EmulatorRunning)
{
//PanicAlert("nJoy: No Gamepad Detected");
PanicAlert("nJoy: No Gamepad Detected");
return false;
}
// Load the first time
if (!g_Config.Loaded) g_Config.Load();
// Load PadMapping[] etc
g_Config.Load();
// Update the PadState[].joy handle
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < joyinfo.size(); j++)
{
if (joyinfo.at(j).Name == PadMapping[i].Name)
{
PadState[i].joy = joyinfo.at(j).joy;
//DEBUG_LOG(PAD, "Slot %i: %s", i, joyinfo.at(j).Name.c_str());
}
}
if (joyinfo.size() > (u32)PadMapping[i].ID)
if(joyinfo.at(PadMapping[i].ID).Good)
PadState[i].joy = SDL_JoystickOpen(PadMapping[i].ID);
}
return true;
}
// Is the device connected?
// ----------------
bool IsConnected(std::string Name)
{
for (int i = 0; i < joyinfo.size(); i++)
{
//DEBUG_LOG(PAD, "IDToName: ID %i id %i %s", ID, i, joyinfo.at(i).Name.c_str());
if (joyinfo.at(i).Name == Name)
return true;
}
}
// It could be possible to crash SDL.dll if SDL functions are called during SDL_Quit/SDL_Init. Therefore these functions.
// ----------------
bool IsPolling()
{
if (!SDLPolling || SDL_JoystickEventState(SDL_QUERY) == SDL_ENABLE)
return false;
else
return true;
}
void EnablePolling(bool Enable)
{
if (Enable)
{
SDLPolling = true;
SDL_JoystickEventState(SDL_IGNORE);
}
else
{
SDLPolling = false;
SDL_JoystickEventState(SDL_ENABLE);
}
}
// ID to Name
// ----------------
std::string IDToName(int ID)
{
for (int i = 0; i < joyinfo.size(); i++)
{
//DEBUG_LOG(PAD, "IDToName: ID %i id %i %s", ID, i, joyinfo.at(i).Name.c_str());
if (joyinfo.at(i).ID == ID)
return joyinfo.at(i).Name;
}
return "";
}
// ID to id - Get the gamepad id from a device ID (the ids will be all or some of the IDs)
// ----------------
int IDToid(int ID)
{
for (int i = 0; i < joyinfo.size(); i++)
{
if (joyinfo.at(i).ID == ID)
return i;
}
if (joyinfo.size() > 0)
{
ERROR_LOG(PAD, "IDToid error");
return 0;
}
else
{
PanicAlert("Error in IDToid. The plugin may crash.");
return -1;
}
return Success;
}

View File

@ -95,24 +95,13 @@
#ifdef _WIN32
extern HWND m_hWnd, m_hConsole; // Handle to window
#endif
extern int NumPads, NumDIDevices, LastPad; // Number of pads
extern bool SDLPolling;
extern bool LiveUpdates;
extern int NumPads, NumGoodPads, LastPad; // Number of goods pads
#endif
// Custom Functions
// ----------------
bool LocalSearchDevices(std::vector<InputCommon::CONTROLLER_INFO> &_joyinfo, int &_NumPads);
bool LocalSearchDevicesReset(std::vector<InputCommon::CONTROLLER_INFO> &_joyinfo, int &_NumPads);
bool DoLocalSearchDevices(std::vector<InputCommon::CONTROLLER_INFO> &_joyinfo, int &_NumPads);
int SearchDIDevices();
bool IsConnected(std::string Name);
bool IsPolling();
void EnablePolling(bool Enable);
std::string IDToName(int ID);
bool IsConnected(std::string Name);
int IDToid(int ID);
bool Search_Devices(std::vector<InputCommon::CONTROLLER_INFO> &_joyinfo, int &_NumPads, int &_NumGoodPads);
void DEBUG_INIT();
void DEBUG_QUIT();
bool IsFocus();