summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/CMakeLists.txt2
-rw-r--r--src/Makefile.am2
-rw-r--r--src/being.cpp2
-rw-r--r--src/being.h8
-rw-r--r--src/gui/char_select.cpp8
-rw-r--r--src/localplayer.cpp1
-rw-r--r--src/player.cpp23
-rw-r--r--src/resources/colordb.cpp119
-rw-r--r--src/resources/colordb.h52
9 files changed, 188 insertions, 29 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index e6b9d3b1..d7ff67a8 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -227,6 +227,8 @@ SET(SRCS
resources/animation.h
resources/buddylist.cpp
resources/buddylist.h
+ resources/colordb.cpp
+ resources/colordb.h
resources/dye.cpp
resources/dye.h
resources/image.cpp
diff --git a/src/Makefile.am b/src/Makefile.am
index f6d06536..0f12579f 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -189,6 +189,8 @@ aethyra_SOURCES = gui/widgets/dropdown.cpp \
resources/animation.h \
resources/buddylist.cpp \
resources/buddylist.h \
+ resources/colordb.cpp \
+ resources/colordb.h \
resources/dye.cpp \
resources/dye.h \
resources/image.cpp \
diff --git a/src/being.cpp b/src/being.cpp
index c4723f79..97ccd42e 100644
--- a/src/being.cpp
+++ b/src/being.cpp
@@ -144,7 +144,7 @@ void Being::setPath(const Path &path)
void Being::setHairStyle(int style, int color)
{
mHairStyle = style < 0 ? mHairStyle : style % NR_HAIR_STYLES;
- mHairColor = color < 0 ? mHairColor : color % NR_HAIR_COLORS;
+ mHairColor = color;
}
void Being::setSprite(int slot, int id, std::string color)
diff --git a/src/being.h b/src/being.h
index 05a49d9a..f5f1a1a7 100644
--- a/src/being.h
+++ b/src/being.h
@@ -36,8 +36,9 @@
#include "gui/speechbubble.h"
+#include "resources/colordb.h"
+
#define NR_HAIR_STYLES 10
-#define NR_HAIR_COLORS 16
#define FIRST_IGNORE_EMOTE 14
@@ -362,6 +363,7 @@ class Being : public Sprite
const std::auto_ptr<Equipment> mEquipment;
+
protected:
/**
* Sets the new path for this being.
@@ -389,6 +391,7 @@ class Being : public Sprite
std::string mName; /**< Name of character */
SpriteIterator mSpriteIterator;
bool mIsGM;
+ bool mParticleEffects; /**< Whether to display particles or not */
/** Engine-related infos about weapon. */
const ItemInfo* mEquippedWeapon;
@@ -405,9 +408,6 @@ class Being : public Sprite
std::vector<std::string> mSpriteColors;
std::list<Particle *> mChildParticleEffects;
- protected:
- bool mParticleEffects; /**< Whether to display particles or not */
-
private:
/**
* Calculates the offset in the given directions.
diff --git a/src/gui/char_select.cpp b/src/gui/char_select.cpp
index c4b1d89e..65d0159f 100644
--- a/src/gui/char_select.cpp
+++ b/src/gui/char_select.cpp
@@ -256,7 +256,10 @@ CharCreateDialog::CharCreateDialog(Window *parent, int slot, Network *network,
{
mPlayer = new Player(0, 0, NULL);
mPlayer->setGender(gender);
- mPlayer->setHairStyle(rand() % NR_HAIR_STYLES, rand() % NR_HAIR_COLORS);
+
+ int numberOfHairColors = ColorDB::size();
+
+ mPlayer->setHairStyle(rand() % NR_HAIR_STYLES, rand() % numberOfHairColors);
mNameField = new TextField("");
mNameLabel = new gcn::Label("Name:");
@@ -322,6 +325,7 @@ CharCreateDialog::~CharCreateDialog()
void
CharCreateDialog::action(const gcn::ActionEvent &event)
{
+ int numberOfColors = ColorDB::size();
if (event.getId() == "create") {
if (getName().length() >= 4) {
// Attempt to create the character
@@ -340,7 +344,7 @@ CharCreateDialog::action(const gcn::ActionEvent &event)
mPlayer->setHairStyle(-1, mPlayer->getHairColor() + 1);
}
else if (event.getId() == "prevcolor") {
- mPlayer->setHairStyle(-1, mPlayer->getHairColor() + NR_HAIR_COLORS - 1);
+ mPlayer->setHairStyle(-1, mPlayer->getHairColor() + numberOfColors - 1);
}
else if (event.getId() == "nextstyle") {
mPlayer->setHairStyle(mPlayer->getHairStyle() + 1, -1);
diff --git a/src/localplayer.cpp b/src/localplayer.cpp
index 66d37ddf..d83bd254 100644
--- a/src/localplayer.cpp
+++ b/src/localplayer.cpp
@@ -54,6 +54,7 @@ LocalPlayer::LocalPlayer(Uint32 id, Uint16 job, Map *map):
mInventory(new Inventory(INVENTORY_SIZE)),
mStorage(new Inventory(STORAGE_SIZE))
{
+ ColorDB::load();
}
LocalPlayer::~LocalPlayer()
diff --git a/src/player.cpp b/src/player.cpp
index 8380fdfe..37badcdc 100644
--- a/src/player.cpp
+++ b/src/player.cpp
@@ -160,32 +160,11 @@ void Player::setGender(int gender)
void Player::setHairStyle(int style, int color)
{
style = style < 0 ? mHairStyle : style % NR_HAIR_STYLES;
- color = color < 0 ? mHairColor : color % NR_HAIR_COLORS;
if (style == mHairStyle && color == mHairColor) return;
Being::setHairStyle(style, color);
- static char const *const colors[NR_HAIR_COLORS] =
- {
- "#8c4b41,da9041,ffffff", // light brown
- "#06372b,489e25,fdedcc", // green
- "#5f0b33,91191c,f9ad81", // dark red
- "#602486,934cc3,fdc689", // purple
- "#805e74,c6b09b,ffffff", // white
- "#8c6625,dab425,ffffff", // yellow
- "#1d2d6d,1594a3,fdedcc", // blue
- "#831f2d,be4f2d,f8cc8b", // brown
- "#432482,584bbc,dae8e5", // light blue
- "#460850,611967,e7b4ae", // dark purple
- "#8f3e21,bc522b,ff946c", // orange
- "#9c6b84,d272a3,ffcae5", // pink
- "#1d1d1d,414141,6f6f6f", // charcoal
- "#525252,99999b,cacaca", // silver
- "#841413,aa2829,ffaeb1", // light red
- "#a82513,ffa525,ffffff", // strawberry blond
- };
-
- setSprite(HAIR_SPRITE, style * -1, colors[color]);
+ setSprite(HAIR_SPRITE, style * -1, ColorDB::get(color));
setAction(mAction);
}
diff --git a/src/resources/colordb.cpp b/src/resources/colordb.cpp
new file mode 100644
index 00000000..837561ed
--- /dev/null
+++ b/src/resources/colordb.cpp
@@ -0,0 +1,119 @@
+/*
+ * Aethyra
+ * Copyright 2008 Aethyra Development Team
+ *
+ * This file is part of Aethyra.
+ *
+ * Aethyra 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.
+ *
+ * Aethyra 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 Aethyra; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <cassert>
+#include <libxml/tree.h>
+
+#include "colordb.h"
+
+#include "../log.h"
+
+#include "../utils/dtor.h"
+#include "../utils/xml.h"
+
+#define HAIR_COLOR_FILE "colors.xml"
+
+namespace
+{
+ ColorDB::Colors mColors;
+ bool mLoaded = false;
+ std::string mFail = "";
+}
+
+void ColorDB::load()
+{
+ if (mLoaded)
+ {
+ return;
+ }
+
+ XML::Document doc(HAIR_COLOR_FILE);
+ xmlNodePtr root = doc.rootNode();
+
+ if (!root || !xmlStrEqual(root->name, BAD_CAST "colors"))
+ {
+ logger->log("Error loading colors file: "
+ HAIR_COLOR_FILE);
+
+ // Provide "legacy" support for the TMW server that
+ // doesn't seperate out hair colors from the actual
+ // code. Seriously, this is freaking annoying.
+ mColors[0] = "#8c4b41,da9041,ffffff"; // light brown
+ mColors[1] = "#06372b,489e25,fdedcc"; // green
+ mColors[2] = "#5f0b33,91191c,f9ad81"; // dark red
+ mColors[3] = "#602486,934cc3,fdc689"; // purple
+ mColors[4] = "#805e74,c6b09b,ffffff"; // white
+ mColors[5] = "#8c6625,dab425,ffffff"; // yellow
+ mColors[6] = "#1d2d6d,1594a3,fdedcc"; // blue
+ mColors[7] = "#831f2d,be4f2d,f8cc8b"; // brown
+ mColors[8] = "#432482,584bbc,dae8e5"; // light blue
+ mColors[9] = "#460850,611967,e7b4ae"; // dark purple
+ }
+ else
+ {
+ for_each_xml_child_node(node, root)
+ {
+ if (xmlStrEqual(node->name, BAD_CAST "color"))
+ {
+ int id = XML::getProperty(node, "id", 0);
+
+ if (mColors.find(id) != mColors.end())
+ {
+ logger->log("ColorDB: Redefinition of dye ID %d", id);
+ }
+
+ mColors[id] = XML::getProperty(node, "dye", "");
+ }
+ }
+ }
+
+ mLoaded = true;
+}
+
+void ColorDB::unload()
+{
+ logger->log("Unloading color database...");
+
+ mColors.clear();
+ mLoaded = false;
+}
+
+std::string& ColorDB::get(int id)
+{
+ assert(mLoaded);
+
+ ColorIterator i = mColors.find(id);
+
+ if (i == mColors.end())
+ {
+ logger->log("ColorDB: Error, unknown dye ID# %d", id);
+ return mFail;
+ }
+ else
+ {
+ return i->second;
+ }
+}
+
+const int& ColorDB::size()
+{
+ return mColors.size();
+}
diff --git a/src/resources/colordb.h b/src/resources/colordb.h
new file mode 100644
index 00000000..43398af4
--- /dev/null
+++ b/src/resources/colordb.h
@@ -0,0 +1,52 @@
+/*
+ * Aethyra
+ * Copyright 2008 Aethyra Development Team
+ *
+ * This file is part of Aethyra.
+ *
+ * Aethyra 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.
+ *
+ * Aethyra 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 Aethyra; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef _AETHYRA_COLOR_MANAGER_H
+#define _AETHYRA_COLOR_MANAGER_H
+
+#include <string>
+#include <map>
+
+/**
+ * The class that holds the color information.
+ */
+namespace ColorDB
+{
+ /**
+ * Loads the color data from <code>colors.xml</code>.
+ */
+ void load();
+
+ /**
+ * Clear the color data
+ */
+ void unload();
+
+ std::string& get(int id);
+
+ const int& size();
+
+ // Color DB
+ typedef std::map<int, std::string> Colors;
+ typedef Colors::iterator ColorIterator;
+};
+
+#endif