Skip to content

Commit

Permalink
actual live updating for tiles
Browse files Browse the repository at this point in the history
  • Loading branch information
jupahe64 committed Nov 9, 2023
1 parent a7d61ab commit aa05630
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
6 changes: 4 additions & 2 deletions Fushigi/ui/Transform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ public class Transform
public Vector3 RotationEuler { get; set; }
public Vector3 Scale { get; set; } = Vector3.One;

public virtual void Update()
{
public event Action? Update;

internal virtual void OnUpdate()
{
Update?.Invoke();
}
}
}
15 changes: 12 additions & 3 deletions Fushigi/ui/bgunit/BGUnitRail.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,12 @@ public BGUnitRail(CourseUnit unit, CourseUnit.Rail rail)
this.Points.Clear();

foreach (var pt in rail.mPoints)
Points.Add(new RailPoint(pt.Value));
{
var railPoint = new RailPoint(pt.Value);
railPoint.Transform.Update += unit.GenerateTileSubUnits;
Points.Add(railPoint);

}

IsClosed = rail.IsClosed;
IsInternal = rail.IsInternal;
Expand Down Expand Up @@ -219,8 +224,6 @@ public void OnMouseUp(LevelViewport viewport)
{
mouseDown = false;
transformStart = false;

CourseUnit.GenerateTileSubUnits();
}

public void OnSelecting(LevelViewport viewport)
Expand All @@ -241,6 +244,8 @@ public void OnSelecting(LevelViewport viewport)
viewport.mEditContext.EndUndoCollection("Move Rail Points");
}

bool anyTransformed = false;

for (int i = 0; i < Points.Count; i++)
{
if (transformStart && ctx.IsSelected(Points[i]))
Expand All @@ -249,8 +254,12 @@ public void OnSelecting(LevelViewport viewport)
diff.Y = MathF.Round(diff.Y, MidpointRounding.AwayFromZero);
posVec.Z = Points[i].Position.Z;
Points[i].Position = Points[i].PreviousPosition + diff;
anyTransformed = true;
}
}

if(anyTransformed)
CourseUnit.GenerateTileSubUnits();
}

public void Render(LevelViewport viewport, ImDrawListPtr mDrawList)
Expand Down
2 changes: 1 addition & 1 deletion Fushigi/ui/undo/TransformUndo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public IRevertable Revert()
Transform.Position = this.PreviousPosition;
Transform.RotationEuler = this.PreviousRotation;
Transform.Scale = this.PreviousScale;
Transform.Update();
Transform.OnUpdate();

//Create revert stack
return new TransformUndo(Transform);
Expand Down

0 comments on commit aa05630

Please sign in to comment.