Skip to content

Commit

Permalink
Merge branch 'SerbiaStrong-220:master' into OkroshkaMedalsResprite
Browse files Browse the repository at this point in the history
  • Loading branch information
Kiiwwwie authored Jan 29, 2025
2 parents 32fd5d4 + 8b3149d commit 8078e9a
Show file tree
Hide file tree
Showing 56 changed files with 606 additions and 195 deletions.
15 changes: 15 additions & 0 deletions Content.Client/Paper/UI/PaperBoundUserInterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Robust.Shared.Utility;
using Content.Shared.Paper;
using static Content.Shared.Paper.PaperComponent;
using Content.Shared.SS220.Paper;

namespace Content.Client.Paper.UI;

Expand All @@ -24,6 +25,10 @@ protected override void Open()
_window = this.CreateWindow<PaperWindow>();
_window.OnSaved += InputOnTextEntered;

// SS220 Document helper begin
_window.DocumentHelper.OnButtonPressed += args => _window.InsertAtCursor(args);
// SS220 Document helper end

if (EntMan.TryGetComponent<PaperComponent>(Owner, out var paper))
{
_window.MaxInputLength = paper.ContentSize;
Expand All @@ -40,6 +45,16 @@ protected override void UpdateState(BoundUserInterfaceState state)
_window?.Populate((PaperBoundUserInterfaceState) state);
}

// SS220 Document Helper begin
protected override void ReceiveMessage(BoundUserInterfaceMessage message)
{
base.ReceiveMessage(message);

if (message is DocumentHelperOptionsMessage optionsMessage)
_window?.DocumentHelper.UpdateState(optionsMessage);
}
// SS220 Document Helper end

private void InputOnTextEntered(string text)
{
SendMessage(new PaperInputTextMessage(text));
Expand Down
8 changes: 8 additions & 0 deletions Content.Client/Paper/UI/PaperWindow.xaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
<paper:PaperWindow xmlns="https://spacestation14.io"
xmlns:paper="clr-namespace:Content.Client.Paper.UI"
xmlns:paper220="clr-namespace:Content.Client.SS220.Paper.UI"
MouseFilter="Stop" Resizable="True" MinSize="150 150"
SetSize="510 660"> <!-- Provide some reasonable sizes by default. Can be changed by the component -->

<!-- SS220 Document helper begin -->
<BoxContainer Orientation="Horizontal">
<Control HorizontalExpand="True" />
<paper220:DocumentHelperWindow Name="DocumentHelper" Access="Public" HorizontalAlignment="Left" VerticalAlignment="Bottom" Margin="0 80"/>
</BoxContainer>
<!-- SS220 Document helper end -->

<BoxContainer Name="ContentsRoot" Orientation="Vertical">
<PanelContainer StyleClasses="AngleRect" VerticalAlignment="Top" HorizontalAlignment="Right" Margin="6">
<TextureButton Name="CloseButton" StyleClasses="windowCloseButton"/>
Expand Down
8 changes: 8 additions & 0 deletions Content.Client/Paper/UI/PaperWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ public void Populate(PaperComponent.PaperBoundUserInterfaceState state)
bool wasEditing = InputContainer.Visible;
InputContainer.Visible = isEditing;
EditButtons.Visible = isEditing;
DocumentHelper.Visible = isEditing; // SS220 Document helper

var msg = new FormattedMessage();
msg.AddMarkupPermissive(state.Text);
Expand Down Expand Up @@ -345,5 +346,12 @@ private void UpdateFillState()
SaveButton.Disabled = false;
}
}

// SS220 Document helper begin
public void InsertAtCursor(string value)
{
Input.InsertAtCursor(value);
}
// SS220 Document helper end
}
}
8 changes: 8 additions & 0 deletions Content.Client/SS220/Paper/Systems/DocumentHelperSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// © SS220, An EULA/CLA with a hosting restriction, full text: https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/CLA.txt
using Content.Shared.SS220.Paper;

namespace Content.Client.SS220.Paper.Systems;

public sealed partial class DocumentHelperSystem : SharedDocumentHelperSystem
{
}
20 changes: 20 additions & 0 deletions Content.Client/SS220/Paper/UI/DocumentHelperWindow.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<paper220:DocumentHelperWindow xmlns="https://spacestation14.io"
xmlns:paper220="clr-namespace:Content.Client.SS220.Paper.UI"
SetSize="280 250">
<BoxContainer Name="BodyContainer" Orientation="Horizontal" HorizontalAlignment="Right" MaxWidth="0">
<Control Name="Body" SetSize="280 250" HorizontalAlignment="Left" Margin="6">
<Control Margin="-22" MouseFilter="Pass">
<PanelContainer Name="PaperBackground" StyleClasses="PaperDefaultBorder" VerticalExpand="True" HorizontalExpand="True"/>
</Control>
<BoxContainer Orientation="Vertical" Margin="0 0 18 0">
<RichTextLabel Text="{Loc 'document-helper-prompt'}" Margin="0 0 0 10"/>
<ScrollContainer VerticalExpand="True">
<BoxContainer Name="OptionsContainer" Orientation="Vertical"/>
</ScrollContainer>
</BoxContainer>
<ContainerButton Name="ExpandButton" VerticalExpand="True" SetWidth="32" HorizontalAlignment="Right" Margin="0 0 -16 0">
<TextureRect Name="ExpandIcon" HorizontalAlignment="Center" StyleClasses="ArrowRight"/>
</ContainerButton>
</Control>
</BoxContainer>
</paper220:DocumentHelperWindow>
160 changes: 160 additions & 0 deletions Content.Client/SS220/Paper/UI/DocumentHelperWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
// © SS220, An EULA/CLA with a hosting restriction, full text: https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/CLA.txt
using Content.Client.Resources;
using Content.Client.SS220.Paper.Systems;
using Content.Client.SS220.StyleTools;
using Content.Client.Stylesheets;
using Content.Shared.SS220.Paper;
using Robust.Client.AutoGenerated;
using Robust.Client.Graphics;
using Robust.Client.Player;
using Robust.Client.ResourceManagement;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.XAML;

namespace Content.Client.SS220.Paper.UI;

[GenerateTypedNameReferences]
public sealed partial class DocumentHelperWindow : Control
{
[Dependency] private readonly IEntityManager _entityManager = default!;
[Dependency] private readonly IPlayerManager _player = default!;
[Dependency] private readonly IResourceCache _resourceCache = default!;
[Dependency] private readonly IStylesheetManager _stylesheetManager = default!;

private const string DocumentHelperOptionLocPrefix = "document-helper-option-";

private readonly SharedDocumentHelperSystem _documentHelper;
private readonly Dictionary<DocumentHelperOptions, BoxContainer> _optionContainer = [];
private bool _isExpanded = false;

public event Action<string>? OnButtonPressed;

public DocumentHelperWindow() : this(DocumentHelperOptions.All) { }

public DocumentHelperWindow(DocumentHelperOptions options = DocumentHelperOptions.All)
{
IoCManager.InjectDependencies(this);
RobustXamlLoader.Load(this);

Stylesheet = new DocumentHelperWindowStyle().Create(_stylesheetManager.SheetNano, _resourceCache);

ExpandButton.OnPressed += args =>
{
SetExpanded(!_isExpanded);
};
SetExpanded(_isExpanded);

_documentHelper = _entityManager.System<DocumentHelperSystem>();

var optionValuesPair = _documentHelper.GetOptionValuesPair(options, _player.LocalSession?.AttachedEntity);
GenerateOptions(optionValuesPair);
}

public void GenerateOptions(Dictionary<DocumentHelperOptions, List<string>> optionValuesPair)
{
foreach (var (option, values) in optionValuesPair)
{
BoxContainer container;
if (_optionContainer.TryGetValue(option, out var dictContainer))
{
container = dictContainer;
container.DisposeAllChildren();
}
else
{
container = new BoxContainer
{
Orientation = BoxContainer.LayoutOrientation.Horizontal,
VerticalAlignment = VAlignment.Center,
};

OptionsContainer.AddChild(container);
}

var label = new Label
{
Text = Loc.GetString($"{DocumentHelperOptionLocPrefix + option.ToString().ToLower()}"),
VerticalAlignment = VAlignment.Top,
Margin = new Thickness(0, 6, 0, 0),
};
label.AddStyleClass("OptionLabel");
container.AddChild(label);

var buttonsContainer = new BoxContainer
{
Orientation = BoxContainer.LayoutOrientation.Vertical
};
foreach (var value in values)
{
var button = new Button
{
Text = value
};
button.AddStyleClass("OptionButton");
button.OnPressed += _ => OnButtonPressed?.Invoke(button.Text);
buttonsContainer.AddChild(button);
}
container.AddChild(buttonsContainer);

_optionContainer[option] = container;
}
}

public void UpdateState(DocumentHelperOptionsMessage state)
{
GenerateOptions(state.OptionValuesPair);
}

private void SetExpanded(bool isExpanded)
{
_isExpanded = isExpanded;
BodyContainer.Margin = new Thickness(0, 0, isExpanded ? 0 : SetSize.X - 12, 0);
ExpandIcon.TextureScale = new(isExpanded ? -1 : 1, 1);
}
}

public sealed class DocumentHelperWindowStyle : QuickStyle
{
protected override void CreateRules()
{
var placeholder = new StyleBoxTexture { Texture = Resources.GetTexture("/Textures/Interface/Nano/placeholder.png") };
placeholder.SetPatchMargin(StyleBox.Margin.All, 19);
placeholder.Mode = StyleBoxTexture.StretchMode.Tile;

Builder.Element<Label>()
.Prop("modulate-self", new Color(10, 10, 10));

Builder.Element<RichTextLabel>()
.Prop("modulate-self", new Color(10, 10, 10));

Builder.Element<PanelContainer>().Class("PaperDefaultBorder")
.Prop("modulate-self", Color.TryParse("#e7e4df", out var color) ? color : default);

Builder.Element<TextureRect>().Class("ArrowRight")
.Prop("texture", Tex("/Textures/Interface/Nano/triangle_right_hollow.svg.png"))
.Prop("modulate-self", new Color(10, 10, 10));

Builder.Element<Button>().Class("OptionButton")
.Prop("stylebox", placeholder)
.Prop("SetHeight", 34f)
.Prop("Margin", new Thickness(6, 2));

Builder.Element<Button>().Class("OptionButton")
.Pseudo("normal")
.Prop("modulate-self", Color.White);
Builder.Element<Button>().Class("OptionButton")
.Pseudo("hover")
.Prop("modulate-self", Color.Gray);
Builder.Element<Button>().Class("OptionButton")
.Pseudo("pressed")
.Prop("modulate-self", Color.Black);
Builder.Element<Button>().Class("OptionButton")
.Pseudo("disabled")
.Prop("modulate-self", Color.White);

Builder.Element<Button>().Class("OptionButton")
.Child<Label>()
.Prop("Margin", new Thickness(0, -14));
}
}
17 changes: 15 additions & 2 deletions Content.Client/SS220/StyleTools/StylesheetBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace Content.Client.SS220.StyleTools
public sealed class StylesheetBuilder
{
private readonly List<StyleRule> _rules;
private readonly List<StyleProperty> _props = new();

private MutableSelectorElement? _currentMainSelector;
private MutableSelectorElement? _currentChildSelector;
Expand Down Expand Up @@ -67,7 +68,7 @@ public StylesheetBuilder Pseudo(string name)

public StylesheetBuilder Prop(string key, object value)
{
_currentSelector?.Prop(key, value);
_props.Add(new StyleProperty(key, value));
return this;
}

Expand All @@ -83,14 +84,26 @@ private void EndCurrentRule()
return;
if (_currentChildSelector is null)
{
PushProps(_currentMainSelector);
_rules.Add(_currentMainSelector);
}
else
{
_rules.Add(StylesheetHelpers.Child().Parent(_currentMainSelector).Child(_currentChildSelector));
var selector = StylesheetHelpers.Child().Parent(_currentMainSelector).Child(_currentChildSelector);
PushProps(selector);
_rules.Add(selector);
}
_currentMainSelector = null;
_currentChildSelector = null;
_props.Clear();
}

private void PushProps(MutableSelector selector)
{
foreach (var prop in _props)
{
selector.Prop(prop.Name, prop.Value);
}
}
}
}
47 changes: 47 additions & 0 deletions Content.Server/SS220/Paper/DocumentHelperSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// © SS220, An EULA/CLA with a hosting restriction, full text: https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/CLA.txt

using Content.Server.Station.Systems;
using Content.Shared.Paper;
using Content.Shared.SS220.Paper;
using Robust.Server.GameObjects;
using System.Linq;
using static Content.Shared.Paper.PaperComponent;

namespace Content.Server.SS220.Paper;

public sealed partial class DocumentHelperSystem : SharedDocumentHelperSystem
{
[Dependency] private readonly StationSystem _stationSystem = default!;
[Dependency] private readonly UserInterfaceSystem _ui = default!;

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

#region Ui
public override List<string> GetValuesByOption(DocumentHelperOptions option, EntityUid? uid = null)
{
List<string> values = [];
switch (option)
{
case DocumentHelperOptions.Station:
values = values.Union(_stationSystem.GetStationNames().Select(x => x.Name)).ToList();
break;
default:
values = base.GetValuesByOption(option, uid);
break;
}

return values;
}

public override void UpdateUserInterface(Entity<PaperComponent> entity, EntityUid actor)
{
base.UpdateUserInterface(entity, actor);
var optionValuesPair = GetOptionValuesPair(DocumentHelperOptions.All, actor);
var message = new DocumentHelperOptionsMessage(optionValuesPair);
_ui.ServerSendUiMessage(entity.Owner, PaperUiKey.Key, message, actor);
}
#endregion
}
1 change: 1 addition & 0 deletions Content.Shared/Access/Components/IdCardComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public sealed partial class IdCardComponent : Component
private string? _jobTitle;

[Access(typeof(SharedIdCardSystem), typeof(SharedPdaSystem), typeof(SharedAgentIdCardSystem), Other = AccessPermissions.ReadWriteExecute)]
[ViewVariables, AutoNetworkedField] // SS220 Fix loc job title
public string? LocalizedJobTitle { set => _jobTitle = value; get => _jobTitle ?? Loc.GetString(JobTitle ?? string.Empty); }

/// <summary>
Expand Down
5 changes: 0 additions & 5 deletions Content.Shared/Paper/PaperComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,6 @@ public sealed partial class PaperComponent : Component, IPhotocopyableComponent
[DataField("sound")]
public SoundSpecifier? Sound { get; private set; } = new SoundCollectionSpecifier("PaperScribbles", AudioParams.Default.WithVariation(0.1f));

//SS220 Add auto form
[AutoNetworkedField]
public EntityUid? Writer;
//SS220 Add auto form

public IPhotocopiedComponentData GetPhotocopiedData()
{
return new PaperPhotocopiedData()
Expand Down
Loading

0 comments on commit 8078e9a

Please sign in to comment.