mirror of
https://github.com/WWhiteDreamProject/wwdpublic.git
synced 2026-04-20 23:17:43 +03:00
Resolves https://github.com/Simple-Station/Einstein-Engines/issues/37 # Description This PR adds languages. Every entity who can speak now speaks a specific language (or Universal, for entities that are not supposed to speak, which is understood by everyone). Other entities who do not understand this language will see gibberish (it's possible to learn how certain induvidual words are spelled. But the spelling changes between rounds). This means that certain creatures, like xenos, cats, vulps, can communicate within their species in their own languages. Similarly, it means that xenos, cats and other things cannot understand GalacticCommon speakers without a translator or cognization. An entity may be able to speak multiple languages, or understand a language but be unable to speak it. Thi PR was orignally made for Frontier but is now being ported and will be maintain here. Orignal PR: https://github.com/new-frontiers-14/frontier-station-14/pull/671 This PR was made orignally by Mnemotechnician and FoxxoTrystan. --- # TODO - [x] Language System. (Check Frontier PR for all the compleated todo list) - [x] Port PR from Frontier. - [x] QOL Changes. - [x] Missing Default Languages. (Missing default langauges for some roundstart species) - [x] Animals Languages. --- <details><summary><h1>Media</h1></summary> <p>    </p> </details> --- # Changelog 🆑 FoxxoTrystan / Mnemotechnician - add: All species can now bring their own cultures and languages --------- Signed-off-by: Mnemotechnican <69920617+Mnemotechnician@users.noreply.github.com> Signed-off-by: FoxxoTrystan <45297731+FoxxoTrystan@users.noreply.github.com> Co-authored-by: fox <daytimer253@gmail.com> Co-authored-by: Mnemotechnican <69920617+Mnemotechnician@users.noreply.github.com> Co-authored-by: Pspritechologist <81725545+Pspritechologist@users.noreply.github.com> Co-authored-by: Lincoln McQueen <lincoln.mcqueen@gmail.com> Co-authored-by: Arkyfloof <Marvinlinke08@gmail.com> Co-authored-by: reese1243 <ber23027@byui.edu> Co-authored-by: VMSolidus <evilexecutive@gmail.com> Co-authored-by: Eagle-0 <114363363+Eagle-0@users.noreply.github.com> Co-authored-by: BlitzDev <145472107+Reese1243@users.noreply.github.com> Co-authored-by: Arkyfloof <161242062+Arkyfloof@users.noreply.github.com> Co-authored-by: Danger Revolution! <142105406+DangerRevolution@users.noreply.github.com> Co-authored-by: DEATHB4DEFEAT <77995199+DEATHB4DEFEAT@users.noreply.github.com>
268 lines
11 KiB
C#
268 lines
11 KiB
C#
using Content.Server.Chat.Systems;
|
|
using Content.Server.Interaction;
|
|
using Content.Server.Language;
|
|
using Content.Server.Popups;
|
|
using Content.Server.Power.Components;
|
|
using Content.Server.Power.EntitySystems;
|
|
using Content.Server.Radio.Components;
|
|
using Content.Server.Speech;
|
|
using Content.Server.Speech.Components;
|
|
using Content.Shared.UserInterface;
|
|
using Content.Shared.Chat;
|
|
using Content.Shared.Examine;
|
|
using Content.Shared.Interaction;
|
|
using Content.Shared.Radio;
|
|
using Content.Shared.Radio.Components;
|
|
using Robust.Server.GameObjects;
|
|
using Robust.Shared.Prototypes;
|
|
|
|
namespace Content.Server.Radio.EntitySystems;
|
|
|
|
/// <summary>
|
|
/// This system handles radio speakers and microphones (which together form a hand-held radio).
|
|
/// </summary>
|
|
public sealed class RadioDeviceSystem : EntitySystem
|
|
{
|
|
[Dependency] private readonly IPrototypeManager _protoMan = default!;
|
|
[Dependency] private readonly PopupSystem _popup = default!;
|
|
[Dependency] private readonly ChatSystem _chat = default!;
|
|
[Dependency] private readonly RadioSystem _radio = default!;
|
|
[Dependency] private readonly InteractionSystem _interaction = default!;
|
|
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
|
|
[Dependency] private readonly UserInterfaceSystem _ui = default!;
|
|
[Dependency] private readonly LanguageSystem _language = default!;
|
|
|
|
// Used to prevent a shitter from using a bunch of radios to spam chat.
|
|
private HashSet<(string, EntityUid)> _recentlySent = new();
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
SubscribeLocalEvent<RadioMicrophoneComponent, ComponentInit>(OnMicrophoneInit);
|
|
SubscribeLocalEvent<RadioMicrophoneComponent, ExaminedEvent>(OnExamine);
|
|
SubscribeLocalEvent<RadioMicrophoneComponent, ActivateInWorldEvent>(OnActivateMicrophone);
|
|
SubscribeLocalEvent<RadioMicrophoneComponent, ListenEvent>(OnListen);
|
|
SubscribeLocalEvent<RadioMicrophoneComponent, ListenAttemptEvent>(OnAttemptListen);
|
|
SubscribeLocalEvent<RadioMicrophoneComponent, PowerChangedEvent>(OnPowerChanged);
|
|
|
|
SubscribeLocalEvent<RadioSpeakerComponent, ComponentInit>(OnSpeakerInit);
|
|
SubscribeLocalEvent<RadioSpeakerComponent, ActivateInWorldEvent>(OnActivateSpeaker);
|
|
SubscribeLocalEvent<RadioSpeakerComponent, RadioReceiveEvent>(OnReceiveRadio);
|
|
|
|
SubscribeLocalEvent<IntercomComponent, BeforeActivatableUIOpenEvent>(OnBeforeIntercomUiOpen);
|
|
SubscribeLocalEvent<IntercomComponent, ToggleIntercomMicMessage>(OnToggleIntercomMic);
|
|
SubscribeLocalEvent<IntercomComponent, ToggleIntercomSpeakerMessage>(OnToggleIntercomSpeaker);
|
|
SubscribeLocalEvent<IntercomComponent, SelectIntercomChannelMessage>(OnSelectIntercomChannel);
|
|
}
|
|
|
|
public override void Update(float frameTime)
|
|
{
|
|
base.Update(frameTime);
|
|
_recentlySent.Clear();
|
|
}
|
|
|
|
|
|
#region Component Init
|
|
private void OnMicrophoneInit(EntityUid uid, RadioMicrophoneComponent component, ComponentInit args)
|
|
{
|
|
if (component.Enabled)
|
|
EnsureComp<ActiveListenerComponent>(uid).Range = component.ListenRange;
|
|
else
|
|
RemCompDeferred<ActiveListenerComponent>(uid);
|
|
}
|
|
|
|
private void OnSpeakerInit(EntityUid uid, RadioSpeakerComponent component, ComponentInit args)
|
|
{
|
|
if (component.Enabled)
|
|
EnsureComp<ActiveRadioComponent>(uid).Channels.UnionWith(component.Channels);
|
|
else
|
|
RemCompDeferred<ActiveRadioComponent>(uid);
|
|
}
|
|
#endregion
|
|
|
|
#region Toggling
|
|
private void OnActivateMicrophone(EntityUid uid, RadioMicrophoneComponent component, ActivateInWorldEvent args)
|
|
{
|
|
if (!component.ToggleOnInteract)
|
|
return;
|
|
|
|
ToggleRadioMicrophone(uid, args.User, args.Handled, component);
|
|
args.Handled = true;
|
|
}
|
|
|
|
private void OnActivateSpeaker(EntityUid uid, RadioSpeakerComponent component, ActivateInWorldEvent args)
|
|
{
|
|
if (!component.ToggleOnInteract)
|
|
return;
|
|
|
|
ToggleRadioSpeaker(uid, args.User, args.Handled, component);
|
|
args.Handled = true;
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
private void OnPowerChanged(EntityUid uid, RadioMicrophoneComponent component, ref PowerChangedEvent args)
|
|
{
|
|
if (args.Powered)
|
|
return;
|
|
SetMicrophoneEnabled(uid, null, false, true, component);
|
|
}
|
|
|
|
public void SetMicrophoneEnabled(EntityUid uid, EntityUid? user, bool enabled, bool quiet = false, RadioMicrophoneComponent? component = null)
|
|
{
|
|
if (!Resolve(uid, ref component, false))
|
|
return;
|
|
|
|
if (component.PowerRequired && !this.IsPowered(uid, EntityManager))
|
|
return;
|
|
|
|
component.Enabled = enabled;
|
|
|
|
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.Broadcasting, component.Enabled);
|
|
if (component.Enabled)
|
|
EnsureComp<ActiveListenerComponent>(uid).Range = component.ListenRange;
|
|
else
|
|
RemCompDeferred<ActiveListenerComponent>(uid);
|
|
}
|
|
|
|
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;
|
|
|
|
if (!quiet)
|
|
{
|
|
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, user);
|
|
}
|
|
|
|
_appearance.SetData(uid, RadioDeviceVisuals.Speaker, component.Enabled);
|
|
if (component.Enabled)
|
|
EnsureComp<ActiveRadioComponent>(uid).Channels.UnionWith(component.Channels);
|
|
else
|
|
RemCompDeferred<ActiveRadioComponent>(uid);
|
|
}
|
|
#endregion
|
|
|
|
private void OnExamine(EntityUid uid, RadioMicrophoneComponent component, ExaminedEvent args)
|
|
{
|
|
if (!args.IsInDetailsRange)
|
|
return;
|
|
|
|
var proto = _protoMan.Index<RadioChannelPrototype>(component.BroadcastChannel);
|
|
|
|
using (args.PushGroup(nameof(RadioMicrophoneComponent)))
|
|
{
|
|
args.PushMarkup(Loc.GetString("handheld-radio-component-on-examine", ("frequency", proto.Frequency)));
|
|
args.PushMarkup(Loc.GetString("handheld-radio-component-chennel-examine",
|
|
("channel", proto.LocalizedName)));
|
|
}
|
|
}
|
|
|
|
private void OnListen(EntityUid uid, RadioMicrophoneComponent component, ListenEvent args)
|
|
{
|
|
if (HasComp<RadioSpeakerComponent>(args.Source))
|
|
return; // no feedback loops please.
|
|
|
|
if (_recentlySent.Add((args.Message, args.Source)))
|
|
_radio.SendRadioMessage(args.Source, args.Message, _protoMan.Index<RadioChannelPrototype>(component.BroadcastChannel), uid);
|
|
}
|
|
|
|
private void OnAttemptListen(EntityUid uid, RadioMicrophoneComponent component, ListenAttemptEvent args)
|
|
{
|
|
if (component.PowerRequired && !this.IsPowered(uid, EntityManager)
|
|
|| component.UnobstructedRequired && !_interaction.InRangeUnobstructed(args.Source, uid, 0))
|
|
{
|
|
args.Cancel();
|
|
}
|
|
}
|
|
|
|
private void OnReceiveRadio(EntityUid uid, RadioSpeakerComponent component, ref RadioReceiveEvent args)
|
|
{
|
|
var nameEv = new TransformSpeakerNameEvent(args.MessageSource, Name(args.MessageSource));
|
|
RaiseLocalEvent(args.MessageSource, nameEv);
|
|
|
|
var name = Loc.GetString("speech-name-relay", ("speaker", Name(uid)),
|
|
("originalName", nameEv.Name));
|
|
|
|
// log to chat so people can identity the speaker/source, but avoid clogging ghost chat if there are many radios
|
|
var message = args.OriginalChatMsg.Message; // The chat system will handle the rest and re-obfuscate if needed.
|
|
_chat.TrySendInGameICMessage(uid, message, InGameICChatType.Whisper, ChatTransmitRange.GhostRangeLimit, nameOverride: name, checkRadioPrefix: false, languageOverride: args.Language);
|
|
}
|
|
|
|
private void OnBeforeIntercomUiOpen(EntityUid uid, IntercomComponent component, BeforeActivatableUIOpenEvent args)
|
|
{
|
|
UpdateIntercomUi(uid, component);
|
|
}
|
|
|
|
private void OnToggleIntercomMic(EntityUid uid, IntercomComponent component, ToggleIntercomMicMessage args)
|
|
{
|
|
if (component.RequiresPower && !this.IsPowered(uid, EntityManager) || args.Session.AttachedEntity is not { } user)
|
|
return;
|
|
|
|
SetMicrophoneEnabled(uid, user, args.Enabled, true);
|
|
UpdateIntercomUi(uid, component);
|
|
}
|
|
|
|
private void OnToggleIntercomSpeaker(EntityUid uid, IntercomComponent component, ToggleIntercomSpeakerMessage args)
|
|
{
|
|
if (component.RequiresPower && !this.IsPowered(uid, EntityManager) || args.Session.AttachedEntity is not { } user)
|
|
return;
|
|
|
|
SetSpeakerEnabled(uid, user, args.Enabled, true);
|
|
UpdateIntercomUi(uid, component);
|
|
}
|
|
|
|
private void OnSelectIntercomChannel(EntityUid uid, IntercomComponent component, SelectIntercomChannelMessage args)
|
|
{
|
|
if (component.RequiresPower && !this.IsPowered(uid, EntityManager) || args.Session.AttachedEntity is not { })
|
|
return;
|
|
|
|
if (!_protoMan.TryIndex<RadioChannelPrototype>(args.Channel, out _) || !component.SupportedChannels.Contains(args.Channel))
|
|
return;
|
|
|
|
if (TryComp<RadioMicrophoneComponent>(uid, out var mic))
|
|
mic.BroadcastChannel = args.Channel;
|
|
if (TryComp<RadioSpeakerComponent>(uid, out var speaker))
|
|
speaker.Channels = new(){ args.Channel };
|
|
UpdateIntercomUi(uid, component);
|
|
}
|
|
|
|
private void UpdateIntercomUi(EntityUid uid, IntercomComponent component)
|
|
{
|
|
var micComp = CompOrNull<RadioMicrophoneComponent>(uid);
|
|
var speakerComp = CompOrNull<RadioSpeakerComponent>(uid);
|
|
|
|
var micEnabled = micComp?.Enabled ?? false;
|
|
var speakerEnabled = speakerComp?.Enabled ?? false;
|
|
var availableChannels = component.SupportedChannels;
|
|
var selectedChannel = micComp?.BroadcastChannel ?? SharedChatSystem.CommonChannel;
|
|
var state = new IntercomBoundUIState(micEnabled, speakerEnabled, availableChannels, selectedChannel);
|
|
_ui.TrySetUiState(uid, IntercomUiKey.Key, state);
|
|
}
|
|
}
|