decalEditorActions.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. function DecalEditorGui::createAction(%this, %class, %desc)
  23. {
  24. pushInstantGroup();
  25. %action = new UndoScriptAction()
  26. {
  27. class = %class;
  28. superClass = BaseDecalEdAction;
  29. actionName = %desc;
  30. tree = DecalEditorTreeView;
  31. };
  32. popInstantGroup();
  33. return %action;
  34. }
  35. function DecalEditorGui::doAction(%this, %action)
  36. {
  37. if (%action.doit())
  38. %action.addToManager(Editor.getUndoManager());
  39. }
  40. function BaseDecalEdAction::redo(%this)
  41. {
  42. // Default redo action is the same as the doit action
  43. %this.doit();
  44. }
  45. function BaseDecalEdAction::undo(%this)
  46. {
  47. }
  48. //------------------------------------------------------------------------------
  49. // Edit node
  50. function DecalEditorGui::doEditNodeDetails(%this, %instanceId, %transformData, %gizmo)
  51. {
  52. %action = %this.createAction(ActionEditNodeDetails, "Edit Decal Transform");
  53. %action.instanceId = %instanceId;
  54. %action.newTransformData = %transformData;
  55. if( %gizmo )
  56. %action.oldTransformData = %this.gizmoDetails;
  57. else
  58. %action.oldTransformData = %this.getDecalTransform(%instanceId);
  59. %this.doAction(%action);
  60. }
  61. function ActionEditNodeDetails::doit(%this)
  62. {
  63. %count = getWordCount(%this.newTransformData);
  64. if(%this.instanceId !$= "" && %count == 7)
  65. {
  66. DecalEditorGui.editDecalDetails( %this.instanceId, %this.newTransformData );
  67. DecalEditorGui.syncNodeDetails();
  68. DecalEditorGui.selectDecal( %this.instanceId );
  69. return true;
  70. }
  71. return false;
  72. }
  73. function ActionEditNodeDetails::undo(%this)
  74. {
  75. %count = getWordCount(%this.oldTransformData);
  76. if(%this.instanceId !$= "" && %count == 7)
  77. {
  78. DecalEditorGui.editDecalDetails( %this.instanceId, %this.oldTransformData );
  79. DecalEditorGui.syncNodeDetails();
  80. DecalEditorGui.selectDecal( %this.instanceId );
  81. }
  82. }
  83. //------------------------------------------------------------------------------
  84. // Delete Decal Datablocks
  85. // This functionality solely depends on the undo/redo datablock callbacks in
  86. // source.
  87. function DecalEditorGui::redoDeleteDecalDatablock( %this, %datablock )
  88. {
  89. // Remove the object from file and place a filter
  90. if( %datablock.getFilename() !$= "" )
  91. {
  92. DecalPMan.removeDirty( %datablock );
  93. DecalPMan.removeObjectFromFile( %datablock );
  94. }
  95. DecalDataList.addFilteredItem( %datablock );
  96. }
  97. function DecalEditorGui::undoDeleteDecalDatablock( %this, %datablock )
  98. {
  99. // Replace the object in file and remove the filter
  100. %filename = %datablock.getFilename();
  101. if( %datablock.getFilename() !$= "" )
  102. {
  103. DecalPMan.setDirty( %datablock, %filename );
  104. DecalPMan.saveDirty();
  105. }
  106. DecalDataList.removeFilteredItem( %datablock );
  107. }