GCPad/New Wiimote Plugin: Individual keyboard and mouse devices are now listed on Windows(2 player with 2 keyboards possible). Improved the ability to map multiple inputs to the same control. Inputs from different devices can be mapped to the same button (example: Mouse Left and XInput A). More advanced mappings such as "Button 1 or 2 and NOT button 3" are possible. I hope the GUI after right clicking a button isn't too confusing(may change it to be a bit more user friendly). Hopefully, I didn't break OSX stuff by 'const'ing a few functions.

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@5757 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
Jordan Woyak
2010-06-21 03:12:16 +00:00
parent fde15c1bc6
commit 9e3b653688
30 changed files with 1232 additions and 1163 deletions

View File

@ -17,9 +17,11 @@
#include "ConfigDiag.h"
#define _connect_macro_(b, f, c, s) (b)->Connect(wxID_ANY, (c), wxCommandEventHandler( f ), (wxObject*)0, (wxEvtHandler*)s)
#define WXSTR_FROM_STR(s) (wxString::FromAscii((s).c_str()))
#define STR_FROM_WXSTR(w) (std::string((w).To8BitData()))
#define _connect_macro_(b, f, c, s) (b)->Connect(wxID_ANY, (c), wxCommandEventHandler( f ), (wxObject*)0, (wxEvtHandler*)s)
#define WXSTR_FROM_STR(s) (wxString::FromAscii((s).c_str()))
// ToAscii was causing probs with some extended ascii characters, To8BitData seems to work
#define STR_FROM_WXSTR(w) (std::string((w).To8BitData()))
void GamepadPage::ConfigExtension( wxCommandEvent& event )
{
@ -103,27 +105,32 @@ void PadSettingChoice::UpdateValue()
}
ControlDialog::ControlDialog(GamepadPage* const parent, InputPlugin& plugin, ControllerInterface::ControlReference* const ref)
:wxDialog( parent, -1, wxT("Configure Control"), wxDefaultPosition )
,control_reference(ref)
,m_plugin(plugin)
: wxDialog(parent, -1, wxT("Configure Control"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
, control_reference(ref)
, m_plugin(plugin)
, m_parent(parent)
{
m_devq = m_parent->controller->default_device;
// GetStrings() sounds slow :/
device_cbox = new wxComboBox( this, -1, wxString::FromAscii( ref->device_qualifier.ToString().c_str() ), wxDefaultPosition, wxSize(256,-1), parent->device_cbox->GetStrings(), wxTE_PROCESS_ENTER );
//device_cbox = new wxComboBox(this, -1, WXSTR_FROM_STR(ref->device_qualifier.ToString()), wxDefaultPosition, wxSize(256,-1), parent->device_cbox->GetStrings(), wxTE_PROCESS_ENTER);
device_cbox = new wxComboBox(this, -1, WXSTR_FROM_STR(m_devq.ToString()), wxDefaultPosition, wxSize(256,-1), parent->device_cbox->GetStrings(), wxTE_PROCESS_ENTER);
_connect_macro_( device_cbox, ControlDialog::SetDevice, wxEVT_COMMAND_COMBOBOX_SELECTED, this );
_connect_macro_( device_cbox, ControlDialog::SetDevice, wxEVT_COMMAND_TEXT_ENTER, this );
control_chooser = new ControlChooser( this, ref, parent );
wxStaticBoxSizer* const control_chooser = CreateControlChooser( this, parent );
wxStaticBoxSizer* const d_szr = new wxStaticBoxSizer( wxVERTICAL, this, wxT("Device") );
d_szr->Add( device_cbox, 0, wxEXPAND|wxALL, 5 );
wxBoxSizer* const szr = new wxBoxSizer( wxVERTICAL );
szr->Add( d_szr, 0, wxEXPAND|wxLEFT|wxRIGHT|wxTOP, 5 );
szr->Add( control_chooser, 0, wxEXPAND|wxALL, 5 );
szr->Add( control_chooser, 1, wxEXPAND|wxALL, 5 );
SetSizerAndFit( szr ); // needed
UpdateGUI();
}
ControlButton::ControlButton( wxWindow* const parent, ControllerInterface::ControlReference* const _ref, const unsigned int width, const std::string& label )
@ -131,9 +138,9 @@ ControlButton::ControlButton( wxWindow* const parent, ControllerInterface::Contr
, control_reference( _ref )
{
if ( label.empty() )
SetLabel( wxString::FromAscii( _ref->control_qualifier.name.c_str() ) );
SetLabel(WXSTR_FROM_STR(_ref->expression));
else
SetLabel( wxString::FromAscii( label.c_str() ) );
SetLabel(WXSTR_FROM_STR(label));
}
void InputConfigDialog::UpdateProfileComboBox()
@ -181,76 +188,63 @@ void InputConfigDialog::ClickSave( wxCommandEvent& event )
Close();
}
void ControlChooser::UpdateListContents()
void ControlDialog::UpdateListContents()
{
control_lbox->Clear();
// make sure it's a valid device
if ( control_reference->device )
const std::vector<ControllerInterface::Device*>::const_iterator di =
std::find(m_plugin.controller_interface.Devices().begin(),
m_plugin.controller_interface.Devices().end(),
m_devq);
if (m_plugin.controller_interface.Devices().end() != di)
{
if ( control_reference->is_input )
if (control_reference->is_input)
{
// for inputs
std::vector<ControllerInterface::Device::Input*>::const_iterator
i = control_reference->device->Inputs().begin(),
e = control_reference->device->Inputs().end();
for ( ; i!=e; ++i )
control_lbox->Append( wxString::FromAscii( (*i)->GetName().c_str() ) );
i = (*di)->Inputs().begin(),
e = (*di)->Inputs().end();
for (; i!=e; ++i)
control_lbox->Append(WXSTR_FROM_STR((*i)->GetName()));
}
else
{
// for outputs
std::vector<ControllerInterface::Device::Output*>::const_iterator
i = control_reference->device->Outputs().begin(),
e = control_reference->device->Outputs().end();
for ( ; i!=e; ++i )
control_lbox->Append( wxString::FromAscii( (*i)->GetName().c_str() ) );
i = (*di)->Outputs().begin(),
e = (*di)->Outputs().end();
for (; i!=e; ++i)
control_lbox->Append(WXSTR_FROM_STR((*i)->GetName()));
}
}
UpdateListSelection();
}
void ControlChooser::UpdateListSelection()
void ControlDialog::SelectControl(const std::string& name)
{
UpdateGUI();
//UpdateGUI();
wxArrayString control_names = control_lbox->GetStrings();
const std::string cname = control_reference->control_qualifier.name;
control_lbox->DeselectAll();
// if text starts and ends with '|' it's multiple controls, otherwise just single one
if (cname.size() ? ((*cname.rbegin()=='|') && (*cname.begin()=='|')) : false)
{
for (int i = int(control_names.size()) - 1; i >= 0; --i)
if (cname.find( control_names[i].Prepend(wxT('|')).Append(wxT('|')).ToAscii()) != cname.npos)
control_lbox->Select( i );
}
else
{
const int n = control_lbox->FindString(wxString::FromAscii(cname.c_str()));
if (n >= 0)
control_lbox->Select(n);
}
const int f = control_lbox->FindString(WXSTR_FROM_STR(name));
if (f >= 0)
control_lbox->Select(f);
}
void ControlChooser::UpdateGUI()
void ControlDialog::UpdateGUI()
{
// update textbox
textctrl->SetValue(wxString::FromAscii(control_reference->control_qualifier.name.c_str()));
textctrl->SetValue(WXSTR_FROM_STR(control_reference->expression));
// updates the "bound controls:" label
size_t bound = control_reference->controls.size();
size_t bound = control_reference->BoundCount();
std::ostringstream ss;
ss << "Bound Controls: ";
if ( bound ) ss << bound; else ss << "None";
m_bound_label->SetLabel(WXSTR_FROM_STR(ss.str()));
m_bound_label->SetLabel( wxString::FromAscii(ss.str().c_str()) );
};
void GamepadPage::UpdateGUI()
{
device_cbox->SetValue( wxString::FromAscii( controller->default_device.ToString().c_str() ) );
device_cbox->SetValue(WXSTR_FROM_STR(controller->default_device.ToString()));
std::vector< ControlGroupBox* >::const_iterator g = control_groups.begin(),
ge = control_groups.end();
@ -260,7 +254,10 @@ void GamepadPage::UpdateGUI()
std::vector<ControlButton*>::const_iterator i = (*g)->control_buttons.begin()
, e = (*g)->control_buttons.end();
for ( ; i!=e; ++i )
(*i)->SetLabel(WXSTR_FROM_STR((*i)->control_reference->control_qualifier.name));
//if (std::string::npos == (*i)->control_reference->expression.find_first_of("`|&!#"))
(*i)->SetLabel(WXSTR_FROM_STR((*i)->control_reference->expression));
//else
//(*i)->SetLabel(wxT("..."));
// cboxes
std::vector<PadSetting*>::const_iterator si = (*g)->options.begin()
@ -289,14 +286,13 @@ void GamepadPage::ClearAll( wxCommandEvent& event )
void ControlDialog::SetControl( wxCommandEvent& event )
{
control_reference->control_qualifier.name =
STR_FROM_WXSTR(control_chooser->textctrl->GetValue());
control_reference->expression = STR_FROM_WXSTR(textctrl->GetValue());
m_plugin.controls_crit.Enter(); // enter
control_reference->UpdateControls();
m_plugin.controller_interface.UpdateReference(control_reference, m_parent->controller->default_device);
m_plugin.controls_crit.Leave(); // leave
control_chooser->UpdateListSelection();
UpdateGUI();
}
void GamepadPage::SetDevice( wxCommandEvent& event )
@ -311,35 +307,62 @@ void GamepadPage::SetDevice( wxCommandEvent& event )
// update references
m_plugin.controls_crit.Enter(); // enter
controller->UpdateReferences(m_plugin.controller_interface);
controller->UpdateReferences( m_plugin.controller_interface );
m_plugin.controls_crit.Leave(); // leave
}
void ControlDialog::SetDevice( wxCommandEvent& event )
{
control_reference->device_qualifier.FromString(STR_FROM_WXSTR(device_cbox->GetValue()));
m_devq.FromString(STR_FROM_WXSTR(device_cbox->GetValue()));
// show user what it was validated as
device_cbox->SetValue(WXSTR_FROM_STR(control_reference->device_qualifier.ToString()));
// update references
m_plugin.controls_crit.Enter(); // enter
m_plugin.controller_interface.UpdateReference(control_reference);
m_plugin.controls_crit.Leave(); // leave
device_cbox->SetValue(WXSTR_FROM_STR(m_devq.ToString()));
// update gui
control_chooser->UpdateListContents();
UpdateListContents();
}
void ControlDialog::ClearControl( wxCommandEvent& event )
void ControlDialog::ClearControl(wxCommandEvent& event)
{
control_reference->control_qualifier.name.clear();
control_reference->expression.clear();
m_plugin.controls_crit.Leave(); // enter
control_reference->UpdateControls();
m_plugin.controller_interface.UpdateReference(control_reference, m_parent->controller->default_device);
m_plugin.controls_crit.Leave(); // leave
control_chooser->UpdateListSelection();
UpdateGUI();
}
void ControlDialog::AppendControl(wxCommandEvent& event)
{
const int num = control_lbox->GetSelection();
if (num < 0)
return;
// o boy!, hax
const wxString lbl = ((wxButton*)event.GetEventObject())->GetLabel();
wxString expr = textctrl->GetLabel();
// append the operator to the expression
if (wxT('!') == lbl[0] || false == expr.empty())
expr += lbl[0];
// non-default device
if (false == (m_devq == m_parent->controller->default_device))
expr.append(wxT('`')).append(WXSTR_FROM_STR(m_devq.ToString())).append(wxT('`'));
// append the control name
expr += control_lbox->GetString(num);
control_reference->expression = STR_FROM_WXSTR(expr);
m_plugin.controls_crit.Leave(); // enter
m_plugin.controller_interface.UpdateReference(control_reference, m_parent->controller->default_device);
m_plugin.controls_crit.Leave(); // leave
UpdateGUI();
}
void GamepadPage::AdjustSetting( wxCommandEvent& event )
@ -354,13 +377,9 @@ void GamepadPage::AdjustSetting( wxCommandEvent& event )
void GamepadPage::AdjustControlOption( wxCommandEvent& event )
{
m_plugin.controls_crit.Enter(); // enter
m_plugin.controls_crit.Enter(); // enter / prolly fine not being here
m_control_dialog->control_reference->range = ControlState( m_control_dialog->control_chooser->range_slider->GetValue() ) / SLIDER_TICK_COUNT;
if ( m_control_dialog->control_reference->is_input )
((ControllerInterface::InputReference*)m_control_dialog->control_reference)->mode =
m_control_dialog->control_chooser->mode_cbox->GetSelection();
m_control_dialog->control_reference->range = (ControlState)(m_control_dialog->range_slider->GetValue()) / SLIDER_TICK_COUNT;
m_plugin.controls_crit.Leave(); // leave
}
@ -378,12 +397,10 @@ void GamepadPage::ConfigControl( wxCommandEvent& event )
void GamepadPage::ClearControl( wxCommandEvent& event )
{
ControlButton* const btn = (ControlButton*)event.GetEventObject();
btn->control_reference->control_qualifier.name.clear();
btn->control_reference->device_qualifier = controller->default_device;
btn->control_reference->expression.clear();
//btn->control_reference->device_qualifier = controller->default_device;
m_plugin.controls_crit.Enter();
if (btn->control_reference->is_input)
((ControllerInterface::InputReference*)btn->control_reference)->mode = 0;
controller->UpdateReferences( m_plugin.controller_interface );
m_plugin.controls_crit.Leave();
@ -391,106 +408,95 @@ void GamepadPage::ClearControl( wxCommandEvent& event )
UpdateGUI();
}
void ControlDialog::DetectControl( wxCommandEvent& event )
void ControlDialog::DetectControl(wxCommandEvent& event)
{
wxButton* const btn = (wxButton*)event.GetEventObject();
// some hacks
const wxString lbl = btn->GetLabel();
wxChar num = lbl[0];
if (num > '9')
const std::vector<ControllerInterface::Device*>::const_iterator di =
std::find(m_plugin.controller_interface.Devices().begin(),
m_plugin.controller_interface.Devices().end(), m_devq);
if (m_plugin.controller_interface.Devices().end() != di)
{
num = 1;
btn->SetLabel(wxT("[ waiting ]"));
}
else
{
num -= 0x30;
btn->SetLabel(wxT("w"));
}
m_plugin.controls_crit.Enter(); // enter
if ( control_reference->Detect( DETECT_WAIT_TIME + (num - 1) * 500, num ) ) // if we got input, update gui
control_chooser->UpdateListSelection();
m_plugin.controls_crit.Leave(); // leave
m_plugin.controls_crit.Enter(); // enter
ControllerInterface::Device::Control* const ctrl = control_reference->Detect(DETECT_WAIT_TIME, *di);
btn->SetLabel(lbl);
// if we got input, select it in the list
if (ctrl)
SelectControl(ctrl->GetName());
m_plugin.controls_crit.Leave(); // leave
btn->SetLabel(lbl);
}
}
void GamepadPage::DetectControl( wxCommandEvent& event )
{
ControlButton* btn = (ControlButton*)event.GetEventObject();
btn->SetLabel(wxT("[ waiting ]"));
// find device :/
const std::vector<ControllerInterface::Device*>::const_iterator di =
std::find(m_plugin.controller_interface.Devices().begin(),
m_plugin.controller_interface.Devices().end(), controller->default_device);
m_plugin.controls_crit.Enter(); // enter
btn->control_reference->Detect( DETECT_WAIT_TIME );
m_plugin.controls_crit.Leave(); // leave
btn->SetLabel(WXSTR_FROM_STR(btn->control_reference->control_qualifier.name));
}
void ControlDialog::SelectControl( wxCommandEvent& event )
{
// needed for linux
if (IsBeingDeleted())
return;
wxListBox* const lb = (wxListBox*)event.GetEventObject();
wxArrayInt sels;
lb->GetSelections( sels );
wxArrayString names = lb->GetStrings();
wxString final_label;
if (sels.GetCount() == 1)
final_label = names[ sels[0] ];
else
if (m_plugin.controller_interface.Devices().end() != di)
{
final_label = wxT('|');
for ( unsigned int i=0; i<sels.GetCount(); ++i )
final_label += names[ sels[i] ] + wxT('|');
btn->SetLabel(wxT("[ waiting ]"));
m_plugin.controls_crit.Enter(); // enter
ControllerInterface::Device::Control* const ctrl = btn->control_reference->Detect(DETECT_WAIT_TIME, *di);
// if we got input, update expression and reference
if (ctrl)
{
btn->control_reference->expression = ctrl->GetName();
m_plugin.controller_interface.UpdateReference(btn->control_reference, controller->default_device);
}
m_plugin.controls_crit.Leave(); // leave
btn->SetLabel(WXSTR_FROM_STR(btn->control_reference->expression));
}
control_reference->control_qualifier.name =
std::string( final_label.ToAscii() );
m_plugin.controls_crit.Enter(); // enter
control_reference->UpdateControls();
m_plugin.controls_crit.Leave(); // leave
control_chooser->UpdateGUI();
}
ControlChooser::ControlChooser( wxWindow* const parent, ControllerInterface::ControlReference* const ref, wxWindow* const eventsink )
: wxStaticBoxSizer( wxVERTICAL, parent, ref->is_input ? wxT("Input") : wxT("Output") )
, control_reference(ref)
wxStaticBoxSizer* ControlDialog::CreateControlChooser( wxWindow* const parent, wxWindow* const eventsink )
{
textctrl = new wxTextCtrl( parent, -1, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER );
_connect_macro_( textctrl, ControlDialog::SetControl, wxEVT_COMMAND_TEXT_ENTER, parent);
wxStaticBoxSizer* const main_szr = new wxStaticBoxSizer(wxVERTICAL, parent, control_reference->is_input ? wxT("Input") : wxT("Output"));
wxButton* const detect_button = new wxButton( parent, -1, ref->is_input ? wxT("Detect 1") : wxT("Test") );
textctrl = new wxTextCtrl(parent, -1, wxEmptyString, wxDefaultPosition, wxSize(-1, 48), wxTE_PROCESS_ENTER | wxTE_MULTILINE);
_connect_macro_(textctrl, ControlDialog::SetControl, wxEVT_COMMAND_TEXT_ENTER, parent);
wxButton* const detect_button = new wxButton( parent, -1, control_reference->is_input ? wxT("Detect") : wxT("Test") );
wxButton* const clear_button = new wxButton( parent, -1, wxT("Clear"), wxDefaultPosition );
wxButton* const set_button = new wxButton( parent, -1, wxT("Set")/*, wxDefaultPosition, wxSize( 32, -1 )*/ );
wxButton* const or_button = new wxButton( parent, -1, wxT("| OR"), wxDefaultPosition );
// TODO: check if && is good on other OS
wxButton* const and_button = new wxButton( parent, -1, wxT("&& AND"), wxDefaultPosition );
wxButton* const not_button = new wxButton( parent, -1, wxT("! NOT"), wxDefaultPosition );
wxButton* const add_button = new wxButton( parent, -1, wxT("# ADD"), wxDefaultPosition );
control_lbox = new wxListBox( parent, -1, wxDefaultPosition, wxSize( 256, 128 ), wxArrayString(), wxLB_EXTENDED );
_connect_macro_( control_lbox, ControlDialog::SelectControl, wxEVT_COMMAND_LISTBOX_SELECTED, parent);
_connect_macro_(or_button, ControlDialog::AppendControl, wxEVT_COMMAND_BUTTON_CLICKED, parent);
_connect_macro_(and_button, ControlDialog::AppendControl, wxEVT_COMMAND_BUTTON_CLICKED, parent);
_connect_macro_(not_button, ControlDialog::AppendControl, wxEVT_COMMAND_BUTTON_CLICKED, parent);
_connect_macro_(add_button, ControlDialog::AppendControl, wxEVT_COMMAND_BUTTON_CLICKED, parent);
wxBoxSizer* const button_sizer = new wxBoxSizer( wxHORIZONTAL );
button_sizer->Add( detect_button, 1, 0, 5 );
if ( ref->is_input )
for ( unsigned int i = 2; i<5; ++i )
{
wxButton* d_btn = new wxButton( parent, -1, wxChar( '0'+i ), wxDefaultPosition, wxSize(20,-1) );
_connect_macro_( d_btn, ControlDialog::DetectControl, wxEVT_COMMAND_BUTTON_CLICKED, parent);
button_sizer->Add( d_btn );
}
button_sizer->Add( clear_button, 1, 0, 5 );
button_sizer->Add( set_button, 1, 0, 5 );
control_lbox = new wxListBox(parent, -1, wxDefaultPosition, wxSize(128, 128));
range_slider = new wxSlider( parent, -1, SLIDER_TICK_COUNT, 0, SLIDER_TICK_COUNT, wxDefaultPosition, wxDefaultSize, wxSL_TOP | wxSL_LABELS /*| wxSL_AUTOTICKS*/ );
wxBoxSizer* const button_sizer = new wxBoxSizer(wxVERTICAL);
button_sizer->Add(detect_button, 1, 0, 5);
button_sizer->Add(clear_button, 1, 0, 5);
button_sizer->Add(or_button, 1, 0, 5);
button_sizer->Add(and_button, 1, 0, 5);
button_sizer->Add(not_button, 1, 0, 5);
button_sizer->Add(add_button, 1, 0, 5);
button_sizer->Add(set_button, 1, 0, 5);
range_slider = new wxSlider( parent, -1, SLIDER_TICK_COUNT, 0, SLIDER_TICK_COUNT * 2, wxDefaultPosition, wxDefaultSize, wxSL_TOP | wxSL_LABELS /*| wxSL_AUTOTICKS*/ );
range_slider->SetValue( control_reference->range * SLIDER_TICK_COUNT );
@ -506,112 +512,96 @@ ControlChooser::ControlChooser( wxWindow* const parent, ControllerInterface::Con
range_sizer->Add( range_label, 0, wxCENTER|wxLEFT, 5 );
range_sizer->Add( range_slider, 1, wxEXPAND|wxLEFT, 5 );
wxBoxSizer* const txtbox_szr = new wxBoxSizer( wxHORIZONTAL );
wxBoxSizer* const ctrls_sizer = new wxBoxSizer(wxHORIZONTAL);
ctrls_sizer->Add(control_lbox, 1, wxEXPAND, 0);
ctrls_sizer->Add(button_sizer, 0, wxEXPAND, 0);
txtbox_szr->Add( textctrl, 1, wxEXPAND, 0 );
Add( range_sizer, 0, wxEXPAND|wxLEFT|wxRIGHT, 5 );
if ( control_reference->is_input )
{
mode_cbox = new wxChoice( parent, -1 );
mode_cbox->Append( wxT("OR") );
mode_cbox->Append( wxT("AND") );
mode_cbox->Append( wxT("NOT") );
mode_cbox->Select( ((ControllerInterface::InputReference*)control_reference)->mode );
_connect_macro_( mode_cbox, GamepadPage::AdjustControlOption, wxEVT_COMMAND_CHOICE_SELECTED, eventsink );
wxBoxSizer* const mode_szr = new wxBoxSizer( wxHORIZONTAL );
mode_szr->Add( new wxStaticText( parent, -1, wxT("Mode") ), 0, wxCENTER|wxLEFT|wxRIGHT, 5 );
mode_szr->Add( mode_cbox, 0, wxLEFT, 5 );
Add( mode_szr, 0, wxEXPAND|wxLEFT|wxRIGHT, 5 );
}
Add( txtbox_szr, 0, wxEXPAND|wxTOP|wxLEFT|wxRIGHT, 5 );
Add( button_sizer, 0, wxEXPAND|wxBOTTOM|wxLEFT|wxRIGHT, 5 );
Add( control_lbox, 0, wxEXPAND|wxLEFT|wxRIGHT|wxBOTTOM, 5 );
Add( m_bound_label, 0, wxEXPAND|wxLEFT, 80 );
main_szr->Add(range_sizer, 0, wxEXPAND|wxLEFT|wxRIGHT, 5);
main_szr->Add(ctrls_sizer, 0, wxEXPAND|wxLEFT|wxRIGHT|wxBOTTOM, 5);
main_szr->Add(textctrl, 1, wxEXPAND|wxLEFT|wxRIGHT|wxBOTTOM, 5);
main_szr->Add(m_bound_label, 0, wxCENTER, 0);
UpdateListContents();
return main_szr;
}
void GamepadPage::GetProfilePath(std::string& path)
{
const wxString& name = profile_cbox->GetValue();
if (false == name.empty())
{
// TODO: check for dumb characters maybe
path = File::GetUserPath(D_CONFIG_IDX);
path += PROFILES_PATH;
path += m_plugin.profile_name;
path += '/';
path += STR_FROM_WXSTR(profile_cbox->GetValue());
path += ".ini";
}
}
void GamepadPage::LoadProfile( wxCommandEvent& event )
{
// TODO: check for dumb characters maybe
if ( profile_cbox->GetValue().empty() )
return;
m_plugin.controls_crit.Enter();
std::string fname;
GamepadPage::GetProfilePath(fname);
std::string fname( File::GetUserPath(D_CONFIG_IDX) );
fname += PROFILES_PATH; fname += m_plugin.profile_name; fname += '/';
fname += profile_cbox->GetValue().ToAscii(); fname += ".ini";
if ( false == File::Exists( fname.c_str() ) )
if (false == File::Exists(fname.c_str()))
return;
IniFile inifile;
inifile.Load(fname);
controller->LoadConfig( inifile.GetOrCreateSection("Profile"));
controller->UpdateReferences( m_plugin.controller_interface );
m_plugin.controls_crit.Enter();
controller->LoadConfig(inifile.GetOrCreateSection("Profile"));
controller->UpdateReferences(m_plugin.controller_interface);
m_plugin.controls_crit.Leave();
UpdateGUI();
}
void GamepadPage::SaveProfile( wxCommandEvent& event )
{
// TODO: check for dumb characters
if ( profile_cbox->GetValue().empty() )
return;
std::string fname;
GamepadPage::GetProfilePath(fname);
std::string fname( File::GetUserPath(D_CONFIG_IDX) );
fname += PROFILES_PATH; fname += m_plugin.profile_name; fname += '/';
if ( false == File::Exists( fname.c_str() ) )
File::CreateFullPath( fname.c_str() );
fname += profile_cbox->GetValue().ToAscii(); fname += ".ini";
// don't need lock
IniFile inifile;
inifile.Load(fname);
controller->SaveConfig( inifile.GetOrCreateSection("Profile") );
inifile.Save(fname);
if (false == fname.empty())
{
IniFile inifile;
controller->SaveConfig(inifile.GetOrCreateSection("Profile"));
inifile.Save(fname);
}
m_config_dialog->UpdateProfileComboBox();
}
void GamepadPage::DeleteProfile( wxCommandEvent& event )
{
// TODO: check for dumb characters maybe
if ( profile_cbox->GetValue().empty() )
return;
// don't need lock
std::string fname( File::GetUserPath(D_CONFIG_IDX) );
fname += PROFILES_PATH; fname += m_plugin.profile_name; fname += '/';
fname += profile_cbox->GetValue().ToAscii(); fname += ".ini";
if ( File::Exists( fname.c_str() ) )
File::Delete( fname.c_str() );
std::string fname;
GamepadPage::GetProfilePath(fname);
const char* const fnamecstr = fname.c_str();
if (File::Exists(fnamecstr))
File::Delete(fnamecstr);
m_config_dialog->UpdateProfileComboBox();
}
void InputConfigDialog::UpdateDeviceComboBox()
{
std::vector< GamepadPage* >::iterator
i = m_padpages.begin(),
std::vector< GamepadPage* >::iterator i = m_padpages.begin(),
e = m_padpages.end();
ControllerInterface::DeviceQualifier dq;
for ( ; i != e; ++i )
{
(*i)->device_cbox->Clear();
std::vector<ControllerInterface::Device*>::const_iterator
di = m_plugin.controller_interface.Devices().begin(),
std::vector<ControllerInterface::Device*>::const_iterator di = m_plugin.controller_interface.Devices().begin(),
de = m_plugin.controller_interface.Devices().end();
for ( ; di!=de; ++di )
{
dq.FromDevice(*di);
dq.FromDevice( *di );
(*i)->device_cbox->Append(WXSTR_FROM_STR(dq.ToString()));
}
(*i)->device_cbox->SetValue(WXSTR_FROM_STR((*i)->controller->default_device.ToString()));
@ -637,7 +627,7 @@ void GamepadPage::RefreshDevices( wxCommandEvent& event )
}
ControlGroupBox::ControlGroupBox( ControllerEmu::ControlGroup* const group, wxWindow* const parent, wxWindow* const eventsink )
: wxStaticBoxSizer( wxVERTICAL, parent, wxString::FromAscii( group->name ) )
: wxStaticBoxSizer( wxVERTICAL, parent, wxString::FromAscii( group->name ) )
{
control_group = group;
@ -903,7 +893,7 @@ GamepadPage::GamepadPage( wxWindow* parent, InputPlugin& plugin, const unsigned
InputConfigDialog::InputConfigDialog(wxWindow* const parent, InputPlugin& plugin, const std::string& name)
: wxDialog(parent, wxID_ANY, wxString::FromAscii(name.c_str()), wxPoint(128,-1), wxDefaultSize)
: wxDialog( parent, wxID_ANY, wxString::FromAscii(name.c_str()), wxPoint(128,-1), wxDefaultSize )
, m_plugin(plugin)
{
m_pad_notebook = new wxNotebook( this, -1, wxDefaultPosition, wxDefaultSize, wxNB_DEFAULT );