1 ///////////////////////////////////////////////////////////////////////////////
2 //            Copyright (C) 2004-2010 by The Allacrost Project
3 //                         All Rights Reserved
4 //
5 // This code is licensed under the GNU GPL version 2. It is free software
6 // and you may modify it and/or redistribute it under the terms of this license.
7 // See http://www.gnu.org/copyleft/gpl.html for details.
8 ///////////////////////////////////////////////////////////////////////////////
9 
10 /** ****************************************************************************
11 *** \file    tileset.h
12 *** \author  Philip Vorsilak, gorzuate@allacrost.org
13 *** \brief   Header file for editor's tileset, used for maintaining a visible
14 ***          "list" of tiles to select from for painting on a map.
15 *** ***************************************************************************/
16 
17 #ifndef __TILESET_HEADER__
18 #define __TILESET_HEADER__
19 
20 //#include <QHeaderView>
21 #include <QImageReader>
22 #include <QRect>
23 #include <Q3Table>
24 //#include <QTableWidgetItem>
25 #include <QVariant>
26 
27 #include "defs.h"
28 #include "script.h"
29 #include "utils.h"
30 #include "video.h"
31 
32 //! All calls to the editor are wrapped in this namespace.
33 namespace hoa_editor
34 {
35 
36 /*	struct AnimatedTileData {
37 		int tile_id;
38 		int time;
39 	};
40 */
41 //! \briefStandard tile dimensions in number of pixels
42 //@{
43 const unsigned int TILE_WIDTH  = 32;
44 const unsigned int TILE_HEIGHT = 32;
45 //@}
46 
47 /** ****************************************************************************
48 *** \brief Represents a tileset and retains the tileset's image and properties
49 ***
50 *** This is a container of tileset data. The tileset's properties are contained
51 *** within a Lua file specific to the tileset. The Lua file is located in a
52 *** separate path from the tileset's image file. Currently this class assumes
53 *** and only supports the Allacrost standard tileset of 512x512 pixels with
54 *** 32x32 pixel tiles (256 total tiles in one tileset file).
55 ***
56 *** \todo Re-examine the need for these odd container choices (maps of vectors)
57 *** \todo Add support for animated tiles (display, editing)
58 *** \todo Add support for creating new tilesets (new Lua data files)
59 *** \todo Add support for saving tileset files
60 *** ***************************************************************************/
61 class Tileset
62 {
63 public:
64 	Tileset();
65 
66 	~Tileset();
67 
68 	/** \brief Returns the filename of a tileset image given the tileset's name
69 	*** \param tileset_name The name of the tileset (e.g. "mountain_village")
70 	**/
71 	static QString CreateImageFilename(const QString& tileset_name);
72 
73 	/** \brief Returns the filename of a tileset definition file given the tileset's name
74 	*** \param tileset_name The name of the tileset (e.g. "mountain_village")
75 	**/
76 	static QString CreateDataFilename(const QString& tileset_name);
77 
78 	/** \brief Returns the tileset name that corresponds to either an image or data filename
79 	*** \param filename The name of the file, which may or may not include the path
80 	**/
81 	static QString CreateTilesetName(const QString& filename);
82 
IsInitialized()83 	bool IsInitialized() const
84 		{ return _initialized; }
85 
86 	/** \brief Creates a new tileset object using only a tileset image
87 	*** \param img_filename The path + name of the image file to use for the tileset
88 	*** \param one_image If true, the tiles vector will contain a single image for the entire tileset
89 	*** \return True if the tileset image was loaded successfully
90 	*** \note A tileset image is required to use this function, but nothing else
91 	**/
92 	virtual bool New(const QString& img_filename, bool one_image = false);
93 
94 	/** \brief Loads the tileset definition file and stores its data in the class containers
95 	*** \param set_name The unique name that identifies the tileset (not a filename)
96 	*** \param one_image If true, the tiles vector will contain a single image for the entire tileset
97 	*** \return True if the tileset was loaded successfully
98 	*** \note This function will clear the previously loaded contents when it is called
99 	**/
100 	virtual bool Load(const QString& set_name, bool one_image = false);
101 
102 	/** \brief Saves the tileset data to its tileset definition file
103 	*** \return True if the save operation was successful
104 	***
105 	**/
106 	bool Save();
107 
108 	//! \brief The name of the tileset this table is representing.
109 	QString tileset_name;
110 
111 	//! \brief Contains the StillImage tiles of the tileset, used in grid.cpp.
112 	std::vector<hoa_video::StillImage> tiles;
113 
114 	//! \brief Contains walkability information for each tile.
115 	std::map<int, std::vector<int32> > walkability;
116 
117 	//! \brief Contains autotiling information for any autotileable tile.
118 	std::map<int, std::string> autotileability;
119 
120 protected:
121 	//! \brief True if the class is holding valid, loaded tileset data
122 	bool _initialized;
123 
124 	//std::vector<std::vector<AnimatedTileData> > _animated_tiles;
125 }; // class Tileset
126 
127 /** ****************************************************************************
128 *** \brief Used to visually represent a tileset via a QT table
129 *** ***************************************************************************/
130 class TilesetTable : public Tileset {
131 public:
132 	TilesetTable();
133 
134 	~TilesetTable();
135 
136 	//! \note Inherited methods from Tileset class that need to be overridden
137 	//@{
138 // 	bool New(const QString& img_filename);
139 	bool Load(const QString& set_name);
140 	//@}
141 
142 	//! Reference to the table implementation of this tileset
143 	Q3Table* table;
144 }; // class TilesetTable : public Tileset
145 
146 } // namespace hoa_editor
147 
148 #endif // __TILESET_HEADER__
149