00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef PALETTE_H
00024 #define PALETTE_H
00025
00026 #include <cstdlib>
00027 #include <string>
00028 #include <vector>
00029
00030 #include <guichan/listmodel.hpp>
00031 #include <guichan/color.hpp>
00032
00033
00034 #define EDEF(a) a,
00035 #define LASTEDEF(a) a
00036 #define ECONFIGSTR(a) Palette::getConfigName(#a),
00037 #define LASTECONFIGSTR(a) Palette::getConfigName(#a)
00038
00039 #define TEXTENUM(name,def)\
00040 enum name { def(EDEF,LASTEDEF) };\
00041 static const std::string name ## Names[]
00042 #define DEFENUMNAMES(name,def)\
00043 const std::string Palette::name ## Names[] = { def(ECONFIGSTR,ECONFIGSTR) "" }
00044
00045
00046 #define GRADIENT_DELAY 40
00047
00051 class Palette : public gcn::ListModel
00052 {
00053 public:
00055 #define COLOR_TYPE(ENTRY,LASTENTRY)\
00056 ENTRY(TEXT)\
00057 ENTRY(SHADOW)\
00058 ENTRY(OUTLINE)\
00059 ENTRY(PROGRESS_BAR)\
00060 ENTRY(BACKGROUND)\
00061 ENTRY(HIGHLIGHT)\
00062 ENTRY(TAB_HIGHLIGHT)\
00063 ENTRY(SHOP_WARNING)\
00064 ENTRY(ITEM_EQUIPPED)\
00065 ENTRY(CHAT)\
00066 ENTRY(GM)\
00067 ENTRY(PLAYER)\
00068 ENTRY(WHISPER)\
00069 ENTRY(IS)\
00070 ENTRY(PARTY)\
00071 ENTRY(SERVER)\
00072 ENTRY(LOGGER)\
00073 ENTRY(HYPERLINK)\
00074 ENTRY(BEING)\
00075 ENTRY(PC)\
00076 ENTRY(SELF)\
00077 ENTRY(GM_NAME)\
00078 ENTRY(NPC)\
00079 ENTRY(MONSTER)\
00080 ENTRY(UNKNOWN_ITEM)\
00081 ENTRY(GENERIC)\
00082 ENTRY(HEAD)\
00083 ENTRY(USABLE)\
00084 ENTRY(TORSO)\
00085 ENTRY(ONEHAND)\
00086 ENTRY(LEGS)\
00087 ENTRY(FEET)\
00088 ENTRY(TWOHAND)\
00089 ENTRY(SHIELD)\
00090 ENTRY(RING)\
00091 ENTRY(NECKLACE)\
00092 ENTRY(ARMS)\
00093 ENTRY(AMMO)\
00094 ENTRY(PARTICLE)\
00095 ENTRY(EXP_INFO)\
00096 ENTRY(PICKUP_INFO)\
00097 ENTRY(HIT_PLAYER_MONSTER)\
00098 ENTRY(HIT_MONSTER_PLAYER)\
00099 ENTRY(HIT_CRITICAL)\
00100 ENTRY(MISS)\
00101 ENTRY(HPBAR_FULL)\
00102 ENTRY(HPBAR_THREE_QUARTERS)\
00103 ENTRY(HPBAR_ONE_HALF)\
00104 ENTRY(HPBAR_ONE_QUARTER)\
00105 LASTENTRY(TYPE_COUNT)
00106
00107 TEXTENUM(ColorType, COLOR_TYPE);
00108
00110 enum GradientType {
00111 STATIC,
00112 PULSE,
00113 SPECTRUM,
00114 RAINBOW
00115 };
00116
00120 Palette();
00121
00125 ~Palette();
00126
00136 const gcn::Color &getColor(char c, bool &valid);
00137
00147 inline const gcn::Color &getColor(ColorType type, int alpha = 255)
00148 {
00149 gcn::Color* col = &mColVector[type].color;
00150 col->a = alpha;
00151 return *col;
00152 }
00153
00161 inline const gcn::Color &getCommittedColor(ColorType type)
00162 {
00163 return mColVector[type].committedColor;
00164 }
00165
00173 inline const gcn::Color &getTestColor(ColorType type)
00174 {
00175 return mColVector[type].testColor;
00176 }
00177
00184 inline void setTestColor(ColorType type, gcn::Color color)
00185 {
00186 mColVector[type].testColor = color;
00187 }
00188
00196 inline GradientType getGradientType(ColorType type)
00197 {
00198 return mColVector[type].grad;
00199 }
00200
00208 inline int getGradientDelay(ColorType type)
00209 { return mColVector[type].delay; }
00210
00218 inline char getColorChar(ColorType type)
00219 {
00220 return mColVector[type].ch;
00221 }
00222
00231 void setColor(ColorType type, int r, int g, int b);
00232
00238 void setGradient(ColorType type, GradientType grad);
00239
00245 void setGradientDelay(ColorType type, int delay)
00246 { mColVector[type].delay = delay; }
00247
00253 inline int getNumberOfElements() { return mColVector.size(); }
00254
00262 std::string getElementAt(int i);
00263
00272 ColorType getColorTypeAt(int i);
00273
00277 inline void commit()
00278 {
00279 commit(false);
00280 }
00281
00285 void rollback();
00286
00290 void advanceGradient();
00291
00292 private:
00294 static const gcn::Color BLACK;
00295
00297 static const gcn::Color RAINBOW_COLORS[];
00298 static const int RAINBOW_COLOR_COUNT;
00300 int mRainbowTime;
00301
00310 void setColorAt(int i, int r, int g, int b);
00311
00316 void commit(bool commitNonStatic);
00317
00318 struct ColorElem
00319 {
00320 ColorType type;
00321 gcn::Color color;
00322 gcn::Color testColor;
00323 gcn::Color committedColor;
00324 std::string text;
00325 char ch;
00326 GradientType grad;
00327 GradientType committedGrad;
00328 int gradientIndex;
00329 int delay;
00330 int committedDelay;
00331
00332 void set(ColorType type, gcn::Color& color, GradientType grad,
00333 const std::string &text, char c, int delay)
00334 {
00335 ColorElem::type = type;
00336 ColorElem::color = color;
00337 ColorElem::testColor = color;
00338 ColorElem::text = text;
00339 ColorElem::ch = c;
00340 ColorElem::grad = grad;
00341 ColorElem::delay = delay;
00342 ColorElem::gradientIndex = rand();
00343 }
00344
00345 inline int getRGB()
00346 {
00347 return (committedColor.r << 16) | (committedColor.g << 8) |
00348 committedColor.b;
00349 }
00350 };
00351 typedef std::vector<ColorElem> ColVector;
00353 ColVector mColVector;
00354 std::vector<ColorElem*> mGradVector;
00355
00363 void addColor(ColorType type, int rgb, GradientType grad,
00364 const std::string &text, char c = 0,
00365 int delay = GRADIENT_DELAY);
00366
00377 static std::string getConfigName(const std::string &typeName);
00378 };
00379
00380 extern Palette *guiPalette;
00381
00382 #endif