2010-07-03 08:04:10 +00:00
|
|
|
|
|
|
|
#include "WiimoteConfigDiag.h"
|
2010-10-12 19:42:29 +00:00
|
|
|
#include "HW/Wiimote.h"
|
2011-02-23 03:06:16 +00:00
|
|
|
#include "HW/WiimoteReal/WiimoteReal.h"
|
2011-01-07 15:18:00 +00:00
|
|
|
#include "Frame.h"
|
2010-07-03 08:04:10 +00:00
|
|
|
|
2011-01-14 03:05:02 +00:00
|
|
|
#define _connect_macro_(b, f, c, s) (b)->Connect(wxID_ANY, (c), wxCommandEventHandler(f), (wxObject*)0, (wxEvtHandler*)s)
|
2010-07-03 08:04:10 +00:00
|
|
|
|
2010-09-16 22:50:18 +00:00
|
|
|
const wxString& ConnectedWiimotesString()
|
|
|
|
{
|
2011-01-07 15:18:00 +00:00
|
|
|
static wxString str;
|
|
|
|
str.Printf(_("Connected to %i Wiimotes"), WiimoteReal::Initialize());
|
2010-09-16 22:50:18 +00:00
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2010-07-03 08:04:10 +00:00
|
|
|
WiimoteConfigPage::WiimoteConfigPage(wxWindow* const parent, const int index)
|
|
|
|
: wxNotebookPage(parent, -1, wxDefaultPosition, wxDefaultSize)
|
2011-02-24 05:05:25 +00:00
|
|
|
, m_index(index), orig_source(g_wiimote_sources[index])
|
2010-07-03 08:04:10 +00:00
|
|
|
{
|
|
|
|
// input source
|
2011-01-05 04:35:46 +00:00
|
|
|
const wxString src_choices[] = { _("None"),
|
|
|
|
_("Emulated Wiimote"), _("Real Wiimote"), _("Hybrid Wiimote") };
|
2010-09-18 16:43:43 +00:00
|
|
|
|
|
|
|
wxChoice* const input_src_choice = new wxChoice(this, -1, wxDefaultPosition, wxDefaultSize,
|
|
|
|
sizeof(src_choices)/sizeof(*src_choices), src_choices);
|
|
|
|
input_src_choice->Select(g_wiimote_sources[m_index]);
|
|
|
|
_connect_macro_(input_src_choice, WiimoteConfigPage::SelectSource, wxEVT_COMMAND_CHOICE_SELECTED, this);
|
2010-07-03 08:04:10 +00:00
|
|
|
|
2011-01-05 04:35:46 +00:00
|
|
|
wxStaticBoxSizer* const input_src_sizer = new wxStaticBoxSizer(wxHORIZONTAL, this, _("Input Source"));
|
2010-09-18 16:43:43 +00:00
|
|
|
input_src_sizer->Add(input_src_choice, 1, wxEXPAND | wxALL, 5);
|
2010-07-03 08:04:10 +00:00
|
|
|
|
|
|
|
// emulated wiimote
|
2011-01-05 04:35:46 +00:00
|
|
|
wxButton* const configure_wiimote_emu_btn = new wxButton(this, -1, _("Configure"));
|
|
|
|
wxStaticBoxSizer* const wiimote_emu_sizer = new wxStaticBoxSizer(wxHORIZONTAL, this, _("Emulated Wiimote"));
|
2010-07-03 08:04:10 +00:00
|
|
|
wiimote_emu_sizer->Add(configure_wiimote_emu_btn, 1, wxEXPAND | wxALL, 5);
|
|
|
|
_connect_macro_(configure_wiimote_emu_btn, WiimoteConfigDiag::ConfigEmulatedWiimote, wxEVT_COMMAND_BUTTON_CLICKED, parent->GetParent());
|
|
|
|
|
|
|
|
// real wiimote
|
2010-09-18 16:43:43 +00:00
|
|
|
connected_wiimotes_txt = new wxStaticText(this, -1, ConnectedWiimotesString());
|
2010-09-16 22:50:18 +00:00
|
|
|
|
2011-01-05 04:35:46 +00:00
|
|
|
wxButton* const refresh_btn = new wxButton(this, -1, _("Refresh"), wxDefaultPosition);
|
2010-09-18 16:43:43 +00:00
|
|
|
_connect_macro_(refresh_btn, WiimoteConfigDiag::RefreshRealWiimotes, wxEVT_COMMAND_BUTTON_CLICKED, parent->GetParent());
|
2010-07-03 08:04:10 +00:00
|
|
|
|
2011-01-05 04:35:46 +00:00
|
|
|
wxStaticBoxSizer* const wiimote_real_sizer = new wxStaticBoxSizer(wxVERTICAL, this, _("Real Wiimote"));
|
2010-09-16 22:50:18 +00:00
|
|
|
wiimote_real_sizer->AddStretchSpacer(1);
|
2010-09-18 16:43:43 +00:00
|
|
|
wiimote_real_sizer->Add(connected_wiimotes_txt, 0, wxALIGN_CENTER | wxBOTTOM | wxLEFT | wxRIGHT, 5);
|
2010-09-16 22:50:18 +00:00
|
|
|
#ifdef _WIN32
|
2011-01-05 04:35:46 +00:00
|
|
|
wxButton* const pairup_btn = new wxButton(this, -1, _("Pair Up"), wxDefaultPosition);
|
2010-09-18 16:43:43 +00:00
|
|
|
_connect_macro_(pairup_btn, WiimoteConfigDiag::PairUpRealWiimotes, wxEVT_COMMAND_BUTTON_CLICKED, parent->GetParent());
|
2010-09-16 22:50:18 +00:00
|
|
|
wiimote_real_sizer->Add(pairup_btn, 0, wxALIGN_CENTER | wxBOTTOM, 5);
|
|
|
|
#endif
|
|
|
|
wiimote_real_sizer->Add(refresh_btn, 0, wxALIGN_CENTER, 5);
|
|
|
|
wiimote_real_sizer->AddStretchSpacer(1);
|
2010-07-03 08:04:10 +00:00
|
|
|
|
|
|
|
// sizers
|
|
|
|
wxBoxSizer* const left_sizer = new wxBoxSizer(wxVERTICAL);
|
2010-09-16 22:50:18 +00:00
|
|
|
left_sizer->Add(input_src_sizer, 0, wxEXPAND | wxBOTTOM, 5);
|
|
|
|
left_sizer->Add(wiimote_emu_sizer, 0, wxEXPAND, 0);
|
2010-07-03 08:04:10 +00:00
|
|
|
|
|
|
|
wxBoxSizer* const main_sizer = new wxBoxSizer(wxHORIZONTAL);
|
|
|
|
main_sizer->Add(left_sizer, 1, wxLEFT | wxTOP | wxBOTTOM | wxEXPAND, 5);
|
|
|
|
main_sizer->Add(wiimote_real_sizer, 1, wxALL | wxEXPAND, 5);
|
|
|
|
|
|
|
|
SetSizerAndFit(main_sizer);
|
|
|
|
Layout();
|
|
|
|
}
|
|
|
|
|
2011-06-02 19:32:34 +00:00
|
|
|
WiimoteGeneralConfigPage::WiimoteGeneralConfigPage(wxWindow* const parent)
|
|
|
|
: wxPanel(parent, -1, wxDefaultPosition)
|
|
|
|
|
|
|
|
{
|
|
|
|
const wxString str[] = { _("Bottom"), _("Top") };
|
|
|
|
wxChoice* const WiiSensBarPos = new wxChoice(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 2, str);
|
|
|
|
wxSlider* const WiiSensBarSens = new wxSlider(this, wxID_ANY, 0, 0, 4, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL);
|
|
|
|
wxSlider* const WiimoteSpkVolume = new wxSlider(this, wxID_ANY, 0, 0, 127);
|
|
|
|
wxCheckBox* const WiimoteMotor = new wxCheckBox(this, wxID_ANY, _("Wiimote Motor"));
|
|
|
|
wxCheckBox* const WiimoteReconnectOnLoad = new wxCheckBox(this, wxID_ANY, _("Reconnect Wiimote on State Loading"));
|
|
|
|
|
|
|
|
wxStaticText* const WiiSensBarPosText = new wxStaticText(this, wxID_ANY, _("Sensor Bar Position:"));
|
|
|
|
wxStaticText* const WiiSensBarSensText = new wxStaticText(this, wxID_ANY, _("IR Sensitivity:"));
|
|
|
|
wxStaticText* const WiiSensBarSensMinText = new wxStaticText(this, wxID_ANY, _("Min"));
|
|
|
|
wxStaticText* const WiiSensBarSensMaxText = new wxStaticText(this, wxID_ANY, _("Max"));
|
|
|
|
wxStaticText* const WiimoteSpkVolumeText = new wxStaticText(this, wxID_ANY, _("Speaker Volume:"));
|
|
|
|
wxStaticText* const WiimoteSpkVolumeMinText = new wxStaticText(this, wxID_ANY, _("Min"));
|
|
|
|
wxStaticText* const WiimoteSpkVolumeMaxText = new wxStaticText(this, wxID_ANY, _("Max"));
|
|
|
|
|
|
|
|
WiiSensBarSens->SetMinSize(wxSize(100,-1));
|
|
|
|
WiimoteSpkVolume->SetMinSize(wxSize(100,-1));
|
|
|
|
|
|
|
|
if (Core::GetState() != Core::CORE_UNINITIALIZED)
|
|
|
|
{
|
|
|
|
WiiSensBarPos->Disable();
|
|
|
|
WiiSensBarSens->Disable();
|
|
|
|
WiimoteSpkVolume->Disable();
|
|
|
|
WiimoteMotor->Disable();
|
|
|
|
WiiSensBarPosText->Disable();
|
|
|
|
WiiSensBarSensText->Disable();
|
|
|
|
WiiSensBarSensMinText->Disable();
|
|
|
|
WiiSensBarSensMaxText->Disable();
|
|
|
|
WiimoteSpkVolumeText->Disable();
|
|
|
|
WiimoteSpkVolumeMinText->Disable();
|
|
|
|
WiimoteSpkVolumeMaxText->Disable();
|
|
|
|
}
|
|
|
|
|
|
|
|
WiiSensBarPos->SetSelection(SConfig::GetInstance().m_SYSCONF->GetData<u8>("BT.BAR"));
|
|
|
|
WiiSensBarSens->SetValue(SConfig::GetInstance().m_SYSCONF->GetData<u32>("BT.SENS"));
|
|
|
|
WiimoteSpkVolume->SetValue(SConfig::GetInstance().m_SYSCONF->GetData<u8>("BT.SPKV"));
|
|
|
|
WiimoteMotor->SetValue(SConfig::GetInstance().m_SYSCONF->GetData<bool>("BT.MOT"));
|
|
|
|
WiimoteReconnectOnLoad->SetValue(SConfig::GetInstance().m_WiimoteReconnectOnLoad);
|
|
|
|
|
|
|
|
|
|
|
|
_connect_macro_(WiiSensBarPos, WiimoteGeneralConfigPage::OnSensorBarPos, wxEVT_COMMAND_CHOICE_SELECTED, this);
|
|
|
|
_connect_macro_(WiiSensBarSens, WiimoteGeneralConfigPage::OnSensorBarSensitivity, wxEVT_COMMAND_SLIDER_UPDATED, this);
|
|
|
|
_connect_macro_(WiimoteSpkVolume, WiimoteGeneralConfigPage::OnSpeakerVolume, wxEVT_COMMAND_SLIDER_UPDATED, this);
|
|
|
|
_connect_macro_(WiimoteMotor, WiimoteGeneralConfigPage::OnMotor, wxEVT_COMMAND_CHECKBOX_CLICKED, this);
|
|
|
|
_connect_macro_(WiimoteReconnectOnLoad, WiimoteGeneralConfigPage::OnReconnectOnLoad, wxEVT_COMMAND_CHECKBOX_CLICKED, this);
|
|
|
|
|
|
|
|
|
|
|
|
wxBoxSizer* const main_sizer = new wxBoxSizer(wxVERTICAL);
|
|
|
|
wxStaticBoxSizer* const general_sizer = new wxStaticBoxSizer(wxVERTICAL, this, _("General Settings"));
|
|
|
|
wxFlexGridSizer* const choice_sizer = new wxFlexGridSizer(2, 5, 5);
|
|
|
|
|
|
|
|
wxBoxSizer* const sensbarsens_sizer = new wxBoxSizer(wxHORIZONTAL);
|
|
|
|
sensbarsens_sizer->Add(WiiSensBarSensMinText, 1, wxALIGN_CENTER_VERTICAL, 0);
|
|
|
|
sensbarsens_sizer->Add(WiiSensBarSens);
|
|
|
|
sensbarsens_sizer->Add(WiiSensBarSensMaxText, 1, wxALIGN_CENTER_VERTICAL, 0);
|
|
|
|
|
|
|
|
wxBoxSizer* const spkvol_sizer = new wxBoxSizer(wxHORIZONTAL);
|
|
|
|
spkvol_sizer->Add(WiimoteSpkVolumeMinText, 1, wxALIGN_CENTER_VERTICAL, 0);
|
|
|
|
spkvol_sizer->Add(WiimoteSpkVolume);
|
|
|
|
spkvol_sizer->Add(WiimoteSpkVolumeMaxText, 1, wxALIGN_CENTER_VERTICAL, 0);
|
|
|
|
|
|
|
|
choice_sizer->Add(WiiSensBarPosText, 1, wxALIGN_CENTER_VERTICAL, 0);
|
|
|
|
choice_sizer->Add(WiiSensBarPos);
|
|
|
|
choice_sizer->Add(WiiSensBarSensText, 1, wxALIGN_CENTER_VERTICAL, 0);
|
|
|
|
choice_sizer->Add(sensbarsens_sizer);
|
|
|
|
choice_sizer->Add(WiimoteSpkVolumeText, 1, wxALIGN_CENTER_VERTICAL, 0);
|
|
|
|
choice_sizer->Add(spkvol_sizer);
|
|
|
|
|
|
|
|
|
|
|
|
wxGridSizer* const wiimote_sizer = new wxGridSizer(1, 5, 5);
|
|
|
|
wiimote_sizer->Add(WiimoteMotor);
|
|
|
|
wiimote_sizer->Add(WiimoteReconnectOnLoad);
|
|
|
|
|
|
|
|
general_sizer->Add(choice_sizer);
|
|
|
|
general_sizer->Add(wiimote_sizer);
|
|
|
|
|
|
|
|
main_sizer->Add(general_sizer, 0, wxEXPAND | wxALL, 5);
|
|
|
|
main_sizer->AddStretchSpacer();
|
|
|
|
SetSizerAndFit(main_sizer);
|
|
|
|
Layout();
|
|
|
|
}
|
|
|
|
|
2010-07-03 08:04:10 +00:00
|
|
|
WiimoteConfigDiag::WiimoteConfigDiag(wxWindow* const parent, InputPlugin& plugin)
|
2011-01-05 04:35:46 +00:00
|
|
|
: wxDialog(parent, -1, _("Dolphin Wiimote Configuration"), wxDefaultPosition, wxDefaultSize)
|
2011-03-15 14:37:04 +00:00
|
|
|
, m_plugin(plugin)
|
2010-07-03 08:04:10 +00:00
|
|
|
{
|
|
|
|
m_pad_notebook = new wxNotebook(this, -1, wxDefaultPosition, wxDefaultSize, wxNB_DEFAULT);
|
2011-06-02 19:32:34 +00:00
|
|
|
m_pad_notebook->AddPage(new WiimoteGeneralConfigPage(m_pad_notebook), wxString(_("General")));
|
2010-07-03 08:04:10 +00:00
|
|
|
for (unsigned int i = 0; i < 4; ++i)
|
|
|
|
{
|
|
|
|
WiimoteConfigPage* const wpage = new WiimoteConfigPage(m_pad_notebook, i);
|
2011-01-14 03:05:02 +00:00
|
|
|
m_pad_notebook->AddPage(wpage, wxString(_("Wiimote ")) + wxChar('1'+i));
|
2011-06-02 19:32:34 +00:00
|
|
|
m_wiimote_config_pages.push_back(wpage);
|
2010-07-03 08:04:10 +00:00
|
|
|
}
|
2011-03-15 14:37:04 +00:00
|
|
|
m_pad_notebook->SetSelection(0);
|
2010-07-03 08:04:10 +00:00
|
|
|
|
2011-06-03 12:26:32 +00:00
|
|
|
Connect(wxID_OK, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(WiimoteConfigDiag::Save));
|
|
|
|
Connect(wxID_CANCEL, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(WiimoteConfigDiag::Cancel));
|
2011-02-23 03:06:16 +00:00
|
|
|
|
2010-07-03 08:04:10 +00:00
|
|
|
wxBoxSizer* const main_sizer = new wxBoxSizer(wxVERTICAL);
|
|
|
|
main_sizer->Add(m_pad_notebook, 1, wxEXPAND | wxALL, 5);
|
2011-06-03 12:26:32 +00:00
|
|
|
main_sizer->Add(CreateButtonSizer(wxOK | wxCANCEL), 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, 5);
|
2010-07-03 08:04:10 +00:00
|
|
|
|
|
|
|
SetSizerAndFit(main_sizer);
|
|
|
|
|
|
|
|
Center();
|
|
|
|
}
|
|
|
|
|
2010-10-12 19:42:29 +00:00
|
|
|
void WiimoteConfigDiag::ConfigEmulatedWiimote(wxCommandEvent&)
|
2010-07-03 08:04:10 +00:00
|
|
|
{
|
2011-06-02 19:32:34 +00:00
|
|
|
InputConfigDialog* const m_emu_config_diag = new InputConfigDialog(this, m_plugin, _trans("Dolphin Emulated Wiimote Configuration"), m_pad_notebook->GetSelection()-1);
|
2010-07-03 08:04:10 +00:00
|
|
|
m_emu_config_diag->ShowModal();
|
|
|
|
m_emu_config_diag->Destroy();
|
|
|
|
}
|
|
|
|
|
2010-09-18 16:43:43 +00:00
|
|
|
void WiimoteConfigDiag::UpdateGUI()
|
|
|
|
{
|
2011-06-02 19:32:34 +00:00
|
|
|
for (std::vector<WiimoteConfigPage*>::iterator it = m_wiimote_config_pages.begin(); it != m_wiimote_config_pages.end(); ++it)
|
|
|
|
(*it)->connected_wiimotes_txt->SetLabel(ConnectedWiimotesString());
|
2010-09-18 16:43:43 +00:00
|
|
|
}
|
|
|
|
|
2010-09-16 22:50:18 +00:00
|
|
|
#ifdef _WIN32
|
2010-10-12 19:42:29 +00:00
|
|
|
void WiimoteConfigDiag::PairUpRealWiimotes(wxCommandEvent&)
|
2010-09-16 22:50:18 +00:00
|
|
|
{
|
|
|
|
const int paired = WiimoteReal::PairUp();
|
|
|
|
|
|
|
|
if (paired > 0)
|
|
|
|
{
|
|
|
|
// Will this message be anoying?
|
2011-01-13 02:05:58 +00:00
|
|
|
//PanicAlertT("Paired %d wiimotes.", paired);
|
2010-09-16 22:50:18 +00:00
|
|
|
WiimoteReal::Refresh();
|
2010-09-18 16:43:43 +00:00
|
|
|
UpdateGUI();
|
2010-09-16 22:50:18 +00:00
|
|
|
}
|
|
|
|
else if (paired < 0)
|
2011-01-13 02:05:58 +00:00
|
|
|
PanicAlertT("A supported bluetooth device was not found!\n"
|
|
|
|
"(Only the Microsoft bluetooth stack is supported.)");
|
2010-09-16 22:50:18 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-10-12 19:42:29 +00:00
|
|
|
void WiimoteConfigDiag::RefreshRealWiimotes(wxCommandEvent&)
|
2010-07-03 08:04:10 +00:00
|
|
|
{
|
|
|
|
WiimoteReal::Refresh();
|
2010-09-18 16:43:43 +00:00
|
|
|
UpdateGUI();
|
2010-07-03 08:04:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void WiimoteConfigPage::SelectSource(wxCommandEvent& event)
|
|
|
|
{
|
2011-02-23 03:06:16 +00:00
|
|
|
// This needs to be changed now in order for refresh to work right.
|
|
|
|
// Revert if the dialog is canceled.
|
2011-02-24 05:05:25 +00:00
|
|
|
g_wiimote_sources[m_index] = event.GetInt();
|
2011-02-23 03:06:16 +00:00
|
|
|
}
|
2011-01-07 15:18:00 +00:00
|
|
|
|
2011-02-23 03:06:16 +00:00
|
|
|
void WiimoteConfigPage::UpdateWiimoteStatus()
|
|
|
|
{
|
2011-02-24 05:05:25 +00:00
|
|
|
if (orig_source != g_wiimote_sources[m_index])
|
2011-02-23 03:06:16 +00:00
|
|
|
{
|
|
|
|
// Disconnect first, otherwise the new source doesn't seem to work
|
|
|
|
CFrame::ConnectWiimote(m_index, false);
|
|
|
|
// Connect wiimotes
|
|
|
|
if (WIIMOTE_SRC_EMU & g_wiimote_sources[m_index])
|
|
|
|
CFrame::ConnectWiimote(m_index, true);
|
2011-02-25 03:56:14 +00:00
|
|
|
else if (WIIMOTE_SRC_REAL & g_wiimote_sources[m_index] && WiimoteReal::g_wiimotes[m_index])
|
2011-02-23 03:06:16 +00:00
|
|
|
CFrame::ConnectWiimote(m_index, WiimoteReal::g_wiimotes[m_index]->IsConnected());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void WiimoteConfigPage::RevertSource()
|
|
|
|
{
|
|
|
|
g_wiimote_sources[m_index] = orig_source;
|
2010-07-03 08:04:10 +00:00
|
|
|
}
|
|
|
|
|
2011-03-15 21:57:00 +00:00
|
|
|
void WiimoteConfigDiag::Save(wxCommandEvent& event)
|
2010-07-03 08:04:10 +00:00
|
|
|
{
|
2011-02-28 20:40:15 +00:00
|
|
|
std::string ini_filename = File::GetUserPath(D_CONFIG_IDX) + WIIMOTE_INI_NAME ".ini";
|
2010-07-03 08:04:10 +00:00
|
|
|
|
|
|
|
IniFile inifile;
|
|
|
|
inifile.Load(ini_filename);
|
|
|
|
|
|
|
|
for (unsigned int i=0; i<MAX_WIIMOTES; ++i)
|
|
|
|
{
|
|
|
|
std::string secname("Wiimote");
|
|
|
|
secname += (char)('1' + i);
|
|
|
|
IniFile::Section& sec = *inifile.GetOrCreateSection(secname.c_str());
|
|
|
|
|
|
|
|
sec.Set("Source", (int)g_wiimote_sources[i]);
|
|
|
|
}
|
2011-06-02 19:32:34 +00:00
|
|
|
for (std::vector<WiimoteConfigPage*>::iterator it = m_wiimote_config_pages.begin(); it != m_wiimote_config_pages.end(); ++it)
|
|
|
|
(*it)->UpdateWiimoteStatus();
|
2010-07-03 08:04:10 +00:00
|
|
|
|
|
|
|
inifile.Save(ini_filename);
|
|
|
|
|
2011-03-15 21:57:00 +00:00
|
|
|
event.Skip();
|
2010-07-22 07:55:35 +00:00
|
|
|
}
|
2011-02-23 03:06:16 +00:00
|
|
|
|
2011-03-15 21:57:00 +00:00
|
|
|
void WiimoteConfigDiag::Cancel(wxCommandEvent& event)
|
2011-02-23 03:06:16 +00:00
|
|
|
{
|
2011-06-02 19:32:34 +00:00
|
|
|
for (std::vector<WiimoteConfigPage*>::iterator it = m_wiimote_config_pages.begin(); it != m_wiimote_config_pages.end(); ++it)
|
|
|
|
(*it)->RevertSource();
|
2011-03-15 14:37:04 +00:00
|
|
|
|
2011-03-15 21:57:00 +00:00
|
|
|
event.Skip();
|
2011-02-23 03:06:16 +00:00
|
|
|
}
|