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());
14 WiimoteConfigPage::WiimoteConfigPage(wxWindow
* const parent
, const int index
)
15 : wxNotebookPage(parent
, -1, wxDefaultPosition
, wxDefaultSize
)
19 m_input_src_choice
= new wxChoice(this, -1, wxDefaultPosition
);
20 m_input_src_choice
->Append(wxT("None"));
21 m_input_src_choice
->Append(wxT("Emulated Wiimote"));
22 m_input_src_choice
->Append(wxT("Real Wiimote"));
23 m_input_src_choice
->Append(wxT("Hybrid Wiimote"));
24 m_input_src_choice
->Select(g_wiimote_sources
[m_index
]);
25 _connect_macro_(m_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(m_input_src_choice
, 1, wxEXPAND
| wxALL
, 5);
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());
37 m_connected_wiimotes_txt
= new wxStaticText(this, -1, wxEmptyString
);
38 m_connected_wiimotes_txt
->SetLabel(ConnectedWiimotesString());
40 wxButton
* const refresh_btn
= new wxButton(this, -1, wxT("Refresh"), wxDefaultPosition
);
41 _connect_macro_(refresh_btn
, WiimoteConfigPage::RefreshRealWiimotes
, wxEVT_COMMAND_BUTTON_CLICKED
, this);
43 wxStaticBoxSizer
* const wiimote_real_sizer
= new wxStaticBoxSizer(wxVERTICAL
, this, wxT("Real Wiimote"));
44 wiimote_real_sizer
->AddStretchSpacer(1);
45 wiimote_real_sizer
->Add(m_connected_wiimotes_txt
, 0, wxALIGN_CENTER
| wxBOTTOM
| wxLEFT
| wxRIGHT
, 5);
47 wxButton
* const pairup_btn
= new wxButton(this, -1, wxT("Pair Up"), wxDefaultPosition
);
48 _connect_macro_(pairup_btn
, WiimoteConfigPage::PairUpRealWiimotes
, wxEVT_COMMAND_BUTTON_CLICKED
, this);
49 wiimote_real_sizer
->Add(pairup_btn
, 0, wxALIGN_CENTER
| wxBOTTOM
, 5);
51 wiimote_real_sizer
->Add(refresh_btn
, 0, wxALIGN_CENTER
, 5);
52 wiimote_real_sizer
->AddStretchSpacer(1);
55 wxBoxSizer
* const left_sizer
= new wxBoxSizer(wxVERTICAL
);
56 left_sizer
->Add(input_src_sizer
, 0, wxEXPAND
| wxBOTTOM
, 5);
57 left_sizer
->Add(wiimote_emu_sizer
, 0, wxEXPAND
, 0);
59 wxBoxSizer
* const main_sizer
= new wxBoxSizer(wxHORIZONTAL
);
60 main_sizer
->Add(left_sizer
, 1, wxLEFT
| wxTOP
| wxBOTTOM
| wxEXPAND
, 5);
61 main_sizer
->Add(wiimote_real_sizer
, 1, wxALL
| wxEXPAND
, 5);
63 SetSizerAndFit(main_sizer
);
67 WiimoteConfigDiag::WiimoteConfigDiag(wxWindow
* const parent
, InputPlugin
& plugin
)
68 : wxDialog(parent
, -1, wxT("Dolphin Wiimote Configuration"), wxDefaultPosition
, wxDefaultSize
)
71 m_pad_notebook
= new wxNotebook(this, -1, wxDefaultPosition
, wxDefaultSize
, wxNB_DEFAULT
);
72 for (unsigned int i
= 0; i
< 4; ++i
)
74 WiimoteConfigPage
* const wpage
= new WiimoteConfigPage(m_pad_notebook
, i
);
75 //m_padpages.push_back(wpage);
76 m_pad_notebook
->AddPage(wpage
, wxString(wxT("Wiimote ")) + wxChar('1'+i
));
79 wxButton
* const ok_button
= new wxButton(this, -1, wxT("OK"), wxDefaultPosition
);
80 _connect_macro_(ok_button
, WiimoteConfigDiag::Save
, wxEVT_COMMAND_BUTTON_CLICKED
, this);
82 wxBoxSizer
* const main_sizer
= new wxBoxSizer(wxVERTICAL
);
83 main_sizer
->Add(m_pad_notebook
, 1, wxEXPAND
| wxALL
, 5);
84 main_sizer
->Add(ok_button
, 0, wxALIGN_RIGHT
| wxRIGHT
| wxBOTTOM
, 5);
86 SetSizerAndFit(main_sizer
);
91 void WiimoteConfigDiag::ConfigEmulatedWiimote(wxCommandEvent
& event
)
93 InputConfigDialog
* const m_emu_config_diag
= new InputConfigDialog(this, m_plugin
, "Dolphin Emulated Wiimote Configuration", m_pad_notebook
->GetSelection());
94 m_emu_config_diag
->ShowModal();
95 m_emu_config_diag
->Destroy();
99 void WiimoteConfigPage::PairUpRealWiimotes(wxCommandEvent
& event
)
101 const int paired
= WiimoteReal::PairUp();
105 // Will this message be anoying?
106 //PanicAlert("Paired %d wiimotes.", paired);
107 WiimoteReal::Refresh();
110 PanicAlert("A supported bluetooth device was not found!\n"
111 "(Only the Microsoft bluetooth stack is supported.)");
115 void WiimoteConfigPage::RefreshRealWiimotes(wxCommandEvent
& event
)
117 WiimoteReal::Refresh();
118 m_connected_wiimotes_txt
->SetLabel(ConnectedWiimotesString());
121 void WiimoteConfigPage::SelectSource(wxCommandEvent
& event
)
123 // should be kinda fine, maybe should just set when user clicks OK, w/e change it later
124 g_wiimote_sources
[m_index
] = m_input_src_choice
->GetSelection();
127 void WiimoteConfigDiag::Save(wxCommandEvent
& event
)
129 std::string ini_filename
= (std::string(File::GetUserPath(D_CONFIG_IDX
)) + g_plugin
.ini_name
+ ".ini" );
132 inifile
.Load(ini_filename
);
134 for (unsigned int i
=0; i
<MAX_WIIMOTES
; ++i
)
136 std::string
secname("Wiimote");
137 secname
+= (char)('1' + i
);
138 IniFile::Section
& sec
= *inifile
.GetOrCreateSection(secname
.c_str());
140 sec
.Set("Source", (int)g_wiimote_sources
[i
]);
143 inifile
.Save(ini_filename
);