-
Notifications
You must be signed in to change notification settings - Fork 4
/
tibiahandler.h
201 lines (176 loc) · 7.57 KB
/
tibiahandler.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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
#ifndef TIBIAHANDLER_H
#define TIBIAHANDLER_H
#include <QListView>
#include <QTreeView>
#include "tibiafile.h"
#include "spritefile.h"
#include "itemfile.h"
#include "picturefile.h"
#include "chasewidget.h"
#include "outputwidget.h"
class ItemModel;
class SpriteModel;
class PictureModel;
class DatFormat;
#define USER_OPERATION_SEARCH 0x01
#define USER_OPERATION_COMPILE 0x02
#define USER_OPERATION_EXPORT 0x03
#define USER_OPERATION_IMPORT 0x04
#define OUTFIT_DIRECTION_DEFAULT 2
#define OUTFIT_DIRECTION_NORTH 0
#define OUTFIT_DIRECTION_EAST 1
#define OUTFIT_DIRECTION_SOUTH 2
#define OUTFIT_DIRECTION_WEST 3
#define PROJECTILE_DIRECTION_DEFAULT 0
#define PROJECTILE_DIRECTION_NORTHWEST 0
#define PROJECTILE_DIRECTION_NORTH 1
#define PROJECTILE_DIRECTION_NORTHEAST 2
#define PROJECTILE_DIRECTION_EAST 3
#define PROJECTILE_DIRECTION_SOUTHEAST 4
#define PROJECTILE_DIRECTION_SOUTH 5
#define PROJECTILE_DIRECTION_SOUTH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00, 0xFF00FF54,
0xFF00FFAA, 0xFF00FFFF, 0xFF00A9FF, 0xFF0055FF, 0xFF0000FF, 0xFF5500FF,
0xFFA900FF, 0xFFFE00FF, 0xFFFF00AA, 0xFFFF0055, 0xFFFF0000, 0xFF484848,
0xFFBF3F00, 0xFFBF7F00, 0xFFBFBF00, 0xFF7FBF00, 0xFF3FBF00, 0xFF00BF00,
0xFF00BF3F, 0xFF00BF7F, 0xFF00BFBF, 0xFF007FBF, 0xFF003FBF, 0xFF0000BF,
0xFF3F00BF, 0xFF7F00BF, 0xFFBF00BF, 0xFFBF007F, 0xFFBF003F, 0xFFBF0000,
0xFF242424, 0xFF7F2A00, 0xFF7F5500, 0xFF7F7F00, 0xFF557F00, 0xFF2A7F00,
0xFF007F00, 0xFF007F2A, 0xFF007F55, 0xFF007F7F, 0xFF00547F, 0xFF002A7F,
0xFF00007F, 0xFF2A007F, 0xFF54007F, 0xFF7F007F, 0xFF7F0055, 0xFF7F002A,
0xFF7F0000,
};*/
typedef QPair<quint8, quint8> DCoord;
static DCoord DirectionTable[] = {
DCoord( 0, 0 ),
DCoord( 1, 0 ),
DCoord( 2, 0 ),
DCoord( 2, 1 ),
DCoord( 2, 2 ),
DCoord( 1, 2 ),
DCoord( 0, 2 ),
DCoord( 0, 1 )
};
struct DrawParameters {
DrawParameters() {
outfitDirection = OUTFIT_DIRECTION_DEFAULT;
projectileDirection = PROJECTILE_DIRECTION_DEFAULT;
animation = 0;
addons = 0;
floor = 0;
blendOverlay = 0;
blendFrame = -1;
cropImage = false;
showPattern = false;
}
quint8 outfitDirection;
quint8 projectileDirection;
quint8 animation;
quint8 addons;
quint8 floor;
qint16 blendOverlay;
qint16 blendFrame;
bool cropImage;
bool showPattern;
bool operator==( const DrawParameters& other ) const {
return ( outfitDirection == other.outfitDirection &&
projectileDirection == other.projectileDirection &&
animation == other.animation &&
addons == other.addons &&
blendOverlay == other.blendOverlay &&
blendFrame == other.blendFrame &&
cropImage == other.cropImage &&
showPattern == other.showPattern );
}
inline bool operator!=( const DrawParameters& other ) const {
return !operator==( other );
}
};
class TibiaHandler : public QObject
{
Q_OBJECT
public:
TibiaHandler( void );
virtual ~TibiaHandler( void );
bool loadFormatFile( const QString& );
bool loadSpriteFile( const QString&, bool, bool newFile = false );
bool loadItemFile( const QString&, DatFormat *, bool, bool newFile = false );
bool loadPictureFile( const QString&, bool, bool newFile = false );
void unloadSpriteFile( void );
void unloadItemFile( void );
void unloadPictureFile( void );
SpriteFile *getSpriteFile( void ) const {
return m_spriteFile;
};
ItemFile *getItemFile( void ) const {
return m_itemFile;
};
PictureFile *getPictureFile( void ) const {
return m_pictureFile;
};
// Drawing functions
//QImage drawItemByLooktype( quint32 lookType, quint8 head, quint8 body, quint8 legs, quint8 feet, const DrawParameters& dParam = DrawParameters() );
//QImage drawItemTemplate( const TibiaItem *tibiaItem, quint8 head, quint8 body, quint8 legs, quint8 feet, const DrawParameters& dParam = DrawParameters() );
QImage drawItemById( quint32 itemId, const DrawParameters& dParam = DrawParameters() );
QImage drawItem( const TibiaItem *tibiaItem, const DrawParameters& dParam = DrawParameters() );
QImage drawItem( const ItemData& itemData, const DrawParameters& dParam = DrawParameters() );
//void translateDirection( quint8 direction, const TibiaItem *tibiaItem, quint8 &divx, quint8 &divy );
void mergeImage( QImage& itemImage, const ItemData& itemData, quint8 divx, quint8 divy, quint8 divz, quint8 animation, qint16 blendFrame, quint32 offset_x = 0, quint32 offset_y = 0 );
void renderImage( qint16 blendframe, QImage& itemImage, const ItemData& itemData, quint8 divx, quint8 divy, quint8 divz, quint8 animation, quint32 override_offset_x, quint32 override_offset_y );
quint32 getSpriteFrame( const ItemData& itemData, quint8 divx, quint8 divy, quint8 divz, quint8 frame, quint32 x, quint32 y, quint8 animation ) const;
SharedResource getSpriteResource( quint32 frame, const ItemData& itemData );
TibiaSprite getSprite( quint32 frame, const TibiaItem *tibiaItem );
TibiaSprite getSprite( quint32 frame, const ItemData& itemData );
qint32 getSpriteFrameByPosition( const ItemData& itemData, quint32 x, quint32 y, quint32 z, quint8 outfitDirection = 0, quint8 projectileDirection = 0, quint8 addons = 0, quint8 blendFrame = 0xFF, quint8 animation = 0 );
static ChaseWidget *getChaseWidget() {
static ChaseWidget *instance;
if( !instance )
instance = new ChaseWidget;
return instance;
}
static OutputWidget *getOutputWidget() {
static OutputWidget *instance;
if( !instance )
instance = new OutputWidget;
return instance;
}
private:
SpriteFile *m_spriteFile;
ItemFile *m_itemFile;
PictureFile *m_pictureFile;
mutable QMutex mutex;
signals:
void outputString( const QString& );
void parseError( QString, QFile::FileError );
void documentError( QString, QString, int );
void itemsLoaded( ItemFile * );
void spritesLoaded( SpriteFile * );
void picturesLoaded( PictureFile * );
void itemsUnloaded( void );
void spritesUnloaded( void );
void picturesUnloaded( void );
void invalidateItems( void );
public slots:
void onAddSprites( quint8, quint32 );
void onRemoveSprites( quint8, quint32 );
// Bounce signals
private slots:
void onDocumentError( QString, QString, int );
void onFileError( QString, QFile::FileError );
};
#endif // TIBIAHANDLER_H