summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--data/graphics/gui/colors.xml47
-rw-r--r--mana.cbp2
-rw-r--r--mana.files3
-rw-r--r--src/CMakeLists.txt2
-rw-r--r--src/Makefile.am2
-rw-r--r--src/being.cpp24
-rw-r--r--src/client.cpp8
-rw-r--r--src/gui/beingpopup.cpp5
-rw-r--r--src/gui/beingpopup.h2
-rw-r--r--src/gui/equipmentwindow.cpp6
-rw-r--r--src/gui/gui.cpp2
-rw-r--r--src/gui/inventorywindow.cpp13
-rw-r--r--src/gui/itempopup.cpp30
-rw-r--r--src/gui/minimap.cpp16
-rw-r--r--src/gui/ministatus.cpp23
-rw-r--r--src/gui/palette.cpp229
-rw-r--r--src/gui/palette.h271
-rw-r--r--src/gui/setup_colors.cpp169
-rw-r--r--src/gui/skilldialog.cpp12
-rw-r--r--src/gui/socialwindow.cpp5
-rw-r--r--src/gui/speechbubble.cpp4
-rw-r--r--src/gui/speechbubble.h4
-rw-r--r--src/gui/statuswindow.cpp115
-rw-r--r--src/gui/statuswindow.h2
-rw-r--r--src/gui/storagewindow.cpp3
-rw-r--r--src/gui/theme.cpp225
-rw-r--r--src/gui/theme.h89
-rw-r--r--src/gui/updatewindow.cpp2
-rw-r--r--src/gui/userpalette.cpp237
-rw-r--r--src/gui/userpalette.h208
-rw-r--r--src/gui/widgets/avatarlistbox.cpp6
-rw-r--r--src/gui/widgets/browserbox.cpp14
-rw-r--r--src/gui/widgets/button.cpp4
-rw-r--r--src/gui/widgets/chattab.cpp2
-rw-r--r--src/gui/widgets/chattab.h2
-rw-r--r--src/gui/widgets/checkbox.cpp2
-rw-r--r--src/gui/widgets/dropdown.cpp6
-rw-r--r--src/gui/widgets/emoteshortcutcontainer.cpp2
-rw-r--r--src/gui/widgets/itemcontainer.cpp2
-rw-r--r--src/gui/widgets/itemshortcutcontainer.cpp4
-rw-r--r--src/gui/widgets/label.cpp4
-rw-r--r--src/gui/widgets/listbox.cpp6
-rw-r--r--src/gui/widgets/progressbar.cpp26
-rw-r--r--src/gui/widgets/progressbar.h13
-rw-r--r--src/gui/widgets/progressindicator.cpp6
-rw-r--r--src/gui/widgets/shoplistbox.cpp14
-rw-r--r--src/gui/widgets/tab.cpp14
-rw-r--r--src/gui/widgets/tab.h6
-rw-r--r--src/gui/widgets/table.cpp8
-rw-r--r--src/gui/widgets/textbox.cpp4
-rw-r--r--src/gui/widgets/textfield.cpp2
-rw-r--r--src/gui/widgets/textpreview.cpp4
-rw-r--r--src/gui/widgets/whispertab.cpp4
-rw-r--r--src/gui/widgets/window.cpp2
-rw-r--r--src/localplayer.cpp13
-rw-r--r--src/localplayer.h6
-rw-r--r--src/monster.cpp6
-rw-r--r--src/net/ea/gui/guildtab.cpp4
-rw-r--r--src/net/ea/gui/partytab.cpp4
-rw-r--r--src/npc.cpp6
-rw-r--r--src/player.cpp13
-rw-r--r--src/resources/dye.cpp49
-rw-r--r--src/resources/dye.h4
-rw-r--r--src/textrenderer.h6
-rw-r--r--src/utils/stringutils.cpp8
65 files changed, 1137 insertions, 899 deletions
diff --git a/data/graphics/gui/colors.xml b/data/graphics/gui/colors.xml
new file mode 100644
index 00000000..45bedb73
--- /dev/null
+++ b/data/graphics/gui/colors.xml
@@ -0,0 +1,47 @@
+<colors>
+ <color id="TEXT" color="#000000" />
+ <color id="SHADOW" color="#000000" />
+ <color id="OUTLINE" color="#000000" />
+ <color id="PROGRESS_BAR" color="#ffffff" />
+ <color id="BUTTON" color="#000000" />
+ <color id="BUTTON_DISABLED" color="#333333" />
+ <color id="TAB" color="#000000" />
+ <color id="BACKGROUND" color="#ffffff" />
+ <color id="HIGHLIGHT" color="#ebc873" />
+ <color id="TAB_FLASH" color="#ff0000" effect="pulse" />
+ <color id="SHOP_WARNING" color="#910000" />
+ <color id="ITEM_EQUIPPED" color="" />
+ <color id="CHAT" color="#000000" />
+ <color id="GM" color="#ff0000" />
+ <color id="PLAYER" color="#1fa052" />
+ <color id="WHISPER" color="#0000ff" />
+ <color id="IS" color="#a08527" />
+ <color id="PARTY" color="#ff00d8" />
+ <color id="GUILD" color="#ff00d8" />
+ <color id="SERVER" color="#8415e2" />
+ <color id="LOGGER" color="#919191" />
+ <color id="HYPERLINK" color="#e50d0d" />
+ <color id="UNKNOWN_ITEM" color="#000000" />
+ <color id="GENERIC" color="#21a5b1" />
+ <color id="HEAD" color="#527fa4" />
+ <color id="USABLE" color="#268d24" />
+ <color id="TORSO" color="#d12aa4" />
+ <color id="ONEHAND" color="#f42a2a" />
+ <color id="LEGS" color="#699900" />
+ <color id="FEET" color="#aa1d48" />
+ <color id="TWOHAND" color="#f46d0e" />
+ <color id="SHIELD" color="#9c2424" />
+ <color id="RING" color="#0000ff" />
+ <color id="NECKLACE" color="#ff00ff" />
+ <color id="ARMS" color="#9c24e8" />
+ <color id="AMMO" color="#8b6311" />
+
+ <progressbar id="DEFAULT" color="#969696" />
+ <progressbar id="HP" color="#ff0000,e28000,c38948,0f6a20" />
+ <progressbar id="MP" color="#1a66e6" />
+ <progressbar id="NO_MP" color="#646464" />
+ <progressbar id="EXP" color="#8fc0d3" />
+ <progressbar id="INVY_SLOTS" color="#e1c819" />
+ <progressbar id="WEIGHT" color="#0000ff,ffff00,ff0000" />
+ <progressbar id="JOB" color="#e187cb" />
+</colors>
diff --git a/mana.cbp b/mana.cbp
index b81560f2..cd2045cc 100644
--- a/mana.cbp
+++ b/mana.cbp
@@ -236,6 +236,8 @@
<Unit filename="src\gui\unregisterdialog.cpp" />
<Unit filename="src\gui\unregisterdialog.h" />
<Unit filename="src\gui\updatewindow.cpp" />
+ <Unit filename="src\gui\userpalette.cpp" />
+ <Unit filename="src\gui\userpalette.h" />
<Unit filename="src\gui\updatewindow.h" />
<Unit filename="src\gui\viewport.cpp" />
<Unit filename="src\gui\viewport.h" />
diff --git a/mana.files b/mana.files
index b3f647a2..ee58c01c 100644
--- a/mana.files
+++ b/mana.files
@@ -5,6 +5,7 @@
./data/fonts/Makefile.am
./data/graphics/CMakeLists.txt
./data/graphics/gui/CMakeLists.txt
+./data/graphics/gui/colors.xml
./data/graphics/gui/Makefile.am
./data/graphics/gui/speechbubble.xml
./data/graphics/gui/window.xml
@@ -183,6 +184,8 @@
./src/gui/unregisterdialog.h
./src/gui/updatewindow.cpp
./src/gui/updatewindow.h
+./src/gui/userpalette.cpp
+./src/gui/userpalette.h
./src/gui/viewport.cpp
./src/gui/viewport.h
./src/gui/widgets/avatarlistbox.cpp
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 68147db7..8490e887 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -304,6 +304,8 @@ SET(SRCS
gui/unregisterdialog.h
gui/updatewindow.cpp
gui/updatewindow.h
+ gui/userpalette.cpp
+ gui/userpalette.h
gui/viewport.cpp
gui/viewport.h
gui/windowmenu.cpp
diff --git a/src/Makefile.am b/src/Makefile.am
index 55937c0c..7081828f 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -203,6 +203,8 @@ mana_SOURCES = gui/widgets/avatarlistbox.cpp \
gui/unregisterdialog.h \
gui/updatewindow.cpp \
gui/updatewindow.h \
+ gui/userpalette.cpp \
+ gui/userpalette.h \
gui/viewport.cpp \
gui/viewport.h \
gui/windowmenu.cpp \
diff --git a/src/being.cpp b/src/being.cpp
index 2c7ba016..72bdef3d 100644
--- a/src/being.cpp
+++ b/src/being.cpp
@@ -35,7 +35,10 @@
#include "text.h"
#include "statuseffect.h"
+#include "gui/gui.h"
#include "gui/speechbubble.h"
+#include "gui/theme.h"
+#include "gui/userpalette.h"
#include "resources/colordb.h"
#include "resources/emotedb.h"
@@ -44,9 +47,6 @@
#include "resources/iteminfo.h"
#include "resources/resourcemanager.h"
-#include "gui/gui.h"
-#include "gui/palette.h"
-#include "gui/speechbubble.h"
#include "utils/dtor.h"
#include "utils/stringutils.h"
@@ -96,8 +96,8 @@ Being::Being(int id, int job, Map *map):
mSpeechBubble = new SpeechBubble;
- mNameColor = &guiPalette->getColor(Palette::NPC);
- mTextColor = &guiPalette->getColor(Palette::CHAT);
+ mNameColor = &userPalette->getColor(UserPalette::NPC);
+ mTextColor = &Theme::getThemeColor(Theme::CHAT);
mWalkSpeed = Net::getPlayerHandler()->getDefaultWalkSpeed();
}
@@ -305,7 +305,7 @@ void Being::setSpeech(const std::string &text, int time)
mText = new Text(mSpeech,
getPixelX(), getPixelY() - getHeight(),
gcn::Graphics::CENTER,
- &guiPalette->getColor(Palette::PARTICLE),
+ &userPalette->getColor(UserPalette::PARTICLE),
true);
}
}
@@ -322,7 +322,7 @@ void Being::takeDamage(Being *attacker, int amount, AttackType type)
// Selecting the right color
if (type == CRITICAL || type == FLEE)
{
- color = &guiPalette->getColor(Palette::HIT_CRITICAL);
+ color = &userPalette->getColor(UserPalette::HIT_CRITICAL);
}
else if (!amount)
{
@@ -330,20 +330,20 @@ void Being::takeDamage(Being *attacker, int amount, AttackType type)
{
// This is intended to be the wrong direction to visually
// differentiate between hits and misses
- color = &guiPalette->getColor(Palette::HIT_MONSTER_PLAYER);
+ color = &userPalette->getColor(UserPalette::HIT_MONSTER_PLAYER);
}
else
{
- color = &guiPalette->getColor(Palette::MISS);
+ color = &userPalette->getColor(UserPalette::MISS);
}
}
else if (getType() == MONSTER)
{
- color = &guiPalette->getColor(Palette::HIT_PLAYER_MONSTER);
+ color = &userPalette->getColor(UserPalette::HIT_PLAYER_MONSTER);
}
else
{
- color = &guiPalette->getColor(Palette::HIT_MONSTER_PLAYER);
+ color = &userPalette->getColor(UserPalette::HIT_MONSTER_PLAYER);
}
// Show damage number
@@ -783,7 +783,7 @@ void Being::drawSpeech(int offsetX, int offsetY)
mText = new Text(mSpeech,
getPixelX(), getPixelY() - getHeight(),
gcn::Graphics::CENTER,
- &guiPalette->getColor(Palette::PARTICLE),
+ &userPalette->getColor(UserPalette::PARTICLE),
true);
}
}
diff --git a/src/client.cpp b/src/client.cpp
index 1b9dcd4c..4e67c3e4 100644
--- a/src/client.cpp
+++ b/src/client.cpp
@@ -42,7 +42,6 @@
#include "gui/gui.h"
#include "gui/login.h"
#include "gui/okdialog.h"
-#include "gui/palette.h"
#include "gui/quitdialog.h"
#include "gui/register.h"
#include "gui/sdlinput.h"
@@ -51,6 +50,7 @@
#include "gui/theme.h"
#include "gui/unregisterdialog.h"
#include "gui/updatewindow.h"
+#include "gui/userpalette.h"
#include "gui/worldselectdialog.h"
#include "gui/widgets/button.h"
@@ -112,7 +112,7 @@ Configuration branding; /**< XML branding information reader */
Logger *logger; /**< Log object */
KeyboardConfig keyboard;
-Palette *guiPalette;
+UserPalette *userPalette;
Graphics *graphics;
Sound sound;
@@ -372,7 +372,7 @@ Client::Client(const Options &options):
// Initialise player relations
player_relations.init();
- guiPalette = new Palette;
+ userPalette = new UserPalette;
setupWindow = new Setup;
sound.playMusic(branding.getValue("loginMusic", "Magick - Real.ogg"));
@@ -443,7 +443,7 @@ Client::~Client()
SDL_FreeSurface(mIcon);
logger->log("Quitting");
- delete guiPalette;
+ delete userPalette;
config.write();
diff --git a/src/gui/beingpopup.cpp b/src/gui/beingpopup.cpp
index 33fdff44..9f05bbdb 100644
--- a/src/gui/beingpopup.cpp
+++ b/src/gui/beingpopup.cpp
@@ -89,8 +89,3 @@ void BeingPopup::show(int x, int y, Player *p)
setVisible(false);
}
-
-gcn::Color BeingPopup::getColor()
-{
- return guiPalette->getColor(Palette::GENERIC);
-}
diff --git a/src/gui/beingpopup.h b/src/gui/beingpopup.h
index 71d9dd2a..f397e374 100644
--- a/src/gui/beingpopup.h
+++ b/src/gui/beingpopup.h
@@ -52,8 +52,6 @@ class BeingPopup : public Popup
private:
Label *mBeingName;
Label *mBeingParty;
-
- static gcn::Color getColor();
};
#endif // BEINGPOPUP_H
diff --git a/src/gui/equipmentwindow.cpp b/src/gui/equipmentwindow.cpp
index 581fd818..43e330f4 100644
--- a/src/gui/equipmentwindow.cpp
+++ b/src/gui/equipmentwindow.cpp
@@ -29,7 +29,7 @@
#include "gui/equipmentwindow.h"
#include "gui/itempopup.h"
-#include "gui/palette.h"
+#include "gui/theme.h"
#include "gui/setup.h"
#include "gui/viewport.h"
@@ -118,7 +118,7 @@ void EquipmentWindow::draw(gcn::Graphics *graphics)
{
if (i == mSelected)
{
- const gcn::Color color = guiPalette->getColor(Palette::HIGHLIGHT);
+ const gcn::Color color = Theme::getThemeColor(Theme::HIGHLIGHT);
// Set color to the highlight color
g->setColor(gcn::Color(color.r, color.g, color.b, getGuiAlpha()));
@@ -143,7 +143,7 @@ void EquipmentWindow::draw(gcn::Graphics *graphics)
mEquipBox[i].posY + 2);
if (i == EQUIP_PROJECTILE_SLOT)
{
- g->setColor(guiPalette->getColor(Palette::TEXT));
+ g->setColor(Theme::getThemeColor(Theme::TEXT));
graphics->drawText(toString(item->getQuantity()),
mEquipBox[i].posX + (BOX_WIDTH / 2),
mEquipBox[i].posY - getFont()->getHeight(),
diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp
index a59b0157..e2354386 100644
--- a/src/gui/gui.cpp
+++ b/src/gui/gui.cpp
@@ -168,7 +168,7 @@ void Gui::logic()
else
mMouseCursorAlpha = std::max(0.0f, mMouseCursorAlpha - 0.005f);
- guiPalette->advanceGradient();
+ Palette::advanceGradients();
gcn::Gui::logic();
}
diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp
index ed008e63..701558a9 100644
--- a/src/gui/inventorywindow.cpp
+++ b/src/gui/inventorywindow.cpp
@@ -30,6 +30,7 @@
#include "gui/itemamount.h"
#include "gui/setup.h"
#include "gui/sdlinput.h"
+#include "gui/theme.h"
#include "gui/viewport.h"
#include "gui/widgets/button.h"
@@ -96,8 +97,8 @@ InventoryWindow::InventoryWindow(int invSize):
mSlotsLabel = new Label(_("Slots:"));
mWeightLabel = new Label(_("Weight:"));
- mSlotsBar = new ProgressBar(0.0f, 100, 20, gcn::Color(225, 200, 25));
- mWeightBar = new ProgressBar(0.0f, 100, 20, gcn::Color(0, 0, 255));
+ mSlotsBar = new ProgressBar(0.0f, 100, 20, Theme::PROG_INVY_SLOTS);
+ mWeightBar = new ProgressBar(0.0f, 100, 20, Theme::PROG_WEIGHT);
place(0, 0, mWeightLabel).setPadding(3);
place(1, 0, mWeightBar, 3);
@@ -140,14 +141,6 @@ void InventoryWindow::logic()
mMaxWeight = player_node->getMaxWeight();
mUsedSlots = usedSlots;
- // Weight Bar coloration
- if (mTotalWeight < (mMaxWeight / 3))
- mWeightBar->setColor(0, 0, 255); // Blue
- else if (mTotalWeight < ((mMaxWeight * 2) / 3))
- mWeightBar->setColor(255, 255, 0); // Yellow
- else
- mWeightBar->setColor(255, 0, 0); // Red
-
// Adjust progress bars
mSlotsBar->setProgress((float) mUsedSlots / mMaxSlots);
mWeightBar->setProgress((float) mTotalWeight / mMaxWeight);
diff --git a/src/gui/itempopup.cpp b/src/gui/itempopup.cpp
index 1d41449d..72a46696 100644
--- a/src/gui/itempopup.cpp
+++ b/src/gui/itempopup.cpp
@@ -26,7 +26,7 @@
#include "units.h"
#include "gui/gui.h"
-#include "gui/palette.h"
+#include "gui/theme.h"
#include "gui/widgets/textbox.h"
@@ -136,33 +136,33 @@ gcn::Color ItemPopup::getColor(ItemType type)
switch (type)
{
case ITEM_UNUSABLE:
- return guiPalette->getColor(Palette::GENERIC);
+ return Theme::getThemeColor(Theme::GENERIC);
case ITEM_USABLE:
- return guiPalette->getColor(Palette::USABLE);
+ return Theme::getThemeColor(Theme::USABLE);
case ITEM_EQUIPMENT_ONE_HAND_WEAPON:
- return guiPalette->getColor(Palette::ONEHAND);
+ return Theme::getThemeColor(Theme::ONEHAND);
case ITEM_EQUIPMENT_TWO_HANDS_WEAPON:
- return guiPalette->getColor(Palette::TWOHAND);
+ return Theme::getThemeColor(Theme::TWOHAND);
case ITEM_EQUIPMENT_TORSO:
- return guiPalette->getColor(Palette::TORSO);
+ return Theme::getThemeColor(Theme::TORSO);
case ITEM_EQUIPMENT_ARMS:
- return guiPalette->getColor(Palette::ARMS);
+ return Theme::getThemeColor(Theme::ARMS);
case ITEM_EQUIPMENT_HEAD:
- return guiPalette->getColor(Palette::HEAD);
+ return Theme::getThemeColor(Theme::HEAD);
case ITEM_EQUIPMENT_LEGS:
- return guiPalette->getColor(Palette::LEGS);
+ return Theme::getThemeColor(Theme::LEGS);
case ITEM_EQUIPMENT_SHIELD:
- return guiPalette->getColor(Palette::SHIELD);
+ return Theme::getThemeColor(Theme::SHIELD);
case ITEM_EQUIPMENT_RING:
- return guiPalette->getColor(Palette::RING);
+ return Theme::getThemeColor(Theme::RING);
case ITEM_EQUIPMENT_NECKLACE:
- return guiPalette->getColor(Palette::NECKLACE);
+ return Theme::getThemeColor(Theme::NECKLACE);
case ITEM_EQUIPMENT_FEET:
- return guiPalette->getColor(Palette::FEET);
+ return Theme::getThemeColor(Theme::FEET);
case ITEM_EQUIPMENT_AMMO:
- return guiPalette->getColor(Palette::AMMO);
+ return Theme::getThemeColor(Theme::AMMO);
default:
- return guiPalette->getColor(Palette::UNKNOWN_ITEM);
+ return Theme::getThemeColor(Theme::UNKNOWN_ITEM);
}
}
diff --git a/src/gui/minimap.cpp b/src/gui/minimap.cpp
index 8e5585ad..53d58d2e 100644
--- a/src/gui/minimap.cpp
+++ b/src/gui/minimap.cpp
@@ -30,8 +30,8 @@
#include "map.h"
#include "player.h"
-#include "gui/palette.h"
#include "gui/setup.h"
+#include "gui/userpalette.h"
#include "resources/image.h"
#include "resources/resourcemanager.h"
@@ -201,32 +201,32 @@ void Minimap::draw(gcn::Graphics *graphics)
{
const Player *player = static_cast<const Player*>(being);
- Palette::ColorType type = Palette::PC;
+ int type = UserPalette::PC;
if (being == player_node)
{
- type = Palette::SELF;
+ type = UserPalette::SELF;
dotSize = 3;
}
else if (player->isGM())
{
- type = Palette::GM_NAME;
+ type = UserPalette::GM;
}
else if (player->isInParty())
{
- type = Palette::PARTY;
+ type = UserPalette::PARTY;
}
- graphics->setColor(guiPalette->getColor(type));
+ graphics->setColor(userPalette->getColor(type));
break;
}
case Being::MONSTER:
- graphics->setColor(guiPalette->getColor(Palette::MONSTER));
+ graphics->setColor(userPalette->getColor(UserPalette::MONSTER));
break;
case Being::NPC:
- graphics->setColor(guiPalette->getColor(Palette::NPC));
+ graphics->setColor(userPalette->getColor(UserPalette::NPC));
break;
default:
diff --git a/src/gui/ministatus.cpp b/src/gui/ministatus.cpp
index c11ea171..cdefc391 100644
--- a/src/gui/ministatus.cpp
+++ b/src/gui/ministatus.cpp
@@ -28,9 +28,13 @@
#include "gui/gui.h"
#include "gui/statuswindow.h"
+#include "gui/theme.h"
#include "gui/widgets/progressbar.h"
+#include "net/net.h"
+#include "net/playerhandler.h"
+
#include "utils/stringutils.h"
extern volatile int tick_time;
@@ -38,15 +42,16 @@ extern volatile int tick_time;
MiniStatusWindow::MiniStatusWindow():
Popup("MiniStatus")
{
- mHpBar = new ProgressBar((float) player_node->getHp()
- / (float) player_node->getMaxHp(),
- 100, 20, gcn::Color(0, 171, 34));
- mMpBar = new ProgressBar((float) player_node->getMaxMP()
- / (float) player_node->getMaxMP(),
- 100, 20, gcn::Color(26, 102, 230));
- mXpBar = new ProgressBar((float) player_node->getExp()
- / player_node->getExpNeeded(),
- 100, 20, gcn::Color(143, 192, 211));
+ int max = player_node->getMaxHp();
+ mHpBar = new ProgressBar(max ? (float) player_node->getHp() / max : 0,
+ 100, 20, Theme::PROG_HP);
+ max = player_node->getMaxMP();
+ mMpBar = new ProgressBar(max ? (float) player_node->getMP() / max : 0,
+ 100, 20, Net::getPlayerHandler()->canUseMagic() ?
+ Theme::PROG_MP : Theme::PROG_NO_MP);
+ max = player_node->getExpNeeded();
+ mXpBar = new ProgressBar(max ? (float) player_node->getExp() / max : 0,
+ 100, 20, Theme::PROG_EXP);
mHpBar->setPosition(0, 3);
mMpBar->setPosition(mHpBar->getWidth() + 3, 3);
mXpBar->setPosition(mMpBar->getX() + mMpBar->getWidth() + 3, 3);
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()
diff --git a/src/gui/palette.h b/src/gui/palette.h
index 0c1d2df0..6a5917c2 100644
--- a/src/gui/palette.h
+++ b/src/gui/palette.h
@@ -23,92 +23,24 @@
#ifndef PALETTE_H
#define PALETTE_H
-#include <guichan/listmodel.hpp>
#include <guichan/color.hpp>
#include <cstdlib>
#include <string>
+#include <set>
#include <vector>
-// Generate strings from an enum ... some preprocessor fun.
-#define EDEF(a) a,
-#define LASTEDEF(a) a
-#define ECONFIGSTR(a) Palette::getConfigName(#a),
-#define LASTECONFIGSTR(a) Palette::getConfigName(#a)
-
-#define TEXTENUM(name,def)\
- enum name { def(EDEF,LASTEDEF) };\
- static const std::string name ## Names[]
-#define DEFENUMNAMES(name,def)\
- const std::string Palette::name ## Names[] = { def(ECONFIGSTR,ECONFIGSTR) "" }
-
// Default Gradient Delay
#define GRADIENT_DELAY 40
/**
* Class controlling the game's color palette.
*/
-class Palette : public gcn::ListModel
+class Palette
{
public:
- /** List of all colors that are configurable. */
- #define COLOR_TYPE(ENTRY,LASTENTRY)\
- ENTRY(TEXT)\
- ENTRY(SHADOW)\
- ENTRY(OUTLINE)\
- ENTRY(PROGRESS_BAR)\
- ENTRY(BUTTON)\
- ENTRY(BUTTON_DISABLED)\
- ENTRY(TAB)\
- ENTRY(BACKGROUND)\
- ENTRY(HIGHLIGHT)\
- ENTRY(TAB_HIGHLIGHT)\
- ENTRY(SHOP_WARNING)\
- ENTRY(ITEM_EQUIPPED)\
- ENTRY(CHAT)\
- ENTRY(GM)\
- ENTRY(PLAYER)\
- ENTRY(WHISPER)\
- ENTRY(IS)\
- ENTRY(PARTY)\
- ENTRY(GUILD)\
- ENTRY(SERVER)\
- ENTRY(LOGGER)\
- ENTRY(HYPERLINK)\
- ENTRY(BEING)\
- ENTRY(PC)\
- ENTRY(SELF)\
- ENTRY(GM_NAME)\
- ENTRY(NPC)\
- ENTRY(MONSTER)\
- ENTRY(UNKNOWN_ITEM)\
- ENTRY(GENERIC)\
- ENTRY(HEAD)\
- ENTRY(USABLE)\
- ENTRY(TORSO)\
- ENTRY(ONEHAND)\
- ENTRY(LEGS)\
- ENTRY(FEET)\
- ENTRY(TWOHAND)\
- ENTRY(SHIELD)\
- ENTRY(RING)\
- ENTRY(NECKLACE)\
- ENTRY(ARMS)\
- ENTRY(AMMO)\
- ENTRY(PARTICLE)\
- ENTRY(EXP_INFO)\
- ENTRY(PICKUP_INFO)\
- ENTRY(HIT_PLAYER_MONSTER)\
- ENTRY(HIT_MONSTER_PLAYER)\
- ENTRY(HIT_CRITICAL)\
- ENTRY(MISS)\
- ENTRY(HPBAR_FULL)\
- ENTRY(HPBAR_THREE_QUARTERS)\
- ENTRY(HPBAR_ONE_HALF)\
- ENTRY(HPBAR_ONE_QUARTER)\
- LASTENTRY(TYPE_COUNT)
-
- TEXTENUM(ColorType, COLOR_TYPE);
+ /** Black Color Constant */
+ static const gcn::Color BLACK;
/** Colors can be static or can alter over time. */
enum GradientType {
@@ -119,16 +51,6 @@ class Palette : public gcn::ListModel
};
/**
- * Constructor
- */
- Palette();
-
- /**
- * Destructor
- */
- ~Palette();
-
- /**
* Returns the color associated with a character, if it exists. Returns
* Palette::BLACK if the character is not found.
*
@@ -148,180 +70,78 @@ class Palette : public gcn::ListModel
*
* @return the requested color
*/
- inline const gcn::Color &getColor(ColorType type, int alpha = 255)
+ inline const gcn::Color &getColor(int type, int alpha = 255)
{
- gcn::Color* col = &mColVector[type].color;
+ gcn::Color* col = &mColors[type].color;
col->a = alpha;
return *col;
}
/**
- * Gets the committed color associated with the specified type.
- *
- * @param type the color type requested
- *
- * @return the requested committed color
- */
- inline const gcn::Color &getCommittedColor(ColorType type)
- {
- return mColVector[type].committedColor;
- }
-
- /**
- * Gets the test color associated with the specified type.
- *
- * @param type the color type requested
- *
- * @return the requested test color
- */
- inline const gcn::Color &getTestColor(ColorType type)
- {
- return mColVector[type].testColor;
- }
-
- /**
- * Sets the test color associated with the specified type.
- *
- * @param type the color type requested
- * @param color the color that should be tested
- */
- inline void setTestColor(ColorType type, gcn::Color color)
- {
- mColVector[type].testColor = color;
- }
-
- /**
* Gets the GradientType associated with the specified type.
*
* @param type the color type of the color
*
* @return the gradient type of the color with the given index
*/
- inline GradientType getGradientType(ColorType type)
+ inline GradientType getGradientType(int type)
{
- return mColVector[type].grad;
+ return mColors[type].grad;
}
/**
- * Gets the gradient delay for the specified type.
+ * Get the character used by the specified color.
*
* @param type the color type of the color
*
- * @return the gradient delay of the color with the given index
+ * @return the color char of the color with the given index
*/
- inline int getGradientDelay(ColorType type)
- { return mColVector[type].delay; }
-
- /**
- * Get the character used by the specified color.
- *
- * @param type the color type of the color
- *
- * @return the color char of the color with the given index
- */
- inline char getColorChar(ColorType type)
+ inline char getColorChar(int type)
{
- return mColVector[type].ch;
+ return mColors[type].ch;
}
/**
- * Sets the color for the specified type.
- *
- * @param type color to be set
- * @param r red component
- * @param g green component
- * @param b blue component
- */
- void setColor(ColorType type, int r, int g, int b);
-
- /**
- * Sets the gradient type for the specified color.
- *
- * @param grad gradient type to set
- */
- void setGradient(ColorType type, GradientType grad);
-
- /**
- * Sets the gradient delay for the specified color.
- *
- * @param grad gradient type to set
- */
- void setGradientDelay(ColorType type, int delay)
- { mColVector[type].delay = delay; }
-
- /**
- * Returns the number of colors known.
- *
- * @return the number of colors known
- */
- inline int getNumberOfElements() { return mColVector.size(); }
-
- /**
- * Returns the name of the ith color.
- *
- * @param i index of color interested in
- *
- * @return the name of the color
- */
- std::string getElementAt(int i);
-
- /**
- * Gets the ColorType used by the color for the element at index i in
- * the current color model.
+ * Gets the gradient delay for the specified type.
*
- * @param i the index of the color
+ * @param type the color type of the color
*
- * @return the color type of the color with the given index
- */
- ColorType getColorTypeAt(int i);
-
- /**
- * Commit the colors
- */
- inline void commit()
- {
- commit(false);
- }
-
- /**
- * Rollback the colors
+ * @return the gradient delay of the color with the given index
*/
- void rollback();
+ inline int getGradientDelay(int type)
+ { return mColors[type].delay; }
/**
* Updates all colors, that are non-static.
*/
- void advanceGradient();
-
- private:
- /** Black Color Constant */
- static const gcn::Color BLACK;
+ static void advanceGradients();
+ protected:
/** Colors used for the rainbow gradient */
static const gcn::Color RAINBOW_COLORS[];
static const int RAINBOW_COLOR_COUNT;
+
/** Time tick, that gradient-type colors were updated the last time. */
int mRainbowTime;
+ typedef std::set<Palette*> Palettes;
+ static Palettes mInstances;
+
/**
- * Define a color replacement.
- *
- * @param i the index of the color to replace
- * @param r red component
- * @param g green component
- * @param b blue component
+ * Constructor
*/
- void setColorAt(int i, int r, int g, int b);
+ Palette(int size);
/**
- * Commit the colors. Commit the non-static color values, if
- * commitNonStatic is true. Only needed in the constructor.
+ * Destructor
*/
- void commit(bool commitNonStatic);
+ ~Palette();
+
+ void advanceGradient();
struct ColorElem
{
- ColorType type;
+ int type;
gcn::Color color;
gcn::Color testColor;
gcn::Color committedColor;
@@ -333,7 +153,7 @@ class Palette : public gcn::ListModel
int delay;
int committedDelay;
- void set(ColorType type, gcn::Color& color, GradientType grad,
+ void set(int type, gcn::Color& color, GradientType grad,
const std::string &text, char c, int delay)
{
ColorElem::type = type;
@@ -352,35 +172,10 @@ class Palette : public gcn::ListModel
committedColor.b;
}
};
- typedef std::vector<ColorElem> ColVector;
+ typedef std::vector<ColorElem> Colors;
/** Vector containing the colors. */
- ColVector mColVector;
+ Colors mColors;
std::vector<ColorElem*> mGradVector;
-
- /**
- * Initialise color
- *
- * @param c character that needs initialising
- * @param rgb default color if not found in config
- * @param text identifier of color
- */
- void addColor(ColorType type, int rgb, GradientType grad,
- const std::string &text, char c = 0,
- int delay = GRADIENT_DELAY);
-
- /**
- * Prefixes the given string with "Color", lowercases all letters but
- * the first and all following a '_'. All '_'s will be removed.
- *
- * E.g.: HIT_PLAYER_MONSTER -> HitPlayerMonster
- *
- * @param typeName string to transform
- *
- * @return the transformed string
- */
- static std::string getConfigName(const std::string &typeName);
};
-extern Palette *guiPalette;
-
#endif
diff --git a/src/gui/setup_colors.cpp b/src/gui/setup_colors.cpp
index bc86e362..12dba82a 100644
--- a/src/gui/setup_colors.cpp
+++ b/src/gui/setup_colors.cpp
@@ -23,7 +23,8 @@
#include "configuration.h"
#include "gui/gui.h"
-#include "gui/palette.h"
+#include "gui/theme.h"
+#include "gui/userpalette.h"
#include "gui/widgets/browserbox.h"
#include "gui/widgets/itemlinkhandler.h"
@@ -48,7 +49,7 @@ Setup_Colors::Setup_Colors() :
{
setName(_("Colors"));
- mColorBox = new ListBox(guiPalette);
+ mColorBox = new ListBox(userPalette);
mColorBox->addSelectionListener(this);
mScroll = new ScrollArea(mColorBox);
@@ -227,18 +228,15 @@ void Setup_Colors::action(const gcn::ActionEvent &event)
void Setup_Colors::valueChanged(const gcn::SelectionEvent &event)
{
mSelected = mColorBox->getSelected();
- Palette::ColorType type = guiPalette->getColorTypeAt(mSelected);
- const gcn::Color *col = &guiPalette->getColor(type);
- Palette::GradientType grad = guiPalette->getGradientType(type);
- const int delay = guiPalette->getGradientDelay(type);
-
- std::string msg;
- const char ch = guiPalette->getColorChar(type);
+ int type = userPalette->getColorTypeAt(mSelected);
+ const gcn::Color *col = &userPalette->getColor(type);
+ Palette::GradientType grad = userPalette->getGradientType(type);
+ const int delay = userPalette->getGradientDelay(type);
mPreview->clearRows();
mPreviewBox->setContent(mTextPreview);
- mTextPreview->setFont(gui->getFont());
- mTextPreview->setTextColor(&guiPalette->getColor(Palette::TEXT));
+ mTextPreview->setFont(boldFont);
+ mTextPreview->setTextColor(col);
mTextPreview->setTextBGColor(NULL);
mTextPreview->setOpaque(false);
mTextPreview->setShadow(true);
@@ -247,125 +245,24 @@ void Setup_Colors::valueChanged(const gcn::SelectionEvent &event)
switch (type)
{
- case Palette::TEXT:
- case Palette::SHADOW:
- case Palette::OUTLINE:
- mTextPreview->setFont(gui->getFont());
- mTextPreview->setShadow(type == Palette::SHADOW);
- mTextPreview->setOutline(type == Palette::OUTLINE);
- break;
- case Palette::PROGRESS_BAR:
- mTextPreview->useTextAlpha(true);
- mTextPreview->setFont(boldFont);
- mTextPreview->setTextColor(col);
- mTextPreview->setOutline(true);
- mTextPreview->setShadow(false);
- break;
- case Palette::BUTTON:
- case Palette::BUTTON_DISABLED:
- case Palette::TAB:
- case Palette::TAB_HIGHLIGHT:
- mTextPreview->setFont(gui->getFont());
- mTextPreview->setTextColor(col);
- mTextPreview->setOutline(false);
- mTextPreview->setShadow(false);
- break;
- case Palette::BACKGROUND:
- case Palette::SHOP_WARNING:
- mTextPreview->setBGColor(col);
- mTextPreview->setOpaque(true);
- mTextPreview->setOutline(false);
- mTextPreview->setShadow(false);
- break;
- case Palette::HPBAR_FULL:
- case Palette::HPBAR_THREE_QUARTERS:
- case Palette::HPBAR_ONE_HALF:
- case Palette::HPBAR_ONE_QUARTER:
- mTextPreview->setTextBGColor(col);
- mTextPreview->setFont(boldFont);
- mTextPreview->setTextColor(&guiPalette->getColor(Palette::PROGRESS_BAR));
- mTextPreview->setOutline(true);
- mTextPreview->setShadow(false);
- mPreview->addRow(rawmsg);
- break;
- case Palette::HIGHLIGHT:
- mTextPreview->setTextBGColor(col);
- mTextPreview->setOutline(false);
- mTextPreview->setShadow(false);
- mPreview->addRow(rawmsg);
- break;
- case Palette::CHAT:
- case Palette::GM:
- case Palette::PLAYER:
- case Palette::WHISPER:
- case Palette::IS:
- case Palette::PARTY:
- case Palette::GUILD:
- case Palette::SERVER:
- case Palette::LOGGER:
- case Palette::HYPERLINK:
- mPreviewBox->setContent(mPreview);
- mPreview->clearRows();
-
- if (ch == '<')
- msg = toString("@@|") + rawmsg + "@@";
- else
- msg = "##" + toString(ch) + rawmsg;
-
- mPreview->addRow(msg);
- break;
- case Palette::ITEM_EQUIPPED:
- mTextPreview->setTextColor(col);
- mTextPreview->setOutline(false);
- mTextPreview->setShadow(false);
- break;
- case Palette::UNKNOWN_ITEM:
- case Palette::GENERIC:
- case Palette::HEAD:
- case Palette::USABLE:
- case Palette::TORSO:
- case Palette::ONEHAND:
- case Palette::LEGS:
- case Palette::FEET:
- case Palette::TWOHAND:
- case Palette::SHIELD:
- case Palette::RING:
- case Palette::NECKLACE:
- case Palette::ARMS:
- case Palette::AMMO:
- mTextPreview->setFont(boldFont);
- mTextPreview->setTextColor(col);
- mTextPreview->setOutline(false);
- mTextPreview->setShadow(false);
- break;
- case Palette::PARTICLE:
- case Palette::EXP_INFO:
- case Palette::PICKUP_INFO:
- case Palette::HIT_PLAYER_MONSTER:
- case Palette::HIT_MONSTER_PLAYER:
- case Palette::HIT_CRITICAL:
- case Palette::MISS:
+ case UserPalette::PARTICLE:
+ case UserPalette::EXP_INFO:
+ case UserPalette::PICKUP_INFO:
+ case UserPalette::HIT_PLAYER_MONSTER:
+ case UserPalette::HIT_MONSTER_PLAYER:
+ case UserPalette::HIT_CRITICAL:
+ case UserPalette::MISS:
mTextPreview->setShadow(false);
- case Palette::BEING:
- case Palette::PC:
- case Palette::SELF:
- case Palette::GM_NAME:
- case Palette::NPC:
- case Palette::MONSTER:
- mTextPreview->setFont(boldFont);
- mTextPreview->setTextColor(col);
- case Palette::TYPE_COUNT:
- break;
}
if (grad != Palette::STATIC && grad != Palette::PULSE)
{ // If nonstatic color, don't display the current, but the committed
// color at the sliders
- col = &guiPalette->getCommittedColor(type);
+ col = &userPalette->getCommittedColor(type);
}
else if (grad == Palette::PULSE)
{
- col = &guiPalette->getTestColor(type);
+ col = &userPalette->getTestColor(type);
}
setEntry(mGradDelaySlider, mGradDelayText, delay);
@@ -388,16 +285,16 @@ void Setup_Colors::setEntry(gcn::Slider *s, TextField *t, int value)
void Setup_Colors::apply()
{
- guiPalette->commit();
+ userPalette->commit();
}
void Setup_Colors::cancel()
{
- guiPalette->rollback();
- Palette::ColorType type = guiPalette->getColorTypeAt(mSelected);
- const gcn::Color *col = &guiPalette->getColor(type);
- mGradTypeSlider->setValue(guiPalette->getGradientType(type));
- const int delay = guiPalette->getGradientDelay(type);
+ userPalette->rollback();
+ int type = userPalette->getColorTypeAt(mSelected);
+ const gcn::Color *col = &userPalette->getColor(type);
+ mGradTypeSlider->setValue(userPalette->getGradientType(type));
+ const int delay = userPalette->getGradientDelay(type);
setEntry(mGradDelaySlider, mGradDelayText, delay);
setEntry(mRedSlider, mRedText, col->r);
setEntry(mGreenSlider, mGreenText, col->g);
@@ -426,8 +323,8 @@ void Setup_Colors::updateGradType()
return;
mSelected = mColorBox->getSelected();
- Palette::ColorType type = guiPalette->getColorTypeAt(mSelected);
- Palette::GradientType grad = guiPalette->getGradientType(type);
+ int type = userPalette->getColorTypeAt(mSelected);
+ Palette::GradientType grad = userPalette->getGradientType(type);
mGradTypeText->setCaption(
(grad == Palette::STATIC) ? _("Static") :
@@ -453,23 +350,23 @@ void Setup_Colors::updateColor()
if (mSelected == -1)
return;
- Palette::ColorType type = guiPalette->getColorTypeAt(mSelected);
- Palette::GradientType grad =
- static_cast<Palette::GradientType>((int)mGradTypeSlider->getValue());
+ int type = userPalette->getColorTypeAt(mSelected);
+ Palette::GradientType grad = static_cast<Palette::GradientType>((int)
+ mGradTypeSlider->getValue());
int delay = (int) mGradDelaySlider->getValue();
- guiPalette->setGradient(type, grad);
- guiPalette->setGradientDelay(type, delay);
+ userPalette->setGradient(type, grad);
+ userPalette->setGradientDelay(type, delay);
if (grad == Palette::STATIC)
{
- guiPalette->setColor(type,
+ userPalette->setColor(type,
static_cast<int>(mRedSlider->getValue()),
static_cast<int>(mGreenSlider->getValue()),
static_cast<int>(mBlueSlider->getValue()));
}
else if (grad == Palette::PULSE)
{
- guiPalette->setTestColor(type, gcn::Color(
+ userPalette->setTestColor(type, gcn::Color(
static_cast<int>(mRedSlider->getValue()),
static_cast<int>(mGreenSlider->getValue()),
static_cast<int>(mBlueSlider->getValue())));
diff --git a/src/gui/skilldialog.cpp b/src/gui/skilldialog.cpp
index 76ddd7b0..da244208 100644
--- a/src/gui/skilldialog.cpp
+++ b/src/gui/skilldialog.cpp
@@ -71,6 +71,7 @@ struct SkillInfo
std::string skillExp;
float progress;
+ gcn::Color color;
~SkillInfo()
{
@@ -146,8 +147,8 @@ public:
Graphics *graphics = static_cast<Graphics*>(gcnGraphics);
- graphics->setColor(guiPalette->getColor(Palette::HIGHLIGHT,
- (int)(mAlpha * 255.0f)));
+ graphics->setColor(Theme::getThemeColor(Theme::HIGHLIGHT,
+ (int) (mAlpha * 255.0f)));
graphics->setFont(getFont());
// Draw filled rectangle around the selected list element
@@ -158,7 +159,7 @@ public:
}
// Draw the list elements
- graphics->setColor(guiPalette->getColor(Palette::TEXT));
+ graphics->setColor(Theme::getThemeColor(Theme::TEXT));
for (int i = 0, y = 1;
i < model->getNumberOfElements();
++i, y += getRowHeight())
@@ -429,6 +430,8 @@ void SkillInfo::update()
progress = 0.0f;
}
+ color = Theme::getProgressColor(Theme::PROG_EXP, progress);
+
if (updateVisibility)
{
model->updateVisibilities();
@@ -452,7 +455,6 @@ void SkillInfo::draw(Graphics *graphics, int y, int width)
{
gcn::Rectangle rect(33, y + 15, width - 33, 17);
- ProgressBar::render(graphics, rect, gcn::Color(143, 192, 211),
- progress, skillExp);
+ ProgressBar::render(graphics, rect, color, progress, skillExp);
}
}
diff --git a/src/gui/socialwindow.cpp b/src/gui/socialwindow.cpp
index 5da8018c..904a710b 100644
--- a/src/gui/socialwindow.cpp
+++ b/src/gui/socialwindow.cpp
@@ -30,6 +30,7 @@
#include "gui/okdialog.h"
#include "gui/setup.h"
#include "gui/textdialog.h"
+#include "gui/theme.h"
#include "gui/widgets/avatarlistbox.h"
#include "gui/widgets/browserbox.h"
@@ -98,7 +99,7 @@ public:
{
setCaption(guild->getName());
- setTabColor(&guiPalette->getColor(Palette::GUILD));
+ setTabColor(&Theme::getThemeColor(Theme::GUILD));
mList = new AvatarListBox(guild);
mScroll = new ScrollArea(mList);
@@ -163,7 +164,7 @@ public:
{
setCaption(party->getName());
- setTabColor(&guiPalette->getColor(Palette::PARTY));
+ setTabColor(&Theme::getThemeColor(Theme::PARTY));
mList = new AvatarListBox(party);
mScroll = new ScrollArea(mList);
diff --git a/src/gui/speechbubble.cpp b/src/gui/speechbubble.cpp
index 5cc5772d..8d7458aa 100644
--- a/src/gui/speechbubble.cpp
+++ b/src/gui/speechbubble.cpp
@@ -46,7 +46,7 @@ SpeechBubble::SpeechBubble():
mSpeechBox = new TextBox;
mSpeechBox->setEditable(false);
mSpeechBox->setOpaque(false);
- mSpeechBox->setTextColor(&guiPalette->getColor(Palette::CHAT));
+ mSpeechBox->setTextColor(&Theme::getThemeColor(Theme::CHAT));
add(mCaption);
add(mSpeechBox);
@@ -66,7 +66,7 @@ void SpeechBubble::setText(const std::string &text, bool showName)
if (text == mText && (mCaption->getWidth() <= mSpeechBox->getMinWidth()))
return;
- mSpeechBox->setTextColor(&guiPalette->getColor(Palette::TEXT));
+ mSpeechBox->setTextColor(&Theme::getThemeColor(Theme::TEXT));
int width = mCaption->getWidth() + 2 * getPadding();
mSpeechBox->setTextWrapped(text, 130 > width ? 130 : width);
diff --git a/src/gui/speechbubble.h b/src/gui/speechbubble.h
index 6d393d74..8682ab7e 100644
--- a/src/gui/speechbubble.h
+++ b/src/gui/speechbubble.h
@@ -23,7 +23,7 @@
#ifndef SPEECHBUBBLE_H
#define SPEECHBUBBLE_H
-#include "gui/palette.h"
+#include "gui/theme.h"
#include "gui/widgets/popup.h"
@@ -42,7 +42,7 @@ class SpeechBubble : public Popup
*/
void setCaption(const std::string &name,
const gcn::Color *color =
- &guiPalette->getColor(Palette::TEXT));
+ &Theme::getThemeColor(Theme::TEXT));
/**
* Sets the text to be displayed.
diff --git a/src/gui/statuswindow.cpp b/src/gui/statuswindow.cpp
index 7ea2cf18..e5d59624 100644
--- a/src/gui/statuswindow.cpp
+++ b/src/gui/statuswindow.cpp
@@ -26,6 +26,7 @@
#include "gui/ministatus.h"
#include "gui/setup.h"
+#include "gui/theme.h"
#include "gui/widgets/button.h"
#include "gui/widgets/label.h"
@@ -99,22 +100,21 @@ StatusWindow::StatusWindow():
mLvlLabel = new Label(strprintf(_("Level: %d"), 0));
mMoneyLabel = new Label(strprintf(_("Money: %s"), ""));
+ int max = player_node->getMaxHp();
mHpLabel = new Label(_("HP:"));
- mHpBar = new ProgressBar((float) player_node->getHp()
- / (float) player_node->getMaxHp(),
- 80, 15, gcn::Color(0, 171, 34));
+ mHpBar = new ProgressBar(max ? (float) player_node->getHp() / max: 0,
+ 80, 15, Theme::PROG_HP);
+ max = player_node->getExpNeeded();
mXpLabel = new Label(_("Exp:"));
- mXpBar = new ProgressBar((float) player_node->getExp()
- / player_node->getExpNeeded(),
- 80, 15, gcn::Color(143, 192, 211));
+ mXpBar = new ProgressBar(max ? (float) player_node->getExp() / max : 0,
+ 80, 15, Theme::PROG_EXP);
+ max = player_node->getMaxMP();
mMpLabel = new Label(_("MP:"));
- mMpBar = new ProgressBar((float) player_node->getMaxMP()
- / (float) player_node->getMaxMP(),
+ mMpBar = new ProgressBar(max ? (float) player_node->getMaxMP() / max : 0,
80, 15, Net::getPlayerHandler()->canUseMagic() ?
- gcn::Color(26, 102, 230) :
- gcn::Color(100, 100, 100));
+ Theme::PROG_MP : Theme::PROG_NO_MP);
place(0, 0, mLvlLabel, 3);
// 5, 0 Job Level
@@ -131,7 +131,7 @@ StatusWindow::StatusWindow():
{
mJobLvlLabel = new Label(strprintf(_("Job: %d"), 0));
mJobLabel = new Label(_("Job:"));
- mJobBar = new ProgressBar(0.0f, 80, 15, gcn::Color(220, 135, 203));
+ mJobBar = new ProgressBar(0.0f, 80, 15, Theme::PROG_JOB);
place(5, 0, mJobLvlLabel, 3);
place(5, 2, mJobLabel).setPadding(3);
@@ -303,84 +303,8 @@ void StatusWindow::updateHPBar(ProgressBar *bar, bool showMax)
else
bar->setText(toString(player_node->getHp()));
- if (player_node->getMaxHp() < 4)
- {
- bar->setColor(guiPalette->getColor(Palette::HPBAR_ONE_QUARTER));
- }
- else
- {
- // HP Bar coloration
- float r1 = 255;
- float g1 = 255;
- float b1 = 255;
-
- float r2 = 255;
- float g2 = 255;
- float b2 = 255;
-
- float weight = 1.0f;
-
- int curHP = player_node->getHp();
- int thresholdLevel = player_node->getMaxHp() / 4;
- int thresholdProgress = curHP % thresholdLevel;
-
- if (thresholdLevel)
- weight = 1 - ((float)thresholdProgress) / ((float)thresholdLevel);
- else
- weight = 0;
-
- if (curHP < (thresholdLevel))
- {
- gcn::Color color1 = guiPalette->getColor(Palette::HPBAR_ONE_HALF);
- gcn::Color color2 = guiPalette->getColor(Palette::HPBAR_ONE_QUARTER);
- r1 = color1.r; r2 = color2.r;
- g1 = color1.g; g2 = color2.g;
- b1 = color1.b; b2 = color2.b;
- }
- else if (curHP < (thresholdLevel*2))
- {
- gcn::Color color1 = guiPalette->getColor(Palette::HPBAR_THREE_QUARTERS);
- gcn::Color color2 = guiPalette->getColor(Palette::HPBAR_ONE_HALF);
- r1 = color1.r; r2 = color2.r;
- g1 = color1.g; g2 = color2.g;
- b1 = color1.b; b2 = color2.b;
- }
- else if (curHP < thresholdLevel*3)
- {
- gcn::Color color1 = guiPalette->getColor(Palette::HPBAR_FULL);
- gcn::Color color2 = guiPalette->getColor(Palette::HPBAR_THREE_QUARTERS);
- r1 = color1.r; r2 = color2.r;
- g1 = color1.g; g2 = color2.g;
- b1 = color1.b; b2 = color2.b;
- }
- else
- {
- gcn::Color color1 = guiPalette->getColor(Palette::HPBAR_FULL);
- gcn::Color color2 = guiPalette->getColor(Palette::HPBAR_FULL);
- r1 = color1.r; r2 = color2.r;
- g1 = color1.g; g2 = color2.g;
- b1 = color1.b; b2 = color2.b;
- }
-
- // Safety checks
- if (weight > 1.0f) weight = 1.0f;
- if (weight < 0.0f) weight = 0.0f;
-
- // Do the color blend
- r1 = (int) weightedAverage(r1, r2,weight);
- g1 = (int) weightedAverage(g1, g2, weight);
- b1 = (int) weightedAverage(b1, b2, weight);
-
- // More safety checks
- if (r1 > 255) r1 = 255;
- if (g1 > 255) g1 = 255;
- if (b1 > 255) b1 = 255;
-
- bar->setColor((int)r1,(int)g1, (int)b1);
- }
-
- bar->setProgress((float) player_node->getHp() / (float) player_node->getMaxHp());
-
+ float prog = (float) player_node->getHp() / player_node->getMaxHp();
+ bar->setProgress(prog);
}
void StatusWindow::updateMPBar(ProgressBar *bar, bool showMax)
@@ -391,13 +315,14 @@ void StatusWindow::updateMPBar(ProgressBar *bar, bool showMax)
else
bar->setText(toString(player_node->getMP()));
+ float prog = (float) player_node->getMP() / player_node->getMaxMP();
+
if (Net::getPlayerHandler()->canUseMagic())
- bar->setColor(26, 102, 230); // blue, to indicate that we have magic
+ bar->setProgressPalette(Theme::PROG_MP);
else
- bar->setColor(100, 100, 100); // grey, to indicate that we lack magic
+ bar->setProgressPalette(Theme::PROG_NO_MP);
- bar->setProgress((float) player_node->getMP() /
- (float) player_node->getMaxMP());
+ bar->setProgress(prog);
}
void StatusWindow::updateProgressBar(ProgressBar *bar, int value, int max,
@@ -423,8 +348,8 @@ void StatusWindow::updateProgressBar(ProgressBar *bar, int value, int max,
void StatusWindow::updateXPBar(ProgressBar *bar, bool percent)
{
- updateProgressBar(bar, player_node->getExp(), player_node->getExpNeeded(),
- percent);
+ updateProgressBar(bar, player_node->getExp(),
+ player_node->getExpNeeded(), percent);
}
void StatusWindow::updateProgressBar(ProgressBar *bar, int id, bool percent)
diff --git a/src/gui/statuswindow.h b/src/gui/statuswindow.h
index 05a6cb01..13ee9a68 100644
--- a/src/gui/statuswindow.h
+++ b/src/gui/statuswindow.h
@@ -67,7 +67,7 @@ class StatusWindow : public Window
static void updateMPBar(ProgressBar *bar, bool showMax = false);
static void updateXPBar(ProgressBar *bar, bool percent = true);
static void updateProgressBar(ProgressBar *bar, int value, int max,
- bool percent);
+ bool percent);
void updateProgressBar(ProgressBar *bar, int id,
bool percent = true);
diff --git a/src/gui/storagewindow.cpp b/src/gui/storagewindow.cpp
index bf54afb9..579725c4 100644
--- a/src/gui/storagewindow.cpp
+++ b/src/gui/storagewindow.cpp
@@ -30,6 +30,7 @@
#include "gui/inventorywindow.h"
#include "gui/itemamount.h"
#include "gui/setup.h"
+#include "gui/theme.h"
#include "gui/viewport.h"
#include "gui/widgets/button.h"
@@ -82,7 +83,7 @@ StorageWindow::StorageWindow(Inventory *inventory):
mSlotsLabel = new Label(_("Slots:"));
- mSlotsBar = new ProgressBar(0.0f, 100, 20, gcn::Color(225, 200, 25));
+ mSlotsBar = new ProgressBar(0.0f, 100, 20, Theme::PROG_INVY_SLOTS);
mSlotsBar->setText(strprintf("%d/%d", mUsedSlots, mInventory->getSize()));
mSlotsBar->setProgress((float) mUsedSlots / mInventory->getSize());
diff --git a/src/gui/theme.cpp b/src/gui/theme.cpp
index 961694e6..1841f8d9 100644
--- a/src/gui/theme.cpp
+++ b/src/gui/theme.cpp
@@ -27,6 +27,7 @@
#include "configuration.h"
#include "log.h"
+#include "resources/dye.h"
#include "resources/image.h"
#include "resources/imageset.h"
#include "resources/resourcemanager.h"
@@ -39,6 +40,8 @@
#include <algorithm>
+#define GUI_ROOT "graphics/gui"
+
std::string Theme::mThemePath;
Theme *Theme::mInstance = 0;
@@ -92,9 +95,12 @@ int Skin::getMinHeight() const
}
Theme::Theme():
- mMinimumOpacity(-1.0f)
+ Palette(THEME_COLORS_END),
+ mMinimumOpacity(-1.0f),
+ mProgressColors(ProgressColors(THEME_PROG_END))
{
config.addListener("guialpha", this);
+ loadColors();
}
Theme::~Theme()
@@ -117,6 +123,18 @@ void Theme::deleteInstance()
mInstance = 0;
}
+gcn::Color Theme::getProgressColor(int type, float progress)
+{
+ DyePalette *dye = mInstance->mProgressColors[type];
+
+ int color[3] = {0, 0, 0};
+ int intensity = (int) (255 * progress);
+
+ dye->getColor(intensity, color);
+
+ return gcn::Color(color[0], color[1], color[2]);
+}
+
Skin *Theme::load(const std::string &filename, const std::string &defaultPath)
{
// Check if this skin was already loaded
@@ -283,7 +301,7 @@ bool Theme::tryThemePath(std::string themePath)
{
if (!themePath.empty())
{
- themePath = "graphics/gui/" + themePath;
+ themePath = GUI_ROOT + themePath;
if (PHYSFS_exists(themePath.c_str()))
{
mThemePath = themePath;
@@ -297,15 +315,13 @@ bool Theme::tryThemePath(std::string themePath)
void Theme::prepareThemePath()
{
// Try theme from settings
- if (tryThemePath(config.getValue("theme", "")))
- return;
+ if (!tryThemePath(config.getValue("theme", "")))
+ // Try theme from branding
+ if (!tryThemePath(branding.getValue("theme", "")))
+ // Use default
+ mThemePath = GUI_ROOT;
- // Try theme from branding
- if (tryThemePath(branding.getValue("theme", "")))
- return;
-
- // Use default
- mThemePath = "graphics/gui";
+ instance()->loadColors(mThemePath);
}
std::string Theme::resolveThemePath(const std::string &path)
@@ -328,7 +344,7 @@ std::string Theme::resolveThemePath(const std::string &path)
return getThemePath() + "/" + path;
// Backup
- return "graphics/gui/" + path;
+ return std::string(GUI_ROOT) + "/" + path;
}
Image *Theme::getImageFromTheme(const std::string &path)
@@ -343,3 +359,190 @@ ImageSet *Theme::getImageSetFromTheme(const std::string &path,
ResourceManager *resman = ResourceManager::getInstance();
return resman->getImageSet(resolveThemePath(path), w, h);
}
+
+static int readColorType(const std::string &type)
+{
+ static std::string colors[] = {
+ "TEXT",
+ "SHADOW",
+ "OUTLINE",
+ "PROGRESS_BAR",
+ "BUTTON",
+ "BUTTON_DISABLED",
+ "TAB",
+ "BACKGROUND",
+ "HIGHLIGHT",
+ "TAB_FLASH",
+ "SHOP_WARNING",
+ "ITEM_EQUIPPED",
+ "CHAT",
+ "GM",
+ "PLAYER",
+ "WHISPER",
+ "IS",
+ "PARTY",
+ "GUILD",
+ "SERVER",
+ "LOGGER",
+ "HYPERLINK",
+ "UNKNOWN_ITEM",
+ "GENERIC",
+ "HEAD",
+ "USABLE",
+ "TORSO",
+ "ONEHAND",
+ "LEGS",
+ "FEET",
+ "TWOHAND",
+ "SHIELD",
+ "RING",
+ "NECKLACE",
+ "ARMS",
+ "AMMO"
+ };
+
+ if (type.empty())
+ return -1;
+
+ for (int i = 0; i < Theme::THEME_COLORS_END; i++)
+ {
+ if (compareStrI(type, colors[i]) == 0)
+ {
+ return i;
+ }
+ }
+
+ return -1;
+}
+
+static gcn::Color readColor(const std::string &description)
+{
+ int size = description.length();
+ if (size < 7 || description[0] != '#')
+ {
+ error:
+ logger->log("Error, invalid theme color palette: %s",
+ description.c_str());
+ return Palette::BLACK;
+ }
+
+ int v = 0;
+ for (int i = 1; i < 7; ++i)
+ {
+ char c = description[i];
+ int n;
+
+ if ('0' <= c && c <= '9')
+ n = c - '0';
+ else if ('A' <= c && c <= 'F')
+ n = c - 'A' + 10;
+ else if ('a' <= c && c <= 'f')
+ n = c - 'a' + 10;
+ else
+ goto error;
+
+ v = (v << 4) | n;
+ }
+
+ return gcn::Color(v);
+}
+
+static Palette::GradientType readColorGradient(const std::string &grad)
+{
+ static std::string grads[] = {
+ "STATIC",
+ "PULSE",
+ "SPECTRUM",
+ "RAINBOW"
+ };
+
+ if (grad.empty())
+ return Palette::STATIC;
+
+ for (int i = 0; i < 4; i++)
+ {
+ if (compareStrI(grad, grads[i]))
+ return (Palette::GradientType) i;
+ }
+
+ return Palette::STATIC;
+}
+
+static int readProgressType(const std::string &type)
+{
+ static std::string colors[] = {
+ "DEFAULT",
+ "HP",
+ "MP",
+ "NO_MP",
+ "EXP",
+ "INVY_SLOTS",
+ "WEIGHT",
+ "JOB"
+ };
+
+ if (type.empty())
+ return -1;
+
+ for (int i = 0; i < Theme::THEME_PROG_END; i++)
+ {
+ if (compareStrI(type, colors[i]) == 0)
+ return i;
+ }
+
+ return -1;
+}
+
+void Theme::loadColors(std::string file)
+{
+ if (file == GUI_ROOT)
+ return; // No need to reload
+
+ if (file == "")
+ file = GUI_ROOT;
+
+ file += "/colors.xml";
+
+ XML::Document doc(file);
+ xmlNodePtr root = doc.rootNode();
+
+ if (!root || !xmlStrEqual(root->name, BAD_CAST "colors"))
+ {
+ logger->log("Error loading colors file: %s", file.c_str());
+ return;
+ }
+
+ int type;
+ std::string temp;
+ gcn::Color color;
+ GradientType grad;
+
+ for_each_xml_child_node(node, root)
+ {
+ if (xmlStrEqual(node->name, BAD_CAST "color"))
+ {
+ type = readColorType(XML::getProperty(node, "id", ""));
+ if (type < 0) // invalid or no type given
+ continue;
+
+ temp = XML::getProperty(node, "color", "");
+ if (temp.empty()) // no color set, so move on
+ continue;
+
+ color = readColor(temp);
+ grad = readColorGradient(XML::getProperty(node, "effect", ""));
+
+ mColors[type].set(type, color, grad, "", 0, 10);
+ }
+
+ if (xmlStrEqual(node->name, BAD_CAST "progressbar"))
+ {
+ type = readProgressType(XML::getProperty(node, "id", ""));
+ if (type < 0) // invalid or no type given
+ continue;
+
+ mProgressColors[type] = new DyePalette(XML::getProperty(node,
+ "color", ""));
+ }
+ }
+}
diff --git a/src/gui/theme.h b/src/gui/theme.h
index abc2612f..4dd63660 100644
--- a/src/gui/theme.h
+++ b/src/gui/theme.h
@@ -27,11 +27,15 @@
#include "configlistener.h"
#include "graphics.h"
+#include "gui/palette.h"
+
#include <map>
#include <string>
+class DyePalette;
class Image;
class ImageSet;
+class ProgressBar;
class Skin
{
@@ -96,7 +100,7 @@ class Skin
Image *mStickyImageDown; /**< Sticky Button Image */
};
-class Theme : public ConfigListener
+class Theme : public Palette, public ConfigListener
{
public:
static Theme *instance();
@@ -115,6 +119,79 @@ class Theme : public ConfigListener
static ImageSet *getImageSetFromTheme(const std::string &path,
int w, int h);
+ enum ThemePalette {
+ TEXT,
+ SHADOW,
+ OUTLINE,
+ PROGRESS_BAR,
+ BUTTON,
+ BUTTON_DISABLED,
+ TAB,
+ BACKGROUND,
+ HIGHLIGHT,
+ TAB_FLASH,
+ SHOP_WARNING,
+ ITEM_EQUIPPED,
+ CHAT,
+ GM,
+ PLAYER,
+ WHISPER,
+ IS,
+ PARTY,
+ GUILD,
+ SERVER,
+ LOGGER,
+ HYPERLINK,
+ UNKNOWN_ITEM,
+ GENERIC,
+ HEAD,
+ USABLE,
+ TORSO,
+ ONEHAND,
+ LEGS,
+ FEET,
+ TWOHAND,
+ SHIELD,
+ RING,
+ NECKLACE,
+ ARMS,
+ AMMO,
+ THEME_COLORS_END
+ };
+
+ enum ProgressPalette {
+ PROG_DEFAULT,
+ PROG_HP,
+ PROG_MP,
+ PROG_NO_MP,
+ PROG_EXP,
+ PROG_INVY_SLOTS,
+ PROG_WEIGHT,
+ PROG_JOB,
+ THEME_PROG_END
+ };
+
+ /**
+ * Gets the color associated with the type. Sets the alpha channel
+ * before returning.
+ *
+ * @param type the color type requested
+ * @param alpha alpha channel to use
+ *
+ * @return the requested color
+ */
+ inline static const gcn::Color &getThemeColor(int type, int alpha = 255)
+ {
+ return mInstance->getColor(type, alpha);
+ }
+
+ const static gcn::Color &getThemeColor(char c, bool &valid)
+ {
+ return mInstance->getColor(c, valid);
+ }
+
+ static gcn::Color getProgressColor(int type, float progress);
+
/**
* Loads a skin.
*/
@@ -152,21 +229,21 @@ class Theme : public ConfigListener
Skins mSkins;
- /**
- * The config listener that listens to changes relevant to all skins.
- */
- ConfigListener *mSkinConfigListener;
-
static std::string mThemePath;
static Theme *mInstance;
static bool tryThemePath(std::string themePath);
+ void loadColors(std::string file = "");
+
/**
* Tells if the current skins opacity
* should not get less than the given value
*/
float mMinimumOpacity;
+
+ typedef std::vector<DyePalette*> ProgressColors;
+ ProgressColors mProgressColors;
};
#endif
diff --git a/src/gui/updatewindow.cpp b/src/gui/updatewindow.cpp
index 743f3936..975fdcff 100644
--- a/src/gui/updatewindow.cpp
+++ b/src/gui/updatewindow.cpp
@@ -140,7 +140,7 @@ UpdaterWindow::UpdaterWindow(const std::string &updateHost,
mBrowserBox = new BrowserBox;
mScrollArea = new ScrollArea(mBrowserBox);
mLabel = new Label(_("Connecting..."));
- mProgressBar = new ProgressBar(0.0, 310, 20, gcn::Color(168, 116, 31));
+ mProgressBar = new ProgressBar(0.0, 310, 20);
mCancelButton = new Button(_("Cancel"), "cancel", this);
mPlayButton = new Button(_("Play"), "play", this);
diff --git a/src/gui/userpalette.cpp b/src/gui/userpalette.cpp
new file mode 100644
index 00000000..71cb054c
--- /dev/null
+++ b/src/gui/userpalette.cpp
@@ -0,0 +1,237 @@
+/*
+ * Configurable text colors
+ * Copyright (C) 2008 Douglas Boffey <dougaboffey@netscape.net>
+ * Copyright (C) 2009 The Mana World Development Team
+ * Copyright (C) 2009-2010 The Mana Developers
+ *
+ * This file is part of The Mana Client.
+ *
+ * This program 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 2 of the License, or
+ * any later version.
+ *
+ * This program 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 <http://www.gnu.org/licenses/>.
+ */
+
+#include "userpalette.h"
+
+#include "configuration.h"
+#include "client.h"
+
+#include "gui/gui.h"
+
+#include "utils/gettext.h"
+#include "utils/stringutils.h"
+
+#include <math.h>
+
+const std::string ColorTypeNames[] = {
+ "Being",
+ "Player",
+ "Self",
+ "GM",
+ "NPC",
+ "Monster",
+ "Party",
+ "Guild",
+ "Particle",
+ "Experience",
+ "Pickup",
+ "Hit Player Monster",
+ "Hit Monster Player",
+ "Hit Critical",
+ "Miss"
+};
+
+std::string UserPalette::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;
+}
+
+UserPalette::UserPalette():
+ Palette(USER_COLOR_LAST)
+{
+ mColors[BEING] = ColorElem();
+ mColors[PC] = ColorElem();
+ mColors[SELF] = ColorElem();
+ mColors[GM] = ColorElem();
+ mColors[NPC] = ColorElem();
+ mColors[MONSTER] = ColorElem();
+
+ addColor(BEING, 0xffffff, STATIC, _("Being"));
+ addColor(PC, 0xffffff, STATIC, _("Other Players' Names"));
+ addColor(SELF, 0xff8040, STATIC, _("Own Name"));
+ addColor(GM, 0x00ff00, STATIC, _("GM Names"));
+ addColor(NPC, 0xc8c8ff, STATIC, _("NPCs"));
+ addColor(MONSTER, 0xff4040, STATIC, _("Monsters"));
+ addColor(PARTY, 0xff00d8, STATIC, _("Party Members"));
+ addColor(GUILD, 0xff00d8, STATIC, _("Guild Members"));
+ addColor(PARTICLE, 0xffffff, STATIC, _("Particle Effects"));
+ addColor(PICKUP_INFO, 0x28dc28, STATIC, _("Pickup Notification"));
+ addColor(EXP_INFO, 0xffff00, STATIC, _("Exp Notification"));
+ addColor(HIT_PLAYER_MONSTER, 0x0064ff, STATIC, _("Player Hits Monster"));
+ addColor(HIT_MONSTER_PLAYER, 0xff3232, STATIC, _("Monster Hits Player"));
+ addColor(HIT_CRITICAL, 0xff0000, RAINBOW, _("Critical Hit"));
+ addColor(MISS, 0xffff00, STATIC, _("Misses"));
+ commit(true);
+}
+
+UserPalette::~UserPalette()
+{
+ for (Colors::iterator col = mColors.begin(),
+ colEnd = mColors.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));
+ }
+ }
+}
+
+void UserPalette::setColor(int type, int r, int g, int b)
+{
+ mColors[type].color.r = r;
+ mColors[type].color.g = g;
+ mColors[type].color.b = b;
+}
+
+void UserPalette::setGradient(int type, GradientType grad)
+{
+ ColorElem *elem = &mColors[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 UserPalette::getElementAt(int i)
+{
+ if (i < 0 || i >= getNumberOfElements())
+ {
+ return "";
+ }
+ return mColors[i].text;
+}
+
+void UserPalette::commit(bool commitNonStatic)
+{
+ for (Colors::iterator i = mColors.begin(), iEnd = mColors.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 UserPalette::rollback()
+{
+ for (Colors::iterator i = mColors.begin(), iEnd = mColors.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;
+ }
+ }
+}
+
+int UserPalette::getColorTypeAt(int i)
+{
+ if (i < 0 || i >= getNumberOfElements())
+ {
+ return BEING;
+ }
+
+ return mColors[i].type;
+}
+
+void UserPalette::addColor(int 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);
+ mColors[type].set(type, trueCol, grad, text, c, delay);
+
+ if (grad != STATIC)
+ mGradVector.push_back(&mColors[type]);
+}
diff --git a/src/gui/userpalette.h b/src/gui/userpalette.h
new file mode 100644
index 00000000..7863f8cd
--- /dev/null
+++ b/src/gui/userpalette.h
@@ -0,0 +1,208 @@
+/*
+ * Configurable text colors
+ * Copyright (C) 2008 Douglas Boffey <dougaboffey@netscape.net>
+ * Copyright (C) 2009 The Mana World Development Team
+ * Copyright (C) 2009-2010 The Mana Developers
+ *
+ * This file is part of The Mana Client.
+ *
+ * This program 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 2 of the License, or
+ * any later version.
+ *
+ * This program 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 <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef USER_PALETTE_H
+#define USER_PALETTE_H
+
+#include "gui/palette.h"
+
+#include <guichan/listmodel.hpp>
+
+/**
+ * Class controlling the game's color palette.
+ */
+class UserPalette : public Palette, public gcn::ListModel
+{
+ public:
+ /** List of all colors that are configurable. */
+ enum {
+ BEING,
+ PC,
+ SELF,
+ GM,
+ NPC,
+ MONSTER,
+ PARTY,
+ GUILD,
+ PARTICLE,
+ EXP_INFO,
+ PICKUP_INFO,
+ HIT_PLAYER_MONSTER,
+ HIT_MONSTER_PLAYER,
+ HIT_CRITICAL,
+ MISS,
+ USER_COLOR_LAST
+ };
+
+ /**
+ * Constructor
+ */
+ UserPalette();
+
+ /**
+ * Destructor
+ */
+ ~UserPalette();
+
+ /**
+ * Gets the committed color associated with the specified type.
+ *
+ * @param type the color type requested
+ *
+ * @return the requested committed color
+ */
+ inline const gcn::Color &getCommittedColor(int type)
+ {
+ return mColors[type].committedColor;
+ }
+
+ /**
+ * Gets the test color associated with the specified type.
+ *
+ * @param type the color type requested
+ *
+ * @return the requested test color
+ */
+ inline const gcn::Color &getTestColor(int type)
+ {
+ return mColors[type].testColor;
+ }
+
+ /**
+ * Sets the test color associated with the specified type.
+ *
+ * @param type the color type requested
+ * @param color the color that should be tested
+ */
+ inline void setTestColor(int type, gcn::Color color)
+ {
+ mColors[type].testColor = color;
+ }
+
+ /**
+ * Sets the color for the specified type.
+ *
+ * @param type color to be set
+ * @param r red component
+ * @param g green component
+ * @param b blue component
+ */
+ void setColor(int type, int r, int g, int b);
+
+ /**
+ * Sets the gradient type for the specified color.
+ *
+ * @param grad gradient type to set
+ */
+ void setGradient(int type, Palette::GradientType grad);
+
+ /**
+ * Sets the gradient delay for the specified color.
+ *
+ * @param grad gradient type to set
+ */
+ void setGradientDelay(int type, int delay)
+ { mColors[type].delay = delay; }
+
+ /**
+ * Returns the number of colors known.
+ *
+ * @return the number of colors known
+ */
+ inline int getNumberOfElements() { return mColors.size(); }
+
+ /**
+ * Returns the name of the ith color.
+ *
+ * @param i index of color interested in
+ *
+ * @return the name of the color
+ */
+ std::string getElementAt(int i);
+
+ /**
+ * Commit the colors
+ */
+ inline void commit()
+ {
+ commit(false);
+ }
+
+ /**
+ * Rollback the colors
+ */
+ void rollback();
+
+ /**
+ * Gets the ColorType used by the color for the element at index i in
+ * the current color model.
+ *
+ * @param i the index of the color
+ *
+ * @return the color type of the color with the given index
+ */
+ int getColorTypeAt(int i);
+
+ private:
+ /**
+ * Define a color replacement.
+ *
+ * @param i the index of the color to replace
+ * @param r red component
+ * @param g green component
+ * @param b blue component
+ */
+ void setColorAt(int i, int r, int g, int b);
+
+ /**
+ * Commit the colors. Commit the non-static color values, if
+ * commitNonStatic is true. Only needed in the constructor.
+ */
+ void commit(bool commitNonStatic);
+
+ /**
+ * Prefixes the given string with "Color", lowercases all letters but
+ * the first and all following a '_'. All '_'s will be removed.
+ *
+ * E.g.: HIT_PLAYER_MONSTER -> HitPlayerMonster
+ *
+ * @param typeName string to transform
+ *
+ * @return the transformed string
+ */
+ static std::string getConfigName(const std::string &typeName);
+
+ /**
+ * Initialise color
+ *
+ * @param c character that needs initialising
+ * @param rgb default color if not found in config
+ * @param text identifier of color
+ */
+ void addColor(int type, int rgb, GradientType grad,
+ const std::string &text, char c = 0,
+ int delay = GRADIENT_DELAY);
+};
+
+extern UserPalette *userPalette;
+
+#endif // USER_PALETTE_H
diff --git a/src/gui/widgets/avatarlistbox.cpp b/src/gui/widgets/avatarlistbox.cpp
index 17651137..0235d104 100644
--- a/src/gui/widgets/avatarlistbox.cpp
+++ b/src/gui/widgets/avatarlistbox.cpp
@@ -74,8 +74,8 @@ void AvatarListBox::draw(gcn::Graphics *gcnGraphics)
Graphics *graphics = static_cast<Graphics*>(gcnGraphics);
- graphics->setColor(guiPalette->getColor(Palette::HIGHLIGHT,
- (int)(mAlpha * 255.0f)));
+ graphics->setColor(Theme::getThemeColor(Theme::HIGHLIGHT,
+ (int) (mAlpha * 255.0f)));
graphics->setFont(getFont());
const int fontHeight = getFont()->getHeight();
@@ -89,7 +89,7 @@ void AvatarListBox::draw(gcn::Graphics *gcnGraphics)
int width = 0;
// Draw the list elements
- graphics->setColor(guiPalette->getColor(Palette::TEXT));
+ graphics->setColor(Theme::getThemeColor(Theme::TEXT));
for (int i = 0, y = 0;
i < model->getNumberOfElements();
++i, y += fontHeight)
diff --git a/src/gui/widgets/browserbox.cpp b/src/gui/widgets/browserbox.cpp
index de4f7a40..d43afed7 100644
--- a/src/gui/widgets/browserbox.cpp
+++ b/src/gui/widgets/browserbox.cpp
@@ -21,7 +21,7 @@
#include "gui/widgets/browserbox.h"
-#include "gui/palette.h"
+#include "gui/theme.h"
#include "gui/widgets/linkhandler.h"
@@ -268,7 +268,7 @@ void BrowserBox::draw(gcn::Graphics *graphics)
if (mOpaque)
{
- graphics->setColor(guiPalette->getColor(Palette::BACKGROUND));
+ graphics->setColor(Theme::getThemeColor(Theme::BACKGROUND));
graphics->fillRectangle(gcn::Rectangle(0, 0, getWidth(), getHeight()));
}
@@ -276,7 +276,7 @@ void BrowserBox::draw(gcn::Graphics *graphics)
{
if ((mHighMode & BACKGROUND))
{
- graphics->setColor(guiPalette->getColor(Palette::HIGHLIGHT));
+ graphics->setColor(Theme::getThemeColor(Theme::HIGHLIGHT));
graphics->fillRectangle(gcn::Rectangle(
mLinks[mSelectedLink].x1,
mLinks[mSelectedLink].y1,
@@ -287,7 +287,7 @@ void BrowserBox::draw(gcn::Graphics *graphics)
if ((mHighMode & UNDERLINE))
{
- graphics->setColor(guiPalette->getColor(Palette::HYPERLINK));
+ graphics->setColor(Theme::getThemeColor(Theme::HYPERLINK));
graphics->drawLine(
mLinks[mSelectedLink].x1,
mLinks[mSelectedLink].y2,
@@ -305,8 +305,8 @@ void BrowserBox::draw(gcn::Graphics *graphics)
char const *hyphen = "~";
int hyphenWidth = font->getWidth(hyphen);
- graphics->setColor(guiPalette->getColor(Palette::TEXT));
- const gcn::Color textColor = guiPalette->getColor(Palette::TEXT);
+ graphics->setColor(Theme::getThemeColor(Theme::TEXT));
+ const gcn::Color textColor = Theme::getThemeColor(Theme::TEXT);
TextRowsHeightIterator h = mTextRowsHeights.begin();
for (TextRowIterator i = mTextRows.begin();
@@ -373,7 +373,7 @@ void BrowserBox::draw(gcn::Graphics *graphics)
{
const char c = row.at(start + 2);
bool valid;
- const gcn::Color col = guiPalette->getColor(c, valid);
+ const gcn::Color col = Theme::getThemeColor(c, valid);
if (c == '>')
{
diff --git a/src/gui/widgets/button.cpp b/src/gui/widgets/button.cpp
index aff46b2a..26e0ad90 100644
--- a/src/gui/widgets/button.cpp
+++ b/src/gui/widgets/button.cpp
@@ -160,9 +160,9 @@ void Button::draw(gcn::Graphics *graphics)
drawImageRect(0, 0, getWidth(), getHeight(), button[mode]);
if (mode == BUTTON_DISABLED)
- graphics->setColor(guiPalette->getColor(Palette::BUTTON_DISABLED));
+ graphics->setColor(Theme::getThemeColor(Theme::BUTTON_DISABLED));
else
- graphics->setColor(guiPalette->getColor(Palette::BUTTON));
+ graphics->setColor(Theme::getThemeColor(Theme::BUTTON));
int textX;
int textY = getHeight() / 2 - getFont()->getHeight() / 2;
diff --git a/src/gui/widgets/chattab.cpp b/src/gui/widgets/chattab.cpp
index ee4197eb..39ea6887 100644
--- a/src/gui/widgets/chattab.cpp
+++ b/src/gui/widgets/chattab.cpp
@@ -197,7 +197,7 @@ void ChatTab::chatLog(std::string line, int own, bool ignoreRecord)
chatWindow->mRecorder->record(line.substr(3));
if (this != getTabbedArea()->getSelectedTab() &&
own != BY_PLAYER)
- setHighlighted(true);
+ setFlash(true);
}
void ChatTab::chatLog(const std::string &nick, const std::string &msg)
diff --git a/src/gui/widgets/chattab.h b/src/gui/widgets/chattab.h
index 3a4133bb..7fd3931e 100644
--- a/src/gui/widgets/chattab.h
+++ b/src/gui/widgets/chattab.h
@@ -115,7 +115,7 @@ class ChatTab : public Tab
friend class ChatWindow;
friend class WhisperWindow;
- virtual void setCurrent() { setHighlighted(false); }
+ virtual void setCurrent() { setFlash(false); }
virtual void handleInput(const std::string &msg);
diff --git a/src/gui/widgets/checkbox.cpp b/src/gui/widgets/checkbox.cpp
index 5ca38727..f9002166 100644
--- a/src/gui/widgets/checkbox.cpp
+++ b/src/gui/widgets/checkbox.cpp
@@ -83,7 +83,7 @@ void CheckBox::draw(gcn::Graphics* graphics)
drawBox(graphics);
graphics->setFont(getFont());
- graphics->setColor(guiPalette->getColor(Palette::TEXT));
+ graphics->setColor(Theme::getThemeColor(Theme::TEXT));
const int h = getHeight() + getHeight() / 2;
diff --git a/src/gui/widgets/dropdown.cpp b/src/gui/widgets/dropdown.cpp
index 57a09ed2..6c3417e7 100644
--- a/src/gui/widgets/dropdown.cpp
+++ b/src/gui/widgets/dropdown.cpp
@@ -143,15 +143,15 @@ void DropDown::draw(gcn::Graphics* graphics)
const int alpha = (int) (mAlpha * 255.0f);
gcn::Color faceColor = getBaseColor();
faceColor.a = alpha;
- const gcn::Color *highlightColor =
- &guiPalette->getColor(Palette::HIGHLIGHT, alpha);
+ const gcn::Color *highlightColor = &Theme::getThemeColor(Theme::HIGHLIGHT,
+ alpha);
gcn::Color shadowColor = faceColor - 0x303030;
shadowColor.a = alpha;
if (mListBox->getListModel() && mListBox->getSelected() >= 0)
{
graphics->setFont(getFont());
- graphics->setColor(guiPalette->getColor(Palette::TEXT));
+ graphics->setColor(Theme::getThemeColor(Theme::TEXT));
graphics->drawText(mListBox->getListModel()->getElementAt(mListBox->getSelected()), 1, 0);
}
diff --git a/src/gui/widgets/emoteshortcutcontainer.cpp b/src/gui/widgets/emoteshortcutcontainer.cpp
index aadc6f24..2b07ad1e 100644
--- a/src/gui/widgets/emoteshortcutcontainer.cpp
+++ b/src/gui/widgets/emoteshortcutcontainer.cpp
@@ -92,7 +92,7 @@ void EmoteShortcutContainer::draw(gcn::Graphics *graphics)
// Draw emote keyboard shortcut.
const char *key = SDL_GetKeyName(
(SDLKey) keyboard.getKeyValue(keyboard.KEY_EMOTE_1 + i));
- graphics->setColor(guiPalette->getColor(Palette::TEXT));
+ graphics->setColor(Theme::getThemeColor(Theme::TEXT));
g->drawText(key, emoteX + 2, emoteY + 2, gcn::Graphics::LEFT);
if (emoteShortcut->getEmote(i))
diff --git a/src/gui/widgets/itemcontainer.cpp b/src/gui/widgets/itemcontainer.cpp
index 0a211d29..5163fc45 100644
--- a/src/gui/widgets/itemcontainer.cpp
+++ b/src/gui/widgets/itemcontainer.cpp
@@ -141,7 +141,7 @@ void ItemContainer::draw(gcn::Graphics *graphics)
caption = "Eq.";
if (item->isEquipped())
- g->setColor(guiPalette->getColor(Palette::ITEM_EQUIPPED));
+ g->setColor(Theme::getThemeColor(Theme::ITEM_EQUIPPED));
else
g->setColor(gcn::Color(0, 0, 0));
diff --git a/src/gui/widgets/itemshortcutcontainer.cpp b/src/gui/widgets/itemshortcutcontainer.cpp
index da5d11c5..92e3e2e5 100644
--- a/src/gui/widgets/itemshortcutcontainer.cpp
+++ b/src/gui/widgets/itemshortcutcontainer.cpp
@@ -87,7 +87,7 @@ void ItemShortcutContainer::draw(gcn::Graphics *graphics)
// Draw item keyboard shortcut.
const char *key = SDL_GetKeyName(
(SDLKey) keyboard.getKeyValue(keyboard.KEY_SHORTCUT_1 + i));
- graphics->setColor(guiPalette->getColor(Palette::TEXT));
+ graphics->setColor(Theme::getThemeColor(Theme::TEXT));
g->drawText(key, itemX + 2, itemY + 2, gcn::Graphics::LEFT);
if (itemShortcut->getItem(i) < 0)
@@ -111,7 +111,7 @@ void ItemShortcutContainer::draw(gcn::Graphics *graphics)
g->drawImage(image, itemX, itemY);
if (item->isEquipped())
- g->setColor(guiPalette->getColor(Palette::ITEM_EQUIPPED));
+ g->setColor(Theme::getThemeColor(Theme::ITEM_EQUIPPED));
g->drawText(caption, itemX + mBoxWidth / 2,
itemY + mBoxHeight - 14, gcn::Graphics::CENTER);
}
diff --git a/src/gui/widgets/label.cpp b/src/gui/widgets/label.cpp
index 464ecf69..4c607edf 100644
--- a/src/gui/widgets/label.cpp
+++ b/src/gui/widgets/label.cpp
@@ -20,7 +20,7 @@
#include "gui/widgets/label.h"
-#include "gui/palette.h"
+#include "gui/theme.h"
Label::Label()
{
@@ -33,6 +33,6 @@ Label::Label(const std::string &caption) :
void Label::draw(gcn::Graphics *graphics)
{
- setForegroundColor(guiPalette->getColor(Palette::TEXT));
+ setForegroundColor(Theme::getThemeColor(Theme::TEXT));
gcn::Label::draw(static_cast<gcn::Graphics*>(graphics));
}
diff --git a/src/gui/widgets/listbox.cpp b/src/gui/widgets/listbox.cpp
index 138cf3a0..eed6b8d0 100644
--- a/src/gui/widgets/listbox.cpp
+++ b/src/gui/widgets/listbox.cpp
@@ -59,8 +59,8 @@ void ListBox::draw(gcn::Graphics *graphics)
updateAlpha();
- graphics->setColor(guiPalette->getColor(Palette::HIGHLIGHT,
- (int)(mAlpha * 255.0f)));
+ graphics->setColor(Theme::getThemeColor(Theme::HIGHLIGHT,
+ (int) (mAlpha * 255.0f)));
graphics->setFont(getFont());
const int fontHeight = getFont()->getHeight();
@@ -71,7 +71,7 @@ void ListBox::draw(gcn::Graphics *graphics)
getWidth(), fontHeight));
// Draw the list elements
- graphics->setColor(guiPalette->getColor(Palette::TEXT));
+ graphics->setColor(Theme::getThemeColor(Theme::TEXT));
for (int i = 0, y = 0; i < mListModel->getNumberOfElements();
++i, y += fontHeight)
{
diff --git a/src/gui/widgets/progressbar.cpp b/src/gui/widgets/progressbar.cpp
index 99a8c36a..028658ab 100644
--- a/src/gui/widgets/progressbar.cpp
+++ b/src/gui/widgets/progressbar.cpp
@@ -41,11 +41,10 @@ float ProgressBar::mAlpha = 1.0;
ProgressBar::ProgressBar(float progress,
int width, int height,
- const gcn::Color &color):
+ int color):
gcn::Widget(),
mSmoothProgress(true),
- mColor(color),
- mColorToGo(color),
+ mProgressPalette(color),
mSmoothColorChange(true)
{
// The progress value is directly set at load time:
@@ -54,6 +53,9 @@ ProgressBar::ProgressBar(float progress,
mProgress = mProgressToGo = progress;
+ mColor = mColorToGo = Theme::getProgressColor(color >= 0 ? color : 0,
+ mProgress);
+
setSize(width, height);
if (mInstances == 0)
@@ -156,6 +158,22 @@ void ProgressBar::setProgress(float progress)
if (!mSmoothProgress)
mProgress = p;
+
+ if (mProgressPalette >= 0)
+ {
+ mColorToGo = Theme::getProgressColor(mProgressPalette, progress);
+ }
+}
+
+void ProgressBar::setProgressPalette(int progressPalette)
+{
+ int oldPalette = mProgressPalette;
+ mProgressPalette = progressPalette;
+
+ if (mProgressPalette != oldPalette && mProgressPalette >= 0)
+ {
+ mColorToGo = Theme::getProgressColor(mProgressPalette, mProgressToGo);
+ }
}
void ProgressBar::setColor(const gcn::Color &color)
@@ -192,7 +210,7 @@ void ProgressBar::render(Graphics *graphics, const gcn::Rectangle &area,
TextRenderer::renderText(graphics, text, textX, textY,
gcn::Graphics::CENTER,
- guiPalette->getColor(Palette::PROGRESS_BAR),
+ Theme::getThemeColor(Theme::PROGRESS_BAR),
gui->getFont(), true, false);
}
diff --git a/src/gui/widgets/progressbar.h b/src/gui/widgets/progressbar.h
index a6bb49d9..56bcb0a0 100644
--- a/src/gui/widgets/progressbar.h
+++ b/src/gui/widgets/progressbar.h
@@ -42,7 +42,7 @@ class ProgressBar : public gcn::Widget
*/
ProgressBar(float progress = 0.0f,
int width = 40, int height = 7,
- const gcn::Color &color = gcn::Color(150, 150, 150));
+ int color = -1);
~ProgressBar();
@@ -72,17 +72,15 @@ class ProgressBar : public gcn::Widget
float getProgress() const { return mProgress; }
/**
- * Change the color of the progress bar.
+ * Change the ProgressPalette for this ProgressBar to follow or -1 to
+ * disable this and manage color manually.
*/
- void setColor(const gcn::Color &color);
+ void setProgressPalette(int progressPalette);
/**
* Change the color of the progress bar.
- *
- * This is an overload provided for convenience.
*/
- inline void setColor(int r, int g, int b)
- { setColor(gcn::Color(r, g, b)); }
+ void setColor(const gcn::Color &color);
/**
* Returns the color of the progress bar.
@@ -124,6 +122,7 @@ class ProgressBar : public gcn::Widget
float mProgress, mProgressToGo;
bool mSmoothProgress;
+ int mProgressPalette; /** < Entry in ProgressPalette or -1 for none. */
gcn::Color mColor;
gcn::Color mColorToGo;
bool mSmoothColorChange;
diff --git a/src/gui/widgets/progressindicator.cpp b/src/gui/widgets/progressindicator.cpp
index 1941da4a..6bda617f 100644
--- a/src/gui/widgets/progressindicator.cpp
+++ b/src/gui/widgets/progressindicator.cpp
@@ -20,15 +20,15 @@
#include "progressindicator.h"
+#include "graphics.h"
+#include "simpleanimation.h"
+
#include "gui/theme.h"
#include "resources/animation.h"
#include "resources/imageset.h"
#include "resources/resourcemanager.h"
-#include "graphics.h"
-#include "simpleanimation.h"
-
#include <guichan/widgets/label.hpp>
ProgressIndicator::ProgressIndicator()
diff --git a/src/gui/widgets/shoplistbox.cpp b/src/gui/widgets/shoplistbox.cpp
index fc9fc4d4..2f5fab34 100644
--- a/src/gui/widgets/shoplistbox.cpp
+++ b/src/gui/widgets/shoplistbox.cpp
@@ -26,7 +26,7 @@
#include "shopitem.h"
#include "gui/itempopup.h"
-#include "gui/palette.h"
+#include "gui/theme.h"
#include "gui/viewport.h"
#include "gui/widgets/shopitems.h"
@@ -76,7 +76,7 @@ void ShopListBox::draw(gcn::Graphics *gcnGraphics)
int alpha = (int)(mAlpha * 255.0f);
const gcn::Color* highlightColor =
- &guiPalette->getColor(Palette::HIGHLIGHT, alpha);
+ &Theme::getThemeColor(Theme::HIGHLIGHT, alpha);
Graphics *graphics = static_cast<Graphics*>(gcnGraphics);
@@ -89,19 +89,19 @@ void ShopListBox::draw(gcn::Graphics *gcnGraphics)
{
gcn::Color temp;
const gcn::Color* backgroundColor =
- &guiPalette->getColor(Palette::BACKGROUND, alpha);
+ &Theme::getThemeColor(Theme::BACKGROUND, alpha);
if (mShopItems &&
mPlayerMoney < mShopItems->at(i)->getPrice() && mPriceCheck)
{
if (i != mSelected)
{
- backgroundColor = &guiPalette->getColor(Palette::SHOP_WARNING,
- alpha);
+ backgroundColor = &Theme::getThemeColor(Theme::SHOP_WARNING,
+ alpha);
}
else
{
- temp = guiPalette->getColor(Palette::SHOP_WARNING, alpha);
+ temp = Theme::getThemeColor(Theme::SHOP_WARNING, alpha);
temp.r = (temp.r + highlightColor->r) / 2;
temp.g = (temp.g + highlightColor->g) / 2;
temp.b = (temp.g + highlightColor->b) / 2;
@@ -125,7 +125,7 @@ void ShopListBox::draw(gcn::Graphics *gcnGraphics)
graphics->drawImage(icon, 1, y);
}
}
- graphics->setColor(guiPalette->getColor(Palette::TEXT));
+ graphics->setColor(Theme::getThemeColor(Theme::TEXT));
graphics->drawText(mListModel->getElementAt(i), ITEM_ICON_SIZE + 5,
y + (ITEM_ICON_SIZE - getFont()->getHeight()) / 2);
}
diff --git a/src/gui/widgets/tab.cpp b/src/gui/widgets/tab.cpp
index d770dbfe..2ab126dd 100644
--- a/src/gui/widgets/tab.cpp
+++ b/src/gui/widgets/tab.cpp
@@ -63,7 +63,7 @@ static TabData const data[TAB_COUNT] = {
ImageRect Tab::tabImg[TAB_COUNT];
Tab::Tab() : gcn::Tab(),
- mTabColor(&guiPalette->getColor(Palette::TAB))
+ mTabColor(&Theme::getThemeColor(Theme::TAB))
{
init();
}
@@ -85,7 +85,7 @@ void Tab::init()
{
setFocusable(false);
setFrameSize(0);
- mHighlighted = false;
+ mFlash = false;
if (mInstances == 0)
{
@@ -148,15 +148,15 @@ void Tab::draw(gcn::Graphics *graphics)
{
mode = TAB_SELECTED;
// if tab is selected, it doesnt need to highlight activity
- mHighlighted = false;
+ mFlash = false;
}
else if (mHasMouse)
{
mode = TAB_HIGHLIGHTED;
}
- if (mHighlighted)
+ if (mFlash)
{
- mLabel->setForegroundColor(guiPalette->getColor(Palette::TAB_HIGHLIGHT));
+ mLabel->setForegroundColor(Theme::getThemeColor(Theme::TAB_FLASH));
}
}
@@ -175,7 +175,7 @@ void Tab::setTabColor(const gcn::Color *color)
mTabColor = color;
}
-void Tab::setHighlighted(bool high)
+void Tab::setFlash(bool flash)
{
- mHighlighted = high;
+ mFlash = flash;
}
diff --git a/src/gui/widgets/tab.h b/src/gui/widgets/tab.h
index 7b372e04..433084f9 100644
--- a/src/gui/widgets/tab.h
+++ b/src/gui/widgets/tab.h
@@ -53,9 +53,9 @@ class Tab : public gcn::Tab
void setTabColor(const gcn::Color *color);
/**
- * Set tab highlighted
+ * Set tab flashing state
*/
- void setHighlighted(bool high);
+ void setFlash(bool flash);
protected:
friend class TabbedArea;
@@ -70,7 +70,7 @@ class Tab : public gcn::Tab
static float mAlpha;
const gcn::Color *mTabColor;
- bool mHighlighted;
+ bool mFlash;
};
#endif
diff --git a/src/gui/widgets/table.cpp b/src/gui/widgets/table.cpp
index 0bc4f3d1..f0887ed7 100644
--- a/src/gui/widgets/table.cpp
+++ b/src/gui/widgets/table.cpp
@@ -23,8 +23,8 @@
#include "configuration.h"
-#include "gui/palette.h"
#include "gui/sdlinput.h"
+#include "gui/theme.h"
#include "utils/dtor.h"
@@ -275,7 +275,7 @@ void GuiTable::draw(gcn::Graphics* graphics)
if (mOpaque)
{
- graphics->setColor(guiPalette->getColor(Palette::BACKGROUND,
+ graphics->setColor(Theme::getThemeColor(Theme::BACKGROUND,
(int)(mAlpha * 255.0f)));
graphics->fillRectangle(gcn::Rectangle(0, 0, getWidth(), getHeight()));
}
@@ -321,8 +321,8 @@ void GuiTable::draw(gcn::Graphics* graphics)
widget->setDimension(bounds);
- graphics->setColor(guiPalette->getColor(Palette::HIGHLIGHT,
- (int)(mAlpha * 255.0f)));
+ graphics->setColor(Theme::getThemeColor(Theme::HIGHLIGHT,
+ (int)(mAlpha * 255.0f)));
if (mLinewiseMode && r == mSelectedRow && c == 0)
{
diff --git a/src/gui/widgets/textbox.cpp b/src/gui/widgets/textbox.cpp
index 9f79c963..f248f35d 100644
--- a/src/gui/widgets/textbox.cpp
+++ b/src/gui/widgets/textbox.cpp
@@ -21,14 +21,14 @@
#include "gui/widgets/textbox.h"
-#include "gui/palette.h"
+#include "gui/theme.h"
#include <guichan/font.hpp>
#include <sstream>
TextBox::TextBox() :
- mTextColor(&guiPalette->getColor(Palette::TEXT))
+ mTextColor(&Theme::getThemeColor(Theme::TEXT))
{
setOpaque(false);
setFrameSize(0);
diff --git a/src/gui/widgets/textfield.cpp b/src/gui/widgets/textfield.cpp
index 1fab4eb7..4453f522 100644
--- a/src/gui/widgets/textfield.cpp
+++ b/src/gui/widgets/textfield.cpp
@@ -108,7 +108,7 @@ void TextField::draw(gcn::Graphics *graphics)
mXScroll);
}
- graphics->setColor(guiPalette->getColor(Palette::TEXT));
+ graphics->setColor(Theme::getThemeColor(Theme::TEXT));
graphics->setFont(getFont());
graphics->drawText(mText, 1 - mXScroll, 1);
}
diff --git a/src/gui/widgets/textpreview.cpp b/src/gui/widgets/textpreview.cpp
index 209752b2..10426d7c 100644
--- a/src/gui/widgets/textpreview.cpp
+++ b/src/gui/widgets/textpreview.cpp
@@ -37,9 +37,9 @@ TextPreview::TextPreview(const std::string &text):
{
mTextAlpha = false;
mFont = gui->getFont();
- mTextColor = &guiPalette->getColor(Palette::TEXT);
+ mTextColor = &Theme::getThemeColor(Theme::TEXT);
mTextBGColor = NULL;
- mBGColor = &guiPalette->getColor(Palette::BACKGROUND);
+ mBGColor = &Theme::getThemeColor(Theme::BACKGROUND);
mOpaque = false;
}
diff --git a/src/gui/widgets/whispertab.cpp b/src/gui/widgets/whispertab.cpp
index 124b3165..858a2e6b 100644
--- a/src/gui/widgets/whispertab.cpp
+++ b/src/gui/widgets/whispertab.cpp
@@ -24,7 +24,7 @@
#include "commandhandler.h"
#include "localplayer.h"
-#include "gui/palette.h"
+#include "gui/theme.h"
#include "net/chathandler.h"
#include "net/net.h"
@@ -36,7 +36,7 @@ WhisperTab::WhisperTab(const std::string &nick) :
ChatTab(nick),
mNick(nick)
{
- setTabColor(&guiPalette->getColor(Palette::WHISPER));
+ setTabColor(&Theme::getThemeColor(Theme::WHISPER));
}
WhisperTab::~WhisperTab()
diff --git a/src/gui/widgets/window.cpp b/src/gui/widgets/window.cpp
index b3d6bd02..2db3afb5 100644
--- a/src/gui/widgets/window.cpp
+++ b/src/gui/widgets/window.cpp
@@ -122,7 +122,7 @@ void Window::draw(gcn::Graphics *graphics)
// Draw title
if (mShowTitle)
{
- g->setColor(guiPalette->getColor(Palette::TEXT));
+ g->setColor(Theme::getThemeColor(Theme::TEXT));
g->setFont(getFont());
g->drawText(getCaption(), 7, 5, gcn::Graphics::LEFT);
}
diff --git a/src/localplayer.cpp b/src/localplayer.cpp
index a48c7f4c..dfee7cdc 100644
--- a/src/localplayer.cpp
+++ b/src/localplayer.cpp
@@ -41,11 +41,11 @@
#include "gui/gui.h"
#include "gui/ministatus.h"
-#include "gui/palette.h"
#include "gui/skilldialog.h"
#include "gui/statuswindow.h"
#include "gui/storagewindow.h"
#include "gui/theme.h"
+#include "gui/userpalette.h"
#include "gui/widgets/chattab.h"
@@ -105,8 +105,8 @@ LocalPlayer::LocalPlayer(int id, int job):
{
mUpdateName = true;
- mTextColor = &guiPalette->getColor(Palette::PLAYER);
- mNameColor = &guiPalette->getColor(Palette::SELF);
+ mTextColor = &Theme::getThemeColor(Theme::PLAYER);
+ mNameColor = &userPalette->getColor(UserPalette::SELF);
initTargetCursor();
@@ -150,7 +150,7 @@ void LocalPlayer::logic()
(int) pos.y - 48,*/
getPixelX(),
getPixelY() - 48,
- &guiPalette->getColor(info.second),
+ &userPalette->getColor(info.second),
gui->getInfoParticleFont(), true);
mMessages.pop_front();
@@ -928,7 +928,7 @@ void LocalPlayer::pickedUp(const ItemInfo &itemInfo, int amount)
if (mMap && config.getValue("showpickupparticle", 0))
{
// Show pickup notification
- addMessageToQueue(itemInfo.getName(), Palette::PICKUP_INFO);
+ addMessageToQueue(itemInfo.getName(), UserPalette::PICKUP_INFO);
}
}
}
@@ -1080,8 +1080,7 @@ void LocalPlayer::loadTargetCursor(const std::string &filename,
mTargetCursor[index][size] = currentCursor;
}
-void LocalPlayer::addMessageToQueue(const std::string &message,
- Palette::ColorType color)
+void LocalPlayer::addMessageToQueue(const std::string &message, int color)
{
mMessages.push_back(MessagePair(message, color));
}
diff --git a/src/localplayer.h b/src/localplayer.h
index 69fd4d0f..dce83ccd 100644
--- a/src/localplayer.h
+++ b/src/localplayer.h
@@ -24,7 +24,7 @@
#include "player.h"
-#include "gui/palette.h"
+#include "gui/userpalette.h"
#include <memory>
#include <vector>
@@ -349,7 +349,7 @@ class LocalPlayer : public Player
{ return mPathSetByMouse; }
void addMessageToQueue(const std::string &message,
- Palette::ColorType color = Palette::EXP_INFO);
+ int color = UserPalette::EXP_INFO);
/**
* Called when a option (set with config.addListener()) is changed
@@ -472,7 +472,7 @@ class LocalPlayer : public Player
/** Animated target cursors. */
SimpleAnimation *mTargetCursor[2][NUM_TC];
- typedef std::pair<std::string, Palette::ColorType> MessagePair;
+ typedef std::pair<std::string, int> MessagePair;
/** Queued exp messages*/
std::list<MessagePair> mMessages;
int mMessageTime;
diff --git a/src/monster.cpp b/src/monster.cpp
index dfe84e65..23be9395 100644
--- a/src/monster.cpp
+++ b/src/monster.cpp
@@ -28,7 +28,7 @@
#include "sound.h"
#include "text.h"
-#include "gui/palette.h"
+#include "gui/userpalette.h"
#include "net/net.h"
@@ -67,8 +67,8 @@ Monster::Monster(int id, int job, Map *map):
}
}
- mNameColor = &guiPalette->getColor(Palette::MONSTER);
- mTextColor = &guiPalette->getColor(Palette::MONSTER);
+ mNameColor = &userPalette->getColor(UserPalette::MONSTER);
+ mTextColor = &userPalette->getColor(UserPalette::MONSTER);
Being::setName(getInfo().getName());
}
diff --git a/src/net/ea/gui/guildtab.cpp b/src/net/ea/gui/guildtab.cpp
index e88c289e..e6fddf4f 100644
--- a/src/net/ea/gui/guildtab.cpp
+++ b/src/net/ea/gui/guildtab.cpp
@@ -25,7 +25,7 @@
#include "guild.h"
#include "localplayer.h"
-#include "gui/palette.h"
+#include "gui/theme.h"
#include "net/net.h"
#include "net/guildhandler.h"
@@ -44,7 +44,7 @@ extern Guild *eaGuild;
GuildTab::GuildTab() :
ChatTab(_("Guild"))
{
- setTabColor(&guiPalette->getColor(Palette::GUILD));
+ setTabColor(&Theme::getThemeColor(Theme::GUILD));
}
GuildTab::~GuildTab()
diff --git a/src/net/ea/gui/partytab.cpp b/src/net/ea/gui/partytab.cpp
index 27e5b2d9..85311352 100644
--- a/src/net/ea/gui/partytab.cpp
+++ b/src/net/ea/gui/partytab.cpp
@@ -25,7 +25,7 @@
#include "localplayer.h"
#include "party.h"
-#include "gui/palette.h"
+#include "gui/theme.h"
#include "net/net.h"
#include "net/partyhandler.h"
@@ -42,7 +42,7 @@ namespace EAthena {
PartyTab::PartyTab() :
ChatTab(_("Party"))
{
- setTabColor(&guiPalette->getColor(Palette::PARTY));
+ setTabColor(&Theme::getThemeColor(Theme::PARTY));
}
PartyTab::~PartyTab()
diff --git a/src/npc.cpp b/src/npc.cpp
index 38aecab8..29a6c61c 100644
--- a/src/npc.cpp
+++ b/src/npc.cpp
@@ -29,7 +29,7 @@
#include "gui/buysell.h"
#include "gui/npcdialog.h"
#include "gui/npcpostdialog.h"
-#include "gui/palette.h"
+#include "gui/userpalette.h"
#include "gui/sell.h"
#include "net/net.h"
@@ -74,6 +74,10 @@ void NPC::setName(const std::string &name)
const std::string displayName = name.substr(0, name.find('#', 0));
Being::setName(displayName);
+
+ mNameColor = &userPalette->getColor(UserPalette::NPC);
+
+ mDispName->setColor(mNameColor);
}
void NPC::talk()
diff --git a/src/player.cpp b/src/player.cpp
index 4fc5d523..dfe45e6c 100644
--- a/src/player.cpp
+++ b/src/player.cpp
@@ -30,8 +30,9 @@
#include "party.h"
#include "text.h"
-#include "gui/palette.h"
#include "gui/socialwindow.h"
+#include "gui/theme.h"
+#include "gui/userpalette.h"
#include "net/charhandler.h"
#include "net/net.h"
@@ -327,20 +328,20 @@ void Player::optionChanged(const std::string &value)
void Player::updateColors()
{
- mTextColor = &guiPalette->getColor(Palette::PLAYER);
+ mTextColor = &userPalette->getColor(Theme::PLAYER);
if (mIsGM)
{
- mTextColor = &guiPalette->getColor(Palette::GM);
- mNameColor = &guiPalette->getColor(Palette::GM_NAME);
+ mTextColor = &userPalette->getColor(Theme::GM);
+ mNameColor = &userPalette->getColor(UserPalette::GM);
}
else if (mParty && mParty == player_node->getParty())
{
- mNameColor = &guiPalette->getColor(Palette::PARTY);
+ mNameColor = &userPalette->getColor(UserPalette::PARTY);
}
else
{
- mNameColor = &guiPalette->getColor(Palette::PC);
+ mNameColor = &userPalette->getColor(UserPalette::PC);
}
if (mDispName)
diff --git a/src/resources/dye.cpp b/src/resources/dye.cpp
index 5116a134..85a87aa4 100644
--- a/src/resources/dye.cpp
+++ b/src/resources/dye.cpp
@@ -75,27 +75,43 @@ DyePalette::DyePalette(const std::string &description)
logger->log("Error, invalid embedded palette: %s", description.c_str());
}
+void DyePalette::addFirstColor(const int color[3])
+{
+ Color c = { {color[0], color[1], color[2]} };
+ mColors.insert(mColors.begin(), c);
+}
+
+void DyePalette::addLastColor(const int color[3])
+{
+ Color c = { {color[0], color[1], color[2]} };
+ mColors.push_back(c);
+}
+
void DyePalette::getColor(int intensity, int color[3]) const
{
- if (intensity == 0)
- {
- color[0] = 0;
- color[1] = 0;
- color[2] = 0;
+ if (mColors.size() == 0)
return;
+
+ Color c0 = mColors[0];
+
+ // Short circuit for black and single-color palettes
+ if (intensity == 0 || mColors.size() == 1)
+ {
+ color[0] = c0.value[0];
+ color[1] = c0.value[1];
+ color[2] = c0.value[2];
}
- int last = mColors.size();
- if (last == 0) return;
+ int last = mColors.size() - 1;
int i = intensity * last / 255;
int t = intensity * last % 255;
int j = t != 0 ? i : i - 1;
// Get the exact color if any, the next color otherwise.
- int r2 = mColors[j].value[0],
- g2 = mColors[j].value[1],
- b2 = mColors[j].value[2];
+ int r2 = mColors[j + 1].value[0],
+ g2 = mColors[j + 1].value[1],
+ b2 = mColors[j + 1].value[2];
if (t == 0)
{
@@ -106,13 +122,13 @@ void DyePalette::getColor(int intensity, int color[3]) const
return;
}
- // Get the previous color. First color is implicitly black.
- int r1 = 0, g1 = 0, b1 = 0;
+ // Get the previous color.
+ int r1 = c0.value[0], g1 = c0.value[1], b1 = c0.value[2];
if (i > 0)
{
- r1 = mColors[i - 1].value[0];
- g1 = mColors[i - 1].value[1];
- b1 = mColors[i - 1].value[2];
+ r1 = mColors[i].value[0];
+ g1 = mColors[i].value[1];
+ b1 = mColors[i].value[2];
}
// Perform a linear interpolation.
@@ -123,6 +139,8 @@ void DyePalette::getColor(int intensity, int color[3]) const
Dye::Dye(const std::string &description)
{
+ static const int black[3] = {0, 0, 0};
+
for (int i = 0; i < 7; ++i)
mDyePalettes[i] = 0;
@@ -161,6 +179,7 @@ Dye::Dye(const std::string &description)
}
mDyePalettes[i] = new DyePalette(description.substr(pos + 2,
next_pos - pos - 2));
+ mDyePalettes[i]->addFirstColor(black); // First color is black
++next_pos;
}
while (next_pos < length);
diff --git a/src/resources/dye.h b/src/resources/dye.h
index 6934fbfa..51d5d65c 100644
--- a/src/resources/dye.h
+++ b/src/resources/dye.h
@@ -39,6 +39,10 @@ class DyePalette
*/
DyePalette(const std::string &pallete);
+ void addFirstColor(const int color[3]);
+
+ void addLastColor(const int color[3]);
+
/**
* Gets a pixel color depending on its intensity.
*/
diff --git a/src/textrenderer.h b/src/textrenderer.h
index 589346ef..4da868f1 100644
--- a/src/textrenderer.h
+++ b/src/textrenderer.h
@@ -24,7 +24,7 @@
#include "graphics.h"
-#include "gui/palette.h"
+#include "gui/theme.h"
/**
* Class for text rendering. Used by the TextParticle, the Text and FlashText
@@ -50,7 +50,7 @@ class TextRenderer
// Text shadow
if (shadow)
{
- graphics->setColor(guiPalette->getColor(Palette::SHADOW,
+ graphics->setColor(Theme::getThemeColor(Theme::SHADOW,
color.a / 2));
if (outline)
{
@@ -71,7 +71,7 @@ class TextRenderer
graphics->drawText(text, x + 2, y + 1, align);*/
// Text outline
- graphics->setColor(guiPalette->getColor(Palette::OUTLINE, color.a));
+ graphics->setColor(Theme::getThemeColor(Theme::OUTLINE, color.a));
graphics->drawText(text, x + 1, y, align);
graphics->drawText(text, x - 1, y, align);
graphics->drawText(text, x, y + 1, align);
diff --git a/src/utils/stringutils.cpp b/src/utils/stringutils.cpp
index 9a53a372..01bf0d3c 100644
--- a/src/utils/stringutils.cpp
+++ b/src/utils/stringutils.cpp
@@ -138,7 +138,13 @@ int compareStrI(const std::string &a, const std::string &b)
return comp;
}
- return 0;
+ // Check string lengths
+ if (itA == endA && itB == endB)
+ return 0;
+ else if (itA == endA)
+ return -1;
+ else
+ return 1;
}
bool isWordSeparator(char chr)