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 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);
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 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);
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);
50 wiimote_real_sizer
->Add(refresh_btn
, 0, wxALIGN_CENTER
, 5);
51 wiimote_real_sizer
->AddStretchSpacer(1);
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
);
66 WiimoteConfigDiag::WiimoteConfigDiag(wxWindow
* const parent
, InputPlugin
& plugin
)
67 : wxDialog(parent
, -1, wxT("Dolphin Wiimote Configuration"), wxDefaultPosition
, wxDefaultSize
)
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
);
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());
105 void WiimoteConfigDiag::PairUpRealWiimotes(wxCommandEvent
& event
)
107 const int paired
= WiimoteReal::PairUp();
111 // Will this message be anoying?
112 //PanicAlert("Paired %d wiimotes.", paired);
113 WiimoteReal::Refresh();
117 PanicAlert("A supported bluetooth device was not found!\n"
118 "(Only the Microsoft bluetooth stack is supported.)");
122 void WiimoteConfigDiag::RefreshRealWiimotes(wxCommandEvent
& event
)
124 WiimoteReal::Refresh();
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" );
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
);