hud_system.cpp 2.15 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include "hud_system.hpp"

#include <imgui_internal.h>
#include <glm/vec2.hpp>
#include <glm/vec4.hpp>

#include <string>
#include <unordered_map>

namespace phase_shifter::ui {

	using namespace mirrage::gui::literals;

	namespace {
		constexpr auto hud_height = 100;
16
		constexpr auto count_down = 300;
17
18
	}

19
20
21
	Hud_system::Hud_system(mirrage::gui::Gui&            gui,
	                       mirrage::ecs::Entity_manager& ecs,
	                       const phase_shifter::gameplay::Beat_system& beat_system)
22
23
	  : _gui(gui)
	  , _ecs(ecs)
24
25
	  , _timeLeft(count_down)
	  , _beat_system(beat_system)
26
27
28
	{
	}

29
30
	void Hud_system::update(mirrage::util::Time dt) {
		_timeLeft -= dt;
31
32
33
34
35
36
37
38
39
40
41
	}

	void Hud_system::draw()
	{
		auto viewport = _gui.viewport();
		auto font     = _gui.find_font("default"_strid);

		if(font.is_some())
			ImGui::PushFont(font.get_or_throw());

		ImGui::PositionNextWindow(glm::vec2(viewport.z, hud_height),
42
43
		                          ImGui::WindowPosition_X::left,
		                          ImGui::WindowPosition_Y::top);
44
45
		if(ImGui::Begin("hud",
		             nullptr,
46
		             ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoBackground)) {
47
			
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
			ImGui::Text("%.2f", _timeLeft.value());

			ImGui::End();
		}

		ImGui::PositionNextWindow(glm::vec2(viewport.z, hud_height),
		                          ImGui::WindowPosition_X::center,
		                          ImGui::WindowPosition_Y::bottom);
		if(ImGui::Begin("beat",
		                nullptr,
		                ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoBackground)) {
			/*
			ImVec2 p = ImGui::GetCursorScreenPos();
			ImGui::BeginChild("Line", {200, 100}, true);
			ImDrawList* drawList = ImGui::GetWindowDrawList();
			drawList->AddLine(p, {p.x, p.y + 50}, 0xFF0000FF, 10);
			ImGui::EndChild();
			*/
			auto time_to_beat = _beat_system.beat_state().time_to_beat;
			ImVec4 col          = time_to_beat < 0.05f ? ImVec4(1, 0, 0, 1) : ImVec4(1,1,1,1);
			ImGui::TextColored(col, "%.2f", time_to_beat);
69
70
71
72
73
74
75
76
77

			ImGui::End();
		}

		if(font.is_some())
			ImGui::PopFont();
	}

} // namespace phase_shifter::ui