2019-04-02 15:13:42 -06:00
|
|
|
// Copyright 2019 Dolphin Emulator Project
|
2021-07-04 19:22:19 -06:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2019-04-02 15:13:42 -06:00
|
|
|
|
|
|
|
#include "VideoCommon/NetPlayGolfUI.h"
|
|
|
|
|
2019-11-22 15:10:41 -07:00
|
|
|
#include <fmt/format.h>
|
2019-04-02 15:13:42 -06:00
|
|
|
#include <imgui.h>
|
|
|
|
|
2019-11-22 15:10:41 -07:00
|
|
|
#include "Core/NetPlayClient.h"
|
|
|
|
|
2019-04-02 15:13:42 -06:00
|
|
|
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)
|
2019-05-29 04:16:28 -06:00
|
|
|
: m_netplay_client{netplay_client}
|
2019-04-02 15:13:42 -06:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-05-29 04:17:24 -06:00
|
|
|
NetPlayGolfUI::~NetPlayGolfUI() = default;
|
|
|
|
|
2019-04-02 15:13:42 -06:00
|
|
|
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;
|
|
|
|
|
2019-11-22 15:10:41 -07:00
|
|
|
if (ImGui::Button(fmt::format("Give Control to {}", player->name).c_str()))
|
2019-04-02 15:13:42 -06:00
|
|
|
{
|
|
|
|
client->RequestGolfControl(player->pid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ImGui::End();
|
|
|
|
}
|