1
/*=============================================================================
3
Copyright (C) 2005-2006 Rasmus Neckelmann (neckelmann@gmail.com)
5
This file is part of XMOTO.
7
XMOTO is free software; you can redistribute it and/or modify
8
it under the terms of the GNU General Public License as published by
9
the Free Software Foundation; either version 2 of the License, or
10
(at your option) any later version.
12
XMOTO is distributed in the hope that it will be useful,
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
GNU General Public License for more details.
17
You should have received a copy of the GNU General Public License
18
along with XMOTO; if not, write to the Free Software
19
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
=============================================================================*/
28
#include "BuildConfig.h"
36
#define THEMES_DIRECTORY "Themes"
37
#define THEME_SPRITE_FILE_DIR "Textures"
38
#define THEME_DECORATION_SPRITE_FILE_DIR THEME_SPRITE_FILE_DIR"/Sprites"
39
#define THEME_EFFECT_SPRITE_FILE_DIR THEME_SPRITE_FILE_DIR"/Effects"
40
#define THEME_MISC_SPRITE_FILE_DIR THEME_SPRITE_FILE_DIR"/Misc"
41
#define THEME_ANIMATION_SPRITE_FILE_DIR THEME_SPRITE_FILE_DIR"/Anims"
42
#define THEME_BIKERPART_SPRITE_FILE_DIR THEME_SPRITE_FILE_DIR"/Riders"
43
#define THEME_UI_SPRITE_FILE_DIR THEME_SPRITE_FILE_DIR"/UI"
44
#define THEME_TEXTURE_SPRITE_FILE_DIR THEME_SPRITE_FILE_DIR"/Textures"
45
#define THEME_FONT_SPRITE_FILE_DIR THEME_SPRITE_FILE_DIR"/Fonts"
47
#define THEME_PLAYER_BODY "PlayerBikerBody"
48
#define THEME_PLAYER_FRONT "PlayerBikerFront"
49
#define THEME_PLAYER_REAR "PlayerBikerRear"
50
#define THEME_PLAYER_WHEEL "PlayerBikerWheel"
51
#define THEME_PLAYER_LOWERARM "PlayerLowerArm"
52
#define THEME_PLAYER_LOWERLEG "PlayerLowerLeg"
53
#define THEME_PLAYER_TORSO "PlayerTorso"
54
#define THEME_PLAYER_UPPERARM "PlayerUpperArm"
55
#define THEME_PLAYER_UPPERLEG "PlayerUpperLeg"
56
#define THEME_PLAYER_UGLYRIDERCOLOR MAKE_COLOR(0,255,0,255)
57
#define THEME_PLAYER_UGLYWHEELCOLOR MAKE_COLOR(255,0,0,255)
59
#if defined(ALLOW_GHOST)
60
#define THEME_GHOST_BODY "GhostBikerBody"
61
#define THEME_GHOST_FRONT "GhostBikerFront"
62
#define THEME_GHOST_REAR "GhostBikerRear"
63
#define THEME_GHOST_WHEEL "GhostBikerWheel"
64
#define THEME_GHOST_LOWERARM "GhostLowerArm"
65
#define THEME_GHOST_LOWERLEG "GhostLowerLeg"
66
#define THEME_GHOST_TORSO "GhostTorso"
67
#define THEME_GHOST_UPPERARM "GhostUpperArm"
68
#define THEME_GHOST_UPPERLEG "GhostUpperLeg"
69
#define THEME_GHOST_UGLYRIDERCOLOR MAKE_COLOR(100,100,128,255)
70
#define THEME_GHOST_UGLYWHEELCOLOR MAKE_COLOR(100,100,128,255)
73
#define THEME_DEFAULT_THEMENAME "Classic"
76
SPRITE_TYPE_ANIMATION,
77
SPRITE_TYPE_BIKERPART,
78
SPRITE_TYPE_DECORATION,
86
enum SpriteBlendMode {
87
SPRITE_BLENDMODE_DEFAULT,
88
SPRITE_BLENDMODE_ADDITIVE
96
Sprite(Theme* p_associated_theme, std::string v_name);
99
virtual enum SpriteType getType() = 0;
100
std::string getName();
101
SpriteBlendMode getBlendMode();
102
void setBlendMode(SpriteBlendMode Mode);
106
the bSmall, bClamp, bFilter parameters are considerated
107
only the first time that getTexture is called for a given sprite
109
vapp::Texture* getTexture(bool bSmall=false, bool bClamp=false, bool bFilter=true);
112
virtual vapp::Texture* getCurrentTexture() = 0;
113
virtual std::string getCurrentTextureFileName() = 0;
114
virtual void setCurrentTexture(vapp::Texture *p_texture) = 0;
115
virtual std::string getFileDir();
118
Theme* m_associated_theme;
120
SpriteBlendMode m_blendmode;
123
class SimpleFrameSprite : public Sprite {
125
SimpleFrameSprite(Theme* p_associated_theme, std::string p_name, std::string p_fileName);
126
virtual ~SimpleFrameSprite();
129
vapp::Texture* getCurrentTexture();
130
std::string getCurrentTextureFileName();
131
void setCurrentTexture(vapp::Texture *p_texture);
134
std::string m_fileName;
135
vapp::Texture* m_texture;
138
class TextureSprite : public SimpleFrameSprite {
140
TextureSprite(Theme* p_associated_theme, std::string p_name, std::string p_filename);
141
virtual ~TextureSprite();
142
enum SpriteType getType();
145
std::string getFileDir();
150
class BikerPartSprite : public SimpleFrameSprite {
152
BikerPartSprite(Theme* p_associated_theme, std::string p_name, std::string p_filename);
153
virtual ~BikerPartSprite();
154
enum SpriteType getType();
157
std::string getFileDir();
162
class AnimationSprite;
164
class AnimationSpriteFrame {
166
AnimationSpriteFrame(AnimationSprite *p_associatedAnimationSprite,
173
virtual ~AnimationSpriteFrame();
174
vapp::Texture *getTexture();
175
void setTexture(vapp::Texture *p_texture);
176
float getCenterX() const;
177
float getCenterY() const;
178
float getWidth() const;
179
float getHeight() const;
180
float getDelay() const;
183
AnimationSprite *m_associatedAnimationSprite;
185
vapp::Texture* m_texture;
193
class AnimationSprite : public Sprite {
195
AnimationSprite(Theme* p_associated_theme, std::string p_name, std::string p_fileBase, std::string p_fileExtention);
196
virtual ~AnimationSprite();
197
enum SpriteType getType();
202
void addFrame(float p_centerX, float p_centerY, float p_width, float p_height, float p_delay);
205
vapp::Texture* getCurrentTexture();
206
std::string getCurrentTextureFileName();
207
void setCurrentTexture(vapp::Texture *p_texture);
208
std::string getFileDir();
211
int getCurrentFrame();
213
std::string m_fileBase;
214
std::string m_fileExtension;
215
unsigned int m_current_frame;
217
std::vector<AnimationSpriteFrame*> m_frames;
221
class EffectSprite : public SimpleFrameSprite {
223
EffectSprite(Theme* p_associated_theme, std::string p_name, std::string p_filename);
224
virtual ~EffectSprite();
225
enum SpriteType getType();
228
std::string getFileDir();
233
class FontSprite : public SimpleFrameSprite {
235
FontSprite(Theme* p_associated_theme, std::string p_name, std::string p_filename);
236
virtual ~FontSprite();
237
enum SpriteType getType();
240
std::string getFileDir();
245
class MiscSprite : public SimpleFrameSprite {
247
MiscSprite(Theme* p_associated_theme, std::string p_name, std::string p_filename);
248
virtual ~MiscSprite();
249
enum SpriteType getType();
252
std::string getFileDir();
257
class UISprite : public SimpleFrameSprite {
259
UISprite(Theme* p_associated_theme, std::string p_name, std::string p_filename);
261
enum SpriteType getType();
264
std::string getFileDir();
269
class DecorationSprite : public SimpleFrameSprite {
271
DecorationSprite(Theme* p_associated_theme, std::string p_name, std::string p_filename, float p_width, float p_height, float p_centerX, float p_centerY, SpriteBlendMode p_blendmode);
272
virtual ~DecorationSprite();
273
enum SpriteType getType();
281
std::string getFileDir();
296
void load(std::string p_themeFile);
298
Sprite* getSprite(enum SpriteType pSpriteType, std::string pName);
299
vapp::Texture* loadTexture(std::string p_fileName,
304
vapp::Texture* getDefaultFont();
305
std::vector<Sprite*> getSpritesList();
306
std::vector<std::string>* getRequiredFiles();
308
BikerTheme* getPlayerTheme();
309
#if defined(ALLOW_GHOST)
310
BikerTheme* getGhostTheme();
314
void initDefaultFont();
316
vapp::TextureManager m_texMan;
318
std::vector<Sprite*> m_sprites;
319
std::vector<std::string> m_requiredFiles;
321
vapp::Texture *m_pDefaultFontTexture;
323
BikerTheme *m_player;
324
#if defined(ALLOW_GHOST)
330
void loadSpritesFromXML(TiXmlElement *p_ThemeXmlDataElement);
332
void newAnimationSpriteFromXML(TiXmlElement *pVarElem);
333
void newBikerPartSpriteFromXML(TiXmlElement *pVarElem);
334
void newDecorationSpriteFromXML(TiXmlElement *pVarElem);
335
void newEffectSpriteFromXML(TiXmlElement *pVarElem);
336
void newFontSpriteFromXML(TiXmlElement *pVarElem);
337
void newMiscSpriteFromXML(TiXmlElement *pVarElem);
338
void newTextureSpriteFromXML(TiXmlElement *pVarElem);
339
void newUISpriteFromXML(TiXmlElement *pVarElem);
341
SpriteBlendMode strToBlendMode(const std::string &s);
342
std::string blendModeToStr(SpriteBlendMode Mode);
347
BikerTheme(Theme* p_associated_theme,
352
std::string p_LowerArm,
353
std::string p_LowerLeg,
355
std::string p_UpperArm,
356
std::string p_UpperLeg,
357
vapp::Color p_UglyRiderColor,
358
vapp::Color p_UglyWheelColor
366
Sprite* getLowerArm();
367
Sprite* getLowerLeg();
369
Sprite* getUpperArm();
370
Sprite* getUpperLeg();
372
vapp::Color getUglyRiderColor();
373
vapp::Color getUglyWheelColor();
376
Theme* m_associated_theme;
378
vapp::Color m_UglyRiderColor;
379
vapp::Color m_UglyWheelColor;
385
std::string m_LowerArm;
386
std::string m_LowerLeg;
388
std::string m_UpperArm;
389
std::string m_UpperLeg;
394
ThemeChoice(std::string p_themeName, std::string p_themeFile, bool p_hosted);
396
std::string ThemeName();
397
std::string ThemeFile();
399
void setRequireUpdate(bool b);
400
bool getRequireUpdate();
401
void setHosted(bool b);
405
std::string m_themeName;
406
std::string m_themeFile;
408
bool m_requireUpdate;
414
#if defined(SUPPORT_WEBACCESS)
415
ThemeChoicer(vapp::WWWAppInterface *p_WebApp = NULL,
416
const ProxySettings *p_proxy_settings = NULL);
423
bool ExistThemeName(std::string p_themeName);
424
std::string getFileName(std::string p_themeName);
425
std::vector<ThemeChoice*> getChoices();
426
ThemeChoice* getChoiceByName(std::string p_themeName);
428
#if defined(SUPPORT_WEBACCESS)
429
void updateFromWWW();
430
void updateThemeFromWWW(ThemeChoice* pThemeChoice);
431
bool isUpdatableThemeFromWWW(ThemeChoice* pThemeChoice);
433
void setURL(const std::string &p_url);
434
void setURLBase(const std::string &p_urlBase);
440
std::string getThemeNameFromFile(std::string p_themeFile);
442
#if defined(SUPPORT_WEBACCESS)
443
WebThemes *m_webThemes;
446
std::vector<ThemeChoice*> m_choices;
449
#endif /* __THEME_H__ */