1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-11-28 15:28:34 +01:00

Compare commits

..

No commits in common. "fa60b5e8b1fed4dc7d0f23632e3df5bd339d6a6a" and "fa1cafd751ee481b45adafda99f0d6195d5bfd99" have entirely different histories.

3 changed files with 17 additions and 42 deletions

View file

@ -19,15 +19,11 @@ Jump to version:
Additions
- **Added the ability for formatted (tokenized) strings to be drawn with custom rotation, origin and flipping**
- Added a RectangleF.FromCorners overload that accepts points
- Added indexers and Count to SpriteAnimation and SpriteAnimationGroup
Improvements
- Allow NumberExtensions.GetPoints to include bottom and right coordinates
- Allow AutoTiling overlayTextures to return null texture regions
Removals
- Marked SpriteAnimation.ByName obsolete in favor of the new indexer
### MLEM.Ui
Additions
- Added the ability to set the anchor that should be used when a tooltip attaches to an element or the mouse

View file

@ -14,10 +14,6 @@ namespace MLEM.Animations {
private readonly AnimationFrame[] frames;
/// <summary>
/// Returns the amount of <see cref="AnimationFrame"/> entries that this sprite animation has.
/// </summary>
public int Count => this.frames.Length;
/// <summary>
/// Returns the <see cref="AnimationFrame"/> at the given index.
/// Index ordering is based on the order that animation frames were added in.
/// </summary>
@ -30,16 +26,15 @@ namespace MLEM.Animations {
get {
// we might have overshot the end time by a little bit, so just return the last frame
if (this.TimeIntoAnimation >= this.TotalTime)
return this[this.Count - 1];
return this.frames[this.frames.Length - 1];
var accum = 0D;
for (var i = 0; i < this.Count; i++) {
var frame = this[i];
foreach (var frame in this.frames) {
accum += frame.Seconds;
if (accum >= this.TimeIntoAnimation)
return frame;
}
// if we're here then the time is negative for some reason, so just return the first frame
return this[0];
return this.frames[0];
}
}
/// <summary>

View file

@ -35,27 +35,13 @@ namespace MLEM.Animations {
/// <inheritdoc cref="SpriteAnimation.SpeedMultiplier"/>
public float SpeedMultiplier {
set {
for (var i = 0; i < this.Count; i++)
this[i].SpeedMultiplier = value;
foreach (var anim in this.animations)
anim.Animation.SpeedMultiplier = value;
}
}
/// <summary>
/// Returns the amount of <see cref="SpriteAnimation"/> entries that this sprite animation group has.
/// </summary>
public int Count => this.animations.Count;
/// <summary>
/// Returns the <see cref="SpriteAnimation"/> at the given index.
/// </summary>
/// <param name="index">The index.</param>
public SpriteAnimation this[int index] => this.animations[index].Animation;
/// <summary>
/// Returns the <see cref="SpriteAnimation"/> in this animation group with the given <see cref="SpriteAnimation.Name"/>, if it exists, and <see langword="null"/> otherwise.
/// </summary>
/// <param name="name">The name of the animation.</param>
public SpriteAnimation this[string name] => this.animations.Find(anim => anim.Animation.Name == name)?.Animation;
/// <summary>
/// A callback for when the currently displaying animation has changed due to a condition with a higher priority being met.
/// A callback for when the currently displaying animation has changed due to a condition with a higher priority being met.
/// </summary>
public event AnimationChanged OnAnimationChanged;
@ -93,9 +79,8 @@ namespace MLEM.Animations {
/// </summary>
/// <param name="name">The <see cref="SpriteAnimation.Name"/> of the animation</param>
/// <returns>The animation by that name, or <c>null</c> if there is none</returns>
[Obsolete("Use the name-based indexer instead")]
public SpriteAnimation ByName(string name) {
return this[name];
return this.animations.Find(anim => anim.Animation.Name == name)?.Animation;
}
private void FindAnimationToPlay() {
@ -105,8 +90,7 @@ namespace MLEM.Animations {
if (this.currentAnimation != null && this.currentAnimation.ShouldPlay())
animToPlay = this.currentAnimation;
for (var i = 0; i < this.Count; i++) {
var anim = this.animations[i];
foreach (var anim in this.animations) {
// if we find an animation with a lower priority then it means we can break since the list is sorted by priority
if (animToPlay != null && anim.Priority <= animToPlay.Priority)
break;
@ -138,18 +122,18 @@ namespace MLEM.Animations {
/// <param name="newAnim">The new animation</param>
public delegate void AnimationChanged(SpriteAnimation oldAnim, SpriteAnimation newAnim);
private class ConditionedAnimation {
}
public readonly SpriteAnimation Animation;
public readonly Func<bool> ShouldPlay;
public readonly int Priority;
internal class ConditionedAnimation {
public ConditionedAnimation(SpriteAnimation animation, Func<bool> shouldPlay, int priority) {
this.Animation = animation;
this.ShouldPlay = shouldPlay;
this.Priority = priority;
}
public readonly SpriteAnimation Animation;
public readonly Func<bool> ShouldPlay;
public readonly int Priority;
public ConditionedAnimation(SpriteAnimation animation, Func<bool> shouldPlay, int priority) {
this.Animation = animation;
this.ShouldPlay = shouldPlay;
this.Priority = priority;
}
}