dolphin/Source/Core/VideoCommon/NetPlayGolfUI.cpp
Lioncash 6fbbc2683e VideoCommon: Make use of fmt outside of shader generators
Migrates most of VideoCommon over to using fmt, with the exception being
the shader generator code. The shader generators are quite large and
have more corner cases to deal with in terms of conversion (shaders have
braces in them, so we need to make sure to escape them).

Because of the large amount of code that would need to be converted, the
conversion of VideoCommon will be in two parts:

- This change (which converts over the general case string formatting),
- A follow up change that will specifically deal with converting over
  the shader generators.
2019-11-23 16:00:45 -05:00

67 lines
1.7 KiB
C++

// Copyright 2019 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#include "VideoCommon/NetPlayGolfUI.h"
#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::shared_ptr<NetPlay::NetPlayClient> netplay_client)
: m_netplay_client{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();
}