diff options
author | Aki <please@ignore.pl> | 2022-05-21 11:55:08 +0200 |
---|---|---|
committer | Aki <please@ignore.pl> | 2022-05-21 11:55:08 +0200 |
commit | 7863e4caa1d07aef348a437fe0a662db68fd7ac3 (patch) | |
tree | bf52dfa7a7c45be1d1a696f5bf7c0c3f90beba68 /View.cpp | |
parent | de8d7a812c4da9f0375dc47626c0e836ba728207 (diff) | |
download | derelict-7863e4caa1d07aef348a437fe0a662db68fd7ac3.zip derelict-7863e4caa1d07aef348a437fe0a662db68fd7ac3.tar.gz derelict-7863e4caa1d07aef348a437fe0a662db68fd7ac3.tar.bz2 |
Added naive Timeline
Diffstat (limited to 'View.cpp')
-rw-r--r-- | View.cpp | 25 |
1 files changed, 19 insertions, 6 deletions
@@ -1,21 +1,26 @@ #include "View.h" +#include <iomanip> #include <algorithm> +#include <functional> +#include <sstream> #include <raylib.h> #include "Grid.h" #include "Label.h" +#include "Timeline.h" #include "Utils.h" -View::View(std::vector<Grid> grids) : +View::View(std::vector<Grid> grids, Timeline timeline) : m_camera {}, m_grids {grids}, m_labels {}, m_grid {0}, m_texture {LoadTexture("resources/wreck.png")}, - m_active {nullptr} + m_active {nullptr}, + m_timeline {timeline} { m_camera.position = Vector3{10.0f, 10.0f, 10.0f}; m_camera.target = Vector3{0.0f, 0.0f, 0.0f}; @@ -33,13 +38,14 @@ View::~View() void -View::update(const float) +View::update(const float dt) { if (IsKeyPressed(KEY_SPACE)) { m_grid++; if (m_grid >= m_grids.size()) m_grid = 0; } + m_timeline.move(dt * 60); UpdateCamera(&m_camera); const int height = GetScreenHeight(); const int width = GetScreenWidth(); @@ -56,7 +62,7 @@ View::update(const float) const auto depth = dist(m_camera.position, wreck.position); const auto length = dist(pos, base); const bool hover = 8.0f > dist(mouse, pos); - m_labels.push_back(Label{pos, base, depth, length, hover}); + m_labels.push_back(Label{pos, base, depth, length, hover, std::ref(wreck)}); } std::sort(m_labels.begin(), m_labels.end(), [](auto& a, auto& b){ return a.depth > b.depth; }); m_active = nullptr; @@ -85,11 +91,18 @@ View::draw() const DrawGrid(12, 1.0f); EndMode3D(); for (const auto& point : m_labels) { + Color line = point.hover ? ORANGE : GRAY; + Color icon = point.hover ? ORANGE : WHITE; + if (!point.hover && point.wreck.get().time > m_timeline.current()) { + line.a = 20; + icon.a = 20; + } if (point.length > 8) - DrawLine(point.base.x, point.base.y, point.pos.x, point.pos.y, point.hover ? ORANGE : DARKGRAY); - DrawTexture(m_texture, point.pos.x - 8, point.pos.y - 8, point.hover ? ORANGE : WHITE); + DrawLine(point.base.x, point.base.y, point.pos.x, point.pos.y, line); + DrawTexture(m_texture, point.pos.x - 8, point.pos.y - 8, icon); } DrawFPS(5, 5); DrawText(TextFormat("%d", m_labels.size()), 5, 25, 20, DARKGRAY); + DrawRectangle(2, GetScreenHeight() - 10, (GetScreenWidth() - 4) * m_timeline.progress(), 8, RED); EndDrawing(); } |