Game Develop Core: ResourcesManager.h Source File

| Game Develop Core Core library for developing platforms and tools compatible with Game Develop.

- Main Page
- Modules
- Classes

- File List
- File Members

All Classes Files Functions Variables Typedefs Enumerations Macros Groups Pages
ResourcesManager.h
Go to the documentation of this file.
1
5 #ifndef GDCORE_RESOURCESMANAGER_H
6 #define GDCORE_RESOURCESMANAGER_H
7 #include <boost/shared_ptr.hpp>
8 #include <string>
9 #include <vector>
10 namespace gd { class Project; }
11 namespace gd { class ResourceFolder; }
12 class TiXmlElement;
13 class wxPaintDC;
14 class wxPanel;
15
16 namespace gd
17 {
18
24 class GD_CORE_API Resource
25 {
26 public:
27 Resource() {};
28 virtual ~Resource() {};
29 virtual Resource* Clone() const { return new Resource(*this);}
30
33 virtual void SetName(const std::string & name_) { name = name_;}
34
37 virtual const std::string & GetName() const {return name;}
38
41 virtual void SetKind(const std::string & newKind) { kind = newKind; }
42
45 virtual const std::string & GetKind() const {return kind;}
46
49 virtual void SetUserAdded(bool isUserAdded) {userAdded = isUserAdded;}
50
53 virtual bool IsUserAdded() const {return userAdded;}
54
60 virtual bool UseFile() { return false; }
61
68 virtual std::string & GetFile() {return badStr;};
69
76 virtual const std::string & GetFile() const {return badStr;};
77
81 std::string GetAbsoluteFile(const gd::Project & game) const;
82
88 virtual bool EditProperty(gd::Project & project, const std::string & property) { return true; };
89
95 virtual bool ChangeProperty(gd::Project & project, const std::string & property, const std::string & newValue) { return true; };
96
100 virtual void GetPropertyInformation(gd::Project & project, const std::string & property, std::string & userFriendlyName, std::string & description) const { return; };
101
107 virtual std::string GetProperty(gd::Project & project, const std::string & property) { return ""; };
108
112 virtual std::vector<std::string> GetAllProperties(gd::Project & project) const { std::vector<std::string> noProperties; return noProperties; };
113
114 #if !defined(GD_NO_WX_GUI)
115
118 virtual void RenderPreview(wxPaintDC & dc, wxPanel & previewPanel, gd::Project & game) {};
119 #endif
120
124 virtual void LoadFromXml(const TiXmlElement * elem) {};
125
129 virtual void SaveToXml(TiXmlElement * elem) const {};
130
131 private:
132 std::string kind;
133 std::string name;
134 bool userAdded;
135
136 static std::string badStr;
137 };
138
145 class GD_CORE_API ImageResource : public Resource
146 {
147 public:
148 ImageResource() : Resource(), smooth(true), alwaysLoaded(false) { SetKind("image"); };
149 virtual ~ImageResource() {};
150 virtual ImageResource* Clone() const { return new ImageResource(*this);}
151
155 virtual std::string & GetFile() {return file;};
156
160 virtual const std::string & GetFile() const {return file;};
161
162 #if defined(GD_IDE_ONLY)
163 virtual bool UseFile() { return true; }
164
165 #if !defined(GD_NO_WX_GUI)
166
169 virtual void RenderPreview(wxPaintDC & dc, wxPanel & previewPanel, gd::Project & game);
170 #endif
171
177 virtual bool EditProperty(gd::Project & project, const std::string & property);
178
184 virtual bool ChangeProperty(gd::Project & project, const std::string & property, const std::string & newValue);
185
191 virtual std::string GetProperty(gd::Project & project, const std::string & property);
192
196 virtual void GetPropertyInformation(gd::Project & project, const std::string & property, std::string & userFriendlyName, std::string & description) const;
197
201 virtual std::vector<std::string> GetAllProperties(gd::Project & project) const;
202
206 virtual void SaveToXml(TiXmlElement * elem) const;
207 #endif
208
212 virtual void LoadFromXml(const TiXmlElement * elem);
213
214 bool smooth;
215 bool alwaysLoaded;
216 private:
217 std::string file;
218 };
219
226 class GD_CORE_API ResourcesManager
227 {
228 public:
229 ResourcesManager();
230 virtual ~ResourcesManager();
231 ResourcesManager(const ResourcesManager&);
232 ResourcesManager& operator=(const ResourcesManager & rhs);
233
237 bool HasResource(const std::string & name) const;
238
242 Resource & GetResource(const std::string & name);
243
247 const Resource & GetResource(const std::string & name) const;
248
252 boost::shared_ptr<Resource> CreateResource(const std::string & kind);
253
257 std::vector<std::string> GetAllResourcesList();
258
259 #if defined(GD_IDE_ONLY)
260
263 boost::shared_ptr<gd::Resource> GetResourceSPtr(const std::string & name);
264
268 bool AddResource(const gd::Resource & resource);
269
273 bool AddResource(const std::string & name, const std::string & filename);
274
278 void RemoveResource(const std::string & name);
279
283 void RenameResource(const std::string & oldName, const std::string & newName);
284
288 bool MoveResourceUpInList(const std::string & name);
289
293 bool MoveResourceDownInList(const std::string & name);
294
298 bool HasFolder(const std::string & name) const;
299
303 const ResourceFolder & GetFolder(const std::string & name) const;
304
308 ResourceFolder & GetFolder(const std::string & name);
309
313 void RemoveFolder(const std::string & name);
314
318 void CreateFolder(const std::string & name);
319
323 bool MoveFolderUpInList(const std::string & name);
324
328 bool MoveFolderDownInList(const std::string & name);
329
333 std::vector<std::string> GetAllFolderList();
334
338 void SaveToXml(TiXmlElement * elem) const;
339 #endif
340
344 void LoadFromXml(const TiXmlElement * elem);
345
346 private:
347 void Init(const ResourcesManager & other);
348
349 std::vector< boost::shared_ptr<Resource> > resources;
350 #if defined(GD_IDE_ONLY)
351 std::vector< ResourceFolder > folders;
352 #endif
353
354 #if defined(GD_IDE_ONLY)
355 static ResourceFolder badFolder;
356 #endif
357 static Resource badResource;
358 };
359
360 #if defined(GD_IDE_ONLY)
361 class GD_CORE_API ResourceFolder
362 {
363 public:
364 ResourceFolder() {};
365 virtual ~ResourceFolder() {};
366 ResourceFolder(const ResourceFolder&);
367 ResourceFolder& operator=(const ResourceFolder & rhs);
368
371 virtual void SetName(const std::string & name_) { name = name_;}
372
375 virtual const std::string & GetName() const {return name;}
376
380 virtual void AddResource(const std::string & name, gd::ResourcesManager & parentManager);
381
385 virtual void RemoveResource(const std::string & name);
386
390 virtual bool HasResource(const std::string & name) const;
391
395 virtual Resource & GetResource(const std::string & name);
396
400 virtual const Resource & GetResource(const std::string & name) const;
401
405 virtual std::vector<std::string> GetAllResourcesList();
406
410 virtual bool MoveResourceUpInList(const std::string & name);
411
415 virtual bool MoveResourceDownInList(const std::string & name);
416
420 virtual void LoadFromXml(const TiXmlElement * elem, gd::ResourcesManager & parentManager);
421
425 virtual void SaveToXml(TiXmlElement * elem) const;
426
427 private:
428 std::string name;
429 std::vector< boost::shared_ptr<Resource> > resources;
430
431 void Init(const ResourceFolder & other);
432 static Resource badResource;
433 };
434 #endif
435
436 }
437
438 #endif // GDCORE_RESOURCESMANAGER_H