Merge pull request #7955 from Techjar/netplay-golf-mode

NetPlay golf mode
This commit is contained in:
spycrab
2019-04-05 17:25:23 +02:00
committed by GitHub
22 changed files with 522 additions and 138 deletions

View File

@ -55,6 +55,7 @@
#include "UICommon/UICommon.h"
#include "VideoCommon/NetPlayChatUI.h"
#include "VideoCommon/NetPlayGolfUI.h"
#include "VideoCommon/RenderBase.h"
#include "VideoCommon/VideoConfig.h"
@ -85,6 +86,8 @@ NetPlayDialog::NetPlayDialog(QWidget* parent)
const bool strict_settings_sync = Config::Get(Config::NETPLAY_STRICT_SETTINGS_SYNC);
const bool host_input_authority = Config::Get(Config::NETPLAY_HOST_INPUT_AUTHORITY);
const bool sync_all_wii_saves = Config::Get(Config::NETPLAY_SYNC_ALL_WII_SAVES);
const bool golf_mode = Config::Get(Config::NETPLAY_GOLF_MODE);
const bool golf_mode_overlay = Config::Get(Config::NETPLAY_GOLF_MODE_OVERLAY);
m_buffer_size_box->setValue(buffer_size);
m_save_sd_action->setChecked(write_save_sdcard_data);
@ -96,6 +99,8 @@ NetPlayDialog::NetPlayDialog(QWidget* parent)
m_strict_settings_sync_action->setChecked(strict_settings_sync);
m_host_input_authority_action->setChecked(host_input_authority);
m_sync_all_wii_saves_action->setChecked(sync_all_wii_saves);
m_golf_mode_action->setChecked(golf_mode);
m_golf_mode_overlay_action->setChecked(golf_mode_overlay);
ConnectWidgets();
@ -144,10 +149,14 @@ void NetPlayDialog::CreateMainLayout()
m_reduce_polling_rate_action->setCheckable(true);
m_host_input_authority_action = m_network_menu->addAction(tr("Host Input Authority"));
m_host_input_authority_action->setCheckable(true);
m_golf_mode_action = m_network_menu->addAction(tr("Golf Mode"));
m_golf_mode_action->setCheckable(true);
m_other_menu = m_menu_bar->addMenu(tr("Other"));
m_record_input_action = m_other_menu->addAction(tr("Record Inputs"));
m_record_input_action->setCheckable(true);
m_golf_mode_overlay_action = m_other_menu->addAction(tr("Show Golf Mode Overlay"));
m_golf_mode_overlay_action->setCheckable(true);
m_game_button->setDefault(false);
m_game_button->setAutoDefault(false);
@ -300,16 +309,18 @@ void NetPlayDialog::ConnectWidgets()
auto client = Settings::Instance().GetNetPlayClient();
auto server = Settings::Instance().GetNetPlayServer();
if (server)
if (server && !m_host_input_authority)
server->AdjustPadBufferSize(value);
else
client->AdjustPadBufferSize(value);
});
connect(m_host_input_authority_action, &QAction::toggled, [](bool checked) {
connect(m_host_input_authority_action, &QAction::toggled, this, [=](bool checked) {
auto server = Settings::Instance().GetNetPlayServer();
if (server)
server->SetHostInputAuthority(checked);
m_golf_mode_action->setEnabled(checked);
});
connect(m_start_button, &QPushButton::clicked, this, &NetPlayDialog::OnStart);
@ -355,6 +366,8 @@ void NetPlayDialog::ConnectWidgets()
connect(m_strict_settings_sync_action, &QAction::toggled, this, &NetPlayDialog::SaveSettings);
connect(m_host_input_authority_action, &QAction::toggled, this, &NetPlayDialog::SaveSettings);
connect(m_sync_all_wii_saves_action, &QAction::toggled, this, &NetPlayDialog::SaveSettings);
connect(m_golf_mode_action, &QAction::toggled, this, &NetPlayDialog::SaveSettings);
connect(m_golf_mode_overlay_action, &QAction::toggled, this, &NetPlayDialog::SaveSettings);
}
void NetPlayDialog::SendMessage(const std::string& msg)
@ -482,6 +495,7 @@ void NetPlayDialog::OnStart()
settings.m_SyncCodes = m_sync_codes_action->isChecked();
settings.m_SyncAllWiiSaves =
m_sync_all_wii_saves_action->isChecked() && m_sync_save_data_action->isChecked();
settings.m_GolfMode = m_golf_mode_action->isChecked();
// Unload GameINI to restore things to normal
Config::RemoveLayer(Config::LayerType::GlobalGame);
@ -539,8 +553,6 @@ void NetPlayDialog::show(std::string nickname, bool use_traversal)
m_game_button->setEnabled(is_hosting);
m_kick_button->setEnabled(false);
m_buffer_label->setText(is_hosting ? tr("Buffer:") : tr("Max Buffer:"));
QDialog::show();
UpdateGUI();
}
@ -817,6 +829,7 @@ void NetPlayDialog::SetOptionsEnabled(bool enabled)
m_strict_settings_sync_action->setEnabled(enabled);
m_host_input_authority_action->setEnabled(enabled);
m_sync_all_wii_saves_action->setEnabled(enabled && m_sync_save_data_action->isChecked());
m_golf_mode_action->setEnabled(enabled && m_host_input_authority_action->isChecked());
}
m_record_input_action->setEnabled(enabled);
@ -829,6 +842,11 @@ void NetPlayDialog::OnMsgStartGame()
g_netplay_chat_ui =
std::make_unique<NetPlayChatUI>([this](const std::string& message) { SendMessage(message); });
if (Settings::Instance().GetNetPlayClient()->GetNetSettings().m_GolfMode)
{
g_netplay_golf_ui = std::make_unique<NetPlayGolfUI>(Settings::Instance().GetNetPlayClient());
}
QueueOnObject(this, [this] {
auto client = Settings::Instance().GetNetPlayClient();
@ -841,6 +859,7 @@ void NetPlayDialog::OnMsgStartGame()
void NetPlayDialog::OnMsgStopGame()
{
g_netplay_chat_ui.reset();
g_netplay_golf_ui.reset();
QueueOnObject(this, [this] { UpdateDiscordPresence(); });
}
@ -857,9 +876,8 @@ void NetPlayDialog::OnPadBufferChanged(u32 buffer)
const QSignalBlocker blocker(m_buffer_size_box);
m_buffer_size_box->setValue(buffer);
});
DisplayMessage(m_host_input_authority && !IsHosting() ?
tr("Max buffer size changed to %1").arg(buffer) :
tr("Buffer size changed to %1").arg(buffer),
DisplayMessage(m_host_input_authority ? tr("Max buffer size changed to %1").arg(buffer) :
tr("Buffer size changed to %1").arg(buffer),
"darkcyan");
m_buffer_size = static_cast<int>(buffer);
@ -867,6 +885,10 @@ void NetPlayDialog::OnPadBufferChanged(u32 buffer)
void NetPlayDialog::OnHostInputAuthorityChanged(bool enabled)
{
m_host_input_authority = enabled;
DisplayMessage(enabled ? tr("Host input authority enabled") : tr("Host input authority disabled"),
"");
QueueOnObject(this, [this, enabled] {
const bool is_hosting = IsHosting();
const bool enable_buffer = is_hosting != enabled;
@ -878,8 +900,9 @@ void NetPlayDialog::OnHostInputAuthorityChanged(bool enabled)
m_buffer_size_box->setHidden(false);
m_buffer_label->setHidden(false);
QSignalBlocker blocker(m_host_input_authority_action);
const QSignalBlocker blocker(m_host_input_authority_action);
m_host_input_authority_action->setChecked(enabled);
m_golf_mode_action->setEnabled(enabled);
}
else
{
@ -887,15 +910,12 @@ void NetPlayDialog::OnHostInputAuthorityChanged(bool enabled)
m_buffer_label->setEnabled(true);
m_buffer_size_box->setHidden(!enable_buffer);
m_buffer_label->setHidden(!enable_buffer);
if (enabled)
m_buffer_size_box->setValue(Config::Get(Config::NETPLAY_CLIENT_BUFFER_SIZE));
}
});
DisplayMessage(enabled ? tr("Host input authority enabled") : tr("Host input authority disabled"),
"");
m_host_input_authority = enabled;
m_buffer_label->setText(enabled ? tr("Max Buffer:") : tr("Buffer:"));
if (enabled)
m_buffer_size_box->setValue(Config::Get(Config::NETPLAY_CLIENT_BUFFER_SIZE));
});
}
void NetPlayDialog::OnDesync(u32 frame, const std::string& player)
@ -958,6 +978,20 @@ void NetPlayDialog::OnSaveDataSyncFailure()
QueueOnObject(this, [this] { SetOptionsEnabled(true); });
}
void NetPlayDialog::OnGolferChanged(const bool is_golfer, const std::string& golfer_name)
{
if (m_host_input_authority)
{
QueueOnObject(this, [this, is_golfer] {
m_buffer_size_box->setEnabled(!is_golfer);
m_buffer_label->setEnabled(!is_golfer);
});
}
if (!golfer_name.empty())
DisplayMessage(tr("%1 is now golfing").arg(QString::fromStdString(golfer_name)), "");
}
bool NetPlayDialog::IsRecording()
{
std::optional<bool> is_recording = RunOnObject(m_record_input_action, &QAction::isChecked);
@ -1002,14 +1036,10 @@ void NetPlayDialog::SaveSettings()
Config::ConfigChangeCallbackGuard config_guard;
if (m_host_input_authority)
{
if (!IsHosting())
Config::SetBase(Config::NETPLAY_CLIENT_BUFFER_SIZE, m_buffer_size_box->value());
}
Config::SetBase(Config::NETPLAY_CLIENT_BUFFER_SIZE, m_buffer_size_box->value());
else
{
Config::SetBase(Config::NETPLAY_BUFFER_SIZE, m_buffer_size_box->value());
}
Config::SetBase(Config::NETPLAY_WRITE_SAVE_SDCARD_DATA, m_save_sd_action->isChecked());
Config::SetBase(Config::NETPLAY_LOAD_WII_SAVE, m_load_wii_action->isChecked());
Config::SetBase(Config::NETPLAY_SYNC_SAVES, m_sync_save_data_action->isChecked());
@ -1019,6 +1049,8 @@ void NetPlayDialog::SaveSettings()
Config::SetBase(Config::NETPLAY_STRICT_SETTINGS_SYNC, m_strict_settings_sync_action->isChecked());
Config::SetBase(Config::NETPLAY_HOST_INPUT_AUTHORITY, m_host_input_authority_action->isChecked());
Config::SetBase(Config::NETPLAY_SYNC_ALL_WII_SAVES, m_sync_all_wii_saves_action->isChecked());
Config::SetBase(Config::NETPLAY_GOLF_MODE, m_golf_mode_action->isChecked());
Config::SetBase(Config::NETPLAY_GOLF_MODE_OVERLAY, m_golf_mode_overlay_action->isChecked());
}
void NetPlayDialog::ShowMD5Dialog(const std::string& file_identifier)