Pretty up the microwave menu, add click sounds. Remove some unnecessary ToList() calls. Remove unnecessary IoC resolves.
This commit is contained in:
@@ -16,6 +16,10 @@ namespace Content.Client.GameObjects.Components.Kitchen
|
||||
{
|
||||
public class MicrowaveBoundUserInterface : BoundUserInterface
|
||||
{
|
||||
#pragma warning disable 649
|
||||
[Dependency] private readonly IEntityManager _entityManager;
|
||||
[Dependency] private readonly IPrototypeManager _prototypeManager;
|
||||
#pragma warning restore 649
|
||||
private MicrowaveMenu _menu;
|
||||
|
||||
private Dictionary<int, EntityUid> _solids = new Dictionary<int, EntityUid>();
|
||||
@@ -38,7 +42,7 @@ namespace Content.Client.GameObjects.Components.Kitchen
|
||||
_menu.OnCookTimeSelected += args =>
|
||||
{
|
||||
var actualButton = args.Button as Button;
|
||||
var newTime = (byte) int.Parse(actualButton.Text);
|
||||
var newTime = (uint) int.Parse(actualButton.Text);
|
||||
_menu.VisualCookTime = newTime;
|
||||
SendMessage(new SharedMicrowaveComponent.MicrowaveSelectCookTimeMessage(newTime));
|
||||
};
|
||||
@@ -75,7 +79,7 @@ namespace Content.Client.GameObjects.Components.Kitchen
|
||||
_menu.IngredientsList.Clear();
|
||||
foreach (var item in reagents)
|
||||
{
|
||||
IoCManager.Resolve<IPrototypeManager>().TryIndex(item.ReagentId, out ReagentPrototype proto);
|
||||
_prototypeManager.TryIndex(item.ReagentId, out ReagentPrototype proto);
|
||||
|
||||
_menu.IngredientsList.AddItem($"{item.Quantity} {proto.Name}");
|
||||
}
|
||||
@@ -83,7 +87,7 @@ namespace Content.Client.GameObjects.Components.Kitchen
|
||||
_solids.Clear();
|
||||
foreach (var entityID in solids)
|
||||
{
|
||||
var entity = IoCManager.Resolve<IEntityManager>().GetEntity(entityID);
|
||||
var entity = _entityManager.GetEntity(entityID);
|
||||
|
||||
if (entity.TryGetComponent(out IconComponent icon))
|
||||
{
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using Robust.Client.Graphics.Drawing;
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.UserInterface.CustomControls;
|
||||
using Robust.Shared.Localization;
|
||||
@@ -15,7 +16,7 @@ namespace Content.Client.GameObjects.Components.Kitchen
|
||||
|
||||
public event Action<BaseButton.ButtonEventArgs> OnCookTimeSelected;
|
||||
|
||||
public byte VisualCookTime { get; set; }
|
||||
public uint VisualCookTime = 1;
|
||||
|
||||
public Button StartButton { get;}
|
||||
public Button EjectButton { get;}
|
||||
@@ -82,6 +83,13 @@ namespace Content.Client.GameObjects.Components.Kitchen
|
||||
buttonGridContainer.AddChild(EjectButton);
|
||||
vSplit.AddChild(buttonGridContainer);
|
||||
|
||||
//Padding
|
||||
vSplit.AddChild(new Control
|
||||
{
|
||||
CustomMinimumSize = (0, 15),
|
||||
SizeFlagsVertical = SizeFlags.Fill,
|
||||
});
|
||||
|
||||
CookTimeButtonGroup = new ButtonGroup();
|
||||
CookTimeButtonVbox = new VBoxContainer
|
||||
{
|
||||
@@ -107,9 +115,12 @@ namespace Content.Client.GameObjects.Components.Kitchen
|
||||
index+=5;
|
||||
}
|
||||
|
||||
var cookTimeOneSecondButton = (Button)CookTimeButtonVbox.GetChild(0);
|
||||
cookTimeOneSecondButton.Pressed = true;
|
||||
|
||||
_cookTimeInfoLabel = new Label
|
||||
{
|
||||
Text = Loc.GetString("COOK TIME:"),
|
||||
Text = Loc.GetString($"COOK TIME: {VisualCookTime}"),
|
||||
Align = Label.AlignMode.Center,
|
||||
Modulate = Color.White,
|
||||
SizeFlagsVertical = SizeFlags.ShrinkCenter
|
||||
@@ -120,18 +131,20 @@ namespace Content.Client.GameObjects.Components.Kitchen
|
||||
SizeFlagsVertical = SizeFlags.FillExpand,
|
||||
ModulateSelfOverride = Color.Red,
|
||||
CustomMinimumSize = (100, 128),
|
||||
PanelOverride = new StyleBoxFlat {BackgroundColor = Color.Black},
|
||||
PanelOverride = new StyleBoxFlat {BackgroundColor = Color.Black.WithAlpha(0.5f)},
|
||||
|
||||
Children =
|
||||
{
|
||||
|
||||
new VBoxContainer
|
||||
{
|
||||
|
||||
Children =
|
||||
{
|
||||
|
||||
new PanelContainer
|
||||
{
|
||||
PanelOverride = new StyleBoxFlat(){BackgroundColor = Color.Red.WithAlpha(0.2f)},
|
||||
PanelOverride = new StyleBoxFlat(){BackgroundColor = Color.Gray.WithAlpha(0.2f)},
|
||||
|
||||
Children =
|
||||
{
|
||||
@@ -162,6 +175,7 @@ namespace Content.Client.GameObjects.Components.Kitchen
|
||||
SizeFlagsHorizontal = SizeFlags.FillExpand,
|
||||
Children =
|
||||
{
|
||||
|
||||
innerTimerPanel
|
||||
},
|
||||
};
|
||||
|
||||
@@ -22,6 +22,8 @@ using Robust.Server.Interfaces.GameObjects;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Localization;
|
||||
using Content.Server.Interfaces;
|
||||
using Robust.Shared.Audio;
|
||||
using YamlDotNet.Serialization.NodeTypeResolvers;
|
||||
|
||||
namespace Content.Server.GameObjects.Components.Kitchen
|
||||
{
|
||||
@@ -57,7 +59,7 @@ namespace Content.Server.GameObjects.Components.Kitchen
|
||||
/// For right now, I don't think any recipe cook time should be greater than 60 seconds.
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
private byte _currentCookTimerTime { get; set; }
|
||||
private uint _currentCookTimerTime { get; set; } = 1;
|
||||
#endregion
|
||||
|
||||
private bool Powered => _powerDevice.Powered;
|
||||
@@ -109,7 +111,6 @@ namespace Content.Server.GameObjects.Components.Kitchen
|
||||
_solids = new Dictionary<string, int>();
|
||||
_solidsVisualList = new List<EntityUid>();
|
||||
_userInterface.OnReceiveMessage += UserInterfaceOnReceiveMessage;
|
||||
|
||||
}
|
||||
|
||||
private void UserInterfaceOnReceiveMessage(ServerBoundUserInterfaceMessage message)
|
||||
@@ -122,10 +123,7 @@ namespace Content.Server.GameObjects.Components.Kitchen
|
||||
switch (message.Message)
|
||||
{
|
||||
case MicrowaveStartCookMessage msg :
|
||||
if (HasContents)
|
||||
{
|
||||
wzhzhzh();
|
||||
}
|
||||
break;
|
||||
|
||||
case MicrowaveEjectMessage msg :
|
||||
@@ -133,6 +131,7 @@ namespace Content.Server.GameObjects.Components.Kitchen
|
||||
{
|
||||
VaporizeReagents();
|
||||
EjectSolids();
|
||||
ClickSound();
|
||||
UpdateUserInterface();
|
||||
}
|
||||
|
||||
@@ -142,12 +141,14 @@ namespace Content.Server.GameObjects.Components.Kitchen
|
||||
if (HasContents)
|
||||
{
|
||||
EjectSolidWithIndex(msg.EntityID);
|
||||
ClickSound();
|
||||
UpdateUserInterface();
|
||||
}
|
||||
break;
|
||||
|
||||
case MicrowaveSelectCookTimeMessage msg:
|
||||
_currentCookTimerTime = msg.newCookTime;
|
||||
ClickSound();
|
||||
UpdateUserInterface();
|
||||
break;
|
||||
}
|
||||
@@ -166,7 +167,7 @@ namespace Content.Server.GameObjects.Components.Kitchen
|
||||
private void UpdateUserInterface()
|
||||
{
|
||||
_solidsVisualList.Clear();
|
||||
foreach(var item in _storage.ContainedEntities.ToList())
|
||||
foreach(var item in _storage.ContainedEntities)
|
||||
{
|
||||
_solidsVisualList.Add(item.Uid);
|
||||
}
|
||||
@@ -240,6 +241,11 @@ namespace Content.Server.GameObjects.Components.Kitchen
|
||||
//This is required. It's 'cook'.
|
||||
private void wzhzhzh()
|
||||
{
|
||||
if (!HasContents)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_busy = true;
|
||||
// Convert storage into Dictionary of ingredients
|
||||
_solids.Clear();
|
||||
@@ -269,11 +275,11 @@ namespace Content.Server.GameObjects.Components.Kitchen
|
||||
|
||||
var goodMeal = (recipeToCook != null)
|
||||
&&
|
||||
(_currentCookTimerTime == (byte)recipeToCook.CookTime) ? true : false;
|
||||
(_currentCookTimerTime == (uint)recipeToCook.CookTime) ? true : false;
|
||||
|
||||
SetAppearance(MicrowaveVisualState.Cooking);
|
||||
_audioSystem.Play(_startCookingSound);
|
||||
Timer.Spawn(_currentCookTimerTime * _cookTimeMultiplier, () =>
|
||||
Timer.Spawn((int)(_currentCookTimerTime * _cookTimeMultiplier), () =>
|
||||
{
|
||||
|
||||
if (goodMeal)
|
||||
@@ -340,7 +346,7 @@ namespace Content.Server.GameObjects.Components.Kitchen
|
||||
{
|
||||
for (var i = 0; i < recipeSolid.Value; i++)
|
||||
{
|
||||
foreach (var item in _storage.ContainedEntities.ToList())
|
||||
foreach (var item in _storage.ContainedEntities)
|
||||
{
|
||||
if (item.Prototype.ID == recipeSolid.Key)
|
||||
{
|
||||
@@ -385,5 +391,12 @@ namespace Content.Server.GameObjects.Components.Kitchen
|
||||
return true;
|
||||
}
|
||||
|
||||
private void ClickSound()
|
||||
{
|
||||
|
||||
_audioSystem.Play("/Audio/machines/machine_switch.ogg", AudioParams.Default.WithVolume(-2f));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,29 +24,17 @@ namespace Content.Shared.Kitchen
|
||||
|
||||
Recipes.Sort(new RecipeComparer());
|
||||
}
|
||||
private class RecipeComparer : IComparer<FoodRecipePrototype>
|
||||
private class RecipeComparer : Comparer<FoodRecipePrototype>
|
||||
{
|
||||
int IComparer<FoodRecipePrototype>.Compare(FoodRecipePrototype x, FoodRecipePrototype y)
|
||||
public override int Compare(FoodRecipePrototype x, FoodRecipePrototype y)
|
||||
{
|
||||
if (x == null || y == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (x.IngredientsReagents.Count < y.IngredientsReagents.Count)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (x.IngredientsReagents.Count > y.IngredientsReagents.Count)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
return -x.IngredientsReagents.Count.CompareTo(y.IngredientsReagents.Count);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,10 +44,10 @@ namespace Content.Shared.Kitchen
|
||||
[Serializable, NetSerializable]
|
||||
public class MicrowaveSelectCookTimeMessage : BoundUserInterfaceMessage
|
||||
{
|
||||
public byte newCookTime;
|
||||
public MicrowaveSelectCookTimeMessage(byte newTime)
|
||||
public uint newCookTime;
|
||||
public MicrowaveSelectCookTimeMessage(uint inputTime)
|
||||
{
|
||||
newCookTime = newTime;
|
||||
newCookTime = inputTime;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user