mirror of
https://github.com/space-syndicate/space-station-14.git
synced 2026-10-09 10:21:18 +03:00
* IoC source gen compatibility Can be merged before or after https://github.com/space-wizards/RobustToolbox/pull/6549 doesn't really matter. * Missed a spot
53 lines
2 KiB
C#
53 lines
2 KiB
C#
using Content.Shared.Popups;
|
|
using Content.Shared.Radio.Components;
|
|
|
|
namespace Content.Shared.Radio.EntitySystems;
|
|
|
|
public abstract partial class SharedRadioDeviceSystem : EntitySystem
|
|
{
|
|
[Dependency] private SharedPopupSystem _popup = default!;
|
|
[Dependency] private 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
|
|
}
|
|
|