forked from space-wizards/space-station-14
-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
254 additions
and
0 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
Content.Client/SS220/AdmemeEvents/JobIconChangerBoundUserInterface.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
16
Content.Client/SS220/AdmemeEvents/UI/JobIconChangerWindow.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
92
Content.Client/SS220/AdmemeEvents/UI/JobIconChangerWindow.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
15
Content.Server/SS220/AdmemeEvents/JobIconChangerComponent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
22
Content.Shared/SS220/AdmemeEvents/SharedJobIconChangerComponent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
Resources/Locale/en-US/ss220/admeme-events/ui/job-icon-changer-window.ftl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
2 changes: 2 additions & 0 deletions
2
Resources/Locale/ru-RU/ss220/admeme-events/ui/job-icon-changer-window.ftl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
job-icon-changer-window-title = Список статус-иконок | ||
job-icon-changer-window-header = Выберите статус-иконку |
2 changes: 2 additions & 0 deletions
2
Resources/Locale/ru-RU/ss220/prototypes/entities/objects/tools/job-icon-changer.ftl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
ent-JobIconChanger = Изменитель статус-иконок | ||
.desc = Используется для изменения статус-иконок. |
19 changes: 19 additions & 0 deletions
19
Resources/Prototypes/SS220/AdmemeEvents/job_icon_changer.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |