Skip to content

Commit

Permalink
First pass at making editing work in the new animation editor - it st…
Browse files Browse the repository at this point in the history
…ill refreshes 2x...
  • Loading branch information
vchelaru committed Feb 2, 2024
1 parent 436a4ff commit 4c3a466
Show file tree
Hide file tree
Showing 10 changed files with 274 additions and 115 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public string GetContentFolder(IElement element)
public FilePath GetGlobalContentFolder() =>
ProjectManager.ProjectBase.GetAbsoluteContentFolder() + "GlobalContent/";


public void IgnoreNextChangeOnFile(FilePath filePath) => IgnoreNextChangeOnFile(filePath.FullPath);
public void IgnoreNextChangeOnFile(string absoluteFileName)
{
IO.FileWatchManager.IgnoreNextChangeOnFile(absoluteFileName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public interface IFileCommands
FilePath GetGlobalContentFolder();

void IgnoreNextChangeOnFile(string absoluteFileName);
void IgnoreNextChangeOnFile(FilePath filePath);

string GetFullFileName(ReferencedFileSave rfs);
FilePath GetFilePath(ReferencedFileSave rfs);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ private static void HandleViewModelPropertyChanged(object sender, PropertyChange
if(ViewModel.SelectedAnimationFrame != null)
{
View.PropertyGrid.Visibility = System.Windows.Visibility.Visible;
View.ShowInPropertyGrid(ViewModel.SelectedAnimationFrame);
PropertyGridManager.ShowInPropertyGrid(ViewModel.SelectedAnimationFrame);
}
else if(ViewModel.SelectedShape != null)
{
Expand All @@ -66,7 +66,7 @@ private static void HandleViewModelPropertyChanged(object sender, PropertyChange
else
{
View.PropertyGrid.Visibility = System.Windows.Visibility.Visible;
View.ShowInPropertyGrid(ViewModel.SelectedAnimationChain);
PropertyGridManager.ShowInPropertyGrid(ViewModel.SelectedAnimationChain);
}
break;
}
Expand Down Expand Up @@ -100,7 +100,7 @@ internal static void ShowTab(FilePath filePath)
}

Tab.Show();
view.GumCanvas.InvalidateVisual();
view.TopGumCanvas.InvalidateVisual();
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,38 +13,71 @@ namespace OfficialPlugins.AnimationChainPlugin.Managers
{
internal static class MemberCategoryManager
{
#region Animation Chain

public static void SetMemberCategories(DataUiGrid grid, AnimationChainViewModel selectedAnimationChain)
{
grid.Categories.Clear();

grid.Categories.AddRange(CreateMemberCategories(selectedAnimationChain));
}

public static void SetMemberCategories(DataUiGrid grid, AnimationFrameViewModel selectedAnimationFrame)
private static List<MemberCategory> CreateMemberCategories(AnimationChainViewModel selectedAnimationChain)
{
var propertiesToShow = new string[]
{
nameof(AnimationFrameViewModel.LengthInSeconds),
List<MemberCategory> toReturn = new List<MemberCategory>();

};
var mainCategory = new MemberCategory();
toReturn.Add(mainCategory);

Add(nameof(AnimationChainViewModel.Name));
Add(nameof(AnimationChainViewModel.Duration));

return toReturn;

var category = grid.Categories[0];
for(int i = category.Members.Count-1; i> -1; i--)
void Add(string propertyName)
{
var member = category.Members[i];
if(propertiesToShow.Contains(member.Name) == false)
{
category.Members.RemoveAt(i);
}
var member = new InstanceMember(propertyName, selectedAnimationChain);
member.IsReadOnly = true;
mainCategory.Members.Add(member);
}
}

#endregion

#region Animation Frame

public static void SetMemberCategories(DataUiGrid grid, AnimationFrameViewModel selectedAnimationFrame)
{
List<MemberCategory> list = new List<MemberCategory>();

var mainCategory = new MemberCategory();
list.Add(mainCategory);


foreach(var member in category.Members)
Add(nameof(AnimationFrameViewModel.StrippedTextureName));
Add(nameof(AnimationFrameViewModel.XOffset));
Add(nameof(AnimationFrameViewModel.YOffset));
Add(nameof(AnimationFrameViewModel.X), canWrite:true);
Add(nameof(AnimationFrameViewModel.Y), canWrite: true);
Add(nameof(AnimationFrameViewModel.Width));
Add(nameof(AnimationFrameViewModel.Height));
Add(nameof(AnimationFrameViewModel.LengthInSeconds));
Add(nameof(AnimationFrameViewModel.FlipHorizontal));
Add(nameof(AnimationFrameViewModel.FlipVertical));

void Add(string propertyName, bool canWrite = false)
{
// for now....
member.IsReadOnly = true;
var member = new InstanceMember(propertyName, selectedAnimationFrame);
member.IsReadOnly = !canWrite;
mainCategory.Members.Add(member);
}

grid.InsertSpacesInCamelCaseMemberNames();

grid.Categories.Clear();
grid.Categories.AddRange(list);

grid.InsertSpacesInCamelCaseMemberNames();
}

//private static List<MemberCategory> CreateMemberCategories(AnimationFrameViewModel animationFrameViewModel)
Expand All @@ -56,35 +89,8 @@ public static void SetMemberCategories(DataUiGrid grid, AnimationFrameViewModel
// return toReturn;
//}

private static List<MemberCategory> CreateMemberCategories(AnimationChainViewModel selectedAnimationChain)
{
List<MemberCategory> toReturn = new List<MemberCategory>();

var mainCategory = new MemberCategory();
toReturn.Add(mainCategory);

mainCategory.Members.Add(GetNameMember(selectedAnimationChain));
mainCategory.Members.Add(GetDurationMember(selectedAnimationChain));

return toReturn;
}
#endregion

private static InstanceMember GetNameMember(AnimationChainViewModel selectedAnimationChain)
{
var nameInstanceMember = new InstanceMember("Name", selectedAnimationChain);
nameInstanceMember.CustomGetEvent += (instance) => ((AnimationChainViewModel)instance)?.Name;
nameInstanceMember.CustomGetTypeEvent += (instance) => typeof(string);
//nameInstanceMember.CustomSetEvent += (instance, value) => ((AnimationChainViewModel)instance).Name = (string)value;
return nameInstanceMember;
}

public static InstanceMember GetDurationMember(AnimationChainViewModel selectedAnimationChain)
{
var nameInstanceMember = new InstanceMember("Duration", selectedAnimationChain);
nameInstanceMember.CustomGetEvent += (instance) => ((AnimationChainViewModel)instance)?.LengthInSeconds;
nameInstanceMember.CustomGetTypeEvent += (instance) => typeof(float);
//nameInstanceMember.CustomSetEvent += (instance, value) => ((AnimationChainViewModel)instance).Name = (string)value;
return nameInstanceMember;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using OfficialPlugins.AnimationChainPlugin.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WpfDataUi;

namespace OfficialPlugins.AnimationChainPlugin.Managers
{
public static class PropertyGridManager
{
static DataUiGrid PropertyGrid;

internal static void Initialize(DataUiGrid propertyGrid)
{
PropertyGrid = propertyGrid;
}

internal static void ShowInPropertyGrid(AnimationChainViewModel selectedAnimationChain)
{
PropertyGrid.Instance = selectedAnimationChain;
MemberCategoryManager.SetMemberCategories(PropertyGrid, selectedAnimationChain);
PropertyGrid.Refresh();
}

internal static void ShowInPropertyGrid(AnimationFrameViewModel selectedAnimationFrame)
{
PropertyGrid.Instance = selectedAnimationFrame;
MemberCategoryManager.SetMemberCategories(PropertyGrid, selectedAnimationFrame);
PropertyGrid.Refresh();
}

}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using FlatRedBall.Glue.MVVM;
using FlatRedBall.Content.AnimationChain;
using FlatRedBall.Glue.MVVM;
using OfficialPlugins.Common.ViewModels;
using System.Collections.ObjectModel;

Expand Down Expand Up @@ -73,6 +74,8 @@ public bool IsShowGuidesChecked
public ShapeViewModel SelectedShape =>
SelectedItem as ShapeViewModel;

public AnimationChainListSave BackgingData { get; internal set; }

public AchxViewModel()
{
WholeZoom = new ZoomViewModel();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
Expand All @@ -20,10 +21,10 @@ public string Name
set => Set(value);
}

public float LengthInSeconds
public float Duration
{
get => Get<float>();
set => Set(value);
private set => Set(value);
}

public AnimationChainSave BackingModel { get; private set; }
Expand All @@ -38,14 +39,30 @@ public void SetFrom(AnimationChainSave animationChain, int resolutionWidth, int
{
BackingModel = animationChain;
Name = animationChain.Name;
LengthInSeconds = animationChain.Frames.Sum(item => item.FrameLength);
Duration = animationChain.Frames.Sum(item => item.FrameLength);

foreach(var frame in animationChain.Frames)
{
var frameVm = new AnimationFrameViewModel();
frameVm.SetFrom(this, frame, resolutionWidth, resolutionHeight);
frameVm.PropertyChanged += HandleFrameViewModelPropertyChanged;
VisibleChildren.Add(frameVm);
}
}

public Action FrameUpdatedByUi;

private void HandleFrameViewModelPropertyChanged(object sender, PropertyChangedEventArgs e)
{
var vm = (AnimationFrameViewModel)sender;
var frame = vm.BackingModel;

var changed = vm.ApplyToFrame(frame);

if(changed)
{
FrameUpdatedByUi?.Invoke();
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using FlatRedBall.Content.AnimationChain;
using FlatRedBall.Glue.MVVM;
using FlatRedBall.Math;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
Expand All @@ -19,15 +20,29 @@ public AnimationFrameViewModel()

public AnimationFrameSave BackingModel { get; set; }
public AnimationChainViewModel Parent { get; private set; }

public string StrippedTextureName
{
get => Get<string>();
set => Set(value);
}

public float LengthInSeconds
{
get => Get<float>();
set => Set(value);
}

public string StrippedTextureName

public float XOffset
{
get => Get<string>();
get => Get<float>();
set => Set(value);
}

public float YOffset
{
get => Get<float>();
set => Set(value);
}

Expand Down Expand Up @@ -70,6 +85,42 @@ public bool FlipVertical
set => Set(value);
}

[DependsOn(nameof(LeftCoordinate))]
public float X
{
get => LeftCoordinate;
set
{
var difference = value - LeftCoordinate;

LeftCoordinate += difference;
RightCoordinate += difference;
}
}

[DependsOn(nameof(TopCoordinate))]
public float Y
{
get => TopCoordinate;
set
{
var difference = value - TopCoordinate;

TopCoordinate += difference;
BottomCoordinate += difference;
}
}

[DependsOn(nameof(RightCoordinate))]
[DependsOn(nameof(LeftCoordinate))]
public int Width => MathFunctions.RoundToInt( (RightCoordinate - LeftCoordinate) );

[DependsOn(nameof(BottomCoordinate))]
[DependsOn(nameof(TopCoordinate))]
public int Height => MathFunctions.RoundToInt( (BottomCoordinate - TopCoordinate) );



public ObservableCollection<ShapeViewModel> VisibleChildren
{
get => Get<ObservableCollection<ShapeViewModel>>();
Expand Down Expand Up @@ -127,5 +178,35 @@ public void SetFrom(AnimationChainViewModel parent, AnimationFrameSave animation
VisibleChildren.Add(shape);
}
}

public bool ApplyToFrame(AnimationFrameSave animationFrame)
{
var toReturn = false;
// build this slowly over time:
if(animationFrame.LeftCoordinate != LeftCoordinate)
{
animationFrame.LeftCoordinate = LeftCoordinate;
toReturn = true;
}

if(animationFrame.TopCoordinate != TopCoordinate)
{
animationFrame.TopCoordinate = TopCoordinate;
toReturn = true;
}

if(animationFrame.RightCoordinate != RightCoordinate)
{
animationFrame.RightCoordinate = RightCoordinate;
toReturn = true;
}

if(animationFrame.BottomCoordinate != BottomCoordinate)
{
animationFrame.BottomCoordinate = BottomCoordinate;
toReturn = true;
}
return toReturn;
}
}
}
Loading

0 comments on commit 4c3a466

Please sign in to comment.