mirror of
https://github.com/haven1433/HexManiacAdvance.git
synced 2026-06-01 04:53:29 -05:00
Refactor: move logic to viewmodel
This commit is contained in:
parent
0b793e9207
commit
5374da126b
|
|
@ -119,12 +119,22 @@ namespace HavenSoft.HexManiac.Core.ViewModels {
|
|||
history.ChangeCompleted();
|
||||
}
|
||||
|
||||
public void HandleMove(int originalIndex, int newIndex) {
|
||||
if (originalIndex == newIndex) return;
|
||||
public IList<(int index, int direction)> HandleMove(int originalIndex, int newIndex) {
|
||||
var otherMovedElements = new List<(int, int)>();
|
||||
if (originalIndex == newIndex) return otherMovedElements;
|
||||
var element = Elements[originalIndex];
|
||||
Elements.RemoveAt(originalIndex);
|
||||
Elements.Insert(newIndex, element);
|
||||
Debug.Assert(Elements.All(item => item != null), "Dex Reorder only works if there are no empty pokedex slots!");
|
||||
|
||||
for (int i = originalIndex; i < newIndex; i++) {
|
||||
otherMovedElements.Add((i, 1));
|
||||
}
|
||||
for (int i = newIndex + 1; i <= originalIndex; i++) {
|
||||
otherMovedElements.Add((i, -1));
|
||||
}
|
||||
|
||||
return otherMovedElements;
|
||||
}
|
||||
|
||||
private static IDictionary<int, (T oldVal, T newVal)> Diff<T>(IList<T> oldList, IList<T> newList) where T : IEquatable<T> {
|
||||
|
|
|
|||
|
|
@ -37,21 +37,13 @@ namespace HavenSoft.HexManiac.WPF.Controls {
|
|||
var viewModel = (DexReorderTab)DataContext;
|
||||
oldTileIndex = Math.Min(Math.Max(0, oldTileIndex), Container.Items.Count - 1);
|
||||
newTileIndex = Math.Min(Math.Max(0, newTileIndex), Container.Items.Count - 1);
|
||||
viewModel.HandleMove(oldTileIndex, newTileIndex);
|
||||
var tilesToAnimate = viewModel.HandleMove(oldTileIndex, newTileIndex);
|
||||
|
||||
for (int i = oldTileIndex; i < newTileIndex; i++) {
|
||||
// all these tiles were moved to the left
|
||||
var image = (PixelImage)MainWindow.GetChild(Container, "PixelImage", viewModel.Elements[i]);
|
||||
foreach(var tile in tilesToAnimate) {
|
||||
var image = (PixelImage)MainWindow.GetChild(Container, "PixelImage", viewModel.Elements[tile.index]);
|
||||
if (!(image.RenderTransform is TranslateTransform)) image.RenderTransform = new TranslateTransform();
|
||||
var transform = (TranslateTransform)image.RenderTransform;
|
||||
transform.BeginAnimation(TranslateTransform.XProperty, new DoubleAnimation(ExpectedElementWidth, 0, span));
|
||||
}
|
||||
for (int i = newTileIndex + 1; i <= oldTileIndex; i++) {
|
||||
// all these tiles were moved to the right
|
||||
var image = (PixelImage)MainWindow.GetChild(Container, "PixelImage", viewModel.Elements[i]);
|
||||
if (!(image.RenderTransform is TranslateTransform)) image.RenderTransform = new TranslateTransform();
|
||||
var transform = (TranslateTransform)image.RenderTransform;
|
||||
transform.BeginAnimation(TranslateTransform.XProperty, new DoubleAnimation(-ExpectedElementWidth, 0, span));
|
||||
transform.BeginAnimation(TranslateTransform.XProperty, new DoubleAnimation(ExpectedElementWidth * tile.direction, 0, span));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user