Skip to content

Commit

Permalink
Merge pull request #1869 from space-syndicate/upstream-sync
Browse files Browse the repository at this point in the history
Upstream sync
  • Loading branch information
Morb0 authored Feb 12, 2024
2 parents 9499452 + 2b78f5b commit baa1216
Show file tree
Hide file tree
Showing 742 changed files with 13,476 additions and 8,715 deletions.
2 changes: 1 addition & 1 deletion Content.Benchmarks/DeviceNetworkingBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
using Content.IntegrationTests;
using Content.IntegrationTests.Pair;
using Content.IntegrationTests.Tests.DeviceNetwork;
using Content.Server.DeviceNetwork;
using Content.Server.DeviceNetwork.Systems;
using Content.Shared.DeviceNetwork;
using Robust.Shared;
using Robust.Shared.Analyzers;
using Robust.Shared.GameObjects;
Expand Down
26 changes: 16 additions & 10 deletions Content.Client/Audio/BackgroundAudioSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ public sealed class BackgroundAudioSystem : EntitySystem
[Dependency] private readonly IStateManager _stateManager = default!;

private readonly AudioParams _lobbyParams = new(-5f, 1, "Master", 0, 0, 0, true, 0f);
private readonly AudioParams _roundEndParams = new(-5f, 1, "Master", 0, 0, 0, false, 0f);

public EntityUid? LobbyStream;
public EntityUid? LobbyMusicStream;
public EntityUid? LobbyRoundRestartAudioStream;

public override void Initialize()
{
Expand Down Expand Up @@ -115,7 +117,7 @@ public void RestartLobbyMusic()

public void StartLobbyMusic()
{
if (LobbyStream != null || !_configManager.GetCVar(CCVars.LobbyMusicEnabled))
if (LobbyMusicStream != null || !_configManager.GetCVar(CCVars.LobbyMusicEnabled))
return;

var file = _gameTicker.LobbySong;
Expand All @@ -124,18 +126,21 @@ public void StartLobbyMusic()
return;
}

LobbyStream = _audio.PlayGlobal(file, Filter.Local(), false,
LobbyMusicStream = _audio.PlayGlobal(
file,
Filter.Local(),
false,
_lobbyParams.WithVolume(_lobbyParams.Volume + SharedAudioSystem.GainToVolume(_configManager.GetCVar(CCVars.LobbyMusicVolume))))?.Entity;
}

private void EndLobbyMusic()
{
LobbyStream = _audio.Stop(LobbyStream);
LobbyMusicStream = _audio.Stop(LobbyMusicStream);
}

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

var file = _gameTicker.RestartSound;
Expand All @@ -144,10 +149,11 @@ private void PlayRestartSound(RoundRestartCleanupEvent ev)
return;
}

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

_audio.PlayGlobal(file, Filter.Local(), false, volume);
LobbyRoundRestartAudioStream = _audio.PlayGlobal(
file,
Filter.Local(),
false,
_roundEndParams.WithVolume(_roundEndParams.Volume + SharedAudioSystem.GainToVolume(_configManager.GetCVar(CCVars.LobbyMusicVolume)))
)?.Entity;
}
}
19 changes: 14 additions & 5 deletions Content.Client/Audio/ContentAudioSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,24 @@ private void OnRoundCleanup(RoundRestartCleanupEvent ev)
_fadingOut.Clear();

// Preserve lobby music but everything else should get dumped.
var lobbyStream = EntityManager.System<BackgroundAudioSystem>().LobbyStream;
TryComp(lobbyStream, out AudioComponent? audioComp);
var oldGain = audioComp?.Gain;
var lobbyMusic = EntityManager.System<BackgroundAudioSystem>().LobbyMusicStream;
TryComp(lobbyMusic, out AudioComponent? lobbyMusicComp);
var oldMusicGain = lobbyMusicComp?.Gain;

var restartAudio = EntityManager.System<BackgroundAudioSystem>().LobbyRoundRestartAudioStream;
TryComp(restartAudio, out AudioComponent? restartComp);
var oldAudioGain = restartComp?.Gain;

SilenceAudio();

if (oldGain != null)
if (oldMusicGain != null)
{
Audio.SetGain(lobbyMusic, oldMusicGain.Value, lobbyMusicComp);
}

if (oldAudioGain != null)
{
Audio.SetGain(lobbyStream, oldGain.Value, audioComp);
Audio.SetGain(restartAudio, oldAudioGain.Value, restartComp);
}
}

Expand Down
10 changes: 5 additions & 5 deletions Content.Client/CartridgeLoader/Cartridges/LogProbeUiEntry.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
Orientation="Vertical">
<BoxContainer Orientation="Horizontal">
<Label Name="NumberLabel"
Align="Center"
SetWidth="60"
Align="Right"
SetWidth="26"
ClipText="True"/>
<Label Name="TimeLabel"
Align="Center"
SetWidth="280"
SetWidth="100"
ClipText="True"/>
<Label Name="AccessorLabel"
Align="Center"
SetWidth="110"
Align="Left"
SetWidth="390"
ClipText="True"/>
</BoxContainer>
<customControls:HSeparator Margin="0 5 0 5"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
BorderColor="#5a5a5a"
BorderThickness="0 0 0 1"/>
</PanelContainer.PanelOverride>
<BoxContainer Orientation="Horizontal" Align="Center" Margin="8">
<Label HorizontalExpand="True" Text="{Loc 'log-probe-label-number'}"/>
<Label HorizontalExpand="True" Text="{Loc 'log-probe-label-time'}"/>
<Label HorizontalExpand="True" Text="{Loc 'log-probe-label-accessor'}"/>
<BoxContainer Orientation="Horizontal" Margin="4 8">
<Label Align="Right" SetWidth="26" ClipText="True" Text="{Loc 'log-probe-label-number'}"/>
<Label Align="Center" SetWidth="100" ClipText="True" Text="{Loc 'log-probe-label-time'}"/>
<Label Align="Left" SetWidth="390" ClipText="True" Text="{Loc 'log-probe-label-accessor'}"/>
</BoxContainer>
</PanelContainer>
<ScrollContainer VerticalExpand="True" HScrollEnabled="True">
Expand Down
13 changes: 1 addition & 12 deletions Content.Client/Chat/UI/SpeechBubble.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,20 +182,9 @@ protected FormattedMessage FormatSpeech(string message, Color? fontColor = null)
return msg;
}

protected string ExtractSpeechSubstring(ChatMessage message, string tag)
{
var rawmsg = message.WrappedMessage;
var tagStart = rawmsg.IndexOf($"[{tag}]");
var tagEnd = rawmsg.IndexOf($"[/{tag}]");
if (tagStart < 0 || tagEnd < 0) //the above return -1 if the tag's not found, which in turn will cause the below to throw an exception. a blank speech bubble is far more noticeably broken than the bubble not appearing at all -bhijn
return "";
tagStart += tag.Length + 2;
return rawmsg.Substring(tagStart, tagEnd - tagStart);
}

protected FormattedMessage ExtractAndFormatSpeechSubstring(ChatMessage message, string tag, Color? fontColor = null)
{
return FormatSpeech(ExtractSpeechSubstring(message, tag), fontColor);
return FormatSpeech(SharedChatSystem.GetStringInsideTag(message, tag), fontColor);
}

}
Expand Down
15 changes: 15 additions & 0 deletions Content.Client/CriminalRecords/CrimeHistoryWindow.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<controls:FancyWindow xmlns="https://spacestation14.io"
xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls"
Title="{Loc 'criminal-records-console-crime-history'}"
MinSize="660 400">
<BoxContainer Orientation="Vertical" HorizontalExpand="True" Margin="5">
<BoxContainer Name="Editing" Orientation="Horizontal" HorizontalExpand="True" Align="Center" Margin="5">
<Button Name="AddButton" Text="{Loc 'criminal-records-add-history'}"/>
<Button Name="DeleteButton" Text="{Loc 'criminal-records-delete-history'}" Disabled="True"/>
</BoxContainer>
<Label Name="NoHistory" Text="{Loc 'criminal-records-no-history'}" HorizontalExpand="True" HorizontalAlignment="Center"/>
<ScrollContainer VerticalExpand="True">
<ItemList Name="History"/> <!-- Populated when window opened -->
</ScrollContainer>
</BoxContainer>
</controls:FancyWindow>
107 changes: 107 additions & 0 deletions Content.Client/CriminalRecords/CrimeHistoryWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
using Content.Shared.Administration;
using Content.Shared.CriminalRecords;
using Content.Client.UserInterface.Controls;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.XAML;

namespace Content.Client.CriminalRecords;

/// <summary>
/// Window opened when Crime History button is pressed
/// </summary>
[GenerateTypedNameReferences]
public sealed partial class CrimeHistoryWindow : FancyWindow
{
public Action<string>? OnAddHistory;
public Action<uint>? OnDeleteHistory;

private uint _maxLength;
private uint? _index;
private DialogWindow? _dialog;

public CrimeHistoryWindow(uint maxLength)
{
RobustXamlLoader.Load(this);

_maxLength = maxLength;

OnClose += () =>
{
_dialog?.Close();
// deselect so when reopening the window it doesnt try to use invalid index
_index = null;
};

AddButton.OnPressed += _ =>
{
if (_dialog != null)
{
_dialog.MoveToFront();
return;
}

var field = "line";
var prompt = Loc.GetString("criminal-records-console-reason");
var placeholder = Loc.GetString("criminal-records-history-placeholder");
var entry = new QuickDialogEntry(field, QuickDialogEntryType.LongText, prompt, placeholder);
var entries = new List<QuickDialogEntry> { entry };
_dialog = new DialogWindow(Title!, entries);

_dialog.OnConfirmed += responses =>
{
var line = responses[field];
if (line.Length < 1 || line.Length > _maxLength)
return;

OnAddHistory?.Invoke(line);
// adding deselects so prevent deleting yeah
_index = null;
DeleteButton.Disabled = true;
};

// prevent MoveToFront being called on a closed window and double closing
_dialog.OnClose += () => { _dialog = null; };
};
DeleteButton.OnPressed += _ =>
{
if (_index is not {} index)
return;

OnDeleteHistory?.Invoke(index);
// prevent total spam wiping
History.ClearSelected();
_index = null;
DeleteButton.Disabled = true;
};

History.OnItemSelected += args =>
{
_index = (uint) args.ItemIndex;
DeleteButton.Disabled = false;
};
History.OnItemDeselected += args =>
{
_index = null;
DeleteButton.Disabled = true;
};
}

public void UpdateHistory(CriminalRecord record, bool access)
{
History.Clear();
Editing.Visible = access;

NoHistory.Visible = record.History.Count == 0;

foreach (var entry in record.History)
{
var time = entry.AddTime;
var line = $"{time.Hours:00}:{time.Minutes:00}:{time.Seconds:00} - {entry.Crime}";
History.AddItem(line);
}

// deselect if something goes wrong
if (_index is {} index && record.History.Count >= index)
_index = null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
using Content.Shared.Access.Systems;
using Content.Shared.CriminalRecords;
using Content.Shared.CriminalRecords.Components;
using Content.Shared.Security;
using Content.Shared.StationRecords;
using Robust.Client.Player;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;

namespace Content.Client.CriminalRecords;

public sealed class CriminalRecordsConsoleBoundUserInterface : BoundUserInterface
{
[Dependency] private readonly IPrototypeManager _proto = default!;
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly IPlayerManager _playerManager = default!;
private readonly AccessReaderSystem _accessReader;

private CriminalRecordsConsoleWindow? _window;
private CrimeHistoryWindow? _historyWindow;

public CriminalRecordsConsoleBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
{
_accessReader = EntMan.System<AccessReaderSystem>();
}

protected override void Open()
{
base.Open();

var comp = EntMan.GetComponent<CriminalRecordsConsoleComponent>(Owner);

_window = new(Owner, comp.MaxStringLength, _playerManager, _proto, _random, _accessReader);
_window.OnKeySelected += key =>
SendMessage(new SelectStationRecord(key));
_window.OnFiltersChanged += (type, filterValue) =>
SendMessage(new SetStationRecordFilter(type, filterValue));
_window.OnStatusSelected += status =>
SendMessage(new CriminalRecordChangeStatus(status, null));
_window.OnDialogConfirmed += (_, reason) =>
SendMessage(new CriminalRecordChangeStatus(SecurityStatus.Wanted, reason));
_window.OnHistoryUpdated += UpdateHistory;
_window.OnHistoryClosed += () => _historyWindow?.Close();
_window.OnClose += Close;

_historyWindow = new(comp.MaxStringLength);
_historyWindow.OnAddHistory += line => SendMessage(new CriminalRecordAddHistory(line));
_historyWindow.OnDeleteHistory += index => SendMessage(new CriminalRecordDeleteHistory(index));

_historyWindow.Close(); // leave closed until user opens it
}

/// <summary>
/// Updates or opens a new history window.
/// </summary>
private void UpdateHistory(CriminalRecord record, bool access, bool open)
{
_historyWindow!.UpdateHistory(record, access);

if (open)
_historyWindow.OpenCentered();
}

protected override void UpdateState(BoundUserInterfaceState state)
{
base.UpdateState(state);

if (state is not CriminalRecordsConsoleState cast)
return;

_window?.UpdateState(cast);
}

protected override void Dispose(bool disposing)
{
base.Dispose(disposing);

_window?.Close();
_historyWindow?.Close();
}
}
Loading

0 comments on commit baa1216

Please sign in to comment.