NetPlayGolfUI.cpp 1.7 KB

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