Next up timer buttons
This commit is contained in:
@@ -1,6 +1,14 @@
|
||||
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.UserInterface.Controls;
|
||||
using Robust.Client.GameObjects;
|
||||
|
||||
namespace Content.Client.GameObjects.Components.Kitchen
|
||||
{
|
||||
@@ -8,6 +16,8 @@ namespace Content.Client.GameObjects.Components.Kitchen
|
||||
{
|
||||
private MicrowaveMenu _menu;
|
||||
|
||||
private Dictionary<int, EntityUid> _solids = new Dictionary<int, EntityUid>();
|
||||
|
||||
public MicrowaveBoundUserInterface(ClientUserInterfaceComponent owner, object uiKey) : base(owner,uiKey)
|
||||
{
|
||||
|
||||
@@ -17,32 +27,70 @@ namespace Content.Client.GameObjects.Components.Kitchen
|
||||
{
|
||||
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 => EjectSolidWithIndex(args.ItemIndex);
|
||||
}
|
||||
|
||||
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;
|
||||
_menu.RefreshContentsDisplay(cstate.ReagentsReagents, cstate.ContainedSolids);
|
||||
}
|
||||
|
||||
RefreshContentsDisplay(cstate.ReagentsReagents, cstate.ContainedSolids);
|
||||
|
||||
}
|
||||
|
||||
public void Cook()
|
||||
{
|
||||
SendMessage(new SharedMicrowaveComponent.MicrowaveStartCookMessage());
|
||||
}
|
||||
|
||||
public void Eject()
|
||||
{
|
||||
SendMessage(new SharedMicrowaveComponent.MicrowaveEjectMessage());
|
||||
}
|
||||
|
||||
public void EjectSolidWithIndex(int index)
|
||||
{
|
||||
SendMessage(new SharedMicrowaveComponent.MicrowaveEjectSolidIndexedMessage(index));
|
||||
SendMessage(new SharedMicrowaveComponent.MicrowaveEjectSolidIndexedMessage(_solids[index]));
|
||||
}
|
||||
|
||||
public void RefreshContentsDisplay(List<Solution.ReagentQuantity> reagents, List<EntityUid> solids)
|
||||
{
|
||||
_menu.IngredientsList.Clear();
|
||||
foreach (var item in reagents)
|
||||
{
|
||||
IoCManager.Resolve<IPrototypeManager>().TryIndex(item.ReagentId, out ReagentPrototype proto);
|
||||
|
||||
_menu.IngredientsList.AddItem($"{item.Quantity} {proto.Name}");
|
||||
}
|
||||
|
||||
_solids.Clear();
|
||||
foreach (var entityID in solids)
|
||||
{
|
||||
var entity = IoCManager.Resolve<IEntityManager>().GetEntity(entityID);
|
||||
|
||||
if (entity.TryGetComponent(out IconComponent icon))
|
||||
{
|
||||
var itemItem = _menu.IngredientsList.AddItem(entity.Name, icon.Icon.Default);
|
||||
|
||||
var index = _menu.IngredientsList.IndexOf(itemItem);
|
||||
_solids.Add(index, entityID);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,79 +17,73 @@ namespace Content.Client.GameObjects.Components.Kitchen
|
||||
|
||||
private MicrowaveBoundUserInterface Owner { get; set; }
|
||||
|
||||
private List<Solution.ReagentQuantity> _heldReagents;
|
||||
public Button StartButton { get;}
|
||||
public Button EjectButton { get;}
|
||||
|
||||
private VBoxContainer InnerScrollContainer { get; set; }
|
||||
public GridContainer TimerButtons { get; }
|
||||
|
||||
public ItemList IngredientsList { get;}
|
||||
|
||||
public MicrowaveMenu(MicrowaveBoundUserInterface owner = null)
|
||||
{
|
||||
Owner = owner;
|
||||
_heldReagents = new List<Solution.ReagentQuantity>();
|
||||
Title = Loc.GetString("Microwave");
|
||||
var vbox = new VBoxContainer()
|
||||
var hSplit = new HSplitContainer
|
||||
{
|
||||
SizeFlagsHorizontal = SizeFlags.Fill,
|
||||
SizeFlagsVertical = SizeFlags.Fill
|
||||
};
|
||||
|
||||
var startButton = new Button()
|
||||
|
||||
IngredientsList = new ItemList
|
||||
{
|
||||
Label = { Text = Loc.GetString("START"), FontColorOverride = Color.Green}
|
||||
};
|
||||
var ejectButton = new Button()
|
||||
{
|
||||
Label = { Text = Loc.GetString("EJECT REAGENTS"),FontColorOverride = Color.Red}
|
||||
};
|
||||
var scrollContainer = new ScrollContainer()
|
||||
{
|
||||
SizeFlagsVertical = SizeFlags.FillExpand
|
||||
SizeFlagsVertical = SizeFlags.Expand,
|
||||
SelectMode = ItemList.ItemListSelectMode.Button,
|
||||
SizeFlagsStretchRatio = 8,
|
||||
CustomMinimumSize = (100,100)
|
||||
};
|
||||
|
||||
InnerScrollContainer = new VBoxContainer()
|
||||
hSplit.AddChild(IngredientsList);
|
||||
|
||||
var vSplit = new VSplitContainer();
|
||||
hSplit.AddChild(vSplit);
|
||||
|
||||
var buttonGridContainer = new GridContainer
|
||||
{
|
||||
SizeFlagsVertical = SizeFlags.FillExpand
|
||||
Columns = 2,
|
||||
};
|
||||
StartButton = new Button
|
||||
{
|
||||
Text = Loc.GetString("START"),
|
||||
};
|
||||
EjectButton = new Button
|
||||
{
|
||||
Text = Loc.GetString("EJECT CONTENTS"),
|
||||
};
|
||||
buttonGridContainer.AddChild(StartButton);
|
||||
buttonGridContainer.AddChild(EjectButton);
|
||||
vSplit.AddChild(buttonGridContainer);
|
||||
|
||||
|
||||
TimerButtons = new GridContainer
|
||||
{
|
||||
Columns = 5,
|
||||
|
||||
};
|
||||
|
||||
scrollContainer.AddChild(InnerScrollContainer);
|
||||
vbox.AddChild(startButton);
|
||||
vbox.AddChild(ejectButton);
|
||||
vbox.AddChild(scrollContainer);
|
||||
Contents.AddChild(vbox);
|
||||
startButton.OnPressed += args => Owner.Cook();
|
||||
ejectButton.OnPressed += args => Owner.Eject();
|
||||
vSplit.AddChild(TimerButtons);
|
||||
|
||||
|
||||
Contents.AddChild(hSplit);
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void RefreshContentsDisplay(List<Solution.ReagentQuantity> reagents, List<EntityUid> solids)
|
||||
{
|
||||
InnerScrollContainer.RemoveAllChildren();
|
||||
foreach (var item in reagents)
|
||||
{
|
||||
IoCManager.Resolve<IPrototypeManager>().TryIndex(item.ReagentId, out ReagentPrototype proto);
|
||||
|
||||
InnerScrollContainer.AddChild(new Label()
|
||||
{
|
||||
Text = $"{item.Quantity} {proto.Name}"
|
||||
});
|
||||
}
|
||||
|
||||
foreach (var item in solids)
|
||||
{
|
||||
var name = IoCManager.Resolve<IEntityManager>().GetEntity(item).Prototype.Name;
|
||||
var solidButton = new Button()
|
||||
{
|
||||
Text = $"{name}"
|
||||
};
|
||||
|
||||
solidButton.OnPressed += args => Owner.EjectSolidWithIndex(solids.IndexOf(item));
|
||||
InnerScrollContainer.AddChild(solidButton);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
base.Dispose(disposing);
|
||||
InnerScrollContainer.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user