using QSB.Events; using QSB.Messaging; using QSB.Player; namespace QSB.FrequencySync.Events { public class IdentifyFrequencyEvent : QSBEvent> { public override EventType Type => EventType.IdentifyFrequency; public override void SetupListener() => GlobalMessenger.AddListener(EventNames.QSBIdentifyFrequency, Handler); public override void CloseListener() => GlobalMessenger.RemoveListener(EventNames.QSBIdentifyFrequency, Handler); private void Handler(SignalFrequency frequency) => SendEvent(CreateMessage(frequency)); private EnumMessage CreateMessage(SignalFrequency frequency) => new EnumMessage { AboutId = QSBPlayerManager.LocalPlayerId, EnumValue = frequency }; public override void OnReceiveRemote(bool server, EnumMessage message) { PlayerData.LearnFrequency(message.EnumValue); var displayMsg = $"{UITextLibrary.GetString(UITextType.NotificationNewFreq)} {AudioSignal.FrequencyToString(message.EnumValue, false)}"; var data = new NotificationData(NotificationTarget.All, displayMsg, 10f, true); NotificationManager.SharedInstance.PostNotification(data, false); } } }