2020-05-03 03:09:54 -05:00
|
|
|
using System.Collections.Generic;
|
2021-09-06 15:49:44 +02:00
|
|
|
using Content.Shared.Chemistry.Components;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Shared.Chemistry.Reagent;
|
|
|
|
|
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;
|
2020-08-13 14:40:27 +02:00
|
|
|
using Robust.Shared.GameObjects;
|
|
|
|
|
using Robust.Shared.IoC;
|
2020-05-28 15:28:35 -05:00
|
|
|
using Robust.Shared.Localization;
|
2020-08-13 14:40:27 +02:00
|
|
|
using Robust.Shared.Prototypes;
|
2021-10-27 23:59:53 +02:00
|
|
|
using static Content.Shared.Kitchen.Components.SharedMicrowaveComponent;
|
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
|
|
|
{
|
2020-08-24 14:10:28 +02:00
|
|
|
[Dependency] private readonly IEntityManager _entityManager = default!;
|
|
|
|
|
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
|
|
|
|
|
2021-03-10 14:48:29 +01:00
|
|
|
private MicrowaveMenu? _menu;
|
2020-05-01 17:19:04 -05:00
|
|
|
|
2020-11-27 11:00:49 +01:00
|
|
|
private readonly Dictionary<int, EntityUid> _solids = new();
|
|
|
|
|
private readonly Dictionary<int, Solution.ReagentQuantity> _reagents =new();
|
2020-05-03 03:09:54 -05:00
|
|
|
|
2020-05-01 17:19:04 -05:00
|
|
|
public MicrowaveBoundUserInterface(ClientUserInterfaceComponent owner, object uiKey) : base(owner,uiKey)
|
|
|
|
|
{
|
|
|
|
|
}
|
2020-05-01 23:34:04 -05:00
|
|
|
|
|
|
|
|
protected override void Open()
|
|
|
|
|
{
|
|
|
|
|
base.Open();
|
|
|
|
|
_menu = new MicrowaveMenu(this);
|
|
|
|
|
_menu.OpenCentered();
|
|
|
|
|
_menu.OnClose += Close;
|
2021-10-27 23:59:53 +02:00
|
|
|
_menu.StartButton.OnPressed += _ => SendMessage(new MicrowaveStartCookMessage());
|
|
|
|
|
_menu.EjectButton.OnPressed += _ => SendMessage(new MicrowaveEjectMessage());
|
2020-05-04 15:16:16 -05:00
|
|
|
_menu.IngredientsList.OnItemSelected += args =>
|
2020-05-06 17:45:45 -05:00
|
|
|
{
|
2021-10-27 23:59:53 +02:00
|
|
|
SendMessage(new MicrowaveEjectSolidIndexedMessage(_solids[args.ItemIndex]));
|
2020-05-04 15:16:16 -05:00
|
|
|
};
|
|
|
|
|
|
2020-05-28 15:28:35 -05:00
|
|
|
_menu.OnCookTimeSelected += (args,buttonIndex) =>
|
2020-05-03 23:58:29 -05:00
|
|
|
{
|
2020-05-28 15:28:35 -05:00
|
|
|
var actualButton = (MicrowaveMenu.MicrowaveCookTimeButton) args.Button ;
|
2021-10-27 23:59:53 +02:00
|
|
|
SendMessage(new MicrowaveSelectCookTimeMessage(buttonIndex,actualButton.CookTime));
|
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
|
|
|
|
|
|
|
|
_menu?.ToggleBusyDisableOverlayPanel(cState.IsMicrowaveBusy);
|
2022-02-12 17:53:54 -07:00
|
|
|
RefreshContentsDisplay(cState.ContainedSolids);
|
2021-03-10 14:48:29 +01:00
|
|
|
|
2021-10-27 23:59:53 +02:00
|
|
|
if (_menu == null) return;
|
|
|
|
|
|
|
|
|
|
var currentlySelectedTimeButton = (Button) _menu.CookTimeButtonVbox.GetChild(cState.ActiveButtonIndex);
|
|
|
|
|
currentlySelectedTimeButton.Pressed = true;
|
|
|
|
|
var cookTime = cState.ActiveButtonIndex == 0
|
|
|
|
|
? Loc.GetString("microwave-menu-instant-button")
|
|
|
|
|
: cState.CurrentCookTime.ToString();
|
|
|
|
|
_menu.CookTimeInfoLabel.Text = Loc.GetString("microwave-bound-user-interface-cook-time-label",
|
|
|
|
|
("time", cookTime));
|
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
|
|
|
{
|
2021-12-09 12:29:27 +01:00
|
|
|
if (_entityManager.Deleted(entity))
|
2020-05-06 17:45:45 -05:00
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2021-03-10 14:48:29 +01:00
|
|
|
|
|
|
|
|
Texture? texture;
|
2021-12-05 18:09:01 +01:00
|
|
|
if (_entityManager.TryGetComponent(entity, out IconComponent? iconComponent))
|
2020-09-28 20:53:47 +02:00
|
|
|
{
|
|
|
|
|
texture = iconComponent.Icon?.Default;
|
2021-03-10 14:48:29 +01:00
|
|
|
}
|
2021-12-05 18:09:01 +01:00
|
|
|
else if (_entityManager.TryGetComponent(entity, out SpriteComponent? 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
|
|
|
|
2021-12-05 18:09:01 +01:00
|
|
|
var solidItem = _menu.IngredientsList.AddItem(_entityManager.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
|
|
|
}
|
|
|
|
|
}
|