Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PORT] Attachments #784

Merged
merged 70 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from 69 commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
0974f9b
attachments
Inconnu1337 Nov 13, 2024
ba43e72
почему я не сделал это сразу
Inconnu1337 Nov 14, 2024
edc1803
фикс магнитного жгута + фикс ямл линтера
Inconnu1337 Nov 14, 2024
684f0d5
ъ
Inconnu1337 Nov 14, 2024
a925490
ы
Inconnu1337 Nov 16, 2024
8082752
Merge branch 'RMCAttachment' of https://github.com/Inconnu1337/space_…
Inconnu1337 Nov 16, 2024
2611001
долбаеб блят
Inconnu1337 Nov 16, 2024
8d4eb9b
к
Inconnu1337 Nov 19, 2024
fc3cda1
е
Inconnu1337 Nov 19, 2024
8e70859
ш
Inconnu1337 Nov 22, 2024
8d4985f
uh
Inconnu1337 Nov 23, 2024
383529d
Merge branch 'master' into RMCAttachment
Inconnu1337 Nov 23, 2024
19cd5b7
ШРЕДЯ АХУЕЕТ
Inconnu1337 Nov 25, 2024
076f438
Merge branch 'RMCAttachment' of https://github.com/Inconnu1337/space_…
Inconnu1337 Nov 25, 2024
2fc25e5
fix MeleeWeaponSystem.cs
Inconnu1337 Nov 25, 2024
754612d
Merge branch 'AdventureTimeSS14:master' into RMCAttachment
Inconnu1337 Nov 30, 2024
f84967e
заебало
Inconnu1337 Nov 30, 2024
12f9ce8
да блять
Inconnu1337 Nov 30, 2024
b151609
Merge branch 'RMCAttachment' of https://github.com/Inconnu1337/space_…
Inconnu1337 Nov 30, 2024
5e2ff2a
40мм_гранаты
PyotrIgn Dec 1, 2024
efefd16
фикс иконки штыка на протокинетике
PyotrIgn Dec 1, 2024
f2c5f87
Merge branch 'master' into RMCAttachment
PyotrIgn Dec 1, 2024
dfabb2a
штык от винтовки Мосина
PyotrIgn Dec 1, 2024
4382958
Merge branch 'master' into RMCAttachment
PyotrIgn Dec 1, 2024
7b031f4
прицелы и бинокль
PyotrIgn Dec 1, 2024
ead4661
holster fix
Inconnu1337 Dec 2, 2024
1cd8169
Merge branch 'RMCAttachment' of https://github.com/Inconnu1337/space_…
Inconnu1337 Dec 2, 2024
0fa98ea
локализации, часть 1
PyotrIgn Dec 2, 2024
ac3d7af
да нахуй иди
Inconnu1337 Dec 3, 2024
34e4a1b
Merge branch 'RMCAttachment' of https://github.com/Inconnu1337/space_…
Inconnu1337 Dec 3, 2024
595109e
локализация часть 2
PyotrIgn Dec 3, 2024
08a9f47
Merge branch 'RMCAttachment' of https://github.com/Inconnu1337/space_…
PyotrIgn Dec 3, 2024
29b415d
замена снарядов в пусковых установках мехов на 40 мм гранаты
PyotrIgn Dec 4, 2024
4e5ff47
удалил лишний файл
Inconnu1337 Dec 5, 2024
62f3906
коллиматорные прицелы, рукоять, лазерный целеуказатель
PyotrIgn Dec 10, 2024
27e2059
Merge branch 'master' into RMCAttachment
PyotrIgn Dec 11, 2024
2048fbb
модули на все оружие + штыки
PyotrIgn Dec 12, 2024
5630a29
Merge branch 'RMCAttachment' of https://github.com/Inconnu1337/space_…
PyotrIgn Dec 12, 2024
6105bfe
Merge branch 'RMCAttachment' of https://github.com/Inconnu1337/space_…
Inconnu1337 Dec 12, 2024
0d94484
много букав
Inconnu1337 Dec 12, 2024
4a88909
шиш
Inconnu1337 Dec 12, 2024
c9f6721
Merge branch 'master' into RMCAttachment
PyotrIgn Dec 13, 2024
11e5113
Update uplink-catalog.ftl
PyotrIgn Dec 13, 2024
c549c9b
глушитель
PyotrIgn Dec 14, 2024
7e82c34
Merge branch 'master' into RMCAttachment
PyotrIgn Dec 14, 2024
1d10a3b
Merge branch 'master' into RMCAttachment
Inconnu1337 Dec 14, 2024
e6bc659
говночистка
Inconnu1337 Dec 14, 2024
f9c422d
Merge branch 'RMCAttachment' of https://github.com/Inconnu1337/space_…
Inconnu1337 Dec 14, 2024
b5c22ea
технологии, покупки модулей в аплинках, сортировка спрайтов
PyotrIgn Dec 14, 2024
91d0024
Merge branch 'RMCAttachment' of https://github.com/Inconnu1337/space_…
PyotrIgn Dec 14, 2024
c029bbf
tweak
Inconnu1337 Dec 14, 2024
16771d2
fix locale
jungarikjan Dec 14, 2024
d7bd624
фикс рси (ты как сломался хм)
PyotrIgn Dec 14, 2024
b95baed
Merge branch 'RMCAttachment' of https://github.com/Inconnu1337/space_…
PyotrIgn Dec 14, 2024
09b49aa
Merge branch 'RMCAttachment' of https://github.com/Inconnu1337/space_…
Inconnu1337 Dec 14, 2024
9e47d74
фикс рси 2
PyotrIgn Dec 14, 2024
956841c
Merge branch 'RMCAttachment' of https://github.com/Inconnu1337/space_…
PyotrIgn Dec 14, 2024
0636923
fix locale 2
jungarikjan Dec 14, 2024
ce8f5f8
фикс рси 3
PyotrIgn Dec 14, 2024
cf566b1
Merge branch 'RMCAttachment' of https://github.com/Inconnu1337/space_…
PyotrIgn Dec 14, 2024
351b7a2
locale fix 3
jungarikjan Dec 14, 2024
0e38e74
унга бунга
jungarikjan Dec 14, 2024
4e2949f
локал
jungarikjan Dec 14, 2024
1d4b72c
раны зашивают* ыыыыыыыыыыыыыы
jungarikjan Dec 14, 2024
7222224
категория модулей в аплинке
PyotrIgn Dec 15, 2024
eb6d548
Merge branch 'RMCAttachment' of https://github.com/Inconnu1337/space_…
PyotrIgn Dec 15, 2024
5c55eb3
а кто такие фиксики
FaDeOkno Dec 14, 2024
937ff6a
Merge branch 'master' into RMCAttachment
PyotrIgn Dec 18, 2024
5e0b288
временный костыль прицелов
Dec 18, 2024
3da0603
фулл авто у дрозда
Dec 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Content.Client._RMC14.Attachable.Systems;
using System.Numerics;

namespace Content.Client._RMC14.Attachable.Components;

[RegisterComponent, AutoGenerateComponentState]
[Access(typeof(AttachableHolderVisualsSystem))]
public sealed partial class AttachableHolderVisualsComponent : Component
{
/// <summary>
/// This dictionary contains a list of offsets for every slot that should display the attachable placed into it.
/// If a slot is not in this dictionary, the attachable inside will not be displayed.
/// The list of valid slot names can be found in AttachableHolderComponent.cs
/// </summary>
[DataField(required: true), AutoNetworkedField]
public Dictionary<string, Vector2> Offsets = new();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
using Content.Client._RMC14.Attachable.Systems;
using System.Numerics;
using Robust.Shared.Utility;

namespace Content.Client._RMC14.Attachable.Components;

[RegisterComponent, AutoGenerateComponentState]
[Access(typeof(AttachableHolderVisualsSystem))]
public sealed partial class AttachableVisualsComponent : Component
{
/// <summary>
/// Optional, only used if the item's own state should not be used.
/// The path to the RSI file that contains all the attached states.
/// </summary>
[DataField, AutoNetworkedField]
public ResPath? Rsi;

/// <summary>
/// Optional, only used if the item's own state should not be used.
/// This prefix is added to the name of the slot the attachable is installed in.
/// The prefix must be in kebab-case and end with a dash, like so: example-prefix-
/// The RSI must contain a state for every slot the attachable fits into.
/// If the attachment only fits into one slot, it should be named as follows: normal-state_suffix.
/// The slot names can be found in AttachableHolderComponent.cs
/// </summary>
[DataField, AutoNetworkedField]
public string? Prefix;

/// <summary>
/// Optional, only used if the item's own state should not be used.
/// This suffix is added to the name of the slot the attachable is installed in.
/// The RSI must contain a state for every slot the attachable fits into.
/// If the attachment only fits into one slot, it should be named as follows: normal-state_suffix.
/// The slot names can be found in AttachableHolderComponent.cs
/// </summary>
[DataField, AutoNetworkedField]
public string? Suffix = "_a";

/// <summary>
/// If true, will include the holder's slot name to find this attachment's state
/// in its RSI.
/// In this case, there must be a separate state for each slot the attachment fits into.
/// The states should be named as follows: prefix-slot-name-suffix.
/// </summary>
[DataField, AutoNetworkedField]
public bool IncludeSlotName;

/// <summary>
/// If this is toggled on and the item has an AttachableToggleableComponent, then the visualisation system will try to show a different sprite when it's active.
/// Each active state must have "-on" appended to the end of its name.
/// </summary>
[DataField, AutoNetworkedField]
public bool ShowActive;

/// <summary>
/// If this is set to true, the attachment will be redrawn on its holder every time it receives an AppearanceChangeEvent. Useful for things like the UGL.
/// </summary>
[DataField, AutoNetworkedField]
public bool RedrawOnAppearanceChange;

[DataField, AutoNetworkedField]
public int Layer;

[DataField, AutoNetworkedField]
public Vector2 Offset;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
using Content.Client._RMC14.Attachable.Components;
using Content.Shared._RMC14.Attachable;
using Content.Shared._RMC14.Attachable.Components;
using Content.Shared._RMC14.Attachable.Events;
using Content.Shared._RMC14.Attachable.Systems;
using Robust.Client.GameObjects;
using Robust.Shared.Containers;

namespace Content.Client._RMC14.Attachable.Systems;

public sealed class AttachableHolderVisualsSystem : EntitySystem
{
[Dependency] private readonly AttachableHolderSystem _attachableHolderSystem = default!;

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

SubscribeLocalEvent<AttachableHolderVisualsComponent, EntRemovedFromContainerMessage>(OnDetached);
SubscribeLocalEvent<AttachableHolderVisualsComponent, AttachableHolderAttachablesAlteredEvent>(OnAttachablesAltered);

SubscribeLocalEvent<AttachableVisualsComponent, AppearanceChangeEvent>(OnAttachableAppearanceChange);
}

private void OnDetached(Entity<AttachableHolderVisualsComponent> holder, ref EntRemovedFromContainerMessage args)
{
if (!HasComp<AttachableVisualsComponent>(args.Entity) || !_attachableHolderSystem.HasSlot(holder.Owner, args.Container.ID))
return;

var holderEv = new AttachableHolderAttachablesAlteredEvent(args.Entity, args.Container.ID, AttachableAlteredType.Detached);
RaiseLocalEvent(holder, ref holderEv);
}

private void OnAttachablesAltered(Entity<AttachableHolderVisualsComponent> holder,
ref AttachableHolderAttachablesAlteredEvent args)
{
if (!TryComp(args.Attachable, out AttachableVisualsComponent? attachableComponent))
return;

string suffix = "";
if (attachableComponent.ShowActive && TryComp(args.Attachable, out AttachableToggleableComponent? toggleableComponent) && toggleableComponent.Active)
suffix = "-on";

var attachable = new Entity<AttachableVisualsComponent>(args.Attachable, attachableComponent);
switch (args.Alteration)
{
case AttachableAlteredType.Attached:
SetAttachableOverlay(holder, attachable, args.SlotId, suffix);
break;

case AttachableAlteredType.Detached:
RemoveAttachableOverlay(holder, args.SlotId);
break;

case AttachableAlteredType.Activated:
if (!attachableComponent.ShowActive)
break;

SetAttachableOverlay(holder, attachable, args.SlotId, suffix);
break;

case AttachableAlteredType.Deactivated:
if (!attachableComponent.ShowActive)
break;

SetAttachableOverlay(holder, attachable, args.SlotId, suffix);
break;

case AttachableAlteredType.Interrupted:
if (!attachableComponent.ShowActive)
break;

SetAttachableOverlay(holder, attachable, args.SlotId);
break;

case AttachableAlteredType.AppearanceChanged:
SetAttachableOverlay(holder, attachable, args.SlotId, suffix);
break;
}
}

private void RemoveAttachableOverlay(Entity<AttachableHolderVisualsComponent> holder, string slotId)
{
if (!holder.Comp.Offsets.ContainsKey(slotId) || !TryComp(holder, out SpriteComponent? spriteComponent))
return;

if (!spriteComponent.LayerMapTryGet(slotId, out var index))
return;

spriteComponent.LayerMapRemove(slotId);
spriteComponent.RemoveLayer(index);
}

private void SetAttachableOverlay(Entity<AttachableHolderVisualsComponent> holder,
Entity<AttachableVisualsComponent> attachable,
string slotId,
string suffix = "")
{
if (!holder.Comp.Offsets.ContainsKey(slotId) ||
!TryComp(holder, out SpriteComponent? holderSprite))
{
return;
}

if (!TryComp(attachable, out SpriteComponent? attachableSprite))
return;

var rsi = attachableSprite.LayerGetActualRSI(attachable.Comp.Layer)?.Path;
var state = attachableSprite.LayerGetState(attachable.Comp.Layer).ToString();
if (attachable.Comp.Rsi is { } rsiPath)
{
rsi = rsiPath;
}

if (!string.IsNullOrWhiteSpace(attachable.Comp.Prefix))
state = attachable.Comp.Prefix;

if (attachable.Comp.IncludeSlotName)
state += slotId;

if (!string.IsNullOrWhiteSpace(attachable.Comp.Suffix))
state += attachable.Comp.Suffix;

state += suffix;

var layerData = new PrototypeLayerData()
{
RsiPath = rsi.ToString(),
State = state,
Offset = holder.Comp.Offsets[slotId] + attachable.Comp.Offset,
Visible = true,
};

if (holderSprite.LayerMapTryGet(slotId, out var index))
{
holderSprite.LayerSetData(index, layerData);
return;
}

holderSprite.LayerMapSet(slotId, holderSprite.AddLayer(layerData));
}

private void OnAttachableAppearanceChange(Entity<AttachableVisualsComponent> attachable, ref AppearanceChangeEvent args)
{
if (!attachable.Comp.RedrawOnAppearanceChange ||
!_attachableHolderSystem.TryGetHolder(attachable.Owner, out var holderUid) ||
!_attachableHolderSystem.TryGetSlotId(holderUid.Value, attachable.Owner, out var slotId))
{
return;
}

var holderEvent = new AttachableHolderAttachablesAlteredEvent(attachable.Owner, slotId, AttachableAlteredType.AppearanceChanged);
RaiseLocalEvent(holderUid.Value, ref holderEvent);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<controls:FancyWindow
xmlns="https://spacestation14.io"
xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls"
Title="{Loc 'rmc-attachable-holder-strip-ui-title'}"
MinSize="200 100"
SetSize="200 100">
<BoxContainer Name="SlotsContainer" Orientation="Vertical" VerticalExpand="True"
HorizontalExpand="True" Margin="8 8 8 8" />
</controls:FancyWindow>
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using Content.Client.UserInterface.Controls;
using Content.Shared._RMC14.Attachable;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.XAML;

namespace Content.Client.ADT._RMC14.Attachable.Ui;

[GenerateTypedNameReferences]
public sealed partial class AttachableHolderChooseSlotMenu : FancyWindow
{
private readonly AttachmentChooseSlotBui _boundUI;
private readonly Dictionary<string, AttachableSlotControl> _attachableSlotControls;

public AttachableHolderChooseSlotMenu(AttachmentChooseSlotBui boundUI)
{
RobustXamlLoader.Load(this);

_boundUI = boundUI;
_attachableSlotControls = new Dictionary<string, AttachableSlotControl>();
OnClose += boundUI.Close;
}

public void UpdateMenu(List<string> attachableSlots)
{
foreach (var slotId in attachableSlots)
{
if (!_attachableSlotControls.ContainsKey(slotId))
AddSlotControl(slotId);
}
}

private void AddSlotControl(string slotId)
{
var slotControl = new AttachableSlotControl(this, _boundUI, slotId);
SlotsContainer.AddChild(slotControl);
_attachableSlotControls.Add(slotId, slotControl);
}

private sealed class AttachableSlotControl : Control
{
public AttachableSlotControl(AttachableHolderChooseSlotMenu slotMenu,
AttachmentChooseSlotBui boundUI,
string slotId)
{
var button = new Button { Text = Loc.GetString(slotId) };

button.OnPressed += _ =>
{
boundUI.SendMessage(new AttachableHolderAttachToSlotMessage(slotId));
slotMenu.Close();
};

AddChild(button);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<controls:FancyWindow
xmlns="https://spacestation14.io"
xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls"
Title="{Loc 'rmc-attachable-holder-strip-ui-title'}"
MinSize="350 400"
SetSize="350 400">
<BoxContainer Name="AttachablesContainer" Orientation="Vertical" VerticalExpand="True"
Margin="8 8 8 8" />
</controls:FancyWindow>
Loading
Loading