From 3e8ebf3133ece10efc8cf9219dafc02e780bc3ab Mon Sep 17 00:00:00 2001 From: Aki Date: Sat, 21 May 2022 21:17:27 +0200 Subject: Added naive icons loading --- Icons.cpp | 93 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 Icons.cpp (limited to 'Icons.cpp') diff --git a/Icons.cpp b/Icons.cpp new file mode 100644 index 0000000..7b90ae0 --- /dev/null +++ b/Icons.cpp @@ -0,0 +1,93 @@ +#include "Icons.h" + +#include +#include + +#include + + +static const std::unordered_map FILENAMES { + {11176, "resources/frigate_16.png"}, + {11198, "resources/frigate_16.png"}, + {11202, "resources/frigate_16.png"}, + {11393, "resources/frigate_16.png"}, + {11400, "resources/frigate_16.png"}, + {11963, "resources/cruiser_16.png"}, + {11965, "resources/cruiser_16.png"}, + {11969, "resources/cruiser_16.png"}, + {11971, "resources/cruiser_16.png"}, + {11987, "resources/cruiser_16.png"}, + {11989, "resources/cruiser_16.png"}, + {11993, "resources/cruiser_16.png"}, + {12017, "resources/cruiser_16.png"}, + {12034, "resources/frigate_16.png"}, + {17920, "resources/battleship_16.png"}, + {19720, "resources/dreadnought_16.png"}, + {19722, "resources/dreadnought_16.png"}, + {2161, "resources/frigate_16.png"}, + {22442, "resources/battleCruiser_16.png"}, + {22456, "resources/destroyer_16.png"}, + {22460, "resources/destroyer_16.png"}, + {22464, "resources/destroyer_16.png"}, + {32876, "resources/destroyer_16.png"}, + {33468, "resources/frigate_16.png"}, + {33474, "resources/mobileStorage.png"}, + {33476, "resources/mobileCynosuralInhibitor.png"}, + {34828, "resources/destroyer_16.png"}, + {35683, "resources/destroyer_16.png"}, + {37480, "resources/destroyer_16.png"}, + {37482, "resources/destroyer_16.png"}, + {37604, "resources/forceAuxiliary_16.png"}, + {3766, "resources/frigate_16.png"}, + {45534, "resources/cruiser_16.png"}, + {583, "resources/frigate_16.png"}, + {585, "resources/frigate_16.png"}, + {606, "resources/rookie_16.png"}, + {634, "resources/cruiser_16.png"}, + {640, "resources/battleship_16.png"}, + {644, "resources/battleship_16.png"}, + {651, "resources/industrial_16.png"}, + {670, "resources/frozenCorpse.png"}, + {672, "resources/shuttle_16.png"}, +}; + + +Icons::Icons() : + m_cache {} +{ +} + + +Icons::~Icons() +{ + reset(); +} + + +void +Icons::reset() +{ + for (const auto& [_, texture] : m_cache) + UnloadTexture(texture); + m_cache.clear(); +} + + +Texture2D +Icons::find(const long int type) +{ + const auto existing = m_cache.find(type); + if (existing != m_cache.end()) { + return existing->second; + } + else { + Texture2D texture; + const auto filename = FILENAMES.find(type); + if (filename != FILENAMES.end()) + texture = LoadTexture(filename->second.data()); + else + texture = LoadTexture("resources/wreck.png"); + m_cache[type] = texture; + return texture; + } +} -- cgit v1.1