(f0d812055) v0.9.9.0
This commit is contained in:
@@ -2,12 +2,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Xml.Linq;
|
||||
using SpriteParams = Barotrauma.RagdollParams.SpriteParams;
|
||||
|
||||
namespace Barotrauma
|
||||
{
|
||||
class DecorativeSprite : ISerializableEntity
|
||||
{
|
||||
public class State
|
||||
{
|
||||
public float RotationState;
|
||||
public float OffsetState;
|
||||
public bool IsActive = true;
|
||||
}
|
||||
|
||||
public string Name => $"Decorative Sprite";
|
||||
public Dictionary<string, SerializableProperty> SerializableProperties { get; set; }
|
||||
|
||||
@@ -57,6 +63,14 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
private float scale;
|
||||
[Serialize(1.0f, true), Editable]
|
||||
public float Scale
|
||||
{
|
||||
get { return scale; }
|
||||
private set { scale = MathHelper.Clamp(value, 0.0f, 10.0f); }
|
||||
}
|
||||
|
||||
[Serialize(AnimationType.None, false), Editable]
|
||||
public AnimationType RotationAnim { get; private set; }
|
||||
|
||||
@@ -66,6 +80,9 @@ namespace Barotrauma
|
||||
[Serialize(0, false, description: "If > 0, only one sprite of the same group is used (chosen randomly)"), Editable(ReadOnly = true)]
|
||||
public int RandomGroupID { get; private set; }
|
||||
|
||||
[Serialize("1.0,1.0,1.0,1.0", true), Editable()]
|
||||
public Color Color { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The sprite is only drawn if these conditions are fulfilled
|
||||
/// </summary>
|
||||
@@ -113,10 +130,10 @@ namespace Barotrauma
|
||||
switch (OffsetAnim)
|
||||
{
|
||||
case AnimationType.Sine:
|
||||
offsetState = offsetState % (MathHelper.TwoPi / OffsetAnimSpeed);
|
||||
offsetState %= (MathHelper.TwoPi / OffsetAnimSpeed);
|
||||
return Offset * (float)Math.Sin(offsetState * OffsetAnimSpeed);
|
||||
case AnimationType.Noise:
|
||||
offsetState = offsetState % (1.0f / (OffsetAnimSpeed * 0.1f));
|
||||
offsetState %= (1.0f / (OffsetAnimSpeed * 0.1f));
|
||||
|
||||
float t = offsetState * 0.1f * OffsetAnimSpeed;
|
||||
return new Vector2(
|
||||
@@ -146,6 +163,51 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
public static void UpdateSpriteStates(Dictionary<int, List<DecorativeSprite>> spriteGroups, Dictionary<DecorativeSprite, State> animStates,
|
||||
int entityID, float deltaTime, Func<PropertyConditional,bool> checkConditional)
|
||||
{
|
||||
foreach (int spriteGroup in spriteGroups.Keys)
|
||||
{
|
||||
for (int i = 0; i < spriteGroups[spriteGroup].Count; i++)
|
||||
{
|
||||
var decorativeSprite = spriteGroups[spriteGroup][i];
|
||||
if (decorativeSprite == null) { continue; }
|
||||
if (spriteGroup > 0)
|
||||
{
|
||||
int activeSpriteIndex = entityID % spriteGroups[spriteGroup].Count;
|
||||
if (i != activeSpriteIndex)
|
||||
{
|
||||
animStates[decorativeSprite].IsActive = false;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
//check if the sprite is active (whether it should be drawn or not)
|
||||
var spriteState = animStates[decorativeSprite];
|
||||
spriteState.IsActive = true;
|
||||
foreach (PropertyConditional conditional in decorativeSprite.IsActiveConditionals)
|
||||
{
|
||||
if (!checkConditional(conditional))
|
||||
{
|
||||
spriteState.IsActive = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!spriteState.IsActive) { continue; }
|
||||
|
||||
//check if the sprite should be animated
|
||||
bool animate = true;
|
||||
foreach (PropertyConditional conditional in decorativeSprite.AnimationConditionals)
|
||||
{
|
||||
if (!checkConditional(conditional)) { animate = false; break; }
|
||||
}
|
||||
if (!animate) { continue; }
|
||||
spriteState.OffsetState += deltaTime;
|
||||
spriteState.RotationState += deltaTime;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Remove()
|
||||
{
|
||||
Sprite?.Remove();
|
||||
|
||||
@@ -49,6 +49,9 @@ namespace Barotrauma.SpriteDeformations
|
||||
[Serialize(false, true), Editable]
|
||||
public bool StopWhenHostIsDead { get; set; }
|
||||
|
||||
[Serialize(false, true), Editable]
|
||||
public bool OnlyInWater { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Only used if UseMovementSine is enabled. Multiplier for Pi.
|
||||
/// </summary>
|
||||
|
||||
@@ -21,6 +21,11 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
public bool Loaded
|
||||
{
|
||||
get { return texture != null && !cannotBeLoaded; }
|
||||
}
|
||||
|
||||
public Sprite(Texture2D texture, Rectangle? sourceRectangle, Vector2? newOffset, float newRotation = 0.0f)
|
||||
{
|
||||
this.texture = texture;
|
||||
@@ -42,7 +47,12 @@ namespace Barotrauma
|
||||
|
||||
partial void LoadTexture(ref Vector4 sourceVector, ref bool shouldReturn)
|
||||
{
|
||||
texture = LoadTexture(this.FilePath);
|
||||
texture = LoadTexture(this.FilePath, out Sprite reusedSprite);
|
||||
if (reusedSprite != null)
|
||||
{
|
||||
FilePath = string.Intern(reusedSprite.FilePath);
|
||||
FullPath = string.Intern(reusedSprite.FullPath);
|
||||
}
|
||||
|
||||
if (texture == null)
|
||||
{
|
||||
@@ -56,7 +66,7 @@ namespace Barotrauma
|
||||
|
||||
public void EnsureLazyLoaded()
|
||||
{
|
||||
if (!lazyLoad || texture != null || cannotBeLoaded) { return; }
|
||||
if (!LazyLoad || texture != null || cannotBeLoaded) { return; }
|
||||
|
||||
Vector4 sourceVector = Vector4.Zero;
|
||||
bool temp2 = false;
|
||||
@@ -69,11 +79,6 @@ namespace Barotrauma
|
||||
size.Y *= sourceRect.Height;
|
||||
RelativeOrigin = SourceElement.GetAttributeVector2("origin", new Vector2(0.5f, 0.5f));
|
||||
}
|
||||
foreach (Sprite s in LoadedSprites)
|
||||
{
|
||||
if (s == this) { continue; }
|
||||
if (s.FullPath == FullPath && s.texture != null) { s.texture = texture; }
|
||||
}
|
||||
if (texture == null)
|
||||
{
|
||||
cannotBeLoaded = true;
|
||||
@@ -99,6 +104,12 @@ namespace Barotrauma
|
||||
|
||||
public static Texture2D LoadTexture(string file)
|
||||
{
|
||||
return LoadTexture(file, out _);
|
||||
}
|
||||
|
||||
public static Texture2D LoadTexture(string file, out Sprite reusedSprite)
|
||||
{
|
||||
reusedSprite = null;
|
||||
if (string.IsNullOrWhiteSpace(file))
|
||||
{
|
||||
Texture2D t = null;
|
||||
@@ -111,7 +122,11 @@ namespace Barotrauma
|
||||
file = Path.GetFullPath(file);
|
||||
foreach (Sprite s in LoadedSprites)
|
||||
{
|
||||
if (s.FullPath == file && s.texture != null && !s.texture.IsDisposed) { return s.texture; }
|
||||
if (s.FullPath == file && s.texture != null && !s.texture.IsDisposed)
|
||||
{
|
||||
reusedSprite = s;
|
||||
return s.texture;
|
||||
}
|
||||
}
|
||||
|
||||
if (File.Exists(file))
|
||||
|
||||
Reference in New Issue
Block a user