OverlayManager 2 Electric Boogaloo (#1410)
This commit is contained in:
@@ -1,11 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Threading;
|
||||
using System.Timers;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Interfaces.Timing;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Timers;
|
||||
using Robust.Shared.ViewVariables;
|
||||
using YamlDotNet.RepresentationModel;
|
||||
using Component = Robust.Shared.GameObjects.Component;
|
||||
@@ -18,72 +23,101 @@ namespace Content.Shared.GameObjects.Components.Mobs
|
||||
public abstract class SharedOverlayEffectsComponent : Component
|
||||
{
|
||||
public override string Name => "OverlayEffectsUI";
|
||||
|
||||
public sealed override uint? NetID => ContentNetIDs.OVERLAYEFFECTS;
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public class OverlayContainer
|
||||
public class OverlayContainer : IEquatable<string>, IEquatable<OverlayContainer>
|
||||
{
|
||||
[ViewVariables(VVAccess.ReadOnly)]
|
||||
public string ID { get; }
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public List<OverlayParameter> Parameters { get; } = new List<OverlayParameter>();
|
||||
|
||||
public OverlayContainer([NotNull] string id)
|
||||
{
|
||||
ID = id;
|
||||
}
|
||||
|
||||
public OverlayContainer(OverlayType type) : this(type.ToString())
|
||||
public OverlayContainer(SharedOverlayID id) : this(id.ToString())
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
public OverlayContainer(SharedOverlayID id, params OverlayParameter[] parameters) : this(id)
|
||||
{
|
||||
if (obj is OverlayContainer container)
|
||||
Parameters.AddRange(parameters);
|
||||
}
|
||||
|
||||
public bool TryGetOverlayParameter<T>(out T parameter) where T : OverlayParameter
|
||||
{
|
||||
var found = Parameters.FirstOrDefault(p => p is T);
|
||||
if (found != null)
|
||||
{
|
||||
return container.ID == ID;
|
||||
parameter = found as T;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (obj is string idString)
|
||||
{
|
||||
return idString == ID;
|
||||
}
|
||||
parameter = default;
|
||||
return false;
|
||||
}
|
||||
|
||||
return base.Equals(obj);
|
||||
public bool Equals(string other)
|
||||
{
|
||||
return ID == other;
|
||||
}
|
||||
|
||||
public bool Equals(OverlayContainer other)
|
||||
{
|
||||
return ID == other?.ID;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return (ID != null ? ID.GetHashCode() : 0);
|
||||
return ID != null ? ID.GetHashCode() : 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public class OverlayEffectComponentState : ComponentState
|
||||
public class OverlayEffectComponentMessage : ComponentMessage
|
||||
{
|
||||
public List<OverlayContainer> Overlays;
|
||||
|
||||
public OverlayEffectComponentState(List<OverlayContainer> overlays) : base(ContentNetIDs.OVERLAYEFFECTS)
|
||||
public OverlayEffectComponentMessage(List<OverlayContainer> overlays)
|
||||
{
|
||||
Directed = true;
|
||||
Overlays = overlays;
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public class TimedOverlayContainer : OverlayContainer
|
||||
public class ResendOverlaysMessage : ComponentMessage
|
||||
{
|
||||
[ViewVariables(VVAccess.ReadOnly)]
|
||||
public int Length { get; }
|
||||
|
||||
public TimedOverlayContainer(string id, int length) : base(id)
|
||||
{
|
||||
Length = length;
|
||||
}
|
||||
|
||||
public void StartTimer(Action finished) => Timer.Spawn(Length, finished);
|
||||
}
|
||||
|
||||
public enum OverlayType
|
||||
[Serializable, NetSerializable]
|
||||
public abstract class OverlayParameter
|
||||
{
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public class TimedOverlayParameter : OverlayParameter
|
||||
{
|
||||
[ViewVariables(VVAccess.ReadOnly)]
|
||||
public int Length { get; set; }
|
||||
|
||||
public double StartedAt { get; private set; }
|
||||
|
||||
public TimedOverlayParameter(int length)
|
||||
{
|
||||
Length = length;
|
||||
StartedAt = IoCManager.Resolve<IGameTiming>().CurTime.TotalMilliseconds;
|
||||
}
|
||||
}
|
||||
|
||||
public enum SharedOverlayID
|
||||
{
|
||||
GradientCircleMaskOverlay,
|
||||
CircleMaskOverlay,
|
||||
|
||||
Reference in New Issue
Block a user