Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 26 additions & 15 deletions WadTool/Forms/FormAnimationEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -491,15 +491,15 @@ private void SelectAnimation(AnimationNode node)
if (node != null)
{
tbName.Text = node.WadAnimation.Name;
nudFramerate.Value = node.WadAnimation.FrameRate;
nudEndFrame.Value = node.WadAnimation.EndFrame;
nudNextAnim.Value = node.WadAnimation.NextAnimation;
nudNextFrame.Value = node.WadAnimation.NextFrame;
nudStartVertVel.Value = (decimal)node.WadAnimation.StartVelocity;
nudEndVertVel.Value = (decimal)node.WadAnimation.EndVelocity;
nudStartHorVel.Value = (decimal)node.WadAnimation.StartLateralVelocity;
nudEndHorVel.Value = (decimal)node.WadAnimation.EndLateralVelocity;
nudBlendFrameCount.Value = (decimal)node.WadAnimation.BlendFrameCount;
SetNumericValue(nudFramerate, node.WadAnimation.FrameRate);
SetNumericValue(nudEndFrame, node.WadAnimation.EndFrame);
SetNumericValue(nudNextAnim, node.WadAnimation.NextAnimation);
SetNumericValue(nudNextFrame, node.WadAnimation.NextFrame);
SetNumericValue(nudStartVertVel, (decimal)node.WadAnimation.StartVelocity);
SetNumericValue(nudEndVertVel, (decimal)node.WadAnimation.EndVelocity);
SetNumericValue(nudStartHorVel, (decimal)node.WadAnimation.StartLateralVelocity);
SetNumericValue(nudEndHorVel, (decimal)node.WadAnimation.EndLateralVelocity);
SetNumericValue(nudBlendFrameCount, (decimal)node.WadAnimation.BlendFrameCount);
bezierCurveEditor.Value = node.WadAnimation.BlendCurve;
cbBlendPreset.SelectedIndex = -1;

Expand Down Expand Up @@ -535,6 +535,17 @@ private void SelectAnimation(AnimationNode node)
_editor.Tool.AnimationEditorCurrentAnimationChanged(prevAnim, _editor.CurrentAnim);
}

private static void SetNumericValue(DarkNumericUpDown control, decimal value)
{
if (value < control.Minimum)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blind extension of the minimum value may result in the absurd scenarios such as extending framerate limit or frame count limit to negative values. I believe this approach is wrong.

control.Minimum = value;

if (value > control.Maximum)
control.Maximum = value;

control.Value = value;
}

private void UpdateSelection()
{
_editor.Selection = timeline.Selection;
Expand Down Expand Up @@ -624,7 +635,7 @@ private void OnKeyframesListChanged()
_frameCount = timeline.Value * _editor.CurrentAnim.WadAnimation.FrameRate;
timeline.Minimum = 0;
timeline.Maximum = _editor.CurrentAnim.DirectXAnimation.KeyFrames.Count - 1;
nudEndFrame.Value = _editor.CurrentAnim.WadAnimation.EndFrame;
SetNumericValue(nudEndFrame, _editor.CurrentAnim.WadAnimation.EndFrame);
UpdateStatusLabel();
}
else
Expand Down Expand Up @@ -728,7 +739,7 @@ private void InflateAnimationBoundingBox(Vector3 value)
InflateFrameBoundingBox(i, value, false);
}

public void ResetEndFrame() => nudEndFrame.Value = _editor.GetRealNumberOfFrames() - 1;
public void ResetEndFrame() => SetNumericValue(nudEndFrame, _editor.GetRealNumberOfFrames() - 1);

public void UpdateTransform()
{
Expand Down Expand Up @@ -1288,7 +1299,7 @@ private void UpdateAnimationParameter(Control control)

// Fix visible values
if (control is DarkTextBox) ((DarkTextBox)control).Text = result.ToString();
else if (control is DarkNumericUpDown) ((DarkNumericUpDown)control).Value = (decimal)result;
else if (control is DarkNumericUpDown) SetNumericValue((DarkNumericUpDown)control, (decimal)result);

// Don't update if not changed
if (oldValue == result)
Expand All @@ -1310,8 +1321,8 @@ private void UpdateAnimationParameter(Control control)
_editor.CurrentAnim.WadAnimation.NextFrame = (ushort)result;
break;
case nameof(nudFramerate):
nudEndFrame.Value = (decimal)Math.Round(_editor.CurrentAnim.WadAnimation.EndFrame /
(_editor.CurrentAnim.WadAnimation.FrameRate / (float)result));
SetNumericValue(nudEndFrame, (decimal)Math.Round(_editor.CurrentAnim.WadAnimation.EndFrame /
(_editor.CurrentAnim.WadAnimation.FrameRate / (float)result)));
_editor.CurrentAnim.WadAnimation.FrameRate = (byte)result;
break;
case nameof(nudEndFrame):
Expand Down Expand Up @@ -2865,4 +2876,4 @@ private void cbBlendPreset_SelectedIndexChanged(object sender, EventArgs e)
bezierCurveEditor.UpdateUI();
}
}
}
}