* move all the radio components and system to Shared. * duh split impl * address reviews * cleanup --------- Co-authored-by: walksanatora <walkerffo22@gmail.com>
54 lines
2.0 KiB
C#
54 lines
2.0 KiB
C#
using Content.Shared.Popups;
|
|
using Content.Shared.Radio.Components;
|
|
|
|
namespace Content.Shared.Radio.EntitySystems;
|
|
|
|
public abstract class SharedRadioDeviceSystem : EntitySystem
|
|
{
|
|
[Dependency] private readonly SharedPopupSystem _popup = default!;
|
|
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
|
|
|
|
#region Toggling
|
|
public void ToggleRadioMicrophone(EntityUid uid, EntityUid user, bool quiet = false, RadioMicrophoneComponent? component = null)
|
|
{
|
|
if (!Resolve(uid, ref component))
|
|
return;
|
|
|
|
SetMicrophoneEnabled(uid, user, !component.Enabled, quiet, component);
|
|
}
|
|
|
|
public virtual void SetMicrophoneEnabled(EntityUid uid, EntityUid? user, bool enabled, bool quiet = false, RadioMicrophoneComponent? component = null) { }
|
|
|
|
public void ToggleRadioSpeaker(EntityUid uid, EntityUid user, bool quiet = false, RadioSpeakerComponent? component = null)
|
|
{
|
|
if (!Resolve(uid, ref component))
|
|
return;
|
|
|
|
SetSpeakerEnabled(uid, user, !component.Enabled, quiet, component);
|
|
}
|
|
|
|
public void SetSpeakerEnabled(EntityUid uid, EntityUid? user, bool enabled, bool quiet = false, RadioSpeakerComponent? component = null)
|
|
{
|
|
if (!Resolve(uid, ref component))
|
|
return;
|
|
|
|
component.Enabled = enabled;
|
|
Dirty(uid, component);
|
|
|
|
if (!quiet && user != null)
|
|
{
|
|
var state = Loc.GetString(component.Enabled ? "handheld-radio-component-on-state" : "handheld-radio-component-off-state");
|
|
var message = Loc.GetString("handheld-radio-component-on-use", ("radioState", state));
|
|
_popup.PopupEntity(message, user.Value, user.Value);
|
|
}
|
|
|
|
_appearance.SetData(uid, RadioDeviceVisuals.Speaker, component.Enabled);
|
|
if (component.Enabled)
|
|
EnsureComp<ActiveRadioComponent>(uid).Channels.UnionWith(component.Channels);
|
|
else
|
|
RemCompDeferred<ActiveRadioComponent>(uid);
|
|
}
|
|
#endregion
|
|
}
|
|
|