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 164 165 166
|
/* Information.cpp
Copyright (c) 2014 by Michael Zahniser
Endless Sky is free software: you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
Foundation, either version 3 of the License, or (at your option) any later version.
Endless Sky is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "Information.h"
#include "image/Sprite.h"
using namespace std;
void Information::SetRegion(const Rectangle &rect)
{
region = rect;
hasCustomRegion = true;
}
const Rectangle &Information::GetCustomRegion() const
{
return region;
}
bool Information::HasCustomRegion() const
{
return hasCustomRegion;
}
void Information::SetSprite(const string &name, const Sprite *sprite, const Point &unit,
float frame, const Swizzle *swizzle)
{
sprites[name] = sprite;
spriteUnits[name] = unit;
spriteFrames[name] = frame;
spriteSwizzles[name] = swizzle;
}
const Sprite *Information::GetSprite(const string &name) const
{
static const Sprite empty;
auto it = sprites.find(name);
return (it == sprites.end()) ? &empty : it->second;
}
const Point &Information::GetSpriteUnit(const string &name) const
{
static const Point up(0., -1.);
auto it = spriteUnits.find(name);
return (it == spriteUnits.end()) ? up : it->second;
}
float Information::GetSpriteFrame(const string &name) const
{
auto it = spriteFrames.find(name);
return (it == spriteFrames.end()) ? 0.f : it->second;
}
const Swizzle *Information::GetSwizzle(const string &name) const
{
auto it = spriteSwizzles.find(name);
return it == spriteSwizzles.end() ? 0 : it->second;
}
void Information::SetString(const string &name, const string &value)
{
strings[name] = value;
}
const string &Information::GetString(const string &name) const
{
static const string empty;
auto it = strings.find(name);
return (it == strings.end()) ? empty : it->second;
}
void Information::SetBar(const string &name, double value, double segments)
{
bars[name] = value;
barSegments[name] = segments;
}
double Information::BarValue(const string &name) const
{
auto it = bars.find(name);
return (it == bars.end()) ? 0. : it->second;
}
double Information::BarSegments(const string &name) const
{
auto it = barSegments.find(name);
return (it == barSegments.end()) ? 1. : it->second;
}
void Information::SetCondition(const string &condition)
{
conditions.insert(condition);
}
bool Information::HasCondition(const string &condition) const
{
if(condition.empty())
return true;
if(condition.front() == '!')
return !HasCondition(condition.substr(1));
return conditions.contains(condition);
}
void Information::SetOutlineColor(const Color &color)
{
outlineColor = color;
}
const Color &Information::GetOutlineColor() const
{
return outlineColor;
}
|