Skip to content

Commit

Permalink
Butt scan refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
TheArturZh committed Jun 25, 2023
1 parent ea25e0a commit 906ca5b
Show file tree
Hide file tree
Showing 10 changed files with 86 additions and 50 deletions.
4 changes: 2 additions & 2 deletions Content.Client/Paper/UI/PaperWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

namespace Content.Client.Paper.UI
{
[GenerateTypedNameReferences]
public sealed partial class PaperWindow : BaseWindow
[GenerateTypedNameReferences, Virtual]
public partial class PaperWindow : BaseWindow
{
// <summary>
// Size of resize handles around the paper
Expand Down
15 changes: 11 additions & 4 deletions Content.Client/SS220/ButtScan/ButtScanBoundUI.cs
Original file line number Diff line number Diff line change
@@ -1,6 +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.Client.Paper;
using Content.Client.SS220.ButtScan.UI;
using Content.Shared.Paper;
using Content.Shared.SS220.ButtScan;
using Robust.Client.GameObjects;

Expand All @@ -22,17 +24,22 @@ public ButtScanBoundUserInterface(ClientUserInterfaceComponent owner, Enum uiKey
/// <inheritdoc/>
protected override void Open()
{
base.Open();

_window = new ButtScanWindow();
_window.OnClose += Close;

if (_entityMgr.TryGetComponent<ButtScanComponent>(_paperEntity, out var scan))
_window.InitVisuals(scan);
if (_entityMgr.TryGetComponent<ButtScanComponent>(_paperEntity, out var scan) &&
_entityMgr.TryGetComponent<PaperVisualsComponent>(_paperEntity, out var paperVisuals))
_window.InitVisuals(scan, paperVisuals);

_window.OpenCentered();
}

protected override void UpdateState(BoundUserInterfaceState state)
{
base.UpdateState(state);
_window?.Populate((SharedPaperComponent.PaperBoundUserInterfaceState) state);
}

protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
Expand Down
21 changes: 5 additions & 16 deletions Content.Client/SS220/ButtScan/UI/ButtScanWindow.xaml
Original file line number Diff line number Diff line change
@@ -1,20 +1,9 @@
<!-- © SS220, An EULA/CLA with a hosting restriction, full text: https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/CLA.txt -->
<ui:ButtScanWindow xmlns="https://spacestation14.io"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:ui="clr-namespace:Content.Client.SS220.ButtScan.UI"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:ui="clr-namespace:Content.Client.SS220.ButtScan.UI"

MouseFilter="Stop"
Resizable="False">

<BoxContainer Name="ContentsRoot" Orientation="Vertical">
<PanelContainer StyleClasses="AngleRect" VerticalAlignment="Top" HorizontalAlignment="Right" Margin="6">
<TextureButton Name="CloseButton" StyleClasses="windowCloseButton"/>
</PanelContainer>

<PanelContainer Name="ScanBackground" StyleClasses="PaperDefaultBorder" VerticalExpand="True" HorizontalExpand="True">
<PanelContainer Name="ScanContent" VerticalExpand="True" HorizontalExpand="True">
<TextureButton Name="ContentsImage" SetSize="300 300" Margin="25 25" HorizontalAlignment="Center" VerticalAlignment="Center" MouseFilter="Ignore"/>
</PanelContainer>
</PanelContainer>
</BoxContainer>
MouseFilter="Stop"
Resizable="False"
SetSize="350 400">
</ui:ButtScanWindow>
50 changes: 43 additions & 7 deletions Content.Client/SS220/ButtScan/UI/ButtScanWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,27 +1,63 @@
// © 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.UserInterface.Controls;
using Content.Client.Paper;
using Content.Client.Paper.UI;
using Content.Shared.Paper;
using Content.Shared.SS220.ButtScan;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.CustomControls;
using Robust.Client.ResourceManagement;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.XAML;

namespace Content.Client.SS220.ButtScan.UI;

[GenerateTypedNameReferences]
public sealed partial class ButtScanWindow : BaseWindow
public sealed partial class ButtScanWindow : PaperWindow
{
[Dependency] private readonly IResourceCache _resCache = default!;

private readonly Vector2 _buttRectSize = new Vector2(300, 300);
private readonly Thickness _buttRectMargin = new(25, 25);

public readonly TextureRect ButtTextureRect;
private readonly Control Layers;

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

Layers = new Control();
Layers.HorizontalExpand = true;
Layers.VerticalExpand = true;

ButtTextureRect = new TextureRect();
ButtTextureRect.Stretch = TextureRect.StretchMode.Scale;
ButtTextureRect.CanShrink = true;
ButtTextureRect.SetSize = _buttRectSize;
ButtTextureRect.Margin = _buttRectMargin;
ButtTextureRect.HorizontalAlignment = HAlignment.Center;
ButtTextureRect.VerticalAlignment = VAlignment.Center;

PaperBackground.AddChild(Layers);
ScrollingContents.Orphan();
Layers.AddChild(ButtTextureRect);
Layers.AddChild(ScrollingContents);
}

public void InitVisuals(ButtScanComponent scan, PaperVisualsComponent visuals)
{
base.InitVisuals(visuals);

CloseButton.OnPressed += _ => Close();
var contentImage = _resCache.GetResource<TextureResource>(scan.ButtTexturePath);
ButtTextureRect.Texture = contentImage;
}

public void InitVisuals(ButtScanComponent scan)
public new void Populate(SharedPaperComponent.PaperBoundUserInterfaceState state)
{
ContentsImage.TexturePath = scan.ButtTexturePath;
ContentsImage.MinSize = ContentsImage.TextureNormal?.Size ?? Vector2.Zero;
base.Populate(state);
BlankPaperIndicator.Visible = false;
}

// Drag by grabbing anywhere
Expand Down
6 changes: 6 additions & 0 deletions Content.Server/Paper/PaperComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ public sealed class PaperComponent : SharedPaperComponent
[DataField("content")]
public string Content { get; set; } = "";

/// <summary>
/// Allows to forbid to write on paper without using stamps as a hack
/// </summary>
[DataField("writable")]
public bool Writable { get; set; } = true;

[DataField("contentSize")]
public int ContentSize { get; set; } = 6000;

Expand Down
2 changes: 1 addition & 1 deletion Content.Server/Paper/PaperSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ private void OnExamined(EntityUid uid, PaperComponent paperComp, ExaminedEvent a

private void OnInteractUsing(EntityUid uid, PaperComponent paperComp, InteractUsingEvent args)
{
if (_tagSystem.HasTag(args.Used, "Write") && paperComp.StampedBy.Count == 0)
if (_tagSystem.HasTag(args.Used, "Write") && paperComp.StampedBy.Count == 0 && paperComp.Writable)
{
var writeEvent = new PaperWriteEvent(uid, args.User);
RaiseLocalEvent(args.Used, ref writeEvent);
Expand Down
21 changes: 15 additions & 6 deletions Resources/Prototypes/SS220/Entities/Objects/Misc/buttscan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,30 @@
description: "A paper with a grayscale copy of the butt, apparently made using photocopier."
components:
- type: Sprite
sprite: SS220/Objects/Misc/butt_scan.rsi
netsync: false
sprite: Objects/Misc/bureaucracy.rsi
layers:
- state: icon
- state: butt_scan
- state: paper_stamp-generic
map: [ "enum.PaperVisualLayers.Stamp" ]
visible: false
- type: ActivatableUI
key: enum.ButtScanUiKey.Key
key: enum.PaperUiKey.Key
closeOnHandDeselect: false
- type: UserInterface
interfaces:
- key: enum.ButtScanUiKey.Key
- key: enum.PaperUiKey.Key
type: ButtScanBoundUserInterface
- type: Paper
writable: false
- type: Appearance
- type: PaperVisuals
backgroundImagePath: "/Textures/Interface/Paper/paper_background_default.svg.96dpi.png"
backgroundPatchMargin: 16.0, 16.0, 16.0, 16.0
contentMargin: 30.0, 30.0, 30.0, 30.0
- type: ButtScan
- type: Item
size: 1
- type: Tag
tags:
- Document
- Trash
- Trash
3 changes: 3 additions & 0 deletions Resources/Textures/Objects/Misc/bureaucracy.rsi/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,9 @@
{
"name": "clipboard-equipped-BELT",
"directions": 4
},
{
"name": "butt_scan"
}
]
}
14 changes: 0 additions & 14 deletions Resources/Textures/SS220/Objects/Misc/butt_scan.rsi/meta.json

This file was deleted.

0 comments on commit 906ca5b

Please sign in to comment.