Skip to content

Commit

Permalink
Merge pull request Rxup#427 from Rxup/upstream-sync
Browse files Browse the repository at this point in the history
Upstream sync
  • Loading branch information
Rxup authored Jan 21, 2024
2 parents 5538554 + 6312807 commit 8fffdf3
Show file tree
Hide file tree
Showing 423 changed files with 9,731 additions and 6,794 deletions.
18 changes: 10 additions & 8 deletions Content.Client/Audio/AmbientSoundSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public sealed class AmbientSoundSystem : SharedAmbientSoundSystem
{
[Dependency] private readonly AmbientSoundTreeSystem _treeSys = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!;
[Dependency] private readonly SharedTransformSystem _xformSystem = default!;
[Dependency] private readonly IConfigurationManager _cfg = default!;
[Dependency] private readonly IGameTiming _gameTiming = default!;
[Dependency] private readonly IPlayerManager _playerManager = default!;
Expand Down Expand Up @@ -172,7 +173,7 @@ public override void Update(float frameTime)

_targetTime = _gameTiming.CurTime+TimeSpan.FromSeconds(_cooldown);

var player = _playerManager.LocalPlayer?.ControlledEntity;
var player = _playerManager.LocalEntity;
if (!EntityManager.TryGetComponent(player, out TransformComponent? xform))
{
ClearSounds();
Expand All @@ -198,13 +199,13 @@ private readonly struct QueryState
public readonly Dictionary<string, List<(float Importance, AmbientSoundComponent)>> SourceDict = new();
public readonly Vector2 MapPos;
public readonly TransformComponent Player;
public readonly EntityQuery<TransformComponent> Query;
public readonly SharedTransformSystem TransformSystem;

public QueryState(Vector2 mapPos, TransformComponent player, EntityQuery<TransformComponent> query)
public QueryState(Vector2 mapPos, TransformComponent player, SharedTransformSystem transformSystem)
{
MapPos = mapPos;
Player = player;
Query = query;
TransformSystem = transformSystem;
}
}

Expand All @@ -218,7 +219,7 @@ private static bool Callback(

var delta = xform.ParentUid == state.Player.ParentUid
? xform.LocalPosition - state.Player.LocalPosition
: xform.WorldPosition - state.MapPos;
: state.TransformSystem.GetWorldPosition(xform) - state.MapPos;

var range = delta.Length();
if (range >= ambientComp.Range)
Expand All @@ -244,7 +245,7 @@ private void ProcessNearbyAmbience(TransformComponent playerXform)
{
var query = GetEntityQuery<TransformComponent>();
var metaQuery = GetEntityQuery<MetaDataComponent>();
var mapPos = playerXform.MapPosition;
var mapPos = _xformSystem.GetMapCoordinates(playerXform);

// Remove out-of-range ambiences
foreach (var (comp, sound) in _playingSounds)
Expand All @@ -258,9 +259,10 @@ private void ProcessNearbyAmbience(TransformComponent playerXform)
xform.MapID == playerXform.MapID &&
!metaQuery.GetComponent(entity).EntityPaused)
{
// TODO: This is just trydistance for coordinates.
var distance = (xform.ParentUid == playerXform.ParentUid)
? xform.LocalPosition - playerXform.LocalPosition
: xform.WorldPosition - mapPos.Position;
: _xformSystem.GetWorldPosition(xform) - mapPos.Position;

if (distance.LengthSquared() < comp.Range * comp.Range)
continue;
Expand All @@ -277,7 +279,7 @@ private void ProcessNearbyAmbience(TransformComponent playerXform)
return;

var pos = mapPos.Position;
var state = new QueryState(pos, playerXform, query);
var state = new QueryState(pos, playerXform, _xformSystem);
var worldAabb = new Box2(pos - MaxAmbientVector, pos + MaxAmbientVector);
_treeSys.QueryAabb(ref state, Callback, mapPos.MapId, worldAabb);

Expand Down
21 changes: 21 additions & 0 deletions Content.Client/Audio/BackgroundAudioSystem.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Content.Client.GameTicking.Managers;
using Content.Client.Lobby;
using Content.Shared.CCVar;
using Content.Shared.GameTicking;
using JetBrains.Annotations;
using Robust.Client;
using Robust.Client.State;
Expand Down Expand Up @@ -39,6 +40,8 @@ public override void Initialize()
_client.PlayerLeaveServer += OnLeave;

_gameTicker.LobbySongUpdated += LobbySongUpdated;

SubscribeNetworkEvent<RoundRestartCleanupEvent>(PlayRestartSound);
}

public override void Shutdown()
Expand Down Expand Up @@ -129,4 +132,22 @@ private void EndLobbyMusic()
{
LobbyStream = _audio.Stop(LobbyStream);
}

private void PlayRestartSound(RoundRestartCleanupEvent ev)
{
if (!_configManager.GetCVar(CCVars.LobbyMusicEnabled))
return;

var file = _gameTicker.RestartSound;
if (string.IsNullOrEmpty(file))
{
return;
}

var volume = _lobbyParams.WithVolume(_lobbyParams.Volume +
SharedAudioSystem.GainToVolume(
_configManager.GetCVar(CCVars.LobbyMusicVolume)));

_audio.PlayGlobal(file, Filter.Local(), false, volume);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ protected override void Open()
base.Open();

var spriteSystem = EntMan.System<SpriteSystem>();
_menu = new CargoConsoleMenu(IoCManager.Resolve<IPrototypeManager>(), spriteSystem);
var localPlayer = IoCManager.Resolve<IPlayerManager>()?.LocalPlayer?.ControlledEntity;
var dependencies = IoCManager.Instance!;
_menu = new CargoConsoleMenu(Owner, EntMan, dependencies.Resolve<IPrototypeManager>(), spriteSystem);
var localPlayer = dependencies.Resolve<IPlayerManager>().LocalEntity;
var description = new FormattedMessage();

string orderRequester;
Expand Down
25 changes: 22 additions & 3 deletions Content.Client/Cargo/UI/CargoConsoleMenu.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Linq;
using Content.Client.UserInterface.Controls;
using Content.Shared.Cargo;
using Content.Shared.Cargo.Components;
using Content.Shared.Cargo.Prototypes;
using Robust.Client.AutoGenerated;
using Robust.Client.GameObjects;
Expand All @@ -14,8 +15,10 @@ namespace Content.Client.Cargo.UI
[GenerateTypedNameReferences]
public sealed partial class CargoConsoleMenu : FancyWindow
{
private IEntityManager _entityManager;
private IPrototypeManager _protoManager;
private SpriteSystem _spriteSystem;
private EntityUid _owner;

public event Action<ButtonEventArgs>? OnItemSelected;
public event Action<ButtonEventArgs>? OnOrderApproved;
Expand All @@ -24,11 +27,13 @@ public sealed partial class CargoConsoleMenu : FancyWindow
private readonly List<string> _categoryStrings = new();
private string? _category;

public CargoConsoleMenu(IPrototypeManager protoManager, SpriteSystem spriteSystem)
public CargoConsoleMenu(EntityUid owner, IEntityManager entMan, IPrototypeManager protoManager, SpriteSystem spriteSystem)
{
RobustXamlLoader.Load(this);
_entityManager = entMan;
_protoManager = protoManager;
_spriteSystem = spriteSystem;
_owner = owner;

Title = Loc.GetString("cargo-console-menu-title");

Expand All @@ -53,7 +58,21 @@ private void SetCategoryText(int id)
Categories.SelectId(id);
}

public IEnumerable<CargoProductPrototype> ProductPrototypes => _protoManager.EnumeratePrototypes<CargoProductPrototype>();
public IEnumerable<CargoProductPrototype> ProductPrototypes
{
get
{
var allowedGroups = _entityManager.GetComponentOrNull<CargoOrderConsoleComponent>(_owner)?.AllowedGroups;

foreach (var cargoPrototype in _protoManager.EnumeratePrototypes<CargoProductPrototype>())
{
if (!allowedGroups?.Contains(cargoPrototype.Group) ?? false)
continue;

yield return cargoPrototype;
}
}
}

/// <summary>
/// Populates the list of products that will actually be shown, using the current filters.
Expand All @@ -80,7 +99,7 @@ public void PopulateProducts()
Product = prototype,
ProductName = { Text = prototype.Name },
MainButton = { ToolTip = prototype.Description },
PointCost = { Text = Loc.GetString("cargo-console-menu-points-amount", ("amount", prototype.PointCost.ToString())) },
PointCost = { Text = Loc.GetString("cargo-console-menu-points-amount", ("amount", prototype.Cost.ToString())) },
Icon = { Texture = _spriteSystem.Frame0(prototype.Icon) },
};
button.MainButton.OnPressed += args =>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
using Content.Shared.Communications;
using Robust.Client.GameObjects;
using Content.Shared.CCVar;
using Content.Shared.Chat;
using Content.Shared.Communications;
using Robust.Shared.Configuration;
using Robust.Shared.Timing;

namespace Content.Client.Communications.UI
{
public sealed class CommunicationsConsoleBoundUserInterface : BoundUserInterface
{
[Dependency] private readonly IGameTiming _gameTiming = default!;
[Dependency] private readonly IConfigurationManager _cfg = default!;

[ViewVariables]
private CommunicationsConsoleMenu? _menu;
Expand Down Expand Up @@ -63,22 +66,9 @@ public void EmergencyShuttleButtonPressed()

public void AnnounceButtonPressed(string message)
{
var msg = (message.Length <= 256 ? message.Trim() : $"{message.Trim().Substring(0, 256)}...").ToCharArray();

// No more than 2 newlines, other replaced to spaces
var newlines = 0;
for (var i = 0; i < msg.Length; i++)
{
if (msg[i] != '\n')
continue;

if (newlines >= 2)
msg[i] = ' ';

newlines++;
}

SendMessage(new CommunicationsConsoleAnnounceMessage(new string(msg)));
var maxLength = _cfg.GetCVar(CCVars.ChatMaxAnnouncementLength);
var msg = SharedChatSystem.SanitizeAnnouncement(message, maxLength);
SendMessage(new CommunicationsConsoleAnnounceMessage(msg));
}

public void CallShuttle()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public CommunicationsConsoleMenu(CommunicationsConsoleBoundUserInterface owner)
var loc = IoCManager.Resolve<ILocalizationManager>();
MessageInput.Placeholder = new Rope.Leaf(loc.GetString("comms-console-menu-announcement-placeholder"));

AnnounceButton.OnPressed += (_) => Owner.AnnounceButtonPressed(Rope.Collapse(MessageInput.TextRope).Trim());
AnnounceButton.OnPressed += (_) => Owner.AnnounceButtonPressed(Rope.Collapse(MessageInput.TextRope));
AnnounceButton.Disabled = !owner.CanAnnounce;

AlertLevelButton.OnItemSelected += args =>
Expand Down
2 changes: 2 additions & 0 deletions Content.Client/GameTicking/Managers/ClientGameTicker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public sealed class ClientGameTicker : SharedGameTicker
[ViewVariables] public bool AreWeReady { get; private set; }
[ViewVariables] public bool IsGameStarted { get; private set; }
[ViewVariables] public string? LobbySong { get; private set; }
[ViewVariables] public string? RestartSound { get; private set; }
[ViewVariables] public string? LobbyBackground { get; private set; }
[ViewVariables] public bool DisallowedLateJoin { get; private set; }
[ViewVariables] public string? ServerInfoBlob { get; private set; }
Expand Down Expand Up @@ -151,6 +152,7 @@ private void RoundEnd(RoundEndMessageEvent message)
{
// Force an update in the event of this song being the same as the last.
SetLobbySong(message.LobbySong, true);
RestartSound = message.RestartSound;

// Don't open duplicate windows (mainly for replays).
if (_window?.RoundId == message.RoundId)
Expand Down
3 changes: 2 additions & 1 deletion Content.Client/Lathe/UI/LatheBoundUserInterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ protected override void UpdateState(BoundUserInterfaceState state)
case LatheUpdateState msg:
if (_menu != null)
_menu.Recipes = msg.Recipes;
_menu?.PopulateRecipes(Owner);
_menu?.PopulateRecipes();
_menu?.UpdateCategories();
_menu?.PopulateQueueList(msg.Queue);
_menu?.SetQueueInfo(msg.CurrentlyProducing);
break;
Expand Down
12 changes: 4 additions & 8 deletions Content.Client/Lathe/UI/LatheMenu.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,10 @@
PlaceHolder="{Loc 'lathe-menu-search-designs'}"
HorizontalExpand="True">
</LineEdit>
<Button
Name="FilterButton"
Text="{Loc 'lathe-menu-search-filter'}"
TextAlign="Center"
Margin="5 0 0 0"
Disabled="True"
StyleClasses="ButtonSquare">
</Button>
<OptionButton
Name="FilterOption"
MinWidth="100"
StyleClasses="ButtonSquare"/>
</BoxContainer>
<BoxContainer Orientation="Vertical"
MinHeight="225"
Expand Down
Loading

0 comments on commit 8fffdf3

Please sign in to comment.