#include "View.h" #include #include #include #include #include #include "Globals.h" #include "Grid.h" #include "Label.h" #include "Timeline.h" #include "VectorMath.h" const Color BACKGROUND {8, 8, 50, 255}; const Color LINE {240, 240, 240, 160}; View::View(std::vector grids, Timeline timeline) : m_cameraman {}, m_grids {grids}, m_labels {}, m_grid {0}, m_active {nullptr}, m_timeline {timeline} { } View::~View() { } void View::update(const float dt) { if (IsKeyPressed(KEY_SPACE)) { m_grid++; if (m_grid >= m_grids.size()) m_grid = 0; } m_cameraman.update(dt); m_timeline.move(dt * 60); const int height = GetScreenHeight(); const int width = GetScreenWidth(); const auto& wrecks = m_grids.at(m_grid).wrecks; m_labels.clear(); m_labels.reserve(wrecks.size()); const auto mouse = GetMousePosition(); for (const auto& wreck : wrecks) { const auto pos = GetWorldToScreen(wreck.position, m_cameraman.camera); const auto base = GetWorldToScreen({wreck.position.x, 0.0f, wreck.position.z}, m_cameraman.camera); if (0 > pos.x || width < pos.x || 0 > pos.y || height < pos.y) if (0 > base.x || width < base.x || 0 > base.y || height < base.y) continue; const auto depth = dist(m_cameraman.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, std::ref(wreck), app.icons.find(wreck.killmail.group)}); } std::sort(m_labels.begin(), m_labels.end(), [](auto& a, auto& b){ return a.depth > b.depth; }); m_active = nullptr; std::for_each(m_labels.rbegin(), m_labels.rend(), [this](auto& label) { if (label.hover) { if (m_active) label.hover = false; else m_active = &label; } }); } void View::draw() const { BeginDrawing(); ClearBackground(BACKGROUND); BeginMode3D(m_cameraman.camera); DrawGrid(12, 1.0f); EndMode3D(); for (const auto& point : m_labels) { Color line = point.hover ? ORANGE : LINE; Color icon = point.hover ? ORANGE : WHITE; Color white = WHITE; if (!point.hover && point.wreck.get().time > m_timeline.current()) { line.a = 20; icon.a = 20; white.a = 20; } if (point.length > 8) DrawLine(point.base.x, point.base.y, point.pos.x, point.pos.y, line); DrawTexture(point.texture, point.pos.x - 8, point.pos.y - 8, icon); int team = point.wreck.get().team; if (team != -1) DrawTexture(app.icons.team_icon(team), point.pos.x + 3, point.pos.y + 3, white); } 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(); }