Outlines moved to InteractionOutlineComponent, now change color when in interaction range.

This commit is contained in:
Pieter-Jan Briers
2019-12-06 02:08:17 +01:00
parent a912c999a9
commit 689d16ee65
34 changed files with 153 additions and 15 deletions

View File

@@ -0,0 +1,59 @@
using Robust.Client.Graphics.Shaders;
using Robust.Client.Interfaces.GameObjects.Components;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Prototypes;
namespace Content.Client.GameObjects.Components
{
[RegisterComponent]
public class InteractionOutlineComponent : Component
{
private const string ShaderInRange = "selection_outline_inrange";
private const string ShaderOutOfRange = "selection_outline";
public override string Name => "InteractionOutline";
#pragma warning disable 649
[Dependency] private readonly IPrototypeManager _prototypeManager;
#pragma warning restore 649
private ShaderInstance _selectionShaderInstance;
private ShaderInstance _selectionShaderInRangeInstance;
/// <inheritdoc />
public override void Initialize()
{
base.Initialize();
_selectionShaderInRangeInstance = _prototypeManager.Index<ShaderPrototype>(ShaderInRange).Instance();
_selectionShaderInstance = _prototypeManager.Index<ShaderPrototype>(ShaderOutOfRange).Instance();
}
public void OnMouseEnter(bool inInteractionRange)
{
if (Owner.TryGetComponent(out ISpriteComponent sprite))
{
sprite.PostShader = inInteractionRange ? _selectionShaderInRangeInstance : _selectionShaderInstance;
sprite.RenderOrder = Owner.EntityManager.CurrentTick.Value;
}
}
public void OnMouseLeave()
{
if (Owner.TryGetComponent(out ISpriteComponent sprite))
{
sprite.PostShader = null;
sprite.RenderOrder = 0;
}
}
public void UpdateInRange(bool inInteractionRange)
{
if (Owner.TryGetComponent(out ISpriteComponent sprite))
{
sprite.PostShader = inInteractionRange ? _selectionShaderInRangeInstance : _selectionShaderInstance;
}
}
}
}

View File

@@ -1,5 +1,8 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Content.Client.GameObjects.Components;
using Content.Client.GameObjects.EntitySystems;
using Content.Shared.GameObjects;
using Robust.Client.GameObjects.EntitySystems; using Robust.Client.GameObjects.EntitySystems;
using Robust.Client.Interfaces.GameObjects; using Robust.Client.Interfaces.GameObjects;
using Robust.Client.Interfaces.GameObjects.Components; using Robust.Client.Interfaces.GameObjects.Components;
@@ -63,21 +66,37 @@ namespace Content.Client.State
var mousePosWorld = eyeManager.ScreenToWorld(new ScreenCoordinates(inputManager.MouseScreenPosition)); var mousePosWorld = eyeManager.ScreenToWorld(new ScreenCoordinates(inputManager.MouseScreenPosition));
var entityToClick = GetEntityUnderPosition(mousePosWorld); var entityToClick = GetEntityUnderPosition(mousePosWorld);
var inRange = false;
if (playerManager.LocalPlayer.ControlledEntity != null && entityToClick != null)
{
var playerPos = playerManager.LocalPlayer.ControlledEntity.Transform.GridPosition;
var entityPos = entityToClick.Transform.GridPosition;
var distance = playerPos.Distance(_mapManager, entityPos);
inRange = distance <= VerbUtility.InteractionRange;
}
InteractionOutlineComponent outline;
if (entityToClick == lastHoveredEntity) if (entityToClick == lastHoveredEntity)
{ {
if (entityToClick != null && entityToClick.TryGetComponent(out outline))
{
outline.UpdateInRange(inRange);
}
return; return;
} }
if (lastHoveredEntity != null && !lastHoveredEntity.Deleted) if (lastHoveredEntity != null && !lastHoveredEntity.Deleted &&
lastHoveredEntity.TryGetComponent(out outline))
{ {
lastHoveredEntity.GetComponent<IClientClickableComponent>().OnMouseLeave(); outline.OnMouseLeave();
} }
lastHoveredEntity = entityToClick; lastHoveredEntity = entityToClick;
if (lastHoveredEntity != null) if (lastHoveredEntity != null && lastHoveredEntity.TryGetComponent(out outline))
{ {
lastHoveredEntity.GetComponent<IClientClickableComponent>().OnMouseEnter(); outline.OnMouseEnter(inRange);
} }
} }
@@ -91,7 +110,8 @@ namespace Content.Client.State
{ {
// Find all the entities intersecting our click // Find all the entities intersecting our click
var worldCoords = coordinates.ToWorld(_mapManager); var worldCoords = coordinates.ToWorld(_mapManager);
var entities = _entityManager.GetEntitiesIntersecting(_mapManager.GetGrid(coordinates.GridID).ParentMapId, worldCoords.Position); var entities = _entityManager.GetEntitiesIntersecting(_mapManager.GetGrid(coordinates.GridID).ParentMapId,
worldCoords.Position);
// Check the entities against whether or not we can click them // Check the entities against whether or not we can click them
var foundEntities = new List<(IEntity clicked, int drawDepth)>(); var foundEntities = new List<(IEntity clicked, int drawDepth)>();
@@ -123,6 +143,7 @@ namespace Content.Client.State
{ {
return val; return val;
} }
var transx = x.clicked.Transform; var transx = x.clicked.Transform;
var transy = y.clicked.Transform; var transy = y.clicked.Transform;
return transx.GridPosition.Y.CompareTo(transy.GridPosition.Y); return transx.GridPosition.Y.CompareTo(transy.GridPosition.Y);
@@ -142,7 +163,8 @@ namespace Content.Client.State
var mousePosWorld = eyeManager.ScreenToWorld(args.PointerLocation); var mousePosWorld = eyeManager.ScreenToWorld(args.PointerLocation);
var entityToClick = GetEntityUnderPosition(mousePosWorld); var entityToClick = GetEntityUnderPosition(mousePosWorld);
var message = new FullInputCmdMessage(timing.CurTick, funcId, args.State, mousePosWorld, args.PointerLocation, entityToClick?.Uid ?? EntityUid.Invalid); var message = new FullInputCmdMessage(timing.CurTick, funcId, args.State, mousePosWorld,
args.PointerLocation, entityToClick?.Uid ?? EntityUid.Invalid);
// client side command handlers will always be sent the local player session. // client side command handlers will always be sent the local player session.
var session = playerManager.LocalPlayer.Session; var session = playerManager.LocalPlayer.Session;

View File

@@ -35,6 +35,9 @@ namespace Content.Server
"LowWall", "LowWall",
"Window", "Window",
"CharacterInfo", "CharacterInfo",
"InteractionOutline",
"MeleeWeaponArcAnimation",
"AnimationsTest",
}; };
foreach (var ignoreName in registerIgnore) foreach (var ignoreName in registerIgnore)
@@ -49,6 +52,7 @@ namespace Content.Server
var cast = (ServerModuleTestingCallbacks) TestingCallbacks; var cast = (ServerModuleTestingCallbacks) TestingCallbacks;
cast.ServerBeforeIoC?.Invoke(); cast.ServerBeforeIoC?.Invoke();
} }
IoCManager.BuildGraph(); IoCManager.BuildGraph();
_gameTicker = IoCManager.Resolve<IGameTicker>(); _gameTicker = IoCManager.Resolve<IGameTicker>();

View File

@@ -3,6 +3,7 @@
name: Thing that heats up on its own and dies name: Thing that heats up on its own and dies
components: components:
- type: Clickable - type: Clickable
- type: InteractionOutline
- type: Sprite - type: Sprite
texture: Objects/Misc/shoes.png texture: Objects/Misc/shoes.png

View File

@@ -25,6 +25,7 @@
- type: Icon - type: Icon
texture: Objects/Janitorial/mopbucket.png texture: Objects/Janitorial/mopbucket.png
- type: Clickable - type: Clickable
- type: InteractionOutline
- type: Solution - type: Solution
maxVol: 500 maxVol: 500
caps: 3 caps: 3

View File

@@ -9,6 +9,7 @@
sprite: Buildings/research.rsi sprite: Buildings/research.rsi
state: server state: server
- type: Clickable - type: Clickable
- type: InteractionOutline
- type: Collidable - type: Collidable
- type: SnapGrid - type: SnapGrid
offset: Center offset: Center
@@ -34,6 +35,7 @@
sprite: Buildings/research.rsi sprite: Buildings/research.rsi
state: tdoppler state: tdoppler
- type: Clickable - type: Clickable
- type: InteractionOutline
- type: Collidable - type: Collidable
shapes: shapes:
- !type:PhysShapeAabb - !type:PhysShapeAabb

View File

@@ -4,6 +4,7 @@
description: It opens, it closes, and maybe crushes you. description: It opens, it closes, and maybe crushes you.
components: components:
- type: Clickable - type: Clickable
- type: InteractionOutline
- type: Sprite - type: Sprite
netsync: false netsync: false

View File

@@ -4,6 +4,7 @@
components: components:
- type: AsteroidRock - type: AsteroidRock
- type: Clickable - type: Clickable
- type: InteractionOutline
- type: Sprite - type: Sprite
sprite: Buildings/Walls/asteroid_rock.rsi sprite: Buildings/Walls/asteroid_rock.rsi
state: 0 state: 0

View File

@@ -3,6 +3,7 @@
name: Catwalk name: Catwalk
components: components:
- type: Clickable - type: Clickable
- type: InteractionOutline
- type: Collidable - type: Collidable
- type: Sprite - type: Sprite
netsync: false netsync: false

View File

@@ -6,6 +6,7 @@
mass: 25 mass: 25
Anchored: true Anchored: true
- type: Clickable - type: Clickable
- type: InteractionOutline
- type: Collidable - type: Collidable
IsScrapingFloor: true IsScrapingFloor: true
shapes: shapes:

View File

@@ -10,6 +10,7 @@
texture: Buildings/weldtank.png texture: Buildings/weldtank.png
- type: Clickable - type: Clickable
- type: InteractionOutline
- type: Collidable - type: Collidable
shapes: shapes:
- !type:PhysShapeAabb - !type:PhysShapeAabb

View File

@@ -3,6 +3,7 @@
id: stool id: stool
components: components:
- type: Clickable - type: Clickable
- type: InteractionOutline
- type: Collidable - type: Collidable
- type: Sprite - type: Sprite
sprite: Buildings/furniture.rsi sprite: Buildings/furniture.rsi
@@ -18,6 +19,7 @@
components: components:
- type: Rotatable - type: Rotatable
- type: Clickable - type: Clickable
- type: InteractionOutline
- type: Collidable - type: Collidable
- type: Sprite - type: Sprite
sprite: Buildings/furniture.rsi sprite: Buildings/furniture.rsi
@@ -32,6 +34,7 @@
components: components:
- type: Rotatable - type: Rotatable
- type: Clickable - type: Clickable
- type: InteractionOutline
- type: Collidable - type: Collidable
- type: Sprite - type: Sprite
sprite: Buildings/furniture.rsi sprite: Buildings/furniture.rsi
@@ -45,6 +48,7 @@
id: chair id: chair
components: components:
- type: Clickable - type: Clickable
- type: InteractionOutline
- type: Collidable - type: Collidable
- type: Sprite - type: Sprite
sprite: Buildings/furniture.rsi sprite: Buildings/furniture.rsi

View File

@@ -3,6 +3,7 @@
name: Girder name: Girder
components: components:
- type: Clickable - type: Clickable
- type: InteractionOutline
- type: Sprite - type: Sprite
texture: Buildings/wall_girder.png texture: Buildings/wall_girder.png
- type: Icon - type: Icon

View File

@@ -6,6 +6,7 @@
handheld: false handheld: false
- type: Clickable - type: Clickable
- type: InteractionOutline
- type: Collidable - type: Collidable
shapes: shapes:

View File

@@ -3,6 +3,7 @@
name: "Lathe" name: "Lathe"
components: components:
- type: Clickable - type: Clickable
- type: InteractionOutline
- type: Collidable - type: Collidable
- type: SnapGrid - type: SnapGrid
offset: Center offset: Center

View File

@@ -3,6 +3,7 @@
name: "Unpowered Light" name: "Unpowered Light"
components: components:
- type: Clickable - type: Clickable
- type: InteractionOutline
- type: Collidable - type: Collidable
- type: Sound - type: Sound
- type: Sprite - type: Sprite
@@ -29,6 +30,7 @@
parent: wall_light parent: wall_light
components: components:
- type: Clickable - type: Clickable
- type: InteractionOutline
- type: Collidable - type: Collidable
- type: Sprite - type: Sprite
sprite: Buildings/light_tube.rsi sprite: Buildings/light_tube.rsi
@@ -53,6 +55,7 @@
parent: wall_light parent: wall_light
components: components:
- type: Clickable - type: Clickable
- type: InteractionOutline
- type: Sprite - type: Sprite
sprite: Buildings/light_small.rsi sprite: Buildings/light_small.rsi
state: off state: off

View File

@@ -4,6 +4,7 @@
description: Goes up to about your waist. description: Goes up to about your waist.
components: components:
- type: Clickable - type: Clickable
- type: InteractionOutline
- type: Sprite - type: Sprite
netsync: false netsync: false
color: "#71797a" color: "#71797a"

View File

@@ -17,6 +17,7 @@
state: scanner_open state: scanner_open
- type: Clickable - type: Clickable
- type: InteractionOutline
- type: Collidable - type: Collidable
shapes: shapes:
- !type:PhysShapeAabb - !type:PhysShapeAabb

View File

@@ -13,6 +13,7 @@
- !type:PhysShapeAabb - !type:PhysShapeAabb
layer: 32 layer: 32
- type: Clickable - type: Clickable
- type: InteractionOutline
- type: Physics - type: Physics
mass: 25 mass: 25
Anchored: true Anchored: true

View File

@@ -4,6 +4,7 @@
description: Transfers power, avoid letting things come down it description: Transfers power, avoid letting things come down it
components: components:
- type: Clickable - type: Clickable
- type: InteractionOutline
- type: Collidable - type: Collidable
- type: Sprite - type: Sprite
netsync: false netsync: false
@@ -40,6 +41,7 @@
description: A portal to hell which summons power from the nether description: A portal to hell which summons power from the nether
components: components:
- type: Clickable - type: Clickable
- type: InteractionOutline
- type: Collidable - type: Collidable
shapes: shapes:
- !type:PhysShapeAabb - !type:PhysShapeAabb
@@ -57,6 +59,7 @@
description: Supplies power directly to nearby objects description: Supplies power directly to nearby objects
components: components:
- type: Clickable - type: Clickable
- type: InteractionOutline
- type: Collidable - type: Collidable
shapes: shapes:
- !type:PhysShapeAabb - !type:PhysShapeAabb
@@ -113,6 +116,7 @@
description: Stores power in its super-magnetic cells description: Stores power in its super-magnetic cells
components: components:
- type: Clickable - type: Clickable
- type: InteractionOutline
- type: Collidable - type: Collidable
shapes: shapes:
- !type:PhysShapeAabb - !type:PhysShapeAabb
@@ -152,6 +156,7 @@
description: A monstrosity that does nothing but suck up power from the nearby wires description: A monstrosity that does nothing but suck up power from the nearby wires
components: components:
- type: Clickable - type: Clickable
- type: InteractionOutline
- type: Collidable - type: Collidable
shapes: shapes:
- !type:PhysShapeAabb - !type:PhysShapeAabb
@@ -172,6 +177,7 @@
description: A terrifying monstrosity that sucks up power from the wireless transmitters, Tesla would be proud description: A terrifying monstrosity that sucks up power from the wireless transmitters, Tesla would be proud
components: components:
- type: Clickable - type: Clickable
- type: InteractionOutline
- type: Collidable - type: Collidable
shapes: shapes:
- !type:PhysShapeAabb - !type:PhysShapeAabb

View File

@@ -3,6 +3,7 @@
id: reagent_dispenser_base id: reagent_dispenser_base
components: components:
- type: Clickable - type: Clickable
- type: InteractionOutline
- type: Collidable - type: Collidable
shapes: shapes:
- !type:PhysShapeAabb - !type:PhysShapeAabb

View File

@@ -16,6 +16,7 @@
state: generic_door state: generic_door
- type: Clickable - type: Clickable
- type: InteractionOutline
- type: Collidable - type: Collidable
shapes: shapes:
- !type:PhysShapeAabb - !type:PhysShapeAabb

View File

@@ -16,6 +16,7 @@
state: crate state: crate
- type: Clickable - type: Clickable
- type: InteractionOutline
- type: Collidable - type: Collidable
shapes: shapes:
- !type:PhysShapeAabb - !type:PhysShapeAabb

View File

@@ -3,6 +3,7 @@
name: "worktop" name: "worktop"
components: components:
- type: Clickable - type: Clickable
- type: InteractionOutline
- type: PlaceableSurface - type: PlaceableSurface
- type: Sprite - type: Sprite
netsync: false netsync: false

View File

@@ -3,6 +3,7 @@
name: Turret Base name: Turret Base
components: components:
- type: Clickable - type: Clickable
- type: InteractionOutline
- type: Collidable - type: Collidable
- type: Sprite - type: Sprite
texture: Buildings/TurrBase.png texture: Buildings/TurrBase.png
@@ -12,6 +13,7 @@
name: Turret (Gun) name: Turret (Gun)
components: components:
- type: Clickable - type: Clickable
- type: InteractionOutline
- type: Collidable - type: Collidable
- type: Sprite - type: Sprite
drawdepth: WallMountedItems drawdepth: WallMountedItems
@@ -26,6 +28,7 @@
name: Turret (Light) name: Turret (Light)
components: components:
- type: Clickable - type: Clickable
- type: InteractionOutline
- type: Collidable - type: Collidable
- type: Sprite - type: Sprite
drawdepth: WallMountedItems drawdepth: WallMountedItems

View File

@@ -6,6 +6,7 @@
Anchored: true Anchored: true
- type: Rotatable - type: Rotatable
- type: Clickable - type: Clickable
- type: InteractionOutline
- type: Sprite - type: Sprite
sprite: Buildings/VendingMachines/empty.rsi sprite: Buildings/VendingMachines/empty.rsi
layers: layers:

View File

@@ -4,6 +4,7 @@
description: Keeps the air in and the greytide out. description: Keeps the air in and the greytide out.
components: components:
- type: Clickable - type: Clickable
- type: InteractionOutline
- type: Sprite - type: Sprite
netsync: false netsync: false
drawdepth: Walls drawdepth: Walls

View File

@@ -4,6 +4,7 @@
description: Don't smudge up the glass down there. description: Don't smudge up the glass down there.
components: components:
- type: Clickable - type: Clickable
- type: InteractionOutline
- type: Sprite - type: Sprite
netsync: false netsync: false
drawdepth: WallTops drawdepth: WallTops

View File

@@ -5,6 +5,7 @@
- type: Item - type: Item
Size: 5 Size: 5
- type: Clickable - type: Clickable
- type: InteractionOutline
- type: Collidable - type: Collidable
shapes: shapes:
- !type:PhysShapeAabb - !type:PhysShapeAabb

View File

@@ -118,6 +118,7 @@
- type: Physics - type: Physics
mass: 5 mass: 5
- type: Clickable - type: Clickable
- type: InteractionOutline
- type: Collidable - type: Collidable
shapes: shapes:
- !type:PhysShapeAabb - !type:PhysShapeAabb
@@ -149,6 +150,7 @@
- type: Physics - type: Physics
mass: 5 mass: 5
- type: Clickable - type: Clickable
- type: InteractionOutline
- type: Collidable - type: Collidable
shapes: shapes:
- !type:PhysShapeAabb - !type:PhysShapeAabb
@@ -179,6 +181,7 @@
- type: Physics - type: Physics
mass: 5 mass: 5
- type: Clickable - type: Clickable
- type: InteractionOutline
- type: Collidable - type: Collidable
shapes: shapes:
- !type:PhysShapeAabb - !type:PhysShapeAabb

View File

@@ -9,6 +9,7 @@
- type: ConstructionGhost - type: ConstructionGhost
- type: Collidable - type: Collidable
- type: Clickable - type: Clickable
- type: InteractionOutline
- type: entity - type: entity
name: somebody-messed-up frame name: somebody-messed-up frame
@@ -18,3 +19,4 @@
- type: Construction - type: Construction
- type: Collidable - type: Collidable
- type: Clickable - type: Clickable
- type: InteractionOutline

View File

@@ -16,6 +16,7 @@
- type: Inventory - type: Inventory
- type: Constructor - type: Constructor
- type: Clickable - type: Clickable
- type: InteractionOutline
- type: Sprite - type: Sprite
netsync: false netsync: false
drawdepth: Mobs drawdepth: Mobs

View File

@@ -11,6 +11,7 @@
texture: Buildings/watertank.png texture: Buildings/watertank.png
- type: Clickable - type: Clickable
- type: InteractionOutline
- type: Collidable - type: Collidable
layer: 31 layer: 31
shape: shape:
@@ -42,4 +43,3 @@
reagents: reagents:
- ReagentId: chem.H2O - ReagentId: chem.H2O
Quantity: 1500 Quantity: 1500

View File

@@ -5,3 +5,11 @@
params: params:
outline_width: 2 outline_width: 2
outline_color: "#FF000055" outline_color: "#FF000055"
- type: shader
id: selection_outline_inrange
kind: source
path: "/Shaders/outline.swsl"
params:
outline_width: 2
outline_color: "#00FF0055"