diff --git a/Source/Core/DolphinWX/Config/WiiConfigPane.cpp b/Source/Core/DolphinWX/Config/WiiConfigPane.cpp index dfbd600470..559bee6051 100644 --- a/Source/Core/DolphinWX/Config/WiiConfigPane.cpp +++ b/Source/Core/DolphinWX/Config/WiiConfigPane.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include "Core/ConfigManager.h" @@ -38,6 +39,9 @@ void WiiConfigPane::InitializeGUI() m_system_language_strings.Add(_("Traditional Chinese")); m_system_language_strings.Add(_("Korean")); + m_bt_sensor_bar_pos_strings.Add(_("Bottom")); + m_bt_sensor_bar_pos_strings.Add(_("Top")); + m_screensaver_checkbox = new wxCheckBox(this, wxID_ANY, _("Enable Screen Saver")); m_pal60_mode_checkbox = new wxCheckBox(this, wxID_ANY, _("Use PAL60 Mode (EuRGB60)")); m_aspect_ratio_choice = @@ -46,6 +50,15 @@ void WiiConfigPane::InitializeGUI() new wxChoice(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, m_system_language_strings); m_sd_card_checkbox = new wxCheckBox(this, wxID_ANY, _("Insert SD Card")); m_connect_keyboard_checkbox = new wxCheckBox(this, wxID_ANY, _("Connect USB Keyboard")); + m_bt_sensor_bar_pos = + new wxChoice(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, m_bt_sensor_bar_pos_strings); + m_bt_sensor_bar_sens = new wxSlider(this, wxID_ANY, 0, 0, 4); + m_bt_speaker_volume = new wxSlider(this, wxID_ANY, 0, 0, 127); + m_bt_wiimote_motor = new wxCheckBox(this, wxID_ANY, _("Wiimote Motor")); + + // With some GTK themes, no minimum size will be applied - so do this manually here + m_bt_sensor_bar_sens->SetMinSize(wxSize(100, -1)); + m_bt_speaker_volume->SetMinSize(wxSize(100, -1)); m_screensaver_checkbox->Bind(wxEVT_CHECKBOX, &WiiConfigPane::OnScreenSaverCheckBoxChanged, this); m_pal60_mode_checkbox->Bind(wxEVT_CHECKBOX, &WiiConfigPane::OnPAL60CheckBoxChanged, this); @@ -54,6 +67,10 @@ void WiiConfigPane::InitializeGUI() m_sd_card_checkbox->Bind(wxEVT_CHECKBOX, &WiiConfigPane::OnSDCardCheckBoxChanged, this); m_connect_keyboard_checkbox->Bind(wxEVT_CHECKBOX, &WiiConfigPane::OnConnectKeyboardCheckBoxChanged, this); + m_bt_sensor_bar_pos->Bind(wxEVT_CHOICE, &WiiConfigPane::OnSensorBarPosChanged, this); + m_bt_sensor_bar_sens->Bind(wxEVT_SLIDER, &WiiConfigPane::OnSensorBarSensChanged, this); + m_bt_speaker_volume->Bind(wxEVT_SLIDER, &WiiConfigPane::OnSpeakerVolumeChanged, this); + m_bt_wiimote_motor->Bind(wxEVT_CHECKBOX, &WiiConfigPane::OnWiimoteMotorChanged, this); m_screensaver_checkbox->SetToolTip(_("Dims the screen after five minutes of inactivity.")); m_pal60_mode_checkbox->SetToolTip(_("Sets the Wii display mode to 60Hz (480i) instead of 50Hz " @@ -77,6 +94,35 @@ void WiiConfigPane::InitializeGUI() misc_settings_grid_sizer->Add(m_system_language_choice, wxGBPosition(3, 1), wxDefaultSpan, wxALL, 5); + auto* const bt_sensor_bar_pos_sizer = new wxBoxSizer(wxHORIZONTAL); + bt_sensor_bar_pos_sizer->Add(new wxStaticText(this, wxID_ANY, _("Min")), 0, + wxALIGN_CENTER_VERTICAL); + bt_sensor_bar_pos_sizer->Add(m_bt_sensor_bar_sens); + bt_sensor_bar_pos_sizer->Add(new wxStaticText(this, wxID_ANY, _("Max")), 0, + wxALIGN_CENTER_VERTICAL); + + auto* const bt_speaker_volume_sizer = new wxBoxSizer(wxHORIZONTAL); + bt_speaker_volume_sizer->Add(new wxStaticText(this, wxID_ANY, _("Min")), 0, + wxALIGN_CENTER_VERTICAL); + bt_speaker_volume_sizer->Add(m_bt_speaker_volume); + bt_speaker_volume_sizer->Add(new wxStaticText(this, wxID_ANY, _("Max")), 0, + wxALIGN_CENTER_VERTICAL); + + wxGridBagSizer* const bt_settings_grid_sizer = new wxGridBagSizer(); + bt_settings_grid_sizer->Add(new wxStaticText(this, wxID_ANY, _("Sensor Bar Position:")), + wxGBPosition(0, 0), wxDefaultSpan, wxALIGN_CENTER_VERTICAL | wxALL, + 5); + bt_settings_grid_sizer->Add(m_bt_sensor_bar_pos, wxGBPosition(0, 1), wxDefaultSpan, wxALL, 5); + bt_settings_grid_sizer->Add(new wxStaticText(this, wxID_ANY, _("IR Sensitivity:")), + wxGBPosition(1, 0), wxDefaultSpan, wxALIGN_CENTER_VERTICAL | wxALL, + 5); + bt_settings_grid_sizer->Add(bt_sensor_bar_pos_sizer, wxGBPosition(1, 1), wxDefaultSpan, wxALL, 5); + bt_settings_grid_sizer->Add(new wxStaticText(this, wxID_ANY, _("Speaker Volume:")), + wxGBPosition(2, 0), wxDefaultSpan, wxALIGN_CENTER_VERTICAL | wxALL, + 5); + bt_settings_grid_sizer->Add(bt_speaker_volume_sizer, wxGBPosition(2, 1), wxDefaultSpan, wxALL, 5); + bt_settings_grid_sizer->Add(m_bt_wiimote_motor, wxGBPosition(3, 0), wxGBSpan(1, 2), wxALL, 5); + wxStaticBoxSizer* const misc_settings_static_sizer = new wxStaticBoxSizer(wxVERTICAL, this, _("Misc Settings")); misc_settings_static_sizer->Add(misc_settings_grid_sizer); @@ -86,9 +132,14 @@ void WiiConfigPane::InitializeGUI() device_settings_sizer->Add(m_sd_card_checkbox, 0, wxALL, 5); device_settings_sizer->Add(m_connect_keyboard_checkbox, 0, wxALL, 5); + auto* const bt_settings_static_sizer = + new wxStaticBoxSizer(wxVERTICAL, this, _("Wii Remote Settings")); + bt_settings_static_sizer->Add(bt_settings_grid_sizer); + wxBoxSizer* const main_sizer = new wxBoxSizer(wxVERTICAL); main_sizer->Add(misc_settings_static_sizer, 0, wxEXPAND | wxALL, 5); main_sizer->Add(device_settings_sizer, 0, wxEXPAND | wxALL, 5); + main_sizer->Add(bt_settings_static_sizer, 0, wxEXPAND | wxALL, 5); SetSizer(main_sizer); } @@ -102,6 +153,11 @@ void WiiConfigPane::LoadGUIValues() m_sd_card_checkbox->SetValue(SConfig::GetInstance().m_WiiSDCard); m_connect_keyboard_checkbox->SetValue(SConfig::GetInstance().m_WiiKeyboard); + + m_bt_sensor_bar_pos->SetSelection(SConfig::GetInstance().m_SYSCONF->GetData("BT.BAR")); + m_bt_sensor_bar_sens->SetValue(SConfig::GetInstance().m_SYSCONF->GetData("BT.SENS")); + m_bt_speaker_volume->SetValue(SConfig::GetInstance().m_SYSCONF->GetData("BT.SPKV")); + m_bt_wiimote_motor->SetValue(SConfig::GetInstance().m_SYSCONF->GetData("BT.MOT")); } void WiiConfigPane::RefreshGUI() @@ -112,6 +168,11 @@ void WiiConfigPane::RefreshGUI() m_pal60_mode_checkbox->Disable(); m_aspect_ratio_choice->Disable(); m_system_language_choice->Disable(); + + m_bt_sensor_bar_pos->Disable(); + m_bt_sensor_bar_sens->Disable(); + m_bt_speaker_volume->Disable(); + m_bt_wiimote_motor->Disable(); } } @@ -153,6 +214,26 @@ void WiiConfigPane::OnAspectRatioChoiceChanged(wxCommandEvent& event) SConfig::GetInstance().m_SYSCONF->SetData("IPL.AR", m_aspect_ratio_choice->GetSelection()); } +void WiiConfigPane::OnSensorBarPosChanged(wxCommandEvent& event) +{ + SConfig::GetInstance().m_SYSCONF->SetData("BT.BAR", event.GetInt()); +} + +void WiiConfigPane::OnSensorBarSensChanged(wxCommandEvent& event) +{ + SConfig::GetInstance().m_SYSCONF->SetData("BT.SENS", event.GetInt()); +} + +void WiiConfigPane::OnSpeakerVolumeChanged(wxCommandEvent& event) +{ + SConfig::GetInstance().m_SYSCONF->SetData("BT.SPKV", event.GetInt()); +} + +void WiiConfigPane::OnWiimoteMotorChanged(wxCommandEvent& event) +{ + SConfig::GetInstance().m_SYSCONF->SetData("BT.MOT", event.GetInt()); +} + // Change from IPL.LNG value to IPL.SADR country code. // http://wiibrew.org/wiki/Country_Codes u8 WiiConfigPane::GetSADRCountryCode(DiscIO::Language language) diff --git a/Source/Core/DolphinWX/Config/WiiConfigPane.h b/Source/Core/DolphinWX/Config/WiiConfigPane.h index 9d875aa0e4..ac482277fd 100644 --- a/Source/Core/DolphinWX/Config/WiiConfigPane.h +++ b/Source/Core/DolphinWX/Config/WiiConfigPane.h @@ -15,6 +15,7 @@ enum class Language; class wxCheckBox; class wxChoice; +class wxSlider; class WiiConfigPane final : public wxPanel { @@ -33,10 +34,16 @@ private: void OnSystemLanguageChoiceChanged(wxCommandEvent&); void OnAspectRatioChoiceChanged(wxCommandEvent&); + void OnSensorBarPosChanged(wxCommandEvent&); + void OnSensorBarSensChanged(wxCommandEvent&); + void OnSpeakerVolumeChanged(wxCommandEvent&); + void OnWiimoteMotorChanged(wxCommandEvent&); + static u8 GetSADRCountryCode(DiscIO::Language language); wxArrayString m_system_language_strings; wxArrayString m_aspect_ratio_strings; + wxArrayString m_bt_sensor_bar_pos_strings; wxCheckBox* m_screensaver_checkbox; wxCheckBox* m_pal60_mode_checkbox; @@ -44,4 +51,9 @@ private: wxCheckBox* m_connect_keyboard_checkbox; wxChoice* m_system_language_choice; wxChoice* m_aspect_ratio_choice; + + wxChoice* m_bt_sensor_bar_pos; + wxSlider* m_bt_sensor_bar_sens; + wxSlider* m_bt_speaker_volume; + wxCheckBox* m_bt_wiimote_motor; }; diff --git a/Source/Core/DolphinWX/ControllerConfigDiag.cpp b/Source/Core/DolphinWX/ControllerConfigDiag.cpp index e05250f3d8..58ddcbaf8a 100644 --- a/Source/Core/DolphinWX/ControllerConfigDiag.cpp +++ b/Source/Core/DolphinWX/ControllerConfigDiag.cpp @@ -2,14 +2,16 @@ // Licensed under GPLv2+ // Refer to the license.txt file included. -#include -#include #include #include + #include #include #include #include +#include +#include +#include #include #include #include @@ -17,7 +19,6 @@ #include "Common/CommonTypes.h" #include "Common/FileUtil.h" #include "Common/IniFile.h" -#include "Common/SysConf.h" #include "Core/ConfigManager.h" #include "Core/Core.h" #include "Core/HW/GCKeyboard.h" @@ -26,6 +27,8 @@ #include "Core/HW/Wiimote.h" #include "Core/HW/WiimoteReal/WiimoteReal.h" #include "Core/HotkeyManager.h" +#include "Core/IPC_HLE/WII_IPC_HLE.h" +#include "Core/IPC_HLE/WII_IPC_HLE_Device_usb_bt_real.h" #include "Core/Movie.h" #include "Core/NetPlayProto.h" #include "DolphinWX/Config/GCAdapterConfigDiag.h" @@ -57,10 +60,75 @@ ControllerConfigDiag::ControllerConfigDiag(wxWindow* const parent) Bind(wxEVT_CLOSE_WINDOW, &ControllerConfigDiag::OnClose, this); Bind(wxEVT_BUTTON, &ControllerConfigDiag::OnCloseButton, this, wxID_CLOSE); + UpdateUI(); + SetLayoutAdaptationMode(wxDIALOG_ADAPTATION_MODE_ENABLED); + SetLayoutAdaptationLevel(wxDIALOG_ADAPTATION_STANDARD_SIZER); SetSizerAndFit(main_sizer); Center(); - UpdateUI(); +} + +void ControllerConfigDiag::UpdateUI() +{ + const bool enable_bt_passthrough_mode = SConfig::GetInstance().m_bt_passthrough_enabled; + + for (unsigned int i = 0; i < MAX_WIIMOTES; ++i) + { + m_wiimote_labels[i]->Enable(!enable_bt_passthrough_mode); + m_wiimote_sources[i]->Enable(!enable_bt_passthrough_mode); + m_wiimote_configure_button[i]->Enable(!enable_bt_passthrough_mode); + + m_wiimote_sources[i]->Select(g_wiimote_sources[i]); + + const bool wii_game_started = + SConfig::GetInstance().bWii || Core::GetState() == Core::CORE_UNINITIALIZED; + if (Core::g_want_determinism || !wii_game_started) + m_wiimote_sources[i]->Disable(); + if (!wii_game_started || + (g_wiimote_sources[i] != WIIMOTE_SRC_EMU && g_wiimote_sources[i] != WIIMOTE_SRC_HYBRID)) + m_wiimote_configure_button[i]->Disable(); + } + + m_passthrough_sync_text->Enable(enable_bt_passthrough_mode); + m_passthrough_sync_btn->Enable(enable_bt_passthrough_mode); + m_passthrough_reset_text->Enable(enable_bt_passthrough_mode); + m_passthrough_reset_btn->Enable(enable_bt_passthrough_mode); + + m_balance_board_checkbox->Enable(!enable_bt_passthrough_mode); + m_enable_continuous_scanning->Enable(!enable_bt_passthrough_mode); + m_refresh_wm_button->Enable(!enable_bt_passthrough_mode); + m_unsupported_bt_text->Enable(!enable_bt_passthrough_mode); + m_enable_speaker_data->Enable(!enable_bt_passthrough_mode); + + // Disable some controls when emulation is running + if (Core::IsRunning()) + { + if (!SConfig::GetInstance().bWii || NetPlay::IsNetPlayRunning()) + { + m_passthrough_sync_text->Disable(); + m_passthrough_sync_btn->Disable(); + m_passthrough_reset_text->Disable(); + m_passthrough_reset_btn->Disable(); + + for (unsigned int i = 0; i < MAX_WIIMOTES; ++i) + { + m_wiimote_labels[i]->Disable(); + m_wiimote_sources[i]->Disable(); + } + m_balance_board_checkbox->Disable(); + } + + m_passthrough_bt_radio->Disable(); + m_emulated_bt_radio->Disable(); + + if (!SConfig::GetInstance().bWii) + { + m_enable_continuous_scanning->Disable(); + m_refresh_wm_button->Disable(); + m_unsupported_bt_text->Disable(); + m_enable_speaker_data->Disable(); + } + } } wxStaticBoxSizer* ControllerConfigDiag::CreateGamecubeSizer() @@ -68,6 +136,7 @@ wxStaticBoxSizer* ControllerConfigDiag::CreateGamecubeSizer() wxStaticBoxSizer* const gamecube_static_sizer = new wxStaticBoxSizer(wxVERTICAL, this, _("GameCube Controllers")); wxFlexGridSizer* const gamecube_flex_sizer = new wxFlexGridSizer(3, 5, 5); + gamecube_flex_sizer->AddGrowableCol(1); wxStaticText* pad_labels[4]; wxChoice* pad_type_choices[4]; @@ -80,7 +149,7 @@ wxStaticBoxSizer* ControllerConfigDiag::CreateGamecubeSizer() const wxWindowID button_id = wxWindow::NewControlId(); m_gc_port_from_config_id.emplace(button_id, i); m_gc_port_configure_button[i] = - new wxButton(this, button_id, _("Configure"), wxDefaultPosition, wxSize(100, 25)); + new wxButton(this, button_id, _("Configure"), wxDefaultPosition, wxSize(100, -1)); m_gc_port_configure_button[i]->Bind(wxEVT_BUTTON, &ControllerConfigDiag::OnGameCubeConfigButton, this); @@ -130,11 +199,11 @@ wxStaticBoxSizer* ControllerConfigDiag::CreateGamecubeSizer() // Add to the sizer gamecube_flex_sizer->Add(pad_labels[i], 0, wxALIGN_CENTER_VERTICAL); - gamecube_flex_sizer->Add(pad_type_choices[i], 0, wxALIGN_CENTER_VERTICAL); + gamecube_flex_sizer->Add(pad_type_choices[i], 0, wxALIGN_CENTER_VERTICAL | wxEXPAND); gamecube_flex_sizer->Add(m_gc_port_configure_button[i], 1, wxEXPAND); } - gamecube_static_sizer->Add(gamecube_flex_sizer, 1, wxEXPAND, 5); + gamecube_static_sizer->Add(gamecube_flex_sizer, 0, wxEXPAND | wxALL, 5); gamecube_static_sizer->AddSpacer(5); return gamecube_static_sizer; @@ -142,13 +211,76 @@ wxStaticBoxSizer* ControllerConfigDiag::CreateGamecubeSizer() wxStaticBoxSizer* ControllerConfigDiag::CreateWiimoteConfigSizer() { + auto* const box = new wxStaticBoxSizer(wxVERTICAL, this, _("Wiimotes")); + + m_passthrough_bt_radio = new wxRadioButton(this, wxID_ANY, _("Passthrough a Bluetooth adapter"), + wxDefaultPosition, wxDefaultSize, wxRB_GROUP); + m_passthrough_bt_radio->Bind(wxEVT_RADIOBUTTON, &ControllerConfigDiag::OnBluetoothModeChanged, + this); + box->Add(m_passthrough_bt_radio, 0, wxLEFT | wxRIGHT | wxTOP | wxEXPAND, 5); + box->Add(CreatePassthroughBTConfigSizer(), 0, wxALL | wxEXPAND, 5); + + box->AddSpacer(10); + + m_emulated_bt_radio = new wxRadioButton(this, wxID_ANY, _("Emulate the Wii's Bluetooth adapter")); + m_emulated_bt_radio->Bind(wxEVT_RADIOBUTTON, &ControllerConfigDiag::OnBluetoothModeChanged, this); + + box->Add(m_emulated_bt_radio, 0, wxALL | wxEXPAND, 5); + box->Add(CreateEmulatedBTConfigSizer(), 0, wxALL | wxEXPAND, 5); + box->AddSpacer(5); + + if (SConfig::GetInstance().m_bt_passthrough_enabled) + m_passthrough_bt_radio->SetValue(true); + else + m_emulated_bt_radio->SetValue(true); + + return box; +} + +wxBoxSizer* ControllerConfigDiag::CreatePassthroughBTConfigSizer() +{ + auto* const sizer = new wxBoxSizer(wxVERTICAL); + + m_passthrough_sync_text = new wxStaticText(this, wxID_ANY, _("Sync real Wiimotes and pair them")); + m_passthrough_sync_btn = + new wxButton(this, wxID_ANY, _("Sync"), wxDefaultPosition, wxSize(100, -1)); + m_passthrough_sync_btn->Bind(wxEVT_BUTTON, &ControllerConfigDiag::OnPassthroughScanButton, this); + + m_passthrough_reset_text = + new wxStaticText(this, wxID_ANY, _("Reset all saved Wiimote pairings")); + m_passthrough_reset_btn = + new wxButton(this, wxID_ANY, _("Reset"), wxDefaultPosition, wxSize(100, -1)); + m_passthrough_reset_btn->Bind(wxEVT_BUTTON, &ControllerConfigDiag::OnPassthroughResetButton, + this); + + auto* const sync_sizer = new wxBoxSizer(wxHORIZONTAL); + sync_sizer->Add(m_passthrough_sync_text, 0, wxALL | wxALIGN_CENTER_VERTICAL, 5); + sync_sizer->AddStretchSpacer(); + sync_sizer->Add(m_passthrough_sync_btn, 0, wxEXPAND); + auto* const reset_sizer = new wxBoxSizer(wxHORIZONTAL); + reset_sizer->Add(m_passthrough_reset_text, 0, wxALL | wxALIGN_CENTER_VERTICAL, 5); + reset_sizer->AddStretchSpacer(); + reset_sizer->Add(m_passthrough_reset_btn, 0, wxEXPAND); + + sizer->Add(sync_sizer, 0, wxEXPAND); + sizer->AddSpacer(5); + sizer->Add(reset_sizer, 0, wxEXPAND); + return sizer; +} + +wxBoxSizer* ControllerConfigDiag::CreateEmulatedBTConfigSizer() +{ + static const std::array src_choices = { + {_("None"), _("Emulated Wiimote"), _("Real Wiimote"), _("Hybrid Wiimote")}}; + + auto* const sizer = new wxBoxSizer(wxVERTICAL); + + // Source selector grid + auto* const grid = new wxFlexGridSizer(3, 5, 5); + grid->AddGrowableCol(1); + for (unsigned int i = 0; i < MAX_WIIMOTES; ++i) { - wxString wiimote_str = wxString::Format(_("Wiimote %i"), i + 1); - - static const std::array src_choices = { - {_("None"), _("Emulated Wiimote"), _("Real Wiimote"), _("Hybrid Wiimote")}}; - // reserve four ids, so that we can calculate the index from the ids later on // Stupid wx 2.8 doesn't support reserving sequential IDs, so we need to do that more // complicated.. @@ -158,234 +290,61 @@ wxStaticBoxSizer* ControllerConfigDiag::CreateWiimoteConfigSizer() int config_bt_id = wxWindow::NewControlId(); m_wiimote_index_from_config_id.emplace(config_bt_id, i); - m_wiimote_labels[i] = new wxStaticText(this, wxID_ANY, wiimote_str); + m_wiimote_labels[i] = + new wxStaticText(this, wxID_ANY, wxString::Format(_("Wiimote %i"), i + 1)); m_wiimote_sources[i] = new wxChoice(this, source_ctrl_id, wxDefaultPosition, wxDefaultSize, src_choices.size(), src_choices.data()); m_wiimote_sources[i]->Bind(wxEVT_CHOICE, &ControllerConfigDiag::OnWiimoteSourceChanged, this); + m_wiimote_configure_button[i] = - new wxButton(this, config_bt_id, _("Configure"), wxDefaultPosition, wxSize(80, 25)); + new wxButton(this, config_bt_id, _("Configure"), wxDefaultPosition, wxSize(100, -1)); m_wiimote_configure_button[i]->Bind(wxEVT_BUTTON, &ControllerConfigDiag::OnWiimoteConfigButton, this); - // Disable controller type selection for certain circumstances. - bool wii_game_started = - SConfig::GetInstance().bWii || Core::GetState() == Core::CORE_UNINITIALIZED; - if (Core::g_want_determinism || !wii_game_started) - m_wiimote_sources[i]->Disable(); - - m_wiimote_sources[i]->Select(g_wiimote_sources[i]); - if (!wii_game_started || - (g_wiimote_sources[i] != WIIMOTE_SRC_EMU && g_wiimote_sources[i] != WIIMOTE_SRC_HYBRID)) - m_wiimote_configure_button[i]->Disable(); + grid->Add(m_wiimote_labels[i], 0, wxALIGN_CENTER_VERTICAL); + grid->Add(m_wiimote_sources[i], 0, wxALIGN_CENTER_VERTICAL | wxEXPAND); + grid->Add(m_wiimote_configure_button[i], 1, wxEXPAND); } - // "Wiimotes" layout - wxStaticBoxSizer* const wiimote_group = new wxStaticBoxSizer(wxVERTICAL, this, _("Wiimotes")); - wxBoxSizer* const wiimote_control_section = new wxBoxSizer(wxHORIZONTAL); - wxFlexGridSizer* const wiimote_sizer = new wxFlexGridSizer(3, 5, 5); - for (unsigned int i = 0; i < 4; ++i) - { - wiimote_sizer->Add(m_wiimote_labels[i], 0, wxALIGN_CENTER_VERTICAL); - wiimote_sizer->Add(m_wiimote_sources[i], 0, wxALIGN_CENTER_VERTICAL); - wiimote_sizer->Add(m_wiimote_configure_button[i]); - } - wiimote_control_section->Add(wiimote_sizer, 1, wxEXPAND, 5); + sizer->Add(grid, 0, wxEXPAND); + sizer->AddSpacer(5); - // Disable some controls when emulation is running - if (Core::GetState() != Core::CORE_UNINITIALIZED && NetPlay::IsNetPlayRunning()) - { - for (int i = 0; i < 4; ++i) - { - m_wiimote_labels[i]->Disable(); - m_wiimote_sources[i]->Disable(); - } - } - - wiimote_group->Add(wiimote_control_section, 0, wxEXPAND); - wiimote_group->AddSpacer(5); - wiimote_group->Add(CreateBalanceBoardSizer(), 0, wxEXPAND); - wiimote_group->AddSpacer(5); - wiimote_group->Add(CreateRealWiimoteSizer(), 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM); - wiimote_group->AddSpacer(5); - m_general_wm_settings = CreateGeneralWiimoteSettingsSizer(); - wiimote_group->Add(m_general_wm_settings, 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM); - - return wiimote_group; -} - -wxStaticBoxSizer* ControllerConfigDiag::CreateBalanceBoardSizer() -{ - m_balance_board_group = new wxStaticBoxSizer(wxHORIZONTAL, this, _("Balance Board")); - wxFlexGridSizer* const bb_sizer = new wxFlexGridSizer(1, 5, 5); - int source_ctrl_id = wxWindow::NewControlId(); - - m_wiimote_index_from_choice_id.emplace(source_ctrl_id, WIIMOTE_BALANCE_BOARD); - - static const std::array src_choices = {{_("None"), _("Real Balance Board")}}; - - wxChoice* const bb_source = new wxChoice(this, source_ctrl_id, wxDefaultPosition, wxDefaultSize, - src_choices.size(), src_choices.data()); - bb_source->Bind(wxEVT_CHOICE, &ControllerConfigDiag::OnWiimoteSourceChanged, this); - - bb_source->Select(g_wiimote_sources[WIIMOTE_BALANCE_BOARD] ? 1 : 0); - - bb_sizer->Add(bb_source, 0, wxALIGN_CENTER_VERTICAL); - - m_balance_board_group->Add(bb_sizer, 1, wxEXPAND, 5); - - // Disable when emulation is running. - if (Core::GetState() != Core::CORE_UNINITIALIZED) - bb_source->Disable(); - - return m_balance_board_group; -} - -wxStaticBoxSizer* ControllerConfigDiag::CreateRealWiimoteSizer() -{ - auto* const real_wiimotes_group = new wxStaticBoxSizer(wxVERTICAL, this, _("Real Wiimotes")); + // Scanning controls + m_enable_continuous_scanning = new wxCheckBox(this, wxID_ANY, _("Continuous Scanning")); + m_enable_continuous_scanning->Bind(wxEVT_CHECKBOX, &ControllerConfigDiag::OnContinuousScanning, + this); + m_enable_continuous_scanning->SetValue(SConfig::GetInstance().m_WiimoteContinuousScanning); + m_refresh_wm_button = + new wxButton(this, wxID_ANY, _("Refresh"), wxDefaultPosition, wxSize(100, -1)); + m_refresh_wm_button->Bind(wxEVT_BUTTON, &ControllerConfigDiag::OnWiimoteRefreshButton, this); m_unsupported_bt_text = - new wxStaticText(this, wxID_ANY, _("A supported Bluetooth device could not be found.\n" - "You must manually connect your Wiimotes.")); - real_wiimotes_group->Add(m_unsupported_bt_text, 0, wxALIGN_CENTER | wxALL, 5); + new wxStaticText(this, wxID_ANY, _("A supported Bluetooth device could not be found,\n" + "so you must connect Wiimotes manually.")); m_unsupported_bt_text->Show(!WiimoteReal::g_wiimote_scanner.IsReady()); + sizer->Add(m_unsupported_bt_text, 0, wxALIGN_CENTER | wxALL, 5); - // Bluetooth adapter passthrough - m_bt_passthrough_text = new wxStaticText( - this, wxID_ANY, _("A Bluetooth adapter will be passed through to the game.\n" - "Only real Wiimotes will be usable.\n" - "Wiimotes can be synced to Dolphin with the sync hotkey.")); - real_wiimotes_group->Add(m_bt_passthrough_text, 0, wxALIGN_CENTER | wxALL, 5); + auto* const scanning_sizer = new wxBoxSizer(wxHORIZONTAL); + scanning_sizer->Add(m_enable_continuous_scanning, 0, wxALIGN_CENTER_VERTICAL); + scanning_sizer->AddStretchSpacer(); + scanning_sizer->Add(m_refresh_wm_button, 0, wxALL | wxEXPAND); + sizer->Add(scanning_sizer, 0, wxEXPAND); - auto* const enable_passthrough = - new wxCheckBox(this, wxID_ANY, _("Enable Bluetooth Adapter Passthrough")); - enable_passthrough->Bind(wxEVT_CHECKBOX, &ControllerConfigDiag::OnPassthroughMode, this); - enable_passthrough->SetValue(SConfig::GetInstance().m_bt_passthrough_enabled); - - auto* const wm_bt_sync_button = new wxButton(this, wxID_ANY, _("Sync Wiimotes")); - wm_bt_sync_button->Bind(wxEVT_BUTTON, &ControllerConfigDiag::OnPassthroughScanButton, this); - auto* const wm_bt_reset_button = new wxButton(this, wxID_ANY, _("Reset pairings")); - wm_bt_reset_button->Bind(wxEVT_BUTTON, &ControllerConfigDiag::OnPassthroughResetButton, this); - - if (Core::GetState() != Core::CORE_UNINITIALIZED) - { - enable_passthrough->Disable(); - if (!SConfig::GetInstance().bWii) - m_bt_passthrough_text->Disable(); - } - - if (!SConfig::GetInstance().bWii || Core::GetState() == Core::CORE_UNINITIALIZED) - { - wm_bt_sync_button->Disable(); - wm_bt_reset_button->Disable(); - } - - m_bt_passthrough_sizer = new wxBoxSizer(wxHORIZONTAL); - m_bt_passthrough_sizer->Add(wm_bt_sync_button, 0, wxALIGN_CENTER_VERTICAL); - m_bt_passthrough_sizer->Add(wm_bt_reset_button, 0, wxALL | wxALIGN_CENTER, 5); - - // Regular real Wiimotes controls - auto* const continuous_scanning = new wxCheckBox(this, wxID_ANY, _("Continuous Scanning")); - continuous_scanning->Bind(wxEVT_CHECKBOX, &ControllerConfigDiag::OnContinuousScanning, this); - continuous_scanning->SetValue(SConfig::GetInstance().m_WiimoteContinuousScanning); - auto* const wm_refresh_button = new wxButton(this, wxID_ANY, _("Refresh")); - wm_refresh_button->Bind(wxEVT_BUTTON, &ControllerConfigDiag::OnWiimoteRefreshButton, this); - - m_real_wiimotes_sizer = new wxBoxSizer(wxHORIZONTAL); - m_real_wiimotes_sizer->Add(continuous_scanning, 0, wxALIGN_CENTER_VERTICAL); - m_real_wiimotes_sizer->AddStretchSpacer(); - m_real_wiimotes_sizer->Add(wm_refresh_button, 0, wxALL | wxALIGN_CENTER, 5); - - real_wiimotes_group->Add(enable_passthrough, 0); - real_wiimotes_group->Add(m_bt_passthrough_sizer, 0, wxEXPAND); - real_wiimotes_group->Add(m_real_wiimotes_sizer, 0, wxEXPAND); - - return real_wiimotes_group; -} - -wxStaticBoxSizer* ControllerConfigDiag::CreateGeneralWiimoteSettingsSizer() -{ - 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); - wxSlider* const WiimoteSpkVolume = new wxSlider(this, wxID_ANY, 0, 0, 127); - wxCheckBox* const WiimoteMotor = new wxCheckBox(this, wxID_ANY, _("Wiimote Motor")); + // Balance Board + m_balance_board_checkbox = new wxCheckBox(this, wxID_ANY, _("Real Balance Board")); + m_balance_board_checkbox->Bind(wxEVT_CHECKBOX, &ControllerConfigDiag::OnBalanceBoardChanged, + this); + m_balance_board_checkbox->SetValue(g_wiimote_sources[WIIMOTE_BALANCE_BOARD] == WIIMOTE_SRC_REAL); + sizer->Add(m_balance_board_checkbox); + sizer->AddSpacer(5); + // Speaker data m_enable_speaker_data = new wxCheckBox(this, wxID_ANY, _("Enable Speaker Data")); m_enable_speaker_data->Bind(wxEVT_CHECKBOX, &ControllerConfigDiag::OnEnableSpeaker, this); m_enable_speaker_data->SetValue(SConfig::GetInstance().m_WiimoteEnableSpeaker); + sizer->Add(m_enable_speaker_data); - 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")); - - // With some GTK themes, no minimum size will be applied - so do this manually here - WiiSensBarSens->SetMinSize(wxSize(100, -1)); - WiimoteSpkVolume->SetMinSize(wxSize(100, -1)); - - // Disable some controls when emulation is running - 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(); - } - - // "General Settings" initialization - WiiSensBarPos->SetSelection(SConfig::GetInstance().m_SYSCONF->GetData("BT.BAR")); - WiiSensBarSens->SetValue(SConfig::GetInstance().m_SYSCONF->GetData("BT.SENS")); - WiimoteSpkVolume->SetValue(SConfig::GetInstance().m_SYSCONF->GetData("BT.SPKV")); - WiimoteMotor->SetValue(SConfig::GetInstance().m_SYSCONF->GetData("BT.MOT")); - - WiiSensBarPos->Bind(wxEVT_CHOICE, &ControllerConfigDiag::OnSensorBarPos, this); - WiiSensBarSens->Bind(wxEVT_SLIDER, &ControllerConfigDiag::OnSensorBarSensitivity, this); - WiimoteSpkVolume->Bind(wxEVT_SLIDER, &ControllerConfigDiag::OnSpeakerVolume, this); - WiimoteMotor->Bind(wxEVT_CHECKBOX, &ControllerConfigDiag::OnMotor, this); - - // "General Settings" layout - 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, 0, wxALIGN_CENTER_VERTICAL); - sensbarsens_sizer->Add(WiiSensBarSens); - sensbarsens_sizer->Add(WiiSensBarSensMaxText, 0, wxALIGN_CENTER_VERTICAL); - - wxBoxSizer* const spkvol_sizer = new wxBoxSizer(wxHORIZONTAL); - spkvol_sizer->Add(WiimoteSpkVolumeMinText, 0, wxALIGN_CENTER_VERTICAL); - spkvol_sizer->Add(WiimoteSpkVolume); - spkvol_sizer->Add(WiimoteSpkVolumeMaxText, 0, wxALIGN_CENTER_VERTICAL); - - choice_sizer->Add(WiiSensBarPosText, 0, wxALIGN_CENTER_VERTICAL); - choice_sizer->Add(WiiSensBarPos); - choice_sizer->Add(WiiSensBarSensText, 0, wxALIGN_CENTER_VERTICAL); - choice_sizer->Add(sensbarsens_sizer); - choice_sizer->Add(WiimoteSpkVolumeText, 0, wxALIGN_CENTER_VERTICAL); - choice_sizer->Add(spkvol_sizer); - - wxGridSizer* const general_wiimote_sizer = new wxGridSizer(1, 5, 5); - general_wiimote_sizer->Add(WiimoteMotor); - general_wiimote_sizer->Add(m_enable_speaker_data); - - general_sizer->Add(choice_sizer); - general_sizer->Add(general_wiimote_sizer); - - return general_sizer; + return sizer; } void ControllerConfigDiag::OnClose(wxCloseEvent& event) @@ -393,7 +352,6 @@ void ControllerConfigDiag::OnClose(wxCloseEvent& event) // Save all settings SConfig::GetInstance().SaveSettings(); SaveWiimoteSource(); - EndModal(wxID_OK); } @@ -525,11 +483,63 @@ void ControllerConfigDiag::OnWiimoteConfigButton(wxCommandEvent& ev) HotkeyManagerEmu::Enable(true); } +void ControllerConfigDiag::OnBluetoothModeChanged(wxCommandEvent& event) +{ + SConfig::GetInstance().m_bt_passthrough_enabled = m_passthrough_bt_radio->GetValue(); + WiimoteReal::Initialize(Wiimote::InitializeMode::DO_NOT_WAIT_FOR_WIIMOTES); + UpdateUI(); +} + +void ControllerConfigDiag::OnPassthroughScanButton(wxCommandEvent& event) +{ + if (!Core::IsRunning()) + { + wxMessageBox(_("A sync can only be triggered when a Wii game is running."), _("Sync Wiimotes"), + wxICON_WARNING); + return; + } + auto device = WII_IPC_HLE_Interface::GetDeviceByName("/dev/usb/oh1/57e/305"); + if (device != nullptr) + std::static_pointer_cast(device) + ->TriggerSyncButtonPressedEvent(); +} + +void ControllerConfigDiag::OnPassthroughResetButton(wxCommandEvent& event) +{ + if (!Core::IsRunning()) + { + wxMessageBox(_("Saved Wiimote pairings can only be reset when a Wii game is running."), + _("Reset Wiimote pairings"), wxICON_WARNING); + return; + } + auto device = WII_IPC_HLE_Interface::GetDeviceByName("/dev/usb/oh1/57e/305"); + if (device != nullptr) + std::static_pointer_cast(device) + ->TriggerSyncButtonHeldEvent(); +} + +void ControllerConfigDiag::OnBalanceBoardChanged(wxCommandEvent& event) +{ + WiimoteReal::ChangeWiimoteSource(WIIMOTE_BALANCE_BOARD, + event.IsChecked() ? WIIMOTE_SRC_REAL : WIIMOTE_SRC_NONE); +} + +void ControllerConfigDiag::OnContinuousScanning(wxCommandEvent& event) +{ + SConfig::GetInstance().m_WiimoteContinuousScanning = event.IsChecked(); + WiimoteReal::Initialize(Wiimote::InitializeMode::DO_NOT_WAIT_FOR_WIIMOTES); +} + void ControllerConfigDiag::OnWiimoteRefreshButton(wxCommandEvent&) { WiimoteReal::Refresh(); } +void ControllerConfigDiag::OnEnableSpeaker(wxCommandEvent& event) +{ + SConfig::GetInstance().m_WiimoteEnableSpeaker = event.IsChecked(); +} + void ControllerConfigDiag::SaveWiimoteSource() { std::string ini_filename = File::GetUserPath(D_CONFIG_IDX) + WIIMOTE_INI_NAME ".ini"; diff --git a/Source/Core/DolphinWX/ControllerConfigDiag.h b/Source/Core/DolphinWX/ControllerConfigDiag.h index f8b4ef3a2c..48a8e4b9fe 100644 --- a/Source/Core/DolphinWX/ControllerConfigDiag.h +++ b/Source/Core/DolphinWX/ControllerConfigDiag.h @@ -6,142 +6,74 @@ #include #include -#include -#include -#include -#include -#include -#include -#include -#include "Common/SysConf.h" +#include + #include "Core/ConfigManager.h" #include "Core/HW/Wiimote.h" -#include "Core/IPC_HLE/WII_IPC_HLE.h" -#include "Core/IPC_HLE/WII_IPC_HLE_Device_usb_bt_real.h" #include "InputCommon/GCAdapter.h" class InputConfig; +class wxCheckBox; +class wxChoice; +class wxRadioButton; +class wxStaticBoxSizer; +class wxStaticText; -class ControllerConfigDiag : public wxDialog +class ControllerConfigDiag final : public wxDialog { public: ControllerConfigDiag(wxWindow* const parent); private: - void OnSensorBarPos(wxCommandEvent& event) - { - SConfig::GetInstance().m_SYSCONF->SetData("BT.BAR", event.GetInt()); - event.Skip(); - } - - void OnSensorBarSensitivity(wxCommandEvent& event) - { - SConfig::GetInstance().m_SYSCONF->SetData("BT.SENS", event.GetInt()); - event.Skip(); - } - - void OnSpeakerVolume(wxCommandEvent& event) - { - SConfig::GetInstance().m_SYSCONF->SetData("BT.SPKV", event.GetInt()); - event.Skip(); - } - - void OnMotor(wxCommandEvent& event) - { - SConfig::GetInstance().m_SYSCONF->SetData("BT.MOT", event.GetInt()); - event.Skip(); - } - - void OnContinuousScanning(wxCommandEvent& event) - { - SConfig::GetInstance().m_WiimoteContinuousScanning = event.IsChecked(); - WiimoteReal::Initialize(Wiimote::InitializeMode::DO_NOT_WAIT_FOR_WIIMOTES); - event.Skip(); - } - - void OnPassthroughMode(wxCommandEvent& event) - { - SConfig::GetInstance().m_bt_passthrough_enabled = event.IsChecked(); - UpdateUI(); - } - - void OnPassthroughScanButton(wxCommandEvent& event) - { - auto device = WII_IPC_HLE_Interface::GetDeviceByName("/dev/usb/oh1/57e/305"); - if (device != nullptr) - std::static_pointer_cast(device) - ->TriggerSyncButtonPressedEvent(); - event.Skip(); - } - - void OnPassthroughResetButton(wxCommandEvent& event) - { - auto device = WII_IPC_HLE_Interface::GetDeviceByName("/dev/usb/oh1/57e/305"); - if (device != nullptr) - std::static_pointer_cast(device) - ->TriggerSyncButtonHeldEvent(); - event.Skip(); - } - - void OnEnableSpeaker(wxCommandEvent& event) - { - SConfig::GetInstance().m_WiimoteEnableSpeaker = event.IsChecked(); - event.Skip(); - } - - void UpdateUI() - { - const bool enable_bt_passthrough_mode = SConfig::GetInstance().m_bt_passthrough_enabled; - m_real_wiimotes_sizer->ShowItems(!enable_bt_passthrough_mode); - m_bt_passthrough_sizer->ShowItems(enable_bt_passthrough_mode); - m_unsupported_bt_text->Show(!enable_bt_passthrough_mode); - m_bt_passthrough_text->Show(enable_bt_passthrough_mode); - m_balance_board_group->ShowItems(!enable_bt_passthrough_mode); - m_enable_speaker_data->Enable(!enable_bt_passthrough_mode); - for (int i = 0; i < MAX_WIIMOTES; ++i) - { - m_wiimote_labels[i]->Enable(!enable_bt_passthrough_mode); - m_wiimote_sources[i]->Enable(!enable_bt_passthrough_mode); - m_wiimote_configure_button[i]->Enable(!enable_bt_passthrough_mode); - } - Layout(); - Fit(); - } + void UpdateUI(); wxStaticBoxSizer* CreateGamecubeSizer(); wxStaticBoxSizer* CreateWiimoteConfigSizer(); - wxStaticBoxSizer* CreateBalanceBoardSizer(); - wxStaticBoxSizer* CreateRealWiimoteSizer(); - wxStaticBoxSizer* CreateGeneralWiimoteSettingsSizer(); + wxBoxSizer* CreatePassthroughBTConfigSizer(); + wxBoxSizer* CreateEmulatedBTConfigSizer(); void OnClose(wxCloseEvent& event); void OnCloseButton(wxCommandEvent& event); - void OnGameCubePortChanged(wxCommandEvent& event); - void OnGameCubeConfigButton(wxCommandEvent& event); - void OnWiimoteSourceChanged(wxCommandEvent& event); void OnWiimoteConfigButton(wxCommandEvent& event); void OnWiimoteRefreshButton(wxCommandEvent& event); void SaveWiimoteSource(); + void OnGameCubePortChanged(wxCommandEvent& event); + void OnGameCubeConfigButton(wxCommandEvent& event); + + void OnBluetoothModeChanged(wxCommandEvent& event); + + void OnPassthroughScanButton(wxCommandEvent& event); + void OnPassthroughResetButton(wxCommandEvent& event); + void OnBalanceBoardChanged(wxCommandEvent& event); + void OnContinuousScanning(wxCommandEvent& event); + void OnEnableSpeaker(wxCommandEvent& event); + std::map m_gc_port_from_choice_id; std::map m_gc_port_from_config_id; std::array m_gc_port_configure_button; std::array m_gc_pad_type_strs; + wxRadioButton* m_passthrough_bt_radio; + wxRadioButton* m_emulated_bt_radio; + + wxStaticText* m_passthrough_sync_text; + wxButton* m_passthrough_sync_btn; + wxStaticText* m_passthrough_reset_text; + wxButton* m_passthrough_reset_btn; + std::map m_wiimote_index_from_choice_id; std::map m_wiimote_index_from_config_id; std::array m_wiimote_configure_button; + std::array m_wiimote_labels; + std::array m_wiimote_sources; + wxCheckBox* m_balance_board_checkbox; - std::array m_wiimote_labels; - std::array m_wiimote_sources; - wxBoxSizer* m_real_wiimotes_sizer; - wxBoxSizer* m_bt_passthrough_sizer; + wxCheckBox* m_enable_continuous_scanning; + wxButton* m_refresh_wm_button; wxStaticText* m_unsupported_bt_text; - wxStaticText* m_bt_passthrough_text; - wxStaticBoxSizer* m_general_wm_settings; - wxStaticBoxSizer* m_balance_board_group; wxCheckBox* m_enable_speaker_data; };