Skip to content

Commit 2a7e0c2

Browse files
committed
finish animation on editor
1 parent 6cf2b2e commit 2a7e0c2

File tree

3 files changed

+43
-19
lines changed

3 files changed

+43
-19
lines changed

Intersect.Editor/Core/Graphics.cs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1469,7 +1469,33 @@ bool alternate
14691469
break;
14701470

14711471
case ResourceGraphicType.Animation:
1472-
//TODO: FIX THIS
1472+
{
1473+
if (!AnimationDescriptor.TryGet(resourceGraphic.AnimationId, out var animation))
1474+
{
1475+
continue;
1476+
}
1477+
1478+
float xpos = x * Options.Instance.Map.TileWidth + xoffset + Options.Instance.Map.TileWidth / 2;
1479+
float ypos = y * Options.Instance.Map.TileHeight + yoffset + Options.Instance.Map.TileHeight / 2;
1480+
1481+
var animationInstance = tmpMap.GetAttributeAnimation(tmpMap.Attributes[x, y], animation.Id);
1482+
1483+
//Update if the animation isn't right!
1484+
if (animationInstance == null || animationInstance.Descriptor != animation)
1485+
{
1486+
tmpMap.SetAttributeAnimation(
1487+
tmpMap.Attributes[x, y], new Animation(animation, true)
1488+
);
1489+
}
1490+
1491+
if (animationInstance != null)
1492+
{
1493+
animationInstance.Update();
1494+
animationInstance.SetPosition((int)xpos, (int)ypos, 0);
1495+
animationInstance.Draw(renderTarget, false, alternate);
1496+
animationInstance.Draw(renderTarget, true, alternate);
1497+
}
1498+
}
14731499
break;
14741500

14751501
default:

Intersect.Editor/Forms/Editors/frmResource.Designer.cs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Intersect.Editor/Forms/Editors/frmResource.cs

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -387,32 +387,20 @@ private void UpdateHealthStateControls()
387387
UpdateGraphicFileControl(currentState);
388388
}
389389

390-
private void UpdateCurrentState(object sender, EventArgs e)
391-
{
392-
if (_editorItem is null)
393-
{
394-
return;
395-
}
396-
397-
if (!TryGetCurrentHealthState(out var currentState))
398-
{
399-
return;
400-
}
401-
402-
currentState.GraphicType = (ResourceGraphicType)cmbGraphicType.SelectedIndex;
403-
currentState.AnimationId = AnimationDescriptor.IdFromList(cmbAnimation.SelectedIndex - 1);
404-
}
405-
406390
private void UpdateGraphicFileControl(ResourceStateDescriptor currentState)
407391
{
408392
cmbGraphicFile.Items.Clear();
409393
cmbGraphicFile.Items.Add(Strings.General.None);
394+
cmbAnimation.Items.Clear();
395+
cmbAnimation.Items.Add(Strings.General.None);
410396

411397
if (currentState.GraphicType == ResourceGraphicType.Animation)
412398
{
413399
cmbGraphicFile.Enabled = false;
414400
picResource.Visible = false;
415401
cmbAnimation.Enabled = true;
402+
cmbAnimation.Items.AddRange(AnimationDescriptor.Names);
403+
cmbAnimation.SelectedIndex = AnimationDescriptor.ListIndex(currentState.AnimationId) + 1;
416404
return;
417405
}
418406

@@ -868,7 +856,7 @@ private void cmbGraphicType_SelectedIndexChanged(object sender, EventArgs e)
868856
return;
869857
}
870858

871-
UpdateCurrentState(sender, e);
859+
currentState.GraphicType = (ResourceGraphicType)cmbGraphicType.SelectedIndex;
872860
UpdateGraphicFileControl(currentState);
873861
}
874862

@@ -915,6 +903,16 @@ private void cmbGraphicFile_SelectedIndexChanged(object sender, EventArgs e)
915903
picResource.Visible = _resourceGraphic != null;
916904
}
917905

906+
private void cmbAnimation_SelectedIndexChanged(object sender, EventArgs e)
907+
{
908+
if (!TryGetCurrentHealthState(out var currentState))
909+
{
910+
return;
911+
}
912+
913+
currentState.AnimationId = AnimationDescriptor.IdFromList(cmbAnimation.SelectedIndex - 1);
914+
}
915+
918916
private void nudHealthRangeMin_ValueChanged(object sender, EventArgs e)
919917
{
920918
if (!TryGetCurrentHealthState(out var currentState))

0 commit comments

Comments
 (0)