Skip to content
This repository has been archived by the owner on Oct 23, 2024. It is now read-only.

Commit

Permalink
Mail polish (#40)
Browse files Browse the repository at this point in the history
* Mail polish

* Make mail recyclable too
  • Loading branch information
Elijahrane authored May 4, 2022
1 parent 106ca5a commit 24e4c1b
Show file tree
Hide file tree
Showing 16 changed files with 80 additions and 12 deletions.
8 changes: 6 additions & 2 deletions Content.Client/Mail/MailSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,19 @@ public sealed class MailSystem : VisualizerSystem<MailVisualsComponent>
protected override void OnAppearanceChange(EntityUid uid, MailVisualsComponent component, ref AppearanceChangeEvent args)
{
if (TryComp(uid, out SpriteComponent? sprite)
&& args.Component.TryGetData(MailVisuals.IsLocked, out bool isLocked))
&& args.Component.TryGetData(MailVisuals.IsLocked, out bool isLocked)
&& args.Component.TryGetData(MailVisuals.IsTrash, out bool isTrash))
{
var state = isTrash ? component.TrashState : component.NormalState;
sprite.LayerSetVisible(MailVisualLayers.IsLocked, isLocked);
sprite.LayerSetState(MailVisualLayers.IsTrash, state);
}
}
}
}

public enum MailVisualLayers : byte
{
IsLocked
IsLocked,
IsTrash
}
6 changes: 6 additions & 0 deletions Content.Client/Mail/MailVisualsComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ namespace Content.Client.Mail;
[RegisterComponent]
public sealed class MailVisualsComponent : Component
{
[DataField("normalState", required: true)]
public string NormalState = default!;

[DataField("trashState", required: true)]
public string TrashState = default!;

[DataField("isLocked")]
public bool IsLocked = true;
}
6 changes: 6 additions & 0 deletions Content.Server/Mail/Components/MailComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,11 @@ public sealed class MailComponent : Component
/// The amount that cargo will be awarded for delivering this mail.
/// </summary>
public int Bounty = 500;

/// <summary>
/// Whether this component is enabled.
/// Removed when it becomes trash.
/// </summary>
public bool Enabled = true;
}
}
2 changes: 1 addition & 1 deletion Content.Server/Mail/Components/MailTeleporterComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public sealed class MailTeleporterComponent : Component

// Not starting accumulator at 0 so mail carriers have some deliveries to make shortly after roundstart.
[DataField("accumulator")]
public float Accumulator = 270f;
public float Accumulator = 285f;

[DataField("teleportInterval")]
public TimeSpan teleportInterval = TimeSpan.FromMinutes(5);
Expand Down
31 changes: 28 additions & 3 deletions Content.Server/Mail/MailSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using Content.Shared.Hands.EntitySystems;
using Content.Shared.Mail;
using Content.Shared.PDA;
using Content.Shared.Tag;
using Robust.Shared.Player;
using Robust.Shared.Random;
using Robust.Shared.Audio;
Expand All @@ -25,6 +26,7 @@ public sealed class MailSystem : EntitySystem
[Dependency] private readonly SharedHandsSystem _handsSystem = default!;
[Dependency] private readonly IdCardSystem _idCardSystem = default!;
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly TagSystem _tagSystem = default!;

// TODO: YAML Serializer won't catch this.
[ViewVariables(VVAccess.ReadWrite)]
Expand All @@ -50,6 +52,7 @@ public sealed class MailSystem : EntitySystem
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<MailComponent, ComponentInit>(OnInit);
SubscribeLocalEvent<MailComponent, UseInHandEvent>(OnUseInHand);
SubscribeLocalEvent<MailComponent, AfterInteractUsingEvent>(OnAfterInteractUsing);
SubscribeLocalEvent<MailComponent, ExaminedEvent>(OnExamined);
Expand All @@ -76,11 +79,22 @@ public override void Update(float frameTime)
}
}

/// <summary>
/// Set initial appearance so stuff doesn't break.
/// </summary>
private void OnInit(EntityUid uid, MailComponent mail, ComponentInit args)
{
UpdateAntiTamperVisuals(uid, true);
UpdateMailTrashState(uid, false);
}

/// <summary>
/// Try to open the mail.
/// <summary>
private void OnUseInHand(EntityUid uid, MailComponent component, UseInHandEvent args)
{
if (!component.Enabled)
return;
if (component.Locked)
{
_popupSystem.PopupEntity(Loc.GetString("mail-locked"), uid, Filter.Entities(args.User));
Expand Down Expand Up @@ -128,7 +142,7 @@ private void OnAfterInteractUsing(EntityUid uid, MailComponent component, AfterI
}
_popupSystem.PopupEntity(Loc.GetString("mail-bounty", ("bounty", component.Bounty)), uid, Filter.Entities(args.User));
component.Locked = false;
UpdateMailVisuals(uid, false);
UpdateAntiTamperVisuals(uid, false);
/// This needs to be revisited for multistation
/// For now let's just add the bounty to the first
/// console we find.
Expand Down Expand Up @@ -203,15 +217,26 @@ public void OpenMail(EntityUid uid, MailComponent? component = null, EntityUid?
if (user != null)
_handsSystem.PickupOrDrop(user, entity);
}
EntityManager.QueueDeleteEntity(uid);
_tagSystem.AddTag(uid, "Trash");
_tagSystem.AddTag(uid, "Recyclable");
component.Enabled = false;
UpdateMailTrashState(uid, true);
}

private void UpdateMailVisuals(EntityUid uid, bool isLocked)
private void UpdateAntiTamperVisuals(EntityUid uid, bool isLocked)
{
if (!TryComp<AppearanceComponent>(uid, out var appearance))
return;

appearance.SetData(MailVisuals.IsLocked, isLocked);
}

private void UpdateMailTrashState(EntityUid uid, bool isTrash)
{
if (!TryComp<AppearanceComponent>(uid, out var appearance))
return;

appearance.SetData(MailVisuals.IsTrash, isTrash);
}
}
}
3 changes: 2 additions & 1 deletion Content.Shared/Mail/MailVisuals.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace Content.Shared.Mail
[Serializable, NetSerializable]
public enum MailVisuals : byte
{
IsLocked
IsLocked,
IsTrash
}
}
4 changes: 4 additions & 0 deletions Resources/Prototypes/Entities/Objects/Specific/Mail/mail.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@
sprite: Objects/Specific/Mail/mail.rsi
layers:
- state: icon
map: ["enum.MailVisualLayers.IsTrash"]
- state: postmark
- state: locked
map: ["enum.MailVisualLayers.IsLocked"]
- type: Appearance
- type: MailVisuals
normalState: icon
trashState: trash

- type: entity
parent: BaseMail
Expand Down
6 changes: 2 additions & 4 deletions Resources/Prototypes/Entities/Objects/Specific/Mail/tools.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@
components:
- type: Sprite
netsync: false
sprite: Objects/Specific/Hydroponics/Equipment/plant_bag.rsi
color: blue
sprite: Clothing/Belt/mailbag.rsi
state: icon
- type: Clothing
sprite: Objects/Specific/Hydroponics/Equipment/plant_bag.rsi
color: blue
sprite: Clothing/Belt/mailbag.rsi
quickEquip: false
Slots:
- belt
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions Resources/Textures/Clothing/Belt/mailbag.rsi/meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"version": 1,
"license": "CC-BY-SA-3.0",
"copyright": "Taken from tgstation at https://github.com/tgstation/tgstation/commit/40d89d11ea4a5cb81d61dc1018b46f4e7d32c62a",
"size": {
"x": 32,
"y": 32
},
"states": [
{
"name": "icon"
},
{
"name": "equipped-BELT",
"directions": 4
}
]
}
Binary file modified Resources/Textures/Objects/Specific/Mail/mail.rsi/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Resources/Textures/Objects/Specific/Mail/mail.rsi/locked.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 7 additions & 1 deletion Resources/Textures/Objects/Specific/Mail/mail.rsi/meta.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"version": 1,
"license": "CC-BY-SA-3.0",
"copyright": "Made by Rane.",
"copyright": "Taken from tgstation at https://github.com/tgstation/tgstation/commit/40d89d11ea4a5cb81d61dc1018b46f4e7d32c62a",
"size": {
"x": 32,
"y": 32
Expand All @@ -12,6 +12,12 @@
},
{
"name": "locked"
},
{
"name": "trash"
},
{
"name": "postmark"
}
]
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 24e4c1b

Please sign in to comment.