Re-organize all projects (#4166)
This commit is contained in:
33
Content.Client/Items/Components/IItemStatus.cs
Normal file
33
Content.Client/Items/Components/IItemStatus.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using Robust.Client.UserInterface;
|
||||
|
||||
namespace Content.Client.Items.Components
|
||||
{
|
||||
/// <summary>
|
||||
/// Allows a component to provide status tooltips next to the hands interface.
|
||||
/// </summary>
|
||||
public interface IItemStatus
|
||||
{
|
||||
/// <summary>
|
||||
/// Called to get a control that represents the status for this component.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// The control to render as status.
|
||||
/// </returns>
|
||||
public Control MakeControl();
|
||||
|
||||
/// <summary>
|
||||
/// Called when the item no longer needs this status (say, dropped from hand)
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// Useful to allow you to drop the control for the GC, if you need to.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// Note that this may be called after a second invocation of <see cref="MakeControl"/> (for example if the user switches the item between two hands).
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
public void DestroyControl(Control control)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
27
Content.Client/Items/Components/ItemComponent.cs
Normal file
27
Content.Client/Items/Components/ItemComponent.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
#nullable enable
|
||||
using Content.Client.Hands;
|
||||
using Content.Shared.Item;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
namespace Content.Client.Items.Components
|
||||
{
|
||||
[RegisterComponent]
|
||||
[ComponentReference(typeof(SharedItemComponent))]
|
||||
public class ItemComponent : SharedItemComponent
|
||||
{
|
||||
public override bool TryPutInHand(IEntity user)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
protected override void OnEquippedPrefixChange()
|
||||
{
|
||||
if (!Owner.TryGetContainer(out var container))
|
||||
return;
|
||||
|
||||
if (container.Owner.TryGetComponent(out HandsComponent? hands))
|
||||
hands.RefreshInHands();
|
||||
}
|
||||
}
|
||||
}
|
||||
12
Content.Client/Items/Components/ItemStatusComponent.cs
Normal file
12
Content.Client/Items/Components/ItemStatusComponent.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
namespace Content.Client.Items.Components
|
||||
{
|
||||
[RegisterComponent]
|
||||
public class ItemStatusComponent : Component
|
||||
{
|
||||
public override string Name => "ItemStatus";
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
14
Content.Client/Items/Managers/IItemSlotManager.cs
Normal file
14
Content.Client/Items/Managers/IItemSlotManager.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using Content.Client.Items.UI;
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
namespace Content.Client.Items.Managers
|
||||
{
|
||||
public interface IItemSlotManager
|
||||
{
|
||||
bool OnButtonPressed(GUIBoundKeyEventArgs args, IEntity? item);
|
||||
void UpdateCooldown(ItemSlotButton? cooldownTexture, IEntity? entity);
|
||||
bool SetItemSlot(ItemSlotButton button, IEntity? entity);
|
||||
void HoverInSlot(ItemSlotButton button, IEntity? entity, bool fits);
|
||||
}
|
||||
}
|
||||
148
Content.Client/Items/Managers/ItemSlotManager.cs
Normal file
148
Content.Client/Items/Managers/ItemSlotManager.cs
Normal file
@@ -0,0 +1,148 @@
|
||||
using Content.Client.Examine;
|
||||
using Content.Client.Items.UI;
|
||||
using Content.Client.Storage;
|
||||
using Content.Client.Verbs;
|
||||
using Content.Shared.Cooldown;
|
||||
using Content.Shared.Input;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.Input;
|
||||
using Robust.Client.Player;
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Input;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
namespace Content.Client.Items.Managers
|
||||
{
|
||||
public class ItemSlotManager : IItemSlotManager
|
||||
{
|
||||
[Dependency] private readonly IPlayerManager _playerManager = default!;
|
||||
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
||||
[Dependency] private readonly IInputManager _inputManager = default!;
|
||||
[Dependency] private readonly IEntitySystemManager _entitySystemManager = default!;
|
||||
[Dependency] private readonly IUserInterfaceManager _uiMgr = default!;
|
||||
[Dependency] private readonly IEntityManager _entityManager = default!;
|
||||
[Dependency] private readonly IEyeManager _eyeManager = default!;
|
||||
[Dependency] private readonly IMapManager _mapManager = default!;
|
||||
|
||||
public bool SetItemSlot(ItemSlotButton button, IEntity? entity)
|
||||
{
|
||||
if (entity == null)
|
||||
{
|
||||
button.SpriteView.Sprite = null;
|
||||
button.StorageButton.Visible = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!entity.TryGetComponent(out ISpriteComponent? sprite))
|
||||
return false;
|
||||
|
||||
button.ClearHover();
|
||||
button.SpriteView.Sprite = sprite;
|
||||
button.StorageButton.Visible = entity.HasComponent<ClientStorageComponent>();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool OnButtonPressed(GUIBoundKeyEventArgs args, IEntity? item)
|
||||
{
|
||||
if (item == null)
|
||||
return false;
|
||||
|
||||
if (args.Function == ContentKeyFunctions.ExamineEntity)
|
||||
{
|
||||
_entitySystemManager.GetEntitySystem<ExamineSystem>()
|
||||
.DoExamine(item);
|
||||
}
|
||||
else if (args.Function == ContentKeyFunctions.OpenContextMenu)
|
||||
{
|
||||
_entitySystemManager.GetEntitySystem<VerbSystem>()
|
||||
.OpenContextMenu(item, _uiMgr.ScreenToUIPosition(args.PointerLocation));
|
||||
}
|
||||
else if (args.Function == ContentKeyFunctions.ActivateItemInWorld)
|
||||
{
|
||||
var inputSys = _entitySystemManager.GetEntitySystem<InputSystem>();
|
||||
|
||||
var func = args.Function;
|
||||
var funcId = _inputManager.NetworkBindMap.KeyFunctionID(args.Function);
|
||||
|
||||
|
||||
var mousePosWorld = _eyeManager.ScreenToMap(args.PointerLocation);
|
||||
|
||||
var coordinates = _mapManager.TryFindGridAt(mousePosWorld, out var grid) ? grid.MapToGrid(mousePosWorld) :
|
||||
EntityCoordinates.FromMap(_entityManager, _mapManager, mousePosWorld);
|
||||
|
||||
var message = new FullInputCmdMessage(_gameTiming.CurTick, _gameTiming.TickFraction, funcId, BoundKeyState.Down,
|
||||
coordinates, args.PointerLocation, item.Uid);
|
||||
|
||||
// client side command handlers will always be sent the local player session.
|
||||
var session = _playerManager.LocalPlayer?.Session;
|
||||
if (session == null)
|
||||
return false;
|
||||
|
||||
inputSys.HandleInputCommand(session, func, message);
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
args.Handle();
|
||||
return true;
|
||||
}
|
||||
|
||||
public void UpdateCooldown(ItemSlotButton? button, IEntity? entity)
|
||||
{
|
||||
var cooldownDisplay = button?.CooldownDisplay;
|
||||
|
||||
if (cooldownDisplay == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (entity == null ||
|
||||
!entity.TryGetComponent(out ItemCooldownComponent? cooldown) ||
|
||||
!cooldown.CooldownStart.HasValue ||
|
||||
!cooldown.CooldownEnd.HasValue)
|
||||
{
|
||||
cooldownDisplay.Visible = false;
|
||||
return;
|
||||
}
|
||||
|
||||
var start = cooldown.CooldownStart.Value;
|
||||
var end = cooldown.CooldownEnd.Value;
|
||||
|
||||
var length = (end - start).TotalSeconds;
|
||||
var progress = (_gameTiming.CurTime - start).TotalSeconds / length;
|
||||
var ratio = (progress <= 1 ? (1 - progress) : (_gameTiming.CurTime - end).TotalSeconds * -5);
|
||||
|
||||
cooldownDisplay.Progress = MathHelper.Clamp((float) ratio, -1, 1);
|
||||
cooldownDisplay.Visible = ratio > -1f;
|
||||
}
|
||||
|
||||
public void HoverInSlot(ItemSlotButton button, IEntity? entity, bool fits)
|
||||
{
|
||||
if (entity == null || !button.MouseIsHovering)
|
||||
{
|
||||
button.ClearHover();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!entity.HasComponent<SpriteComponent>())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Set green / red overlay at 50% transparency
|
||||
var hoverEntity = _entityManager.SpawnEntity("hoverentity", MapCoordinates.Nullspace);
|
||||
var hoverSprite = hoverEntity.GetComponent<SpriteComponent>();
|
||||
hoverSprite.CopyFrom(entity.GetComponent<SpriteComponent>());
|
||||
hoverSprite.Color = fits ? new Color(0, 255, 0, 127) : new Color(255, 0, 0, 127);
|
||||
|
||||
button.HoverSpriteView.Sprite = hoverSprite;
|
||||
}
|
||||
}
|
||||
}
|
||||
147
Content.Client/Items/UI/ItemSlotButton.cs
Normal file
147
Content.Client/Items/UI/ItemSlotButton.cs
Normal file
@@ -0,0 +1,147 @@
|
||||
using System;
|
||||
using Content.Client.Cooldown;
|
||||
using Content.Client.Stylesheets;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Shared.Input;
|
||||
using Robust.Shared.Maths;
|
||||
|
||||
namespace Content.Client.Items.UI
|
||||
{
|
||||
public class ItemSlotButton : Control
|
||||
{
|
||||
private const string HighlightShader = "SelectionOutlineInrange";
|
||||
|
||||
public TextureRect Button { get; }
|
||||
public SpriteView SpriteView { get; }
|
||||
public SpriteView HoverSpriteView { get; }
|
||||
public TextureButton StorageButton { get; }
|
||||
public CooldownGraphic CooldownDisplay { get; }
|
||||
|
||||
public Action<GUIBoundKeyEventArgs>? OnPressed { get; set; }
|
||||
public Action<GUIBoundKeyEventArgs>? OnStoragePressed { get; set; }
|
||||
public Action<GUIMouseHoverEventArgs>? OnHover { get; set; }
|
||||
|
||||
public bool EntityHover => HoverSpriteView.Sprite != null;
|
||||
public bool MouseIsHovering;
|
||||
|
||||
private readonly PanelContainer _highlightRect;
|
||||
|
||||
public string TextureName { get; set; }
|
||||
|
||||
public ItemSlotButton(Texture texture, Texture storageTexture, string textureName)
|
||||
{
|
||||
MinSize = (64, 64);
|
||||
|
||||
TextureName = textureName;
|
||||
|
||||
AddChild(Button = new TextureRect
|
||||
{
|
||||
Texture = texture,
|
||||
TextureScale = (2, 2),
|
||||
MouseFilter = MouseFilterMode.Stop
|
||||
});
|
||||
|
||||
AddChild(_highlightRect = new PanelContainer
|
||||
{
|
||||
StyleClasses = { StyleNano.StyleClassHandSlotHighlight },
|
||||
MinSize = (32, 32),
|
||||
Visible = false
|
||||
});
|
||||
|
||||
Button.OnKeyBindDown += OnButtonPressed;
|
||||
|
||||
AddChild(SpriteView = new SpriteView
|
||||
{
|
||||
Scale = (2, 2),
|
||||
OverrideDirection = Direction.South
|
||||
});
|
||||
|
||||
AddChild(HoverSpriteView = new SpriteView
|
||||
{
|
||||
Scale = (2, 2),
|
||||
OverrideDirection = Direction.South
|
||||
});
|
||||
|
||||
AddChild(StorageButton = new TextureButton
|
||||
{
|
||||
TextureNormal = storageTexture,
|
||||
Scale = (0.75f, 0.75f),
|
||||
HorizontalAlignment = HAlignment.Right,
|
||||
VerticalAlignment = VAlignment.Bottom,
|
||||
Visible = false,
|
||||
});
|
||||
|
||||
StorageButton.OnKeyBindDown += args =>
|
||||
{
|
||||
if (args.Function != EngineKeyFunctions.UIClick)
|
||||
{
|
||||
OnButtonPressed(args);
|
||||
}
|
||||
};
|
||||
|
||||
StorageButton.OnPressed += OnStorageButtonPressed;
|
||||
|
||||
Button.OnMouseEntered += _ =>
|
||||
{
|
||||
MouseIsHovering = true;
|
||||
};
|
||||
Button.OnMouseEntered += OnButtonHover;
|
||||
|
||||
Button.OnMouseExited += _ =>
|
||||
{
|
||||
MouseIsHovering = false;
|
||||
ClearHover();
|
||||
};
|
||||
|
||||
AddChild(CooldownDisplay = new CooldownGraphic
|
||||
{
|
||||
Visible = false,
|
||||
});
|
||||
}
|
||||
|
||||
public void ClearHover()
|
||||
{
|
||||
if (EntityHover)
|
||||
{
|
||||
HoverSpriteView.Sprite?.Owner.Delete();
|
||||
HoverSpriteView.Sprite = null;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void Highlight(bool highlight)
|
||||
{
|
||||
if (highlight)
|
||||
{
|
||||
_highlightRect.Visible = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
_highlightRect.Visible = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnButtonPressed(GUIBoundKeyEventArgs args)
|
||||
{
|
||||
OnPressed?.Invoke(args);
|
||||
}
|
||||
|
||||
private void OnStorageButtonPressed(BaseButton.ButtonEventArgs args)
|
||||
{
|
||||
if (args.Event.Function == EngineKeyFunctions.UIClick)
|
||||
{
|
||||
OnStoragePressed?.Invoke(args.Event);
|
||||
}
|
||||
else
|
||||
{
|
||||
OnPressed?.Invoke(args.Event);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnButtonHover(GUIMouseHoverEventArgs args)
|
||||
{
|
||||
OnHover?.Invoke(args);
|
||||
}
|
||||
}
|
||||
}
|
||||
162
Content.Client/Items/UI/ItemStatusPanel.cs
Normal file
162
Content.Client/Items/UI/ItemStatusPanel.cs
Normal file
@@ -0,0 +1,162 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Content.Client.Items.Components;
|
||||
using Content.Client.Resources;
|
||||
using Content.Client.Stylesheets;
|
||||
using Content.Shared.Hands.Components;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Utility;
|
||||
using Robust.Shared.ViewVariables;
|
||||
using static Content.Client.IoC.StaticIoC;
|
||||
|
||||
namespace Content.Client.Items.UI
|
||||
{
|
||||
public class ItemStatusPanel : Control
|
||||
{
|
||||
[ViewVariables]
|
||||
private readonly List<(IItemStatus, Control)> _activeStatusComponents = new();
|
||||
|
||||
[ViewVariables]
|
||||
private readonly Label _itemNameLabel;
|
||||
[ViewVariables]
|
||||
private readonly VBoxContainer _statusContents;
|
||||
[ViewVariables]
|
||||
private readonly PanelContainer _panel;
|
||||
|
||||
[ViewVariables]
|
||||
private IEntity? _entity;
|
||||
|
||||
public ItemStatusPanel(Texture texture, StyleBox.Margin cutout, StyleBox.Margin flat, Label.AlignMode textAlign)
|
||||
{
|
||||
var panel = new StyleBoxTexture
|
||||
{
|
||||
Texture = texture
|
||||
};
|
||||
panel.SetContentMarginOverride(StyleBox.Margin.Vertical, 4);
|
||||
panel.SetContentMarginOverride(StyleBox.Margin.Horizontal, 6);
|
||||
panel.SetPatchMargin(flat, 2);
|
||||
panel.SetPatchMargin(cutout, 13);
|
||||
|
||||
AddChild(_panel = new PanelContainer
|
||||
{
|
||||
PanelOverride = panel,
|
||||
ModulateSelfOverride = Color.White.WithAlpha(0.9f),
|
||||
Children =
|
||||
{
|
||||
new VBoxContainer
|
||||
{
|
||||
SeparationOverride = 0,
|
||||
Children =
|
||||
{
|
||||
(_statusContents = new VBoxContainer()),
|
||||
(_itemNameLabel = new Label
|
||||
{
|
||||
ClipText = true,
|
||||
StyleClasses = {StyleNano.StyleClassItemStatus},
|
||||
Align = textAlign
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
VerticalAlignment = VAlignment.Bottom;
|
||||
|
||||
// TODO: Depending on if its a two-hand panel or not
|
||||
MinSize = (150, 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of <see cref="ItemStatusPanel"/>
|
||||
/// based on whether or not it is being created for the right
|
||||
/// or left hand.
|
||||
/// </summary>
|
||||
/// <param name="location">
|
||||
/// The location of the hand that this panel is for
|
||||
/// </param>
|
||||
/// <returns>the new <see cref="ItemStatusPanel"/> instance</returns>
|
||||
public static ItemStatusPanel FromSide(HandLocation location)
|
||||
{
|
||||
string texture;
|
||||
StyleBox.Margin cutOut;
|
||||
StyleBox.Margin flat;
|
||||
Label.AlignMode textAlign;
|
||||
|
||||
switch (location)
|
||||
{
|
||||
case HandLocation.Left:
|
||||
texture = "/Textures/Interface/Nano/item_status_right.svg.96dpi.png";
|
||||
cutOut = StyleBox.Margin.Left | StyleBox.Margin.Top;
|
||||
flat = StyleBox.Margin.Right | StyleBox.Margin.Bottom;
|
||||
textAlign = Label.AlignMode.Right;
|
||||
break;
|
||||
case HandLocation.Middle:
|
||||
texture = "/Textures/Interface/Nano/item_status_middle.svg.96dpi.png";
|
||||
cutOut = StyleBox.Margin.Right | StyleBox.Margin.Top;
|
||||
flat = StyleBox.Margin.Left | StyleBox.Margin.Bottom;
|
||||
textAlign = Label.AlignMode.Left;
|
||||
break;
|
||||
case HandLocation.Right:
|
||||
texture = "/Textures/Interface/Nano/item_status_left.svg.96dpi.png";
|
||||
cutOut = StyleBox.Margin.Right | StyleBox.Margin.Top;
|
||||
flat = StyleBox.Margin.Left | StyleBox.Margin.Bottom;
|
||||
textAlign = Label.AlignMode.Left;
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException(nameof(location), location, null);
|
||||
}
|
||||
|
||||
return new ItemStatusPanel(ResC.GetTexture(texture), cutOut, flat, textAlign);
|
||||
}
|
||||
|
||||
public void Update(IEntity? entity)
|
||||
{
|
||||
if (entity == null)
|
||||
{
|
||||
ClearOldStatus();
|
||||
_entity = null;
|
||||
_panel.Visible = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (entity != _entity)
|
||||
{
|
||||
_entity = entity;
|
||||
BuildNewEntityStatus();
|
||||
_itemNameLabel.Text = entity.Name;
|
||||
}
|
||||
|
||||
_panel.Visible = true;
|
||||
}
|
||||
|
||||
private void ClearOldStatus()
|
||||
{
|
||||
_statusContents.RemoveAllChildren();
|
||||
|
||||
foreach (var (itemStatus, control) in _activeStatusComponents)
|
||||
{
|
||||
itemStatus.DestroyControl(control);
|
||||
}
|
||||
|
||||
_activeStatusComponents.Clear();
|
||||
}
|
||||
|
||||
private void BuildNewEntityStatus()
|
||||
{
|
||||
DebugTools.AssertNotNull(_entity);
|
||||
|
||||
ClearOldStatus();
|
||||
|
||||
foreach (var statusComponent in _entity!.GetAllComponents<IItemStatus>())
|
||||
{
|
||||
var control = statusComponent.MakeControl();
|
||||
_statusContents.AddChild(control);
|
||||
|
||||
_activeStatusComponents.Add((statusComponent, control));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user