Skip to content

Commit

Permalink
Merge pull request #711 from modern-nm/changeling-gamerule-fix
Browse files Browse the repository at this point in the history
Круговое меню генокраду + починка возможности добавить генокрада через антаг меню
  • Loading branch information
modern-nm authored May 21, 2024
2 parents 9feeca4 + 06b4105 commit 4b9f008
Show file tree
Hide file tree
Showing 11 changed files with 393 additions and 82 deletions.
104 changes: 104 additions & 0 deletions Content.Client/ADT/Changeling/ChangelingPanelSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/// Made for Adventure Time Project by ModerN. https://github.com/modern-nm mailto:[email protected]
/// see also https://github.com/DocNITE/liebendorf-station/tree/feature/emote-radial-panel
using Content.Client.Humanoid;
using Content.Client.UserInterface.Systems.Radial;
using Content.Client.UserInterface.Systems.Radial.Controls;
using Content.Shared.Changeling;
using Content.Shared.Humanoid.Prototypes;
using Robust.Client.GameObjects;
using Robust.Client.Player;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Shared.Map;
using Robust.Shared.Player;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
using Robust.Shared.Utility;
using System.Numerics;

namespace Content.Client.ADT.Language;

public sealed class ChangelingPanelSystem : EntitySystem
{
[Dependency] private readonly IPrototypeManager _proto = default!;
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly IUserInterfaceManager _userInterfaceManager = default!;
[Dependency] private readonly IPlayerManager _playerMan = default!;
[Dependency] private readonly SpriteSystem _spriteSystem = default!;
[Dependency] private readonly IEntityManager _entManager = default!;
[Dependency] private readonly HumanoidAppearanceSystem _appearanceSystem = default!;

/// <summary>
/// We should enable radial for single target
/// </summary>
private RadialContainer? _openedMenu;

private const string DefaultIcon = "/Textures/Interface/AdminActions/play.png";

private const string EmptyIcon = "/Textures/Interface/AdminActions/emptyIcon.png";

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

SubscribeLocalEvent<PlayerAttachedEvent>(OnPlayerAttached);
SubscribeLocalEvent<PlayerDetachedEvent>(OnPlayerDetached);

SubscribeNetworkEvent<RequestChangelingFormsMenuEvent>(HandleChangelingFormsMenuEvent);
}

private void HandleChangelingFormsMenuEvent(RequestChangelingFormsMenuEvent args)
{
if (_openedMenu != null)
return;
if (_playerMan.LocalEntity == null)
{
return;
}

//if (!TryComp<ChangelingComponent>(_playerMan.LocalEntity.Value, out var changelingComponent)) // нет на клиенте
// return;

_openedMenu = _userInterfaceManager.GetUIController<RadialUiController>()
.CreateRadialContainer();

foreach (var humanoid in args.HumanoidData)
{
var dummy = _entManager.SpawnEntity(_proto.Index<SpeciesPrototype>(humanoid.Species).DollPrototype, MapCoordinates.Nullspace);
//var humanoidEntityUid = GetEntity(humanoid); // Entities on the client outside of the FOV are nonexistant. You can see that if you zoom out. //So it'll give you UID 0 which is EntityUid.Invalid.
_appearanceSystem.LoadProfile(dummy, humanoid.Profile);
var face = new SpriteView();
face.SetEntity(dummy);

var actionName = humanoid.Name;
var texturePath = _spriteSystem.Frame0(new SpriteSpecifier.Texture(new ResPath(EmptyIcon)));

var emoteButton = _openedMenu.AddButton(actionName, texturePath, face);
emoteButton.Opacity = 210;
emoteButton.Tooltip = null;
emoteButton.Controller.OnPressed += (_) =>
{
var ev = new SelectChangelingFormEvent(args.Target, entitySelected: humanoid.NetEntity);
RaiseNetworkEvent(ev);
_openedMenu.Dispose();
};
}
_openedMenu.OnClose += (_) =>
{
_openedMenu = null;
};
if (_playerMan.LocalEntity != null)
_openedMenu.OpenAttached(_playerMan.LocalEntity.Value);

}

private void OnPlayerAttached(PlayerAttachedEvent args)
{
_openedMenu?.Dispose();
}

private void OnPlayerDetached(PlayerDetachedEvent args)
{
_openedMenu?.Dispose();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public void OpenCentered()
if (Parent == null)
return;

LayoutContainer.SetPosition(this, (Parent.Size/2) - (Size/2));
LayoutContainer.SetPosition(this, (Parent.Size / 2) - (Size / 2));
UpdateButtons();
}

Expand All @@ -156,7 +156,7 @@ public void OpenCenteredAt(Vector2 position)
if (Parent == null)
return;

LayoutContainer.SetPosition(this, (Parent.Size * position) - (Size/2));
LayoutContainer.SetPosition(this, (Parent.Size * position) - (Size / 2));
UpdateButtons();
}

Expand Down Expand Up @@ -211,12 +211,13 @@ public RadialItem AddButton(string action, string? texturePath = null)
/// <param name="action">Item content text</param>
/// <param name="texture">Item's icon texture</param>
/// <returns></returns>
public RadialItem AddButton(string action, Texture? texture)
public RadialItem AddButton(string action, Texture? texture, SpriteView spriteView = default!)
{
var button = new RadialItem();
button.Content = action;
button.Controller.TexturePath = ItemBackgroundTexturePath;

if (spriteView != null)
button.EntityView.SetEntity(spriteView.NetEnt != null ? spriteView.NetEnt.Value : NetEntity.Invalid);
if (texture != null)
button.Icon.Texture = texture;

Expand All @@ -229,13 +230,13 @@ private void UpdateButtons()
{
Visible = true;

var angleDegrees = 360/Layout.ChildCount;
var angleDegrees = 360 / Layout.ChildCount;
var stepAngle = -angleDegrees + -90;
var distance = GetDistance();

foreach (var child in Layout.Children)
{
var button = (RadialItem)child;
var button = (RadialItem) child;
button.ButtonSize = new Vector2(NormalSize, NormalSize);
stepAngle += angleDegrees;
var pos = GetPointFromPolar(stepAngle, distance);
Expand Down Expand Up @@ -329,8 +330,8 @@ protected override void Draw(DrawingHandleScreen handle)

foreach (var child in Layout.Children)
{
var button = (RadialItem)child;
LayoutContainer.SetPosition(child, button.Offset - (button.Size/2));
var button = (RadialItem) child;
LayoutContainer.SetPosition(child, button.Offset - (button.Size / 2));
}

// FIXME: We use item's offset like "local item position" for animation. Need make some better way to do it;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
Access="Public"
VerticalExpand="True"
HorizontalExpand="True">
<SpriteView Access="Public" Name="EntityView"
SetSize="64 64"
OverrideDirection="South">
</SpriteView>
<TextureRect Access="Public" Name="Icon"
VerticalExpand="True"
HorizontalExpand="True"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Numerics;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Animations;

Expand Down
Loading

0 comments on commit 4b9f008

Please sign in to comment.