Microwave interface.

This commit is contained in:
FL-OZ
2020-05-01 23:34:04 -05:00
parent 13fba25edc
commit dd19466578
8 changed files with 256 additions and 22 deletions

View File

@@ -15,6 +15,7 @@ using Content.Shared.GameObjects.Components.Chemistry;
using Content.Shared.GameObjects.Components.Markers; using Content.Shared.GameObjects.Components.Markers;
using Content.Shared.GameObjects.Components.Research; using Content.Shared.GameObjects.Components.Research;
using Content.Shared.GameObjects.Components.VendingMachines; using Content.Shared.GameObjects.Components.VendingMachines;
using Content.Shared.Kitchen;
using Robust.Client; using Robust.Client;
using Robust.Client.Interfaces; using Robust.Client.Interfaces;
using Robust.Client.Interfaces.Graphics.Overlays; using Robust.Client.Interfaces.Graphics.Overlays;
@@ -142,8 +143,7 @@ namespace Content.Client
"Mop", "Mop",
"Bucket", "Bucket",
"Puddle", "Puddle",
"CanSpill", "CanSpill"
"Microwave"
}; };
foreach (var ignoreName in registerIgnore) foreach (var ignoreName in registerIgnore)
@@ -161,7 +161,7 @@ namespace Content.Client
factory.Register<SharedWiresComponent>(); factory.Register<SharedWiresComponent>();
factory.Register<SharedCargoConsoleComponent>(); factory.Register<SharedCargoConsoleComponent>();
factory.Register<SharedReagentDispenserComponent>(); factory.Register<SharedReagentDispenserComponent>();
factory.Register<SharedMicrowaveComponent>();
prototypes.RegisterIgnore("material"); prototypes.RegisterIgnore("material");
prototypes.RegisterIgnore("reaction"); //Chemical reactions only needed by server. Reactions checks are server-side. prototypes.RegisterIgnore("reaction"); //Chemical reactions only needed by server. Reactions checks are server-side.
prototypes.RegisterIgnore("barSign"); prototypes.RegisterIgnore("barSign");

View File

@@ -2,15 +2,45 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
using Content.Shared.Kitchen;
using Robust.Shared.GameObjects.Components.UserInterface;
namespace Content.Client.GameObjects.Components.Kitchen namespace Content.Client.GameObjects.Components.Kitchen
{ {
public class MicrowaveBoundUserInterface : BoundUserInterface public class MicrowaveBoundUserInterface : BoundUserInterface
{ {
private MicrowaveMenu _menu;
public MicrowaveBoundUserInterface(ClientUserInterfaceComponent owner, object uiKey) : base(owner,uiKey) public MicrowaveBoundUserInterface(ClientUserInterfaceComponent owner, object uiKey) : base(owner,uiKey)
{ {
} }
protected override void Open()
{
base.Open();
_menu = new MicrowaveMenu(this);
_menu.OpenCentered();
_menu.OnClose += Close;
}
protected override void UpdateState(BoundUserInterfaceState state)
{
base.UpdateState(state);
if (!(state is MicrowaveUserInterfaceState cstate))
return;
_menu.RefreshReagents(cstate.ContainedReagents);
}
public void Cook()
{
SendMessage(new SharedMicrowaveComponent.MicrowaveStartCookMessage());
}
public void Eject()
{
SendMessage(new SharedMicrowaveComponent.MicrowaveEjectMessage());
}
} }
} }

View File

@@ -0,0 +1,95 @@
using System.Collections.Generic;
using Content.Shared.Chemistry;
using Content.Shared.GameObjects;
using Content.Shared.Kitchen;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.CustomControls;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Maths;
using Robust.Shared.Prototypes;
namespace Content.Client.GameObjects.Components.Kitchen
{
public class MicrowaveMenu : SS14Window
{
protected override Vector2? CustomSize => (512, 256);
public MicrowaveBoundUserInterface Owner { get; set; }
private List<Solution.ReagentQuantity> _heldReagents;
private VBoxContainer InnerScrollContainer { get; set; }
public MicrowaveMenu(MicrowaveBoundUserInterface owner = null)
{
Owner = owner;
_heldReagents = new List<Solution.ReagentQuantity>();
Title = Loc.GetString("Microwave");
var vbox = new VBoxContainer()
{
SizeFlagsVertical = SizeFlags.Fill
};
var startButton = new Button()
{
Label = { Text = Loc.GetString("START")}
};
var ejectButton = new Button()
{
Label = { Text = Loc.GetString("EJECT CONTENTS")}
};
var scrollContainer = new ScrollContainer()
{
SizeFlagsVertical = SizeFlags.FillExpand
};
InnerScrollContainer = new VBoxContainer()
{
SizeFlagsVertical = SizeFlags.FillExpand
};
scrollContainer.AddChild(InnerScrollContainer);
vbox.AddChild(startButton);
vbox.AddChild(ejectButton);
vbox.AddChild(scrollContainer);
Contents.AddChild(vbox);
startButton.OnPressed += OnCookButtonPressed;
ejectButton.OnPressed += OnEjectButtonPressed;
}
private void OnEjectButtonPressed(BaseButton.ButtonEventArgs obj)
{
Owner.Eject();
}
private void OnCookButtonPressed(BaseButton.ButtonEventArgs args)
{
Owner.Cook();
}
public void RefreshReagents(List<Solution.ReagentQuantity> reagents)
{
InnerScrollContainer.RemoveAllChildren();
foreach (var item in reagents)
{
IoCManager.Resolve<IPrototypeManager>().TryIndex(item.ReagentId, out ReagentPrototype proto);
InnerScrollContainer.AddChild(new Label()
{
Text = $"{item.Quantity} {proto.Name}"
});
}
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
InnerScrollContainer.Dispose();
}
}
}

View File

@@ -1,14 +1,14 @@
using System.Reflection.Metadata.Ecma335; using System;
using System.Reflection.Metadata.Ecma335;
using Content.Client.GameObjects.Components.Sound; using Content.Client.GameObjects.Components.Sound;
using Content.Shared.GameObjects.Components.Power; using Content.Shared.GameObjects.Components.Power;
using Content.Shared.GameObjects.Components.Sound; using Content.Shared.GameObjects.Components.Sound;
using Content.Shared.Kitchen; using Content.Shared.Kitchen;
using Robust.Client.GameObjects; using Robust.Client.GameObjects;
using Robust.Client.GameObjects.EntitySystems;
using Robust.Client.Interfaces.GameObjects.Components; using Robust.Client.Interfaces.GameObjects.Components;
using Robust.Shared.Audio; using Robust.Shared.Audio;
using Robust.Shared.Interfaces.GameObjects; using Robust.Shared.GameObjects.Components.UserInterface;
using Robust.Shared.IoC; using Robust.Shared.Serialization;
using YamlDotNet.RepresentationModel; using YamlDotNet.RepresentationModel;
namespace Content.Client.GameObjects.Components.Kitchen namespace Content.Client.GameObjects.Components.Kitchen
@@ -60,6 +60,7 @@ namespace Content.Client.GameObjects.Components.Kitchen
} }
public enum MicrowaveVisualizerLayers public enum MicrowaveVisualizerLayers
{ {
Base, Base,

View File

@@ -1,5 +1,4 @@
using System; using System.Linq;
using System.Linq;
using Content.Server.GameObjects.EntitySystems; using Content.Server.GameObjects.EntitySystems;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.IoC; using Robust.Shared.IoC;
@@ -15,24 +14,22 @@ using Robust.Server.GameObjects;
using Content.Shared.GameObjects.Components.Power; using Content.Shared.GameObjects.Components.Power;
using Robust.Server.GameObjects.EntitySystems; using Robust.Server.GameObjects.EntitySystems;
using Robust.Server.GameObjects.Components.Container; using Robust.Server.GameObjects.Components.Container;
using Robust.Shared.Log;
using Content.Server.GameObjects.Components.Power; using Content.Server.GameObjects.Components.Power;
using Robust.Server.GameObjects.Components.UserInterface;
using Robust.Server.Interfaces.GameObjects;
namespace Content.Server.GameObjects.Components.Kitchen namespace Content.Server.GameObjects.Components.Kitchen
{ {
[RegisterComponent] [RegisterComponent]
[ComponentReference(typeof(IActivate))] [ComponentReference(typeof(IActivate))]
public class KitchenMicrowaveComponent : Component, IActivate public class KitchenMicrowaveComponent : SharedMicrowaveComponent, IActivate, ISolutionChange
{ {
#pragma warning disable 649 #pragma warning disable 649
[Dependency] private readonly IEntitySystemManager _entitySystemManager; [Dependency] private readonly IEntitySystemManager _entitySystemManager;
[Dependency] private readonly IEntityManager _entityManager; [Dependency] private readonly IEntityManager _entityManager;
[Dependency] private readonly RecipeManager _recipeManager; [Dependency] private readonly RecipeManager _recipeManager;
#pragma warning restore 649 #pragma warning restore 649
public override string Name => "Microwave";
private int _cookTimeDefault; private int _cookTimeDefault;
private int _cookTimeMultiplier; //For upgrades and stuff I guess? private int _cookTimeMultiplier; //For upgrades and stuff I guess?
private string _badRecipeName; private string _badRecipeName;
@@ -42,6 +39,10 @@ namespace Content.Server.GameObjects.Components.Kitchen
[ViewVariables] [ViewVariables]
public bool _busy = false; public bool _busy = false;
private bool Powered => _powerDevice.Powered;
private bool HasContents => _contents.ReagentList.Count > 0;
private AppearanceComponent _appearance; private AppearanceComponent _appearance;
private AudioSystem _audioSystem; private AudioSystem _audioSystem;
@@ -49,6 +50,9 @@ namespace Content.Server.GameObjects.Components.Kitchen
private PowerDeviceComponent _powerDevice; private PowerDeviceComponent _powerDevice;
private Container _storage; private Container _storage;
private BoundUserInterface _userInterface;
void ISolutionChange.SolutionChanged(SolutionChangeEventArgs eventArgs) => UpdateUserInterface();
public override void ExposeData(ObjectSerializer serializer) public override void ExposeData(ObjectSerializer serializer)
{ {
base.ExposeData(serializer); base.ExposeData(serializer);
@@ -68,23 +72,48 @@ namespace Content.Server.GameObjects.Components.Kitchen
_appearance = Owner.GetComponent<AppearanceComponent>(); _appearance = Owner.GetComponent<AppearanceComponent>();
_powerDevice = Owner.GetComponent<PowerDeviceComponent>(); _powerDevice = Owner.GetComponent<PowerDeviceComponent>();
_audioSystem = _entitySystemManager.GetEntitySystem<AudioSystem>(); _audioSystem = _entitySystemManager.GetEntitySystem<AudioSystem>();
_userInterface = Owner.GetComponent<ServerUserInterfaceComponent>()
.GetBoundUserInterface(MicrowaveUiKey.Key);
_userInterface.OnReceiveMessage += UserInterfaceOnReceiveMessage;
} }
private void UserInterfaceOnReceiveMessage(ServerBoundUserInterfaceMessage message)
{
if (!Powered || _busy) return;
switch (message.Message)
{
case MicrowaveStartCookMessage msg :
if (!HasContents) return;
UpdateUserInterface();
wzhzhzh();
break;
case MicrowaveEjectMessage msg :
if (!HasContents) return;
EjectReagents();
UpdateUserInterface();
break;
}
}
void IActivate.Activate(ActivateEventArgs eventArgs) void IActivate.Activate(ActivateEventArgs eventArgs)
{ {
if (!eventArgs.User.TryGetComponent(out IActorComponent actor))
if (!_powerDevice.Powered || _busy) return;
if (_contents.ReagentList.Count <= 0)
{
return; return;
} if (!Powered) return;
_busy = true; UpdateUserInterface();
wzhzhzh(); _userInterface.Open(actor.playerSession);
} }
//This is required. //This is required.
private void wzhzhzh() private void wzhzhzh()
{ {
_busy = true;
foreach(var r in _recipeManager.Recipes) foreach(var r in _recipeManager.Recipes)
{ {
@@ -101,7 +130,7 @@ namespace Content.Server.GameObjects.Components.Kitchen
} }
else else
{ {
_contents.RemoveAllSolution(); EjectReagents();
} }
var entityToSpawn = success ? r._result : _badRecipeName; var entityToSpawn = success ? r._result : _badRecipeName;
@@ -113,6 +142,14 @@ namespace Content.Server.GameObjects.Components.Kitchen
return; return;
} }
} }
/// <summary>
/// This actually deletes all the reagents.
/// </summary>
private void EjectReagents()
{
_contents.RemoveAllSolution();
}
private bool CanSatisfyRecipe(FoodRecipePrototype recipe) private bool CanSatisfyRecipe(FoodRecipePrototype recipe)
{ {
foreach (var item in recipe._ingredients) foreach (var item in recipe._ingredients)
@@ -144,5 +181,10 @@ namespace Content.Server.GameObjects.Components.Kitchen
if (_appearance != null || Owner.TryGetComponent(out _appearance)) if (_appearance != null || Owner.TryGetComponent(out _appearance))
_appearance.SetData(PowerDeviceVisuals.VisualState, state); _appearance.SetData(PowerDeviceVisuals.VisualState, state);
} }
private void UpdateUserInterface()
{
_userInterface.SetState(new MicrowaveUserInterfaceState(_contents.Solution.Contents.ToList()));
}
} }
} }

View File

@@ -42,5 +42,6 @@
public const uint PAPER = 1037; public const uint PAPER = 1037;
public const uint REAGENT_INJECTOR = 1038; public const uint REAGENT_INJECTOR = 1038;
public const uint GHOST = 1039; public const uint GHOST = 1039;
public const uint MICROWAVE = 1040;
} }
} }

View File

@@ -0,0 +1,60 @@
using System;
using System.Collections.Generic;
using Content.Shared.Chemistry;
using Content.Shared.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.Serialization;
using Robust.Shared.GameObjects.Components;
using Robust.Shared.GameObjects.Components.UserInterface;
namespace Content.Shared.Kitchen
{
public class SharedMicrowaveComponent : Component
{
public override string Name => "Microwave";
public override uint? NetID => ContentNetIDs.MICROWAVE;
[Serializable, NetSerializable]
public class MicrowaveStartCookMessage : BoundUserInterfaceMessage
{
public MicrowaveStartCookMessage()
{
}
}
[Serializable, NetSerializable]
public class MicrowaveEjectMessage : BoundUserInterfaceMessage
{
public MicrowaveEjectMessage()
{
}
}
}
[NetSerializable, Serializable]
public class MicrowaveUserInterfaceState : BoundUserInterfaceState
{
public readonly List<Solution.ReagentQuantity> ContainedReagents;
public MicrowaveUserInterfaceState(List<Solution.ReagentQuantity> contained)
{
ContainedReagents = contained;
}
}
[Serializable, NetSerializable]
public enum MicrowaveVisualState
{
Idle,
Cooking
}
[NetSerializable, Serializable]
public enum MicrowaveUiKey
{
Key
}
}

View File

@@ -13,6 +13,11 @@
visuals: visuals:
- type: MicrowaveVisualizer - type: MicrowaveVisualizer
- type: Sound - type: Sound
- type: UserInterface
interfaces:
- key: enum.MicrowaveUiKey.Key
type: MicrowaveBoundUserInterface
- type: Collidable - type: Collidable
shapes: shapes: