Add support for negative frames on timeline
This commit is contained in:
parent
60e09b8511
commit
b2baf9b449
@ -26,8 +26,8 @@ namespace LayoutBXLYT
|
||||
|
||||
private void ReloadAnimation()
|
||||
{
|
||||
FrameCount = (uint)BxlanAnimation.AnimationInfo.FrameSize;
|
||||
StartFrame = (uint)BxlanAnimation.AnimationTag.StartFrame;
|
||||
FrameCount = BxlanAnimation.AnimationTag.EndFrame;
|
||||
StartFrame = BxlanAnimation.AnimationTag.StartFrame;
|
||||
|
||||
Textures.Clear();
|
||||
AnimGroups.Clear();
|
||||
|
@ -1869,6 +1869,8 @@ namespace LayoutBXLYT.Cafe
|
||||
|
||||
public BasePane Property { get; set; }
|
||||
|
||||
public USD1 UserData { get; set; }
|
||||
|
||||
public byte[] PaneInfo { get; set; }
|
||||
|
||||
public PartProperty(FileReader reader, Header header, long StartPosition)
|
||||
@ -1919,7 +1921,7 @@ namespace LayoutBXLYT.Cafe
|
||||
if (userDataOffset != 0)
|
||||
{
|
||||
reader.SeekBegin(StartPosition + userDataOffset);
|
||||
|
||||
UserData = new USD1(reader, header);
|
||||
}
|
||||
if (panelInfoOffset != 0)
|
||||
{
|
||||
@ -1956,7 +1958,11 @@ namespace LayoutBXLYT.Cafe
|
||||
|
||||
public void WriteUserData(FileWriter writer, LayoutHeader header, long startPos)
|
||||
{
|
||||
|
||||
if (UserData != null)
|
||||
{
|
||||
writer.WriteUint32Offset(_ofsPos + 4, startPos);
|
||||
UserData.Write(writer, header);
|
||||
}
|
||||
}
|
||||
|
||||
public void WritePaneInfo(FileWriter writer, LayoutHeader header, long startPos)
|
||||
|
@ -1579,8 +1579,8 @@ namespace LayoutBXLYT
|
||||
{
|
||||
if (animation == null)
|
||||
animation = new LytAnimation(this, parentLayout);
|
||||
else
|
||||
animation.UpdateLayout(parentLayout);
|
||||
|
||||
animation.UpdateLayout(parentLayout);
|
||||
return animation;
|
||||
}
|
||||
}
|
||||
|
@ -100,6 +100,21 @@ namespace Toolbox.Library
|
||||
}
|
||||
}
|
||||
|
||||
public float StartFrame
|
||||
{
|
||||
get
|
||||
{
|
||||
float startFrame = float.MaxValue;
|
||||
for (int i = 0; i < currentAnimations.Count; i++)
|
||||
startFrame = Math.Min(startFrame, currentAnimations[i].StartFrame);
|
||||
|
||||
if (startFrame == float.MaxValue)
|
||||
startFrame = 0;
|
||||
|
||||
return startFrame;
|
||||
}
|
||||
}
|
||||
|
||||
private List<STAnimation> currentAnimations = new List<STAnimation>();
|
||||
|
||||
public void AddAnimation(STAnimation animation, bool reset = true)
|
||||
@ -110,8 +125,6 @@ namespace Toolbox.Library
|
||||
if (reset)
|
||||
Reset();
|
||||
|
||||
Console.WriteLine($"Add anim " + animation.Name);
|
||||
|
||||
currentAnimations.Add(animation);
|
||||
|
||||
ResetModels();
|
||||
@ -119,9 +132,11 @@ namespace Toolbox.Library
|
||||
totalFrame.Maximum = (decimal)FrameCount;
|
||||
totalFrame.Value = (decimal)FrameCount;
|
||||
currentFrameUpDown.Maximum = (decimal)FrameCount;
|
||||
animationTrackBar.ActiveAnimation = animation;
|
||||
currentFrameUpDown.Minimum = (decimal)StartFrame;
|
||||
animationTrackBar.FrameCount = (float)FrameCount;
|
||||
currentFrameUpDown.Value = 0;
|
||||
animationTrackBar.StartTime = (int)StartFrame;
|
||||
animationTrackBar.ActiveAnimation = animation;
|
||||
currentFrameUpDown.Value = (decimal)StartFrame;
|
||||
|
||||
SetAnimationsToFrame(0);
|
||||
UpdateViewport();
|
||||
@ -209,7 +224,7 @@ namespace Toolbox.Library
|
||||
|
||||
private void Stop()
|
||||
{
|
||||
currentFrameUpDown.Value = 0;
|
||||
currentFrameUpDown.Value = (decimal)StartFrame;
|
||||
AnimationPlayerState = AnimPlayerState.Stop;
|
||||
UpdateAnimationUI();
|
||||
animationTimer.Stop();
|
||||
@ -254,7 +269,7 @@ namespace Toolbox.Library
|
||||
if (animationTrackBar.CurrentFrame == animationTrackBar.FrameCount - 1)
|
||||
{
|
||||
if (IsLooping)
|
||||
currentFrameUpDown.Value = 0;
|
||||
currentFrameUpDown.Value = (decimal)StartFrame;
|
||||
else
|
||||
Stop();
|
||||
}
|
||||
@ -270,7 +285,7 @@ namespace Toolbox.Library
|
||||
|
||||
private void animationPlayBtn_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (currentAnimations.Count == 0 || FrameCount <= 0)
|
||||
if (currentAnimations.Count == 0 || FrameCount <= StartFrame)
|
||||
return;
|
||||
|
||||
if (AnimationPlayerState == AnimPlayerState.Playing)
|
||||
@ -283,13 +298,13 @@ namespace Toolbox.Library
|
||||
{
|
||||
if (currentAnimations.Count == 0) return;
|
||||
|
||||
if (totalFrame.Value < 1)
|
||||
if (totalFrame.Value < (decimal)StartFrame + 1)
|
||||
{
|
||||
totalFrame.Value = 1;
|
||||
totalFrame.Value = (decimal)StartFrame + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
animationTrackBar.CurrentFrame = 0;
|
||||
animationTrackBar.CurrentFrame = StartFrame;
|
||||
animationTrackBar.FrameCount = FrameCount;
|
||||
}
|
||||
}
|
||||
@ -323,7 +338,7 @@ namespace Toolbox.Library
|
||||
}
|
||||
|
||||
private void animationTrackBar_ValueChanged(object sender, EventArgs e) {
|
||||
if (currentAnimations.Count == 0 || totalFrame.Value <= 0)
|
||||
if (currentAnimations.Count == 0 || totalFrame.Value <= (decimal)StartFrame)
|
||||
return;
|
||||
|
||||
currentFrameUpDown.Value = (decimal)animationTrackBar.CurrentFrame;
|
||||
@ -365,7 +380,7 @@ namespace Toolbox.Library
|
||||
//Reset it when it reaches the total frame count
|
||||
if (anim.Frame >= anim.FrameCount && anim.Loop)
|
||||
{
|
||||
anim.Frame = 0;
|
||||
anim.Frame = anim.StartFrame;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -24,6 +24,12 @@ namespace Toolbox.Library.Forms
|
||||
|
||||
protected int margin = 0;
|
||||
|
||||
private int startTime = 0;
|
||||
public int StartTime
|
||||
{
|
||||
set { startTime = value; }
|
||||
}
|
||||
|
||||
public event EventHandler FrameChanged;
|
||||
|
||||
private Timer timer = new Timer();
|
||||
@ -32,10 +38,10 @@ namespace Toolbox.Library.Forms
|
||||
|
||||
private void ResolveCollision()
|
||||
{
|
||||
if (frameLeft < 0)
|
||||
if (frameLeft < startTime)
|
||||
{
|
||||
frameRight -= frameLeft;
|
||||
frameLeft = 0;
|
||||
frameRight += startTime - frameLeft;
|
||||
frameLeft = startTime;
|
||||
}
|
||||
else if (frameRight > lastFrame)
|
||||
{
|
||||
@ -46,18 +52,18 @@ namespace Toolbox.Library.Forms
|
||||
|
||||
private void ResolveFitting()
|
||||
{
|
||||
if (frameLeft < 0)
|
||||
if (frameLeft < startTime)
|
||||
{
|
||||
frameRight -= frameLeft;
|
||||
frameRight += startTime - frameLeft;
|
||||
if (frameRight > lastFrame)
|
||||
frameRight = lastFrame;
|
||||
frameLeft = 0;
|
||||
frameLeft = startTime;
|
||||
}
|
||||
else if (frameRight > lastFrame)
|
||||
{
|
||||
frameLeft += lastFrame - frameRight;
|
||||
if (frameLeft < 0)
|
||||
frameLeft = 0;
|
||||
if (frameLeft < startTime)
|
||||
frameLeft = startTime;
|
||||
frameRight = lastFrame;
|
||||
}
|
||||
}
|
||||
@ -90,7 +96,7 @@ namespace Toolbox.Library.Forms
|
||||
|
||||
if (value == 1)
|
||||
{
|
||||
frameLeft = 0;
|
||||
frameLeft = startTime;
|
||||
frameRight = 1;
|
||||
}
|
||||
else
|
||||
@ -150,7 +156,7 @@ namespace Toolbox.Library.Forms
|
||||
step = Math.Round(Math.Max(1, step));
|
||||
}
|
||||
|
||||
if (lastFrame != 0)
|
||||
if (lastFrame != startTime)
|
||||
{
|
||||
double max;
|
||||
if (frameRight < lastFrame)
|
||||
@ -215,10 +221,10 @@ namespace Toolbox.Library.Forms
|
||||
frameRight -= step;
|
||||
|
||||
#region resolve collsions
|
||||
if (frameLeft < 0)
|
||||
if (frameLeft < startTime)
|
||||
{
|
||||
frameRight -= frameLeft;
|
||||
frameLeft = 0;
|
||||
frameLeft = startTime;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
@ -237,7 +243,7 @@ namespace Toolbox.Library.Forms
|
||||
#endregion
|
||||
}
|
||||
|
||||
currentFrame = Math.Min(Math.Max(0, (int)Math.Round(((lastMousePos.X - 20 - margin) * (frameRight - frameLeft) / (Width - 40 - margin) + frameLeft))), lastFrame);
|
||||
currentFrame = Math.Min(Math.Max(startTime, (int)Math.Round(((lastMousePos.X - 20 - margin) * (frameRight - frameLeft) / (Width - 40 - margin) + frameLeft))), lastFrame);
|
||||
FrameChanged?.Invoke(this, new EventArgs());
|
||||
Refresh();
|
||||
}
|
||||
@ -245,7 +251,7 @@ namespace Toolbox.Library.Forms
|
||||
protected override void OnMouseMove(MouseEventArgs e)
|
||||
{
|
||||
base.OnMouseMove(e);
|
||||
if (lastFrame == 0)
|
||||
if (lastFrame == startTime)
|
||||
return;
|
||||
|
||||
if (e.Button == MouseButtons.Left)
|
||||
@ -253,7 +259,7 @@ namespace Toolbox.Library.Forms
|
||||
|
||||
timer.Enabled = (e.X < 20 + margin || e.X > Width - 20);
|
||||
Locked = true;
|
||||
currentFrame = Math.Min(Math.Max(0, (int)Math.Round(((e.X - 20 - margin) * (frameRight - frameLeft) / (Width - 40 - margin) + frameLeft))), lastFrame);
|
||||
currentFrame = Math.Min(Math.Max(startTime, (int)Math.Round(((e.X - 20 - margin) * (frameRight - frameLeft) / (Width - 40 - margin) + frameLeft))), lastFrame);
|
||||
FrameChanged?.Invoke(this, new EventArgs());
|
||||
Refresh();
|
||||
}
|
||||
@ -281,7 +287,7 @@ namespace Toolbox.Library.Forms
|
||||
protected override void OnMouseWheel(MouseEventArgs e)
|
||||
{
|
||||
base.OnMouseWheel(e);
|
||||
if (lastFrame == 0)
|
||||
if (lastFrame == startTime)
|
||||
return;
|
||||
|
||||
if (frameRight - frameLeft <= 2 && e.Delta > 0)
|
||||
@ -289,7 +295,7 @@ namespace Toolbox.Library.Forms
|
||||
|
||||
double delta = 1 + Math.Min(Math.Max(-0.5, -e.Delta * 0.00390625), 0.5);
|
||||
|
||||
double frameOrigin = Math.Min(Math.Max(0, ((e.X - 20 - margin) * (frameRight - frameLeft) / (Width - 40 - margin) + frameLeft)), lastFrame);
|
||||
double frameOrigin = Math.Min(Math.Max(startTime, ((e.X - 20 - margin) * (frameRight - frameLeft) / (Width - 40 - margin) + frameLeft)), lastFrame);
|
||||
|
||||
frameLeft = Math.Min(-1, (frameLeft - frameOrigin)) * delta + frameOrigin;
|
||||
frameRight = Math.Max(1, (frameRight - frameOrigin)) * delta + frameOrigin;
|
||||
|
Loading…
Reference in New Issue
Block a user