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