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:
committed by
Pieter-Jan Briers
parent
b8becf4a56
commit
37df61113e
160
Content.Client/GameObjects/Components/Mobs/SpeciesUI.cs
Normal file
160
Content.Client/GameObjects/Components/Mobs/SpeciesUI.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user