Skip to content

Commit 26ace1a

Browse files
committed
Spectator checkbox functionality
1 parent c908fdb commit 26ace1a

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

Source/Core/Core/NetPlayServer.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -797,6 +797,47 @@ unsigned int NetPlayServer::OnData(sf::Packet& packet, Client& player)
797797
}
798798
break;
799799

800+
case MessageID::PadSpectator:
801+
{
802+
bool spectator;
803+
packet >> spectator;
804+
805+
auto padmap = GetPadMapping();
806+
807+
int player_port = -1;
808+
for (int i = 0; i < (int)padmap.size(); i++)
809+
{
810+
if (padmap[i] == player.pid)
811+
{
812+
player_port = i;
813+
break;
814+
}
815+
}
816+
817+
if (spectator)
818+
{
819+
if (player_port != -1)
820+
padmap[player_port] = 0;
821+
}
822+
else
823+
{
824+
bool assigned = false;
825+
for (int i = 0; i < (int)padmap.size(); i++)
826+
{
827+
if (padmap[i] == 0)
828+
{
829+
padmap[i] = player.pid;
830+
assigned = true;
831+
break;
832+
}
833+
}
834+
}
835+
836+
this->SetPadMapping(padmap);
837+
}
838+
break;
839+
840+
800841
case MessageID::PadData:
801842
{
802843
// if this is pad data from the last game still being received, ignore it

Source/Core/DolphinQt/NetPlay/NetPlayDialog.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,8 @@ void NetPlayDialog::ConnectWidgets()
405405
connect(m_start_button, &QPushButton::clicked, this, &NetPlayDialog::OnStart);
406406
connect(m_quit_button, &QPushButton::clicked, this, &NetPlayDialog::reject);
407407

408+
connect(m_is_spectator, &QCheckBox::toggled, this, &NetPlayDialog::IsSpectatorEnabled);
409+
408410
connect(m_game_button, &QPushButton::clicked, [this] {
409411
GameListDialog gld(m_game_list_model, this);
410412
SetQWidgetWindowDecorations(&gld);
@@ -493,6 +495,17 @@ void NetPlayDialog::OnChat()
493495
});
494496
}
495497

498+
void NetPlayDialog::IsSpectatorEnabled(bool enabled)
499+
{
500+
auto client = Settings::Instance().GetNetPlayClient();
501+
if (!client)
502+
return;
503+
sf::Packet packet;
504+
packet << static_cast<u8>(NetPlay::MessageID::PadSpectator);
505+
packet << enabled;
506+
client->SendAsync(std::move(packet));
507+
}
508+
496509
void NetPlayDialog::OnIndexAdded(bool success, const std::string error)
497510
{
498511
DisplayMessage(success ? tr("Successfully added to the NetPlay index") :

Source/Core/DolphinQt/NetPlay/NetPlayDialog.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ class NetPlayDialog : public QDialog, public NetPlay::NetPlayUI
8181
bool IsRecording() override;
8282
bool IsMusicOff() override;
8383
bool IsSpectator() override;
84+
void IsSpectatorEnabled(bool enabled);
8485
std::shared_ptr<const UICommon::GameFile>
8586
FindGameFile(const NetPlay::SyncIdentifier& sync_identifier,
8687
NetPlay::SyncIdentifierComparison* found = nullptr) override;

0 commit comments

Comments
 (0)