Commit abde0f51b3062c158fb52e9dfff23d21d3be03d1

  • avatar
  • Yohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer>
  • Sun Jul 11 20:05:44 CEST 2010
Made the different hard-coded paths and files be now taken from the
data/paths.xml configuration file.

Also added default gui theme path in branding and default wallpaper path
and file searched respectively in the branding and paths.xml files.

Hard-coded values are still used as fallbacks.

Resolves: Manasource Mantis #148.

Reviewed-by: jaxad0127.
  
33 error.xml
44 )
55
6INSTALL(FILES ${FILES} DESTINATION ${DATA_DIR}/graphics/sprits)
6INSTALL(FILES ${FILES} DESTINATION ${DATA_DIR}/graphics/sprites)
  
10221022 // we can go.
10231023 int hairstyles = 1;
10241024
1025 while (ItemDB::get(-hairstyles).getSprite(GENDER_MALE) != "error.xml")
1025 while (ItemDB::get(-hairstyles).getSprite(GENDER_MALE) !=
1026 paths.getValue("spriteErrorFile", "error.xml"))
10261027 hairstyles++;
10271028
10281029 mNumberOfHairstyles = hairstyles;
  
113113 /**
114114 * Directions, to be used as bitmask values
115115 */
116 enum { DOWN = 1, LEFT = 2, UP = 4, RIGHT = 8 };
116 enum BeingDirection
117 {
118 DOWN = 1,
119 LEFT = 2,
120 UP = 4,
121 RIGHT = 8
122 };
117123
118124 /**
119125 * Constructor.
  
109109
110110Configuration config; /**< XML file configuration reader */
111111Configuration branding; /**< XML branding information reader */
112Configuration paths; /**< XML default paths information reader */
112113Logger *logger; /**< Log object */
113114KeyboardConfig keyboard;
114115
727727 "zip",
728728 false);
729729 }
730
731 // Read default paths file 'data/paths.xml'
732 paths.init("paths.xml", true);
730733
731734 // Load XML databases
732735 ColorDB::load();
  
137137 }
138138}
139139
140void Configuration::init(const std::string &filename)
140void Configuration::init(const std::string &filename, bool useResManager)
141141{
142 mConfigPath = filename;
142 XML::Document doc(filename, useResManager);
143143
144 // Do not attempt to read config from non-existant file
145 FILE *testFile = fopen(filename.c_str(), "r");
146 if (!testFile)
144 if (!doc.rootNode())
145 {
146 logger->log("Couldn't open configuration file: %s", filename.c_str());
147147 return;
148 }
149
150 if (useResManager)
151 mConfigPath = "PhysFS://" + filename;
148152 else
149 fclose(testFile);
153 mConfigPath = filename;
150154
151 xmlDocPtr doc = xmlReadFile(filename.c_str(), NULL, 0);
155 xmlNodePtr rootNode = doc.rootNode();
152156
153 if (!doc) return;
154
155 xmlNodePtr rootNode = xmlDocGetRootElement(doc);
156
157157 if (!rootNode || !xmlStrEqual(rootNode->name, BAD_CAST "configuration"))
158158 {
159159 logger->log("Warning: No configuration file (%s)", filename.c_str());
160 xmlFreeDoc(doc);
161160 return;
162161 }
163162
164163 initFromXML(rootNode);
165
166 xmlFreeDoc(doc);
167164}
168165
169166void ConfigurationObject::writeToXML(xmlTextWriterPtr writer)
  
197197 /**
198198 * Reads config file and parse all options into memory.
199199 *
200 * \param filename path to config file
200 * @param filename path to config file
201 * @param useResManager Make use of the resource manager.
201202 */
202 void init(const std::string &filename);
203 void init(const std::string &filename, bool useResManager = false);
203204
204205 /**
205206 * Writes the current settings back to the config file.
245245 typedef ListenerMap::iterator ListenerMapIterator;
246246 ListenerMap mListenerMap;
247247
248 std::string mConfigPath; /**< Location of config file */
248 std::string mConfigPath; /**< Location of config file */
249249};
250250
251251extern Configuration branding;
252252extern Configuration config;
253extern Configuration paths;
253254
254255#endif
  
928928
929929 mMapName = mapPath;
930930
931 std::string fullMap = "maps/" + mapPath + ".tmx";
931 std::string fullMap = paths.getValue("maps", "maps/")
932 + mMapName + ".tmx";
932933 ResourceManager *resman = ResourceManager::getInstance();
933934 if (!resman->exists(fullMap))
934935 fullMap += ".gz";
  
107107 const int fontSize = (int) config.getValue("fontSize", 11);
108108 std::string fontFile = branding.getValue("font", "fonts/dejavusans.ttf");
109109 std::string path = resman->getPath(fontFile);
110
110111 try
111112 {
112113 mGuiFont = new TrueTypeFont(path, fontSize);
  
2929#include "gui/widgets/scrollarea.h"
3030
3131#include "resources/resourcemanager.h"
32#include "configuration.h"
3233
3334#include "utils/gettext.h"
3435
9494void HelpWindow::loadFile(const std::string &file)
9595{
9696 ResourceManager *resman = ResourceManager::getInstance();
97 std::string helpPath = branding.getValue("helpPath", "");
98 if (helpPath.empty())
99 helpPath = paths.getValue("help", "help/");
97100 std::vector<std::string> lines =
98 resman->loadTextFile("help/" + file + ".txt");
101 resman->loadTextFile(helpPath + file + ".txt");
99102
100103 for (unsigned int i = 0; i < lines.size(); ++i)
101104 {
  
102102 if (showImage)
103103 {
104104 ResourceManager *resman = ResourceManager::getInstance();
105 Image *image = resman->getImage("graphics/items/" + item.getImageName());
105 Image *image = resman->getImage(
106 paths.getValue("itemIcons", "graphics/items/")
107 + item.getImageName());
106108 mIcon->setImage(image);
107109 if (image)
108110 {
  
4040
4141#include <algorithm>
4242
43#define GUI_ROOT "graphics/gui/"
44
43static std::string defaultThemePath;
4544std::string Theme::mThemePath;
4645Theme *Theme::mInstance = 0;
4746
47// Set the theme path...
48static void initDefaultThemePath()
49{
50 ResourceManager *resman = ResourceManager::getInstance();
51 defaultThemePath = branding.getValue("guiThemePath", "");
52
53 if (!defaultThemePath.empty() && resman->isDirectory(defaultThemePath))
54 return;
55 else
56 defaultThemePath = "graphics/gui/";
57}
58
4859Skin::Skin(ImageRect skin, Image *close, Image *stickyUp, Image *stickyDown,
4960 const std::string &filePath,
5061 const std::string &name):
6666 mCloseImage(close),
6767 mStickyImageUp(stickyUp),
6868 mStickyImageDown(stickyDown)
69{
70}
69{}
7170
7271Skin::~Skin()
7372{
109109 mMinimumOpacity(-1.0f),
110110 mProgressColors(ProgressColors(THEME_PROG_END))
111111{
112 initDefaultThemePath();
113
112114 config.addListener("guialpha", this);
113115 loadColors();
114116
325325{
326326 if (!themePath.empty())
327327 {
328 themePath = GUI_ROOT + themePath;
328 themePath = defaultThemePath + themePath;
329329 if (PHYSFS_exists(themePath.c_str()))
330330 {
331331 mThemePath = themePath;
343343 // Try theme from branding
344344 if (!tryThemePath(branding.getValue("theme", "")))
345345 // Use default
346 mThemePath = GUI_ROOT;
346 mThemePath = defaultThemePath;
347347
348348 instance()->loadColors(mThemePath);
349349}
368368 return getThemePath() + "/" + path;
369369
370370 // Backup
371 return std::string(GUI_ROOT) + "/" + path;
371 return std::string(defaultThemePath) + "/" + path;
372372}
373373
374374Image *Theme::getImageFromTheme(const std::string &path)
520520
521521void Theme::loadColors(std::string file)
522522{
523 if (file == GUI_ROOT)
523 if (file == defaultThemePath)
524524 return; // No need to reload
525525
526526 if (file == "")
527 file = GUI_ROOT;
527 file = defaultThemePath;
528528
529529 file += "/colors.xml";
530530
  
2626#include "resources/image.h"
2727#include "resources/iteminfo.h"
2828#include "resources/resourcemanager.h"
29#include "configuration.h"
2930
3031Item::Item(int id, int quantity, bool equipment, bool equipped):
3132 mImage(0),
5858 mDrawImage->decRef();
5959
6060 ResourceManager *resman = ResourceManager::getInstance();
61 std::string imagePath = "graphics/items/" + getInfo().getImageName();
61 std::string imagePath = paths.getValue("itemIcons", "graphics/items/")
62 + getInfo().getImageName();
6263 mImage = resman->getImage(imagePath);
6364 mDrawImage = resman->getImage(imagePath);
6465
6566 if (!mImage)
66 mImage = Theme::getImageFromTheme("unknown-item.png");
67 mImage = Theme::getImageFromTheme(paths.getValue("unknownItemFile",
68 "unknown-item.png"));
6769
6870 if (!mDrawImage)
69 mDrawImage = Theme::getImageFromTheme("unknown-item.png");
71 mDrawImage = Theme::getImageFromTheme(
72 paths.getValue("unknownItemFile",
73 "unknown-item.png"));
7074}
  
10351035 sound.playSfx(soundFile);
10361036 }
10371037 else
1038 {
1039 sound.playSfx("sfx/fist-swish.ogg");
1040 }
1038 sound.playSfx(paths.getValue("attackSfxFile", "fist-swish.ogg"));
10411039
10421040 Net::getPlayerHandler()->attack(target->getId());
10431041 if ((Net::getNetworkType() == ServerInfo::TMWATHENA) && !keep)
  
3434
3535#include "resources/monsterdb.h"
3636#include "resources/monsterinfo.h"
37#include "configuration.h"
3738
3839Monster::Monster(int id, int subtype, Map *map):
3940 Being(id, subtype, map),
133133 for (std::list<std::string>::const_iterator i = sprites.begin();
134134 i != sprites.end(); i++)
135135 {
136 std::string file = "graphics/sprites/" + *i;
136 std::string file = paths.getValue("sprites",
137 "graphics/sprites/") + *i;
137138 mSprites.push_back(AnimatedSprite::load(file));
138139 }
139140
140141 // Ensure that something is shown
141142 if (mSprites.size() == 0)
142143 {
143 mSprites.push_back(AnimatedSprite::load("graphics/sprites/error.xml"));
144 mSprites.push_back(AnimatedSprite::load(
145 paths.getValue("sprites", "graphics/sprites/") +
146 paths.getValue("spriteErrorFile", "error.xml") ));
144147 }
145148
146149 if (Particle::enabled)
  
232232 }
233233 if (speed)
234234 {
235 /**
235 /*
236236 * The being's speed is transfered in tiles per second * 10
237237 * to keep it transferable in a Byte.
238238 * We set it back to tiles per second and in a float.
  
2929#include "log.h"
3030#include "particle.h"
3131#include "npc.h"
32#include "configuration.h"
3233
3334#include "gui/chat.h"
3435#include "gui/gui.h"
142142 player_node->setLevel(msg.readInt16());
143143 player_node->setCharacterPoints(msg.readInt16());
144144 player_node->setCorrectionPoints(msg.readInt16());
145 Particle* effect = particleEngine->addEffect("graphics/particles/levelup.particle.xml", 0, 0);
145 Particle* effect = particleEngine->addEffect(
146 paths.getValue("particles", "graphics/particles/")
147 + paths.getValue("levelUpEffectFile", "levelup.particle.xml"),
148 0, 0);
146149 player_node->controlParticle(effect);
147150 } break;
148151
  
3636#include "net/npchandler.h"
3737
3838#include "resources/npcdb.h"
39#include "configuration.h"
3940
4041NPC::NPC(int id, int subtype, Map *map):
4142 Player(id, subtype, map, true)
6969 i != info.sprites.end();
7070 i++)
7171 {
72 std::string file = "graphics/sprites/" + (*i)->sprite;
72 std::string file = paths.getValue("sprites",
73 "graphics/sprites/") + (*i)->sprite;
7374 int variant = (*i)->variant;
7475 mSprites.push_back(AnimatedSprite::load(file, variant));
7576 mSpriteIDs.push_back(0);
  
118118 default: break;
119119 }
120120 Particle *p;
121 p = particleEngine->addEffect("graphics/particles/" +
122 particleEffect, 0, 0, rotation);
121 p = particleEngine->addEffect(
122 paths.getValue("particles",
123 "graphics/particles/")
124 + particleEffect, 0, 0, rotation);
123125 controlParticle(p);
124126 }
125127
195195 if (!color.empty())
196196 filename += "|" + color;
197197
198 equipmentSprite = AnimatedSprite::load("graphics/sprites/" +
199 filename);
198 equipmentSprite = AnimatedSprite::load(
199 paths.getValue("sprites", "graphics/sprites/") + filename);
200200 }
201201
202202 if (equipmentSprite)
  
2424#include "log.h"
2525
2626#include "utils/xml.h"
27#include "configuration.h"
2728
2829namespace
2930{
4242 mLastEmote = 0;
4343
4444 EmoteSprite *unknownSprite = new EmoteSprite;
45 unknownSprite->sprite = AnimatedSprite::load("error.xml");
45 unknownSprite->sprite = AnimatedSprite::load(
46 paths.getValue("spriteErrorFile", "error.xml") );
4647 unknownSprite->name = "unknown";
4748 mUnknown.sprites.push_back(unknownSprite);
4849
7878 if (xmlStrEqual(spriteNode->name, BAD_CAST "sprite"))
7979 {
8080 EmoteSprite *currentSprite = new EmoteSprite;
81 std::string file = "graphics/sprites/" + (std::string)
82 (const char*) spriteNode->xmlChildrenNode->content;
81 std::string file = paths.getValue("sprites",
82 "graphics/sprites/")
83 + (std::string) (const char*)
84 spriteNode->xmlChildrenNode->content;
8385 currentSprite->sprite = AnimatedSprite::load(file,
8486 XML::getProperty(spriteNode, "variant", 0));
8587 currentInfo->sprites.push_back(currentSprite);
  
3030#include "utils/gettext.h"
3131#include "utils/stringutils.h"
3232#include "utils/xml.h"
33#include "configuration.h"
3334
3435#include <libxml/tree.h>
3536
116116 mUnknown = new ItemInfo;
117117 mUnknown->setName(_("Unknown item"));
118118 mUnknown->setImageName("");
119 mUnknown->setSprite("error.xml", GENDER_MALE);
120 mUnknown->setSprite("error.xml", GENDER_FEMALE);
119 std::string errFile = paths.getValue("spriteErrorFile", "error.xml");
120 mUnknown->setSprite(errFile, GENDER_MALE);
121 mUnknown->setSprite(errFile, GENDER_FEMALE);
121122
122123 XML::Document doc("items.xml");
123124 xmlNodePtr rootNode = doc.rootNode();
  
2222#include "resources/iteminfo.h"
2323
2424#include "resources/itemdb.h"
25#include "configuration.h"
2526
2627const std::string &ItemInfo::getSprite(Gender gender) const
2728{
6969
7070void ItemInfo::addSound(EquipmentSoundEvent event, const std::string &filename)
7171{
72 mSounds[event].push_back("sfx/" + filename);
72 mSounds[event].push_back(paths.getValue("sfx", "sfx/") + filename);
7373}
7474
7575const std::string &ItemInfo::getSound(EquipmentSoundEvent event) const
  
323323 if (config.getValue("showWarps", 1))
324324 {
325325 map->addParticleEffect(
326 "graphics/particles/warparea.particle.xml",
326 paths.getValue("particles",
327 "graphics/particles/")
328 + paths.getValue("portalEffectFile",
329 "warparea.particle.xml"),
327330 objX, objY, objW, objH);
328331 }
329332 }
  
3030#include "utils/xml.h"
3131
3232#include "net/net.h"
33#include "configuration.h"
3334
3435#define OLD_TMWATHENA_OFFSET 1002
3536
4646 if (mLoaded)
4747 unload();
4848
49 mUnknown.addSprite("error.xml");
49 mUnknown.addSprite(paths.getValue("spriteErrorFile", "error.xml"));
5050
5151 logger->log("Initializing monster database...");
5252
  
2323
2424#include "utils/dtor.h"
2525#include "utils/gettext.h"
26#include "configuration.h"
2627
2728MonsterInfo::MonsterInfo():
2829 mName(_("unnamed")),
4646 mSounds[event] = new std::vector<std::string>;
4747 }
4848
49 mSounds[event]->push_back("sfx/" + filename);
49 mSounds[event]->push_back(paths.getValue("sfx", "sfx/")
50 + filename);
5051}
5152
5253const std::string &MonsterInfo::getSound(MonsterSoundEvent event) const
  
2424#include "log.h"
2525
2626#include "utils/xml.h"
27#include "configuration.h"
2728
2829namespace
2930{
3939 unload();
4040
4141 NPCsprite *unknownSprite = new NPCsprite;
42 unknownSprite->sprite = "error.xml";
42 unknownSprite->sprite = paths.getValue("spriteErrorFile",
43 "error.xml");
4344 unknownSprite->variant = 0;
4445 mUnknown.sprites.push_back(unknownSprite);
4546
  
3030#include "resources/imageset.h"
3131#include "resources/resourcemanager.h"
3232
33#include "configuration.h"
34
3335#include "utils/xml.h"
3436
3537#include <set>
6363 {
6464 logger->log("Error, failed to parse %s", animationFile.c_str());
6565
66 if (animationFile != "graphics/sprites/error.xml")
66 std::string errorFile = paths.getValue("sprites", "graphics/sprites")
67 + paths.getValue("spriteErrorFile",
68 "error.xml");
69 if (animationFile != errorFile)
6770 {
68 return load("graphics/sprites/error.xml", 0);
71 return load(errorFile, 0);
6972 }
7073 else
7174 {
283283 if (filename.empty())
284284 return;
285285
286 XML::Document doc("graphics/sprites/" + filename);
286 XML::Document doc(paths.getValue("sprites", "graphics/sprites/")
287 + filename);
287288 xmlNodePtr rootNode = doc.rootNode();
288289
289290 if (!rootNode || !xmlStrEqual(rootNode->name, BAD_CAST "sprite"))
  
2121
2222#include "resources/wallpaper.h"
2323
24#include "resources/resourcemanager.h"
2425#include "log.h"
2526
2627#include "utils/stringutils.h"
28#include "configuration.h"
2729
2830#include <physfs.h>
2931
3434#include <time.h>
3535#include <vector>
3636
37#define WALLPAPER_FOLDER "graphics/images/"
38#define WALLPAPER_BASE "login_wallpaper.png"
39
4037struct WallpaperData
4138{
4239 std::string filename;
4444static std::vector<WallpaperData> wallpaperData;
4545static bool haveBackup; // Is the backup (no size given) version available?
4646
47static std::string wallpaperPath;
48static std::string wallpaperFile;
49
50// Search for the wallpaper path values sequentially..
51static void initDefaultWallpaperPaths()
52{
53 ResourceManager *resman = ResourceManager::getInstance();
54
55 // Init the path
56 wallpaperPath = branding.getValue("wallpapersPath", "");
57
58 if (!wallpaperPath.empty() && resman->isDirectory(wallpaperPath))
59 return;
60 else
61 wallpaperPath = paths.getValue("wallpapers", "");
62
63 if (wallpaperPath.empty() || !resman->isDirectory(wallpaperPath))
64 wallpaperPath = "graphics/images/";
65
66 // Init the default file
67 wallpaperFile = branding.getValue("wallpaperFile", "");
68
69 if (!wallpaperFile.empty() && resman->isDirectory(wallpaperFile))
70 return;
71 else
72 wallpaperFile = paths.getValue("wallpaperFile", "");
73
74 if (wallpaperFile.empty() || !resman->isDirectory(wallpaperFile))
75 wallpaperFile = "login_wallpaper.png";
76}
77
4778bool wallpaperCompare(WallpaperData a, WallpaperData b)
4879{
4980 int aa = a.width * a.height;
8787{
8888 wallpaperData.clear();
8989
90 char **imgs = PHYSFS_enumerateFiles(WALLPAPER_FOLDER);
90 initDefaultWallpaperPaths();
9191
92 char **imgs = PHYSFS_enumerateFiles(wallpaperPath.c_str());
93
9294 for (char **i = imgs; *i != NULL; i++)
9395 {
9496 int width;
9597 int height;
9698
9799 // If the backup file is found, we tell it.
98 if (strncmp (*i, WALLPAPER_BASE, strlen(*i)) == 0)
100 if (strncmp (*i, wallpaperFile.c_str(), strlen(*i)) == 0)
99101 haveBackup = true;
100102
101103 // If the image format is terminated by: "_<width>x<height>.png"
118118 if (sscanf(*i, filename.c_str(), &width, &height) == 2)
119119 {
120120 WallpaperData wp;
121 wp.filename = WALLPAPER_FOLDER;
121 wp.filename = wallpaperPath;
122122 wp.filename.append(*i);
123123 wp.width = width;
124124 wp.height = height;
164164
165165 // Return the backup file if everything else failed...
166166 if (haveBackup)
167 return std::string(WALLPAPER_FOLDER WALLPAPER_BASE);
167 return std::string(wallpaperPath + wallpaperFile);
168168
169169 // Return an empty string if everything else failed
170170 return std::string();
  
3737 static void loadWallpapers();
3838
3939 /**
40 * Returns the larget wallpaper for the given resolution, or the
40 * Returns the largest wallpaper for the given resolution, or the
4141 * default wallpaper if none are found.
4242 *
4343 * @param width the desired width
  
2727#include "resources/resourcemanager.h"
2828#include "resources/soundeffect.h"
2929
30#include "configuration.h"
31
3032Sound::Sound():
3133 mInstalled(false),
3234 mSfxVolume(100),
151151 // it to a temporary physical file so that SDL_mixer can stream it.
152152 logger->log("Loading music \"%s\" from temporary file tempMusic.ogg",
153153 path.c_str());
154 bool success = resman->copyFile("music/" + filename, "tempMusic.ogg");
154 bool success = resman->copyFile(
155 paths.getValue("music", "music/")
156 + filename, "tempMusic.ogg");
155157 if (success)
156158 path = resman->getPath("tempMusic.ogg");
157159 else
239239 return;
240240
241241 ResourceManager *resman = ResourceManager::getInstance();
242 SoundEffect *sample = resman->getSoundEffect(path);
242 SoundEffect *sample = resman->getSoundEffect(
243 paths.getValue("sfx", "sfx/") + path);
243244 if (sample)
244245 {
245246 logger->log("Sound::playSfx() Playing: %s", path.c_str());
  
2828
2929#include "utils/xml.h"
3030
31#include "configuration.h"
32
3133#include <map>
3234
3335#define STATUS_EFFECTS_FILE "status-effects.xml"
7070 else
7171 {
7272 AnimatedSprite *sprite = AnimatedSprite::load(
73 "graphics/sprites/" + mIcon);
73 paths.getValue("sprites", "graphics/sprites/") + mIcon);
7474 if (false && sprite)
7575 {
7676 sprite->play(ACTION_DEFAULT);
125125
126126 if (!rootNode || !xmlStrEqual(rootNode->name, BAD_CAST "status-effects"))
127127 {
128 logger->log("Error loading status effects file: "
129 STATUS_EFFECTS_FILE);
128 logger->log("Error loading status effects file: " STATUS_EFFECTS_FILE);
130129 return;
131130 }
132131