gcsx_scriptedit.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /* GCSx
  2. ** SCRIPTEDIT.H
  3. **
  4. ** Script support
  5. ** Expands basic Script to include editor functionality
  6. */
  7. /*****************************************************************************
  8. ** Copyright (C) 2003-2006 Janson
  9. **
  10. ** This program is free software; you can redistribute it and/or modify
  11. ** it under the terms of the GNU General Public License as published by
  12. ** the Free Software Foundation; either version 2 of the License, or
  13. ** (at your option) any later version.
  14. **
  15. ** This program is distributed in the hope that it will be useful,
  16. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. ** GNU General Public License for more details.
  19. **
  20. ** You should have received a copy of the GNU General Public License
  21. ** along with this program; if not, write to the Free Software
  22. ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
  23. *****************************************************************************/
  24. #ifndef __GCSx_SCRIPTEDIT_H_
  25. #define __GCSx_SCRIPTEDIT_H_
  26. class ScriptEdit : public Script, virtual public SaveLoad {
  27. protected:
  28. // Has the script been modified from initial state (from empty if new)
  29. int headerModified;
  30. int contentModified;
  31. int disassociated;
  32. int inMiddleOfUndoBlock;
  33. int dependencyModified; // Triggers recompile
  34. int sourceModified; // Triggers reparse/recompile
  35. // Our node on the world browser
  36. TreeView* browserNode;
  37. // Set us as modified
  38. // Setting content modified also loads from cache if needed
  39. // Call these before actually making any modifications
  40. // (if header changes affect content, call both modifieds first)
  41. void setHeaderModified();
  42. void setContentModified();
  43. // must be uncached
  44. void clean(int full = 1);
  45. public:
  46. // Id of 0 = we're going to load (or create/import) immediately
  47. // Any other id = we start out modified
  48. // World and ID may be NULL/0 if in process of creating
  49. ScriptEdit(class WorldEdit* myWorld, Script::ScriptType type = Script::SCRIPT_CODE, int myId = 0); // Starts with default settings
  50. virtual ~ScriptEdit();
  51. // Intended only for use after creating/importing- not in general usage
  52. void setInfo(class WorldEdit* myWorld, int newId);
  53. // Tells us to disassociate ourselves from anything, we've been "deleted"
  54. // or that we've been "readded" again
  55. // FileException means couldn't decache, and nothing was done
  56. void disassociate() throw_File;
  57. // Node is world browser node that we readd to
  58. void reassociate(TreeView* node);
  59. class WorldEdit* getWorldEdit() { return dynamic_cast<WorldEdit*>(world); }
  60. const class WorldEdit* getWorldEdit() const { return dynamic_cast<WorldEdit*>(world); }
  61. // Change properties; handles undo
  62. void setName(const std::string& newName, Window* srcWin = NULL, Window* exWin = NULL) throw_Undo;
  63. void setDefault(class AnimGroup* newAnimgroup, class TileSet* newTileset, int newId, Window* srcWin = NULL, Window* exWin = NULL) throw_Undo;
  64. std::list<std::string>& getSource(); // Must LOCK first
  65. // Prepares for needed or forced compilation (lock optional)
  66. void cleanForCompile(int force = 0);
  67. // Must LOCK first
  68. // These only compile as needed- calls cleanForCompile for you
  69. // Errors may result
  70. void parseFuncs();
  71. void compile(); // Includes parse if not done
  72. void link();
  73. void decompile();
  74. // Returns true if OK pressed
  75. // Locks and unlocks script
  76. int propertiesDialog(Window* srcWin = NULL, Window* exWin = NULL);
  77. // Code window (editor)
  78. void openEditWindow();
  79. // Tells script it's code has been modified (by an edit window, etc.)
  80. enum ContentChangeType {
  81. SCRIPT_REMOVE_LINES = 1,
  82. SCRIPT_INSERT_LINES, // It's assumed these are modified as well
  83. SCRIPT_MODIFY_LINE, // One or more lines
  84. SCRIPT_MODIFY_DONE, // Called after each batch is complete
  85. };
  86. // Call BEFORE making changes, so it can properly save undo
  87. void codeModifiedPre(ContentChangeType type, int firstRow, int numRows, EditBox* editbox = NULL, Window* srcWin = NULL);
  88. // Call AFTER making changes, so it can properly send notification
  89. void codeModifiedPost(ContentChangeType type, int firstRow, int numRows, EditBox* editbox = NULL, Window* exWin = NULL);
  90. // Tells script to add itself to the world browser node
  91. void addToBrowser(TreeView* node, int makeCurrent = 1);
  92. void dropBrowser(); // Called if script gets dropped from browser
  93. // Treeview event handling
  94. int treeviewEvent(int code, int command, int check);
  95. static int treeviewEventWrap(void* ptr, int code, int command, int check);
  96. // File access
  97. int isHeaderModified() const;
  98. int isContentModified() const;
  99. Uint32 saveHeader(FileWrite* file) throw_File;
  100. void saveContent(FileWrite* file) throw_File;
  101. void saveSuccess();
  102. void cachedContent(FileRead* file, int oldData);
  103. };
  104. #endif