Skip to content

Commit

Permalink
Merge pull request Simple-Station#22 from VMSolidus/upstream-merge-6/…
Browse files Browse the repository at this point in the history
…10/2024

Upstream merge 6/10/2024
  • Loading branch information
VMSolidus committed Jun 11, 2024
2 parents 2633ac1 + 68c8a3a commit bc84a0e
Show file tree
Hide file tree
Showing 208 changed files with 2,267 additions and 532 deletions.
85 changes: 48 additions & 37 deletions Content.Client/Language/LanguageMenuWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Console;
using Robust.Shared.Utility;
using Serilog;
using static Content.Shared.Language.Systems.SharedLanguageSystem;

namespace Content.Client.Language;
Expand All @@ -23,6 +24,15 @@ public LanguageMenuWindow()
_clientLanguageSystem = IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<LanguageSystem>();
}

protected override void Opened()
{
// Refresh the window when it gets opened.
// This actually causes two refreshes: one immediately, and one after the server sends a state message.
UpdateState(_clientLanguageSystem.CurrentLanguage, _clientLanguageSystem.SpokenLanguages);
_clientLanguageSystem.RequestStateUpdate();
}


public void UpdateState(string currentLanguage, List<string> spokenLanguages)
{
var langName = Loc.GetString($"language-{currentLanguage}-name");
Expand All @@ -46,55 +56,55 @@ public void UpdateState(string currentLanguage, List<string> spokenLanguages)

private void AddLanguageEntry(string language)
{
var proto = _clientLanguageSystem.GetLanguage(language);
var proto = _clientLanguageSystem.GetLanguagePrototype(language);
var state = new EntryState { language = language };

var container = new BoxContainer();
container.Orientation = BoxContainer.LayoutOrientation.Vertical;
var container = new BoxContainer { Orientation = BoxContainer.LayoutOrientation.Vertical };

// Create and add a header with the name and the button to select the language
#region Header
var header = new BoxContainer
{
var header = new BoxContainer();
header.Orientation = BoxContainer.LayoutOrientation.Horizontal;
Orientation = BoxContainer.LayoutOrientation.Horizontal,
HorizontalExpand = true,
SeparationOverride = 2
};

header.Orientation = BoxContainer.LayoutOrientation.Horizontal;
header.HorizontalExpand = true;
header.SeparationOverride = 2;
var name = new Label
{
Text = proto?.Name ?? Loc.GetString("generic-error"),
MinWidth = 50,
HorizontalExpand = true
};

var name = new Label();
name.Text = proto?.Name ?? "<error>";
name.MinWidth = 50;
name.HorizontalExpand = true;
var button = new Button { Text = "Choose" };
button.OnPressed += _ => OnLanguageChosen(language);
state.button = button;

var button = new Button();
button.Text = "Choose";
button.OnPressed += _ => OnLanguageChosen(language);
state.button = button;
header.AddChild(name);
header.AddChild(button);

header.AddChild(name);
header.AddChild(button);
container.AddChild(header);
#endregion

container.AddChild(header);
}

// Create and add a collapsible description
#region Collapsible description
var body = new CollapsibleBody
{
var body = new CollapsibleBody();
body.HorizontalExpand = true;
body.Margin = new Thickness(4f, 4f);
HorizontalExpand = true,
Margin = new Thickness(4f, 4f)
};

var description = new RichTextLabel();
description.SetMessage(proto?.Description ?? "<error>");
description.HorizontalExpand = true;
var description = new RichTextLabel { HorizontalExpand = true };
description.SetMessage(proto?.Description ?? Loc.GetString("generic-error"));
body.AddChild(description);

body.AddChild(description);
var collapser = new Collapsible(Loc.GetString("language-menu-description-header"), body)
{
Orientation = BoxContainer.LayoutOrientation.Vertical,
HorizontalExpand = true
};

var collapser = new Collapsible(Loc.GetString("language-menu-description-header"), body);
collapser.Orientation = BoxContainer.LayoutOrientation.Vertical;
collapser.HorizontalExpand = true;

container.AddChild(collapser);
}
container.AddChild(collapser);
#endregion

// Before adding, wrap the new container in a PanelContainer to give it a distinct look
var wrapper = new PanelContainer();
Expand All @@ -106,9 +116,10 @@ private void AddLanguageEntry(string language)
_entries.Add(state);
}


private void OnLanguageChosen(string id)
{
var proto = _clientLanguageSystem.GetLanguage(id);
var proto = _clientLanguageSystem.GetLanguagePrototype(id);
if (proto != null)
_clientLanguageSystem.RequestSetLanguage(proto);
}
Expand Down
35 changes: 22 additions & 13 deletions Content.Client/Language/Systems/LanguageSystem.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Content.Shared.Language;
using Content.Shared.Language.Events;
using Content.Shared.Language.Systems;
using Robust.Client;
using Robust.Shared.Console;

namespace Content.Client.Language.Systems;
Expand All @@ -14,6 +15,8 @@ namespace Content.Client.Language.Systems;
/// </remarks>
public sealed class LanguageSystem : SharedLanguageSystem
{
[Dependency] private readonly IBaseClient _client = default!;

/// <summary>
/// The current language of the entity currently possessed by the player.
/// </summary>
Expand All @@ -27,11 +30,26 @@ public sealed class LanguageSystem : SharedLanguageSystem
/// </summary>
public List<string> UnderstoodLanguages { get; private set; } = new();

[Dependency] private readonly IConsoleHost _consoleHost = default!;

public override void Initialize()
{
base.Initialize();

SubscribeNetworkEvent<LanguagesUpdatedMessage>(OnLanguagesUpdated);
_client.RunLevelChanged += OnRunLevelChanged;
}

private void OnLanguagesUpdated(LanguagesUpdatedMessage message)
{
CurrentLanguage = message.CurrentLanguage;
SpokenLanguages = message.Spoken;
UnderstoodLanguages = message.Understood;
}

private void OnRunLevelChanged(object? sender, RunLevelChangedEventArgs args)
{
// Request an update when entering a game
if (args.NewLevel == ClientRunLevel.InGame)
RequestStateUpdate();
}

/// <summary>
Expand All @@ -45,23 +63,14 @@ public void RequestStateUpdate()

public void RequestSetLanguage(LanguagePrototype language)
{
// May cause some minor desync...
if (language.ID == CurrentLanguage)
return;

// (This is dumb. This is very dumb. It should be a message instead.)
// TODO Change this, soonish
_consoleHost.ExecuteCommand("languageselect " + language.ID);
RaiseNetworkEvent(new LanguagesSetMessage(language.ID));

// May cause some minor desync...
// So to reduce the probability of desync, we replicate the change locally too
if (SpokenLanguages.Contains(language.ID))
CurrentLanguage = language.ID;
}

private void OnLanguagesUpdated(LanguagesUpdatedMessage message)
{
CurrentLanguage = message.CurrentLanguage;
SpokenLanguages = message.Spoken;
UnderstoodLanguages = message.Understood;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,32 @@ namespace Content.Client.UserInterface.Systems.Language;
[UsedImplicitly]
public sealed class LanguageMenuUIController : UIController, IOnStateEntered<GameplayState>, IOnStateExited<GameplayState>
{
public LanguageMenuWindow? _languageWindow;
public LanguageMenuWindow? LanguageWindow;
private MenuButton? LanguageButton => UIManager.GetActiveUIWidgetOrNull<MenuBar.Widgets.GameTopMenuBar>()?.LanguageButton;

public override void Initialize()
{
SubscribeNetworkEvent((LanguagesUpdatedMessage message, EntitySessionEventArgs args) => _languageWindow?.UpdateState(message.CurrentLanguage, message.Spoken));
SubscribeNetworkEvent((LanguagesUpdatedMessage message, EntitySessionEventArgs _) =>
LanguageWindow?.UpdateState(message.CurrentLanguage, message.Spoken));
}

public void OnStateEntered(GameplayState state)
{
DebugTools.Assert(_languageWindow == null);
DebugTools.Assert(LanguageWindow == null);

_languageWindow = UIManager.CreateWindow<LanguageMenuWindow>();
LayoutContainer.SetAnchorPreset(_languageWindow, LayoutContainer.LayoutPreset.CenterTop);
LanguageWindow = UIManager.CreateWindow<LanguageMenuWindow>();
LayoutContainer.SetAnchorPreset(LanguageWindow, LayoutContainer.LayoutPreset.CenterTop);

CommandBinds.Builder.Bind(ContentKeyFunctions.OpenLanguageMenu, InputCmdHandler.FromDelegate(_ => ToggleWindow())).Register<LanguageMenuUIController>();
CommandBinds.Builder.Bind(ContentKeyFunctions.OpenLanguageMenu,
InputCmdHandler.FromDelegate(_ => ToggleWindow())).Register<LanguageMenuUIController>();
}

public void OnStateExited(GameplayState state)
{
if (_languageWindow != null)
if (LanguageWindow != null)
{
_languageWindow.Dispose();
_languageWindow = null;
LanguageWindow.Dispose();
LanguageWindow = null;
}

CommandBinds.Unregister<LanguageMenuUIController>();
Expand All @@ -47,61 +49,41 @@ public void OnStateExited(GameplayState state)
public void UnloadButton()
{
if (LanguageButton == null)
{
return;
}

LanguageButton.OnPressed -= LanguageButtonPressed;
}

public void LoadButton()
{
if (LanguageButton == null)
{
return;
}

LanguageButton.OnPressed += LanguageButtonPressed;

if (_languageWindow == null)
{
if (LanguageWindow == null)
return;
}

_languageWindow.OnClose += DeactivateButton;
_languageWindow.OnOpen += ActivateButton;
LanguageWindow.OnClose += () => LanguageButton.Pressed = false;
LanguageWindow.OnOpen += () => LanguageButton.Pressed = true;
}

private void DeactivateButton() => LanguageButton!.Pressed = false;
private void ActivateButton() => LanguageButton!.Pressed = true;

private void LanguageButtonPressed(ButtonEventArgs args)
{
ToggleWindow();
}

private void CloseWindow()
{
_languageWindow?.Close();
}

private void ToggleWindow()
{
if (_languageWindow == null)
if (LanguageWindow == null)
return;

if (LanguageButton != null)
{
LanguageButton.SetClickPressed(!_languageWindow.IsOpen);
}
LanguageButton.SetClickPressed(!LanguageWindow.IsOpen);

if (_languageWindow.IsOpen)
{
CloseWindow();
}
if (LanguageWindow.IsOpen)
LanguageWindow.Close();
else
{
_languageWindow.Open();
}
LanguageWindow.Open();
}
}
12 changes: 12 additions & 0 deletions Content.Server/Abilities/Mime/MimePowersComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,17 @@ public sealed partial class MimePowersComponent : Component
/// </summary>
[DataField("vowCooldown")]
public TimeSpan VowCooldown = TimeSpan.FromMinutes(5);

/// <summary
/// Psionic Feedback for if a mime with their vow intact is scanned by a Mantis
/// </summary>
[DataField("mimeFeedback")]
public string MimeFeedback = "mime-feedback";

/// <summary
/// Psionic Feedback for if a mime with their vow intact is scanned by a Mantis
/// </summary>
[DataField("mimeBrokenFeedback")]
public string MimeBrokenFeedback = "mime-broken-feedback";
}
}
Loading

0 comments on commit bc84a0e

Please sign in to comment.