~ubuntu-branches/ubuntu/wily/xmoto/wily-proposed

« back to all changes in this revision

Viewing changes to src/Theme.h

  • Committer: Bazaar Package Importer
  • Author(s): Samuel Mimram
  • Date: 2006-09-14 21:01:20 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20060914210120-bvr7yu9rafb3fivp
Tags: 0.2.1-1
* New upstream release.
* Removed manpages and desktop files from the Debian package as they are now
  provided upstream.
* Make the package binNMUable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*=============================================================================
 
2
XMOTO
 
3
Copyright (C) 2005-2006 Rasmus Neckelmann (neckelmann@gmail.com)
 
4
 
 
5
This file is part of XMOTO.
 
6
 
 
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.
 
11
 
 
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.
 
16
 
 
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
=============================================================================*/
 
21
 
 
22
#ifndef __THEME_H__
 
23
#define __THEME_H__
 
24
 
 
25
#include <string>
 
26
#include <vector>
 
27
 
 
28
#include "BuildConfig.h"
 
29
#include "VTexture.h"
 
30
#include "VFileIO.h"
 
31
#include "WWW.h"
 
32
 
 
33
class ProxySettings;
 
34
class WebThemes;
 
35
 
 
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"
 
46
 
 
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)
 
58
 
 
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)
 
71
#endif
 
72
 
 
73
#define THEME_DEFAULT_THEMENAME "Classic"
 
74
 
 
75
  enum SpriteType {
 
76
    SPRITE_TYPE_ANIMATION,
 
77
    SPRITE_TYPE_BIKERPART,
 
78
    SPRITE_TYPE_DECORATION,
 
79
    SPRITE_TYPE_EFFECT,
 
80
    SPRITE_TYPE_FONT,
 
81
    SPRITE_TYPE_MISC,
 
82
    SPRITE_TYPE_TEXTURE,
 
83
    SPRITE_TYPE_UI
 
84
  };
 
85
  
 
86
  enum SpriteBlendMode {
 
87
    SPRITE_BLENDMODE_DEFAULT,
 
88
    SPRITE_BLENDMODE_ADDITIVE
 
89
  };
 
90
 
 
91
class Theme;
 
92
class BikerTheme;
 
93
 
 
94
class Sprite {
 
95
  public:
 
96
  Sprite(Theme* p_associated_theme, std::string v_name);
 
97
  virtual ~Sprite();
 
98
 
 
99
  virtual enum SpriteType getType() = 0;
 
100
  std::string getName();
 
101
  SpriteBlendMode getBlendMode();
 
102
  void setBlendMode(SpriteBlendMode Mode);
 
103
  void load();
 
104
 
 
105
  /* 
 
106
     the bSmall, bClamp, bFilter parameters are considerated 
 
107
     only the first time that getTexture is called for a given sprite
 
108
  */
 
109
  vapp::Texture* getTexture(bool bSmall=false, bool bClamp=false, bool bFilter=true);
 
110
 
 
111
 protected:
 
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();
 
116
 
 
117
  private:
 
118
  Theme* m_associated_theme;
 
119
  std::string m_name;
 
120
  SpriteBlendMode m_blendmode;
 
121
};
 
122
 
 
123
class SimpleFrameSprite : public Sprite {
 
124
 public:
 
125
  SimpleFrameSprite(Theme* p_associated_theme, std::string p_name, std::string p_fileName);
 
126
  virtual ~SimpleFrameSprite();
 
127
 
 
128
 protected:
 
129
  vapp::Texture* getCurrentTexture();
 
130
  std::string getCurrentTextureFileName();
 
131
  void setCurrentTexture(vapp::Texture *p_texture);
 
132
 
 
133
 private:
 
134
  std::string m_fileName;
 
135
  vapp::Texture* m_texture;
 
136
};
 
137
 
 
138
class TextureSprite : public SimpleFrameSprite {
 
139
 public:
 
140
  TextureSprite(Theme* p_associated_theme, std::string p_name, std::string p_filename);
 
141
  virtual ~TextureSprite();
 
142
  enum SpriteType getType();
 
143
 
 
144
 protected:
 
145
  std::string getFileDir();
 
146
 
 
147
 private:
 
148
};
 
149
 
 
150
class BikerPartSprite : public SimpleFrameSprite {
 
151
 public:
 
152
  BikerPartSprite(Theme* p_associated_theme, std::string p_name, std::string p_filename);
 
153
  virtual ~BikerPartSprite();
 
154
  enum SpriteType getType();
 
155
 
 
156
 protected:
 
157
  std::string getFileDir();
 
158
 
 
159
 private:
 
160
};
 
161
 
 
162
class AnimationSprite;
 
163
 
 
164
class AnimationSpriteFrame {
 
165
 public:
 
166
  AnimationSpriteFrame(AnimationSprite *p_associatedAnimationSprite,
 
167
                       float p_centerX,
 
168
                       float p_centerY,
 
169
                       float p_width,
 
170
                       float p_height,
 
171
                       float p_delay
 
172
                       );
 
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;
 
181
 
 
182
 private:
 
183
  AnimationSprite *m_associatedAnimationSprite;
 
184
 
 
185
  vapp::Texture* m_texture;
 
186
  float m_centerX;
 
187
  float m_centerY;
 
188
  float m_width;
 
189
  float m_height;
 
190
  float m_delay;
 
191
};
 
192
 
 
193
class AnimationSprite : public Sprite {
 
194
 public:
 
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();
 
198
  float getCenterX();
 
199
  float getCenterY();
 
200
  float getWidth();
 
201
  float getHeight();
 
202
  void  addFrame(float p_centerX, float p_centerY, float p_width, float p_height, float p_delay);
 
203
 
 
204
 protected:
 
205
  vapp::Texture* getCurrentTexture();
 
206
  std::string getCurrentTextureFileName();
 
207
  void setCurrentTexture(vapp::Texture *p_texture);
 
208
  std::string getFileDir();
 
209
 
 
210
 private:
 
211
  int getCurrentFrame();
 
212
 
 
213
  std::string m_fileBase;
 
214
  std::string m_fileExtension;
 
215
  unsigned int m_current_frame;
 
216
  void cleanFrames();
 
217
  std::vector<AnimationSpriteFrame*> m_frames;
 
218
  float m_fFrameTime;
 
219
};
 
220
 
 
221
class EffectSprite : public SimpleFrameSprite {
 
222
 public:
 
223
  EffectSprite(Theme* p_associated_theme, std::string p_name, std::string p_filename);
 
224
  virtual ~EffectSprite();
 
225
  enum SpriteType getType();
 
226
 
 
227
 protected:
 
228
  std::string getFileDir();
 
229
 
 
230
 private:
 
231
};
 
232
 
 
233
class FontSprite : public SimpleFrameSprite {
 
234
 public:
 
235
  FontSprite(Theme* p_associated_theme, std::string p_name, std::string p_filename);
 
236
  virtual ~FontSprite();
 
237
  enum SpriteType getType();
 
238
 
 
239
 protected:
 
240
  std::string getFileDir();
 
241
 
 
242
 private:
 
243
};
 
244
 
 
245
class MiscSprite : public SimpleFrameSprite {
 
246
 public:
 
247
  MiscSprite(Theme* p_associated_theme, std::string p_name, std::string p_filename);
 
248
  virtual ~MiscSprite();
 
249
  enum SpriteType getType();
 
250
 
 
251
 protected:
 
252
  std::string getFileDir();
 
253
 
 
254
 private:
 
255
};
 
256
 
 
257
class UISprite : public SimpleFrameSprite {
 
258
 public:
 
259
  UISprite(Theme* p_associated_theme, std::string p_name, std::string p_filename);
 
260
  virtual ~UISprite();
 
261
  enum SpriteType getType();
 
262
 
 
263
 protected:
 
264
  std::string getFileDir();
 
265
 
 
266
 private:
 
267
};
 
268
 
 
269
class DecorationSprite : public SimpleFrameSprite {
 
270
 public:
 
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();
 
274
 
 
275
  float getWidth();
 
276
  float getHeight();
 
277
  float getCenterX();
 
278
  float getCenterY();
 
279
 
 
280
 protected:
 
281
  std::string getFileDir();
 
282
 
 
283
 private:
 
284
  float m_width;
 
285
  float m_height;
 
286
  float m_centerX;
 
287
  float m_centerY;
 
288
 
 
289
};
 
290
 
 
291
class Theme {
 
292
  public:
 
293
  Theme();
 
294
  ~Theme();
 
295
 
 
296
  void load(std::string p_themeFile);
 
297
 
 
298
  Sprite* getSprite(enum SpriteType pSpriteType, std::string pName);
 
299
  vapp::Texture* loadTexture(std::string p_fileName,
 
300
                             bool bSmall=false,
 
301
                             bool bClamp=false,
 
302
                             bool bFilter=true);
 
303
 
 
304
  vapp::Texture* getDefaultFont();
 
305
  std::vector<Sprite*> getSpritesList();
 
306
  std::vector<std::string>* getRequiredFiles();
 
307
 
 
308
  BikerTheme* getPlayerTheme();
 
309
#if defined(ALLOW_GHOST)
 
310
  BikerTheme* getGhostTheme();
 
311
#endif
 
312
 
 
313
  private:
 
314
  void initDefaultFont();
 
315
 
 
316
  vapp::TextureManager m_texMan;
 
317
  std::string m_name;
 
318
  std::vector<Sprite*> m_sprites;
 
319
  std::vector<std::string> m_requiredFiles;
 
320
 
 
321
  vapp::Texture *m_pDefaultFontTexture;
 
322
 
 
323
  BikerTheme *m_player;
 
324
#if defined(ALLOW_GHOST)
 
325
  BikerTheme *m_ghost;
 
326
#endif
 
327
 
 
328
  void cleanSprites();
 
329
 
 
330
  void loadSpritesFromXML(TiXmlElement *p_ThemeXmlDataElement);
 
331
 
 
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);
 
340
  
 
341
  SpriteBlendMode strToBlendMode(const std::string &s);
 
342
  std::string blendModeToStr(SpriteBlendMode Mode);
 
343
};
 
344
 
 
345
class BikerTheme {
 
346
 public:
 
347
  BikerTheme(Theme* p_associated_theme,
 
348
             std::string p_Body,
 
349
             std::string p_Front,
 
350
             std::string p_Rear,
 
351
             std::string p_Wheel,
 
352
             std::string p_LowerArm,
 
353
             std::string p_LowerLeg,
 
354
             std::string p_Torso,
 
355
             std::string p_UpperArm,
 
356
             std::string p_UpperLeg,
 
357
             vapp::Color p_UglyRiderColor,
 
358
             vapp::Color p_UglyWheelColor
 
359
             );
 
360
  ~BikerTheme();
 
361
 
 
362
  Sprite* getBody();
 
363
  Sprite* getFront();
 
364
  Sprite* getRear();
 
365
  Sprite* getWheel();
 
366
  Sprite* getLowerArm();
 
367
  Sprite* getLowerLeg();
 
368
  Sprite* getTorso();
 
369
  Sprite* getUpperArm();
 
370
  Sprite* getUpperLeg();
 
371
 
 
372
  vapp::Color getUglyRiderColor();
 
373
  vapp::Color getUglyWheelColor();
 
374
 
 
375
 private:
 
376
  Theme* m_associated_theme;
 
377
 
 
378
  vapp::Color m_UglyRiderColor;
 
379
  vapp::Color m_UglyWheelColor;
 
380
  
 
381
  std::string m_Body;
 
382
  std::string m_Front;
 
383
  std::string m_Rear;
 
384
  std::string m_Wheel;
 
385
  std::string m_LowerArm;
 
386
  std::string m_LowerLeg;
 
387
  std::string m_Torso;
 
388
  std::string m_UpperArm;
 
389
  std::string m_UpperLeg;
 
390
};
 
391
 
 
392
class ThemeChoice {
 
393
 public:
 
394
  ThemeChoice(std::string p_themeName, std::string p_themeFile, bool p_hosted);
 
395
  ~ThemeChoice();
 
396
  std::string ThemeName();
 
397
  std::string ThemeFile();
 
398
 
 
399
  void setRequireUpdate(bool b);
 
400
  bool getRequireUpdate();
 
401
  void setHosted(bool b);
 
402
  bool getHosted();
 
403
 
 
404
 private:
 
405
  std::string m_themeName;
 
406
  std::string m_themeFile;
 
407
  bool m_hosted;
 
408
  bool m_requireUpdate;
 
409
};
 
410
 
 
411
class ThemeChoicer {
 
412
 public:
 
413
 
 
414
#if defined(SUPPORT_WEBACCESS)
 
415
  ThemeChoicer(vapp::WWWAppInterface *p_WebApp = NULL,
 
416
               const ProxySettings *p_proxy_settings = NULL);          
 
417
#else
 
418
  ThemeChoicer(void);          
 
419
#endif
 
420
 
 
421
  ~ThemeChoicer();
 
422
 
 
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);
 
427
 
 
428
#if defined(SUPPORT_WEBACCESS)
 
429
  void updateFromWWW();
 
430
  void updateThemeFromWWW(ThemeChoice* pThemeChoice);
 
431
  bool isUpdatableThemeFromWWW(ThemeChoice* pThemeChoice);
 
432
 
 
433
  void setURL(const std::string &p_url);
 
434
  void setURLBase(const std::string &p_urlBase);
 
435
#endif
 
436
 
 
437
 private:
 
438
  void cleanList();
 
439
  void initList();
 
440
  std::string getThemeNameFromFile(std::string p_themeFile);
 
441
  
 
442
#if defined(SUPPORT_WEBACCESS)
 
443
  WebThemes *m_webThemes;
 
444
#endif
 
445
 
 
446
  std::vector<ThemeChoice*> m_choices;
 
447
};
 
448
 
 
449
#endif /* __THEME_H__ */