Sweeping changes/improvements to the microwave. (#997)
Co-authored-by: FL-OZ <anotherscuffed@gmail.com> Co-authored-by: Pieter-Jan Briers <pieterjan.briers+git@gmail.com>
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using Robust.Client.GameObjects.Components.UserInterface;
|
||||
using System;
|
||||
using Robust.Client.GameObjects.Components.UserInterface;
|
||||
using Content.Shared.Kitchen;
|
||||
using Robust.Shared.GameObjects.Components.UserInterface;
|
||||
using Robust.Shared.IoC;
|
||||
@@ -7,10 +8,14 @@ using Content.Shared.Chemistry;
|
||||
using Robust.Shared.GameObjects;
|
||||
using System.Collections.Generic;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
|
||||
|
||||
using Robust.Client.GameObjects;
|
||||
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
|
||||
{
|
||||
@@ -50,12 +55,11 @@ namespace Content.Client.GameObjects.Components.Kitchen
|
||||
new SharedMicrowaveComponent.MicrowaveVaporizeReagentIndexedMessage(_reagents[args.ItemIndex]));
|
||||
};
|
||||
|
||||
_menu.OnCookTimeSelected += args =>
|
||||
_menu.OnCookTimeSelected += (args,buttonIndex) =>
|
||||
{
|
||||
var actualButton = args.Button as Button;
|
||||
var newTime = (uint) int.Parse(actualButton.Text);
|
||||
_menu.VisualCookTime = newTime;
|
||||
SendMessage(new SharedMicrowaveComponent.MicrowaveSelectCookTimeMessage(newTime));
|
||||
var actualButton = (MicrowaveMenu.MicrowaveCookTimeButton) args.Button ;
|
||||
var newTime = actualButton.CookTime;
|
||||
SendMessage(new SharedMicrowaveComponent.MicrowaveSelectCookTimeMessage(buttonIndex,actualButton.CookTime));
|
||||
};
|
||||
|
||||
}
|
||||
@@ -79,45 +83,259 @@ namespace Content.Client.GameObjects.Components.Kitchen
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_menu.ToggleBusyDisableOverlayPanel(cstate.IsMicrowaveBusy);
|
||||
RefreshContentsDisplay(cstate.ReagentsReagents, cstate.ContainedSolids);
|
||||
|
||||
RefreshContentsDisplay(cstate.ReagentQuantities, cstate.ContainedSolids);
|
||||
var currentlySelectedTimeButton = (Button) _menu.CookTimeButtonVbox.GetChild(cstate.ActiveButtonIndex);
|
||||
currentlySelectedTimeButton.Pressed = true;
|
||||
var label = cstate.ActiveButtonIndex <= 0 ? Loc.GetString("INSTANT") : cstate.CurrentCookTime.ToString();
|
||||
_menu._cookTimeInfoLabel.Text = $"{Loc.GetString("COOK TIME")}: {label}";
|
||||
}
|
||||
|
||||
|
||||
private void RefreshContentsDisplay(IReadOnlyList<Solution.ReagentQuantity> reagents, List<EntityUid> solids)
|
||||
private void RefreshContentsDisplay(Solution.ReagentQuantity[] reagents, EntityUid[] containedSolids)
|
||||
{
|
||||
_reagents.Clear();
|
||||
_menu.IngredientsListReagents.Clear();
|
||||
foreach (var reagent in reagents)
|
||||
for (var i = 0; i < reagents.Length; i++)
|
||||
{
|
||||
_prototypeManager.TryIndex(reagent.ReagentId, out ReagentPrototype proto);
|
||||
var reagentAdded = _menu.IngredientsListReagents.AddItem($"{reagent.Quantity} {proto.Name}");
|
||||
_prototypeManager.TryIndex(reagents[i].ReagentId, out ReagentPrototype proto);
|
||||
var reagentAdded = _menu.IngredientsListReagents.AddItem($"{reagents[i].Quantity} {proto.Name}");
|
||||
var reagentIndex = _menu.IngredientsListReagents.IndexOf(reagentAdded);
|
||||
_reagents.Add(reagentIndex, reagent);
|
||||
_reagents.Add(reagentIndex, reagents[i]);
|
||||
}
|
||||
|
||||
_solids.Clear();
|
||||
_menu.IngredientsList.Clear();
|
||||
foreach (var entityID in solids)
|
||||
for (var j = 0; j < containedSolids.Length; j++)
|
||||
{
|
||||
if (!_entityManager.TryGetEntity(entityID, out var entity))
|
||||
if (!_entityManager.TryGetEntity(containedSolids[j], out var entity))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!entity.Deleted && entity.TryGetComponent(out IconComponent icon))
|
||||
if (entity.Deleted || !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);
|
||||
continue;
|
||||
}
|
||||
|
||||
var solidItem = _menu.IngredientsList.AddItem(entity.Name, icon.Icon.Default);
|
||||
var solidIndex = _menu.IngredientsList.IndexOf(solidItem);
|
||||
_solids.Add(solidIndex, containedSolids[j]);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class MicrowaveMenu : SS14Window
|
||||
{
|
||||
|
||||
public class MicrowaveCookTimeButton : Button
|
||||
{
|
||||
public uint CookTime;
|
||||
}
|
||||
|
||||
|
||||
protected override Vector2? CustomSize => (512, 256);
|
||||
|
||||
private MicrowaveBoundUserInterface Owner { get; set; }
|
||||
|
||||
public event Action<BaseButton.ButtonEventArgs, int> OnCookTimeSelected;
|
||||
|
||||
public Button StartButton { get; }
|
||||
public Button EjectButton { get; }
|
||||
|
||||
public PanelContainer TimerFacePlate { get; }
|
||||
|
||||
public ButtonGroup CookTimeButtonGroup { get; }
|
||||
public VBoxContainer CookTimeButtonVbox { get; }
|
||||
|
||||
private VBoxContainer ButtonGridContainer { get; }
|
||||
|
||||
private PanelContainer DisableCookingPanelOverlay { get; }
|
||||
|
||||
|
||||
public ItemList IngredientsList { get; }
|
||||
|
||||
public ItemList IngredientsListReagents { get; }
|
||||
public Label _cookTimeInfoLabel { get; }
|
||||
|
||||
public MicrowaveMenu(MicrowaveBoundUserInterface owner = null)
|
||||
{
|
||||
Owner = owner;
|
||||
Title = Loc.GetString("Microwave");
|
||||
DisableCookingPanelOverlay = new PanelContainer
|
||||
{
|
||||
MouseFilter = MouseFilterMode.Stop,
|
||||
PanelOverride = new StyleBoxFlat {BackgroundColor = Color.Black.WithAlpha(0.60f)},
|
||||
SizeFlagsHorizontal = SizeFlags.Fill,
|
||||
SizeFlagsVertical = SizeFlags.Fill,
|
||||
};
|
||||
|
||||
|
||||
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);
|
||||
|
||||
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 <= 6; i++)
|
||||
{
|
||||
var newButton = new MicrowaveCookTimeButton
|
||||
{
|
||||
Text = index <= 0 ? Loc.GetString("INSTANT") : index.ToString(),
|
||||
CookTime = (uint)index,
|
||||
TextAlign = Label.AlignMode.Center,
|
||||
ToggleMode = true,
|
||||
Group = CookTimeButtonGroup,
|
||||
};
|
||||
CookTimeButtonVbox.AddChild(newButton);
|
||||
newButton.OnToggled += args =>
|
||||
{
|
||||
OnCookTimeSelected?.Invoke(args, newButton.GetPositionInParent());
|
||||
|
||||
};
|
||||
index += 5;
|
||||
}
|
||||
|
||||
var cookTimeOneSecondButton = (Button) CookTimeButtonVbox.GetChild(0);
|
||||
cookTimeOneSecondButton.Pressed = true;
|
||||
|
||||
|
||||
_cookTimeInfoLabel = new Label
|
||||
{
|
||||
Text = Loc.GetString("COOK TIME: 1"),
|
||||
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);
|
||||
Contents.AddChild(DisableCookingPanelOverlay);
|
||||
}
|
||||
|
||||
public void ToggleBusyDisableOverlayPanel(bool shouldDisable)
|
||||
{
|
||||
DisableCookingPanelOverlay.Visible = shouldDisable;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user