mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-01-09 21:59:16 +00:00
31 lines
1.2 KiB
C#
31 lines
1.2 KiB
C#
using QSB.Events;
|
|
using QSB.Messaging;
|
|
using QSB.Player;
|
|
|
|
namespace QSB.FrequencySync.Events
|
|
{
|
|
public class IdentifyFrequencyEvent : QSBEvent<EnumMessage<SignalFrequency>>
|
|
{
|
|
public override EventType Type => EventType.IdentifyFrequency;
|
|
|
|
public override void SetupListener() => GlobalMessenger<SignalFrequency>.AddListener(EventNames.QSBIdentifyFrequency, Handler);
|
|
public override void CloseListener() => GlobalMessenger<SignalFrequency>.RemoveListener(EventNames.QSBIdentifyFrequency, Handler);
|
|
|
|
private void Handler(SignalFrequency frequency) => SendEvent(CreateMessage(frequency));
|
|
|
|
private EnumMessage<SignalFrequency> CreateMessage(SignalFrequency frequency) => new EnumMessage<SignalFrequency>
|
|
{
|
|
AboutId = QSBPlayerManager.LocalPlayerId,
|
|
EnumValue = frequency
|
|
};
|
|
|
|
public override void OnReceiveRemote(bool server, EnumMessage<SignalFrequency> message)
|
|
{
|
|
PlayerData.LearnFrequency(message.EnumValue);
|
|
var displayMsg = $"{UITextLibrary.GetString(UITextType.NotificationNewFreq)} <color=orange>{AudioSignal.FrequencyToString(message.EnumValue, false)}</color>";
|
|
var data = new NotificationData(NotificationTarget.All, displayMsg, 10f, true);
|
|
NotificationManager.SharedInstance.PostNotification(data, false);
|
|
}
|
|
}
|
|
}
|