Add Microwave (#862)
* Add meal recipe prototype class and yaml file. Add bare bones MicrowaveComponent. * Reformat the way recipe prototypes work to something sensible. More work on Microwave component. * Rewrite recipe prototype. Fix comparer in microwavecomponent. * Add Eris microwave RSI. Cleaned up the Microwave component code. * Refactor "output" to "result" for recipes/prototypes. Remove a debug recipe from meal_recipes.yml Add food.yml for food related reagents: sugar, flour, etc. * Unfuck mostly everything. * ShadowCommander is MVP. * Add microwave visualizer. Clean up microwave code. * Reformat 'PoweredIdle' to 'Idle' * Refactor SoundComponent for stopping sounds. * A shit ton of microwave stuff i can't really explain this. * Microwave interface. * Add (not working) basis for allowing solids (entities) in recipes. * Microwave UI + solids implemented. * Next up timer buttons * Microwave is done. Added an easter egg recipe and made the cheeseburger recipe more sensible. * Delete microwave.dmi, unneeded. Revert accidently changes to Shared EntryPoint.cs * trying that again * Remove unused 'ding.ogg' * revert entrypoint to master * revert sharedlathecomponent to master * Pretty up the microwave menu, add click sounds. Remove some unnecessary ToList() calls. Remove unnecessary IoC resolves. * And not a single "ToList()" went home to their family that day..... * Seperated Reagent item list and Solid item list to allow for vaporizing particular reagents at will. (also fixes a really nasty null reference exception because they shared the same list before D: ) * Remove unncessary class dictionary and list. Fix meal prototype properties. * lol Co-authored-by: FL-OZ <yetanotherscuffed@gmail.com> Co-authored-by: FLOZ <anotherscuffed@gmail.com> Co-authored-by: Pieter-Jan Briers <pieterjan.briers+git@gmail.com>
This commit is contained in:
@@ -0,0 +1,119 @@
|
||||
using Robust.Client.GameObjects.Components.UserInterface;
|
||||
using Content.Shared.Kitchen;
|
||||
using Robust.Shared.GameObjects.Components.UserInterface;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Content.Shared.Chemistry;
|
||||
using Robust.Shared.GameObjects;
|
||||
using System.Collections.Generic;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
|
||||
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
|
||||
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>();
|
||||
private Dictionary<int, Solution.ReagentQuantity> _reagents =new Dictionary<int, Solution.ReagentQuantity>();
|
||||
|
||||
public MicrowaveBoundUserInterface(ClientUserInterfaceComponent owner, object uiKey) : base(owner,uiKey)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected override void Open()
|
||||
{
|
||||
base.Open();
|
||||
_menu = new MicrowaveMenu(this);
|
||||
_menu.OpenCentered();
|
||||
_menu.OnClose += Close;
|
||||
_menu.StartButton.OnPressed += args => SendMessage(new SharedMicrowaveComponent.MicrowaveStartCookMessage());
|
||||
_menu.EjectButton.OnPressed += args => SendMessage(new SharedMicrowaveComponent.MicrowaveEjectMessage());
|
||||
_menu.IngredientsList.OnItemSelected += args =>
|
||||
{
|
||||
SendMessage(new SharedMicrowaveComponent.MicrowaveEjectSolidIndexedMessage(_solids[args.ItemIndex]));
|
||||
|
||||
};
|
||||
|
||||
_menu.IngredientsListReagents.OnItemSelected += args =>
|
||||
{
|
||||
SendMessage(
|
||||
new SharedMicrowaveComponent.MicrowaveVaporizeReagentIndexedMessage(_reagents[args.ItemIndex]));
|
||||
};
|
||||
|
||||
_menu.OnCookTimeSelected += args =>
|
||||
{
|
||||
var actualButton = args.Button as Button;
|
||||
var newTime = (uint) int.Parse(actualButton.Text);
|
||||
_menu.VisualCookTime = newTime;
|
||||
SendMessage(new SharedMicrowaveComponent.MicrowaveSelectCookTimeMessage(newTime));
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
base.Dispose(disposing);
|
||||
if (!disposing)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_solids?.Clear();
|
||||
_menu?.Dispose();
|
||||
}
|
||||
|
||||
|
||||
protected override void UpdateState(BoundUserInterfaceState state)
|
||||
{
|
||||
base.UpdateState(state);
|
||||
if (!(state is MicrowaveUpdateUserInterfaceState cstate))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
RefreshContentsDisplay(cstate.ReagentsReagents, cstate.ContainedSolids);
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void RefreshContentsDisplay(IReadOnlyList<Solution.ReagentQuantity> reagents, List<EntityUid> solids)
|
||||
{
|
||||
_reagents.Clear();
|
||||
_menu.IngredientsListReagents.Clear();
|
||||
foreach (var reagent in reagents)
|
||||
{
|
||||
_prototypeManager.TryIndex(reagent.ReagentId, out ReagentPrototype proto);
|
||||
var reagentAdded = _menu.IngredientsListReagents.AddItem($"{reagent.Quantity} {proto.Name}");
|
||||
var reagentIndex = _menu.IngredientsListReagents.IndexOf(reagentAdded);
|
||||
_reagents.Add(reagentIndex, reagent);
|
||||
}
|
||||
|
||||
_solids.Clear();
|
||||
_menu.IngredientsList.Clear();
|
||||
foreach (var entityID in solids)
|
||||
{
|
||||
var entity = _entityManager.GetEntity(entityID);
|
||||
|
||||
if (entity.TryGetComponent(out IconComponent icon))
|
||||
{
|
||||
var solidItem = _menu.IngredientsList.AddItem(entity.Name, icon.Icon.Default);
|
||||
|
||||
var solidIndex = _menu.IngredientsList.IndexOf(solidItem);
|
||||
_solids.Add(solidIndex, entityID);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
206
Content.Client/GameObjects/Components/Kitchen/MicrowaveMenu.cs
Normal file
206
Content.Client/GameObjects/Components/Kitchen/MicrowaveMenu.cs
Normal file
@@ -0,0 +1,206 @@
|
||||
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;
|
||||
using Robust.Shared.Maths;
|
||||
|
||||
namespace Content.Client.GameObjects.Components.Kitchen
|
||||
{
|
||||
public class MicrowaveMenu : SS14Window
|
||||
{
|
||||
protected override Vector2? CustomSize => (512, 256);
|
||||
|
||||
private MicrowaveBoundUserInterface Owner { get; set; }
|
||||
|
||||
public event Action<BaseButton.ButtonEventArgs> OnCookTimeSelected;
|
||||
|
||||
public uint VisualCookTime = 1;
|
||||
|
||||
public Button StartButton { get;}
|
||||
public Button EjectButton { get;}
|
||||
|
||||
public PanelContainer TimerFacePlate { get; }
|
||||
|
||||
public ButtonGroup CookTimeButtonGroup { get; }
|
||||
private VBoxContainer CookTimeButtonVbox { get; }
|
||||
|
||||
public ItemList IngredientsList { get;}
|
||||
|
||||
public ItemList IngredientsListReagents { get; }
|
||||
private Label _cookTimeInfoLabel { get; }
|
||||
|
||||
public MicrowaveMenu(MicrowaveBoundUserInterface owner = null)
|
||||
{
|
||||
Owner = owner;
|
||||
Title = Loc.GetString("Microwave");
|
||||
var hSplit = new HBoxContainer
|
||||
{
|
||||
SizeFlagsHorizontal = SizeFlags.Fill,
|
||||
SizeFlagsVertical = SizeFlags.Fill
|
||||
};
|
||||
|
||||
IngredientsListReagents = new ItemList
|
||||
{
|
||||
SizeFlagsVertical = SizeFlags.FillExpand,
|
||||
SizeFlagsHorizontal = SizeFlags.FillExpand,
|
||||
SelectMode = ItemList.ItemListSelectMode.Button,
|
||||
SizeFlagsStretchRatio = 2,
|
||||
CustomMinimumSize = (100,128)
|
||||
};
|
||||
|
||||
IngredientsList = new ItemList
|
||||
{
|
||||
SizeFlagsVertical = SizeFlags.FillExpand,
|
||||
SizeFlagsHorizontal = SizeFlags.FillExpand,
|
||||
SelectMode = ItemList.ItemListSelectMode.Button,
|
||||
SizeFlagsStretchRatio = 2,
|
||||
CustomMinimumSize = (100,128)
|
||||
};
|
||||
|
||||
hSplit.AddChild(IngredientsListReagents);
|
||||
//Padding between the lists.
|
||||
hSplit.AddChild(new Control
|
||||
{
|
||||
CustomMinimumSize = (0,5),
|
||||
});
|
||||
|
||||
hSplit.AddChild(IngredientsList);
|
||||
|
||||
var vSplit = new VBoxContainer
|
||||
{
|
||||
SizeFlagsVertical = SizeFlags.FillExpand,
|
||||
SizeFlagsHorizontal = SizeFlags.FillExpand,
|
||||
};
|
||||
|
||||
hSplit.AddChild(vSplit);
|
||||
|
||||
var buttonGridContainer = new VBoxContainer
|
||||
{
|
||||
Align = BoxContainer.AlignMode.Center,
|
||||
SizeFlagsStretchRatio = 3
|
||||
};
|
||||
|
||||
StartButton = new Button
|
||||
{
|
||||
Text = Loc.GetString("Start"),
|
||||
TextAlign = Label.AlignMode.Center,
|
||||
|
||||
};
|
||||
|
||||
EjectButton = new Button
|
||||
{
|
||||
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);
|
||||
|
||||
//Padding
|
||||
vSplit.AddChild(new Control
|
||||
{
|
||||
CustomMinimumSize = (0, 15),
|
||||
SizeFlagsVertical = SizeFlags.Fill,
|
||||
});
|
||||
|
||||
CookTimeButtonGroup = new ButtonGroup();
|
||||
CookTimeButtonVbox = new VBoxContainer
|
||||
{
|
||||
SizeFlagsVertical = SizeFlags.FillExpand,
|
||||
Align = BoxContainer.AlignMode.Center,
|
||||
};
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
var cookTimeOneSecondButton = (Button)CookTimeButtonVbox.GetChild(0);
|
||||
cookTimeOneSecondButton.Pressed = true;
|
||||
|
||||
_cookTimeInfoLabel = new Label
|
||||
{
|
||||
Text = Loc.GetString($"COOK TIME: {VisualCookTime}"),
|
||||
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.WithAlpha(0.5f)},
|
||||
|
||||
Children =
|
||||
{
|
||||
|
||||
new VBoxContainer
|
||||
{
|
||||
|
||||
Children =
|
||||
{
|
||||
|
||||
new PanelContainer
|
||||
{
|
||||
PanelOverride = new StyleBoxFlat(){BackgroundColor = Color.Gray.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);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
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.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 OnChangeData(AppearanceComponent component)
|
||||
{
|
||||
base.OnChangeData(component);
|
||||
var sprite = component.Owner.GetComponent<ISpriteComponent>();
|
||||
_soundComponent ??= component.Owner.GetComponent<SoundComponent>();
|
||||
if (!component.TryGetData(PowerDeviceVisuals.VisualState, out MicrowaveVisualState state))
|
||||
{
|
||||
state = MicrowaveVisualState.Idle;
|
||||
}
|
||||
switch (state)
|
||||
{
|
||||
case MicrowaveVisualState.Idle:
|
||||
sprite.LayerSetState(MicrowaveVisualizerLayers.Base, "mw");
|
||||
sprite.LayerSetState(MicrowaveVisualizerLayers.BaseUnlit, "mw_unlit");
|
||||
_soundComponent.StopAllSounds();
|
||||
break;
|
||||
|
||||
case MicrowaveVisualState.Cooking:
|
||||
sprite.LayerSetState(MicrowaveVisualizerLayers.Base, "mw");
|
||||
sprite.LayerSetState(MicrowaveVisualizerLayers.BaseUnlit, "mw_running_unlit");
|
||||
var audioParams = AudioParams.Default;
|
||||
audioParams.Loop = true;
|
||||
var schedSound = new ScheduledSound();
|
||||
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);
|
||||
sprite.LayerSetVisible(MicrowaveVisualizerLayers.BaseUnlit, glowingPartsVisible);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
private enum MicrowaveVisualizerLayers
|
||||
{
|
||||
Base,
|
||||
BaseUnlit
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Content.Shared.GameObjects.Components.Sound;
|
||||
using Microsoft.DiaSymReader;
|
||||
using Robust.Client.GameObjects.EntitySystems;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
@@ -15,7 +17,7 @@ namespace Content.Client.GameObjects.Components.Sound
|
||||
[RegisterComponent]
|
||||
public class SoundComponent : SharedSoundComponent
|
||||
{
|
||||
private readonly List<ScheduledSound> _schedules = new List<ScheduledSound>();
|
||||
private readonly Dictionary<ScheduledSound, IPlayingAudioStream> _audioStreams = new Dictionary<ScheduledSound, IPlayingAudioStream>();
|
||||
private AudioSystem _audioSystem;
|
||||
#pragma warning disable 649
|
||||
[Dependency] private readonly IRobustRandom _random;
|
||||
@@ -23,26 +25,27 @@ namespace Content.Client.GameObjects.Components.Sound
|
||||
|
||||
public override void StopAllSounds()
|
||||
{
|
||||
foreach (var schedule in _schedules)
|
||||
foreach (var kvp in _audioStreams)
|
||||
{
|
||||
schedule.Play = false;
|
||||
kvp.Key.Play = false;
|
||||
kvp.Value.Stop();
|
||||
}
|
||||
_schedules.Clear();
|
||||
_audioStreams.Clear();
|
||||
}
|
||||
|
||||
public override void StopScheduledSound(string filename)
|
||||
{
|
||||
foreach (var schedule in _schedules.ToArray())
|
||||
foreach (var kvp in _audioStreams)
|
||||
{
|
||||
if (schedule.Filename != filename) continue;
|
||||
schedule.Play = false;
|
||||
_schedules.Remove(schedule);
|
||||
if (kvp.Key.Filename != filename) continue;
|
||||
kvp.Key.Play = false;
|
||||
kvp.Value.Stop();
|
||||
_audioStreams.Remove(kvp.Key);
|
||||
}
|
||||
}
|
||||
|
||||
public override void AddScheduledSound(ScheduledSound schedule)
|
||||
{
|
||||
_schedules.Add(schedule);
|
||||
Play(schedule);
|
||||
}
|
||||
|
||||
@@ -54,16 +57,11 @@ namespace Content.Client.GameObjects.Components.Sound
|
||||
{
|
||||
if (!schedule.Play) return; // We make sure this hasn't changed.
|
||||
if (_audioSystem == null) _audioSystem = IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<AudioSystem>();
|
||||
_audioSystem.Play(schedule.Filename, Owner, schedule.AudioParams);
|
||||
_audioStreams.Add(schedule,_audioSystem.Play(schedule.Filename, Owner, schedule.AudioParams));
|
||||
|
||||
if (schedule.Times == 0)
|
||||
{
|
||||
_schedules.Remove(schedule);
|
||||
return;
|
||||
}
|
||||
if (schedule.Times == 0) return;
|
||||
|
||||
if (schedule.Times > 0)
|
||||
schedule.Times--;
|
||||
if (schedule.Times > 0) schedule.Times--;
|
||||
|
||||
Play(schedule);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user