diff --git a/Assets/uAdventure/Editor/Engine logic/Controllers/Data controllers/Scene/ElementReferenceDataControl.cs b/Assets/uAdventure/Editor/Engine logic/Controllers/Data controllers/Scene/ElementReferenceDataControl.cs index f19dd13e..92310a9c 100644 --- a/Assets/uAdventure/Editor/Engine logic/Controllers/Data controllers/Scene/ElementReferenceDataControl.cs +++ b/Assets/uAdventure/Editor/Engine logic/Controllers/Data controllers/Scene/ElementReferenceDataControl.cs @@ -217,6 +217,21 @@ public void setElementScale(float scale) controller.AddTool(new ChangeElementReferenceTool(elementReference, scale)); } + /** + * Set the position and scale for the element references + * + * @param x + * X coordinate for the element reference + * @param y + * Y coordinate for the element reference + * @param scale + * the scale for the element reference + */ + public void setElementPositionAndScale(int x, int y, float scale) + { + controller.AddTool(new ChangeElementReferenceTool(elementReference, x, y, scale)); + } + public override System.Object getContent() { diff --git a/Assets/uAdventure/Editor/Engine logic/Controllers/Data controllers/Scene/ReferencesListDataControl.cs b/Assets/uAdventure/Editor/Engine logic/Controllers/Data controllers/Scene/ReferencesListDataControl.cs index 5fd292ee..b5fc2188 100644 --- a/Assets/uAdventure/Editor/Engine logic/Controllers/Data controllers/Scene/ReferencesListDataControl.cs +++ b/Assets/uAdventure/Editor/Engine logic/Controllers/Data controllers/Scene/ReferencesListDataControl.cs @@ -372,8 +372,8 @@ private void performAddElement(int type, string id) getReferencesList(elementType).Add(newElementReference); ElementReferenceDataControl erdc = new ElementReferenceDataControl(sceneDataControl, newElementReference, type, counter); var defaultPos = sceneDataControl.getDefaultInitialPosition(); - erdc.setElementPosition((int)defaultPos.x, (int)defaultPos.y); - erdc.setElementScale(sceneDataControl.getElementAppropiateScale(erdc.getReferencedElementDataControl() as DataControlWithResources)); + newElementReference.setPosition((int)defaultPos.x, (int)defaultPos.y); + newElementReference.setScale(sceneDataControl.getElementAppropiateScale(erdc.getReferencedElementDataControl() as DataControlWithResources)); ElementContainer ec = new ElementContainer(erdc, -1, null); lastElementContainer = ec; reassignLayerAllReferencesDataControl(insertInOrder(ec, false)); diff --git a/Assets/uAdventure/Editor/Engine logic/Controllers/Data controllers/Scene/SceneDataControl.cs b/Assets/uAdventure/Editor/Engine logic/Controllers/Data controllers/Scene/SceneDataControl.cs index b79498e2..ea79475c 100644 --- a/Assets/uAdventure/Editor/Engine logic/Controllers/Data controllers/Scene/SceneDataControl.cs +++ b/Assets/uAdventure/Editor/Engine logic/Controllers/Data controllers/Scene/SceneDataControl.cs @@ -183,9 +183,10 @@ public void setPreviewBackground(string path) // References foreach(var reference in referencesListDataControl.getRefferences()) { - reference.setElementPosition((int)(reference.getElementX() * background.width / previousBackgroundSize.x), + var data = reference.getElementReference(); + data.setPosition((int)(reference.getElementX() * background.width / previousBackgroundSize.x), (int)(reference.getElementY() * background.height / previousBackgroundSize.y)); - reference.setElementScale(reference.getElementScale() * background.height / previousBackgroundSize.y); + data.setScale(reference.getElementScale() * background.height / previousBackgroundSize.y); } // Areas diff --git a/Assets/uAdventure/Editor/Engine logic/Controllers/Tools/General/ChangeElementReferenceTool.cs b/Assets/uAdventure/Editor/Engine logic/Controllers/Tools/General/ChangeElementReferenceTool.cs index 11267c2d..88e53f57 100644 --- a/Assets/uAdventure/Editor/Engine logic/Controllers/Tools/General/ChangeElementReferenceTool.cs +++ b/Assets/uAdventure/Editor/Engine logic/Controllers/Tools/General/ChangeElementReferenceTool.cs @@ -7,18 +7,12 @@ namespace uAdventure.Editor { public class ChangeElementReferenceTool : Tool { - - private ElementReference elementReference; - + private readonly ElementReference elementReference; private int x, y; - - private int oldX, oldY; - - private bool changePosition; - - private bool changeScale; - - private float scale, oldScale; + private readonly int oldX, oldY; + private readonly bool changePosition, changeScale; + private float scale; + private readonly float oldScale; public ChangeElementReferenceTool(ElementReference elementReference, int x, int y) { @@ -32,16 +26,30 @@ public ChangeElementReferenceTool(ElementReference elementReference, int x, int changeScale = false; } - public ChangeElementReferenceTool(ElementReference elementReference2, float scale2) + public ChangeElementReferenceTool(ElementReference elementReference, float scale) { - this.elementReference = elementReference2; - this.scale = scale2; - this.oldScale = elementReference.getScale(); + this.elementReference = elementReference; + this.scale = scale; + this.oldScale = this.elementReference.getScale(); changePosition = false; changeScale = true; } + public ChangeElementReferenceTool(ElementReference elementReference, int x, int y, float scale) + { + + this.elementReference = elementReference; + this.x = x; + this.y = y; + this.scale = scale; + this.oldX = elementReference.getX(); + this.oldY = elementReference.getY(); + this.oldScale = this.elementReference.getScale(); + changePosition = true; + changeScale = true; + } + public override bool canRedo() { @@ -59,27 +67,29 @@ public override bool canUndo() public override bool combine(Tool other) { - - if (other is ChangeElementReferenceTool) + var combined = false; + var otherReferenceTool = other as ChangeElementReferenceTool; + if (otherReferenceTool != null) { - ChangeElementReferenceTool crvt = (ChangeElementReferenceTool)other; - if (crvt.elementReference != elementReference) + if (otherReferenceTool.elementReference != elementReference) + { return false; - if (crvt.changePosition && changePosition) + } + if (otherReferenceTool.changePosition && changePosition) { - x = crvt.x; - y = crvt.y; - timeStamp = crvt.timeStamp; - return true; + x = otherReferenceTool.x; + y = otherReferenceTool.y; + timeStamp = otherReferenceTool.timeStamp; + combined = true; } - if (crvt.changeScale && changeScale) + if (otherReferenceTool.changeScale && changeScale) { - scale = crvt.scale; - timeStamp = crvt.timeStamp; - return true; + scale = otherReferenceTool.scale; + timeStamp = otherReferenceTool.timeStamp; + combined = true; } } - return false; + return combined; } @@ -90,7 +100,7 @@ public override bool doTool() { elementReference.setScale(scale); } - else if (changePosition) + if (changePosition) { elementReference.setPosition(x, y); } @@ -113,7 +123,7 @@ public override bool redoTool() { elementReference.setScale(scale); } - else if (changePosition) + if (changePosition) { elementReference.setPosition(x, y); } @@ -129,7 +139,7 @@ public override bool undoTool() { elementReference.setScale(oldScale); } - else if (changePosition) + if (changePosition) { elementReference.setPosition(oldX, oldY); } diff --git a/Assets/uAdventure/Editor/Windows/Windows types/Editor window/Scenes/ScenesWindowElementReference.cs b/Assets/uAdventure/Editor/Windows/Windows types/Editor window/Scenes/ScenesWindowElementReference.cs index 61f5d9ec..f5d759ce 100644 --- a/Assets/uAdventure/Editor/Windows/Windows types/Editor window/Scenes/ScenesWindowElementReference.cs +++ b/Assets/uAdventure/Editor/Windows/Windows types/Editor window/Scenes/ScenesWindowElementReference.cs @@ -337,8 +337,7 @@ public override void OnDrawingGizmosSelected() var scale = original.size.magnitude / unscaled.size.magnitude; // And then we set the values in the reference - elemRef.setElementPosition(Mathf.RoundToInt(position.x), Mathf.RoundToInt(position.y)); - elemRef.setElementScale(scale); + elemRef.setElementPositionAndScale(Mathf.RoundToInt(position.x), Mathf.RoundToInt(position.y), scale); } EditorGUI.BeginChangeCheck(); diff --git a/Assets/uAdventure/Editor/Windows/Windows types/Editor window/Scenes/ScenesWindowPlayerMovement.cs b/Assets/uAdventure/Editor/Windows/Windows types/Editor window/Scenes/ScenesWindowPlayerMovement.cs index 2bba7bf5..364c62d9 100644 --- a/Assets/uAdventure/Editor/Windows/Windows types/Editor window/Scenes/ScenesWindowPlayerMovement.cs +++ b/Assets/uAdventure/Editor/Windows/Windows types/Editor window/Scenes/ScenesWindowPlayerMovement.cs @@ -636,26 +636,60 @@ public override void OnDrawingGizmosSelected() [EditorComponent(typeof(TrajectoryDataControl), Name = "Trajectory", Order = 0)] public class TrajectoryComponent : AbstractEditorComponent { - public int Action { get; set; } + private int action = 0; - public TrajectoryComponent(Rect rect, GUIContent content, GUIStyle style, params GUILayoutOption[] options) : base(rect, content, style, options) + private NodeDataControl pairing = null; + + private TrajectoryDataControl previousTrajectoryDataControl; + public int Action { + get { return action; } + set + { + if (action == value) + { + return; + } + + action = value; + if (action != 2 && action >= 0) + { + pairing = null; + } + } } - private NodeDataControl pairing = null; + public TrajectoryComponent(Rect rect, GUIContent content, GUIStyle style, params GUILayoutOption[] options) : base(rect, content, style, options) + { + } public override void OnDrawingGizmos() { var trajectory = Target as TrajectoryDataControl; + if (trajectory == null) + { + return; + } + + if (SceneEditor.Current.Disabled && pairing != null) + { + pairing = null; + } + + if (previousTrajectoryDataControl != trajectory) + { + previousTrajectoryDataControl = trajectory; + pairing = null; + } if (Event.current.type == EventType.MouseDown) { - DataControl selected = SceneEditor.Current.SelectedElement; - NodeDataControl node = selected as NodeDataControl; - SideDataControl side = selected as SideDataControl; + var selected = SceneEditor.Current.SelectedElement; + var node = selected as NodeDataControl; + var side = selected as SideDataControl; - bool isNode = node != null && trajectory.getNodes().Contains(node); - bool isSide = side != null && trajectory.getSides().Contains(side); + var isNode = node != null && trajectory.getNodes().Contains(node); + var isSide = side != null && trajectory.getSides().Contains(side); switch (Action) { @@ -688,6 +722,10 @@ public override void OnDrawingGizmos() pairing = null; } } + else + { + pairing = null; + } break; // Initial