MaterialDocManager.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /*
  2. ===========================================================================
  3. Doom 3 GPL Source Code
  4. Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
  6. Doom 3 Source Code is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. Doom 3 Source Code is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
  17. If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
  18. ===========================================================================
  19. */
  20. #pragma once
  21. #include "MaterialEditor.h"
  22. #include "MaterialModifier.h"
  23. #include "MaterialDoc.h"
  24. class MaterialView;
  25. #define MAX_UNDOREDO 32
  26. /**
  27. * Responsible for managing the materials that are being viewed and/or edited.
  28. */
  29. class MaterialDocManager {
  30. public:
  31. MaterialDocManager(void);
  32. ~MaterialDocManager(void);
  33. //Reg/UnReg Material Views
  34. void RegisterMaterialView(MaterialView* view);
  35. void UnRegisterMaterialView(MaterialView* view);
  36. void UnRegisterAllMaterialViews();
  37. //Material Selection
  38. void SetSelectedMaterial(idMaterial* material);
  39. MaterialDoc* GetCurrentMaterialDoc() { return currentMaterial; };
  40. //State Checking Methods
  41. bool DoesFileNeedApply(const char* filename);
  42. bool DoesAnyNeedApply();
  43. bool IsFileModified(const char* filename);
  44. bool IsAnyModified();
  45. //Adding or deleting a material
  46. void AddMaterial(const char* name, const char* filename, const char* sourceText = NULL, bool addUndo = true);
  47. void RedoAddMaterial(const char* name, bool clearData = true);
  48. void DeleteMaterial(MaterialDoc* material, bool addUndo = true);
  49. //Applying
  50. void ApplyMaterial(MaterialDoc* materialDoc);
  51. void ApplyFile(const char* filename);
  52. void ApplyAll();
  53. //Saving
  54. void SaveMaterial(MaterialDoc* material);
  55. void SaveFile(const char* filename);
  56. void SaveAllMaterials();
  57. //File Reloading
  58. void ReloadFile(const char *filename);
  59. //Used to get and/or create a MaterialDoc object for editing
  60. MaterialDoc* CreateMaterialDoc(const char* materialName);
  61. MaterialDoc* CreateMaterialDoc(idMaterial* material);
  62. MaterialDoc* GetInProgressDoc(idMaterial* material);
  63. //Copy Paste
  64. void CopyMaterial(MaterialDoc* materialDoc = NULL, bool cut = false);
  65. void ClearCopy();
  66. bool IsCopyMaterial();
  67. idStr GetCopyMaterialName();
  68. void PasteMaterial(const char* name, const char* filename);
  69. void CopyStage(MaterialDoc* materialDoc, int stageNum);
  70. void ClearCopyStage();
  71. bool IsCopyStage();
  72. void PasteStage(MaterialDoc* materialDoc);
  73. void GetCopyStageInfo(int& type, idStr& name);
  74. //Undo/Redo
  75. void Undo();
  76. bool IsUndoAvailable();
  77. void ClearUndo();
  78. void Redo();
  79. bool IsRedoAvailable();
  80. void ClearRedo();
  81. void AddMaterialUndoModifier(MaterialModifier* mod, bool clearRedo = true);
  82. void AddMaterialRedoModifier(MaterialModifier* mod);
  83. //Searching
  84. bool FindMaterial(const char* name, MaterialSearchData_t* searchData, bool checkName);
  85. //Misc
  86. idStr GetUniqueMaterialName(idStr name);
  87. protected:
  88. /**
  89. * View notification types
  90. */
  91. enum {
  92. SELECTION_CHANGE,
  93. MATERIAL_CHANGE,
  94. MATERIAL_APPLY,
  95. MATERIAL_SAVE,
  96. MATERIAL_SAVE_FILE,
  97. MATERIAL_ADD,
  98. MATERIAL_DELETE,
  99. MATERIAL_ADD_STAGE,
  100. MATERIAL_DELETE_STAGE,
  101. MATERIAL_MOVE_STAGE,
  102. MATERIAL_ATTRIBUTE_CHANGE,
  103. MATERIAL_NAME_CHANGE,
  104. FILE_RELOAD
  105. };
  106. void NotifyViews(MaterialDoc* materialDoc, int notifyType, ... );
  107. //Doc Notification members
  108. friend MaterialDoc;
  109. void MaterialChanged(MaterialDoc* materialDoc);
  110. void MaterialApplied(MaterialDoc* materialDoc);
  111. void MaterialSaved(MaterialDoc* materialDoc);
  112. void MaterialNameChanged(const char* oldName, MaterialDoc* materialDoc);
  113. void StageAdded(MaterialDoc* materialDoc, int stageNum);
  114. void StageDeleted(MaterialDoc* materialDoc, int stageNum);
  115. void StageMoved(MaterialDoc* materialDoc, int from, int to);
  116. void AttributeChanged(MaterialDoc* materialDoc, int stage, const char* attribName);
  117. protected:
  118. idList<MaterialView*> materialViews;
  119. MaterialDoc* currentMaterial;
  120. idHashTable<MaterialDoc*> inProgressMaterials;
  121. idList<MaterialModifier*> undoModifiers;
  122. idList<MaterialModifier*> redoModifiers;
  123. //Copy/Paste
  124. bool cutMaterial;
  125. idStr copyMaterial;
  126. //Copy/Paste Stage
  127. idStr copyStageMaterial;
  128. MEStage_t copyStage;
  129. };