Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Ranked Button
Creates a check box which toggles ranked mode. The check box is disabled when a game starts and is reenabled when the game ends. The chat also indicates when ranked is enabled.
  • Loading branch information
LittleCoaks committed Aug 19, 2021
1 parent 6e7edf7 commit f36396d
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 3 deletions.
13 changes: 13 additions & 0 deletions Source/Core/Core/NetPlayClient.cpp
Expand Up @@ -577,6 +577,13 @@ unsigned int NetPlayClient::OnData(sf::Packet& packet)
}
break;

case NP_MSG_RANKED_BOX:
{
packet >>m_ranked_client;
m_dialog->OnRankedEnabled(m_ranked_client);
}
break;

case NP_MSG_PAD_BUFFER:
{
u32 size = 0;
Expand Down Expand Up @@ -2403,6 +2410,12 @@ void NetPlayClient::AdjustPadBufferSize(const unsigned int size)
m_dialog->OnPadBufferChanged(size);
}

void NetPlayClient::AdjustRankedBox(const unsigned int is_ranked)
{
m_ranked_client = is_ranked;
m_dialog->OnRankedEnabled(is_ranked);
}

SyncIdentifier NetPlayClient::GetSDCardIdentifier()
{
return SyncIdentifier{{}, "sd", {}, {}, {}, {}};
Expand Down
4 changes: 4 additions & 0 deletions Source/Core/Core/NetPlayClient.h
Expand Up @@ -58,6 +58,7 @@ class NetPlayUI
virtual void OnTraversalStateChanged(TraversalClient::State state) = 0;
virtual void OnGameStartAborted() = 0;
virtual void OnGolferChanged(bool is_golfer, const std::string& golfer_name) = 0;
virtual void OnRankedEnabled(unsigned int is_ranked) = 0;

virtual bool IsRecording() = 0;
virtual std::shared_ptr<const UICommon::GameFile>
Expand Down Expand Up @@ -146,6 +147,7 @@ class NetPlayClient : public TraversalClientClient
const PadMappingArray& GetWiimoteMapping() const;

void AdjustPadBufferSize(unsigned int size);
void AdjustRankedBox(unsigned int is_ranked);

static SyncIdentifier GetSDCardIdentifier();

Expand Down Expand Up @@ -186,6 +188,8 @@ class NetPlayClient : public TraversalClientClient
Common::Flag m_is_running{false};
Common::Flag m_do_loop{true};

unsigned int m_ranked_client = 0;

// In non-host input authority mode, this is how many packets each client should
// try to keep in-flight to the other clients. In host input authority mode, this is how
// many incoming input packets need to be queued up before the client starts
Expand Down
2 changes: 2 additions & 0 deletions Source/Core/Core/NetPlayProto.h
Expand Up @@ -135,6 +135,8 @@ enum
NP_MSG_CHUNKED_DATA_COMPLETE = 0x44,
NP_MSG_CHUNKED_DATA_ABORT = 0x45,

NP_MSG_RANKED_BOX = 0x5F,

NP_MSG_PAD_DATA = 0x60,
NP_MSG_PAD_MAPPING = 0x61,
NP_MSG_PAD_BUFFER = 0x62,
Expand Down
15 changes: 15 additions & 0 deletions Source/Core/Core/NetPlayServer.cpp
Expand Up @@ -665,6 +665,21 @@ void NetPlayServer::AdjustPadBufferSize(unsigned int size)
}
}

void NetPlayServer::AdjustRankedBox(unsigned int is_ranked)
{
if (m_is_running)
return;
m_current_ranked_value = is_ranked;
std::lock_guard lkg(m_crit.game);

// tell clients to change ranked box
sf::Packet spac;
spac << static_cast<MessageId>(NP_MSG_RANKED_BOX);
spac << static_cast<u32>(m_current_ranked_value);

SendAsyncToClients(std::move(spac));
}

void NetPlayServer::SetHostInputAuthority(const bool enable)
{
std::lock_guard lkg(m_crit.game);
Expand Down
4 changes: 4 additions & 0 deletions Source/Core/Core/NetPlayServer.h
Expand Up @@ -67,6 +67,8 @@ class NetPlayServer : public TraversalClientClient
void AdjustPadBufferSize(unsigned int size);
void SetHostInputAuthority(bool enable);

void AdjustRankedBox(unsigned int is_ranked);

void KickPlayer(PlayerId player);

u16 GetPort() const;
Expand Down Expand Up @@ -168,6 +170,8 @@ class NetPlayServer : public TraversalClientClient
PlayerId m_current_golfer = 1;
PlayerId m_pending_golfer = 0;

int m_current_ranked_value = 0;

std::map<PlayerId, Client> m_players;

std::unordered_map<u32, std::vector<std::pair<PlayerId, u64>>> m_timebase_by_frame;
Expand Down
38 changes: 35 additions & 3 deletions Source/Core/DolphinQt/NetPlay/NetPlayDialog.cpp
Expand Up @@ -6,6 +6,7 @@
#include <QAction>
#include <QActionGroup>
#include <QApplication>
#include <QCheckBox>
#include <QClipboard>
#include <QComboBox>
#include <QFileDialog>
Expand Down Expand Up @@ -105,7 +106,10 @@ void NetPlayDialog::CreateMainLayout()
m_quit_button = new QPushButton(tr("Quit"));
m_splitter = new QSplitter(Qt::Horizontal);
m_menu_bar = new QMenuBar(this);
m_ranked_box = new QCheckBox(tr("Ranked"));

m_ranked_box->setChecked(false);
m_current_ranked_value = 0;
m_data_menu = m_menu_bar->addMenu(tr("Data"));
m_data_menu->setToolTipsVisible(true);
m_write_save_data_action = m_data_menu->addAction(tr("Write Save Data"));
Expand Down Expand Up @@ -196,8 +200,9 @@ void NetPlayDialog::CreateMainLayout()
options_widget->addWidget(m_start_button, 0, 0, Qt::AlignVCenter);
options_widget->addWidget(m_buffer_label, 0, 1, Qt::AlignVCenter);
options_widget->addWidget(m_buffer_size_box, 0, 2, Qt::AlignVCenter);
options_widget->addWidget(m_quit_button, 0, 3, Qt::AlignVCenter | Qt::AlignRight);
options_widget->addWidget(m_quit_button, 0, 4, Qt::AlignVCenter | Qt::AlignRight);
options_widget->setColumnStretch(3, 1000);
options_widget->addWidget(m_ranked_box, 0, 3, Qt::AlignVCenter);

m_main_layout->addLayout(options_widget, 2, 0, 1, -1, Qt::AlignRight);
m_main_layout->setRowStretch(1, 1000);
Expand Down Expand Up @@ -307,6 +312,13 @@ void NetPlayDialog::ConnectWidgets()
client->AdjustPadBufferSize(value);
});

connect(m_ranked_box, qOverload<int>(&QCheckBox::stateChanged), [this](int is_ranked) {
//if (is_ranked == m_current_ranked_value)
//return;
auto server = Settings::Instance().GetNetPlayServer();
server->AdjustRankedBox(is_ranked);
});

const auto hia_function = [this](bool enable) {
if (m_host_input_authority != enable)
{
Expand Down Expand Up @@ -358,6 +370,7 @@ void NetPlayDialog::ConnectWidgets()

// SaveSettings() - Save Hosting-Dialog Settings

connect(m_ranked_box, &QCheckBox::toggled, this, &NetPlayDialog::SaveSettings);
connect(m_buffer_size_box, qOverload<int>(&QSpinBox::valueChanged), this,
&NetPlayDialog::SaveSettings);
connect(m_write_save_data_action, &QAction::toggled, this, &NetPlayDialog::SaveSettings);
Expand Down Expand Up @@ -397,6 +410,20 @@ void NetPlayDialog::OnChat()
});
}


void NetPlayDialog::OnRankedEnabled(unsigned int is_ranked)
{
if (is_ranked != 0)
{
DisplayMessage(tr("Ranked Mode Enabled"), "green");
}
else
{
DisplayMessage(tr("Ranked Mode Disabled"), "red");
}
}


void NetPlayDialog::OnIndexAdded(bool success, const std::string error)
{
DisplayMessage(success ? tr("Successfully added to the NetPlay index") :
Expand Down Expand Up @@ -462,6 +489,7 @@ void NetPlayDialog::show(std::string nickname, bool use_traversal)

bool is_hosting = Settings::Instance().GetNetPlayServer() != nullptr;


if (is_hosting)
{
if (use_traversal)
Expand Down Expand Up @@ -800,9 +828,11 @@ void NetPlayDialog::OnMsgStartGame()
if (client)
{
if (auto game = FindGameFile(m_current_game_identifier))
{
client->StartGame(game->GetFilePath());
else
PanicAlertFmtT("Selected game doesn't exist in game list!");
m_ranked_box->setEnabled(false);
}
else PanicAlertFmtT("Selected game doesn't exist in game list!");
}
UpdateDiscordPresence();
});
Expand All @@ -813,6 +843,7 @@ void NetPlayDialog::OnMsgStopGame()
g_netplay_chat_ui.reset();
g_netplay_golf_ui.reset();
QueueOnObject(this, [this] { UpdateDiscordPresence(); });
m_ranked_box->setEnabled(true);
}

void NetPlayDialog::OnMsgPowerButton()
Expand Down Expand Up @@ -1046,6 +1077,7 @@ void NetPlayDialog::LoadSettings()
const bool golf_mode_overlay = Config::Get(Config::NETPLAY_GOLF_MODE_OVERLAY);
const bool hide_remote_gbas = Config::Get(Config::NETPLAY_HIDE_REMOTE_GBAS);

m_ranked_box->setChecked(false);
m_buffer_size_box->setValue(buffer_size);
m_write_save_data_action->setChecked(write_save_data);
m_load_wii_action->setChecked(load_wii_save);
Expand Down
4 changes: 4 additions & 0 deletions Source/Core/DolphinQt/NetPlay/NetPlayDialog.h
Expand Up @@ -62,6 +62,8 @@ class NetPlayDialog : public QDialog, public NetPlay::NetPlayUI
void OnGameStartAborted() override;
void OnGolferChanged(bool is_golfer, const std::string& golfer_name) override;

void OnRankedEnabled(unsigned int is_ranked) override;

void OnIndexAdded(bool success, const std::string error) override;
void OnIndexRefreshFailed(const std::string error) override;

Expand Down Expand Up @@ -144,6 +146,7 @@ class NetPlayDialog : public QDialog, public NetPlay::NetPlayUI
QAction* m_hide_remote_gbas_action;
QPushButton* m_quit_button;
QSplitter* m_splitter;
QCheckBox* m_ranked_box;
QActionGroup* m_network_mode_group;

QGridLayout* m_main_layout;
Expand All @@ -162,4 +165,5 @@ class NetPlayDialog : public QDialog, public NetPlay::NetPlayUI
int m_player_count = 0;
int m_old_player_count = 0;
bool m_host_input_authority = false;
int m_current_ranked_value = 0;
};

0 comments on commit f36396d

Please sign in to comment.