[Feat] Внешний вид и название канистр можно изменить прямо в игре (#317)
* feat: Теперь можно менять внешний вид канистр газов * fix: русский язык (я его не знаю)
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
using Content.Shared._White.PolymorphableCanister;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Client._White.PolymorphableCanister;
|
||||
|
||||
public sealed class PolymorphableCanisterSystem : SharedPolymorphableCanisterSystem
|
||||
{
|
||||
[Dependency] private readonly IComponentFactory _componentFactory = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<PolymorphableCanisterComponent, AfterAutoHandleStateEvent>(HandleState);
|
||||
}
|
||||
|
||||
private void HandleState(EntityUid uid,
|
||||
PolymorphableCanisterComponent component,
|
||||
ref AfterAutoHandleStateEvent args)
|
||||
{
|
||||
UpdateAppearance(uid, component.CurrentPrototype);
|
||||
}
|
||||
|
||||
protected override void UpdateSprite(EntityUid uid, EntityPrototype proto)
|
||||
{
|
||||
base.UpdateSprite(uid, proto);
|
||||
|
||||
if (!TryComp(uid, out SpriteComponent? sprite) ||
|
||||
!proto.TryGetComponent(out SpriteComponent? otherSprite, _componentFactory))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
sprite.CopyFrom(otherSprite);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
using Content.Shared._White.PolymorphableCanister;
|
||||
using JetBrains.Annotations;
|
||||
|
||||
namespace Content.Client._White.PolymorphableCanister.UI;
|
||||
|
||||
[UsedImplicitly]
|
||||
// ReSharper disable once InconsistentNaming
|
||||
public sealed class PolymorphableCanisterBUI : BoundUserInterface
|
||||
{
|
||||
private PolymorphableCanisterMenu? _menu;
|
||||
|
||||
public PolymorphableCanisterBUI(EntityUid owner, Enum uiKey) : base(owner, uiKey)
|
||||
{
|
||||
IoCManager.InjectDependencies(this);
|
||||
}
|
||||
|
||||
protected override void Open()
|
||||
{
|
||||
_menu = new PolymorphableCanisterMenu(Owner, this);
|
||||
_menu.OnClose += Close;
|
||||
_menu.OpenCentered();
|
||||
}
|
||||
|
||||
public void SendMessage(string protoId)
|
||||
{
|
||||
SendMessage(new PolymorphableCanisterMessage(protoId));
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
base.Dispose(disposing);
|
||||
if (!disposing)
|
||||
return;
|
||||
|
||||
_menu?.Dispose();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<ui:RadialMenu xmlns="https://spacestation14.io"
|
||||
xmlns:ui="clr-namespace:Content.Client.UserInterface.Controls"
|
||||
BackButtonStyleClass="RadialMenuBackButton"
|
||||
CloseButtonStyleClass="RadialMenuCloseButton"
|
||||
VerticalExpand="True"
|
||||
HorizontalExpand="True"
|
||||
MinSize="450 450">
|
||||
|
||||
<!-- Main container to hold all canister states-->
|
||||
<ui:RadialContainer Name="Main" VerticalExpand="True" HorizontalExpand="True" Radius="140"
|
||||
ReserveSpaceForHiddenChildren="False" />
|
||||
</ui:RadialMenu>
|
||||
@@ -0,0 +1,57 @@
|
||||
using System.Numerics;
|
||||
using Content.Client.UserInterface.Controls;
|
||||
using Content.Shared._White.PolymorphableCanister;
|
||||
using Robust.Client.AutoGenerated;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Client.UserInterface.XAML;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Client._White.PolymorphableCanister.UI;
|
||||
|
||||
[GenerateTypedNameReferences]
|
||||
public sealed partial class PolymorphableCanisterMenu : RadialMenu
|
||||
{
|
||||
[Dependency] private readonly EntityManager _entManager = default!;
|
||||
[Dependency] private readonly IPrototypeManager _protoManager = default!;
|
||||
|
||||
public PolymorphableCanisterMenu(EntityUid owner, PolymorphableCanisterBUI bui)
|
||||
{
|
||||
IoCManager.InjectDependencies(this);
|
||||
RobustXamlLoader.Load(this);
|
||||
|
||||
if (!_entManager.TryGetComponent<PolymorphableCanisterComponent>(owner, out var canister))
|
||||
return;
|
||||
|
||||
var spriteSystem = _entManager.System<SpriteSystem>();
|
||||
|
||||
var main = FindControl<RadialContainer>("Main");
|
||||
// ReSharper disable once ConditionIsAlwaysTrueOrFalseAccordingToNullableAPIContract
|
||||
if (main is null)
|
||||
return;
|
||||
|
||||
foreach (var protoId in canister.Prototypes)
|
||||
{
|
||||
if (canister.CurrentPrototype == protoId)
|
||||
continue;
|
||||
|
||||
if (!_protoManager.TryIndex(protoId, out var proto))
|
||||
continue;
|
||||
|
||||
var button = new RadialMenuTextureButton
|
||||
{
|
||||
ToolTip = Loc.GetString(proto.Name),
|
||||
TextureNormal = spriteSystem.GetPrototypeIcon(protoId).Default,
|
||||
StyleClasses = { "RadialMenuButton" },
|
||||
SetSize = new Vector2(64f, 64f)
|
||||
};
|
||||
|
||||
button.OnButtonUp += _ =>
|
||||
{
|
||||
bui.SendMessage(protoId);
|
||||
Close();
|
||||
};
|
||||
|
||||
main.AddChild(button);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user