From ae4b89441c11e927fad3ab63c304602b69b6bfe6 Mon Sep 17 00:00:00 2001 From: "Admiral H. Curtiss" Date: Sun, 25 Sep 2022 04:22:30 +0200 Subject: [PATCH] Qt/WiimoteControllersWidget: Disable remote Wiimote configuration during netplay. --- Source/Core/Core/NetPlayClient.cpp | 25 ++++++++++++++++--- Source/Core/Core/NetPlayClient.h | 1 + Source/Core/Core/NetPlayProto.h | 1 + .../Config/WiimoteControllersWidget.cpp | 7 ++++-- 4 files changed, 29 insertions(+), 5 deletions(-) diff --git a/Source/Core/Core/NetPlayClient.cpp b/Source/Core/Core/NetPlayClient.cpp index 825ff7777a..013d7e4fe5 100644 --- a/Source/Core/Core/NetPlayClient.cpp +++ b/Source/Core/Core/NetPlayClient.cpp @@ -2321,11 +2321,22 @@ bool NetPlayClient::IsFirstInGamePad(int ingame_pad) const [](auto mapping) { return mapping > 0; }); } +static int CountLocalPads(const PadMappingArray& pad_map, const PlayerId& local_player_pid) +{ + return static_cast( + std::count_if(pad_map.begin(), pad_map.end(), [&local_player_pid](const auto& mapping) { + return mapping == local_player_pid; + })); +} + int NetPlayClient::NumLocalPads() const { - return static_cast(std::count_if(m_pad_map.begin(), m_pad_map.end(), [this](auto mapping) { - return mapping == m_local_player->pid; - })); + return CountLocalPads(m_pad_map, m_local_player->pid); +} + +int NetPlayClient::NumLocalWiimotes() const +{ + return CountLocalPads(m_wiimote_map, m_local_player->pid); } static int InGameToLocal(int ingame_pad, const PadMappingArray& pad_map, PlayerId local_player_pid) @@ -2653,6 +2664,14 @@ PadDetails GetPadDetails(int pad_num) return res; } +int NumLocalWiimotes() +{ + std::lock_guard lk(crit_netplay_client); + if (netplay_client) + return netplay_client->NumLocalWiimotes(); + return 0; +} + void NetPlay_Enable(NetPlayClient* const np) { std::lock_guard lk(crit_netplay_client); diff --git a/Source/Core/Core/NetPlayClient.h b/Source/Core/Core/NetPlayClient.h index 262f726d3d..dbd1095204 100644 --- a/Source/Core/Core/NetPlayClient.h +++ b/Source/Core/Core/NetPlayClient.h @@ -151,6 +151,7 @@ public: bool IsFirstInGamePad(int ingame_pad) const; int NumLocalPads() const; + int NumLocalWiimotes() const; int InGamePadToLocalPad(int ingame_pad) const; int LocalPadToInGamePad(int local_pad) const; diff --git a/Source/Core/Core/NetPlayProto.h b/Source/Core/Core/NetPlayProto.h index c3fb8cc0cc..f7137f66d8 100644 --- a/Source/Core/Core/NetPlayProto.h +++ b/Source/Core/Core/NetPlayProto.h @@ -256,4 +256,5 @@ void SetSIPollBatching(bool state); void SendPowerButtonEvent(); std::string GetGBASavePath(int pad_num); PadDetails GetPadDetails(int pad_num); +int NumLocalWiimotes(); } // namespace NetPlay diff --git a/Source/Core/DolphinQt/Config/WiimoteControllersWidget.cpp b/Source/Core/DolphinQt/Config/WiimoteControllersWidget.cpp index 61c14163fc..21b0fc1b33 100644 --- a/Source/Core/DolphinQt/Config/WiimoteControllersWidget.cpp +++ b/Source/Core/DolphinQt/Config/WiimoteControllersWidget.cpp @@ -287,7 +287,8 @@ void WiimoteControllersWidget::LoadSettings(Core::State state) const bool running_gc = running && !SConfig::GetInstance().bWii; const bool enable_passthrough = m_wiimote_passthrough->isChecked() && !running_gc; const bool enable_emu_bt = !m_wiimote_passthrough->isChecked() && !running_gc; - const bool running_netplay = running && NetPlay::IsNetPlayRunning(); + const bool is_netplay = NetPlay::IsNetPlayRunning(); + const bool running_netplay = running && is_netplay; m_wiimote_sync->setEnabled(enable_passthrough); m_wiimote_reset->setEnabled(enable_passthrough); @@ -295,13 +296,15 @@ void WiimoteControllersWidget::LoadSettings(Core::State state) for (auto* pt_label : m_wiimote_pt_labels) pt_label->setEnabled(enable_passthrough); + const int num_local_wiimotes = is_netplay ? NetPlay::NumLocalWiimotes() : 4; for (size_t i = 0; i < m_wiimote_groups.size(); i++) { m_wiimote_labels[i]->setEnabled(enable_emu_bt); m_wiimote_boxes[i]->setEnabled(enable_emu_bt && !running_netplay); const bool is_emu_wiimote = m_wiimote_boxes[i]->currentIndex() == 1; - m_wiimote_buttons[i]->setEnabled(enable_emu_bt && is_emu_wiimote); + m_wiimote_buttons[i]->setEnabled(enable_emu_bt && is_emu_wiimote && + static_cast(i) < num_local_wiimotes); } m_wiimote_real_balance_board->setEnabled(enable_emu_bt && !running_netplay);