Commit 306b27cd authored by Kevin Balz's avatar Kevin Balz
Browse files

Merge branch 'feature/10-ui-hud' into 'develop'

Feature/10 ui hud

See merge request !6
parents 10133b11 38bd1e7c
Pipeline #3233 failed with stage
in 1 minute and 20 seconds
...@@ -17,7 +17,7 @@ namespace phase_shifter::gameplay { ...@@ -17,7 +17,7 @@ namespace phase_shifter::gameplay {
_acc = 0; _acc = 0;
} }
_state = {beat, _acc, beat_time - _acc}; _state = {beat, _acc, beat_time - _acc, beat_time};
} }
} // namespace phase_shifter::gameplay } // namespace phase_shifter::gameplay
...@@ -32,7 +32,7 @@ namespace phase_shifter { ...@@ -32,7 +32,7 @@ namespace phase_shifter {
, _camera_system(std::make_unique<gameplay::Camera_system>(_entities)) , _camera_system(std::make_unique<gameplay::Camera_system>(_entities))
, _input_system(std::make_unique<input::Input_system>(engine.bus(), _entities)) , _input_system(std::make_unique<input::Input_system>(engine.bus(), _entities))
, _attachment_system(std::make_unique<helper::Attachment_system>(_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>(); _entities.register_component_type<ecs::components::Transform_comp>();
......
...@@ -13,16 +13,28 @@ namespace phase_shifter::ui { ...@@ -13,16 +13,28 @@ namespace phase_shifter::ui {
namespace { namespace {
constexpr auto hud_height = 100; constexpr auto hud_height = 100;
} constexpr auto count_down = 300;
constexpr auto bar_speed = 100;
} // namespace
Hud_system::Hud_system(mirrage::gui::Gui& gui, mirrage::ecs::Entity_manager& ecs) Hud_system::Hud_system(mirrage::gui::Gui& gui,
: _gui(gui) mirrage::ecs::Entity_manager& ecs,
, _ecs(ecs) const phase_shifter::gameplay::Beat_system& beat_system)
: _gui(gui), _ecs(ecs), _timeLeft(count_down), _beat_system(beat_system)
{ {
//_circle_texture = _gui.load_texture("tex:circle"_aid);
_max_distance = gui.viewport().z / 2;
} }
void Hud_system::update(mirrage::util::Time dt) void Hud_system::update(mirrage::util::Time dt)
{ {
_timeLeft -= dt;
auto state = _beat_system.beat_state();
int max_bars = static_cast<int>(_max_distance / (bar_speed * state.avg_beat_time) + 1);
if(state.beat && _beats < max_bars) {
_beats++;
}
_offset = state.time_to_beat * bar_speed;
} }
void Hud_system::draw() void Hud_system::draw()
...@@ -33,20 +45,56 @@ namespace phase_shifter::ui { ...@@ -33,20 +45,56 @@ namespace phase_shifter::ui {
if(font.is_some()) if(font.is_some())
ImGui::PushFont(font.get_or_throw()); ImGui::PushFont(font.get_or_throw());
ImGui::PushStyleColor(ImGuiCol_WindowBg, "#333333FF"_imcolor.Value);
ImGui::PositionNextWindow(glm::vec2(viewport.z, hud_height), ImGui::PositionNextWindow(glm::vec2(viewport.z, hud_height),
ImGui::WindowPosition_X::center, ImGui::WindowPosition_X::left,
ImGui::WindowPosition_Y::bottom); ImGui::WindowPosition_Y::top);
if(ImGui::Begin("hud", if(ImGui::Begin("hud",
nullptr, 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, 150), ImGui::WindowPosition_X::center, ImGui::WindowPosition_Y::bottom);
if(ImGui::Begin("beat",
nullptr,
ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize
| ImGuiWindowFlags_NoBackground)) {
ImGui::PushStyleColor(ImGuiCol_Border, "#00000000"_imcolor.Value); // Hide Border
ImVec2 cursor = ImGui::GetCursorScreenPos();
auto beat_state = _beat_system.beat_state();
int max_bars = static_cast<int>(_max_distance / (bar_speed * beat_state.avg_beat_time) + 1);
auto line_offset = bar_speed * beat_state.avg_beat_time;
auto start_offset = (max_bars - _beats) * line_offset;
ImGui::BeginChild("Line", {viewport.z, 90}, true);
ImDrawList* drawList = ImGui::GetWindowDrawList();
for(int i = 0; i < _beats; i++) {
ImVec2 p(cursor.x + _max_distance - _offset - start_offset - i * line_offset, cursor.y + 10);
drawList->AddLine(p, {p.x, p.y + 50}, 0xFFFFFFFF, 1);
}
for(int i = 0; i < _beats; i++) {
ImVec2 p(cursor.x + viewport.z / 2 + _offset + start_offset + i * line_offset, cursor.y + 10);
drawList->AddLine(p, {p.x, p.y + 50}, 0xFFFFFFFF, 1);
}
ImVec2 middle(cursor.x + viewport.z / 2, cursor.y);
drawList->AddLine(middle, {middle.x, middle.y + 70}, 0xFFFF0000, 3);
ImGui::EndChild();
ImGui::PopStyleColor();
ImGui::End(); ImGui::End();
if(beat_state.beat || beat_state.avg_beat_time - beat_state.time_since_beat < 0.1f
|| beat_state.time_to_beat < 0.1f) {
//TODO: Flash image to beat
//ImGui::Image(_circle_texture.get(), {10, 10});
}
} }
ImGui::PopStyleColor();
if(font.is_some()) if(font.is_some())
ImGui::PopFont(); ImGui::PopFont();
......
...@@ -6,13 +6,16 @@ ...@@ -6,13 +6,16 @@
#include <unordered_map> #include <unordered_map>
#include <memory> #include <memory>
#include "../gameplay/beat_system.hpp"
namespace phase_shifter::ui { namespace phase_shifter::ui {
class Hud_system { class Hud_system {
public: 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 update(mirrage::util::Time dt);
void draw(); void draw();
...@@ -20,6 +23,11 @@ namespace phase_shifter::ui { ...@@ -20,6 +23,11 @@ namespace phase_shifter::ui {
private: private:
mirrage::gui::Gui& _gui; mirrage::gui::Gui& _gui;
mirrage::ecs::Entity_manager& _ecs; mirrage::ecs::Entity_manager& _ecs;
mirrage::util::Time _timeLeft;
int _beats = 0;
float _offset = 0;
float _max_distance;
const phase_shifter::gameplay::Beat_system& _beat_system;
}; };
} // namespace phase_shifter::ui } // 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