Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/e-ucm/uAdventure
Browse files Browse the repository at this point in the history
  • Loading branch information
Synpheros committed Mar 24, 2019
2 parents f1c7e30 + 39eff2a commit e1b107e
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 46 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
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -688,6 +722,10 @@ public override void OnDrawingGizmos()
pairing = null;
}
}
else
{
pairing = null;
}
break;

// Initial
Expand Down

0 comments on commit e1b107e

Please sign in to comment.