diff --git a/Content.Client/EntryPoint.cs b/Content.Client/EntryPoint.cs index 35fb7b7748..971096182b 100644 --- a/Content.Client/EntryPoint.cs +++ b/Content.Client/EntryPoint.cs @@ -15,6 +15,7 @@ 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.Kitchen; using Robust.Client; using Robust.Client.Interfaces; using Robust.Client.Interfaces.Graphics.Overlays; @@ -142,8 +143,7 @@ namespace Content.Client "Mop", "Bucket", "Puddle", - "CanSpill", - "Microwave" + "CanSpill" }; foreach (var ignoreName in registerIgnore) @@ -161,7 +161,7 @@ namespace Content.Client factory.Register(); factory.Register(); factory.Register(); - + factory.Register(); prototypes.RegisterIgnore("material"); prototypes.RegisterIgnore("reaction"); //Chemical reactions only needed by server. Reactions checks are server-side. prototypes.RegisterIgnore("barSign"); diff --git a/Content.Client/GameObjects/Components/Kitchen/MicrowaveBoundUserInterface.cs b/Content.Client/GameObjects/Components/Kitchen/MicrowaveBoundUserInterface.cs index 7c15ecb885..1fdd84c7e6 100644 --- a/Content.Client/GameObjects/Components/Kitchen/MicrowaveBoundUserInterface.cs +++ b/Content.Client/GameObjects/Components/Kitchen/MicrowaveBoundUserInterface.cs @@ -2,15 +2,45 @@ using System; using System.Collections.Generic; using System.Text; +using Content.Shared.Kitchen; +using Robust.Shared.GameObjects.Components.UserInterface; namespace Content.Client.GameObjects.Components.Kitchen { public class MicrowaveBoundUserInterface : BoundUserInterface { + private MicrowaveMenu _menu; 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()); + } } } diff --git a/Content.Client/GameObjects/Components/Kitchen/MicrowaveMenu.cs b/Content.Client/GameObjects/Components/Kitchen/MicrowaveMenu.cs new file mode 100644 index 0000000000..0b7016fdba --- /dev/null +++ b/Content.Client/GameObjects/Components/Kitchen/MicrowaveMenu.cs @@ -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 _heldReagents; + + private VBoxContainer InnerScrollContainer { get; set; } + + public MicrowaveMenu(MicrowaveBoundUserInterface owner = null) + { + Owner = owner; + _heldReagents = new List(); + 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 reagents) + { + InnerScrollContainer.RemoveAllChildren(); + foreach (var item in reagents) + { + IoCManager.Resolve().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(); + } + } +} diff --git a/Content.Client/GameObjects/Components/Kitchen/MicrowaveVisualizer.cs b/Content.Client/GameObjects/Components/Kitchen/MicrowaveVisualizer.cs index 124dafb8e2..e7c443074c 100644 --- a/Content.Client/GameObjects/Components/Kitchen/MicrowaveVisualizer.cs +++ b/Content.Client/GameObjects/Components/Kitchen/MicrowaveVisualizer.cs @@ -1,14 +1,14 @@ -using System.Reflection.Metadata.Ecma335; +using System; +using System.Reflection.Metadata.Ecma335; using Content.Client.GameObjects.Components.Sound; using Content.Shared.GameObjects.Components.Power; using Content.Shared.GameObjects.Components.Sound; using Content.Shared.Kitchen; using Robust.Client.GameObjects; -using Robust.Client.GameObjects.EntitySystems; using Robust.Client.Interfaces.GameObjects.Components; using Robust.Shared.Audio; -using Robust.Shared.Interfaces.GameObjects; -using Robust.Shared.IoC; +using Robust.Shared.GameObjects.Components.UserInterface; +using Robust.Shared.Serialization; using YamlDotNet.RepresentationModel; namespace Content.Client.GameObjects.Components.Kitchen @@ -60,6 +60,7 @@ namespace Content.Client.GameObjects.Components.Kitchen } + public enum MicrowaveVisualizerLayers { Base, diff --git a/Content.Server/GameObjects/Components/Kitchen/KitchenMicrowaveComponent.cs b/Content.Server/GameObjects/Components/Kitchen/KitchenMicrowaveComponent.cs index 63c2da2b10..cd7c932235 100644 --- a/Content.Server/GameObjects/Components/Kitchen/KitchenMicrowaveComponent.cs +++ b/Content.Server/GameObjects/Components/Kitchen/KitchenMicrowaveComponent.cs @@ -1,5 +1,4 @@ -using System; -using System.Linq; +using System.Linq; using Content.Server.GameObjects.EntitySystems; using Robust.Shared.GameObjects; using Robust.Shared.IoC; @@ -15,24 +14,22 @@ using Robust.Server.GameObjects; using Content.Shared.GameObjects.Components.Power; using Robust.Server.GameObjects.EntitySystems; using Robust.Server.GameObjects.Components.Container; -using Robust.Shared.Log; using Content.Server.GameObjects.Components.Power; +using Robust.Server.GameObjects.Components.UserInterface; +using Robust.Server.Interfaces.GameObjects; namespace Content.Server.GameObjects.Components.Kitchen { [RegisterComponent] [ComponentReference(typeof(IActivate))] - public class KitchenMicrowaveComponent : Component, IActivate + public class KitchenMicrowaveComponent : SharedMicrowaveComponent, IActivate, ISolutionChange { - #pragma warning disable 649 [Dependency] private readonly IEntitySystemManager _entitySystemManager; [Dependency] private readonly IEntityManager _entityManager; [Dependency] private readonly RecipeManager _recipeManager; #pragma warning restore 649 - public override string Name => "Microwave"; - private int _cookTimeDefault; private int _cookTimeMultiplier; //For upgrades and stuff I guess? private string _badRecipeName; @@ -42,6 +39,10 @@ namespace Content.Server.GameObjects.Components.Kitchen [ViewVariables] public bool _busy = false; + private bool Powered => _powerDevice.Powered; + + private bool HasContents => _contents.ReagentList.Count > 0; + private AppearanceComponent _appearance; private AudioSystem _audioSystem; @@ -49,6 +50,9 @@ namespace Content.Server.GameObjects.Components.Kitchen private PowerDeviceComponent _powerDevice; private Container _storage; + + private BoundUserInterface _userInterface; + void ISolutionChange.SolutionChanged(SolutionChangeEventArgs eventArgs) => UpdateUserInterface(); public override void ExposeData(ObjectSerializer serializer) { base.ExposeData(serializer); @@ -68,23 +72,48 @@ namespace Content.Server.GameObjects.Components.Kitchen _appearance = Owner.GetComponent(); _powerDevice = Owner.GetComponent(); _audioSystem = _entitySystemManager.GetEntitySystem(); + _userInterface = Owner.GetComponent() + .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) { - - if (!_powerDevice.Powered || _busy) return; - if (_contents.ReagentList.Count <= 0) - { + if (!eventArgs.User.TryGetComponent(out IActorComponent actor)) return; - } - _busy = true; - wzhzhzh(); + if (!Powered) return; + UpdateUserInterface(); + _userInterface.Open(actor.playerSession); + } //This is required. private void wzhzhzh() { + _busy = true; foreach(var r in _recipeManager.Recipes) { @@ -101,7 +130,7 @@ namespace Content.Server.GameObjects.Components.Kitchen } else { - _contents.RemoveAllSolution(); + EjectReagents(); } var entityToSpawn = success ? r._result : _badRecipeName; @@ -113,6 +142,14 @@ namespace Content.Server.GameObjects.Components.Kitchen return; } } + + /// + /// This actually deletes all the reagents. + /// + private void EjectReagents() + { + _contents.RemoveAllSolution(); + } private bool CanSatisfyRecipe(FoodRecipePrototype recipe) { foreach (var item in recipe._ingredients) @@ -144,5 +181,10 @@ namespace Content.Server.GameObjects.Components.Kitchen if (_appearance != null || Owner.TryGetComponent(out _appearance)) _appearance.SetData(PowerDeviceVisuals.VisualState, state); } + + private void UpdateUserInterface() + { + _userInterface.SetState(new MicrowaveUserInterfaceState(_contents.Solution.Contents.ToList())); + } } } diff --git a/Content.Shared/GameObjects/ContentNetIDs.cs b/Content.Shared/GameObjects/ContentNetIDs.cs index ef69972f4d..f9832cc751 100644 --- a/Content.Shared/GameObjects/ContentNetIDs.cs +++ b/Content.Shared/GameObjects/ContentNetIDs.cs @@ -42,5 +42,6 @@ public const uint PAPER = 1037; public const uint REAGENT_INJECTOR = 1038; public const uint GHOST = 1039; + public const uint MICROWAVE = 1040; } } diff --git a/Content.Shared/Kitchen/SharedMicrowaveComponent.cs b/Content.Shared/Kitchen/SharedMicrowaveComponent.cs new file mode 100644 index 0000000000..59e34aa82f --- /dev/null +++ b/Content.Shared/Kitchen/SharedMicrowaveComponent.cs @@ -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 ContainedReagents; + public MicrowaveUserInterfaceState(List contained) + { + ContainedReagents = contained; + } + } + + [Serializable, NetSerializable] + public enum MicrowaveVisualState + { + Idle, + Cooking + } + + [NetSerializable, Serializable] + public enum MicrowaveUiKey + { + Key + } + +} diff --git a/Resources/Prototypes/Entities/kitchen.yml b/Resources/Prototypes/Entities/kitchen.yml index 5828bd07ea..f517051c87 100644 --- a/Resources/Prototypes/Entities/kitchen.yml +++ b/Resources/Prototypes/Entities/kitchen.yml @@ -13,6 +13,11 @@ visuals: - type: MicrowaveVisualizer - type: Sound + - type: UserInterface + interfaces: + - key: enum.MicrowaveUiKey.Key + type: MicrowaveBoundUserInterface + - type: Collidable shapes: