Functional GUI!
This commit is contained in:
@@ -62,8 +62,9 @@
|
||||
<Compile Include="EntryPoint.cs" />
|
||||
<Compile Include="Prototypes\DiscoBall.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="GameObjects\Components\Items\HandsComponent.cs" />
|
||||
<Compile Include="GameObjects\Components\Items\ClientHandsComponent.cs" />
|
||||
<Compile Include="Interfaces\GameObjects\Components\Items\IHandsComponent.cs" />
|
||||
<Compile Include="UserInterface\HandsGui.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Content.Shared\Content.Shared.csproj">
|
||||
@@ -82,6 +83,10 @@
|
||||
<Project>{31d24303-f6a9-4d53-bb03-a73edcb3186d}</Project>
|
||||
<Name>sfml-system</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\engine\SFML\src\Window\sfml-window.csproj">
|
||||
<Project>{d17de83d-a592-461f-8af2-53f9e22e1d0f}</Project>
|
||||
<Name>sfml-window</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\engine\SS14.Client.Graphics\SS14.Client.Graphics.csproj">
|
||||
<Project>{302b877e-0000-0000-0000-000000000000}</Project>
|
||||
<Name>SS14.Client.Graphics</Name>
|
||||
@@ -105,4 +110,4 @@
|
||||
<ContentAssemblies Include="$(OutputPath)Content.Client.pdb" Condition="'$(Configuration)' == 'Debug'" />
|
||||
<ContentAssemblies Include="$(OutputPath)Content.Shared.pdb" Condition="'$(Configuration)' == 'Debug'" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
</Project>
|
||||
@@ -1,5 +1,10 @@
|
||||
using Content.Client.Interfaces.GameObjects;
|
||||
using Content.Client.Interfaces.GameObjects;
|
||||
using Content.Client.UserInterface;
|
||||
using Content.Shared.GameObjects;
|
||||
using Lidgren.Network;
|
||||
using SS14.Client.Interfaces.UserInterface;
|
||||
using SS14.Client.UserInterface;
|
||||
using SS14.Shared;
|
||||
using SS14.Shared.GameObjects;
|
||||
using SS14.Shared.Interfaces.GameObjects;
|
||||
using SS14.Shared.IoC;
|
||||
@@ -10,6 +15,7 @@ namespace Content.Client.GameObjects
|
||||
public class HandsComponent : SharedHandsComponent, IHandsComponent
|
||||
{
|
||||
private readonly Dictionary<string, IEntity> hands = new Dictionary<string, IEntity>();
|
||||
public string ActiveIndex { get; private set; }
|
||||
|
||||
public IEntity GetEntity(string index)
|
||||
{
|
||||
@@ -29,6 +35,21 @@ namespace Content.Client.GameObjects
|
||||
{
|
||||
hands[hand.Key] = Owner.EntityManager.GetEntity(hand.Value);
|
||||
}
|
||||
|
||||
ActiveIndex = cast.ActiveIndex;
|
||||
|
||||
var uiMgr = (UserInterfaceManager)IoCManager.Resolve<IUserInterfaceManager>();
|
||||
|
||||
if (uiMgr.GetSingleComponentByGuiComponentType(GuiComponentType.HandsUi) == null)
|
||||
{
|
||||
uiMgr.AddComponent(new HandsGui());
|
||||
}
|
||||
uiMgr.ComponentUpdate(GuiComponentType.HandsUi, this);
|
||||
}
|
||||
|
||||
public void SendChangeHand(string index)
|
||||
{
|
||||
Owner.SendComponentNetworkMessage(this, NetDeliveryMethod.ReliableUnordered, index);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,4 @@
|
||||
using Content.Client.Interfaces.GameObjects;
|
||||
using Content.Shared.GameObjects;
|
||||
using SS14.Shared.GameObjects;
|
||||
using SS14.Shared.Interfaces.GameObjects;
|
||||
using SS14.Shared.IoC;
|
||||
using System.Collections.Generic;
|
||||
using SS14.Shared.Interfaces.GameObjects;
|
||||
|
||||
namespace Content.Client.Interfaces.GameObjects
|
||||
{
|
||||
@@ -12,5 +7,8 @@ namespace Content.Client.Interfaces.GameObjects
|
||||
public interface IHandsComponent
|
||||
{
|
||||
IEntity GetEntity(string index);
|
||||
string ActiveIndex { get; }
|
||||
|
||||
void SendChangeHand(string index);
|
||||
}
|
||||
}
|
||||
|
||||
192
Content.Client/UserInterface/HandsGui.cs
Normal file
192
Content.Client/UserInterface/HandsGui.cs
Normal file
@@ -0,0 +1,192 @@
|
||||
using Content.Client.Interfaces.GameObjects;
|
||||
using OpenTK.Graphics;
|
||||
using SFML.Graphics;
|
||||
using SFML.Window;
|
||||
using SS14.Client.GameObjects;
|
||||
using SS14.Client.Graphics;
|
||||
using SS14.Client.Graphics.Utility;
|
||||
using SS14.Client.Interfaces.Player;
|
||||
using SS14.Client.Interfaces.Resource;
|
||||
using SS14.Client.Interfaces.UserInterface;
|
||||
using SS14.Client.UserInterface.Components;
|
||||
using SS14.Shared;
|
||||
using SS14.Shared.Interfaces.GameObjects;
|
||||
using SS14.Shared.IoC;
|
||||
using SS14.Shared.Maths;
|
||||
|
||||
namespace Content.Client.UserInterface
|
||||
{
|
||||
public class HandsGui : GuiComponent
|
||||
{
|
||||
private readonly Color4 _inactiveColor = new Color4(90, 90, 90, 255);
|
||||
|
||||
private readonly IPlayerManager _playerManager = IoCManager.Resolve<IPlayerManager>();
|
||||
private readonly IUserInterfaceManager _userInterfaceManager = IoCManager.Resolve<IUserInterfaceManager>();
|
||||
private readonly Sprite handSlot;
|
||||
private readonly int spacing = 1;
|
||||
|
||||
private UiHandInfo LeftHand;
|
||||
private UiHandInfo RightHand;
|
||||
private Box2i handL;
|
||||
private Box2i handR;
|
||||
|
||||
public HandsGui()
|
||||
{
|
||||
var _resMgr = IoCManager.Resolve<IResourceCache>();
|
||||
ComponentClass = GuiComponentType.HandsUi;
|
||||
handSlot = _resMgr.GetSprite("hand");
|
||||
ZDepth = 5;
|
||||
}
|
||||
|
||||
public override void ComponentUpdate(params object[] args)
|
||||
{
|
||||
base.ComponentUpdate(args);
|
||||
UpdateHandIcons();
|
||||
}
|
||||
|
||||
public override void Update(float frameTime)
|
||||
{
|
||||
var slotBounds = handSlot.GetLocalBounds();
|
||||
var width = (int)((slotBounds.Width * 2) + spacing);
|
||||
var height = (int)slotBounds.Height;
|
||||
Position = new Vector2i((int)(CluwneLib.Window.Viewport.Width - width) / 2, (int)CluwneLib.Window.Viewport.Height - height - 10);
|
||||
handL = Box2i.FromDimensions(Position.X, Position.Y, (int)slotBounds.Width, (int)slotBounds.Height);
|
||||
handR = Box2i.FromDimensions(Position.X + (int)slotBounds.Width + spacing, Position.Y, (int)slotBounds.Width, (int)slotBounds.Height);
|
||||
ClientArea = Box2i.FromDimensions(Position.X, Position.Y, width, (int)slotBounds.Height);
|
||||
}
|
||||
|
||||
public override void Render()
|
||||
{
|
||||
if (_playerManager?.ControlledEntity == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
IEntity entity = _playerManager.ControlledEntity;
|
||||
if (!entity.TryGetComponent<IHandsComponent>(out var hands))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var leftActive = hands.ActiveIndex == "left";
|
||||
|
||||
handSlot.Color = Color.White;
|
||||
handSlot.SetTransformToRect(leftActive ? handL : handR);
|
||||
handSlot.Draw();
|
||||
|
||||
handSlot.Color = _inactiveColor.Convert();
|
||||
handSlot.SetTransformToRect(leftActive ? handR : handL);
|
||||
handSlot.Draw();
|
||||
|
||||
if (LeftHand.Entity != null && LeftHand.HeldSprite != null)
|
||||
{
|
||||
var bounds = LeftHand.HeldSprite.GetLocalBounds();
|
||||
LeftHand.HeldSprite.SetTransformToRect(
|
||||
Box2i.FromDimensions(handL.Left + (int)(handL.Width / 2f - bounds.Width / 2f),
|
||||
handL.Top + (int)(handL.Height / 2f - bounds.Height / 2f),
|
||||
(int)bounds.Width, (int)bounds.Height));
|
||||
LeftHand.HeldSprite.Draw();
|
||||
}
|
||||
|
||||
if (RightHand.Entity != null && RightHand.HeldSprite != null)
|
||||
{
|
||||
var bounds = RightHand.HeldSprite.GetLocalBounds();
|
||||
RightHand.HeldSprite.SetTransformToRect(
|
||||
Box2i.FromDimensions(handR.Left + (int)(handR.Width / 2f - bounds.Width / 2f),
|
||||
handR.Top + (int)(handR.Height / 2f - bounds.Height / 2f),
|
||||
(int)bounds.Width, (int)bounds.Height));
|
||||
RightHand.HeldSprite.Draw();
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateHandIcons()
|
||||
{
|
||||
if (_playerManager?.ControlledEntity == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
IEntity entity = _playerManager.ControlledEntity;
|
||||
if (!entity.TryGetComponent<IHandsComponent>(out var hands))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var left = hands.GetEntity("left");
|
||||
var right = hands.GetEntity("right");
|
||||
|
||||
if (left != null)
|
||||
{
|
||||
if (left != LeftHand.Entity)
|
||||
{
|
||||
LeftHand.Entity = left;
|
||||
LeftHand.HeldSprite = GetIconSprite(left);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LeftHand.Entity = null;
|
||||
LeftHand.HeldSprite = null;
|
||||
}
|
||||
|
||||
if (right != null)
|
||||
{
|
||||
if (right != RightHand.Entity)
|
||||
{
|
||||
RightHand.Entity = right;
|
||||
RightHand.HeldSprite = GetIconSprite(right);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
RightHand.Entity = null;
|
||||
RightHand.HeldSprite = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void SendSwitchHandTo(string index)
|
||||
{
|
||||
IEntity entity = _playerManager.ControlledEntity;
|
||||
if (!entity.TryGetComponent<IHandsComponent>(out var hands))
|
||||
{
|
||||
return;
|
||||
}
|
||||
hands.SendChangeHand(index);
|
||||
}
|
||||
|
||||
public override bool MouseDown(MouseButtonEventArgs e)
|
||||
{
|
||||
if (e.Button != Mouse.Button.Right)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (handL.Contains(e.X, e.Y))
|
||||
{
|
||||
SendSwitchHandTo("left");
|
||||
return true;
|
||||
}
|
||||
if (handR.Contains(e.X, e.Y))
|
||||
{
|
||||
SendSwitchHandTo("right");
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static Sprite GetIconSprite(IEntity entity)
|
||||
{
|
||||
Sprite icon = null;
|
||||
if (entity.TryGetComponent<IconComponent>(out var component))
|
||||
{
|
||||
icon = component.Icon;
|
||||
}
|
||||
return icon ?? IoCManager.Resolve<IResourceCache>().DefaultSprite();
|
||||
}
|
||||
|
||||
private struct UiHandInfo
|
||||
{
|
||||
public IEntity Entity { get; set; }
|
||||
public Sprite HeldSprite { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -59,7 +59,7 @@
|
||||
<Compile Include="Interfaces\GameObjects\Components\Items\IHandsComponent.cs" />
|
||||
<Compile Include="Interfaces\GameObjects\Components\Items\IInventoryComponent.cs" />
|
||||
<Compile Include="Interfaces\GameObjects\Components\Items\IItemComponent.cs" />
|
||||
<Compile Include="GameObjects\Components\Items\HandsComponent.cs" />
|
||||
<Compile Include="GameObjects\Components\Items\ServerHandsComponent.cs" />
|
||||
<Compile Include="GameObjects\Components\Items\InventoryComponent.cs" />
|
||||
<Compile Include="GameObjects\Components\Items\ItemComponent.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
@@ -91,4 +91,4 @@
|
||||
<ContentAssemblies Include="$(OutputPath)Content.Server.pdb" Condition="'$(Configuration)' == 'Debug'" />
|
||||
<ContentAssemblies Include="$(OutputPath)Content.Shared.pdb" Condition="'$(Configuration)' == 'Debug'" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
</Project>
|
||||
@@ -1,6 +1,7 @@
|
||||
using Content.Server.Interfaces.GameObjects;
|
||||
using Content.Server.Interfaces.GameObjects;
|
||||
using SS14.Shared.GameObjects;
|
||||
using SS14.Shared.Interfaces.GameObjects;
|
||||
using SS14.Server.Interfaces.GameObjects;
|
||||
using System;
|
||||
|
||||
namespace Content.Server.GameObjects
|
||||
@@ -20,6 +21,11 @@ namespace Content.Server.GameObjects
|
||||
}
|
||||
|
||||
ContainingSlot = null;
|
||||
|
||||
foreach (var component in Owner.GetComponents<ISpriteRenderableComponent>())
|
||||
{
|
||||
component.Visible = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void EquippedToSlot(IInventorySlot slot)
|
||||
@@ -30,6 +36,11 @@ namespace Content.Server.GameObjects
|
||||
}
|
||||
|
||||
ContainingSlot = slot;
|
||||
|
||||
foreach (var component in Owner.GetComponents<ISpriteRenderableComponent>())
|
||||
{
|
||||
component.Visible = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,12 +4,11 @@ using SS14.Server.GameObjects.Events;
|
||||
using SS14.Server.Interfaces.GameObjects;
|
||||
using SS14.Shared;
|
||||
using SS14.Shared.GameObjects;
|
||||
using SS14.Shared.Interfaces.GameObjects;
|
||||
using SS14.Shared.Utility;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using YamlDotNet.RepresentationModel;
|
||||
using Lidgren.Network;
|
||||
|
||||
namespace Content.Server.GameObjects
|
||||
{
|
||||
@@ -224,7 +223,7 @@ namespace Content.Server.GameObjects
|
||||
dict[hand.Key] = hand.Value.Item.Owner.Uid;
|
||||
}
|
||||
}
|
||||
return new HandsComponentState(dict);
|
||||
return new HandsComponentState(dict, ActiveIndex);
|
||||
}
|
||||
|
||||
// Game logic goes here.
|
||||
@@ -276,5 +275,19 @@ namespace Content.Server.GameObjects
|
||||
|
||||
PutInHand(item, ActiveIndex, fallback: false);
|
||||
}
|
||||
|
||||
public override void HandleNetworkMessage(IncomingEntityComponentMessage message, NetConnection sender)
|
||||
{
|
||||
if (message.MessageParameters.Count != 1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var index = message.MessageParameters[0];
|
||||
if (index is string newIndex && HasHand(newIndex))
|
||||
{
|
||||
ActiveIndex = newIndex;
|
||||
}
|
||||
base.HandleNetworkMessage(message, sender);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -56,7 +56,7 @@
|
||||
<ItemGroup>
|
||||
<Compile Include="EntryPoint.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="GameObjects\Components\Items\HandsComponent.cs" />
|
||||
<Compile Include="GameObjects\Components\Items\SharedHandsComponent.cs" />
|
||||
<Compile Include="GameObjects\Components\NetIDs.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
@@ -97,4 +97,4 @@
|
||||
<Copy SourceFiles="@(Resource)" DestinationFiles="..\bin\Server\Resources\%(Prefix)%(RecursiveDir)%(Filename)%(Extension)" />
|
||||
</Target>
|
||||
<Target Name="AfterBuild" DependsOnTargets="CopyResources" />
|
||||
</Project>
|
||||
</Project>
|
||||
@@ -1,4 +1,4 @@
|
||||
using SS14.Shared.GameObjects;
|
||||
using SS14.Shared.GameObjects;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
@@ -16,10 +16,12 @@ namespace Content.Shared.GameObjects
|
||||
public class HandsComponentState : ComponentState
|
||||
{
|
||||
public readonly Dictionary<string, int> Hands;
|
||||
public readonly string ActiveIndex;
|
||||
|
||||
public HandsComponentState(Dictionary<string, int> hands)
|
||||
public HandsComponentState(Dictionary<string, int> hands, string activeIndex) : base(ContentNetIDs.HANDS)
|
||||
{
|
||||
Hands = hands;
|
||||
ActiveIndex = activeIndex;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,3 +5,10 @@
|
||||
components:
|
||||
- type: Item
|
||||
|
||||
- type: entity
|
||||
name: "Mop 2: Handle edition"
|
||||
parent: Mop
|
||||
id: MopItem
|
||||
components:
|
||||
- type: Item
|
||||
|
||||
|
||||
Reference in New Issue
Block a user