2023-09-05 09:55:10 +12:00
|
|
|
using Content.Shared.Chemistry.Reagent;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Shared.Kitchen.Components;
|
2020-12-08 11:56:10 +01:00
|
|
|
using JetBrains.Annotations;
|
2020-05-03 03:09:54 -05:00
|
|
|
using Robust.Client.GameObjects;
|
2020-09-28 20:53:47 +02:00
|
|
|
using Robust.Client.Graphics;
|
2020-05-03 23:58:29 -05:00
|
|
|
using Robust.Client.UserInterface.Controls;
|
2024-02-14 06:16:00 +08:00
|
|
|
using Robust.Shared.Timing;
|
2020-05-01 17:19:04 -05:00
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
namespace Content.Client.Kitchen.UI
|
2020-05-01 17:19:04 -05:00
|
|
|
{
|
2020-12-08 11:56:10 +01:00
|
|
|
[UsedImplicitly]
|
2022-02-16 00:23:23 -07:00
|
|
|
public sealed class MicrowaveBoundUserInterface : BoundUserInterface
|
2020-05-01 17:19:04 -05:00
|
|
|
{
|
2023-07-08 09:02:17 -07:00
|
|
|
[ViewVariables]
|
2021-03-10 14:48:29 +01:00
|
|
|
private MicrowaveMenu? _menu;
|
2020-05-01 17:19:04 -05:00
|
|
|
|
2023-07-08 09:02:17 -07:00
|
|
|
[ViewVariables]
|
2020-11-27 11:00:49 +01:00
|
|
|
private readonly Dictionary<int, EntityUid> _solids = new();
|
2020-05-03 03:09:54 -05:00
|
|
|
|
2023-07-08 09:02:17 -07:00
|
|
|
[ViewVariables]
|
2023-09-05 09:55:10 +12:00
|
|
|
private readonly Dictionary<int, ReagentQuantity> _reagents = new();
|
2024-02-14 06:16:00 +08:00
|
|
|
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
|
|
|
|
|
|
|
|
|
public MicrowaveUpdateUserInterfaceState currentState = default!;
|
2023-07-08 09:02:17 -07:00
|
|
|
|
2023-09-11 09:42:41 +10:00
|
|
|
private IEntityManager _entManager;
|
|
|
|
|
|
2023-07-08 09:02:17 -07:00
|
|
|
public MicrowaveBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
|
2020-05-01 17:19:04 -05:00
|
|
|
{
|
2023-09-11 09:42:41 +10:00
|
|
|
_entManager = IoCManager.Resolve<IEntityManager>();
|
2020-05-01 17:19:04 -05:00
|
|
|
}
|
2020-05-01 23:34:04 -05:00
|
|
|
|
2024-02-14 06:16:00 +08:00
|
|
|
public TimeSpan GetCurrentTime()
|
|
|
|
|
{
|
|
|
|
|
return _gameTiming.CurTime;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-01 23:34:04 -05:00
|
|
|
protected override void Open()
|
|
|
|
|
{
|
|
|
|
|
base.Open();
|
|
|
|
|
_menu = new MicrowaveMenu(this);
|
|
|
|
|
_menu.OpenCentered();
|
|
|
|
|
_menu.OnClose += Close;
|
2024-02-14 06:16:00 +08:00
|
|
|
_menu.StartButton.OnPressed += _ => SendPredictedMessage(new MicrowaveStartCookMessage());
|
|
|
|
|
_menu.EjectButton.OnPressed += _ => SendPredictedMessage(new MicrowaveEjectMessage());
|
2020-05-04 15:16:16 -05:00
|
|
|
_menu.IngredientsList.OnItemSelected += args =>
|
2020-05-06 17:45:45 -05:00
|
|
|
{
|
2024-02-14 06:16:00 +08:00
|
|
|
SendPredictedMessage(new MicrowaveEjectSolidIndexedMessage(EntMan.GetNetEntity(_solids[args.ItemIndex])));
|
2020-05-04 15:16:16 -05:00
|
|
|
};
|
|
|
|
|
|
2023-07-08 09:02:17 -07:00
|
|
|
_menu.OnCookTimeSelected += (args, buttonIndex) =>
|
2020-05-03 23:58:29 -05:00
|
|
|
{
|
2024-02-14 06:16:00 +08:00
|
|
|
var selectedCookTime = (uint) 0;
|
|
|
|
|
|
|
|
|
|
if (args.Button is MicrowaveMenu.MicrowaveCookTimeButton microwaveCookTimeButton)
|
|
|
|
|
{
|
|
|
|
|
// args.Button is a MicrowaveCookTimeButton
|
|
|
|
|
var actualButton = (MicrowaveMenu.MicrowaveCookTimeButton) args.Button;
|
|
|
|
|
selectedCookTime = actualButton.CookTime == 0 ? 0 : actualButton.CookTime;
|
|
|
|
|
// SendMessage(new MicrowaveSelectCookTimeMessage((int) selectedCookTime / 5, actualButton.CookTime));
|
|
|
|
|
SendPredictedMessage(new MicrowaveSelectCookTimeMessage((int) selectedCookTime / 5, actualButton.CookTime));
|
|
|
|
|
|
|
|
|
|
_menu.CookTimeInfoLabel.Text = Loc.GetString("microwave-bound-user-interface-cook-time-label",
|
|
|
|
|
("time", selectedCookTime));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// args.Button is a normal button aka instant cook button
|
|
|
|
|
SendPredictedMessage(new MicrowaveSelectCookTimeMessage((int) selectedCookTime, 0));
|
|
|
|
|
|
|
|
|
|
_menu.CookTimeInfoLabel.Text = Loc.GetString("microwave-bound-user-interface-cook-time-label",
|
|
|
|
|
("time", Loc.GetString("microwave-menu-instant-button")));
|
|
|
|
|
}
|
2020-05-03 23:58:29 -05:00
|
|
|
};
|
2020-05-01 23:34:04 -05:00
|
|
|
}
|
|
|
|
|
|
2020-05-03 03:09:54 -05:00
|
|
|
protected override void Dispose(bool disposing)
|
|
|
|
|
{
|
|
|
|
|
base.Dispose(disposing);
|
2021-03-10 14:48:29 +01:00
|
|
|
|
2020-05-03 03:09:54 -05:00
|
|
|
if (!disposing)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2021-03-10 14:48:29 +01:00
|
|
|
|
|
|
|
|
_solids.Clear();
|
2020-05-03 03:09:54 -05:00
|
|
|
_menu?.Dispose();
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-01 23:34:04 -05:00
|
|
|
protected override void UpdateState(BoundUserInterfaceState state)
|
|
|
|
|
{
|
|
|
|
|
base.UpdateState(state);
|
2020-11-26 14:33:31 +01:00
|
|
|
if (state is not MicrowaveUpdateUserInterfaceState cState)
|
2020-05-03 03:09:54 -05:00
|
|
|
{
|
2020-05-01 23:34:04 -05:00
|
|
|
return;
|
2020-05-03 03:09:54 -05:00
|
|
|
}
|
2021-03-10 14:48:29 +01:00
|
|
|
|
2024-02-14 06:16:00 +08:00
|
|
|
|
|
|
|
|
_menu?.ToggleBusyDisableOverlayPanel(cState.IsMicrowaveBusy || cState.ContainedSolids.Length == 0);
|
|
|
|
|
currentState = cState;
|
2023-09-11 09:42:41 +10:00
|
|
|
|
|
|
|
|
// TODO move this to a component state and ensure the net ids.
|
|
|
|
|
RefreshContentsDisplay(_entManager.GetEntityArray(cState.ContainedSolids));
|
2021-03-10 14:48:29 +01:00
|
|
|
|
2021-10-27 23:59:53 +02:00
|
|
|
if (_menu == null) return;
|
|
|
|
|
|
2024-02-14 06:16:00 +08:00
|
|
|
//Set the cook time info label
|
|
|
|
|
var cookTime = cState.ActiveButtonIndex == 0
|
2021-10-27 23:59:53 +02:00
|
|
|
? Loc.GetString("microwave-menu-instant-button")
|
|
|
|
|
: cState.CurrentCookTime.ToString();
|
2024-02-14 06:16:00 +08:00
|
|
|
|
|
|
|
|
|
2021-10-27 23:59:53 +02:00
|
|
|
_menu.CookTimeInfoLabel.Text = Loc.GetString("microwave-bound-user-interface-cook-time-label",
|
|
|
|
|
("time", cookTime));
|
2024-02-14 06:16:00 +08:00
|
|
|
_menu.StartButton.Disabled = cState.IsMicrowaveBusy || cState.ContainedSolids.Length == 0;
|
|
|
|
|
_menu.EjectButton.Disabled = cState.IsMicrowaveBusy || cState.ContainedSolids.Length == 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Set the correct button active button
|
|
|
|
|
if (cState.ActiveButtonIndex == 0)
|
|
|
|
|
{
|
|
|
|
|
_menu.InstantCookButton.Pressed = true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var currentlySelectedTimeButton = (Button) _menu.CookTimeButtonVbox.GetChild(cState.ActiveButtonIndex - 1);
|
|
|
|
|
currentlySelectedTimeButton.Pressed = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Set the "micowave light" ui color to indicate if the microwave is busy or not
|
|
|
|
|
if (cState.IsMicrowaveBusy && cState.ContainedSolids.Length > 0)
|
|
|
|
|
{
|
|
|
|
|
_menu.IngredientsPanel.PanelOverride = new StyleBoxFlat { BackgroundColor = Color.FromHex("#947300") };
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_menu.IngredientsPanel.PanelOverride = new StyleBoxFlat { BackgroundColor = Color.FromHex("#1B1B1E") };
|
|
|
|
|
}
|
2020-05-01 23:34:04 -05:00
|
|
|
}
|
|
|
|
|
|
2022-02-12 17:53:54 -07:00
|
|
|
private void RefreshContentsDisplay(EntityUid[] containedSolids)
|
2020-05-03 01:34:00 -05:00
|
|
|
{
|
2020-05-04 15:16:16 -05:00
|
|
|
_reagents.Clear();
|
2021-03-10 14:48:29 +01:00
|
|
|
|
|
|
|
|
if (_menu == null) return;
|
|
|
|
|
|
2020-05-03 03:09:54 -05:00
|
|
|
_solids.Clear();
|
2020-05-04 15:16:16 -05:00
|
|
|
_menu.IngredientsList.Clear();
|
2021-12-05 18:09:01 +01:00
|
|
|
foreach (var entity in containedSolids)
|
2020-05-03 03:09:54 -05:00
|
|
|
{
|
2023-07-08 09:02:17 -07:00
|
|
|
if (EntMan.Deleted(entity))
|
2020-05-06 17:45:45 -05:00
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2021-03-10 14:48:29 +01:00
|
|
|
|
2023-05-19 19:13:10 +12:00
|
|
|
// TODO just use sprite view
|
|
|
|
|
|
2021-03-10 14:48:29 +01:00
|
|
|
Texture? texture;
|
2023-07-08 09:02:17 -07:00
|
|
|
if (EntMan.TryGetComponent<IconComponent>(entity, out var iconComponent))
|
2020-09-28 20:53:47 +02:00
|
|
|
{
|
2023-07-08 09:02:17 -07:00
|
|
|
texture = EntMan.System<SpriteSystem>().GetIcon(iconComponent);
|
2021-03-10 14:48:29 +01:00
|
|
|
}
|
2023-07-08 09:02:17 -07:00
|
|
|
else if (EntMan.TryGetComponent<SpriteComponent>(entity, out var spriteComponent))
|
2020-09-28 20:53:47 +02:00
|
|
|
{
|
|
|
|
|
texture = spriteComponent.Icon?.Default;
|
2021-03-10 14:48:29 +01:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2020-09-28 20:53:47 +02:00
|
|
|
|
2023-07-08 09:02:17 -07:00
|
|
|
var solidItem = _menu.IngredientsList.AddItem(EntMan.GetComponent<MetaDataComponent>(entity).EntityName, texture);
|
2020-05-28 15:28:35 -05:00
|
|
|
var solidIndex = _menu.IngredientsList.IndexOf(solidItem);
|
2021-12-05 18:09:01 +01:00
|
|
|
_solids.Add(solidIndex, entity);
|
2020-05-28 15:28:35 -05:00
|
|
|
}
|
2020-05-03 01:34:00 -05:00
|
|
|
}
|
2020-05-01 17:19:04 -05:00
|
|
|
}
|
|
|
|
|
}
|