Skip to content
Browse files

fixed bugs related to undo-redo

  • Loading branch information...
1 parent 6b49c69 commit 35d3fd5158ff10b0045b65e6c7a2f9ff4df869b4 @keyemkey keyemkey committed Jul 1, 2013
View
14 awaybuilder-core/src/awaybuilder/CoreContext.as
@@ -61,21 +61,22 @@ package awaybuilder
import awaybuilder.controller.scene.ChangeShadowMethodCommand;
import awaybuilder.controller.scene.ChangeSkeletonCommand;
import awaybuilder.controller.scene.ChangeSkyBoxCommand;
+ import awaybuilder.controller.scene.ChangeSubMeshCommand;
import awaybuilder.controller.scene.ChangeTextureCommand;
import awaybuilder.controller.scene.ChangeTextureProjectorCommand;
import awaybuilder.controller.scene.DeleteCommand;
import awaybuilder.controller.scene.ReparentAnimationCommand;
import awaybuilder.controller.scene.ReparentLightCommand;
import awaybuilder.controller.scene.ReparentObjectCommand;
- import awaybuilder.controller.scene.RotateObjectCommand;
- import awaybuilder.controller.scene.ScaleObjectCommand;
+ import awaybuilder.controller.scene.RotateCommand;
+ import awaybuilder.controller.scene.ScaleCommand;
import awaybuilder.controller.scene.SelectCommand;
import awaybuilder.controller.scene.SwitchFreeCameraModeCommand;
import awaybuilder.controller.scene.SwitchTargetCameraModeCommand;
import awaybuilder.controller.scene.SwitchTransformRotateModeCommand;
import awaybuilder.controller.scene.SwitchTransformScaleModeCommand;
import awaybuilder.controller.scene.SwitchTransformTranslateModeCommand;
- import awaybuilder.controller.scene.TranslateObjectCommand;
+ import awaybuilder.controller.scene.TranslateCommand;
import awaybuilder.controller.scene.events.SceneEvent;
import awaybuilder.model.AssetsModel;
import awaybuilder.model.DocumentModel;
@@ -132,9 +133,9 @@ package awaybuilder
this.commandMap.mapEvent(SceneEvent.SWITCH_TRANSFORM_SCALE, SwitchTransformScaleModeCommand);
this.commandMap.mapEvent(SceneEvent.SWITCH_TRANSFORM_TRANSLATE, SwitchTransformTranslateModeCommand);
- this.commandMap.mapEvent(SceneEvent.ROTATE_OBJECT, RotateObjectCommand);
- this.commandMap.mapEvent(SceneEvent.TRANSLATE_OBJECT, TranslateObjectCommand);
- this.commandMap.mapEvent(SceneEvent.SCALE_OBJECT, ScaleObjectCommand);
+ this.commandMap.mapEvent(SceneEvent.ROTATE_OBJECT, RotateCommand);
+ this.commandMap.mapEvent(SceneEvent.TRANSLATE_OBJECT, TranslateCommand);
+ this.commandMap.mapEvent(SceneEvent.SCALE_OBJECT, ScaleCommand);
this.commandMap.mapEvent(SceneEvent.DELETE, DeleteCommand);
this.commandMap.mapEvent(SceneEvent.SELECT, SelectCommand);
@@ -150,6 +151,7 @@ package awaybuilder
commandMap.mapEvent(SceneEvent.REPARENT_ANIMATIONS, ReparentAnimationCommand);
commandMap.mapEvent(SceneEvent.CHANGE_MESH, ChangeMeshCommand);
+ commandMap.mapEvent(SceneEvent.CHANGE_SUBMESH, ChangeSubMeshCommand);
commandMap.mapEvent(SceneEvent.CHANGE_CONTAINER, ChangeContainerCommand);
commandMap.mapEvent(SceneEvent.CHANGE_MATERIAL, ChangeMaterialCommand);
commandMap.mapEvent(SceneEvent.CHANGE_LIGHT, ChangeLightCommand);
View
24 awaybuilder-core/src/awaybuilder/controller/scene/ChangeMaterialCommand.as
@@ -12,7 +12,7 @@ package awaybuilder.controller.scene
override public function execute():void
{
- var newValues:Vector.<MaterialVO> = event.newValue as Vector.<MaterialVO>;
+ var newValues:Vector.<MaterialVO> = getNewValues();
var oldValues:Vector.<MaterialVO> = new Vector.<MaterialVO>();
for( var i:int = 0; i < event.items.length; i++ )
@@ -25,5 +25,27 @@ package awaybuilder.controller.scene
saveOldValue( event, oldValues );
commitHistoryEvent( event );
}
+
+ private function getNewValues():Vector.<MaterialVO>
+ {
+ var newValues:Vector.<MaterialVO> = new Vector.<MaterialVO>();
+
+ if( event.newValue is Vector.<MaterialVO> )
+ {
+ for each( var asset:MaterialVO in event.newValue )
+ {
+ newValues.push( asset.clone() );
+ }
+ }
+ else
+ {
+ for( var i:int = 0; i < event.items.length; i++ )
+ {
+ newValues.push( MaterialVO(event.newValue).clone() );
+ }
+ }
+ event.newValue = newValues;
+ return newValues;
+ }
}
}
View
24 awaybuilder-core/src/awaybuilder/controller/scene/ChangeMeshCommand.as
@@ -23,7 +23,7 @@ package awaybuilder.controller.scene
override public function execute():void
{
- var newValues:Vector.<MeshVO> = event.newValue as Vector.<MeshVO>;
+ var newValues:Vector.<MeshVO> = getNewValues();
var oldValues:Vector.<MeshVO> = new Vector.<MeshVO>();
for( var i:int = 0; i < event.items.length; i++ )
@@ -43,5 +43,27 @@ package awaybuilder.controller.scene
saveOldValue( event, oldValues );
commitHistoryEvent( event );
}
+
+ private function getNewValues():Vector.<MeshVO>
+ {
+ var newValues:Vector.<MeshVO> = new Vector.<MeshVO>();
+
+ if( event.newValue is Vector.<MeshVO> )
+ {
+ for each( var asset:MeshVO in event.newValue )
+ {
+ newValues.push( asset.clone() );
+ }
+ }
+ else
+ {
+ for( var i:int = 0; i < event.items.length; i++ )
+ {
+ newValues.push( MeshVO(event.newValue).clone() );
+ }
+ }
+ event.newValue = newValues;
+ return newValues;
+ }
}
}
View
49 awaybuilder-core/src/awaybuilder/controller/scene/ChangeSubMeshCommand.as
@@ -0,0 +1,49 @@
+package awaybuilder.controller.scene
+{
+ import awaybuilder.controller.history.HistoryCommandBase;
+ import awaybuilder.controller.scene.events.SceneEvent;
+ import awaybuilder.model.vo.scene.SubMeshVO;
+
+ public class ChangeSubMeshCommand extends HistoryCommandBase
+ {
+ [Inject]
+ public var event:SceneEvent;
+
+ override public function execute():void
+ {
+ var newValues:Vector.<SubMeshVO> = getNewValues();
+ var oldValues:Vector.<SubMeshVO> = new Vector.<SubMeshVO>();
+
+ for( var i:int = 0; i < event.items.length; i++ )
+ {
+ var asset:SubMeshVO = event.items[i] as SubMeshVO;
+ oldValues.push( asset.clone() );
+ asset.material = SubMeshVO( newValues[i] ).material;
+ }
+ saveOldValue( event, oldValues );
+ commitHistoryEvent( event );
+ }
+
+ private function getNewValues():Vector.<SubMeshVO>
+ {
+ var newValues:Vector.<SubMeshVO> = new Vector.<SubMeshVO>();
+
+ if( event.newValue is Vector.<SubMeshVO> )
+ {
+ for each( var asset:SubMeshVO in event.newValue )
+ {
+ newValues.push( asset.clone() );
+ }
+ }
+ else
+ {
+ for( var i:int = 0; i < event.items.length; i++ )
+ {
+ newValues.push( SubMeshVO(event.newValue).clone() );
+ }
+ }
+ event.newValue = newValues;
+ return newValues;
+ }
+ }
+}
View
2 ...r/controller/scene/RotateObjectCommand.as → ...builder/controller/scene/RotateCommand.as
@@ -9,7 +9,7 @@ package awaybuilder.controller.scene
import flash.geom.Vector3D;
- public class RotateObjectCommand extends HistoryCommandBase
+ public class RotateCommand extends HistoryCommandBase
{
[Inject]
public var event:SceneEvent;
View
2 ...er/controller/scene/ScaleObjectCommand.as → ...ybuilder/controller/scene/ScaleCommand.as
@@ -7,7 +7,7 @@
import flash.geom.Vector3D;
- public class ScaleObjectCommand extends HistoryCommandBase
+ public class ScaleCommand extends HistoryCommandBase
{
[Inject]
public var event:SceneEvent;
View
2 ...ontroller/scene/TranslateObjectCommand.as → ...lder/controller/scene/TranslateCommand.as
@@ -10,7 +10,7 @@ package awaybuilder.controller.scene
import flash.geom.Vector3D;
- public class TranslateObjectCommand extends HistoryCommandBase
+ public class TranslateCommand extends HistoryCommandBase
{
[Inject]
public var event:SceneEvent;
View
32 awaybuilder-core/src/awaybuilder/controller/scene/TranslatePivotCommand.as
@@ -0,0 +1,32 @@
+package awaybuilder.controller.scene
+{
+ import awaybuilder.controller.history.HistoryCommandBase;
+ import awaybuilder.controller.scene.events.SceneEvent;
+ import awaybuilder.model.vo.scene.ObjectVO;
+
+ import flash.geom.Vector3D;
+
+ public class TranslatePivotCommand extends HistoryCommandBase
+ {
+ [Inject]
+ public var event:SceneEvent;
+
+ override public function execute():void
+ {
+ var newValues:Vector.<Vector3D> = event.newValue as Vector.<Vector3D>;
+ var oldValues:Vector.<Vector3D> = new Vector.<Vector3D>();
+
+ for( var i:int = 0; i < event.items.length; i++ )
+ {
+ var asset:ObjectVO = event.items[i] as ObjectVO;
+ oldValues.push( new Vector3D( asset.x, asset.y, asset.z ) );
+ asset.pivotX = isNaN(newValues[i].x)?asset.x:newValues[i].x;
+ asset.pivotY = isNaN(newValues[i].y)?asset.y:newValues[i].y;
+ asset.pivotZ = isNaN(newValues[i].z)?asset.z:newValues[i].z;
+ }
+
+ saveOldValue( event, oldValues );
+ commitHistoryEvent( event );
+ }
+ }
+}
View
1 awaybuilder-core/src/awaybuilder/controller/scene/events/SceneEvent.as
@@ -25,6 +25,7 @@ import flash.events.Event;
public static const CHANGE_CONTAINER:String = "changeContainer";
public static const CHANGE_GEOMETRY:String = "changeGeometry";
public static const CHANGE_MESH:String = "changeMesh";
+ public static const CHANGE_SUBMESH:String = "changeSubMesh";
public static const CHANGE_TEXTURE_PROJECTOR:String = "changeTextureProjector";
public static const CHANGE_MATERIAL:String = "changeMaterial";
public static const CHANGE_LIGHT:String = "changeLight";
View
10 awaybuilder-core/src/awaybuilder/model/vo/scene/SubMeshVO.as
@@ -20,5 +20,15 @@ package awaybuilder.model.vo.scene
public var parentMesh:MeshVO;
+ public function clone():SubMeshVO
+ {
+ var m:SubMeshVO = new SubMeshVO();
+ m.id = this.id;
+ m.material = this.material;
+ m.subGeometry = this.subGeometry;
+ m.parentMesh = this.parentMesh;
+ return m;
+ }
+
}
}
View
6 awaybuilder-core/src/awaybuilder/view/components/editors/renderers/SubmeshItemRenderer.mxml
@@ -65,9 +65,9 @@
private function dropDownList1_changeHandler(event:IndexChangeEvent):void
{
- _subMesh.material = dropDownList.selectedItem as MaterialVO;
- // TODO check why it fires twice
- dispatchEvent(new PropertyEditorEvent(PropertyEditorEvent.MESH_SUBMESH_CHANGE, _subMesh, true));
+ var subMesh:SubMeshVO = _subMesh.clone();
+ subMesh.material = dropDownList.selectedItem as MaterialVO;
+ dispatchEvent(new PropertyEditorEvent(PropertyEditorEvent.MESH_SUBMESH_CHANGE, subMesh, true));
}
private function editSubmeshMaterialButton_clickHandler(event:MouseEvent):void
View
23 awaybuilder-core/src/awaybuilder/view/mediators/CoreEditorMediator.as
@@ -188,6 +188,7 @@ package awaybuilder.view.mediators
addContextListener(SceneEvent.SCALE_OBJECT, eventDispatcher_translateHandler);
addContextListener(SceneEvent.ROTATE_OBJECT, eventDispatcher_translateHandler);
addContextListener(SceneEvent.CHANGE_MESH, eventDispatcher_changeMeshHandler);
+ addContextListener(SceneEvent.CHANGE_SUBMESH, eventDispatcher_changeMeshHandler);
addContextListener(SceneEvent.CHANGE_LIGHT, eventDispatcher_changeLightHandler);
addContextListener(SceneEvent.CHANGE_MATERIAL, eventDispatcher_changeMaterialHandler);
addContextListener(SceneEvent.CHANGE_LIGHTPICKER, eventDispatcher_changeLightPickerHandler);
@@ -1128,22 +1129,18 @@ package awaybuilder.view.mediators
}
}
-// private function eventDispatcher_updateMeshMaterialHandler(event:SceneEvent):void
-// {
-// for each (var item:ObjectContainer3D in event.items) {
-// var mVO:MeshVO = assets.GetAsset(item) as MeshVO;
-// for each( var sub:SubMeshVO in mVO.subMeshes )
-// {
-// applySubMesh( sub );
-// }
-// }
-// }
-//
private function eventDispatcher_changeMeshHandler(event:SceneEvent):void
{
- for each( var asset:MeshVO in event.items )
+ for each( var asset:AssetVO in event.items )
{
- applyMesh( asset );
+ if( asset is MeshVO )
+ {
+ applyMesh( asset as MeshVO );
+ }
+ else if( asset is SubMeshVO )
+ {
+ applyMesh( SubMeshVO(asset).parentMesh );
+ }
}
}
private function updateChildren( children:ArrayCollection ):void
View
8 awaybuilder-core/src/awaybuilder/view/mediators/LibraryPanelMediator.as
@@ -241,7 +241,6 @@ package awaybuilder.view.mediators
this.dispatch(new SceneEvent(SceneEvent.SELECT,[asset]));
}
- private var _doNotUpdate:Boolean = false;
private function view_treeChangeHandler(event:LibraryPanelEvent):void
{
if( event.data )
@@ -253,7 +252,6 @@ package awaybuilder.view.mediators
{
items.push(selectedItems[i]);
}
-// _doNotUpdate = true;
this.dispatch(new SceneEvent(SceneEvent.SELECT,items));
}
}
@@ -401,12 +399,6 @@ package awaybuilder.view.mediators
private function context_itemsSelectHandler(event:SceneEvent):void
{
- if( _doNotUpdate )
- {
- _doNotUpdate = false;
- return;
- }
-
_selectedSceneItems = new Vector.<Object>();
for each( var asset:AssetVO in event.items )
{
View
22 awaybuilder-core/src/awaybuilder/view/mediators/PropertiesPanelMediator.as
@@ -259,43 +259,33 @@ package awaybuilder.view.mediators
}
private function view_meshSubmeshChangeHandler(event:PropertyEditorEvent):void
{
+ var currentSubmesh:SubMeshVO;
if( view.data )
{
var vo:MeshVO = view.data as MeshVO;
- var newValue:MeshVO = vo.clone() as MeshVO;
- for each( var subMesh:SubMeshVO in newValue.subMeshes )
+ for each( var subMesh:SubMeshVO in vo.subMeshes )
{
if( subMesh.equals( AssetVO(event.data) ) )
{
- subMesh.material = SubMeshVO(event.data).material;
+ currentSubmesh = subMesh;
}
}
- this.dispatch(new SceneEvent(SceneEvent.CHANGE_MESH,[view.data], newValue));
+ this.dispatch(new SceneEvent(SceneEvent.CHANGE_SUBMESH,[currentSubmesh], event.data));
}
}
private function view_materialChangeHandler(event:PropertyEditorEvent):void
{
var items:Array;
if( view.data is MaterialVO ) items = [view.data];
if( view.data is Array ) items = view.data as Array;
- var newValues:Vector.<MaterialVO> = new Vector.<MaterialVO>();
- for each( var asset:MaterialVO in items )
- {
- newValues.push( event.data );
- }
- this.dispatch(new SceneEvent(SceneEvent.CHANGE_MATERIAL,items, newValues));
+ this.dispatch(new SceneEvent(SceneEvent.CHANGE_MATERIAL, items, event.data));
}
private function view_materialNameChangeHandler(event:PropertyEditorEvent):void
{
var items:Array;
if( view.data is MaterialVO ) items = [view.data];
if( view.data is Array ) items = view.data as Array;
- var newValues:Vector.<MaterialVO> = new Vector.<MaterialVO>();
- for each( var asset:MaterialVO in items )
- {
- newValues.push( event.data );
- }
- this.dispatch(new SceneEvent(SceneEvent.CHANGE_MATERIAL,items, newValues, true));
+ this.dispatch(new SceneEvent(SceneEvent.CHANGE_MATERIAL,items, event.data, true));
}
private function view_materialAmbientMethodHandler(event:PropertyEditorEvent):void
{
View
4 awaybuilder-desktop/src/awaybuilder/desktop/model/DesktopDocumentService.as
@@ -283,9 +283,9 @@ package awaybuilder.desktop.model
replaceDocumentDataEvent.value = document;
replaceDocumentDataEvent.globalOptions = globalOptions;
}
- else if( _nextEvent is ConcatenateDataOperationEvent )
+ else if( _nextEvent is HistoryEvent )
{
- var concatenateDataOperationEvent:ConcatenateDataOperationEvent = _nextEvent as ConcatenateDataOperationEvent;
+ var concatenateDataOperationEvent:HistoryEvent = _nextEvent as HistoryEvent;
concatenateDataOperationEvent.newValue = document;
}
dispatch( _nextEvent );

0 comments on commit 35d3fd5

Please sign in to comment.
Something went wrong with that request. Please try again.