From e0de78eecfbc8898b028f191326e87f647d6aa5b Mon Sep 17 00:00:00 2001 From: Aki Date: Thu, 9 Jun 2022 20:08:22 +0200 Subject: Added group icons to wreck labels --- App.cpp | 1 + Icons.cpp | 31 ++++++++++++++++++++++++++++++- Icons.h | 4 ++++ Reader.cpp | 2 +- Snapshot.cpp | 32 +++++++++++++++++++++++++++++++- Snapshot.h | 3 +++ Source.h | 2 ++ View.cpp | 5 +++++ Wreck.h | 1 + 9 files changed, 78 insertions(+), 3 deletions(-) diff --git a/App.cpp b/App.cpp index 99ac62f..4e607ef 100644 --- a/App.cpp +++ b/App.cpp @@ -15,6 +15,7 @@ App::App() : InitWindow(800, 600, "Derelict"); SetWindowState(FLAG_WINDOW_RESIZABLE); SetTargetFPS(60); + icons.draw_team_icons(); } diff --git a/Icons.cpp b/Icons.cpp index a903e19..f08787f 100644 --- a/Icons.cpp +++ b/Icons.cpp @@ -2,6 +2,7 @@ #include #include +#include #include @@ -31,7 +32,8 @@ static const std::unordered_map FILENAMES { Icons::Icons() : - m_cache {} + m_cache {}, + m_teams {} { } @@ -48,6 +50,25 @@ Icons::reset() for (const auto& [_, texture] : m_cache) UnloadTexture(texture); m_cache.clear(); + for (const auto& texture : m_teams) + UnloadRenderTexture(texture); + m_teams.clear(); +} + + +void +Icons::draw_team_icons() +{ + if (!m_teams.empty()) + return; + m_teams.reserve(2); + for (const auto color : {Color{204, 8, 153, 255}, Color{20, 234, 106, 255}}) { + auto texture = LoadRenderTexture(6, 6); + BeginTextureMode(texture); + DrawRectangle(0, 0, 6, 6, color); + EndTextureMode(); + m_teams.push_back(std::move(texture)); + } } @@ -68,3 +89,11 @@ Icons::find(const long int group) return texture; } } + + +Texture2D +Icons::team_icon(const int team) +{ + auto& render = m_teams.at(team); + return render.texture; +} diff --git a/Icons.h b/Icons.h index a6d4b89..cc68172 100644 --- a/Icons.h +++ b/Icons.h @@ -2,6 +2,7 @@ #include #include +#include #include @@ -12,7 +13,10 @@ public: Icons(); ~Icons(); void reset(); + void draw_team_icons(); Texture2D find(long int group); + Texture2D team_icon(int team); private: std::unordered_map m_cache; + std::vector m_teams; }; diff --git a/Reader.cpp b/Reader.cpp index d6826f6..52bb0fd 100644 --- a/Reader.cpp +++ b/Reader.cpp @@ -30,7 +30,7 @@ Reader::read(Source& source) if (km.time < start) start = km.time; if (end < km.time) end = km.time; auto& grid = find_grid_for(grids, km.position); - grid.wrecks.push_back(Wreck{Vector3{0, 0, 0}, km, 0}); + grid.wrecks.push_back(Wreck{Vector3{0, 0, 0}, km, 0, source.team(km.owner)}); } for (auto& grid : grids) { LongVector3 average {0, 0, 0}; diff --git a/Snapshot.cpp b/Snapshot.cpp index 99cf400..5d76e73 100644 --- a/Snapshot.cpp +++ b/Snapshot.cpp @@ -5,11 +5,13 @@ #include #include #include +#include #include #include #include "Killmail.h" +#include "Owner.h" using json = nlohmann::json; @@ -24,7 +26,8 @@ NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(LongVector3, x, y, z) Snapshot::Snapshot(const char* filename) : - m_killmails {} + m_killmails {}, + m_teams {} { if (!FileExists(filename)) throw "File does not exist"; @@ -38,6 +41,14 @@ Snapshot::Snapshot(const char* filename) : dump.at("killmails").get_to(m_killmails); for (auto& km : m_killmails) km.group = group_lookup[km.ship]; + int team = 0; + for (const auto& members : dump.at("teams")) { + for (const auto& entry : members) { + const auto id = entry.get(); + m_teams[id] = team; + } + ++team; + } UnloadFileText(text); } @@ -49,6 +60,25 @@ Snapshot::killmails() const } +int +Snapshot::team(const Owner& owner) const +{ + auto find = [this](long int id) -> int { + if (id < 0) + return -1; + const auto search = m_teams.find(id); + if (search == m_teams.end()) + return -1; + return search->second; + }; + int id; + if ((id = find(owner.faction)) != -1) return id; + if ((id = find(owner.alliance)) != -1) return id; + if ((id = find(owner.corporation)) != -1) return id; + return -1; +} + + void from_json(const json& j, tm& d) { diff --git a/Snapshot.h b/Snapshot.h index ab1b8e1..c993b23 100644 --- a/Snapshot.h +++ b/Snapshot.h @@ -1,6 +1,7 @@ #pragma once #include +#include #include "Killmail.h" #include "Source.h" @@ -11,6 +12,8 @@ class Snapshot : public Source public: explicit Snapshot(const char* filename); std::vector killmails() const override; + int team(const Owner& owner) const override; private: std::vector m_killmails; + std::unordered_map m_teams; }; diff --git a/Source.h b/Source.h index 1dba9ea..f583666 100644 --- a/Source.h +++ b/Source.h @@ -3,10 +3,12 @@ #include #include "Killmail.h" +#include "Owner.h" struct Source { virtual ~Source() = default; virtual std::vector killmails() const = 0; + virtual int team(const Owner& owner) const = 0; }; diff --git a/View.cpp b/View.cpp index 6f09ba5..542c031 100644 --- a/View.cpp +++ b/View.cpp @@ -86,13 +86,18 @@ View::draw() const 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); diff --git a/Wreck.h b/Wreck.h index 3fa4aa5..865ec95 100644 --- a/Wreck.h +++ b/Wreck.h @@ -10,4 +10,5 @@ struct Wreck Vector3 position; Killmail killmail; double time; + int team; }; -- cgit v1.1