Skip to content

Commit

Permalink
Add job icon changer
Browse files Browse the repository at this point in the history
  • Loading branch information
Skriler committed Feb 28, 2024
1 parent 9c618ab commit 83de374
Show file tree
Hide file tree
Showing 10 changed files with 254 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// © 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.SS220.AdmemeEvents.UI;
using Content.Shared.SS220.AdmemeEvents;

namespace Content.Client.SS220.AdmemeEvents;

public sealed class JobIconChangerBoundUserInterface : BoundUserInterface
{
private JobIconChangerWindow? _window;

public JobIconChangerBoundUserInterface(EntityUid owner, Enum uiKey)
: base(owner, uiKey)
{ }

protected override void Open()
{
base.Open();

_window = new JobIconChangerWindow(this);

_window.OnClose += Close;
_window.OpenCentered();
}

public void OnJobIconChanged(string newJobIcon)
{
SendMessage(new JobIconChangerChangedMessage(newJobIcon));
_window?.Close();
}

protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (!disposing)
return;

_window?.Dispose();
}
}
16 changes: 16 additions & 0 deletions Content.Client/SS220/AdmemeEvents/UI/JobIconChangerWindow.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!-- © SS220, An EULA/CLA with a hosting restriction, full text: https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/CLA.txt -->

<DefaultWindow
xmlns="https://spacestation14.io"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="{Loc 'job-icon-changer-window-title'}"
MinSize="240 150"
Resizable="False"
>
<BoxContainer Orientation="Vertical">
<Label Text="{Loc 'job-icon-changer-window-header'}"/>
<GridContainer Name="IconGrid" Columns="5">
<!-- Job icon buttons are generated in the code -->
</GridContainer>
</BoxContainer>
</DefaultWindow>
92 changes: 92 additions & 0 deletions Content.Client/SS220/AdmemeEvents/UI/JobIconChangerWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
// © SS220, An EULA/CLA with a hosting restriction, full text: https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/CLA.txt

using System.Linq;
using System.Numerics;
using Content.Client.Stylesheets;
using Content.Shared.Antag;
using Content.Shared.StatusIcon;
using Robust.Client.AutoGenerated;
using Robust.Client.GameObjects;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.CustomControls;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Prototypes;

namespace Content.Client.SS220.AdmemeEvents.UI;

[GenerateTypedNameReferences]
public sealed partial class JobIconChangerWindow : DefaultWindow
{
private static readonly string[] JobIconFilter = { "IOT", "NT", "USSP" };
private static readonly int JobIconColumnCount = 5;
private static readonly Vector2 BtnMaxSize = new Vector2(42, 28);
private static readonly Vector2 TexScale = new Vector2(2.5f, 2.5f);

[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly IEntitySystemManager _entitySystem = default!;

private readonly SpriteSystem _spriteSystem;
private readonly JobIconChangerBoundUserInterface _bui;

public JobIconChangerWindow(JobIconChangerBoundUserInterface bui)
{
RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this);

_spriteSystem = _entitySystem.GetEntitySystem<SpriteSystem>();
_bui = bui;

var jobIconList = _prototypeManager.EnumeratePrototypes<StatusIconPrototype>()
.Where(icon => JobIconFilter.Any(filter => icon.ID.StartsWith(filter)))
.OrderBy(icon => icon.ID)
.ToList();

SetAllowedIcons(jobIconList);
}

public void SetAllowedIcons(List<StatusIconPrototype> jobIconList)
{
IconGrid.DisposeAllChildren();

var jobIconBtnGroup = new ButtonGroup();

string styleBase;
Button jobIconBtn;
TextureRect jobIconTex;

short i = 0;
foreach (var jobIcon in jobIconList)
{
styleBase = GetStyleBase(i);

jobIconBtn = new Button
{
Access = AccessLevel.Public,
StyleClasses = { styleBase },
MaxSize = BtnMaxSize,
Group = jobIconBtnGroup,
};

jobIconTex = new TextureRect
{
Texture = _spriteSystem.Frame0(jobIcon.Icon),
TextureScale = TexScale,
Stretch = TextureRect.StretchMode.KeepCentered,
};

jobIconBtn.AddChild(jobIconTex);
jobIconBtn.OnPressed += _ => _bui.OnJobIconChanged(jobIcon.ID);
IconGrid.AddChild(jobIconBtn);

i++;
}
}

private string GetStyleBase(int counter)
{
var modulo = counter % JobIconColumnCount;
return (modulo == 0) ? StyleBase.ButtonOpenRight :
(modulo == JobIconColumnCount - 1) ? StyleBase.ButtonOpenLeft : StyleBase.ButtonOpenBoth;
}
}
15 changes: 15 additions & 0 deletions Content.Server/SS220/AdmemeEvents/JobIconChangerComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// © SS220, An EULA/CLA with a hosting restriction, full text: https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/CLA.txt

namespace Content.Server.SS220.AdmemeEvents;

using Content.Shared.StatusIcon;
using Robust.Shared.GameStates;
using Robust.Shared.Prototypes;

[RegisterComponent]
[Access(typeof(JobIconChangerSystem))]
public sealed partial class JobIconChangerComponent : Component
{
[DataField, ViewVariables(VVAccess.ReadWrite)]
public ProtoId<StatusIconPrototype> JobIcon;
}
44 changes: 44 additions & 0 deletions Content.Server/SS220/AdmemeEvents/JobIconChangerSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// © 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.Administration.Logs;
using Content.Shared.Interaction;
using Content.Shared.SS220.AdmemeEvents;

namespace Content.Server.SS220.AdmemeEvents;

public sealed class JobIconChangerSystem : EntitySystem
{
public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<JobIconChangerComponent, JobIconChangerChangedMessage>(OnJobChanged);
SubscribeLocalEvent<JobIconChangerComponent, AfterInteractEvent>(OnAfterInteract);
}

private void OnJobChanged(EntityUid uid, JobIconChangerComponent component, JobIconChangerChangedMessage args)
{
if (string.IsNullOrWhiteSpace(args.JobIcon))
return;

component.JobIcon = args.JobIcon;
}

private void OnAfterInteract(EntityUid uid, JobIconChangerComponent component, AfterInteractEvent args)
{
//if (component.JobIcon == null || !args.CanReach)
// return;

if (args.Handled || args.Target is not { } target)
return;

if (!TryComp(target, out EventRoleComponent? eventRoleComponent))
return;

eventRoleComponent.StatusIcon = component.JobIcon;

args.Handled = true;

Dirty(target, eventRoleComponent);
}
}
22 changes: 22 additions & 0 deletions Content.Shared/SS220/AdmemeEvents/SharedJobIconChangerComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// © SS220, An EULA/CLA with a hosting restriction, full text: https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/CLA.txt

using Robust.Shared.Serialization;

namespace Content.Shared.SS220.AdmemeEvents;

[Serializable, NetSerializable]
public enum JobIconChangerKey : byte
{
Key,
}

[Serializable, NetSerializable]
public sealed class JobIconChangerChangedMessage : BoundUserInterfaceMessage
{
public string JobIcon { get; }

public JobIconChangerChangedMessage(string jobIcon)
{
JobIcon = jobIcon;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
job-icon-changer-window-title = Status icons list
job-icon-changer-window-header = Pick job icon
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
job-icon-changer-window-title = Список статус-иконок
job-icon-changer-window-header = Выберите статус-иконку
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ent-JobIconChanger = Изменитель статус-иконок
.desc = Используется для изменения статус-иконок.
19 changes: 19 additions & 0 deletions Resources/Prototypes/SS220/AdmemeEvents/job_icon_changer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
- type: entity
parent: BaseItem
id: JobIconChanger
name: job icons changer
suffix: Shitspawn, Ebent, FractWar
description: Used to change job icons.
components:
- type: Sprite
sprite: Objects/Tools/access_configurator.rsi
state: icon
- type: Item
size: Small
- type: ActivatableUI
key: enum.JobIconChangerKey.Key
- type: UserInterface
interfaces:
- key: enum.JobIconChangerKey.Key
type: JobIconChangerBoundUserInterface
- type: JobIconChanger

0 comments on commit 83de374

Please sign in to comment.