Commit 7103ba0d authored by Kevin Balz's avatar Kevin Balz
Browse files

Display countdown and time to beat

parent d0bd4460
Pipeline #3228 passed with stage
in 1 minute and 54 seconds
......@@ -30,7 +30,7 @@ namespace phase_shifter {
, _movement_system(std::make_unique<gameplay::Movement_system>(_entities, *_beat_system))
, _input_system(std::make_unique<input::Input_system>(engine.bus(), _entities))
, _attachment_system(std::make_unique<helper::Attachment_system>(_entities))
, _hud_system(std::make_unique<ui::Hud_system>(engine.gui(), _entities))
, _hud_system(std::make_unique<ui::Hud_system>(engine.gui(), _entities, *_beat_system))
{
_entities.register_component_type<ecs::components::Transform_comp>();
......
......@@ -13,16 +13,21 @@ namespace phase_shifter::ui {
namespace {
constexpr auto hud_height = 100;
constexpr auto count_down = 300;
}
Hud_system::Hud_system(mirrage::gui::Gui& gui, mirrage::ecs::Entity_manager& ecs)
Hud_system::Hud_system(mirrage::gui::Gui& gui,
mirrage::ecs::Entity_manager& ecs,
const phase_shifter::gameplay::Beat_system& beat_system)
: _gui(gui)
, _ecs(ecs)
, _timeLeft(count_down)
, _beat_system(beat_system)
{
}
void Hud_system::update(mirrage::util::Time dt)
{
void Hud_system::update(mirrage::util::Time dt) {
_timeLeft -= dt;
}
void Hud_system::draw()
......@@ -33,20 +38,37 @@ namespace phase_shifter::ui {
if(font.is_some())
ImGui::PushFont(font.get_or_throw());
ImGui::PushStyleColor(ImGuiCol_WindowBg, "#333333FF"_imcolor.Value);
ImGui::PositionNextWindow(glm::vec2(viewport.z, hud_height),
ImGui::WindowPosition_X::center,
ImGui::WindowPosition_Y::bottom);
ImGui::WindowPosition_X::left,
ImGui::WindowPosition_Y::top);
if(ImGui::Begin("hud",
nullptr,
ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize)) {
ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoBackground)) {
ImGui::Text("TODO");
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);
ImGui::End();
}
ImGui::PopStyleColor();
if(font.is_some())
ImGui::PopFont();
......
......@@ -6,13 +6,16 @@
#include <unordered_map>
#include <memory>
#include "../gameplay/beat_system.hpp"
namespace phase_shifter::ui {
class Hud_system {
public:
Hud_system(mirrage::gui::Gui& gui, mirrage::ecs::Entity_manager& ecs);
Hud_system(mirrage::gui::Gui& gui,
mirrage::ecs::Entity_manager& ecs,
const phase_shifter::gameplay::Beat_system& beat_system);
void update(mirrage::util::Time dt);
void draw();
......@@ -20,6 +23,8 @@ namespace phase_shifter::ui {
private:
mirrage::gui::Gui& _gui;
mirrage::ecs::Entity_manager& _ecs;
mirrage::util::Time _timeLeft;
const phase_shifter::gameplay::Beat_system& _beat_system;
};
} // namespace phase_shifter::ui
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment