summaryrefslogtreecommitdiff
path: root/src/gui/palette.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/palette.cpp')
-rw-r--r--src/gui/palette.cpp229
1 files changed, 12 insertions, 217 deletions
diff --git a/src/gui/palette.cpp b/src/gui/palette.cpp
index d2309399..9ddbb34d 100644
--- a/src/gui/palette.cpp
+++ b/src/gui/palette.cpp
@@ -33,6 +33,7 @@
#include <math.h>
const gcn::Color Palette::BLACK = gcn::Color(0, 0, 0);
+Palette::Palettes Palette::mInstances;
const gcn::Color Palette::RAINBOW_COLORS[7] = {
gcn::Color(255, 0, 0),
@@ -46,127 +47,22 @@ const gcn::Color Palette::RAINBOW_COLORS[7] = {
/** Number of Elemets of RAINBOW_COLORS */
const int Palette::RAINBOW_COLOR_COUNT = 7;
-std::string Palette::getConfigName(const std::string &typeName)
-{
- std::string res = "Color" + typeName;
-
- int pos = 5;
- for (size_t i = 0; i < typeName.length(); i++)
- {
- if (i == 0 || typeName[i] == '_')
- {
- if (i > 0)
- i++;
-
- res[pos] = typeName[i];
- }
- else
- {
- res[pos] = tolower(typeName[i]);
- }
- pos++;
- }
- res.erase(pos, res.length() - pos);
-
- return res;
-}
-
-DEFENUMNAMES(ColorType, COLOR_TYPE);
-
-Palette::Palette() :
+Palette::Palette(int size) :
mRainbowTime(tick_time),
- mColVector(ColVector(TYPE_COUNT))
+ mColors(Colors(size))
{
- std::string indent = " ";
- addColor(TEXT, 0x000000, STATIC, _("Text"));
- addColor(SHADOW, 0x000000, STATIC, indent + _("Text Shadow"));
- addColor(OUTLINE, 0x000000, STATIC, indent + _("Text Outline"));
- addColor(PROGRESS_BAR, 0xffffff, STATIC, indent + _("Progress Bar Labels"));
- addColor(BUTTON, 0x000000, STATIC, indent + _("Buttons"));
- addColor(BUTTON_DISABLED, 0xCCCCCC, STATIC, indent + _("Disabled Buttons"));
- addColor(TAB, 0x00000, STATIC, indent + _("Tabs"));
-
- addColor(BACKGROUND, 0xffffff, STATIC, _("Background"));
-
- addColor(HIGHLIGHT, 0xebc873, STATIC, _("Highlight"), 'H');
- addColor(TAB_HIGHLIGHT, 0xff0000, PULSE, indent + _("Tab Highlight"));
- addColor(SHOP_WARNING, 0x910000, STATIC, indent + _("Item Too Expensive"));
- addColor(ITEM_EQUIPPED, 0x000091, STATIC, indent + _("Item Is Equipped"));
-
- addColor(CHAT, 0x000000, STATIC, _("Chat"), 'C');
- addColor(GM, 0xff0000, STATIC, indent + _("GM"), 'G');
- addColor(PLAYER, 0x1fa052, STATIC, indent + _("Player"), 'Y');
- addColor(WHISPER, 0x00feaf, STATIC, indent + _("Whisper"), 'W');
- addColor(IS, 0xa08527, STATIC, indent + _("Is"), 'I');
- addColor(PARTY, 0xf48055, STATIC, indent + _("Party"), 'P');
- addColor(GUILD, 0xf48055, STATIC, indent + _("Guild"), 'U');
- addColor(SERVER, 0x8415e2, STATIC, indent + _("Server"), 'S');
- addColor(LOGGER, 0x919191, STATIC, indent + _("Logger"), 'L');
- addColor(HYPERLINK, 0xe50d0d, STATIC, indent + _("Hyperlink"), '<');
-
- addColor(BEING, 0xffffff, STATIC, _("Being"));
- addColor(PC, 0xffffff, STATIC, indent + _("Other Players' Names"));
- addColor(SELF, 0xff8040, STATIC, indent + _("Own Name"));
- addColor(GM_NAME, 0x00ff00, STATIC, indent + _("GM Names"));
- addColor(NPC, 0xc8c8ff, STATIC, indent + _("NPCs"));
- addColor(MONSTER, 0xff4040, STATIC, indent + _("Monsters"));
-
- addColor(UNKNOWN_ITEM, 0x000000, STATIC, _("Unknown Item Type"));
- addColor(GENERIC, 0x21a5b1, STATIC, indent + _("Generics"));
- addColor(HEAD, 0x527fa4, STATIC, indent + _("Hats"));
- addColor(USABLE, 0x268d24, STATIC, indent + _("Usables"));
- addColor(TORSO, 0xd12aa4, STATIC, indent + _("Shirts"));
- addColor(ONEHAND, 0xf42a2a, STATIC, indent + _("One Handed Weapons"));
- addColor(LEGS, 0x699900, STATIC, indent + _("Pants"));
- addColor(FEET, 0xaa1d48, STATIC, indent + _("Shoes"));
- addColor(TWOHAND, 0xf46d0e, STATIC, indent + _("Two Handed Weapons"));
- addColor(SHIELD, 0x9c2424, STATIC, indent + _("Shields"));
- addColor(RING, 0x0000ff, STATIC, indent + _("Rings"));
- addColor(NECKLACE, 0xff00ff, STATIC, indent + _("Necklaces"));
- addColor(ARMS, 0x9c24e8, STATIC, indent + _("Arms"));
- addColor(AMMO, 0x8b6311, STATIC, indent + _("Ammo"));
-
- addColor(PARTICLE, 0xffffff, STATIC, _("Particle Effects"));
- addColor(PICKUP_INFO, 0x28dc28, STATIC, indent + _("Pickup Notification"));
- addColor(EXP_INFO, 0xffff00, STATIC, indent + _("Exp Notification"));
- addColor(HIT_PLAYER_MONSTER, 0x0064ff, STATIC,
- indent + _("Player Hits Monster"));
- addColor(HIT_MONSTER_PLAYER, 0xff3232, STATIC,
- indent + _("Monster Hits Player"));
- addColor(HIT_CRITICAL, 0xff0000, RAINBOW, indent + _("Critical Hit"));
- addColor(MISS, 0xffff00, STATIC, indent + _("Misses"));
-
- addColor(HPBAR_FULL, 0x0f6a20, STATIC, _("HP Bar"));
- addColor(HPBAR_THREE_QUARTERS, 0xc38948, STATIC, indent + _("3/4 HP Bar"));
- addColor(HPBAR_ONE_HALF, 0xe28000, STATIC, indent + _("1/2 HP Bar"));
- addColor(HPBAR_ONE_QUARTER, 0xff0000, PULSE, indent + _("1/4 HP Bar"));
- commit(true);
+ mInstances.insert(this);
}
Palette::~Palette()
{
- for (ColVector::iterator col = mColVector.begin(),
- colEnd = mColVector.end(); col != colEnd; ++col)
- {
- const std::string &configName = ColorTypeNames[col->type];
- config.setValue(configName + "Gradient", col->committedGrad);
-
- if (col->grad != STATIC)
- config.setValue(configName + "Delay", col->delay);
-
- if (col->grad == STATIC || col->grad == PULSE)
- {
- char buffer[20];
- sprintf(buffer, "0x%06x", col->getRGB());
- config.setValue(configName, std::string(buffer));
- }
- }
+ mInstances.erase(this);
}
const gcn::Color& Palette::getColor(char c, bool &valid)
{
- for (ColVector::const_iterator col = mColVector.begin(),
- colEnd = mColVector.end(); col != colEnd; ++col)
+ for (Colors::const_iterator col = mColors.begin(),
+ colEnd = mColors.end(); col != colEnd; ++col)
{
if (col->ch == c)
{
@@ -178,116 +74,15 @@ const gcn::Color& Palette::getColor(char c, bool &valid)
return BLACK;
}
-void Palette::setColor(ColorType type, int r, int g, int b)
-{
- mColVector[type].color.r = r;
- mColVector[type].color.g = g;
- mColVector[type].color.b = b;
-}
-
-void Palette::setGradient(ColorType type, GradientType grad)
-{
- ColorElem *elem = &mColVector[type];
- if (elem->grad != STATIC && grad == STATIC)
- {
- for (size_t i = 0; i < mGradVector.size(); i++)
- {
- if (mGradVector[i] == elem)
- {
- mGradVector.erase(mGradVector.begin() + i);
- break;
- }
- }
- }
- else if (elem->grad == STATIC && grad != STATIC)
- {
- mGradVector.push_back(elem);
- }
-
- if (elem->grad != grad)
- {
- elem->grad = grad;
- }
-}
-
-std::string Palette::getElementAt(int i)
+void Palette::advanceGradients()
{
- if (i < 0 || i >= getNumberOfElements())
- {
- return "";
- }
- return mColVector[i].text;
-}
+ Palettes::iterator it = mInstances.begin();
+ Palettes::iterator it_end = mInstances.end();
-Palette::ColorType Palette::getColorTypeAt(int i)
-{
- if (i < 0 || i >= getNumberOfElements())
+ for (; it != it_end; it++)
{
- return CHAT;
+ (*it)->advanceGradient();
}
- return mColVector[i].type;
-}
-
-void Palette::commit(bool commitNonStatic)
-{
- for (ColVector::iterator i = mColVector.begin(), iEnd = mColVector.end();
- i != iEnd; ++i)
- {
- i->committedGrad = i->grad;
- i->committedDelay = i->delay;
- if (commitNonStatic || i->grad == STATIC)
- {
- i->committedColor = i->color;
- }
- else if (i->grad == PULSE)
- {
- i->committedColor = i->testColor;
- }
- }
-}
-
-void Palette::rollback()
-{
- for (ColVector::iterator i = mColVector.begin(), iEnd = mColVector.end();
- i != iEnd; ++i)
- {
- if (i->grad != i->committedGrad)
- {
- setGradient(i->type, i->committedGrad);
- }
- setGradientDelay(i->type, i->committedDelay);
- setColor(i->type, i->committedColor.r, i->committedColor.g,
- i->committedColor.b);
- if (i->grad == PULSE)
- {
- i->testColor.r = i->committedColor.r;
- i->testColor.g = i->committedColor.g;
- i->testColor.b = i->committedColor.b;
- }
- }
-}
-
-void Palette::addColor(Palette::ColorType type, int rgb,
- Palette::GradientType grad, const std::string &text,
- char c, int delay)
-{
- const std::string &configName = ColorTypeNames[type];
- char buffer[20];
- sprintf(buffer, "0x%06x", rgb);
- const std::string rgbString = config.getValue(configName,
- std::string(buffer));
- unsigned int rgbValue = 0;
- if (rgbString.length() == 8 && rgbString[0] == '0' && rgbString[1] == 'x')
- rgbValue = atox(rgbString);
- else
- rgbValue = atoi(rgbString.c_str());
- gcn::Color trueCol = rgbValue;
- grad = (GradientType) config.getValue(configName + "Gradient", grad);
- delay = (int) config.getValue(configName + "Delay", delay);
- mColVector[type].set(type, trueCol, grad, text, c, delay);
-
- if (grad != STATIC)
- mGradVector.push_back(&mColVector[type]);
}
void Palette::advanceGradient()