undoActions.ed.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. // Undo actions that are useful in multiple editors.
  23. //=============================================================================================
  24. // Undo reparenting.
  25. //=============================================================================================
  26. //---------------------------------------------------------------------------------------------
  27. function UndoActionReparentObjects::create( %treeView )
  28. {
  29. pushInstantGroup();
  30. %action = new UndoScriptAction()
  31. {
  32. class = "UndoActionReparentObjects";
  33. numObjects = 0;
  34. treeView = %treeView;
  35. };
  36. popInstantGroup();
  37. return %action;
  38. }
  39. //---------------------------------------------------------------------------------------------
  40. function UndoActionReparentObjects::add( %this, %object, %oldParent, %newParent )
  41. {
  42. %index = %this.numObjects;
  43. %this.objects[ %index ] = %object;
  44. %this.oldParents[ %index ] = %oldParent;
  45. %this.newParents[ %index ] = %newParent;
  46. %this.numObjects = %this.numObjects + 1;
  47. }
  48. //---------------------------------------------------------------------------------------------
  49. function UndoActionReparentObjects::undo( %this )
  50. {
  51. %numObjects = %this.numObjects;
  52. for( %i = 0; %i < %numObjects; %i ++ )
  53. {
  54. %obj = %this.objects[ %i ];
  55. %group = %this.oldParents[ %i ];
  56. if( isObject( %obj ) && isObject( %group ) )
  57. %obj.parentGroup = %group;
  58. }
  59. if( isObject( %this.treeView ) )
  60. %this.treeView.update();
  61. }
  62. //---------------------------------------------------------------------------------------------
  63. function UndoActionReparentObjects::redo( %this )
  64. {
  65. %numObjects = %this.numObjects;
  66. for( %i = 0; %i < %numObjects; %i ++ )
  67. {
  68. %obj = %this.objects[ %i ];
  69. %group = %this.newParents[ %i ];
  70. if( isObject( %obj ) && isObject( %group ) )
  71. %obj.parentGroup = %group;
  72. }
  73. if( isObject( %this.treeView ) )
  74. %this.treeView.update();
  75. }