Add imgui golf mode overlay

This commit is contained in:
Techjar 2019-04-02 17:13:42 -04:00
parent 1a12876330
commit 6c393f9ff4
13 changed files with 156 additions and 10 deletions

View File

@ -56,5 +56,7 @@ const ConfigInfo<bool> NETPLAY_HOST_INPUT_AUTHORITY{{System::Main, "NetPlay", "H
const ConfigInfo<bool> NETPLAY_SYNC_ALL_WII_SAVES{{System::Main, "NetPlay", "SyncAllWiiSaves"},
false};
const ConfigInfo<bool> NETPLAY_GOLF_MODE{{System::Main, "NetPlay", "GolfMode"}, false};
const ConfigInfo<bool> NETPLAY_GOLF_MODE_OVERLAY{{System::Main, "NetPlay", "GolfModeOverlay"},
true};
} // namespace Config

View File

@ -46,5 +46,6 @@ extern const ConfigInfo<bool> NETPLAY_STRICT_SETTINGS_SYNC;
extern const ConfigInfo<bool> NETPLAY_HOST_INPUT_AUTHORITY;
extern const ConfigInfo<bool> NETPLAY_SYNC_ALL_WII_SAVES;
extern const ConfigInfo<bool> NETPLAY_GOLF_MODE;
extern const ConfigInfo<bool> NETPLAY_GOLF_MODE_OVERLAY;
} // namespace Config

View File

@ -2108,15 +2108,19 @@ void NetPlayClient::RequestGolfControl()
RequestGolfControl(m_local_player->pid);
}
// called from ---GUI--- thread
std::string NetPlayClient::GetCurrentGolfer()
{
std::lock_guard<std::recursive_mutex> lkp(m_crit.players);
if (m_players.count(m_current_golfer))
return m_players[m_current_golfer].name;
return "";
}
// called from ---GUI--- thread
bool NetPlayClient::LocalPlayerHasControllerMapped() const
{
const auto mapping_matches_player_id = [this](const PlayerId& mapping) {
return mapping == m_local_player->pid;
};
return std::any_of(m_pad_map.begin(), m_pad_map.end(), mapping_matches_player_id) ||
std::any_of(m_wiimote_map.begin(), m_wiimote_map.end(), mapping_matches_player_id);
return PlayerHasControllerMapped(m_local_player->pid);
}
bool NetPlayClient::IsFirstInGamePad(int ingame_pad) const
@ -2169,6 +2173,19 @@ int NetPlayClient::LocalPadToInGamePad(int local_pad) const
return ingame_pad;
}
bool NetPlayClient::PlayerHasControllerMapped(const PlayerId pid) const
{
const auto mapping_matches_player_id = [pid](const PlayerId& mapping) { return mapping == pid; };
return std::any_of(m_pad_map.begin(), m_pad_map.end(), mapping_matches_player_id) ||
std::any_of(m_wiimote_map.begin(), m_wiimote_map.end(), mapping_matches_player_id);
}
bool NetPlayClient::IsLocalPlayer(const PlayerId pid) const
{
return pid == m_local_player->pid;
}
void NetPlayClient::SendTimeBase()
{
std::lock_guard<std::mutex> lk(crit_netplay_client);

View File

@ -114,6 +114,7 @@ public:
void SendPowerButtonEvent();
void RequestGolfControl(PlayerId pid);
void RequestGolfControl();
std::string GetCurrentGolfer();
// Send and receive pads values
bool WiimoteUpdate(int _number, u8* data, const u8 size, u8 reporting_mode);
@ -131,6 +132,10 @@ public:
int InGamePadToLocalPad(int ingame_pad) const;
int LocalPadToInGamePad(int localPad) const;
bool PlayerHasControllerMapped(PlayerId pid) const;
bool LocalPlayerHasControllerMapped() const;
bool IsLocalPlayer(PlayerId pid) const;
static void SendTimeBase();
bool DoAllPlayersHaveGame();
@ -209,8 +214,6 @@ private:
Failure
};
bool LocalPlayerHasControllerMapped() const;
void SendStartGamePacket();
void SendStopGamePacket();

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"
@ -86,6 +87,7 @@ NetPlayDialog::NetPlayDialog(QWidget* parent)
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);
@ -98,6 +100,7 @@ NetPlayDialog::NetPlayDialog(QWidget* parent)
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();
@ -152,6 +155,8 @@ void NetPlayDialog::CreateMainLayout()
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);
@ -362,6 +367,7 @@ void NetPlayDialog::ConnectWidgets()
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)
@ -836,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();
@ -848,6 +859,7 @@ void NetPlayDialog::OnMsgStartGame()
void NetPlayDialog::OnMsgStopGame()
{
g_netplay_chat_ui.reset();
g_netplay_golf_ui.reset();
QueueOnObject(this, [this] { UpdateDiscordPresence(); });
}
@ -1038,6 +1050,7 @@ void NetPlayDialog::SaveSettings()
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)

View File

@ -133,6 +133,7 @@ private:
QAction* m_host_input_authority_action;
QAction* m_sync_all_wii_saves_action;
QAction* m_golf_mode_action;
QAction* m_golf_mode_overlay_action;
QPushButton* m_quit_button;
QSplitter* m_splitter;

View File

@ -28,6 +28,7 @@
#include "InputCommon/InputConfig.h"
#include "VideoCommon/NetPlayChatUI.h"
#include "VideoCommon/NetPlayGolfUI.h"
#include "VideoCommon/RenderBase.h"
Settings::Settings()
@ -298,6 +299,7 @@ void Settings::ResetNetPlayClient(NetPlay::NetPlayClient* client)
m_client.reset(client);
g_netplay_chat_ui.reset();
g_netplay_golf_ui.reset();
}
std::shared_ptr<NetPlay::NetPlayServer> Settings::GetNetPlayServer()

View File

@ -23,6 +23,7 @@ add_library(videocommon
IndexGenerator.cpp
LightingShaderGen.cpp
NetPlayChatUI.cpp
NetPlayGolfUI.cpp
OnScreenDisplay.cpp
OpcodeDecoding.cpp
PerfQueryBase.cpp

View File

@ -0,0 +1,66 @@
// Copyright 2019 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#include "Common/StringUtil.h"
#include "Core/NetPlayClient.h"
#include "VideoCommon/NetPlayGolfUI.h"
#include <imgui.h>
constexpr float DEFAULT_WINDOW_WIDTH = 220.0f;
constexpr float DEFAULT_WINDOW_HEIGHT = 45.0f;
std::unique_ptr<NetPlayGolfUI> g_netplay_golf_ui;
NetPlayGolfUI::NetPlayGolfUI(std::shared_ptr<NetPlay::NetPlayClient> netplay_client)
{
m_netplay_client = netplay_client;
}
void NetPlayGolfUI::Display()
{
auto client = m_netplay_client.lock();
if (!client)
return;
const float scale = ImGui::GetIO().DisplayFramebufferScale.x;
ImGui::SetNextWindowPos(ImVec2((20.0f + DEFAULT_WINDOW_WIDTH) * scale, 10.0f * scale),
ImGuiCond_FirstUseEver);
ImGui::SetNextWindowSizeConstraints(
ImVec2(DEFAULT_WINDOW_WIDTH * scale, DEFAULT_WINDOW_HEIGHT * scale),
ImGui::GetIO().DisplaySize);
// TODO: Translate these strings once imgui has multilingual fonts
if (!ImGui::Begin("Golf Mode", nullptr, ImGuiWindowFlags_None))
{
ImGui::End();
return;
}
ImGui::Text("Current Golfer: %s", client->GetCurrentGolfer().c_str());
if (client->LocalPlayerHasControllerMapped())
{
if (ImGui::Button("Take Control"))
{
client->RequestGolfControl();
}
for (auto player : client->GetPlayers())
{
if (client->IsLocalPlayer(player->pid) || !client->PlayerHasControllerMapped(player->pid))
continue;
if (ImGui::Button(StringFromFormat("Give Control to %s", player->name.c_str()).c_str()))
{
client->RequestGolfControl(player->pid);
}
}
}
ImGui::End();
}

View File

@ -0,0 +1,27 @@
// Copyright 2019 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#pragma once
#include <memory>
#include <string>
namespace NetPlay
{
class NetPlayClient;
}
class NetPlayGolfUI
{
public:
explicit NetPlayGolfUI(std::shared_ptr<NetPlay::NetPlayClient> netplay_client);
~NetPlayGolfUI() = default;
void Display();
private:
std::weak_ptr<NetPlay::NetPlayClient> m_netplay_client;
};
extern std::unique_ptr<NetPlayGolfUI> g_netplay_golf_ui;

View File

@ -37,6 +37,7 @@
#include "Common/Timer.h"
#include "Core/Analytics.h"
#include "Core/Config/NetplaySettings.h"
#include "Core/Config/SYSCONFSettings.h"
#include "Core/ConfigManager.h"
#include "Core/Core.h"
@ -58,6 +59,7 @@
#include "VideoCommon/FramebufferManager.h"
#include "VideoCommon/ImageWrite.h"
#include "VideoCommon/NetPlayChatUI.h"
#include "VideoCommon/NetPlayGolfUI.h"
#include "VideoCommon/OnScreenDisplay.h"
#include "VideoCommon/PixelEngine.h"
#include "VideoCommon/PixelShaderManager.h"
@ -532,6 +534,9 @@ void Renderer::DrawDebugText()
if (g_ActiveConfig.bShowNetPlayMessages && g_netplay_chat_ui)
g_netplay_chat_ui->Display();
if (Config::Get(Config::NETPLAY_GOLF_MODE_OVERLAY) && g_netplay_golf_ui)
g_netplay_golf_ui->Display();
if (g_ActiveConfig.bOverlayProjStats)
Statistics::DisplayProj();
}

View File

@ -58,6 +58,7 @@
<ClCompile Include="ImageWrite.cpp" />
<ClCompile Include="IndexGenerator.cpp" />
<ClCompile Include="NetPlayChatUI.cpp" />
<ClCompile Include="NetPlayGolfUI.cpp" />
<ClCompile Include="OnScreenDisplay.cpp" />
<ClCompile Include="OpcodeDecoding.cpp" />
<ClCompile Include="PerfQueryBase.cpp" />
@ -122,6 +123,7 @@
<ClInclude Include="FramebufferShaderGen.h" />
<ClInclude Include="GXPipelineTypes.h" />
<ClInclude Include="NetPlayChatUI.h" />
<ClInclude Include="NetPlayGolfUI.h" />
<ClInclude Include="ShaderCache.h" />
<ClInclude Include="UberShaderCommon.h" />
<ClInclude Include="UberShaderPixel.h" />
@ -192,4 +194,4 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
</Project>

View File

@ -200,6 +200,9 @@
<ClCompile Include="NetPlayChatUI.cpp">
<Filter>Util</Filter>
</ClCompile>
<ClCompile Include="NetPlayGolfUI.cpp">
<Filter>Util</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="CommandProcessor.h" />
@ -392,8 +395,11 @@
<ClInclude Include="NetPlayChatUI.h">
<Filter>Util</Filter>
</ClInclude>
<ClInclude Include="NetPlayGolfUI.h">
<Filter>Util</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Text Include="CMakeLists.txt" />
</ItemGroup>
</Project>
</Project>