Debian Codegraph @

Source/Core/VideoCommon/NetPlayGolfUI.cpp

raw symbols SCIP
1 // Copyright 2019 Dolphin Emulator Project
2 // SPDX-License-Identifier: GPL-2.0-or-later
3
4 #include "VideoCommon/NetPlayGolfUI.h"
5
6 #include <utility>
7
8 #include <fmt/format.h>
9 #include <imgui.h>
10
11 #include "Core/NetPlayClient.h"
12
13 constexpr float DEFAULT_WINDOW_WIDTH = 220.0f;
14 constexpr float DEFAULT_WINDOW_HEIGHT = 45.0f;
15
16 std::unique_ptr<NetPlayGolfUI> g_netplay_golf_ui;
17
18 NetPlayGolfUI::NetPlayGolfUI(std::weak_ptr<NetPlay::NetPlayClient> netplay_client)
19 : m_netplay_client{std::move(netplay_client)}
20 {
21 }
22
23 NetPlayGolfUI::~NetPlayGolfUI() = default;
24
25 void NetPlayGolfUI::Display()
26 {
27 auto client = m_netplay_client.lock();
28 if (!client)
29 return;
30
31 const float scale = ImGui::GetIO().DisplayFramebufferScale.x;
32
33 ImGui::SetNextWindowPos(ImVec2((20.0f + DEFAULT_WINDOW_WIDTH) * scale, 10.0f * scale),
34 ImGuiCond_FirstUseEver);
35 ImGui::SetNextWindowSizeConstraints(
36 ImVec2(DEFAULT_WINDOW_WIDTH * scale, DEFAULT_WINDOW_HEIGHT * scale),
37 ImGui::GetIO().DisplaySize);
38
39 // TODO: Translate these strings once imgui has multilingual fonts
40 if (!ImGui::Begin("Golf Mode", nullptr, ImGuiWindowFlags_None))
41 {
42 ImGui::End();
43 return;
44 }
45
46 ImGui::Text("Current Golfer: %s", client->GetCurrentGolfer().c_str());
47
48 if (client->LocalPlayerHasControllerMapped())
49 {
50 if (ImGui::Button("Take Control"))
51 {
52 client->RequestGolfControl();
53 }
54
55 for (auto player : client->GetPlayers())
56 {
57 if (client->IsLocalPlayer(player->pid) || !client->PlayerHasControllerMapped(player->pid))
58 continue;
59
60 if (ImGui::Button(fmt::format("Give Control to {}", player->name).c_str()))
61 {
62 client->RequestGolfControl(player->pid);
63 }
64 }
65 }
66
67 ImGui::End();
68 }