committed by
Pieter-Jan Briers
parent
3c476d2b40
commit
88920696f3
@@ -11,6 +11,7 @@ using Content.Client.UserInterface;
|
||||
using Content.Shared.GameObjects.Components.Chemistry;
|
||||
using Content.Shared.GameObjects.Components.Markers;
|
||||
using Content.Shared.GameObjects.Components.Research;
|
||||
using Content.Shared.GameObjects.Components.VendingMachines;
|
||||
using Content.Shared.Interfaces;
|
||||
using Robust.Client.Interfaces;
|
||||
using Robust.Client.Interfaces.Graphics.Overlays;
|
||||
@@ -105,6 +106,8 @@ namespace Content.Client
|
||||
factory.Register<SharedSpawnPointComponent>();
|
||||
factory.Register<SolutionComponent>();
|
||||
|
||||
factory.Register<SharedVendingMachineComponent>();
|
||||
|
||||
prototypes.RegisterIgnore("material");
|
||||
|
||||
IoCManager.Register<IGameHud, GameHud>();
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
using Content.Client.VendingMachines;
|
||||
using Content.Shared.GameObjects.Components.VendingMachines;
|
||||
using Robust.Client.GameObjects.Components.UserInterface;
|
||||
using Robust.Shared.GameObjects.Components.UserInterface;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.ViewVariables;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Content.Client.GameObjects.Components.VendingMachines
|
||||
{
|
||||
class VendingMachineBoundUserInterface : BoundUserInterface
|
||||
{
|
||||
[ViewVariables]
|
||||
private VendingMachineMenu _menu;
|
||||
|
||||
public SharedVendingMachineComponent VendingMachine { get; private set; }
|
||||
|
||||
public VendingMachineBoundUserInterface(ClientUserInterfaceComponent owner, object uiKey) : base(owner, uiKey)
|
||||
{
|
||||
SendMessage(new SharedVendingMachineComponent.InventorySyncRequestMessage());
|
||||
}
|
||||
|
||||
protected override void Open()
|
||||
{
|
||||
base.Open();
|
||||
|
||||
if(!Owner.Owner.TryGetComponent(out SharedVendingMachineComponent vendingMachine))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
VendingMachine = vendingMachine;
|
||||
|
||||
_menu = new VendingMachineMenu() { Owner = this, Title = Owner.Owner.Name };
|
||||
_menu.Populate(VendingMachine.Inventory);
|
||||
|
||||
_menu.OnClose += Close;
|
||||
_menu.OpenCentered();
|
||||
}
|
||||
|
||||
public void Eject(string ID)
|
||||
{
|
||||
SendMessage(new SharedVendingMachineComponent.VendingMachineEjectMessage(ID));
|
||||
}
|
||||
|
||||
protected override void ReceiveMessage(BoundUserInterfaceMessage message)
|
||||
{
|
||||
switch(message)
|
||||
{
|
||||
case SharedVendingMachineComponent.VendingMachineInventoryMessage msg:
|
||||
_menu.Populate(msg.Inventory);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
base.Dispose(disposing);
|
||||
if(!disposing) { return; }
|
||||
_menu?.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
using System;
|
||||
using Content.Client.GameObjects.Components.Doors;
|
||||
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;
|
||||
using static Content.Shared.GameObjects.Components.VendingMachines.SharedVendingMachineComponent;
|
||||
|
||||
namespace Content.Client.GameObjects.Components.VendingMachines
|
||||
{
|
||||
public class VendingMachineVisualizer2D : AppearanceVisualizer
|
||||
{
|
||||
// TODO: The length of these animations is supposed to be dictated
|
||||
// by the vending machine's pack prototype's `AnimationDuration`
|
||||
// but we have no good way of passing that data from the server
|
||||
// to the client at the moment. Rework Visualizers?
|
||||
private const string DeniedAnimationKey = "deny";
|
||||
private const string EjectAnimationKey = "eject";
|
||||
|
||||
private Animation _deniedAnimation;
|
||||
private Animation _ejectAnimation;
|
||||
|
||||
public override void LoadData(YamlMappingNode node)
|
||||
{
|
||||
base.LoadData(node);
|
||||
_deniedAnimation = new Animation {Length = TimeSpan.FromSeconds(1.2f)};
|
||||
{
|
||||
var flick = new AnimationTrackSpriteFlick();
|
||||
_deniedAnimation.AnimationTracks.Add(flick);
|
||||
flick.LayerKey = VendingMachineVisualLayers.Base;
|
||||
flick.KeyFrames.Add(new AnimationTrackSpriteFlick.KeyFrame("deny", 0f));
|
||||
}
|
||||
|
||||
_ejectAnimation = new Animation {Length = TimeSpan.FromSeconds(1.2f)};
|
||||
{
|
||||
var flick = new AnimationTrackSpriteFlick();
|
||||
_ejectAnimation.AnimationTracks.Add(flick);
|
||||
flick.LayerKey = VendingMachineVisualLayers.Base;
|
||||
flick.KeyFrames.Add(new AnimationTrackSpriteFlick.KeyFrame("eject", 0f));
|
||||
}
|
||||
}
|
||||
|
||||
public override void InitializeEntity(IEntity entity)
|
||||
{
|
||||
base.InitializeEntity(entity);
|
||||
|
||||
if (!entity.HasComponent<AnimationPlayerComponent>())
|
||||
{
|
||||
entity.AddComponent<AnimationPlayerComponent>();
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnChangeData(AppearanceComponent component)
|
||||
{
|
||||
var sprite = component.Owner.GetComponent<ISpriteComponent>();
|
||||
var animPlayer = component.Owner.GetComponent<AnimationPlayerComponent>();
|
||||
if (!component.TryGetData(VendingMachineVisuals.VisualState, out VendingMachineVisualState state))
|
||||
{
|
||||
state = VendingMachineVisualState.Normal;
|
||||
}
|
||||
|
||||
switch (state)
|
||||
{
|
||||
case VendingMachineVisualState.Normal:
|
||||
sprite.LayerSetState(VendingMachineVisualLayers.Base, "normal");
|
||||
break;
|
||||
case VendingMachineVisualState.Off:
|
||||
sprite.LayerSetState(VendingMachineVisualLayers.Base, "off");
|
||||
break;
|
||||
case VendingMachineVisualState.Broken:
|
||||
sprite.LayerSetState(VendingMachineVisualLayers.Base, "broken");
|
||||
break;
|
||||
case VendingMachineVisualState.Deny:
|
||||
if (!animPlayer.HasRunningAnimation(DeniedAnimationKey))
|
||||
{
|
||||
animPlayer.Play(_deniedAnimation, DeniedAnimationKey);
|
||||
}
|
||||
|
||||
break;
|
||||
case VendingMachineVisualState.Eject:
|
||||
if (!animPlayer.HasRunningAnimation(EjectAnimationKey))
|
||||
{
|
||||
animPlayer.Play(_ejectAnimation, EjectAnimationKey);
|
||||
}
|
||||
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
}
|
||||
|
||||
public enum VendingMachineVisualLayers
|
||||
{
|
||||
Base,
|
||||
}
|
||||
}
|
||||
}
|
||||
79
Content.Client/VendingMachines/VendingMachineMenu.cs
Normal file
79
Content.Client/VendingMachines/VendingMachineMenu.cs
Normal file
@@ -0,0 +1,79 @@
|
||||
using Content.Client.GameObjects.Components.VendingMachines;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.UserInterface.CustomControls;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Maths;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.Interfaces.ResourceManagement;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Prototypes;
|
||||
using static Content.Shared.GameObjects.Components.VendingMachines.SharedVendingMachineComponent;
|
||||
|
||||
namespace Content.Client.VendingMachines
|
||||
{
|
||||
class VendingMachineMenu : SS14Window
|
||||
{
|
||||
protected override Vector2? CustomSize => (300, 450);
|
||||
|
||||
private ItemList _items;
|
||||
private List<VendingMachineInventoryEntry> _cachedInventory;
|
||||
|
||||
#pragma warning disable CS0649
|
||||
[Dependency]
|
||||
private IResourceCache _resourceCache;
|
||||
[Dependency]
|
||||
private readonly IPrototypeManager _prototypeManager;
|
||||
#pragma warning restore
|
||||
public VendingMachineBoundUserInterface Owner { get; set; }
|
||||
public VendingMachineMenu()
|
||||
{
|
||||
}
|
||||
|
||||
public VendingMachineMenu(string name) : base(name)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
IoCManager.InjectDependencies(this);
|
||||
|
||||
_items = new ItemList()
|
||||
{
|
||||
SizeFlagsStretchRatio = 8,
|
||||
SizeFlagsVertical = SizeFlags.FillExpand,
|
||||
};
|
||||
_items.OnItemSelected += ItemSelected;
|
||||
|
||||
Contents.AddChild(_items);
|
||||
}
|
||||
|
||||
public void Populate(List<VendingMachineInventoryEntry> inventory)
|
||||
{
|
||||
_items.Clear();
|
||||
_cachedInventory = inventory;
|
||||
foreach (VendingMachineInventoryEntry entry in inventory)
|
||||
{
|
||||
Texture icon = null;
|
||||
if(_prototypeManager.TryIndex(entry.ID, out EntityPrototype prototype))
|
||||
{
|
||||
icon = IconComponent.GetPrototypeIcon(prototype, _resourceCache).TextureFor(Direction.South);
|
||||
}
|
||||
_items.AddItem($"{entry.ID} ({entry.Amount} left)", icon);
|
||||
}
|
||||
}
|
||||
|
||||
public void ItemSelected(ItemList.ItemListSelectedEventArgs args)
|
||||
{
|
||||
Owner.Eject(_cachedInventory[args.ItemIndex].ID);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user