Skip to content

Commit

Permalink
Small improvments on functionality and readability on dupe function; …
Browse files Browse the repository at this point in the history
…better animation rendering with frame's speed support.
  • Loading branch information
Xeeynamo committed Nov 20, 2017
1 parent 282004e commit 26bdaf7
Show file tree
Hide file tree
Showing 10 changed files with 105 additions and 63 deletions.
5 changes: 4 additions & 1 deletion AnimationEditor/AboutWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:AnimationEditor"
mc:Ignorable="d"
Title="About" Height="128" Width="288" WindowStyle="ToolWindow">
Title="About" Height="164" Width="288" WindowStyle="ToolWindow">
<StackPanel Orientation="Horizontal" Margin="10">
<Image Width="48" Source="MainIcon.ico" VerticalAlignment="Top" Margin="0 0 10 0">

Expand All @@ -22,6 +22,9 @@
https://github.com/xeeynamo/rsdk
</Hyperlink>
</TextBlock>
<Separator/>
<TextBlock Text="Additional fixes by:"/>
<TextBlock Text="thesupersonic16"/>
</StackPanel>
</StackPanel>
</Window>
21 changes: 15 additions & 6 deletions AnimationEditor/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:AnimationEditor"
mc:Ignorable="d"
Title="{Binding Title}" Height="416.565" Width="660.991">
Title="{Binding Title}" Height="444" Width="660">
<DockPanel>
<Menu DockPanel.Dock="Top">
<MenuItem Header="_File">
Expand Down Expand Up @@ -62,17 +62,26 @@
IsEnabled="{Binding IsAnimationSelected}">
<DockPanel DockPanel.Dock="Bottom">
<StackPanel DockPanel.Dock="Right" VerticalAlignment="Bottom">
<Button x:Name="ButtonFrameDupe" Grid.Column="1" Margin="0 0 0 5" Click="ButtonFrameDupe_Click"
IsEnabled="{Binding IsAnimationSelected}">
<Image Source="{StaticResource Document_16x}" Width="16"/>
</Button>
<Button x:Name="ButtonFrameAdd" Grid.Column="1" Margin="0 0 0 5" Click="ButtonFrameAdd_Click"
<Button x:Name="ButtonFrameAdd" Grid.Column="1" Margin="0 0 0 2" Click="ButtonFrameAdd_Click"
IsEnabled="{Binding IsAnimationSelected}">
<Image Source="{StaticResource Add_16x}" Width="16"/>
<Button.ToolTip>
<Label Content="Create an empty frame"/>
</Button.ToolTip>
</Button>
<Button x:Name="ButtonFrameDupe" Grid.Column="1" Margin="0 0 0 2" Click="ButtonFrameDupe_Click"
IsEnabled="{Binding IsFrameSelected}">
<Image Source="{StaticResource Copy_16x}" Width="16"/>
<Button.ToolTip>
<Label Content="Duplicate selected frame"/>
</Button.ToolTip>
</Button>
<Button x:Name="ButtonFrameRemove" Grid.Column="1" Click="ButtonFrameRemove_Click"
IsEnabled="{Binding IsFrameSelected}">
<Image Source="{StaticResource Remove_color_16x}" Width="16"/>
<Button.ToolTip>
<Label Content="Delete the selected frame"/>
</Button.ToolTip>
</Button>
</StackPanel>
<ListBox x:Name="FramesList" ScrollViewer.HorizontalScrollBarVisibility="Visible"
Expand Down
4 changes: 2 additions & 2 deletions AnimationEditor/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.1.0.0")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: AssemblyVersion("1.2.0.0")]
[assembly: AssemblyFileVersion("1.2.0.0")]
17 changes: 15 additions & 2 deletions AnimationEditor/Services/AnimationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,26 @@ private void Timer_Elapsed(object sender, ElapsedEventArgs e)
var curAnim = CurrentAnimation;
if (curAnim == null) return;
if (IsRunning == false) return;
if (FramesPerSecond <= 0) return;
if ((CurrentAnimation?.Speed ?? 0) <= 0) return;

int framesCount = curAnim.GetFrames().Count();
int loop = curAnim.Loop;
if (framesCount <= 0) return;

double freq = 1.0 / (CurrentAnimation.Speed / 4);
var currentFrame = curAnim.GetFrames()
.Skip(FrameIndex)
.FirstOrDefault();
int frameSpeed;
if (currentFrame is RSDK5.Frame current5Frame)
{
frameSpeed = current5Frame.Duration;
}
else
{
frameSpeed = 256;
}

double freq = 1.0 / ((double)CurrentAnimation.Speed / frameSpeed * 64.0);
double timer = Stopwatch.ElapsedMilliseconds;
var index = (int)Math.Floor(timer / (freq * 1000.0));
if (index >= 0)
Expand Down
2 changes: 1 addition & 1 deletion AnimationEditor/TextureWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public partial class TextureWindow : Window
public string BasePath { get; private set; }

public TextureWindowViewModel ViewModel => DataContext as TextureWindowViewModel;
public MainViewModel MainViewModel {get; set;}
public MainViewModel MainViewModel { get; }

public int SelectedIndex
{
Expand Down
91 changes: 51 additions & 40 deletions AnimationEditor/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -340,28 +340,29 @@ public int SelectedFramePivotY
}
}

public ushort SelectedFrameID
public ushort SelectedFrameId
{
get => (SelectedFrame as RSDK5.Frame)?.ID ?? 0;
get => (SelectedFrame as RSDK5.Frame)?.Id ?? 0;
set
{
if (SelectedFrame is RSDK5.Frame frame)
frame.ID = value;
InvalidateCanvas();
{
frame.Id = value;
InvalidateCanvas();
}
}
}

public int SelectedFrameDuration
{
get
{
return (SelectedFrame as RSDK5.Frame)?.Duration ?? 0;
}
get => (SelectedFrame as RSDK5.Frame)?.Duration ?? 0;
set
{
if (SelectedFrame is RSDK5.Frame frame)
{
frame.Duration = value;
InvalidateCanvas();
InvalidateCanvas();
}
}
}

Expand Down Expand Up @@ -454,7 +455,7 @@ public void InvalidateFrameProperties()
OnPropertyChanged(nameof(SelectedFrameHeight));
OnPropertyChanged(nameof(SelectedFramePivotX));
OnPropertyChanged(nameof(SelectedFramePivotY));
OnPropertyChanged(nameof(SelectedFrameID));
OnPropertyChanged(nameof(SelectedFrameId));
OnPropertyChanged(nameof(SelectedFrameDuration));
OnPropertyChanged(nameof(SelectedHitbox));
}
Expand Down Expand Up @@ -523,44 +524,54 @@ public void AnimationRemove()
}
public void FrameAdd()
{
_animationData.Factory(out IFrame o);
AnimationFrames.Add(new FrameViewModel(_spriteService, o));
var frames = SelectedAnimation.GetFrames().ToList();
frames.Add(o);
SelectedAnimation.SetFrames(frames);
_animationData.Factory(out IFrame frame);
FrameAdd(frame);
}
public void FrameAdd(IFrame frame, int? insertOnIndex = null)
{
var frameVm = new FrameViewModel(_spriteService, frame);
var list = SelectedAnimation.GetFrames().ToList();
if (!insertOnIndex.HasValue)
{
AnimationFrames.Add(frameVm);
list.Add(frame);
}
else
{
AnimationFrames.Insert(insertOnIndex.Value, frameVm);
list.Insert(insertOnIndex.Value, frame);
}
SelectedAnimation.SetFrames(list);
}

public void DupeFrame()
{
if (SelectedAnimation is RSDK5.AnimationEntry selectedAni)
{
var currentFrame = SelectedFrame as RSDK5.Frame;
var newFrame = new RSDK5.Frame(currentFrame.Hitboxes.Length);

// Copying all the Infomation
newFrame.Duration = currentFrame.Duration;
newFrame.X = currentFrame.X;
newFrame.Y = currentFrame.Y;
newFrame.Width = currentFrame.Width;
newFrame.Height = currentFrame.Height;
newFrame.CollisionBox = currentFrame.CollisionBox;
newFrame.SpriteSheet = currentFrame.SpriteSheet;
newFrame.CenterX = currentFrame.CenterX;
newFrame.CenterY = currentFrame.CenterY;

// HitBoxes
newFrame.Hitboxes = new RSDK5.Hitbox[currentFrame.Hitboxes.Length];
for (int i = 0; i < currentFrame.Hitboxes.Length; ++i)
var selectedFrame = SelectedFrame;

_animationData.Factory(out IFrame newFrame);
newFrame.X = selectedFrame.X;
newFrame.Y = selectedFrame.Y;
newFrame.Width = selectedFrame.Width;
newFrame.Height = selectedFrame.Height;
newFrame.CollisionBox = selectedFrame.CollisionBox;
newFrame.SpriteSheet = selectedFrame.SpriteSheet;
newFrame.CenterX = selectedFrame.CenterX;
newFrame.CenterY = selectedFrame.CenterY;

if (newFrame is RSDK5.Frame new5Frame &&
selectedFrame is RSDK5.Frame selected5Frame)
{
new5Frame.Duration = selected5Frame.Duration;

// Duplicates hitboxes too.
new5Frame.Hitboxes = new RSDK5.Hitbox[selected5Frame.Hitboxes?.Length ?? 0];
for (int i = 0; i < new5Frame.Hitboxes.Length; i++)
{
var hitBox = new RSDK5.Hitbox();
newFrame.Hitboxes[i] = hitBox;
new5Frame.Hitboxes[i] = hitBox;
}

// Adds the frame to the Animation
AnimationFrames.Insert(SelectedFrameIndex, new FrameViewModel(_spriteService, newFrame));
selectedAni.Frames.Insert(SelectedFrameIndex, newFrame);
--SelectedFrameIndex;
}
FrameAdd(newFrame, SelectedFrameIndex);
}

public void FrameRemove()
Expand Down
4 changes: 2 additions & 2 deletions RSDK5/Animation.AnimationEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public AnimationEntry(BinaryReader reader, int collisionBoxesCount)
SpriteSheet = reader.ReadByte(),
CollisionBox = 0,
Duration = reader.ReadInt16(), // Make sure this is correct
ID = reader.ReadUInt16(),
Id = reader.ReadUInt16(),
X = reader.ReadInt16(),
Y = reader.ReadInt16(),
Width = reader.ReadInt16(),
Expand Down Expand Up @@ -98,7 +98,7 @@ public void SaveChanges(BinaryWriter writer)
{
writer.Write((byte)entry.SpriteSheet);
writer.Write((short)entry.Duration); // Make sure this is correct
writer.Write((ushort)entry.ID);
writer.Write((ushort)entry.Id);
writer.Write((short)entry.X);
writer.Write((short)entry.Y);
writer.Write((short)entry.Width);
Expand Down
4 changes: 2 additions & 2 deletions RSDK5/Animation.Frame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class Frame : IFrame

public int Duration { get; set; } // Make sure this is correct

public ushort ID { get; set; }
public ushort Id { get; set; }

public int X { get; set; }

Expand Down Expand Up @@ -61,7 +61,7 @@ public Frame(int hitboxesCount = 0)
// TODO
public IHitbox GetHitbox(int index)
{
if (Hitboxes.Length > 0 && index < Hitboxes.Length)
if (Hitboxes.Length >= 0 && index < Hitboxes.Length)
return Hitboxes[index];
else
return null;
Expand Down
8 changes: 1 addition & 7 deletions RSDK5/Animation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,8 @@ public void SaveChanges(BinaryWriter writer)
{
writer.Write(MagicCode);

TotalFramesCount = 0;
var animationsCount = (ushort)Math.Min(Animations.Count, ushort.MaxValue);
for (int i = 0; i < animationsCount; i++)
{
TotalFramesCount += Animations[i].Frames.Count;
}

TotalFramesCount = Animations.Take(animationsCount).Sum(x => x.Frames.Count);
writer.Write(TotalFramesCount);

var spriteSheetsCount = (byte)Math.Min(SpriteSheets.Count, byte.MaxValue);
Expand All @@ -122,7 +117,6 @@ public void SaveChanges(BinaryWriter writer)
writer.Write(StringEncoding.GetBytes(item));
}

animationsCount = (ushort)Math.Min(Animations.Count, ushort.MaxValue);
writer.Write(animationsCount);
for (int i = 0; i < animationsCount; i++)
{
Expand Down
12 changes: 12 additions & 0 deletions Xe.Tools.Wpf/Icons/VisualStudioIcons.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,18 @@
</DrawingGroup>
</DrawingImage.Drawing>
</DrawingImage>
<DrawingImage x:Key="Copy_16x">
<DrawingImage.Drawing>
<DrawingGroup>
<DrawingGroup.Children>
<GeometryDrawing Brush="#00FFFFFF" Geometry="F1M16,16L0,16 0,0 16,0z" />
<GeometryDrawing Brush="#FFF6F6F6" Geometry="F1M5.0004,-0.000199999999999534L5.0004,4.0008 0.9994,4.0008 0.9994,15.9998 10.9994,15.9998 10.9994,12.0008 15.0004,12.0008 15.0004,-0.000199999999999534z" />
<GeometryDrawing Brush="#FF424242" Geometry="F1M9,6L3,6 3,14 9,14z M10,15L2,15 2,5 10,5z M11,11L11,10 13,10 13,2 7,2 7,4 6,4 6,1 14,1 14,11z" />
<GeometryDrawing Brush="#FFF0EFF1" Geometry="F1M7,2L7,4 11,4 11,10 13,10 13,2z M9,14L3,14 3,6 9,6z" />
</DrawingGroup.Children>
</DrawingGroup>
</DrawingImage.Drawing>
</DrawingImage>
<DrawingImage x:Key="Document_16x">
<DrawingImage.Drawing>
<DrawingGroup>
Expand Down

0 comments on commit 26bdaf7

Please sign in to comment.