| 1 | |
| 2 | #include "WiimoteConfigDiag.h" |
| 3 | #include "HW/Wiimote.h" |
| 4 | #include "HW/WiimoteReal/WiimoteReal.h" |
| 5 | #include "Frame.h" |
| 6 | |
| 7 | WiimoteConfigDiag::WiimoteConfigDiag(wxWindow* const parent, InputPlugin& plugin) |
| 8 | : wxDialog(parent, -1, _("Dolphin Wiimote Configuration")wxGetTranslation(("Dolphin Wiimote Configuration")), wxDefaultPosition, wxDefaultSize) |
| 9 | , m_plugin(plugin) |
| 10 | { |
| 11 | wxBoxSizer* const main_sizer = new wxBoxSizer(wxVERTICAL); |
| 12 | |
| 13 | |
| 14 | |
| 15 | wxStaticText* wiimote_label[4]; |
| 16 | wxChoice* wiimote_source_ch[4]; |
| 17 | |
| 18 | for (unsigned int i = 0; i < MAX_WIIMOTES; ++i) |
| 1 | Loop condition is true. Entering loop body | |
|
| 2 | | Assuming 'i' is >= MAX_WIIMOTES | |
|
| 3 | | Loop condition is false. Execution jumps to the end of the function | |
|
| 19 | { |
| 20 | wxString str; |
| 21 | str.Printf(_("Wiimote %i")wxGetTranslation(("Wiimote %i")), i + 1); |
| 22 | |
| 23 | const wxString src_choices[] = { _("None")wxGetTranslation(("None")), |
| 24 | _("Emulated Wiimote")wxGetTranslation(("Emulated Wiimote")), _("Real Wiimote")wxGetTranslation(("Real Wiimote")), _("Hybrid Wiimote")wxGetTranslation(("Hybrid Wiimote")) }; |
| 25 | |
| 26 | |
| 27 | |
| 28 | int source_ctrl_id = wxWindow::NewControlId(); |
| 29 | m_wiimote_index_from_ctrl_id.insert(std::pair<wxWindowID, unsigned int>(source_ctrl_id, i)); |
| 30 | |
| 31 | int config_bt_id = wxWindow::NewControlId(); |
| 32 | m_wiimote_index_from_conf_bt_id.insert(std::pair<wxWindowID, unsigned int>(config_bt_id, i)); |
| 33 | |
| 34 | wiimote_label[i] = new wxStaticText(this, wxID_ANY, str); |
| 35 | wiimote_source_ch[i] = new wxChoice(this, source_ctrl_id, wxDefaultPosition, wxDefaultSize, sizeof(src_choices)/sizeof(*src_choices), src_choices); |
| 36 | wiimote_source_ch[i]->Bind(wxEVT_COMMAND_CHOICE_SELECTED, &WiimoteConfigDiag::SelectSource, this); |
| 37 | wiimote_configure_bt[i] = new wxButton(this, config_bt_id, _("Configure")wxGetTranslation(("Configure"))); |
| 38 | wiimote_configure_bt[i]->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &WiimoteConfigDiag::ConfigEmulatedWiimote, this); |
| 39 | |
| 40 | m_orig_wiimote_sources[i] = g_wiimote_sources[i]; |
| 41 | wiimote_source_ch[i]->Select(m_orig_wiimote_sources[i]); |
| 42 | if (m_orig_wiimote_sources[i] != WIIMOTE_SRC_EMU && m_orig_wiimote_sources[i] != WIIMOTE_SRC_HYBRID) |
| 43 | wiimote_configure_bt[i]->Disable(); |
| 44 | } |
| 45 | |
| 46 | |
| 47 | |
| 48 | wxStaticBoxSizer* const wiimote_group = new wxStaticBoxSizer(wxHORIZONTAL, this, _("Wiimotes")wxGetTranslation(("Wiimotes"))); |
| 49 | wxFlexGridSizer* const wiimote_sizer = new wxFlexGridSizer(3, 5, 5); |
| 50 | for (unsigned int i = 0; i < 4; ++i) |
| 4 | | Loop condition is true. Entering loop body | |
|
| 51 | { |
| 52 | wiimote_sizer->Add(wiimote_label[i], 0, wxALIGN_CENTER_VERTICAL); |
| 5 | | Function call argument is an uninitialized value |
|
| 53 | wiimote_sizer->Add(wiimote_source_ch[i], 0, wxALIGN_CENTER_VERTICAL); |
| 54 | wiimote_sizer->Add(wiimote_configure_bt[i]); |
| 55 | } |
| 56 | wiimote_group->Add(wiimote_sizer, 1, wxEXPAND, 5 ); |
| 57 | |
| 58 | |
| 59 | |
| 60 | wxStaticBoxSizer* const bb_group = new wxStaticBoxSizer(wxHORIZONTAL, this, _("Balance Board")wxGetTranslation(("Balance Board"))); |
| 61 | wxFlexGridSizer* const bb_sizer = new wxFlexGridSizer(1, 5, 5); |
| 62 | int source_ctrl_id = wxWindow::NewControlId(); |
| 63 | m_wiimote_index_from_ctrl_id.insert(std::pair<wxWindowID, unsigned int>(source_ctrl_id, WIIMOTE_BALANCE_BOARD)); |
| 64 | const wxString src_choices[] = { _("None")wxGetTranslation(("None")), _("Real Balance Board")wxGetTranslation(("Real Balance Board")) }; |
| 65 | wxChoice* bb_source = new wxChoice(this, source_ctrl_id, wxDefaultPosition, wxDefaultSize, sizeof(src_choices)/sizeof(*src_choices), src_choices); |
| 66 | bb_source->Bind(wxEVT_COMMAND_CHOICE_SELECTED, &WiimoteConfigDiag::SelectSource, this); |
| 67 | |
| 68 | m_orig_wiimote_sources[WIIMOTE_BALANCE_BOARD] = g_wiimote_sources[WIIMOTE_BALANCE_BOARD]; |
| 69 | bb_source->Select(m_orig_wiimote_sources[WIIMOTE_BALANCE_BOARD] ? 1 : 0); |
| 70 | |
| 71 | bb_sizer->Add(bb_source, 0, wxALIGN_CENTER_VERTICAL); |
| 72 | |
| 73 | bb_group->Add(bb_sizer, 1, wxEXPAND, 5 ); |
| 74 | |
| 75 | |
| 76 | |
| 77 | wxButton* const refresh_btn = new wxButton(this, -1, _("Refresh")wxGetTranslation(("Refresh")), wxDefaultPosition); |
| 78 | refresh_btn->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &WiimoteConfigDiag::RefreshRealWiimotes, this); |
| 79 | |
| 80 | wxStaticBoxSizer* const real_wiimotes_group = new wxStaticBoxSizer(wxVERTICAL, this, _("Real Wiimotes")wxGetTranslation(("Real Wiimotes"))); |
| 81 | |
| 82 | wxBoxSizer* const real_wiimotes_sizer = new wxBoxSizer(wxHORIZONTAL); |
| 83 | |
| 84 | if (!WiimoteReal::g_wiimote_scanner.IsReady()) |
| 85 | real_wiimotes_group->Add(new wxStaticText(this, -1, _("A supported bluetooth device could not be found.\n"wxGetTranslation(("A supported bluetooth device could not be found.\n" "You must manually connect your wiimotes.")) |
| 86 | "You must manually connect your wiimotes.")wxGetTranslation(("A supported bluetooth device could not be found.\n" "You must manually connect your wiimotes."))), 0, wxALIGN_CENTER | wxALL, 5); |
| 87 | |
| 88 | wxCheckBox* const continuous_scanning = new wxCheckBox(this, wxID_ANY, _("Continuous Scanning")wxGetTranslation(("Continuous Scanning"))); |
| 89 | continuous_scanning->Bind(wxEVT_COMMAND_CHECKBOX_CLICKED, &WiimoteConfigDiag::OnContinuousScanning, this); |
| 90 | continuous_scanning->SetValue(SConfig::GetInstance().m_WiimoteContinuousScanning); |
| 91 | |
| 92 | auto wiimote_speaker = new wxCheckBox(this, wxID_ANY, _("Enable Speaker Data")wxGetTranslation(("Enable Speaker Data"))); |
| 93 | wiimote_speaker->Bind(wxEVT_COMMAND_CHECKBOX_CLICKED, &WiimoteConfigDiag::OnEnableSpeaker, this); |
| 94 | wiimote_speaker->SetValue(SConfig::GetInstance().m_WiimoteEnableSpeaker); |
| 95 | |
| 96 | real_wiimotes_sizer->Add(continuous_scanning, 0, wxALIGN_CENTER_VERTICAL); |
| 97 | real_wiimotes_sizer->AddStretchSpacer(1); |
| 98 | real_wiimotes_sizer->Add(refresh_btn, 0, wxALL | wxALIGN_CENTER, 5); |
| 99 | |
| 100 | real_wiimotes_group->Add(wiimote_speaker, 0); |
| 101 | real_wiimotes_group->Add(real_wiimotes_sizer, 0, wxEXPAND); |
| 102 | |
| 103 | |
| 104 | const wxString str[] = { _("Bottom")wxGetTranslation(("Bottom")), _("Top")wxGetTranslation(("Top")) }; |
| 105 | wxChoice* const WiiSensBarPos = new wxChoice(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 2, str); |
| 106 | wxSlider* const WiiSensBarSens = new wxSlider(this, wxID_ANY, 0, 0, 4, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTALwxHORIZONTAL); |
| 107 | wxSlider* const WiimoteSpkVolume = new wxSlider(this, wxID_ANY, 0, 0, 127); |
| 108 | wxCheckBox* const WiimoteMotor = new wxCheckBox(this, wxID_ANY, _("Wiimote Motor")wxGetTranslation(("Wiimote Motor"))); |
| 109 | wxCheckBox* const WiimoteReconnectOnLoad = new wxCheckBox(this, wxID_ANY, _("Reconnect Wiimote on State Loading")wxGetTranslation(("Reconnect Wiimote on State Loading"))); |
| 110 | |
| 111 | wxStaticText* const WiiSensBarPosText = new wxStaticText(this, wxID_ANY, _("Sensor Bar Position:")wxGetTranslation(("Sensor Bar Position:"))); |
| 112 | wxStaticText* const WiiSensBarSensText = new wxStaticText(this, wxID_ANY, _("IR Sensitivity:")wxGetTranslation(("IR Sensitivity:"))); |
| 113 | wxStaticText* const WiiSensBarSensMinText = new wxStaticText(this, wxID_ANY, _("Min")wxGetTranslation(("Min"))); |
| 114 | wxStaticText* const WiiSensBarSensMaxText = new wxStaticText(this, wxID_ANY, _("Max")wxGetTranslation(("Max"))); |
| 115 | wxStaticText* const WiimoteSpkVolumeText = new wxStaticText(this, wxID_ANY, _("Speaker Volume:")wxGetTranslation(("Speaker Volume:"))); |
| 116 | wxStaticText* const WiimoteSpkVolumeMinText = new wxStaticText(this, wxID_ANY, _("Min")wxGetTranslation(("Min"))); |
| 117 | wxStaticText* const WiimoteSpkVolumeMaxText = new wxStaticText(this, wxID_ANY, _("Max")wxGetTranslation(("Max"))); |
| 118 | |
| 119 | |
| 120 | WiiSensBarSens->SetMinSize(wxSize(100,-1)); |
| 121 | WiimoteSpkVolume->SetMinSize(wxSize(100,-1)); |
| 122 | |
| 123 | |
| 124 | |
| 125 | if (Core::GetState() != Core::CORE_UNINITIALIZED) |
| 126 | { |
| 127 | WiiSensBarPos->Disable(); |
| 128 | WiiSensBarSens->Disable(); |
| 129 | WiimoteSpkVolume->Disable(); |
| 130 | WiimoteMotor->Disable(); |
| 131 | WiiSensBarPosText->Disable(); |
| 132 | WiiSensBarSensText->Disable(); |
| 133 | WiiSensBarSensMinText->Disable(); |
| 134 | WiiSensBarSensMaxText->Disable(); |
| 135 | WiimoteSpkVolumeText->Disable(); |
| 136 | WiimoteSpkVolumeMinText->Disable(); |
| 137 | WiimoteSpkVolumeMaxText->Disable(); |
| 138 | } |
| 139 | |
| 140 | |
| 141 | |
| 142 | WiiSensBarPos->SetSelection(SConfig::GetInstance().m_SYSCONF->GetData<u8>("BT.BAR")); |
| 143 | WiiSensBarSens->SetValue(SConfig::GetInstance().m_SYSCONF->GetData<u32>("BT.SENS")); |
| 144 | WiimoteSpkVolume->SetValue(SConfig::GetInstance().m_SYSCONF->GetData<u8>("BT.SPKV")); |
| 145 | WiimoteMotor->SetValue(SConfig::GetInstance().m_SYSCONF->GetData<bool>("BT.MOT")); |
| 146 | WiimoteReconnectOnLoad->SetValue(SConfig::GetInstance().m_WiimoteReconnectOnLoad); |
| 147 | |
| 148 | WiiSensBarPos->Bind(wxEVT_COMMAND_CHOICE_SELECTED, &WiimoteConfigDiag::OnSensorBarPos, this); |
| 149 | WiiSensBarSens->Bind(wxEVT_COMMAND_SLIDER_UPDATED, &WiimoteConfigDiag::OnSensorBarSensitivity, this); |
| 150 | WiimoteSpkVolume->Bind(wxEVT_COMMAND_SLIDER_UPDATED, &WiimoteConfigDiag::OnSpeakerVolume, this); |
| 151 | WiimoteMotor->Bind(wxEVT_COMMAND_CHECKBOX_CLICKED, &WiimoteConfigDiag::OnMotor, this); |
| 152 | WiimoteReconnectOnLoad->Bind(wxEVT_COMMAND_CHECKBOX_CLICKED, &WiimoteConfigDiag::OnReconnectOnLoad, this); |
| 153 | |
| 154 | |
| 155 | |
| 156 | wxStaticBoxSizer* const general_sizer = new wxStaticBoxSizer(wxVERTICAL, this, _("General Settings")wxGetTranslation(("General Settings"))); |
| 157 | wxFlexGridSizer* const choice_sizer = new wxFlexGridSizer(2, 5, 5); |
| 158 | |
| 159 | wxBoxSizer* const sensbarsens_sizer = new wxBoxSizer(wxHORIZONTAL); |
| 160 | sensbarsens_sizer->Add(WiiSensBarSensMinText, 0, wxALIGN_CENTER_VERTICAL); |
| 161 | sensbarsens_sizer->Add(WiiSensBarSens); |
| 162 | sensbarsens_sizer->Add(WiiSensBarSensMaxText, 0, wxALIGN_CENTER_VERTICAL); |
| 163 | |
| 164 | wxBoxSizer* const spkvol_sizer = new wxBoxSizer(wxHORIZONTAL); |
| 165 | spkvol_sizer->Add(WiimoteSpkVolumeMinText, 0, wxALIGN_CENTER_VERTICAL); |
| 166 | spkvol_sizer->Add(WiimoteSpkVolume); |
| 167 | spkvol_sizer->Add(WiimoteSpkVolumeMaxText, 0, wxALIGN_CENTER_VERTICAL); |
| 168 | |
| 169 | choice_sizer->Add(WiiSensBarPosText, 0, wxALIGN_CENTER_VERTICAL); |
| 170 | choice_sizer->Add(WiiSensBarPos); |
| 171 | choice_sizer->Add(WiiSensBarSensText, 0, wxALIGN_CENTER_VERTICAL); |
| 172 | choice_sizer->Add(sensbarsens_sizer); |
| 173 | choice_sizer->Add(WiimoteSpkVolumeText, 0, wxALIGN_CENTER_VERTICAL); |
| 174 | choice_sizer->Add(spkvol_sizer); |
| 175 | |
| 176 | wxGridSizer* const general_wiimote_sizer = new wxGridSizer(1, 5, 5); |
| 177 | general_wiimote_sizer->Add(WiimoteMotor); |
| 178 | general_wiimote_sizer->Add(WiimoteReconnectOnLoad); |
| 179 | |
| 180 | general_sizer->Add(choice_sizer); |
| 181 | general_sizer->Add(general_wiimote_sizer); |
| 182 | |
| 183 | |
| 184 | |
| 185 | main_sizer->Add(wiimote_group, 0, wxEXPAND | wxALL, 5); |
| 186 | main_sizer->Add(bb_group, 0, wxEXPAND | wxALL, 5); |
| 187 | main_sizer->Add(real_wiimotes_group, 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, 5); |
| 188 | main_sizer->Add(general_sizer, 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, 5); |
| 189 | main_sizer->Add(CreateButtonSizer(wxOK0x00000004 | wxCANCEL0x00000010), 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, 5); |
| 190 | |
| 191 | Bind(wxEVT_COMMAND_BUTTON_CLICKED, &WiimoteConfigDiag::Save, this, wxID_OK); |
| 192 | Bind(wxEVT_COMMAND_BUTTON_CLICKED, &WiimoteConfigDiag::Cancel, this, wxID_CANCEL); |
| 193 | |
| 194 | SetSizerAndFit(main_sizer); |
| 195 | Center(); |
| 196 | } |
| 197 | |
| 198 | |
| 199 | void WiimoteConfigDiag::ConfigEmulatedWiimote(wxCommandEvent& ev) |
| 200 | { |
| 201 | InputConfigDialog* const m_emu_config_diag = new InputConfigDialog(this, m_plugin, _trans("Dolphin Emulated Wiimote Configuration")"Dolphin Emulated Wiimote Configuration", m_wiimote_index_from_conf_bt_id[ev.GetId()]); |
| 202 | m_emu_config_diag->ShowModal(); |
| 203 | m_emu_config_diag->Destroy(); |
| 204 | } |
| 205 | |
| 206 | void WiimoteConfigDiag::RefreshRealWiimotes(wxCommandEvent&) |
| 207 | { |
| 208 | WiimoteReal::Refresh(); |
| 209 | } |
| 210 | |
| 211 | void WiimoteConfigDiag::SelectSource(wxCommandEvent& event) |
| 212 | { |
| 213 | |
| 214 | |
| 215 | int index = m_wiimote_index_from_ctrl_id[event.GetId()]; |
| 216 | |
| 217 | if(index != WIIMOTE_BALANCE_BOARD) |
| 218 | { |
| 219 | WiimoteReal::ChangeWiimoteSource(index, event.GetInt()); |
| 220 | if (g_wiimote_sources[index] != WIIMOTE_SRC_EMU && g_wiimote_sources[index] != WIIMOTE_SRC_HYBRID) |
| 221 | wiimote_configure_bt[index]->Disable(); |
| 222 | else |
| 223 | wiimote_configure_bt[index]->Enable(); |
| 224 | } |
| 225 | else |
| 226 | { |
| 227 | WiimoteReal::ChangeWiimoteSource(index, event.GetInt() ? WIIMOTE_SRC_REAL : WIIMOTE_SRC_NONE); |
| 228 | } |
| 229 | } |
| 230 | |
| 231 | void WiimoteConfigDiag::RevertSource() |
| 232 | { |
| 233 | for (int i = 0; i < MAX_BBMOTES; ++i) |
| 234 | g_wiimote_sources[i] = m_orig_wiimote_sources[i]; |
| 235 | } |
| 236 | |
| 237 | void WiimoteConfigDiag::Save(wxCommandEvent& event) |
| 238 | { |
| 239 | std::string ini_filename = File::GetUserPath(D_CONFIG_IDX) + WIIMOTE_INI_NAME"WiimoteNew" ".ini"; |
| 240 | |
| 241 | IniFile inifile; |
| 242 | inifile.Load(ini_filename); |
| 243 | |
| 244 | for (unsigned int i=0; i<MAX_WIIMOTES; ++i) |
| 245 | { |
| 246 | std::string secname("Wiimote"); |
| 247 | secname += (char)('1' + i); |
| 248 | IniFile::Section& sec = *inifile.GetOrCreateSection(secname.c_str()); |
| 249 | |
| 250 | sec.Set("Source", (int)g_wiimote_sources[i]); |
| 251 | } |
| 252 | |
| 253 | std::string secname("BalanceBoard"); |
| 254 | IniFile::Section& sec = *inifile.GetOrCreateSection(secname.c_str()); |
| 255 | sec.Set("Source", (int)g_wiimote_sources[WIIMOTE_BALANCE_BOARD]); |
| 256 | |
| 257 | inifile.Save(ini_filename); |
| 258 | |
| 259 | event.Skip(); |
| 260 | } |
| 261 | |
| 262 | void WiimoteConfigDiag::Cancel(wxCommandEvent& event) |
| 263 | { |
| 264 | RevertSource(); |
| 265 | event.Skip(); |
| 266 | } |