mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-01-18 13:23:05 +00:00
42 lines
1.3 KiB
C#
42 lines
1.3 KiB
C#
using QSB.Events;
|
|
using QSB.Messaging;
|
|
using QSB.Player;
|
|
|
|
namespace QSB.Tools.TranslatorTool.Events
|
|
{
|
|
public class PlayerTranslatorEvent : QSBEvent<ToggleMessage>
|
|
{
|
|
public override EventType Type => EventType.TranslatorActiveChange;
|
|
|
|
public override void SetupListener()
|
|
{
|
|
GlobalMessenger.AddListener(EventNames.EquipTranslator, HandleEquip);
|
|
GlobalMessenger.AddListener(EventNames.UnequipTranslator, HandleUnequip);
|
|
}
|
|
|
|
public override void CloseListener()
|
|
{
|
|
GlobalMessenger.RemoveListener(EventNames.EquipTranslator, HandleEquip);
|
|
GlobalMessenger.RemoveListener(EventNames.UnequipTranslator, HandleUnequip);
|
|
}
|
|
|
|
private void HandleEquip() => SendEvent(CreateMessage(true));
|
|
private void HandleUnequip() => SendEvent(CreateMessage(false));
|
|
|
|
private ToggleMessage CreateMessage(bool value) => new ToggleMessage
|
|
{
|
|
AboutId = LocalPlayerId,
|
|
ToggleValue = value
|
|
};
|
|
|
|
public override void OnReceiveRemote(bool server, ToggleMessage message)
|
|
{
|
|
var player = QSBPlayerManager.GetPlayer(message.AboutId);
|
|
player.PlayerStates.TranslatorEquipped = message.ToggleValue;
|
|
player.Translator?.ChangeEquipState(message.ToggleValue);
|
|
}
|
|
|
|
public override void OnReceiveLocal(bool server, ToggleMessage message) =>
|
|
QSBPlayerManager.LocalPlayer.PlayerStates.TranslatorEquipped = message.ToggleValue;
|
|
}
|
|
} |