Skip to content

Commit

Permalink
Merge branch 'master' into ExperimantalLanguage
Browse files Browse the repository at this point in the history
  • Loading branch information
FoxxoTrystan authored Jul 4, 2024
2 parents 86f0c86 + febd6c7 commit 3a11030
Show file tree
Hide file tree
Showing 250 changed files with 8,027 additions and 1,684 deletions.
45 changes: 45 additions & 0 deletions Content.Client/Consent/ClientConsentManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using Content.Shared.Consent;
using Robust.Shared.Network;

namespace Content.Client.Consent;

public sealed class ClientConsentManager : IClientConsentManager
{
[Dependency] private readonly IClientNetManager _netManager = default!;

// TODO: sync all players consent settings with ServerConsentManager, for client prediction
private PlayerConsentSettings? _consent;

public bool HasLoaded => _consent is not null;

public event Action? OnServerDataLoaded;

public void Initialize()
{
_netManager.RegisterNetMessage<MsgUpdateConsent>(HandleUpdateConsent);
}

public void UpdateConsent(PlayerConsentSettings consentSettings)
{
var msg = new MsgUpdateConsent
{
Consent = consentSettings
};
_netManager.ClientSendMessage(msg);
}

public PlayerConsentSettings GetConsent()
{
if (_consent is null)
throw new InvalidOperationException("Consent settings not loaded yet?");

return _consent;
}

private void HandleUpdateConsent(MsgUpdateConsent message)
{
_consent = message.Consent;

OnServerDataLoaded?.Invoke();
}
}
7 changes: 7 additions & 0 deletions Content.Client/Consent/ConsentSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
using Content.Shared.Consent;

namespace Content.Client.Consent;

public sealed class ConsentSystem : SharedConsentSystem
{
}
13 changes: 13 additions & 0 deletions Content.Client/Consent/IClientConsentManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Content.Shared.Consent;

namespace Content.Client.Consent;

public interface IClientConsentManager
{
event Action OnServerDataLoaded;
bool HasLoaded { get; }

void Initialize();
void UpdateConsent(PlayerConsentSettings consentSettings);
PlayerConsentSettings GetConsent();
}
102 changes: 102 additions & 0 deletions Content.Client/Consent/UI/ConsentUiController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
using Content.Client.Consent.UI.Windows;
using Content.Client.Gameplay;
using Content.Client.UserInterface.Controls;
using Content.Client.UserInterface.Systems.MenuBar.Widgets;
using Content.Shared.Input;
using Robust.Client.Input;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controllers;
using Robust.Client.UserInterface.Controllers.Implementations;
using Robust.Shared.Input.Binding;
using Robust.Shared.Map;
using Robust.Shared.Player;
using Robust.Shared.Utility;
using JetBrains.Annotations;
using static Robust.Client.UserInterface.Controls.BaseButton;

namespace Content.Client.Consent.UI;

[UsedImplicitly]
public sealed class ConsentUiController : UIController, IOnStateChanged<GameplayState>
{
[Dependency] private readonly IInputManager _input = default!;

private ConsentWindow? _window;

private MenuButton? ConsentButton => UIManager.GetActiveUIWidgetOrNull<GameTopMenuBar>()?.ConsentButton;

public void OnStateEntered(GameplayState state)
{
EnsureWindow();

_input.SetInputCommand(ContentKeyFunctions.OpenConsentWindow,
InputCmdHandler.FromDelegate(_ => ToggleWindow()));
}

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

public void UnloadButton()
{
if (ConsentButton == null)
{
return;
}

ConsentButton.OnPressed -= ConsentButtonPressed;
}

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

ConsentButton.OnPressed += ConsentButtonPressed;
}

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

private void EnsureWindow()
{
if (_window is { Disposed: false })
return;

_window = UIManager.CreateWindow<ConsentWindow>();
_window.OnOpen += () => {
if (ConsentButton is not null)
ConsentButton.Pressed = true;
};
_window.OnClose += () => {
if (ConsentButton is not null)
ConsentButton.Pressed = false;
_window.UpdateUi(); // Discard unsaved changes
};
}

private void ToggleWindow()
{
if (_window is null)
return;

UIManager.ClickSound();
if (_window.IsOpen != true)
{
_window.OpenCentered();
}
else
{
_window.Close();
}
}
}
63 changes: 63 additions & 0 deletions Content.Client/Consent/UI/Windows/ConsentWindow.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<controls:FancyWindow
xmlns="https://spacestation14.io"
xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:gfx="clr-namespace:Robust.Client.Graphics;assembly=Robust.Client"
MinSize="620 670"
Title="{Loc consent-window-title}"
Resizable="False">
<BoxContainer Orientation="Vertical" HorizontalExpand="True" Margin="5">
<Label Text="{Loc consent-window-text}" />
<BoxContainer Orientation="Horizontal" Margin="5">
<Label Name="SaveLabel" FontColorOverride="Red" Access="Public" />
<Control HorizontalExpand="True" />
<Button
Name="SaveConsentSettings"
Access="Public"
Text="Save"
Disabled="True" />
</BoxContainer>
<Label Text="{Loc consent-window-freetext-label}" />
<PanelContainer HorizontalExpand="True" VerticalExpand="True" MinWidth="200">
<PanelContainer.PanelOverride>
<gfx:StyleBoxFlat BackgroundColor="#1B1B1E" />
</PanelContainer.PanelOverride>
<TextEdit
Name="ConsentFreetext"
Access="Public"
MinHeight="100"
VerticalExpand="True" />
</PanelContainer>
<Control MinSize="0 10" />
<Label Text="{Loc consent-window-toggles-label}" />

<!-- TODO: Generate these in code by iterating prototypes? -->
<!-- Example Consent Toggle -->
<PanelContainer HorizontalExpand="True" MinWidth="200">
<PanelContainer.PanelOverride>
<gfx:StyleBoxFlat BackgroundColor="#1B1B1E" />
</PanelContainer.PanelOverride>
<BoxContainer Orientation="Vertical" HorizontalExpand="True" Margin="5">
<BoxContainer Orientation="Horizontal" Margin="5">
<Label Text="{Loc consent-example1}" />
<Control HorizontalExpand="True" />
<Button
Name="ConsentToggleExample1Off"
ToggleMode="True"
Access="Public"
Text="Off"
StyleClasses="OpenRight" />
<Button
Name="ConsentToggleExample1On"
ToggleMode="True"
Access="Public"
Text="On"
StyleClasses="OpenLeft" />
</BoxContainer>
<Label Text="{Loc consent-example1-desc}" />
</BoxContainer>
</PanelContainer>


</BoxContainer>
</controls:FancyWindow>
101 changes: 101 additions & 0 deletions Content.Client/Consent/UI/Windows/ConsentWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
using Content.Client.UserInterface.Controls;
using Content.Shared.CCVar;
using Content.Shared.Consent;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.CustomControls;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Configuration;
using Robust.Shared.Prototypes;
using Robust.Shared.Utility;

namespace Content.Client.Consent.UI.Windows;

[GenerateTypedNameReferences]
public sealed partial class ConsentWindow : FancyWindow
{
[Dependency] private readonly IClientConsentManager _consentManager = default!;
[Dependency] private readonly IConfigurationManager _configManager = default!;

private ButtonGroup Example1Buttons;

public ConsentWindow()
{
RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this);

SaveConsentSettings.OnPressed += _ => {
SaveConsentSettings.Disabled = true;
_consentManager.UpdateConsent(GetSettings());
};

_consentManager.OnServerDataLoaded += UpdateUi;
if (_consentManager.HasLoaded)
UpdateUi();

ConsentFreetext.Placeholder = new Rope.Leaf(Loc.GetString("consent-window-freetext-placeholder"));
ConsentFreetext.OnTextChanged += _ => UnsavedChanges();

Example1Buttons = new ButtonGroup();
ConsentToggleExample1On.Group = Example1Buttons;
ConsentToggleExample1On.OnToggled += _ => UnsavedChanges();
ConsentToggleExample1Off.Group = Example1Buttons;
ConsentToggleExample1Off.OnToggled += _ => UnsavedChanges();
}

private PlayerConsentSettings GetSettings()
{
var text = Rope.Collapse(ConsentFreetext.TextRope);
var toggles = new Dictionary<ProtoId<ConsentTogglePrototype>, string>();

if (Example1Buttons.Pressed == ConsentToggleExample1On)
{
toggles["Example1"] = "on";
}

return new(text, toggles);
}

private void UnsavedChanges()
{
// Validate freetext length
var maxLength = _configManager.GetCVar(CCVars.ConsentFreetextMaxLength);
var length = Rope.Collapse(ConsentFreetext.TextRope).Length;

if (length > maxLength)
{
SaveLabel.Text = Loc.GetString("consent-window-char-limit-warning", ("length", length), ("maxLength", maxLength));
SaveConsentSettings.Disabled = true;

return;
}

// If everything is valid, enable save button and inform user they need to save.
SaveLabel.Text = Loc.GetString("consent-window-unsaved-changes");
SaveConsentSettings.Disabled = false;
}

public void UpdateUi()
{
var consent = _consentManager.GetConsent();

ConsentToggleExample1Off.Pressed = true;

ConsentFreetext.TextRope = new Rope.Leaf(consent.Freetext);
foreach (var toggle in consent.Toggles)
{
if (toggle.Key == "Example1" && toggle.Value == "on")
{
ConsentToggleExample1On.Pressed = true;
}
else
{
throw new InvalidOperationException("Invalid consent toggle");
}
}

SaveConsentSettings.Disabled = true;
SaveLabel.Text = "";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,6 @@ public override Control GetUIFragmentRoot()
public override void Setup(BoundUserInterface userInterface, EntityUid? fragmentOwner)
{
_fragment = new CrimeAssistUiFragment();

_fragment.OnSync += _ => SendSyncMessage(userInterface);
}

private void SendSyncMessage(BoundUserInterface userInterface)
{
var syncMessage = new CrimeAssistSyncMessageEvent();
var message = new CartridgeUiMessage(syncMessage);
userInterface.SendMessage(message);
}

public override void UpdateState(BoundUserInterfaceState state)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Content.Client.Message;
using Content.Shared.DeltaV.CartridgeLoader.Cartridges;
using Robust.Client.AutoGenerated;
using Robust.Client.ResourceManagement;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Prototypes;
Expand All @@ -13,9 +12,7 @@ namespace Content.Client.DeltaV.CartridgeLoader.Cartridges;
public sealed partial class CrimeAssistUiFragment : BoxContainer
{
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly IResourceCache _resourceCache = default!;

public event Action<bool>? OnSync;
private CrimeAssistPage _currentPage;
private List<CrimeAssistPage>? _pages;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<BoxContainer xmlns="https://spacestation14.io"
xmlns:cartridges="clr-namespace:Content.Client.DeltaV.CartridgeLoader.Cartridges"
xmlns:customControls="clr-namespace:Content.Client.Administration.UI.CustomControls"
HorizontalExpand="True"
VerticalExpand="True"
Margin="5">
<!-- All labels populated in constructor -->
<BoxContainer Orientation="Horizontal" HorizontalAlignment="Left">
<BoxContainer Orientation="Vertical">
<Label Name="Status"/>
<Label Text="{Loc 'criminal-records-console-reason'}"/>
</BoxContainer>
<customControls:VSeparator StyleClasses="LowDivider" Margin="8 0"/>
<BoxContainer Orientation="Vertical">
<Label Name="Title"/>
<Label Name="Reason"/>
</BoxContainer>
</BoxContainer>
</BoxContainer>
Loading

0 comments on commit 3a11030

Please sign in to comment.