Species Component (#130)

* Fix this
fug
oksure
Creates the initial species component, damage states, and threshold templates and hooks them into the damageable component

* More rebase fixes

* test

* Pre future rebase

* Please

* Lol

* Lol2

* SHADERS

* Update Engine

* yml file

* Fix an initialization issue, injects dependencies

* Fix error in loading shaders

* Makes a master character ui controller component added upon client attachment to entity and remove upon client detachment from entity

* Fixes just about everytrhing

* Address PJB's comments

* geeze

* Make overlays work in worldspace instead of screen space and not cover user interfaces

* update submodule
This commit is contained in:
clusterfack
2018-12-13 07:47:19 -06:00
committed by Pieter-Jan Briers
parent b8becf4a56
commit 37df61113e
52 changed files with 1172 additions and 183 deletions

View File

@@ -0,0 +1,108 @@
using Content.Client.GameObjects.Components.Mobs;
using Content.Shared.Input;
using SS14.Client.Interfaces.Input;
using SS14.Client.UserInterface.CustomControls;
using SS14.Shared.GameObjects;
using SS14.Shared.Input;
using SS14.Shared.IoC;
using SS14.Shared.Utility;
using System.Collections.Generic;
using System.Linq;
namespace Content.Client.GameObjects.Components.Actor
{
/// <summary>
/// A semi-abstract component which gets added to entities upon attachment and collects all character
/// user interfaces into a single window and keybind for the user
/// </summary>
public class CharacterInterface : Component
{
public override string Name => "Character Interface Component";
/// <summary>
/// Stored keybind to open the menu on keypress
/// </summary>
private InputCmdHandler _openMenuCmdHandler;
/// <summary>
/// Window to hold each of the character interfaces
/// </summary>
private SS14Window _window;
/// <summary>
/// Create the window with all character UIs and bind it to a keypress
/// </summary>
public override void Initialize()
{
base.Initialize();
//Use all the character ui interfaced components to create the character window
var UIcomponents = Owner.GetAllComponents<ICharacterUI>();
_window = new CharacterWindow(UIcomponents);
//Add to screen the window and hide it
_window.AddToScreen();
_window.Close();
//Toggle window visible/invisible on keypress
_openMenuCmdHandler = InputCmdHandler.FromDelegate(session => {
if (_window.Visible)
{
_window.Close();
}
else
{
_window.Open();
}
});
//Set keybind to open character menu
var inputMgr = IoCManager.Resolve<IInputManager>();
inputMgr.SetInputCommand(ContentKeyFunctions.OpenCharacterMenu, _openMenuCmdHandler);
}
/// <summary>
/// Dispose of window and the keypress binding
/// </summary>
public override void OnRemove()
{
base.OnRemove();
_window.Dispose();
_window = null;
var inputMgr = IoCManager.Resolve<IInputManager>();
inputMgr.SetInputCommand(ContentKeyFunctions.OpenCharacterMenu, null);
}
/// <summary>
/// A window that collects and shows all the individual character user interfaces
/// </summary>
public class CharacterWindow : SS14Window
{
protected override ResourcePath ScenePath => new ResourcePath("/Scenes/Mobs/CharacterWindow.tscn");
public CharacterWindow(IEnumerable<ICharacterUI> windowcomponents)
{
//TODO: sort window components by priority of window component
foreach(var element in windowcomponents.OrderByDescending(x => x.Priority))
{
Contents.AddChild(element.Scene);
}
HideOnClose = true;
}
}
}
/// <summary>
/// Determines ordering of the character user interface, small values come sooner
/// </summary>
public enum UIPriority
{
First = 0,
Species = 100,
Inventory = 200,
Last = 99999
}
}

View File

@@ -0,0 +1,31 @@
using Content.Shared.GameObjects;
using SS14.Shared.GameObjects;
using SS14.Shared.Interfaces.GameObjects;
using SS14.Shared.Interfaces.Network;
using System.Collections.Generic;
namespace Content.Client.GameObjects
{
/// <summary>
/// Fuck I really hate doing this
/// TODO: make sure the client only gets damageable component on the clientside entity for its player mob
/// </summary>
public class DamageableComponent : SharedDamageableComponent
{
/// <inheritdoc />
public override string Name => "Damageable";
public Dictionary<DamageType, int> CurrentDamage = new Dictionary<DamageType, int>();
public override void HandleComponentState(ComponentState state)
{
base.HandleComponentState(state);
if(state is DamageComponentState)
{
var damagestate = (DamageComponentState)state;
CurrentDamage = damagestate.CurrentDamage;
}
}
}
}

View File

@@ -1,15 +1,9 @@
using Content.Shared.GameObjects;
using Content.Shared.Input;
using SS14.Client.GameObjects;
using SS14.Client.Interfaces.GameObjects.Components;
using SS14.Client.Interfaces.Input;
using SS14.Client.UserInterface;
using SS14.Client.UserInterface.Controls;
using SS14.Client.UserInterface.CustomControls;
using SS14.Shared.GameObjects;
using SS14.Shared.Input;
using SS14.Shared.Interfaces.GameObjects;
using SS14.Shared.Interfaces.Network;
using SS14.Shared.IoC;
using SS14.Shared.Serialization;
using SS14.Shared.Utility;
@@ -20,21 +14,36 @@ using Content.Client.GameObjects.Components.Clothing;
using SS14.Shared.Interfaces.Reflection;
using static Content.Shared.GameObjects.Components.Inventory.EquipmentSlotDefines;
using static Content.Shared.GameObjects.SharedInventoryComponent.ClientInventoryMessage;
using Content.Client.GameObjects.Components.Mobs;
using Content.Client.GameObjects.Components.Actor;
namespace Content.Client.GameObjects
{
public class ClientInventoryComponent : SharedInventoryComponent
/// <summary>
/// A character UI which shows items the user has equipped within his inventory
/// </summary>
public class ClientInventoryComponent : SharedInventoryComponent, ICharacterUI
{
private Dictionary<Slots, IEntity> _slots = new Dictionary<Slots, IEntity>();
/// <summary>
/// Holds the godot control for the inventory window
/// </summary>
private InventoryWindow _window;
private string _templateName = "HumanInventory"; //stored for serialization purposes
private InputCmdHandler _openMenuCmdHandler;
/// <summary>
/// Inventory template after being loaded from instance creator and string name
/// </summary>
private Inventory _inventory;
private ISpriteComponent _sprite;
//Relevant interface implementation for the character UI controller
public Control Scene => _window;
public UIPriority Priority => UIPriority.Inventory;
public override void OnRemove()
{
base.OnRemove();
@@ -42,22 +51,17 @@ namespace Content.Client.GameObjects
_window.Dispose();
}
public override void OnAdd()
{
base.OnAdd();
_openMenuCmdHandler = InputCmdHandler.FromDelegate(session => { _window.AddToScreen(); _window.Open(); });
}
public override void Initialize()
{
base.Initialize();
//Loads inventory template
var reflectionManager = IoCManager.Resolve<IReflectionManager>();
var type = reflectionManager.LooseGetType(_templateName);
DebugTools.Assert(type != null);
_inventory = (Inventory)Activator.CreateInstance(type);
//Creates godot control class for inventory
_window = new InventoryWindow(this);
_window.CreateInventory(_inventory);
@@ -120,21 +124,6 @@ namespace Content.Client.GameObjects
}
}
public override void HandleMessage(ComponentMessage message, INetChannel netChannel = null, IComponent component = null)
{
var inputMgr = IoCManager.Resolve<IInputManager>();
switch (message)
{
case PlayerAttachedMsg _:
inputMgr.SetInputCommand(ContentKeyFunctions.OpenCharacterMenu, _openMenuCmdHandler);
break;
case PlayerDetachedMsg _:
inputMgr.SetInputCommand(ContentKeyFunctions.OpenCharacterMenu, null);
break;
}
}
private void _setSlot(Slots slot, IEntity entity)
{
if (_sprite != null && entity.TryGetComponent(out ClothingComponent clothing))
@@ -178,7 +167,7 @@ namespace Content.Client.GameObjects
/// <summary>
/// Temporary window to hold the basis for inventory hud
/// </summary>
private class InventoryWindow : SS14Window
private class InventoryWindow : Control
{
private int elements_x;
@@ -187,13 +176,11 @@ namespace Content.Client.GameObjects
private Dictionary<Slots, InventoryButton> InventorySlots = new Dictionary<Slots, InventoryButton>(); //ordered dictionary?
private ClientInventoryComponent InventoryComponent;
protected override ResourcePath ScenePath => new ResourcePath("/Scenes/Inventory/HumanInventory.tscn");
protected override ResourcePath ScenePath => new ResourcePath("/Scenes/Mobs/HumanInventory.tscn");
public InventoryWindow(ClientInventoryComponent inventory)
{
InventoryComponent = inventory;
HideOnClose = true;
}
/// <summary>
@@ -203,7 +190,7 @@ namespace Content.Client.GameObjects
{
elements_x = inventory.Columns;
GridContainer = (GridContainer)Contents.GetChild("PanelContainer").GetChild("CenterContainer").GetChild("GridContainer");
GridContainer = (GridContainer)GetChild("CenterContainer").GetChild("GridContainer");
GridContainer.Columns = elements_x;
IndexedSlots = new List<Slots>(inventory.SlotMasks);
@@ -304,7 +291,7 @@ namespace Content.Client.GameObjects
public Slots Slot;
public EntityUid EntityUid;
protected override ResourcePath ScenePath => new ResourcePath("/Scenes/Inventory/StorageSlot.tscn");
protected override ResourcePath ScenePath => new ResourcePath("/Scenes/Mobs/StorageSlot.tscn");
public InventoryButton(Slots slot)
{

View File

@@ -0,0 +1,21 @@
using Content.Client.GameObjects.Components.Actor;
using SS14.Client.UserInterface;
namespace Content.Client.GameObjects.Components.Mobs
{
/// <summary>
/// An interface which is gathered to assemble the character window from multiple components
/// </summary>
public interface ICharacterUI
{
/// <summary>
/// The godot control which holds the character user interface to be included in the window
/// </summary>
Control Scene { get; }
/// <summary>
/// The order it will appear in the character UI, higher is lower
/// </summary>
UIPriority Priority { get; }
}
}

View File

@@ -0,0 +1,160 @@
using Content.Client.GameObjects.Components.Actor;
using Content.Client.GameObjects.Components.Mobs;
using Content.Client.Graphics.Overlays;
using Content.Shared.GameObjects;
using SS14.Client.GameObjects;
using SS14.Client.Interfaces.Graphics.Overlays;
using SS14.Client.Interfaces.ResourceManagement;
using SS14.Client.Player;
using SS14.Client.ResourceManagement;
using SS14.Client.UserInterface;
using SS14.Client.UserInterface.Controls;
using SS14.Shared.GameObjects;
using SS14.Shared.Interfaces.GameObjects;
using SS14.Shared.Interfaces.Network;
using SS14.Shared.IoC;
using SS14.Shared.Log;
using SS14.Shared.Utility;
using System.Collections.Generic;
namespace Content.Client.GameObjects
{
/// <summary>
/// A character UI component which shows the current damage state of the mob (living/dead)
/// </summary>
public class SpeciesUI : Component, ICharacterUI
{
public override string Name => "Species";
public override uint? NetID => ContentNetIDs.SPECIES;
/// <summary>
/// Holds the godot control for the species window
/// </summary>
private SpeciesWindow _window;
/// <summary>
/// An enum representing the current state being applied to the user
/// </summary>
private ScreenEffects _currentEffect = ScreenEffects.None;
// Required dependencies
[Dependency] private readonly IOverlayManager _overlayManager;
[Dependency] private readonly IPlayerManager _playerManager;
//Relevant interface implementation for the character UI controller
public Control Scene => _window;
public UIPriority Priority => UIPriority.Species;
/// <summary>
/// Allows calculating if we need to act due to this component being controlled by the current mob
/// </summary>
private bool CurrentlyControlled => _playerManager.LocalPlayer.ControlledEntity == Owner;
/// <summary>
/// Holds the screen effects that can be applied mapped ot their relevant overlay
/// </summary>
private Dictionary<ScreenEffects, IOverlay> EffectsDictionary;
public override void OnRemove()
{
base.OnRemove();
_window.Dispose();
}
public override void OnAdd()
{
base.OnAdd();
IoCManager.InjectDependencies(this);
_window = new SpeciesWindow();
EffectsDictionary = new Dictionary<ScreenEffects, IOverlay>()
{
{ ScreenEffects.CircleMask, new CircleMaskOverlay() },
{ ScreenEffects.GradientCircleMask, new GradientCircleMask() }
};
}
public override void HandleMessage(ComponentMessage message, INetChannel netChannel = null, IComponent component = null)
{
switch (message)
{
case HudStateChange msg:
if(CurrentlyControlled)
{
ChangeHudIcon(msg);
}
break;
case PlayerAttachedMsg _:
ApplyOverlay();
break;
case PlayerDetachedMsg _:
RemoveOverlay();
break;
}
}
private void ChangeHudIcon(HudStateChange changemessage)
{
_window.SetIcon(changemessage);
SetOverlay(changemessage);
}
private void SetOverlay(HudStateChange message)
{
RemoveOverlay();
_currentEffect = message.effect;
ApplyOverlay();
}
private void RemoveOverlay()
{
if (_currentEffect != ScreenEffects.None)
{
var appliedeffect = EffectsDictionary[_currentEffect];
_overlayManager.RemoveOverlay(nameof(appliedeffect));
}
_currentEffect = ScreenEffects.None;
}
private void ApplyOverlay()
{
if (_currentEffect != ScreenEffects.None)
{
_overlayManager.AddOverlay(EffectsDictionary[_currentEffect]);
}
}
private class SpeciesWindow : Control
{
private TextureRect _textureRect;
protected override ResourcePath ScenePath => new ResourcePath("/Scenes/Mobs/Species.tscn");
protected override void Initialize()
{
base.Initialize();
_textureRect = (TextureRect)GetChild("TextureRect");
}
public void SetIcon(HudStateChange changemessage)
{
if (!IoCManager.Resolve<IResourceCache>().TryGetResource<TextureResource>(new ResourcePath("/Textures") / changemessage.StateSprite, out var newtexture))
{
Logger.Info("The Species Health Sprite {0} Does Not Exist", new ResourcePath("/Textures") / changemessage.StateSprite);
return;
}
_textureRect.Texture = newtexture;
}
}
}
}