-
Notifications
You must be signed in to change notification settings - Fork 59
/
CGameSkin.h
142 lines (121 loc) · 4.65 KB
/
CGameSkin.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/////////////////////////////////////////
//
// OpenLieroX
//
// code under LGPL, based on JasonBs work,
// enhanced by Dark Charlie and Albert Zeyer
//
//
/////////////////////////////////////////
// Worm skin class
// Created 16/6/08
// Karel Petranek
#ifndef __CWORMSKIN_H__
#define __CWORMSKIN_H__
#include "GfxPrimitives.h"
#include "SmartPointer.h"
#include "Color.h"
#include "ThreadPool.h"
#include "DynDraw.h"
#include "util/CustomVar.h"
#include "game/Attr.h"
// Some basic defines
#define CPU_WIDTH 10
#define SHADOW_OPACITY 96 // TODO: move this to some more general header
struct GameSkinPreviewDrawer;
class CMap;
class CViewport;
struct SkinAction_Colorize;
struct SkinAction_Load;
#define WORM_SKIN_FRAME_WIDTH 32
#define WORM_SKIN_FRAME_HEIGHT 18
#define WORM_SKIN_FRAME_SPACING 4
#define WORM_SKIN_WIDTH 20
#define WORM_SKIN_HEIGHT 18
class CGameSkin : public CustomVar {
public:
CGameSkin(bool graphical = true) : isGraphical(graphical), thread(NULL) { *this = WormSkin(); }
CGameSkin(int fw, int fh, int fs, int sw, int sh, bool graphical);
CGameSkin(const CGameSkin& skin);
CGameSkin(const CGameSkin& skin, bool graphical);
~CGameSkin();
static CGameSkin WormSkin() {
CGameSkin skin(WORM_SKIN_FRAME_WIDTH,
WORM_SKIN_FRAME_HEIGHT,
WORM_SKIN_FRAME_SPACING,
WORM_SKIN_WIDTH,
WORM_SKIN_HEIGHT,
false);
return skin;
}
CGameSkin& operator=(const CGameSkin& oth);
virtual BaseObject* parentObject() const;
private:
bool isGraphical; // if false, we don't do any loading
bool loaded;
SmartPointer<SDL_Surface> bmpSurface;
SmartPointer<SDL_Surface> bmpNormal;
SmartPointer<SDL_Surface> bmpMirrored;
SmartPointer<SDL_Surface> bmpShadow;
SmartPointer<SDL_Surface> bmpMirroredShadow;
SmartPointer<SDL_Surface> bmpPreview;
ATTR(CGameSkin, std::string, sFileName, 1, { onUpdate = onFilenameUpdate; serverside = false; })
ATTR(CGameSkin, Color, iColor, 2, { defaultValue = Color(128, 128, 128); onUpdate = onColorUpdate; serverside = false; })
ATTR(CGameSkin, Color, iDefaultColor, 3, { defaultValue = Color(128, 128, 128); serverside = false; })
bool bColorized;
int iBotIcon;
int iFrameWidth; // Width of one frame
int iFrameHeight; // Height of one frame
int iFrameSpacing; // Gap between two frames
int iSkinWidth; // Width of the skin itself
int iSkinHeight; // Height of the skin itself
struct Thread;
Thread* thread;
friend struct Thread;
friend struct GameSkinPreviewDrawer;
friend struct SkinAction_Colorize;
friend struct SkinAction_Load;
friend void skin_load(const CGameSkin& s);
private:
void init(int fw, int fh, int fs, int sw, int sh); void uninit();
void createSurfaces();
bool PrepareNormalSurface();
bool PrepareShadowSurface();
bool PrepareColorizedSurface();
bool PreparePreviewSurface();
bool PrepareMirrorSurface();
void GenerateNormalSurface();
void GenerateShadow();
void GeneratePreview();
void GenerateMirroredImage();
void Colorize_Execute(bool& breakSignal);
void Load_Execute(bool& breakSignal);
void DrawInternal(SDL_Surface *surf, int x, int y, int frame, bool draw_cpu, bool mirrored, bool blockUntilReady, bool half) const;
static void onFilenameUpdate(BaseObject* base, const AttrDesc* attrDesc, ScriptVar_t oldValue);
static void onColorUpdate(BaseObject* base, const AttrDesc* attrDesc, ScriptVar_t oldValue);
public:
void Draw(SDL_Surface *surf, int x, int y, int frame, bool draw_cpu, bool mirrored, bool blockUntilReady = false) const;
void DrawHalf(SDL_Surface *surf, int x, int y, int frame, bool draw_cpu, bool mirrored, bool blockUntilReady = false) const;
void DrawShadow(SDL_Surface *surf, int x, int y, int frame, bool mirrored) const;
void DrawShadowOnMap(CMap* cMap, CViewport* v, SDL_Surface *surf, int x, int y, int frame, bool mirrored) const;
Color renderColorAt(int x, int y, int frame, bool mirrored) const;
void Colorize(Color col);
void ColorizeDefault() { Colorize(iDefaultColor); }
void Change(const std::string& file);
SmartPointer<DynDrawIntf> getPreview();
std::string getFileName() const { return sFileName; }
int getBotIcon() const { return iBotIcon; }
void setBotIcon(int _i) { iBotIcon = _i; }
Color getDefaultColor() const { return iDefaultColor; }
void setDefaultColor(Color _c) { iDefaultColor = _c; }
int getFrameCount() const;
int getSkinWidth() const { return iSkinWidth; }
int getSkinHeight() const { return iSkinHeight; }
// --- CustomVar ---
virtual CustomVar* copy() const;
virtual bool operator==(const CustomVar& o) const;
virtual bool operator<(const CustomVar& o) const;
virtual std::string toString() const;
virtual bool fromString( const std::string & str);
};
#endif