-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathTileMap.h
284 lines (274 loc) · 10.6 KB
/
TileMap.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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
#ifndef __TILEMAP__
#define __TILEMAP__
#include "TSettings.h"
#include "TEAction.h"
#include "TDialogs.h"
#include "TSelection.h"
#include "TCollision.h"
class TTexture{
public:
TextureParameters* mTexParam;
TTexture() { mTexParam = &mGlobalSettings.mGlobalTexParam; }
~TTexture();
SDL_Texture* TileTex = NULL;
std::vector<unsigned char> FileData;
std::vector<Uint32> PixelData;
SDL_Rect CurrentArea;
int initTexture();
int updateTexture(TPalette* tpal);
int loadFromFile(std::string filename, TPalette* tpal);
int loadFromBuffer(std::vector<unsigned char>& cTileBuf, TPalette* tpal);
int saveToFile(std::string filename);
int setPixel(int xpos, int ypos, unsigned char tcolor, TPalette* tpal);
unsigned char getPixel(int pindex);
unsigned char getPixel(int pindex, int poffset);
unsigned char getPixel(int pindex, int poffset, int tflip);
int getFlipIndex(int pindex, int tflip);
int setPixel(int pindex, unsigned char pcolor);
int setPixel(int pindex, unsigned char pcolor, std::vector<unsigned char>& tBuf);
static int setPixel(int pindex, unsigned char pcolor, std::vector<unsigned char>& tBuf, TextureParameters* cTexParam);
// SDL_Rect render(int xpos, int ypos, int tscale=1, bool updateRect=false ,bool drawGrid=false);
SDL_Rect renderEx(int xpos, int ypos, int tscale, SDL_RendererFlip flip);
void renderEd(int xpos, int ypos, TPalette* tpal);
bool bPixelSelected = false;
};
class TPixel{
public:
int PixelIndex;
SDL_Color PixelColor;
SDL_Rect CurrentArea;
int setPixelColor(unsigned char tcolor, TPalette* tpal);
SDL_Rect renderIm(int xpos, int ypos, int tscale = 1, bool updateRect = false, bool drawGrid = false);
SDL_Rect renderImDisabled(int xpos, int ypos, int tscale = 1, bool updateRect = false, bool drawGrid = false);
SDL_Rect renderEditor(int xpos, int ypos, int tscale = 1, bool updateRect = false, bool drawGrid = false);
// SDL_Rect render(int xpos, int ypos, int tscale=1, bool updateRect=false ,bool drawGrid=false);
SDL_Rect renderEd(int xpos, int ypos, TextureParameters* mTexParam, int tscale = 1, bool updateRect = false, bool drawGrid = false);
SDL_Rect renderEdSel(int xpos, int ypos, int tscale, bool drawGrid = false);
bool bPixelSelected = false;
bool bPixelSelectedEdit = false;
};
class TPalette : public Dialog{
public:
std::vector<SDL_Color> TPalette;
std::vector<SDL_Color> TPaletteEdit;
ImVec4 mEditColor;
ImVec4 mEditColorPick;
bool bIsPickerOpen = false;
void setEditColor();
int mR;
int mG;
int mB;
bool bUpdateEditColor = true;
bool bHasBackupColor = false;
int mBackupColor = 0;
int initPalette();
int initPaletteEdit();
int loadFromFile(std::string palPath);
int saveToFolder(std::string palPath);
int saveToFile(std::string palPath);
void close();
int importGimpPalette(std::string palPath);
int importPaletteEdit(std::string palPath);
int importPaletteEdit(std::string palPath, int exStart, int exRange, int inStart);
int exportGimpPaletteEdit(std::string palPath);
int exportPaletteEdit(std::string palPath);
int exportGimpPaletteEdit(std::string palPath, int expStart, int expRange);
int exportPaletteEdit(std::string palPath, int expStart, int expRange);
bool bImportingPalette = false;
bool bImportingOpen = false;
std::vector<TPixel*> TPixels;
std::vector<TPixel*> TPixelsEdit;
std::vector<SDL_Rect> PixelAreas;
int initTPixels();
int updateTPixels();
Uint32 mapPaletteColor(int tcolor);
ImU32 getImColor(SDL_Color cColor);
ImU32 getImColorVec4(ImVec4 cColor);
ImU32 getImColorInv(SDL_Color cColor);
ImVec4 getIm4Color(SDL_Color cColor);
ImVec4 getIm4ColorIm(ImU32 cColor);
SDL_Color getSDLColor(ImVec4 cCol);
static SDL_Color getSDLColorIm(ImU32 cCol);
SDL_Color getSDLColor4Bit(int cR, int cG, int cB);
int getClosest4Bit(int cCol);
void setSelectedColor(SDL_Color cColor);
int updatePalette();
int renderEditor(int xpos, int ypos);
int renderIm(int xpos, int ypos, TextureParameters* mTexParam);
// int render(int xpos, int ypos);
SDL_Rect renderTileEd(int xpos, int ypos, int tcolor, TextureParameters* mTexParam);
SDL_Rect renderSpriteEd(int xpos, int ypos, int tcolor, TextureParameters* mTexParam);
SDL_Rect renderTileEd(int xpos, int ypos, int tcolor, int cScale, TextureParameters* mTexParam);
SDL_Rect renderSelEd(int xpos, int ypos, int tcolor, int cScale);
std::vector<std::string> mMapColorVals = { "%d/0", "%d/17", "%d/34", "%d/51", "%d/68", "%d/85", "%d/102", "%d/119", "%d/136", "%d/153", "%d/170", "%d/187", "%d/204", "%d/221", "%d/238", "%d/255" };
std::map<int, int> mMapColorIn = { {0, 0}, {1, 17}, {2, 34}, {3, 51}, {4, 68}, {5, 85}, {6, 102}, {7, 119}, {8, 136}, {9, 153}, {10, 170}, {11, 187}, {12, 204}, {13, 221}, {14, 238}, {15, 255} };
std::map<int, int> mMapColorOut = { {0, 0}, {17, 1}, {34, 2}, {51, 3}, {68, 4}, {85, 5}, {102, 6}, {119, 7}, {136, 8}, {153, 9}, {170, 10}, {187, 11}, {204, 12}, {221, 13}, {238, 14}, {255, 15} };
};
class Tile : public TTexture{
public:
~Tile();
void freeTexture();
int initTile();
int initTexture();
std::vector<SDL_Texture*> TPOffset;
std::vector<SDL_Rect> PixelAreas;
// SDL_Rect render(int xpos, int ypos, int tscale=1, bool updateRect=false ,bool drawGrid=false);
SDL_Rect renderIm(int xpos, int ypos, int mIndex, int& mDragAndDropped, int tscale = 1, bool updateRect = false, bool drawGrid = false);
SDL_Rect renderImCol(int xpos, int ypos, int mIndex, int mColVal, int tscale, bool bColEditSelected);
SDL_Rect render(int xpos, int ypos, int tscale, TileProperties tProps);
void renderEd(int xpos, int ypos, TPalette* tpal);
void renderEdSel(int xpos, int ypos, TPalette* tpal, int cScale);
static int renderSelection(SDL_Rect& sRect, SDL_Color sColor);
int updateTexture(TPalette* tpal);
int recreateTexture(TPalette* tpal);
int loadFromFile(std::string filename, TPalette* tpal);
int loadFromBuffer(std::vector<unsigned char>& cTileBuf, TPalette* tpal);
int replaceWithBuffer(std::vector<unsigned char>& cTileBuf, TPalette* tpal);
int createNew(TPalette* tpal);
int rotater();
int rotatel();
int rotate(double cAngle);
int scale(double cScale);
int upscale(Tile* cCopyTile);
int applyFilter();
int applyOffset(int poffset, bool bReplaceZero = false);
bool bIsSelected = false;
const static int MaxScale = 24;
const static int MinScale = 4;
TEActionUndoStack mActionStack;
TSelection mSelection;
};
class TileSet{
public:
TileSet(){mClipboardTiles.mLocalTexParam.TexPixelSize+=6;};
void shutdown();
void close();
std::string DataPath;
std::vector<Tile*> TTiles;
std::vector<SDL_Rect> TileAreas;
std::vector<SDL_Rect> EditPixelAreas;
std::vector<SDL_Rect> TileSetAreas;
void resizeEdit();
void resizeScale();
void updateEditAreas(std::vector<SDL_Rect>& cTile, int xpos, int ypos);
int getXY(int xpos, int ypos, int cxpos, int cypos);
std::vector<int> getPadding();
TOverlay mOverlay;
void initoverlay();
void setoverlay();
int mOverlayScaleX;
int mOverlayScaleY;
bool bRenderOverlay = false;
bool bImRenderOverlay = false;
bool bCheckMaxSize = true;
int mCurTileScale = 15;
int mMaxTileScale = 4;
int mCurColumns = 1;
int mColSpace = 10;
int mMaxScrollY = 0;
int mSelEdWidth = 4;
int mCurEdScale = 10;
int mPixelScale = 1;
int mMaxColumns = 4;
int mMinTileScale = 7;
int mChildTop = 0;
const static int MaxScale = 24;
const static int MinScale = 4;
const static int MaxGrid = 16;
const static int MinGrid = 2;
const static int MaxCol = 5;
const static int MinCol = 2;
const static int MaxTile = 15;
const static int MinTile = 4;
const static int MaxMin = 1;
const static int MaxMax = 10;
int mSelectionAreaX;
int mSelectionAreaY;
int reCalculateScale();
SDL_Rect mTileSetBackGround;
int loadFromFile(std::string tpath, std::string tfile, TPalette* tpal);
int saveToFolder(std::string tpath);
Tile* createNew(TPalette* tpal);
Tile* createNewCopy(Tile* cCopyTile, TPalette* tpal);
Tile* createNewFromBuffer(std::vector<unsigned char>& newBuf, TPalette* tpal);
Tile* createNewFromFile(std::string newPAth, TPalette* tpal);
int importFile(std::string tpath, std::string tfile, TPalette* tpal);
int importPNG(SDL_Surface* cTiles, TPalette* tpal);
int importTileSet(std::string cTilePath, std::vector<Tile*>& cNewTiles);
int applyOffset(int poffset, bool bReplaceZero = false);
void dropLastTile();
int deleteTile(int cDropTile);
int removeTile(int cDropTile);
void appendTile(Tile* addTile);
// int render(int ypos, int mScroll);
int renderEd(int xpos, int ypos);
int renderIm(int ypos);//, int mScroll);
int renderImMax(int ypos);
bool bUpdateWinPos = false;
bool bUpdateWinPosMax = false;
bool bUpdateEditSelection = false;
bool bUpdateEditSelectionScale = false;
bool bShowClipboardTiles = false;
bool bShowClipboardTileSet = false;
std::map<int, int> mTileSizeIn = { {0, 8}, {1, 16} };
std::map<int, int> mTileSizeOut = { {8, 0}, {16, 1} };
TSelection mSelection;
TEActionUndoStack mActionStack;
TClipboard mClipboardTiles;
TClipboard mClipboardTileSet;
};
class TileProperties{
public:
int mPaletteOffset = 0;
bool bFlipX = false;
bool bFlipY = false;
};
class TileMap{
public:
std::string DataPath;
std::string DataFile;
bool bIsSavedToFile = false;
int TileMapHeight = 32;
int TileMapWidth = 32;
int mMapSelectedTile = 0;
int TileMapScale = 3;
int mTileMapScrollX = 0;
int mTileMapScrollY = 0;
TOverlay mOverlay;
void init();
void initoverlay();
bool bRenderOverlay = false;
bool bRenderOverlayColMap = false;
std::string getMapSize();
std::string getSize(){return getMapSize();};
std::vector<unsigned char> FileData;
int getTile(int cTile);
int setTile(int cTile, int cTileVal);
int getFlip(int cTile);
int setFlip(int cTile, int cTileFlip);
int getOffset(int cTile);
int setOffset(int cTile, int cOffset);
void swapTileValues(int tVal1, int tVal2);
TileProperties getTileProp(int cTile);
std::vector<SDL_Rect> TileAreas;
int removeTile(int cDropTile);
int moveTile(int cSource, int cTarget);
int loadFromFile(std::string path, std::string filename, bool bLoadColMap = false);
int loadFromFileOffset(std::string path, std::string filename, int cTileOffset);
int loadFromFileOffset(std::string path, std::string filename, int cTileOffset, int cPaletteOffset);
int saveToFolder(std::string tpath, std::string tfile);
int createNew();
int createNew(int nWidth, int nHeight, int nSValue);
int createNew(int nWidth, int nHeight, int nSValue, int cPaletteOffset);
int createCollisionMap(int cFormat);
int removeCollisionMap();
int render(int xpos, int ypos, TileSet* mTiles);
std::map<int, int> mTilemapSizesIn = { {0, 32}, {1, 64}, {2, 128}, {3, 256} };
std::map<int, int> mTilemapSizesOut = { {32, 0}, {64, 1}, {128, 2}, {256, 3} };
SDL_Rect mBorder;
TSelection mSelection;
bool bHasCollisionMap = false;
TCollisionMap mColMap;
bool bIsTileZeroTransparent = false;
};
#endif