New Wiimote Plugin: Fix Emulated Wiimote Problem.(fixes issue 3230) Made the "Connect...
[dolphin.git] / Source / Plugins / Plugin_WiimoteNew / Src / WiimoteConfigDiag.cpp
blob5ac1e9ee33e3c18cef331738c4bde4c1c018157d
2 #include "WiimoteConfigDiag.h"
3 #include "WiimoteReal/WiimoteReal.h"
5 #define _connect_macro_(b, f, c, s) (b)->Connect(wxID_ANY, (c), wxCommandEventHandler( f ), (wxObject*)0, (wxEvtHandler*)s)
7 const wxString& ConnectedWiimotesString()
9 static wxString str = wxT("Connected to . Wiimotes");
10 str[13] = wxChar(wxT('0') + WiimoteReal::Initialize());
11 return str;
14 WiimoteConfigPage::WiimoteConfigPage(wxWindow* const parent, const int index)
15 : wxNotebookPage(parent, -1, wxDefaultPosition, wxDefaultSize)
16 , m_index(index)
18 // input source
19 const wxString src_choices[] = { wxT("None"),
20 wxT("Emulated Wiimote"), wxT("Real Wiimote"), wxT("Hybrid Wiimote") };
22 wxChoice* const input_src_choice = new wxChoice(this, -1, wxDefaultPosition, wxDefaultSize,
23 sizeof(src_choices)/sizeof(*src_choices), src_choices);
24 input_src_choice->Select(g_wiimote_sources[m_index]);
25 _connect_macro_(input_src_choice, WiimoteConfigPage::SelectSource, wxEVT_COMMAND_CHOICE_SELECTED, this);
27 wxStaticBoxSizer* const input_src_sizer = new wxStaticBoxSizer(wxHORIZONTAL, this, wxT("Input Source"));
28 input_src_sizer->Add(input_src_choice, 1, wxEXPAND | wxALL, 5);
30 // emulated wiimote
31 wxButton* const configure_wiimote_emu_btn = new wxButton(this, -1, wxT("Configure"));
32 wxStaticBoxSizer* const wiimote_emu_sizer = new wxStaticBoxSizer(wxHORIZONTAL, this, wxT("Emulated Wiimote"));
33 wiimote_emu_sizer->Add(configure_wiimote_emu_btn, 1, wxEXPAND | wxALL, 5);
34 _connect_macro_(configure_wiimote_emu_btn, WiimoteConfigDiag::ConfigEmulatedWiimote, wxEVT_COMMAND_BUTTON_CLICKED, parent->GetParent());
36 // real wiimote
37 connected_wiimotes_txt = new wxStaticText(this, -1, ConnectedWiimotesString());
39 wxButton* const refresh_btn = new wxButton(this, -1, wxT("Refresh"), wxDefaultPosition);
40 _connect_macro_(refresh_btn, WiimoteConfigDiag::RefreshRealWiimotes, wxEVT_COMMAND_BUTTON_CLICKED, parent->GetParent());
42 wxStaticBoxSizer* const wiimote_real_sizer = new wxStaticBoxSizer(wxVERTICAL, this, wxT("Real Wiimote"));
43 wiimote_real_sizer->AddStretchSpacer(1);
44 wiimote_real_sizer->Add(connected_wiimotes_txt, 0, wxALIGN_CENTER | wxBOTTOM | wxLEFT | wxRIGHT, 5);
45 #ifdef _WIN32
46 wxButton* const pairup_btn = new wxButton(this, -1, wxT("Pair Up"), wxDefaultPosition);
47 _connect_macro_(pairup_btn, WiimoteConfigDiag::PairUpRealWiimotes, wxEVT_COMMAND_BUTTON_CLICKED, parent->GetParent());
48 wiimote_real_sizer->Add(pairup_btn, 0, wxALIGN_CENTER | wxBOTTOM, 5);
49 #endif
50 wiimote_real_sizer->Add(refresh_btn, 0, wxALIGN_CENTER, 5);
51 wiimote_real_sizer->AddStretchSpacer(1);
53 // sizers
54 wxBoxSizer* const left_sizer = new wxBoxSizer(wxVERTICAL);
55 left_sizer->Add(input_src_sizer, 0, wxEXPAND | wxBOTTOM, 5);
56 left_sizer->Add(wiimote_emu_sizer, 0, wxEXPAND, 0);
58 wxBoxSizer* const main_sizer = new wxBoxSizer(wxHORIZONTAL);
59 main_sizer->Add(left_sizer, 1, wxLEFT | wxTOP | wxBOTTOM | wxEXPAND, 5);
60 main_sizer->Add(wiimote_real_sizer, 1, wxALL | wxEXPAND, 5);
62 SetSizerAndFit(main_sizer);
63 Layout();
66 WiimoteConfigDiag::WiimoteConfigDiag(wxWindow* const parent, InputPlugin& plugin)
67 : wxDialog(parent, -1, wxT("Dolphin Wiimote Configuration"), wxDefaultPosition, wxDefaultSize)
68 , m_plugin(plugin)
70 m_pad_notebook = new wxNotebook(this, -1, wxDefaultPosition, wxDefaultSize, wxNB_DEFAULT);
71 for (unsigned int i = 0; i < 4; ++i)
73 WiimoteConfigPage* const wpage = new WiimoteConfigPage(m_pad_notebook, i);
74 //m_padpages.push_back(wpage);
75 m_pad_notebook->AddPage(wpage, wxString(wxT("Wiimote ")) + wxChar('1'+i));
78 wxButton* const ok_button = new wxButton(this, -1, wxT("OK"), wxDefaultPosition);
79 _connect_macro_(ok_button, WiimoteConfigDiag::Save, wxEVT_COMMAND_BUTTON_CLICKED, this);
81 wxBoxSizer* const main_sizer = new wxBoxSizer(wxVERTICAL);
82 main_sizer->Add(m_pad_notebook, 1, wxEXPAND | wxALL, 5);
83 main_sizer->Add(ok_button, 0, wxALIGN_RIGHT | wxRIGHT | wxBOTTOM, 5);
85 SetSizerAndFit(main_sizer);
87 Center();
90 void WiimoteConfigDiag::ConfigEmulatedWiimote(wxCommandEvent& event)
92 InputConfigDialog* const m_emu_config_diag = new InputConfigDialog(this, m_plugin, "Dolphin Emulated Wiimote Configuration", m_pad_notebook->GetSelection());
93 m_emu_config_diag->ShowModal();
94 m_emu_config_diag->Destroy();
97 void WiimoteConfigDiag::UpdateGUI()
99 for (size_t p = 0; p < m_pad_notebook->GetPageCount(); ++p)
100 ((WiimoteConfigPage*)m_pad_notebook->GetPage(p))->
101 connected_wiimotes_txt->SetLabel(ConnectedWiimotesString());
104 #ifdef _WIN32
105 void WiimoteConfigDiag::PairUpRealWiimotes(wxCommandEvent& event)
107 const int paired = WiimoteReal::PairUp();
109 if (paired > 0)
111 // Will this message be anoying?
112 //PanicAlert("Paired %d wiimotes.", paired);
113 WiimoteReal::Refresh();
114 UpdateGUI();
116 else if (paired < 0)
117 PanicAlert("A supported bluetooth device was not found!\n"
118 "(Only the Microsoft bluetooth stack is supported.)");
120 #endif
122 void WiimoteConfigDiag::RefreshRealWiimotes(wxCommandEvent& event)
124 WiimoteReal::Refresh();
125 UpdateGUI();
128 void WiimoteConfigPage::SelectSource(wxCommandEvent& event)
130 // should be kinda fine, maybe should just set when user clicks OK, w/e change it later
131 g_wiimote_sources[m_index] = event.GetInt();
134 void WiimoteConfigDiag::Save(wxCommandEvent& event)
136 std::string ini_filename = (std::string(File::GetUserPath(D_CONFIG_IDX)) + g_plugin.ini_name + ".ini" );
138 IniFile inifile;
139 inifile.Load(ini_filename);
141 for (unsigned int i=0; i<MAX_WIIMOTES; ++i)
143 std::string secname("Wiimote");
144 secname += (char)('1' + i);
145 IniFile::Section& sec = *inifile.GetOrCreateSection(secname.c_str());
147 sec.Set("Source", (int)g_wiimote_sources[i]);
150 inifile.Save(ini_filename);
152 Close();