quantum-space-buddies/QSB/FrequencySync/Events/IdentifySignalEvent.cs

31 lines
1.2 KiB
C#
Raw Normal View History

2020-12-24 19:35:42 +00:00
using QSB.Events;
using QSB.Messaging;
using QSB.Player;
namespace QSB.FrequencySync.Events
{
public class IdentifySignalEvent : QSBEvent<EnumMessage<SignalName>>
{
public override EventType Type => EventType.IdentifySignal;
public override void SetupListener() => GlobalMessenger<SignalName>.AddListener(EventNames.QSBIdentifySignal, Handler);
public override void CloseListener() => GlobalMessenger<SignalName>.RemoveListener(EventNames.QSBIdentifySignal, Handler);
private void Handler(SignalName name) => SendEvent(CreateMessage(name));
private EnumMessage<SignalName> CreateMessage(SignalName name) => new EnumMessage<SignalName>
{
AboutId = QSBPlayerManager.LocalPlayerId,
Value = name
};
public override void OnReceiveRemote(bool server, EnumMessage<SignalName> message)
{
PlayerData.LearnSignal(message.Value);
GlobalMessenger.FireEvent("IdentifySignal");
var displayMsg = $"{UITextLibrary.GetString(UITextType.NotificationSignalIdentified)} <color=orange>{AudioSignal.SignalNameToString(message.Value)}</color>";
var data = new NotificationData(NotificationTarget.All, displayMsg, 10f, true);
NotificationManager.SharedInstance.PostNotification(data, false);
}
}
}