Next up timer buttons
This commit is contained in:
@@ -1,6 +1,14 @@
|
|||||||
using Robust.Client.GameObjects.Components.UserInterface;
|
using Robust.Client.GameObjects.Components.UserInterface;
|
||||||
using Content.Shared.Kitchen;
|
using Content.Shared.Kitchen;
|
||||||
using Robust.Shared.GameObjects.Components.UserInterface;
|
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
|
namespace Content.Client.GameObjects.Components.Kitchen
|
||||||
{
|
{
|
||||||
@@ -8,6 +16,8 @@ namespace Content.Client.GameObjects.Components.Kitchen
|
|||||||
{
|
{
|
||||||
private MicrowaveMenu _menu;
|
private MicrowaveMenu _menu;
|
||||||
|
|
||||||
|
private Dictionary<int, EntityUid> _solids = new Dictionary<int, EntityUid>();
|
||||||
|
|
||||||
public MicrowaveBoundUserInterface(ClientUserInterfaceComponent owner, object uiKey) : base(owner,uiKey)
|
public MicrowaveBoundUserInterface(ClientUserInterfaceComponent owner, object uiKey) : base(owner,uiKey)
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -17,32 +27,70 @@ namespace Content.Client.GameObjects.Components.Kitchen
|
|||||||
{
|
{
|
||||||
base.Open();
|
base.Open();
|
||||||
_menu = new MicrowaveMenu(this);
|
_menu = new MicrowaveMenu(this);
|
||||||
|
|
||||||
_menu.OpenCentered();
|
_menu.OpenCentered();
|
||||||
_menu.OnClose += Close;
|
_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)
|
protected override void UpdateState(BoundUserInterfaceState state)
|
||||||
{
|
{
|
||||||
base.UpdateState(state);
|
base.UpdateState(state);
|
||||||
if (!(state is MicrowaveUpdateUserInterfaceState cstate))
|
if (!(state is MicrowaveUpdateUserInterfaceState cstate))
|
||||||
|
{
|
||||||
return;
|
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)
|
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 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)
|
public MicrowaveMenu(MicrowaveBoundUserInterface owner = null)
|
||||||
{
|
{
|
||||||
Owner = owner;
|
Owner = owner;
|
||||||
_heldReagents = new List<Solution.ReagentQuantity>();
|
|
||||||
Title = Loc.GetString("Microwave");
|
Title = Loc.GetString("Microwave");
|
||||||
var vbox = new VBoxContainer()
|
var hSplit = new HSplitContainer
|
||||||
{
|
{
|
||||||
|
SizeFlagsHorizontal = SizeFlags.Fill,
|
||||||
SizeFlagsVertical = SizeFlags.Fill
|
SizeFlagsVertical = SizeFlags.Fill
|
||||||
};
|
};
|
||||||
|
|
||||||
var startButton = new Button()
|
|
||||||
|
IngredientsList = new ItemList
|
||||||
{
|
{
|
||||||
Label = { Text = Loc.GetString("START"), FontColorOverride = Color.Green}
|
SizeFlagsVertical = SizeFlags.Expand,
|
||||||
};
|
SelectMode = ItemList.ItemListSelectMode.Button,
|
||||||
var ejectButton = new Button()
|
SizeFlagsStretchRatio = 8,
|
||||||
{
|
CustomMinimumSize = (100,100)
|
||||||
Label = { Text = Loc.GetString("EJECT REAGENTS"),FontColorOverride = Color.Red}
|
|
||||||
};
|
|
||||||
var scrollContainer = new ScrollContainer()
|
|
||||||
{
|
|
||||||
SizeFlagsVertical = SizeFlags.FillExpand
|
|
||||||
};
|
};
|
||||||
|
|
||||||
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);
|
vSplit.AddChild(TimerButtons);
|
||||||
vbox.AddChild(startButton);
|
|
||||||
vbox.AddChild(ejectButton);
|
|
||||||
vbox.AddChild(scrollContainer);
|
Contents.AddChild(hSplit);
|
||||||
Contents.AddChild(vbox);
|
|
||||||
startButton.OnPressed += args => Owner.Cook();
|
|
||||||
ejectButton.OnPressed += args => Owner.Eject();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
protected override void Dispose(bool disposing)
|
||||||
{
|
{
|
||||||
base.Dispose(disposing);
|
base.Dispose(disposing);
|
||||||
InnerScrollContainer.Dispose();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ namespace Content.Server.GameObjects.Components.Kitchen
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case MicrowaveEjectSolidIndexedMessage msg:
|
case MicrowaveEjectSolidIndexedMessage msg:
|
||||||
EjectIndexedSolid(msg.index);
|
EjectIndexedSolid(msg.EntityID);
|
||||||
UpdateUserInterface();
|
UpdateUserInterface();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -272,10 +272,9 @@ namespace Content.Server.GameObjects.Components.Kitchen
|
|||||||
_solids.Clear();
|
_solids.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void EjectIndexedSolid(int index)
|
private void EjectIndexedSolid(EntityUid entityID)
|
||||||
{
|
{
|
||||||
var entityToRemove = _storage.ContainedEntities.ToArray()[index];
|
_storage.Remove(_entityManager.GetEntity(entityID));
|
||||||
_storage.Remove(entityToRemove);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -38,10 +38,10 @@ namespace Content.Shared.Kitchen
|
|||||||
public class MicrowaveEjectSolidIndexedMessage : BoundUserInterfaceMessage
|
public class MicrowaveEjectSolidIndexedMessage : BoundUserInterfaceMessage
|
||||||
{
|
{
|
||||||
|
|
||||||
public int index;
|
public EntityUid EntityID;
|
||||||
public MicrowaveEjectSolidIndexedMessage(int i)
|
public MicrowaveEjectSolidIndexedMessage(EntityUid entityID)
|
||||||
{
|
{
|
||||||
index = i;
|
EntityID = entityID;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user