Merge branch 'master' into RefactorMouseFilterMode
This commit is contained in:
@@ -120,7 +120,6 @@ namespace Content.Client.GameObjects.Components.Doors
|
||||
{
|
||||
animPlayer.Play(OpenAnimation, AnimationKey);
|
||||
}
|
||||
|
||||
break;
|
||||
case DoorVisualState.Open:
|
||||
sprite.LayerSetState(DoorVisualLayers.Base, "open");
|
||||
|
||||
@@ -0,0 +1,107 @@
|
||||
using System;
|
||||
using Content.Shared.GameObjects.Components.Power;
|
||||
using Robust.Client.Animations;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Client.GameObjects.Components.Animations;
|
||||
using Robust.Client.Interfaces.GameObjects.Components;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using YamlDotNet.RepresentationModel;
|
||||
|
||||
namespace Content.Client.GameObjects.Components.Power
|
||||
{
|
||||
public class AutolatheVisualizer2D : AppearanceVisualizer
|
||||
{
|
||||
private const string AnimationKey = "autolathe_animation";
|
||||
|
||||
private Animation _buildingAnimation;
|
||||
private Animation _insertingMetalAnimation;
|
||||
private Animation _insertingGlassAnimation;
|
||||
|
||||
public override void LoadData(YamlMappingNode node)
|
||||
{
|
||||
base.LoadData(node);
|
||||
|
||||
_buildingAnimation = PopulateAnimation("autolathe_building", "autolathe_building_unlit", 0.5f);
|
||||
_insertingMetalAnimation = PopulateAnimation("autolathe_inserting_metal_plate", "autolathe_inserting_unlit", 0.9f);
|
||||
_insertingGlassAnimation = PopulateAnimation("autolathe_inserting_glass_plate", "autolathe_inserting_unlit", 0.9f);
|
||||
}
|
||||
|
||||
private Animation PopulateAnimation(string sprite, string spriteUnlit, float length)
|
||||
{
|
||||
var animation = new Animation {Length = TimeSpan.FromSeconds(length)};
|
||||
|
||||
var flick = new AnimationTrackSpriteFlick();
|
||||
animation.AnimationTracks.Add(flick);
|
||||
flick.LayerKey = AutolatheVisualLayers.Base;
|
||||
flick.KeyFrames.Add(new AnimationTrackSpriteFlick.KeyFrame(sprite, 0f));
|
||||
|
||||
var flickUnlit = new AnimationTrackSpriteFlick();
|
||||
animation.AnimationTracks.Add(flickUnlit);
|
||||
flickUnlit.LayerKey = AutolatheVisualLayers.BaseUnlit;
|
||||
flickUnlit.KeyFrames.Add(new AnimationTrackSpriteFlick.KeyFrame(spriteUnlit, 0f));
|
||||
|
||||
return animation;
|
||||
}
|
||||
|
||||
public override void InitializeEntity(IEntity entity)
|
||||
{
|
||||
if (!entity.HasComponent<AnimationPlayerComponent>())
|
||||
{
|
||||
entity.AddComponent<AnimationPlayerComponent>();
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnChangeData(AppearanceComponent component)
|
||||
{
|
||||
base.OnChangeData(component);
|
||||
|
||||
var sprite = component.Owner.GetComponent<ISpriteComponent>();
|
||||
var animPlayer = component.Owner.GetComponent<AnimationPlayerComponent>();
|
||||
if (!component.TryGetData(PowerDeviceVisuals.VisualState, out LatheVisualState state))
|
||||
{
|
||||
state = LatheVisualState.Idle;
|
||||
}
|
||||
|
||||
switch (state)
|
||||
{
|
||||
case LatheVisualState.Idle:
|
||||
if (animPlayer.HasRunningAnimation(AnimationKey))
|
||||
{
|
||||
animPlayer.Stop(AnimationKey);
|
||||
}
|
||||
|
||||
sprite.LayerSetState(AutolatheVisualLayers.Base, "autolathe");
|
||||
sprite.LayerSetState(AutolatheVisualLayers.BaseUnlit, "autolathe_unlit");
|
||||
break;
|
||||
case LatheVisualState.Producing:
|
||||
if (!animPlayer.HasRunningAnimation(AnimationKey))
|
||||
{
|
||||
animPlayer.Play(_buildingAnimation, AnimationKey);
|
||||
}
|
||||
break;
|
||||
case LatheVisualState.InsertingMetal:
|
||||
if (!animPlayer.HasRunningAnimation(AnimationKey))
|
||||
{
|
||||
animPlayer.Play(_insertingMetalAnimation, AnimationKey);
|
||||
}
|
||||
break;
|
||||
case LatheVisualState.InsertingGlass:
|
||||
if (!animPlayer.HasRunningAnimation(AnimationKey))
|
||||
{
|
||||
animPlayer.Play(_insertingGlassAnimation, AnimationKey);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
|
||||
var glowingPartsVisible = !(component.TryGetData(PowerDeviceVisuals.Powered, out bool powered) && !powered);
|
||||
sprite.LayerSetVisible(AutolatheVisualLayers.BaseUnlit, glowingPartsVisible);
|
||||
}
|
||||
public enum AutolatheVisualLayers
|
||||
{
|
||||
Base,
|
||||
BaseUnlit
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
using System;
|
||||
using Content.Shared.GameObjects.Components.Power;
|
||||
using Robust.Client.Animations;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Client.GameObjects.Components.Animations;
|
||||
using Robust.Client.Interfaces.GameObjects.Components;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using YamlDotNet.RepresentationModel;
|
||||
|
||||
namespace Content.Client.GameObjects.Components.Power
|
||||
{
|
||||
public class ProtolatheVisualizer2D : AppearanceVisualizer
|
||||
{
|
||||
private const string AnimationKey = "protolathe_animation";
|
||||
|
||||
private Animation _buildingAnimation;
|
||||
private Animation _insertingMetalAnimation;
|
||||
private Animation _insertingGlassAnimation;
|
||||
|
||||
public override void LoadData(YamlMappingNode node)
|
||||
{
|
||||
base.LoadData(node);
|
||||
|
||||
_buildingAnimation = PopulateAnimation("protolathe_building", 0.9f);
|
||||
_insertingMetalAnimation = PopulateAnimation("protolathe_metal", 0.9f);
|
||||
_insertingGlassAnimation = PopulateAnimation("protolathe_glass", 0.9f);
|
||||
}
|
||||
|
||||
private Animation PopulateAnimation(string sprite, float length)
|
||||
{
|
||||
var animation = new Animation {Length = TimeSpan.FromSeconds(length)};
|
||||
|
||||
var flick = new AnimationTrackSpriteFlick();
|
||||
animation.AnimationTracks.Add(flick);
|
||||
flick.LayerKey = ProtolatheVisualLayers.AnimationLayer;
|
||||
flick.KeyFrames.Add(new AnimationTrackSpriteFlick.KeyFrame(sprite, 0f));
|
||||
|
||||
return animation;
|
||||
}
|
||||
|
||||
public override void InitializeEntity(IEntity entity)
|
||||
{
|
||||
if (!entity.HasComponent<AnimationPlayerComponent>())
|
||||
{
|
||||
entity.AddComponent<AnimationPlayerComponent>();
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnChangeData(AppearanceComponent component)
|
||||
{
|
||||
base.OnChangeData(component);
|
||||
|
||||
var sprite = component.Owner.GetComponent<ISpriteComponent>();
|
||||
var animPlayer = component.Owner.GetComponent<AnimationPlayerComponent>();
|
||||
if (!component.TryGetData(PowerDeviceVisuals.VisualState, out LatheVisualState state))
|
||||
{
|
||||
state = LatheVisualState.Idle;
|
||||
}
|
||||
sprite.LayerSetVisible(ProtolatheVisualLayers.AnimationLayer, true);
|
||||
switch (state)
|
||||
{
|
||||
case LatheVisualState.Idle:
|
||||
if (animPlayer.HasRunningAnimation(AnimationKey))
|
||||
{
|
||||
animPlayer.Stop(AnimationKey);
|
||||
}
|
||||
|
||||
sprite.LayerSetState(ProtolatheVisualLayers.Base, "protolathe");
|
||||
sprite.LayerSetState(ProtolatheVisualLayers.BaseUnlit, "protolathe_unlit");
|
||||
sprite.LayerSetVisible(ProtolatheVisualLayers.AnimationLayer, false);
|
||||
break;
|
||||
case LatheVisualState.Producing:
|
||||
if (!animPlayer.HasRunningAnimation(AnimationKey))
|
||||
{
|
||||
animPlayer.Play(_buildingAnimation, AnimationKey);
|
||||
}
|
||||
break;
|
||||
case LatheVisualState.InsertingMetal:
|
||||
if (!animPlayer.HasRunningAnimation(AnimationKey))
|
||||
{
|
||||
animPlayer.Play(_insertingMetalAnimation, AnimationKey);
|
||||
}
|
||||
break;
|
||||
case LatheVisualState.InsertingGlass:
|
||||
if (!animPlayer.HasRunningAnimation(AnimationKey))
|
||||
{
|
||||
animPlayer.Play(_insertingGlassAnimation, AnimationKey);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
|
||||
var glowingPartsVisible = !(component.TryGetData(PowerDeviceVisuals.Powered, out bool powered) && !powered);
|
||||
sprite.LayerSetVisible(ProtolatheVisualLayers.BaseUnlit, glowingPartsVisible);
|
||||
}
|
||||
public enum ProtolatheVisualLayers
|
||||
{
|
||||
Base,
|
||||
BaseUnlit,
|
||||
AnimationLayer
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -121,7 +121,7 @@ namespace Content.Client.GameObjects.EntitySystems
|
||||
|
||||
DebugTools.AssertNotNull(_currentPopup);
|
||||
|
||||
var buttons = new List<Button>();
|
||||
var buttons = new Dictionary<string, List<Button>>();
|
||||
|
||||
var vBox = _currentPopup.List;
|
||||
vBox.DisposeAllChildren();
|
||||
@@ -137,7 +137,10 @@ namespace Content.Client.GameObjects.EntitySystems
|
||||
};
|
||||
}
|
||||
|
||||
buttons.Add(button);
|
||||
if(!buttons.ContainsKey(data.Category))
|
||||
buttons[data.Category] = new List<Button>();
|
||||
|
||||
buttons[data.Category].Add(button);
|
||||
}
|
||||
|
||||
var user = GetUserEntity();
|
||||
@@ -148,7 +151,13 @@ namespace Content.Client.GameObjects.EntitySystems
|
||||
continue;
|
||||
|
||||
var disabled = verb.GetVisibility(user, component) != VerbVisibility.Visible;
|
||||
buttons.Add(CreateVerbButton(verb.GetText(user, component), disabled, verb.ToString(),
|
||||
var category = verb.GetCategory(user, component);
|
||||
|
||||
|
||||
if(!buttons.ContainsKey(category))
|
||||
buttons[category] = new List<Button>();
|
||||
|
||||
buttons[category].Add(CreateVerbButton(verb.GetText(user, component), disabled, verb.ToString(),
|
||||
entity.ToString(), () => verb.Activate(user, component)));
|
||||
}
|
||||
//Get global verbs. Visible for all entities regardless of their components.
|
||||
@@ -158,17 +167,33 @@ namespace Content.Client.GameObjects.EntitySystems
|
||||
continue;
|
||||
|
||||
var disabled = globalVerb.GetVisibility(user, entity) != VerbVisibility.Visible;
|
||||
buttons.Add(CreateVerbButton(globalVerb.GetText(user, entity), disabled, globalVerb.ToString(),
|
||||
var category = globalVerb.GetCategory(user, entity);
|
||||
|
||||
if(!buttons.ContainsKey(category))
|
||||
buttons[category] = new List<Button>();
|
||||
|
||||
buttons[category].Add(CreateVerbButton(globalVerb.GetText(user, entity), disabled, globalVerb.ToString(),
|
||||
entity.ToString(), () => globalVerb.Activate(user, entity)));
|
||||
}
|
||||
|
||||
if (buttons.Count > 0)
|
||||
{
|
||||
buttons.Sort((a, b) => string.Compare(a.Text, b.Text, StringComparison.Ordinal));
|
||||
|
||||
foreach (var button in buttons)
|
||||
foreach (var (category, verbs) in buttons)
|
||||
{
|
||||
vBox.AddChild(button);
|
||||
if (string.IsNullOrEmpty(category))
|
||||
continue;
|
||||
|
||||
vBox.AddChild(CreateCategoryButton(category, verbs));
|
||||
}
|
||||
|
||||
if (buttons.ContainsKey(""))
|
||||
{
|
||||
buttons[""].Sort((a, b) => string.Compare(a.Text, b.Text, StringComparison.Ordinal));
|
||||
|
||||
foreach (var verb in buttons[""])
|
||||
{
|
||||
vBox.AddChild(verb);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -204,6 +229,25 @@ namespace Content.Client.GameObjects.EntitySystems
|
||||
return button;
|
||||
}
|
||||
|
||||
private Button CreateCategoryButton(string text, List<Button> verbButtons)
|
||||
{
|
||||
verbButtons.Sort((a, b) => string.Compare(a.Text, b.Text, StringComparison.Ordinal));
|
||||
|
||||
var button = new Button
|
||||
{
|
||||
Text = $"{text}...",
|
||||
};
|
||||
button.OnPressed += _ =>
|
||||
{
|
||||
_currentPopup.List.DisposeAllChildren();
|
||||
foreach (var verb in verbButtons)
|
||||
{
|
||||
_currentPopup.List.AddChild(verb);
|
||||
}
|
||||
};
|
||||
return button;
|
||||
}
|
||||
|
||||
private void CloseContextMenu()
|
||||
{
|
||||
_currentPopup?.Dispose();
|
||||
|
||||
@@ -13,6 +13,8 @@ namespace Content.Client.GlobalVerbs
|
||||
class ViewVariablesVerb : GlobalVerb
|
||||
{
|
||||
public override string GetText(IEntity user, IEntity target) => "View variables";
|
||||
public override string GetCategory(IEntity user, IEntity target) => "Debug";
|
||||
|
||||
public override bool RequireInteractionRange => false;
|
||||
|
||||
public override VerbVisibility GetVisibility(IEntity user, IEntity target)
|
||||
|
||||
Reference in New Issue
Block a user