gcsx_worldedit.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /* GCSx
  2. ** WORLDEDIT.H
  3. **
  4. ** World storage- editor-only functionality
  5. */
  6. /*****************************************************************************
  7. ** Copyright (C) 2003-2006 Janson
  8. **
  9. ** This program is free software; you can redistribute it and/or modify
  10. ** it under the terms of the GNU General Public License as published by
  11. ** the Free Software Foundation; either version 2 of the License, or
  12. ** (at your option) any later version.
  13. **
  14. ** This program is distributed in the hope that it will be useful,
  15. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. ** GNU General Public License for more details.
  18. **
  19. ** You should have received a copy of the GNU General Public License
  20. ** along with this program; if not, write to the Free Software
  21. ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
  22. *****************************************************************************/
  23. #ifndef __GCSx_WORLDEDIT_H_
  24. #define __GCSx_WORLDEDIT_H_
  25. class WorldEdit : public World, virtual public SaveLoad {
  26. public:
  27. typedef std::map<int, class LayerEdit*> LayerIndex;
  28. typedef std::map<int, class SpawnEdit*> SpawnIndex;
  29. typedef std::map<int, class FolderEdit*> FolderIndex;
  30. private:
  31. // Our file, in writable format; should be same as file member
  32. class WorldFile* saveFile;
  33. int headerModified;
  34. int contentModified;
  35. // Resources, indexed by id, that only need to be searched for in editor
  36. LayerIndex layersById;
  37. SpawnIndex spawnsById;
  38. FolderIndex foldersById;
  39. // Points to our node on the world browser, we must keep it updated
  40. // as we add and remove scenes, etc.
  41. class TreeView* browserNode;
  42. // List of all currently open worlds
  43. static std::set<class WorldEdit*>* allWorlds;
  44. // Treeview handling constants
  45. enum {
  46. TREEVIEW_WORLD = 1,
  47. TREEVIEW_SCENE,
  48. TREEVIEW_TILESET,
  49. TREEVIEW_FONT,
  50. TREEVIEW_NOTES,
  51. TREEVIEW_ANIMGROUP,
  52. TREEVIEW_SCRIPT,
  53. TREEVIEW_FOLDER,
  54. };
  55. public:
  56. WorldEdit() throw_File; // Default constructor creates a blank new "Untitled" world
  57. WorldEdit(const char* wFilename) throw_File; // Opens an existing world for editing
  58. virtual ~WorldEdit(); // Closes/deletes all resources, removes all from browser
  59. // Change properties; handles undo
  60. void setTitle(const std::string& newTitle, Window* srcWin = NULL, Window* exWin = NULL) throw_Undo;
  61. // (doesn't check ID for accuracy)
  62. void setStartScene(int sId, Window* srcWin = NULL, Window* exWin = NULL) throw_Undo;
  63. // Returns true if OK pressed
  64. int propertiesDialog(Window* srcWin = NULL, Window* exWin = NULL);
  65. // Add and remove from byId indices
  66. // Safe to change name, as not indexed by name
  67. // Only call these when adding/removing layers/spawns
  68. // Indexing scenes automatically gets layers/spawns too now
  69. void indexLayer(LayerEdit* addLayer);
  70. void deindexLayer(LayerEdit* remLayer);
  71. void indexSpawn(SpawnEdit* addSpwan);
  72. void deindexSpawn(SpawnEdit* remSpawn);
  73. void indexScene(Scene* addScene);
  74. void deindexScene(Scene* remScene);
  75. void indexFolder(FolderEdit* addFolder);
  76. void deindexFolder(FolderEdit* remFolder);
  77. // Find items based on name or iterate sequence
  78. // Designed for runtime efficiency
  79. class LayerEdit* findLayer(int fId) const;
  80. LayerIndex::const_iterator beginLayer() const { return layersById.begin(); }
  81. LayerIndex::const_iterator endLayer() const { return layersById.end(); }
  82. class SpawnEdit* findSpawn(int fId) const;
  83. SpawnIndex::const_iterator beginSpawn() const { return spawnsById.begin(); }
  84. SpawnIndex::const_iterator endSpawn() const { return spawnsById.end(); }
  85. class FolderEdit* findFolder(int fId) const;
  86. FolderIndex::const_iterator beginFolder() const { return foldersById.begin(); }
  87. FolderIndex::const_iterator endFolder() const { return foldersById.end(); }
  88. // Find items based on block type- currently used by folders (and undo, for folders)
  89. SaveLoad* findItem(int blockType, int id);
  90. // Create new IDs
  91. int unusedSceneId() const;
  92. int unusedTileSetId() const;
  93. int unusedAnimGroupId() const;
  94. int unusedScriptId() const;
  95. int unusedLayerId() const;
  96. int unusedSpawnId() const;
  97. int unusedFolderId() const;
  98. // Our undo handler
  99. UndoBuffer undo;
  100. // File operations
  101. // Returns true if was saved
  102. int save(); // Calls saveAs if no filename ever assigned
  103. int saveAs();
  104. // Close; asks to save if modified; then deletes self if appropriate
  105. // Returns true if was closed and deleted; justSave causes us to
  106. // check modified status and save as if closing, but don't actually
  107. // close yet; returns true if ok, false if cancelled; dontAsk tells
  108. // us not to ask about being modified
  109. int close(int justSave = 0, int dontAsk = 0);
  110. // Delete a resource- removes from our list AND actually deletes it
  111. // Returns 1 if deleted; 0 if couldn't be deleted (such as user cancelled)
  112. int deleteTileset(class TileSetEdit* toDelete, Window* srcWin = NULL);
  113. int deleteScene(class SceneEdit* toDelete, Window* srcWin = NULL);
  114. int deleteAnimGroup(class AnimGroupEdit* toDelete, Window* srcWin = NULL);
  115. int deleteScript(class ScriptEdit* toDelete, Window* srcWin = NULL);
  116. int deleteFolder(class FolderEdit* toDelete, Window* srcWin = NULL);
  117. // Readds a resource that was deleted and disassociated earlier
  118. void readdTileset(class TileSetEdit* toAdd);
  119. void readdScene(class SceneEdit* toAdd);
  120. void readdAnimGroup(class AnimGroupEdit* toAdd);
  121. void readdScript(class ScriptEdit* toAdd);
  122. void readdFolder(class FolderEdit* toAdd);
  123. // Adds an outside-created resource (as a single undo create event, also)
  124. void importTileSet(class TileSetEdit* toAdd, int openWindow = 1, Window* srcWin = NULL);
  125. void importScene(class SceneEdit* toAdd, int openWindow = 1, Window* srcWin = NULL);
  126. // Tells world to add itself to the world browser
  127. void addToBrowser(class TreeView* worldBrowser);
  128. // Other editor windows cascade to these
  129. Window::CommandSupport supportsCommand(int code) const;
  130. int commandEvent(int code);
  131. // Treeview event handling
  132. int treeviewEvent(int code, int command, int check);
  133. static int treeviewEventWrap(void* ptr, int code, int command, int check);
  134. // Asks to save all modified worlds; returns true if everything ok, false
  135. // if any hit cancel; intended for use when quitting
  136. static int modifiedAll();
  137. // Closes or saves all currently open worlds
  138. static void closeAll(int dontAsk = 0);
  139. static void saveAll();
  140. // File access
  141. int isHeaderModified() const;
  142. int isContentModified() const;
  143. // (overrides World, we actually load notes)
  144. void loadContent(class FileRead* file);
  145. Uint32 saveHeader(class FileWrite* file) throw_File;
  146. void saveContent(class FileWrite* file);
  147. void saveSuccess();
  148. void cachedContent(class FileRead* file, int oldData);
  149. void setHeaderModified();
  150. void setGlobalLinksModified();
  151. // Verifies if a given world is still open
  152. static int verifyWorld(class WorldEdit* verify);
  153. // Returns number of worlds open
  154. static int countWorlds();
  155. // Returns currently open worlds, in order (0 is first position; returns NULL if done)
  156. static class WorldEdit* listWorlds(int pos);
  157. };
  158. #endif