Skip to content

Commit

Permalink
moved race box to top menubar
Browse files Browse the repository at this point in the history
  • Loading branch information
ohlidalp authored and Petr Ohlídal committed Sep 8, 2021
1 parent d369fce commit 5472275
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 40 deletions.
40 changes: 0 additions & 40 deletions source/main/gui/panels/GUI_DirectionArrow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,46 +74,6 @@ void GUI::DirectionArrow::Update(RoR::GfxActor* player_vehicle)

// Update arrow direction
m_node->lookAt(data.simbuf_dir_arrow_target, Ogre::Node::TS_WORLD, Ogre::Vector3::UNIT_Y);

// Update distance
float distance = 0.0f;
if (player_vehicle != nullptr && player_vehicle->GetSimDataBuffer().simbuf_live_local)
{
distance = player_vehicle->GetSimDataBuffer().simbuf_pos.distance(data.simbuf_dir_arrow_target);
}
else
{
distance = data.simbuf_character_pos.distance(data.simbuf_dir_arrow_target);
}

GUIManager::GuiTheme const& theme = App::GetGuiManager()->GetTheme();

ImGuiWindowFlags flags = ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoScrollbar;
std::string text_a = data.simbuf_dir_arrow_text;
std::string text_b = fmt::format("{:.1f} {}", distance, _LC("DirectionArrow", "meter"));
const float content_width = ImGui::CalcTextSize(text_a.c_str()).x + ImGui::CalcTextSize(text_b.c_str()).x;
ImGui::SetNextWindowContentWidth(content_width);
ImGui::SetNextWindowPos(ImVec2((ImGui::GetIO().DisplaySize.x/2.f) - (content_width / 2.f), theme.screen_edge_padding.y));
ImGui::PushStyleColor(ImGuiCol_WindowBg, theme.semitransparent_window_bg);
ImGui::Begin("Arrow", nullptr, flags);
ImGui::Text(text_a.c_str());
ImGui::SameLine();

if (distance < 50)
{
ImGui::TextColored(theme.success_text_color,"%s", text_b.c_str());
}
else if (distance > 200)
{
ImGui::TextColored(theme.warning_text_color,"%s", text_b.c_str());
}
else
{
ImGui::TextColored(theme.value_blue_text_color,"%s", text_b.c_str());
}

ImGui::End();
ImGui::PopStyleColor(1); // WindowBg
}
else
{
Expand Down
36 changes: 36 additions & 0 deletions source/main/gui/panels/GUI_TopMenubar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "ActorManager.h"
#include "CameraManager.h"
#include "GameContext.h"
#include "GfxScene.h"
#include "GUIManager.h"
#include "GUIUtils.h"
#include "GUI_MainSelector.h"
Expand Down Expand Up @@ -818,9 +819,12 @@ void TopMenubar::DrawActorListSinglePlayer()
void TopMenubar::DrawSpecialStateBox(float top_offset)
{
std::string special_text;
std::string special_text_b;
ImVec4 special_color = ImGui::GetStyle().Colors[ImGuiCol_Text]; // Regular color
ImVec4 special_color_b = ImVec4(0,0,0,0);
float content_width = 0.f;
bool replay_box = false;
bool race_box = false;

// Gather state info
if (App::GetGameContext()->GetActorManager()->IsSimulationPaused() && !App::GetGuiManager()->IsGuiHidden())
Expand All @@ -846,6 +850,33 @@ void TopMenubar::DrawSpecialStateBox(float top_offset)
replay_box = true;
special_text = _LC("TopMenubar", "Replay");
}
else if (App::GetGfxScene()->GetSimDataBuffer().simbuf_dir_arrow_visible)
{
race_box = true;

// Calculate distance
GfxScene::SimBuffer& data = App::GetGfxScene()->GetSimDataBuffer();
GUIManager::GuiTheme const& theme = App::GetGuiManager()->GetTheme();
float distance = 0.0f;
Actor* player_actor = App::GetGfxScene()->GetSimDataBuffer().simbuf_player_actor;
if (player_actor != nullptr &&
player_actor->GetGfxActor()->GetSimDataBuffer().simbuf_live_local)
{
distance = player_actor->GetGfxActor()->GetSimDataBuffer().simbuf_pos.distance(data.simbuf_dir_arrow_target);
}
else
{
distance = data.simbuf_character_pos.distance(data.simbuf_dir_arrow_target);
}

// format text
special_text = App::GetGfxScene()->GetSimDataBuffer().simbuf_dir_arrow_text;
special_text_b = fmt::format("{:.1f} {}", distance, _LC("DirectionArrow", "meter"));
content_width = ImGui::CalcTextSize(special_text.c_str()).x + ImGui::CalcTextSize(special_text_b.c_str()).x;
special_color_b = (distance < 50)
? theme.success_text_color
: ((distance > 200) ? theme.warning_text_color : theme.value_blue_text_color);
}

// Draw box if needed
if (!special_text.empty())
Expand Down Expand Up @@ -885,6 +916,11 @@ void TopMenubar::DrawSpecialStateBox(float top_offset)
ImGui::TextDisabled("%s: %s", _LC("TopMenubar", "Time"), str);

}
else if (race_box)
{
ImGui::SameLine();
ImGui::TextColored(special_color_b,"%s", special_text_b.c_str());
}
ImGui::End();
}
ImGui::PopStyleColor(1); // WindowBg
Expand Down

0 comments on commit 5472275

Please # to comment.