Commit b51b5eb8 authored by Georg Schäfer's avatar Georg Schäfer
Browse files

Merge branch 'develop' of...

Merge branch 'develop' of gitlab.fsi.hochschule-trier.de:GameDevWeek/sommersemester-2019/cpp/phaseshifter into develop
parents 0ca41c2d 6ff0116c
Pipeline #3273 passed with stage
in 8 minutes and 1 second
......@@ -38,7 +38,7 @@ namespace phase_shifter::gameplay {
auto Beat_system::graphic_time_scale() const -> float
{
constexpr auto t1_len = 0.1f;
constexpr auto t1_len = 0.05f;
constexpr auto t2_len = 0.6f;
constexpr auto factor = (1.f - (1.f - t1_len - t2_len) * 0.01f) / (t1_len + t2_len) * 2.f;
......
#include "hud_system.hpp"
#include <imgui_internal.h>
#include <glm/glm.hpp>
#include <glm/vec2.hpp>
#include <glm/vec4.hpp>
......@@ -12,8 +13,10 @@ namespace phase_shifter::ui {
using namespace mirrage::gui::literals;
namespace {
constexpr auto hud_height = 100;
constexpr auto bar_speed = 100;
constexpr auto hud_height = 100;
constexpr auto bar_height = 90;
constexpr auto beat_bar_height = 80;
constexpr auto bar_speed = 100;
} // namespace
Hud_system::Hud_system(mirrage::gui::Gui& gui,
......@@ -22,17 +25,11 @@ namespace phase_shifter::ui {
: _gui(gui), _ecs(ecs), _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)
{
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;
_offset = _beat_system.beat_state().time_to_beat * bar_speed;
}
void Hud_system::draw()
......@@ -56,31 +53,35 @@ namespace phase_shifter::ui {
ImGui::End();
}
ImGui::PositionNextWindow(
glm::vec2(viewport.z, 150), ImGui::WindowPosition_X::center, ImGui::WindowPosition_Y::bottom);
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)) {
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);
ImVec2 cursor = ImGui::GetCursorScreenPos();
cursor.y += hud_height / 2.f - 10;
auto beat_state = _beat_system.beat_state();
auto line_offset = bar_speed * beat_state.avg_beat_time;
auto beats = std::clamp(beat_state.beats_left, 0, 5);
ImGui::BeginChild("Line", {viewport.z, bar_height}, 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++) {
auto x_offset = _offset + i * line_offset;
auto height = beat_bar_height * (1.f - glm::smoothstep(0.f, beats * line_offset, x_offset));
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 p(cursor.x + viewport.z / 2 - x_offset, cursor.y - height / 2.f);
drawList->AddLine(p, {p.x, p.y + height}, 0xFFFFFFFF, 1);
p.x = cursor.x + viewport.z / 2 + x_offset;
drawList->AddLine(p, {p.x, p.y + height}, 0xFFFFFFFF, 1);
}
ImVec2 middle(cursor.x + viewport.z / 2, cursor.y);
drawList->AddLine(middle, {middle.x, middle.y + 70}, 0xFFFF0000, 3);
ImVec2 middle(cursor.x + viewport.z / 2, cursor.y - bar_height / 2.f);
drawList->AddLine(middle, {middle.x, middle.y + bar_height}, 0xFFFF0000, 4);
ImGui::EndChild();
ImGui::PopStyleColor();
......
......@@ -24,9 +24,7 @@ namespace phase_shifter::ui {
private:
mirrage::gui::Gui& _gui;
mirrage::ecs::Entity_manager& _ecs;
int _beats = 0;
float _offset = 0;
float _max_distance;
const phase_shifter::gameplay::Beat_system& _beat_system;
};
......
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