Skip to content

Commit

Permalink
Fixed #60
Browse files Browse the repository at this point in the history
  • Loading branch information
Victorma committed Mar 23, 2019
1 parent 19c48a1 commit 39eff2a
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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()
{
Expand All @@ -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;
}


Expand All @@ -90,7 +100,7 @@ public override bool doTool()
{
elementReference.setScale(scale);
}
else if (changePosition)
if (changePosition)
{
elementReference.setPosition(x, y);
}
Expand All @@ -113,7 +123,7 @@ public override bool redoTool()
{
elementReference.setScale(scale);
}
else if (changePosition)
if (changePosition)
{
elementReference.setPosition(x, y);
}
Expand All @@ -129,7 +139,7 @@ public override bool undoTool()
{
elementReference.setScale(oldScale);
}
else if (changePosition)
if (changePosition)
{
elementReference.setPosition(oldX, oldY);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 39eff2a

Please sign in to comment.