summaryrefslogtreecommitdiff
path: root/Source/Core/VideoCommon/NetPlayGolfUI.cpp
blob: 87b866b348ec7515ab0a9795f2de71ff2d891b5a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Copyright 2019 Dolphin Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later

#include "VideoCommon/NetPlayGolfUI.h"

#include <utility>

#include <fmt/format.h>
#include <imgui.h>

#include "Core/NetPlayClient.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::weak_ptr<NetPlay::NetPlayClient> netplay_client)
    : m_netplay_client{std::move(netplay_client)}
{
}

NetPlayGolfUI::~NetPlayGolfUI() = default;

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(fmt::format("Give Control to {}", player->name).c_str()))
      {
        client->RequestGolfControl(player->pid);
      }
    }
  }

  ImGui::End();
}