1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
|
/* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */
#ifndef CURSORICONS_H
#define CURSORICONS_H
#include <string>
#include <vector>
#include "System/float3.h"
#include "System/UnorderedMap.hpp"
class CMouseCursor;
class CCursorIcons
{
public:
void AddIcon(int cmd, const float3& pos) {
if (!enabled)
return;
icons.emplace_back(cmd, pos);
}
void AddIconText(const std::string& text, const float3& pos) {
if (!enabled)
return;
texts.emplace_back(text, pos);
}
void AddBuildIcon(int cmd, const float3& pos, int team, int facing) {
if (!enabled)
return;
buildIcons.emplace_back(cmd, pos, team, facing);
}
void Init() {
Clear();
icons.reserve(32);
texts.reserve(32);
buildIcons.reserve(32);
customTypes.clear();
customTypes.reserve(32);
}
void Draw();
void Enable(bool b) { enabled = b; }
void SetCustomType(int cmdID, const std::string& cursor);
protected:
void Sort();
void Clear() {
icons.clear();
texts.clear();
buildIcons.clear();
}
void DrawCursors();
void DrawTexts();
void DrawBuilds();
const CMouseCursor* GetCursor(int cmd) const;
protected:
bool enabled = true;
struct Icon {
Icon(int c, const float3& p): cmd(c), pos(p) {}
bool operator == (const Icon& i) const { return (!((*this) < i) && !(i < (*this))); }
bool operator < (const Icon& i) const
{
// render the WAIT type commands last
if (cmd > i.cmd) return true;
if (cmd < i.cmd) return false;
if (pos.x < i.pos.x) return true;
if (pos.x > i.pos.x) return false;
if (pos.y < i.pos.y) return true;
if (pos.y > i.pos.y) return false;
if (pos.z < i.pos.z) return true;
if (pos.z > i.pos.z) return false;
return false;
}
int cmd;
float3 pos;
};
struct IconText {
IconText(const std::string& t, const float3& p): text(t), pos(p) {}
IconText(const IconText& i) = delete;
IconText(IconText&& i) { *this = std::move(i); }
IconText& operator = (const IconText& i) = delete;
IconText& operator = (IconText&& i) {
text = std::move(i.text);
pos = i.pos;
return *this;
}
bool operator == (const IconText& i) const { return (!((*this) < i) && !(i < (*this))); }
bool operator < (const IconText& i) const
{
if (pos.x < i.pos.x) return true;
if (pos.x > i.pos.x) return false;
if (pos.y < i.pos.y) return true;
if (pos.y > i.pos.y) return false;
if (pos.z < i.pos.z) return true;
if (pos.z > i.pos.z) return false;
return (text < i.text);
}
std::string text;
float3 pos;
};
struct BuildIcon {
BuildIcon(int c, const float3& p, int t, int f): pos(p), cmd(c), team(t), facing(f) {}
bool operator == (const BuildIcon& i) const { return (!((*this) < i) && !(i < (*this))); }
bool operator < (const BuildIcon& i) const
{
if (cmd > i.cmd) return true;
if (cmd < i.cmd) return false;
if (pos.x < i.pos.x) return true;
if (pos.x > i.pos.x) return false;
if (pos.y < i.pos.y) return true;
if (pos.y > i.pos.y) return false;
if (pos.z < i.pos.z) return true;
if (pos.z > i.pos.z) return false;
if (team > i.team) return true;
if (team < i.team) return false;
if (facing > i.facing) return true;
if (facing < i.facing) return false;
return false;
}
float3 pos;
int cmd;
int team;
int facing;
};
std::vector<Icon> icons;
std::vector<IconText> texts;
std::vector<BuildIcon> buildIcons;
spring::unsynced_map<int, std::string> customTypes;
};
extern CCursorIcons cursorIcons;
#endif /* CURSORICONS_H */
|