From 24370c1b5da8e163e96a339da6c0e1b69e2a728e Mon Sep 17 00:00:00 2001 From: dexyfex Date: Tue, 26 Sep 2017 12:07:45 +1000 Subject: [PATCH] Multi-select update graphics, fix for multi-move path nodes --- GameFiles/FileTypes/YndFile.cs | 6 ++-- Project/UndoStep.cs | 50 +++++++++++++++++++++++++++++++++- WorldForm.cs | 10 +++++-- 3 files changed, 59 insertions(+), 7 deletions(-) diff --git a/GameFiles/FileTypes/YndFile.cs b/GameFiles/FileTypes/YndFile.cs index 7d28c9c..8015e06 100644 --- a/GameFiles/FileTypes/YndFile.cs +++ b/GameFiles/FileTypes/YndFile.cs @@ -827,9 +827,9 @@ namespace CodeWalker.GameFiles _RawData.PositionZ = (short)(pos.Z * 32.0f); Vector3 newpos = pos; - newpos.X = _RawData.PositionX / 4.0f; - newpos.Y = _RawData.PositionY / 4.0f; - newpos.Z = _RawData.PositionZ / 32.0f; + //newpos.X = _RawData.PositionX / 4.0f; + //newpos.Y = _RawData.PositionY / 4.0f; + //newpos.Z = _RawData.PositionZ / 32.0f; Position = newpos; UpdateLinkLengths(); diff --git a/Project/UndoStep.cs b/Project/UndoStep.cs index f7c511e..2f7cd66 100644 --- a/Project/UndoStep.cs +++ b/Project/UndoStep.cs @@ -29,12 +29,14 @@ namespace CodeWalker.Project public Vector3 StartPosition { get; set; } public Vector3 EndPosition { get; set; } - public MultiPositionUndoStep(MapSelection multiSel, MapSelection[] items, Vector3 startpos) + public MultiPositionUndoStep(MapSelection multiSel, MapSelection[] items, Vector3 startpos, WorldForm wf) { Selection = multiSel; Items = items; StartPosition = startpos; EndPosition = multiSel.WidgetPosition; + + UpdateGraphics(wf); } private void Update(WorldForm wf, ref MapSelection sel, Vector3 p, Vector3 o) @@ -51,8 +53,54 @@ namespace CodeWalker.Project wf.SelectMulti(Items); wf.SetWidgetPosition(p); + + UpdateGraphics(wf); } + + private void UpdateGraphics(WorldForm wf) + { + + Dictionary pathYnds = new Dictionary(); + Dictionary trainTracks = new Dictionary(); + Dictionary scenarioYmts = new Dictionary(); + + if (Items != null) + { + foreach (var item in Items) + { + if (item.PathNode != null) + { + pathYnds[item.PathNode.Ynd] = 1; + } + if (item.TrainTrackNode != null) + { + trainTracks[item.TrainTrackNode.Track] = 1; + } + if (item.ScenarioNode != null) + { + scenarioYmts[item.ScenarioNode.Ymt] = 1; + } + } + } + + foreach (var kvp in pathYnds) + { + wf.UpdatePathYndGraphics(kvp.Key, true); + } + foreach (var kvp in trainTracks) + { + wf.UpdateTrainTrackGraphics(kvp.Key, false); + } + foreach (var kvp in scenarioYmts) + { + wf.UpdateScenarioGraphics(kvp.Key, false); + } + + } + + + public override void Undo(WorldForm wf, ref MapSelection sel) { Update(wf, ref sel, StartPosition, EndPosition); diff --git a/WorldForm.cs b/WorldForm.cs index bce18fe..691f240 100644 --- a/WorldForm.cs +++ b/WorldForm.cs @@ -3470,11 +3470,11 @@ namespace CodeWalker } else { + var dpos = newpos - oldpos; for (int i = 0; i < SelectedItems.Count; i++) { var refpos = SelectedItems[i].WidgetPosition; - var relpos = refpos - oldpos; - SelectedItems[i].SetPosition(relpos + newpos, refpos, false); + SelectedItems[i].SetPosition(refpos + dpos, refpos, false); } SelectedItem.MultipleSelectionCenter = newpos; } @@ -3586,6 +3586,9 @@ namespace CodeWalker { if (fullupdate) { + ynd.UpdateAllNodePositions(); + ynd.BuildBVH(); + space.BuildYndData(ynd); } else @@ -3618,6 +3621,7 @@ namespace CodeWalker public void UpdateTrainTrackGraphics(TrainTrack tt, bool fullupdate) { tt.BuildVertices(); + tt.BuildBVH(); //if (fullupdate) //{ // //space.BuildYndData(ynd); @@ -6347,7 +6351,7 @@ namespace CodeWalker { switch (tw.Mode) { - case WidgetMode.Position: s = new MultiPositionUndoStep(SelectedItem, SelectedItems.ToArray(), UndoStartPosition); break; + case WidgetMode.Position: s = new MultiPositionUndoStep(SelectedItem, SelectedItems.ToArray(), UndoStartPosition, this); break; } } else if (ent != null)