diff --git a/Content.Client/GameObjects/Components/Kitchen/MicrowaveBoundUserInterface.cs b/Content.Client/GameObjects/Components/Kitchen/MicrowaveBoundUserInterface.cs index a9f676fc48..94fa205bb2 100644 --- a/Content.Client/GameObjects/Components/Kitchen/MicrowaveBoundUserInterface.cs +++ b/Content.Client/GameObjects/Components/Kitchen/MicrowaveBoundUserInterface.cs @@ -7,8 +7,10 @@ using Content.Shared.Chemistry; using Robust.Shared.GameObjects; using System.Collections.Generic; using Robust.Shared.Interfaces.GameObjects; -using Robust.Client.UserInterface.Controls; + + using Robust.Client.GameObjects; +using Robust.Client.UserInterface.Controls; namespace Content.Client.GameObjects.Components.Kitchen { @@ -32,7 +34,15 @@ namespace Content.Client.GameObjects.Components.Kitchen _menu.OnClose += Close; _menu.StartButton.OnPressed += args => SendMessage(new SharedMicrowaveComponent.MicrowaveStartCookMessage()); _menu.EjectButton.OnPressed += args => SendMessage(new SharedMicrowaveComponent.MicrowaveEjectMessage()); - _menu.IngredientsList.OnItemSelected += args => EjectSolidWithIndex(args.ItemIndex); + _menu.IngredientsList.OnItemSelected += args => SendMessage(new SharedMicrowaveComponent.MicrowaveEjectSolidIndexedMessage(_solids[args.ItemIndex])); + _menu.OnCookTimeSelected += args => + { + var actualButton = args.Button as Button; + var newTime = (byte) int.Parse(actualButton.Text); + _menu.VisualCookTime = newTime; + SendMessage(new SharedMicrowaveComponent.MicrowaveSelectCookTimeMessage(newTime)); + }; + } protected override void Dispose(bool disposing) @@ -60,12 +70,7 @@ namespace Content.Client.GameObjects.Components.Kitchen } - public void EjectSolidWithIndex(int index) - { - SendMessage(new SharedMicrowaveComponent.MicrowaveEjectSolidIndexedMessage(_solids[index])); - } - - public void RefreshContentsDisplay(List reagents, List solids) + private void RefreshContentsDisplay(List reagents, List solids) { _menu.IngredientsList.Clear(); foreach (var item in reagents) @@ -88,7 +93,7 @@ namespace Content.Client.GameObjects.Components.Kitchen _solids.Add(index, entityID); } - + } } diff --git a/Content.Client/GameObjects/Components/Kitchen/MicrowaveMenu.cs b/Content.Client/GameObjects/Components/Kitchen/MicrowaveMenu.cs index 1c43d5cdac..1c7e2e8ce9 100644 --- a/Content.Client/GameObjects/Components/Kitchen/MicrowaveMenu.cs +++ b/Content.Client/GameObjects/Components/Kitchen/MicrowaveMenu.cs @@ -1,13 +1,9 @@ -using System.Collections.Generic; -using Content.Shared.Chemistry; +using System; +using Robust.Client.Graphics.Drawing; using Robust.Client.UserInterface.Controls; using Robust.Client.UserInterface.CustomControls; -using Robust.Shared.GameObjects; -using Robust.Shared.Interfaces.GameObjects; -using Robust.Shared.IoC; using Robust.Shared.Localization; using Robust.Shared.Maths; -using Robust.Shared.Prototypes; namespace Content.Client.GameObjects.Components.Kitchen { @@ -17,18 +13,26 @@ namespace Content.Client.GameObjects.Components.Kitchen private MicrowaveBoundUserInterface Owner { get; set; } + public event Action OnCookTimeSelected; + + public byte VisualCookTime { get; set; } + public Button StartButton { get;} public Button EjectButton { get;} - public GridContainer TimerButtons { get; } + public PanelContainer TimerFacePlate { get; } + + public ButtonGroup CookTimeButtonGroup { get; } + private VBoxContainer CookTimeButtonVbox { get; } public ItemList IngredientsList { get;} + private Label _cookTimeInfoLabel { get; } public MicrowaveMenu(MicrowaveBoundUserInterface owner = null) { Owner = owner; Title = Loc.GetString("Microwave"); - var hSplit = new HSplitContainer + var hSplit = new HBoxContainer { SizeFlagsHorizontal = SizeFlags.Fill, SizeFlagsVertical = SizeFlags.Fill @@ -37,53 +41,135 @@ namespace Content.Client.GameObjects.Components.Kitchen IngredientsList = new ItemList { - SizeFlagsVertical = SizeFlags.Expand, + SizeFlagsVertical = SizeFlags.FillExpand, + SizeFlagsHorizontal = SizeFlags.FillExpand, SelectMode = ItemList.ItemListSelectMode.Button, SizeFlagsStretchRatio = 8, - CustomMinimumSize = (100,100) + CustomMinimumSize = (200,256) }; hSplit.AddChild(IngredientsList); - var vSplit = new VSplitContainer(); + var vSplit = new VBoxContainer + { + SizeFlagsVertical = SizeFlags.FillExpand, + SizeFlagsHorizontal = SizeFlags.FillExpand, + }; + hSplit.AddChild(vSplit); - var buttonGridContainer = new GridContainer + var buttonGridContainer = new VBoxContainer { - Columns = 2, + Align = BoxContainer.AlignMode.Center, + SizeFlagsStretchRatio = 3 }; + StartButton = new Button { - Text = Loc.GetString("START"), + Text = Loc.GetString("Start"), + TextAlign = Label.AlignMode.Center, + }; + EjectButton = new Button { - Text = Loc.GetString("EJECT CONTENTS"), + Text = Loc.GetString("Eject All Contents"), + ToolTip = Loc.GetString("This vaporizes all reagents, but ejects any solids."), + TextAlign = Label.AlignMode.Center, }; + buttonGridContainer.AddChild(StartButton); buttonGridContainer.AddChild(EjectButton); vSplit.AddChild(buttonGridContainer); - - TimerButtons = new GridContainer + CookTimeButtonGroup = new ButtonGroup(); + CookTimeButtonVbox = new VBoxContainer { - Columns = 5, - + SizeFlagsVertical = SizeFlags.FillExpand, + Align = BoxContainer.AlignMode.Center, }; - vSplit.AddChild(TimerButtons); + var index = 0; + for (var i = 0; i <= 12; i++) + { + var newButton = new Button + { + Text = (index <= 0 ? 1 : index).ToString(), + TextAlign = Label.AlignMode.Center, + Group = CookTimeButtonGroup, + }; + CookTimeButtonVbox.AddChild(newButton); + newButton.OnPressed += args => + { + OnCookTimeSelected?.Invoke(args); + _cookTimeInfoLabel.Text = $"{Loc.GetString("COOK TIME")}: {VisualCookTime}"; + }; + index+=5; + } + + _cookTimeInfoLabel = new Label + { + Text = Loc.GetString("COOK TIME:"), + Align = Label.AlignMode.Center, + Modulate = Color.White, + SizeFlagsVertical = SizeFlags.ShrinkCenter + }; + + var innerTimerPanel = new PanelContainer + { + SizeFlagsVertical = SizeFlags.FillExpand, + ModulateSelfOverride = Color.Red, + CustomMinimumSize = (100, 128), + PanelOverride = new StyleBoxFlat {BackgroundColor = Color.Black}, + + Children = + { + new VBoxContainer + { + + Children = + { + new PanelContainer + { + PanelOverride = new StyleBoxFlat(){BackgroundColor = Color.Red.WithAlpha(0.2f)}, + + Children = + { + _cookTimeInfoLabel + } + }, + + new ScrollContainer() + { + SizeFlagsVertical = SizeFlags.FillExpand, + + Children = + { + CookTimeButtonVbox, + } + }, + + } + } + } + }; + + TimerFacePlate = new PanelContainer() + { + SizeFlagsVertical = SizeFlags.FillExpand, + SizeFlagsHorizontal = SizeFlags.FillExpand, + Children = + { + innerTimerPanel + }, + }; + + vSplit.AddChild(TimerFacePlate); Contents.AddChild(hSplit); - } - - - protected override void Dispose(bool disposing) - { - base.Dispose(disposing); - } } } diff --git a/Content.Client/GameObjects/Components/Kitchen/MicrowaveVisualizer.cs b/Content.Client/GameObjects/Components/Kitchen/MicrowaveVisualizer.cs index 2c38876680..1591670f16 100644 --- a/Content.Client/GameObjects/Components/Kitchen/MicrowaveVisualizer.cs +++ b/Content.Client/GameObjects/Components/Kitchen/MicrowaveVisualizer.cs @@ -1,26 +1,19 @@ -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.Sound; using Content.Shared.Kitchen; using Robust.Client.GameObjects; using Robust.Client.Interfaces.GameObjects.Components; using Robust.Shared.Audio; -using Robust.Shared.GameObjects.Components.UserInterface; -using Robust.Shared.Serialization; -using YamlDotNet.RepresentationModel; +using Robust.Shared.Log; + namespace Content.Client.GameObjects.Components.Kitchen { public sealed class MicrowaveVisualizer : AppearanceVisualizer { private SoundComponent _soundComponent; - private const string _microwaveSoundLoop = "/Audio/machines/microwave_loop.ogg"; - public override void LoadData(YamlMappingNode node) - { - base.LoadData(node); - } + private const string MicrowaveSoundLoop = "/Audio/machines/microwave_loop.ogg"; public override void OnChangeData(AppearanceComponent component) { @@ -45,11 +38,15 @@ namespace Content.Client.GameObjects.Components.Kitchen var audioParams = AudioParams.Default; audioParams.Loop = true; var schedSound = new ScheduledSound(); - schedSound.Filename = _microwaveSoundLoop; + schedSound.Filename = MicrowaveSoundLoop; schedSound.AudioParams = audioParams; _soundComponent.AddScheduledSound(schedSound); break; + default: + Logger.Debug($"Something terrible happened in {this}"); + break; + } var glowingPartsVisible = !(component.TryGetData(PowerDeviceVisuals.Powered, out bool powered) && !powered); @@ -59,7 +56,7 @@ namespace Content.Client.GameObjects.Components.Kitchen } - public enum MicrowaveVisualizerLayers + private enum MicrowaveVisualizerLayers { Base, BaseUnlit diff --git a/Content.Server/GameObjects/Components/Kitchen/KitchenMicrowaveComponent.cs b/Content.Server/GameObjects/Components/Kitchen/KitchenMicrowaveComponent.cs index d678c7f7e6..db31904525 100644 --- a/Content.Server/GameObjects/Components/Kitchen/KitchenMicrowaveComponent.cs +++ b/Content.Server/GameObjects/Components/Kitchen/KitchenMicrowaveComponent.cs @@ -33,38 +33,55 @@ namespace Content.Server.GameObjects.Components.Kitchen [Dependency] private readonly IEntitySystemManager _entitySystemManager; [Dependency] private readonly IEntityManager _entityManager; [Dependency] private readonly RecipeManager _recipeManager; - [Dependency] private readonly IPrototypeManager _prototypeManager; [Dependency] private readonly IServerNotifyManager _notifyManager; #pragma warning restore 649 +#region YAMLSERIALIZE private int _cookTimeDefault; private int _cookTimeMultiplier; //For upgrades and stuff I guess? private string _badRecipeName; private string _startCookingSound; private string _cookingCompleteSound; +#endregion + +#region VIEWVARIABLES [ViewVariables] private SolutionComponent _solution; [ViewVariables] private bool _busy = false; + /// + /// This is a fixed offset of 5. + /// The cook times for all recipes should be divisible by 5,with a minimum of 1 second. + /// For right now, I don't think any recipe cook time should be greater than 60 seconds. + /// + [ViewVariables] + private byte _currentCookTimerTime { get; set; } +#endregion + private bool Powered => _powerDevice.Powered; private bool HasContents => _solution.ReagentList.Count > 0 || _storage.ContainedEntities.Count > 0; - private AppearanceComponent _appearance; + void ISolutionChange.SolutionChanged(SolutionChangeEventArgs eventArgs) => UpdateUserInterface(); private AudioSystem _audioSystem; + private AppearanceComponent _appearance; private PowerDeviceComponent _powerDevice; - private Container _storage; + private BoundUserInterface _userInterface; + private Container _storage; + /// + /// A dictionary of PrototypeIDs and integers representing quantity. + /// private Dictionary _solids; private List _solidsVisualList; - private BoundUserInterface _userInterface; - void ISolutionChange.SolutionChanged(SolutionChangeEventArgs eventArgs) => UpdateUserInterface(); + + public override void ExposeData(ObjectSerializer serializer) { base.ExposeData(serializer); @@ -97,22 +114,40 @@ namespace Content.Server.GameObjects.Components.Kitchen private void UserInterfaceOnReceiveMessage(ServerBoundUserInterfaceMessage message) { - if (!Powered || _busy || !HasContents) return; + if (!Powered || _busy) + { + return; + } switch (message.Message) { case MicrowaveStartCookMessage msg : - wzhzhzh(); + if (HasContents) + { + wzhzhzh(); + } break; case MicrowaveEjectMessage msg : - VaporizeReagents(); - EjectSolids(); - UpdateUserInterface(); + if (HasContents) + { + VaporizeReagents(); + EjectSolids(); + UpdateUserInterface(); + } + break; case MicrowaveEjectSolidIndexedMessage msg: - EjectIndexedSolid(msg.EntityID); + if (HasContents) + { + EjectSolidWithIndex(msg.EntityID); + UpdateUserInterface(); + } + break; + + case MicrowaveSelectCookTimeMessage msg: + _currentCookTimerTime = msg.newCookTime; UpdateUserInterface(); break; } @@ -122,7 +157,10 @@ namespace Content.Server.GameObjects.Components.Kitchen private void SetAppearance(MicrowaveVisualState state) { if (_appearance != null || Owner.TryGetComponent(out _appearance)) + { _appearance.SetData(PowerDeviceVisuals.VisualState, state); + } + } private void UpdateUserInterface() @@ -138,9 +176,10 @@ namespace Content.Server.GameObjects.Components.Kitchen void IActivate.Activate(ActivateEventArgs eventArgs) { - if (!eventArgs.User.TryGetComponent(out IActorComponent actor)) + if (!eventArgs.User.TryGetComponent(out IActorComponent actor) || !Powered) + { return; - if (!Powered) return; + } UpdateUserInterface(); _userInterface.Open(actor.playerSession); @@ -177,33 +216,34 @@ namespace Content.Server.GameObjects.Components.Kitchen //Move units from attackSolution to targetSolution var removedSolution = attackSolution.SplitSolution(realTransferAmount); if (!mySolution.TryAddSolution(removedSolution)) + { return false; + } _notifyManager.PopupMessage(Owner.Transform.GridPosition, eventArgs.User, Loc.GetString("Transferred {0}u", removedSolution.TotalVolume)); return true; } - if (itemEntity.TryGetComponent(typeof(FoodComponent), out var food)) + if (!itemEntity.TryGetComponent(typeof(FoodComponent), out var food)) { - var ent = food.Owner; //Get the entity of the ItemComponent. - - _storage.Insert(ent); - - UpdateUserInterface(); - return true; + return false; } - - return false; + + var ent = food.Owner; //Get the entity of the ItemComponent. + _storage.Insert(ent); + UpdateUserInterface(); + return true; + } - //This is required. + //This is required. It's 'cook'. private void wzhzhzh() { _busy = true; // Convert storage into Dictionary of ingredients _solids.Clear(); - foreach(var item in _storage.ContainedEntities.ToList()) + foreach(var item in _storage.ContainedEntities) { if(_solids.ContainsKey(item.Prototype.ID)) { @@ -216,35 +256,44 @@ namespace Content.Server.GameObjects.Components.Kitchen } // Check recipes + FoodRecipePrototype recipeToCook = null; foreach(var r in _recipeManager.Recipes) { - - var success = CanSatisfyRecipe(r); - SetAppearance(MicrowaveVisualState.Cooking); - _audioSystem.Play(_startCookingSound); - var time = success ? r.CookTime : _cookTimeDefault; - Timer.Spawn(time * _cookTimeMultiplier, () => + if (!CanSatisfyRecipe(r)) { + continue; + } - if (success) - { - SubtractContents(r); - } - else - { - VaporizeReagents(); - VaporizeSolids(); - } - - var entityToSpawn = success ? r.Result : _badRecipeName; - _entityManager.SpawnEntity(entityToSpawn, Owner.Transform.GridPosition); - _audioSystem.Play(_cookingCompleteSound); - SetAppearance(MicrowaveVisualState.Idle); - _busy = false; - }); - UpdateUserInterface(); - return; + recipeToCook = r; } + + var goodMeal = (recipeToCook != null) + && + (_currentCookTimerTime == (byte)recipeToCook.CookTime) ? true : false; + + SetAppearance(MicrowaveVisualState.Cooking); + _audioSystem.Play(_startCookingSound); + Timer.Spawn(_currentCookTimerTime * _cookTimeMultiplier, () => + { + + if (goodMeal) + { + SubtractContents(recipeToCook); + } + else + { + VaporizeReagents(); + VaporizeSolids(); + } + + var entityToSpawn = goodMeal ? recipeToCook.Result : _badRecipeName; + _entityManager.SpawnEntity(entityToSpawn, Owner.Transform.GridPosition); + _audioSystem.Play(_cookingCompleteSound); + SetAppearance(MicrowaveVisualState.Idle); + _busy = false; + }); + UpdateUserInterface(); + return; } private void VaporizeReagents() @@ -257,8 +306,10 @@ namespace Content.Server.GameObjects.Components.Kitchen { foreach (var item in _storage.ContainedEntities.ToList()) { + _storage.Remove(item); item.Delete(); } + _solids.Clear(); } private void EjectSolids() @@ -272,7 +323,7 @@ namespace Content.Server.GameObjects.Components.Kitchen _solids.Clear(); } - private void EjectIndexedSolid(EntityUid entityID) + private void EjectSolidWithIndex(EntityUid entityID) { _storage.Remove(_entityManager.GetEntity(entityID)); } @@ -280,15 +331,27 @@ namespace Content.Server.GameObjects.Components.Kitchen private void SubtractContents(FoodRecipePrototype recipe) { - foreach(var kvp in recipe.IngredientsReagents) + foreach(var recipeReagent in recipe.IngredientsReagents) { - _solution.TryRemoveReagent(kvp.Key, ReagentUnit.New(kvp.Value)); + _solution.TryRemoveReagent(recipeReagent.Key, ReagentUnit.New(recipeReagent.Value)); } - foreach (var solid in recipe.IngredientsSolids) + foreach (var recipeSolid in recipe.IngredientsSolids) { - _solids[solid.Key] -= solid.Value; + for (var i = 0; i < recipeSolid.Value; i++) + { + foreach (var item in _storage.ContainedEntities.ToList()) + { + if (item.Prototype.ID == recipeSolid.Key) + { + _storage.Remove(item); + item.Delete(); + break; + } + } + } } + } private bool CanSatisfyRecipe(FoodRecipePrototype recipe) diff --git a/Content.Shared/Kitchen/SharedMicrowaveComponent.cs b/Content.Shared/Kitchen/SharedMicrowaveComponent.cs index 4c9860dc43..d0615c7a75 100644 --- a/Content.Shared/Kitchen/SharedMicrowaveComponent.cs +++ b/Content.Shared/Kitchen/SharedMicrowaveComponent.cs @@ -4,10 +4,7 @@ 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; -using Robust.Shared.Interfaces.GameObjects; - namespace Content.Shared.Kitchen { @@ -44,8 +41,19 @@ namespace Content.Shared.Kitchen EntityID = entityID; } } + [Serializable, NetSerializable] + public class MicrowaveSelectCookTimeMessage : BoundUserInterfaceMessage + { + public byte newCookTime; + public MicrowaveSelectCookTimeMessage(byte newTime) + { + newCookTime = newTime; + } + } } + + [NetSerializable, Serializable] public class MicrowaveUpdateUserInterfaceState : BoundUserInterfaceState { diff --git a/Resources/Prototypes/Entities/Items/Consumables/food.yml b/Resources/Prototypes/Entities/Items/Consumables/food.yml index 7ab00d754b..d07c9a4fe9 100644 --- a/Resources/Prototypes/Entities/Items/Consumables/food.yml +++ b/Resources/Prototypes/Entities/Items/Consumables/food.yml @@ -2865,3 +2865,20 @@ sprite: Objects/Food/xenomeatpie.rsi - type: Icon sprite: Objects/Food/xenomeatpie.rsi + +- type: entity + parent: FoodBase + id: DisgustingSweptSoup + name: Salty Sweet Miso Cola Soup + description: Jesus christ. + components: + - type: Food + contents: + reagents: + - ReagentId: chem.Bleach + Quantity: 15 + spawn_on_finish: TrashSnackBowl + - type: Sprite + sprite: Objects/Food/stew.rsi + - type: Icon + sprite: Objects/Food/stew.rsi diff --git a/Resources/Prototypes/Kitchen/meal_recipes.yml b/Resources/Prototypes/Kitchen/meal_recipes.yml index 356f254188..7d936bc846 100644 --- a/Resources/Prototypes/Kitchen/meal_recipes.yml +++ b/Resources/Prototypes/Kitchen/meal_recipes.yml @@ -2,10 +2,20 @@ id: RecipeCheeseburger name: Cheeseburger Recipe result: FoodCheeseburger - time: 1 + time: 5 reagents: - chem.H2O: 15 - chem.Nutriment: 5 + chem.Nutriment: 10 solids: - Food4NoRaisins: 2 + FoodBreadSlice: 2 + + +- type: microwaveMealRecipe + id: RecipeMisoColaSoup + name: Salty Sweet MisoCola Soup Recipe + result: DisgustingSweptSoup + time: 15 + reagents: + chem.Cola: 5 + solids: + FoodMiloSoup: 1