diff --git a/Content.Client/GameObjects/Components/Kitchen/MicrowaveBoundUserInterface.cs b/Content.Client/GameObjects/Components/Kitchen/MicrowaveBoundUserInterface.cs index 6a07143798..bb70363912 100644 --- a/Content.Client/GameObjects/Components/Kitchen/MicrowaveBoundUserInterface.cs +++ b/Content.Client/GameObjects/Components/Kitchen/MicrowaveBoundUserInterface.cs @@ -1,8 +1,4 @@ using Robust.Client.GameObjects.Components.UserInterface; -using System; -using System.Collections.Generic; -using System.Text; -using Content.Client.GameObjects.Components.Mobs; using Content.Shared.Kitchen; using Robust.Shared.GameObjects.Components.UserInterface; @@ -28,9 +24,9 @@ namespace Content.Client.GameObjects.Components.Kitchen protected override void UpdateState(BoundUserInterfaceState state) { base.UpdateState(state); - if (!(state is MicrowaveUserInterfaceState cstate)) + if (!(state is MicrowaveUpdateUserInterfaceState cstate)) return; - _menu.RefreshContents(cstate.ReagentsReagents, cstate.ContainedSolids); + _menu.RefreshContentsDisplay(cstate.ReagentsReagents, cstate.ContainedSolids); } @@ -43,5 +39,10 @@ namespace Content.Client.GameObjects.Components.Kitchen { SendMessage(new SharedMicrowaveComponent.MicrowaveEjectMessage()); } + + public void EjectSolidWithIndex(int index) + { + SendMessage(new SharedMicrowaveComponent.MicrowaveEjectSolidIndexedMessage(index)); + } } } diff --git a/Content.Client/GameObjects/Components/Kitchen/MicrowaveMenu.cs b/Content.Client/GameObjects/Components/Kitchen/MicrowaveMenu.cs index 83a4a84552..828b06ad25 100644 --- a/Content.Client/GameObjects/Components/Kitchen/MicrowaveMenu.cs +++ b/Content.Client/GameObjects/Components/Kitchen/MicrowaveMenu.cs @@ -1,11 +1,9 @@ using System.Collections.Generic; using Content.Shared.Chemistry; -using Content.Shared.GameObjects; -using Content.Shared.Kitchen; -using Robust.Client.ResourceManagement; 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; @@ -17,7 +15,7 @@ namespace Content.Client.GameObjects.Components.Kitchen { protected override Vector2? CustomSize => (512, 256); - public MicrowaveBoundUserInterface Owner { get; set; } + private MicrowaveBoundUserInterface Owner { get; set; } private List _heldReagents; @@ -35,11 +33,11 @@ namespace Content.Client.GameObjects.Components.Kitchen var startButton = new Button() { - Label = { Text = Loc.GetString("START")} + Label = { Text = Loc.GetString("START"), FontColorOverride = Color.Green} }; var ejectButton = new Button() { - Label = { Text = Loc.GetString("EJECT REAGENTS")} + Label = { Text = Loc.GetString("EJECT REAGENTS"),FontColorOverride = Color.Red} }; var scrollContainer = new ScrollContainer() { @@ -56,24 +54,12 @@ namespace Content.Client.GameObjects.Components.Kitchen vbox.AddChild(ejectButton); vbox.AddChild(scrollContainer); Contents.AddChild(vbox); - startButton.OnPressed += OnCookButtonPressed; - ejectButton.OnPressed += OnEjectButtonPressed; + startButton.OnPressed += args => Owner.Cook(); + ejectButton.OnPressed += args => Owner.Eject(); } - private void OnEjectButtonPressed(BaseButton.ButtonEventArgs obj) - { - Owner.Eject(); - } - - private void OnCookButtonPressed(BaseButton.ButtonEventArgs args) - { - Owner.Cook(); - - } - - - public void RefreshContents(List reagents, Dictionary solids) + public void RefreshContentsDisplay(List reagents, List solids) { InnerScrollContainer.RemoveAllChildren(); foreach (var item in reagents) @@ -82,20 +68,20 @@ namespace Content.Client.GameObjects.Components.Kitchen InnerScrollContainer.AddChild(new Label() { - Text = $"{item.Quantity} {proto.Name}" }); } foreach (var item in solids) { - IoCManager.Resolve().TryIndex(item.Key, out EntityPrototype proto); - var solidLabel = new Button() + var name = IoCManager.Resolve().GetEntity(item).Prototype.Name; + var solidButton = new Button() { - Text = $"{item.Value} {proto.Name}" + Text = $"{name}" }; - InnerScrollContainer.AddChild(solidLabel); + solidButton.OnPressed += args => Owner.EjectSolidWithIndex(solids.IndexOf(item)); + InnerScrollContainer.AddChild(solidButton); } } diff --git a/Content.Client/GameObjects/Components/Kitchen/MicrowaveVisualizer.cs b/Content.Client/GameObjects/Components/Kitchen/MicrowaveVisualizer.cs index e7c443074c..2c38876680 100644 --- a/Content.Client/GameObjects/Components/Kitchen/MicrowaveVisualizer.cs +++ b/Content.Client/GameObjects/Components/Kitchen/MicrowaveVisualizer.cs @@ -20,8 +20,6 @@ namespace Content.Client.GameObjects.Components.Kitchen public override void LoadData(YamlMappingNode node) { base.LoadData(node); - //_audioSystem = IoCManager.Resolve().GetEntitySystem(); - } public override void OnChangeData(AppearanceComponent component) diff --git a/Content.Server/GameObjects/Components/Kitchen/KitchenMicrowaveComponent.cs b/Content.Server/GameObjects/Components/Kitchen/KitchenMicrowaveComponent.cs index 8f7fc05429..7b72081d1c 100644 --- a/Content.Server/GameObjects/Components/Kitchen/KitchenMicrowaveComponent.cs +++ b/Content.Server/GameObjects/Components/Kitchen/KitchenMicrowaveComponent.cs @@ -20,6 +20,8 @@ using Content.Server.GameObjects.Components.Power; using Robust.Server.GameObjects.Components.UserInterface; using Robust.Server.Interfaces.GameObjects; using Robust.Shared.Prototypes; +using Robust.Shared.Localization; +using Content.Server.Interfaces; namespace Content.Server.GameObjects.Components.Kitchen { @@ -32,20 +34,23 @@ namespace Content.Server.GameObjects.Components.Kitchen [Dependency] private readonly IEntityManager _entityManager; [Dependency] private readonly RecipeManager _recipeManager; [Dependency] private readonly IPrototypeManager _prototypeManager; + [Dependency] private readonly IServerNotifyManager _notifyManager; #pragma warning restore 649 private int _cookTimeDefault; private int _cookTimeMultiplier; //For upgrades and stuff I guess? private string _badRecipeName; + private string _startCookingSound; + private string _cookingCompleteSound; [ViewVariables] - private SolutionComponent _contents; + private SolutionComponent _solution; [ViewVariables] - public bool _busy = false; + private bool _busy = false; private bool Powered => _powerDevice.Powered; - private bool HasContents => _contents.ReagentList.Count > 0 || _entityContents.Count > 0; + private bool HasContents => _solution.ReagentList.Count > 0 || _storage.ContainedEntities.Count > 0; private AppearanceComponent _appearance; @@ -55,7 +60,8 @@ namespace Content.Server.GameObjects.Components.Kitchen private Container _storage; - private Dictionary _entityContents; + private Dictionary _solids; + private List _solidsVisualList; private BoundUserInterface _userInterface; void ISolutionChange.SolutionChanged(SolutionChangeEventArgs eventArgs) => UpdateUserInterface(); @@ -65,12 +71,14 @@ namespace Content.Server.GameObjects.Components.Kitchen serializer.DataField(ref _badRecipeName, "failureResult", "FoodBadRecipe"); serializer.DataField(ref _cookTimeDefault, "cookTime", 5); serializer.DataField(ref _cookTimeMultiplier, "cookTimeMultiplier", 1000); + serializer.DataField(ref _startCookingSound, "beginCookingSound","/Audio/machines/microwave_start_beep.ogg" ); + serializer.DataField(ref _cookingCompleteSound, "foodDoneSound","/Audio/machines/microwave_done_beep.ogg" ); } public override void Initialize() { base.Initialize(); - _contents ??= Owner.TryGetComponent(out SolutionComponent solutionComponent) + _solution ??= Owner.TryGetComponent(out SolutionComponent solutionComponent) ? solutionComponent : Owner.AddComponent(); @@ -80,33 +88,53 @@ namespace Content.Server.GameObjects.Components.Kitchen _audioSystem = _entitySystemManager.GetEntitySystem(); _userInterface = Owner.GetComponent() .GetBoundUserInterface(MicrowaveUiKey.Key); - _entityContents = new Dictionary(); + + _solids = new Dictionary(); + _solidsVisualList = new List(); _userInterface.OnReceiveMessage += UserInterfaceOnReceiveMessage; } private void UserInterfaceOnReceiveMessage(ServerBoundUserInterfaceMessage message) { - if (!Powered || _busy) return; + if (!Powered || _busy || !HasContents) return; switch (message.Message) { case MicrowaveStartCookMessage msg : - if (!HasContents) return; - UpdateUserInterface(); wzhzhzh(); break; case MicrowaveEjectMessage msg : - if (!HasContents) return; - DestroyReagents(); + VaporizeReagents(); EjectSolids(); UpdateUserInterface(); break; + + case MicrowaveEjectSolidIndexedMessage msg: + EjectIndexedSolid(msg.index); + UpdateUserInterface(); + break; } } + private void SetAppearance(MicrowaveVisualState state) + { + if (_appearance != null || Owner.TryGetComponent(out _appearance)) + _appearance.SetData(PowerDeviceVisuals.VisualState, state); + } + + private void UpdateUserInterface() + { + _solidsVisualList.Clear(); + foreach(var item in _storage.ContainedEntities.ToList()) + { + _solidsVisualList.Add(item.Uid); + } + + _userInterface.SetState(new MicrowaveUpdateUserInterfaceState(_solution.Solution.Contents.ToList(), _solidsVisualList)); + } void IActivate.Activate(ActivateEventArgs eventArgs) { @@ -121,25 +149,51 @@ namespace Content.Server.GameObjects.Components.Kitchen public bool AttackBy(AttackByEventArgs eventArgs) { var itemEntity = eventArgs.User.GetComponent().GetActiveHand.Owner; - if (itemEntity.TryGetComponent(typeof(FoodComponent), out var food)) + + if(itemEntity.TryGetComponent(out var attackPourable)) { - if (_entityContents.TryGetValue(itemEntity.Prototype.ID, out var quantity) && quantity > 0) + //Get target and check if it can be poured into + if (!Owner.TryGetComponent(out var mySolution) + || !mySolution.CanPourIn) { - quantity++; - food.Owner.Delete(); - UpdateUserInterface(); - return true; - } - else - { - _storage.Insert(food.Owner); + return false; } - _entityContents.Add(itemEntity.Prototype.ID, 1); - UpdateUserInterface(); + if (!itemEntity.TryGetComponent(out var attackSolution) + || !attackSolution.CanPourOut) + { + return false; + } + + //Get transfer amount. May be smaller than _transferAmount if not enough room + var realTransferAmount = ReagentUnit.Min(attackPourable.TransferAmount, mySolution.EmptyVolume); + if (realTransferAmount <= 0) //Special message if container is full + { + _notifyManager.PopupMessage(Owner.Transform.GridPosition, eventArgs.User, + Loc.GetString("Container is full")); + return false; + } + + //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)) + { + var ent = food.Owner; //Get the entity of the ItemComponent. + + _storage.Insert(ent); + + UpdateUserInterface(); + return true; + } + return false; } @@ -147,13 +201,28 @@ namespace Content.Server.GameObjects.Components.Kitchen private void wzhzhzh() { _busy = true; + // Convert storage into Dictionary of ingredients + _solids.Clear(); + foreach(var item in _storage.ContainedEntities.ToList()) + { + if(_solids.ContainsKey(item.Prototype.ID)) + { + _solids[item.Prototype.ID]++; + } + else + { + _solids.Add(item.Prototype.ID, 1); + } + } + + // Check recipes foreach(var r in _recipeManager.Recipes) { var success = CanSatisfyRecipe(r); SetAppearance(MicrowaveVisualState.Cooking); - _audioSystem.Play("/Audio/machines/microwave_start_beep.ogg"); - var time = success ? r._cookTime : _cookTimeDefault; + _audioSystem.Play(_startCookingSound); + var time = success ? r.CookTime : _cookTimeDefault; Timer.Spawn(time * _cookTimeMultiplier, () => { @@ -163,28 +232,33 @@ namespace Content.Server.GameObjects.Components.Kitchen } else { - DestroyReagents(); - EjectSolids(); + VaporizeReagents(); + VaporizeSolids(); } - var entityToSpawn = success ? r._result : _badRecipeName; + var entityToSpawn = success ? r.Result : _badRecipeName; _entityManager.SpawnEntity(entityToSpawn, Owner.Transform.GridPosition); - _audioSystem.Play("/Audio/machines/microwave_done_beep.ogg"); + _audioSystem.Play(_cookingCompleteSound); SetAppearance(MicrowaveVisualState.Idle); _busy = false; }); - _busy = false; UpdateUserInterface(); return; } } - /// - /// This actually deletes all the reagents. - /// - private void DestroyReagents() + private void VaporizeReagents() { - _contents.RemoveAllSolution(); + _solution.RemoveAllSolution(); + + } + + private void VaporizeSolids() + { + foreach (var item in _storage.ContainedEntities.ToList()) + { + item.Delete(); + } } private void EjectSolids() @@ -195,23 +269,34 @@ namespace Content.Server.GameObjects.Components.Kitchen _storage.Remove(item); } - foreach (var kvp in _entityContents) - { - if (kvp.Value > 1 && _prototypeManager.TryIndex(kvp.Key, out EntityPrototype proto)) - { - for(int i = 0; i <= kvp.Value - 1; i++) - _entityManager.SpawnEntity(proto.Name, Owner.Transform.GridPosition); + _solids.Clear(); + } - } + private void EjectIndexedSolid(int index) + { + var entityToRemove = _storage.ContainedEntities.ToArray()[index]; + _storage.Remove(entityToRemove); + } + + + private void SubtractContents(FoodRecipePrototype recipe) + { + foreach(var kvp in recipe.IngredientsReagents) + { + _solution.TryRemoveReagent(kvp.Key, ReagentUnit.New(kvp.Value)); } - _entityContents.Clear(); + foreach (var solid in recipe.IngredientsSolids) + { + _solids[solid.Key] -= solid.Value; + } } + private bool CanSatisfyRecipe(FoodRecipePrototype recipe) { - foreach (var reagent in recipe._ingReagents) + foreach (var reagent in recipe.IngredientsReagents) { - if (!_contents.ContainsReagent(reagent.Key, out var amount)) + if (!_solution.ContainsReagent(reagent.Key, out var amount)) { return false; } @@ -222,14 +307,14 @@ namespace Content.Server.GameObjects.Components.Kitchen } } - foreach (var solid in recipe._ingSolids) + foreach (var solid in recipe.IngredientsSolids) { - if (!_entityContents.TryGetValue(solid.Key, out var amount)) + if (!_solids.ContainsKey(solid.Key)) { return false; } - if (amount < solid.Value) + if (_solids[solid.Key] < solid.Value) { return false; } @@ -238,31 +323,5 @@ namespace Content.Server.GameObjects.Components.Kitchen return true; } - private void SubtractContents(FoodRecipePrototype recipe) - { - foreach(var item in recipe._ingReagents) - { - _contents.TryRemoveReagent(item.Key, ReagentUnit.New(item.Value)); - } - - foreach(var item in recipe._ingSolids) - { - _entityContents.TryGetValue(item.Key, out var value); - value -= item.Value; - } - } - - private void SetAppearance(MicrowaveVisualState state) - { - if (_appearance != null || Owner.TryGetComponent(out _appearance)) - _appearance.SetData(PowerDeviceVisuals.VisualState, state); - } - - private void UpdateUserInterface() - { - _userInterface.SetState(new MicrowaveUserInterfaceState(_contents.Solution.Contents.ToList(), solids:_entityContents)); - } - - } } diff --git a/Content.Shared/Kitchen/RecipeManager.cs b/Content.Shared/Kitchen/RecipeManager.cs index 72772f2434..454c21a440 100644 --- a/Content.Shared/Kitchen/RecipeManager.cs +++ b/Content.Shared/Kitchen/RecipeManager.cs @@ -33,12 +33,12 @@ namespace Content.Shared.Kitchen return 0; } - if (x._ingReagents.Count < y._ingReagents.Count) + if (x.IngredientsReagents.Count < y.IngredientsReagents.Count) { return 1; } - if (x._ingReagents.Count > y._ingReagents.Count) + if (x.IngredientsReagents.Count > y.IngredientsReagents.Count) { return -1; } diff --git a/Content.Shared/Kitchen/SharedMicrowaveComponent.cs b/Content.Shared/Kitchen/SharedMicrowaveComponent.cs index fa506fd107..bbe20d244b 100644 --- a/Content.Shared/Kitchen/SharedMicrowaveComponent.cs +++ b/Content.Shared/Kitchen/SharedMicrowaveComponent.cs @@ -6,6 +6,7 @@ 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 @@ -32,14 +33,25 @@ namespace Content.Shared.Kitchen { } } + + [Serializable, NetSerializable] + public class MicrowaveEjectSolidIndexedMessage : BoundUserInterfaceMessage + { + + public int index; + public MicrowaveEjectSolidIndexedMessage(int i) + { + index = i; + } + } } [NetSerializable, Serializable] - public class MicrowaveUserInterfaceState : BoundUserInterfaceState + public class MicrowaveUpdateUserInterfaceState : BoundUserInterfaceState { public readonly List ReagentsReagents; - public readonly Dictionary ContainedSolids; - public MicrowaveUserInterfaceState(List reagents, Dictionary solids) + public readonly List ContainedSolids; + public MicrowaveUpdateUserInterfaceState(List reagents, List solids) { ReagentsReagents = reagents; ContainedSolids = solids; diff --git a/Content.Shared/Prototypes/Kitchen/MicrowaveMealRecipePrototype.cs b/Content.Shared/Prototypes/Kitchen/MicrowaveMealRecipePrototype.cs index f54a1ac86c..abae3d5eb1 100644 --- a/Content.Shared/Prototypes/Kitchen/MicrowaveMealRecipePrototype.cs +++ b/Content.Shared/Prototypes/Kitchen/MicrowaveMealRecipePrototype.cs @@ -18,16 +18,17 @@ namespace Content.Shared.Prototypes.Kitchen public class FoodRecipePrototype : IPrototype, IIndexedPrototype { - public string _id; - public string _name => Loc.GetString(Name); - private string Name; - public string _result; - public IReadOnlyDictionary _ingReagents => IngredientsReagents; - public IReadOnlyDictionary _ingSolids => IngredientsSolids; + private string _id; + public string Name => Loc.GetString(Name); + private string _name; + public string Result; + public int CookTime; + public IReadOnlyDictionary IngredientsReagents => _ingsReagents; + public IReadOnlyDictionary IngredientsSolids => _ingsSolids; + + private Dictionary _ingsReagents; + private Dictionary _ingsSolids; - private Dictionary IngredientsReagents; - private Dictionary IngredientsSolids; - public int _cookTime; public string ID => _id; @@ -36,11 +37,11 @@ namespace Content.Shared.Prototypes.Kitchen var serializer = YamlObjectSerializer.NewReader(mapping); serializer.DataField(ref _id, "id", string.Empty); - serializer.DataField(ref Name, "name", string.Empty); - serializer.DataField(ref _result, "result", string.Empty); - serializer.DataField(ref IngredientsReagents, "reagents", new Dictionary()); - serializer.DataField(ref IngredientsSolids, "solids", new Dictionary()); - serializer.DataField(ref _cookTime, "time", 5); + serializer.DataField(ref _name, "name", string.Empty); + serializer.DataField(ref Result, "result", string.Empty); + serializer.DataField(ref _ingsReagents, "reagents", new Dictionary()); + serializer.DataField(ref _ingsSolids, "solids", new Dictionary()); + serializer.DataField(ref CookTime, "time", 5); } } diff --git a/Resources/Prototypes/Kitchen/meal_recipes.yml b/Resources/Prototypes/Kitchen/meal_recipes.yml index a1c3fc51ba..356f254188 100644 --- a/Resources/Prototypes/Kitchen/meal_recipes.yml +++ b/Resources/Prototypes/Kitchen/meal_recipes.yml @@ -2,10 +2,10 @@ id: RecipeCheeseburger name: Cheeseburger Recipe result: FoodCheeseburger - time: 10 + time: 1 reagents: chem.H2O: 15 chem.Nutriment: 5 solids: - FoodMeatBreadSlice: 1 + Food4NoRaisins: 2