Added auto label for ChemMaster (#5596)

This commit is contained in:
Spartak
2021-11-28 18:25:23 -08:00
committed by GitHub
parent 47186a6dec
commit 30c87ca6b2
6 changed files with 137 additions and 65 deletions

View File

@@ -38,19 +38,19 @@ namespace Content.Client.Chemistry.UI
_window.OnClose += Close;
//Setup static button actions.
_window.EjectButton.OnPressed += _ => PrepareData(UiAction.Eject, null, null, null, null);
_window.BufferTransferButton.OnPressed += _ => PrepareData(UiAction.Transfer, null, null, null, null);
_window.BufferDiscardButton.OnPressed += _ => PrepareData(UiAction.Discard, null, null, null, null);
_window.CreatePillButton.OnPressed += _ => PrepareData(UiAction.CreatePills, null, null, _window.PillAmount.Value, null);
_window.CreateBottleButton.OnPressed += _ => PrepareData(UiAction.CreateBottles, null, null, null, _window.BottleAmount.Value);
_window.EjectButton.OnPressed += _ => PrepareData(UiAction.Eject, null, null, null, null, null);
_window.BufferTransferButton.OnPressed += _ => PrepareData(UiAction.Transfer, null, null, null, null, null);
_window.BufferDiscardButton.OnPressed += _ => PrepareData(UiAction.Discard, null, null, null, null, null);
_window.CreatePillButton.OnPressed += _ => PrepareData(UiAction.CreatePills, null, _window.LabelLine, null, _window.PillAmount.Value, null);
_window.CreateBottleButton.OnPressed += _ => PrepareData(UiAction.CreateBottles, null, _window.LabelLine, null, null, _window.BottleAmount.Value);
for(uint i = 0; i < _window.PillTypeButtons.Length; i++)
{
uint type = i;
_window.PillTypeButtons[i].OnPressed += _ => PrepareData(UiAction.SetPillType, null, type + 1, null, null);
_window.PillTypeButtons[i].OnPressed += _ => PrepareData(UiAction.SetPillType, null, null, type + 1, null, null);
}
_window.OnChemButtonPressed += (args, button) => PrepareData(UiAction.ChemButton, button, null, null, null);
_window.OnChemButtonPressed += (args, button) => PrepareData(UiAction.ChemButton, button, null, null, null, null);
}
/// <summary>
@@ -69,15 +69,15 @@ namespace Content.Client.Chemistry.UI
_window?.UpdateState(castState); //Update window state
}
private void PrepareData(UiAction action, ChemButton? button, uint? pillType, int? pillAmount, int? bottleAmount)
private void PrepareData(UiAction action, ChemButton? button, string? label, uint? pillType, int? pillAmount, int? bottleAmount)
{
if (button != null)
{
SendMessage(new UiActionMessage(action, button.Amount, button.Id, button.IsBuffer, null, null, null));
SendMessage(new UiActionMessage(action, button.Amount, button.Id, button.IsBuffer, null, null, null, null));
}
else
{
SendMessage(new UiActionMessage(action, null, null, null, pillType, pillAmount, bottleAmount));
{
SendMessage(new UiActionMessage(action, null, null, null, label, pillType, pillAmount, bottleAmount));
}
}

View File

@@ -41,7 +41,7 @@
StyleClasses="OpenLeft" />
</BoxContainer>
<!-- Buffer info -->
<PanelContainer VerticalExpand="True" SizeFlagsStretchRatio="6" MinSize="0 100">
<PanelContainer VerticalExpand="True" SizeFlagsStretchRatio="1" MinSize="0 150">
<PanelContainer.PanelOverride>
<gfx:StyleBoxFlat BackgroundColor="#1B1B1E" />
</PanelContainer.PanelOverride>
@@ -66,47 +66,50 @@
<PanelContainer.PanelOverride>
<gfx:StyleBoxFlat BackgroundColor="#1B1B1E" />
</PanelContainer.PanelOverride>
<!-- Packaging options -->
<!-- Packaging Info -->
<BoxContainer Orientation="Vertical"
HorizontalExpand="True">
<!-- Packaging Info -->
<BoxContainer Orientation="Vertical"
HorizontalExpand="True">
<BoxContainer Orientation="Horizontal">
<!-- Pills Type Buttons -->
<Label Text="{Loc 'chem-master-window-pill-type-label'}"/>
<Control HorizontalExpand="True"
MinSize="50 0"></Control>
<GridContainer Name="Grid" Columns="10">
<!-- Pills type buttons are generated in the code -->
</GridContainer>
</BoxContainer>
<BoxContainer Orientation="Horizontal">
<Label Text="{Loc 'chem-master-window-pills-label'}" />
<Control HorizontalExpand="True"
MinSize="50 0" />
<SpinBox Name="PillAmount"
Access="Public"
Value="1" />
<Button Name="CreatePillButton"
HorizontalExpand="True"
VerticalExpand="True"
SeparationOverride="5">
<!-- Label for output -->
<BoxContainer Orientation="Horizontal">
<Label Text="{Loc 'chem-master-current-text-label'}" />
<Control HorizontalExpand="True" MinSize="50 0"/>
<LineEdit Name="LabelLineEdit" SetWidth="455"/>
</BoxContainer>
<!-- Pills Type Buttons -->
<BoxContainer Orientation="Horizontal">
<Label Text="{Loc 'chem-master-window-pill-type-label'}"/>
<Control HorizontalExpand="True" MinSize="50 0"/>
<GridContainer Name="Grid" Columns="10">
<!-- Pills type buttons are generated in the code -->
</GridContainer>
</BoxContainer>
<BoxContainer Orientation="Horizontal">
<Label Text="{Loc 'chem-master-window-pills-label'}" />
<Control HorizontalExpand="True"
MinSize="50 0" />
<SpinBox Name="PillAmount"
Access="Public"
Text="{Loc 'chem-master-window-create-pill-button'}" />
<Label Text="{Loc 'chem-master-window-max-pills-volume-text'}"
StyleClasses="LabelSecondaryColor" />
</BoxContainer>
<BoxContainer Orientation="Horizontal">
<Label Text="{Loc 'chem-master-window-bottles-label'}" />
<Control HorizontalExpand="True"
MinSize="50 0" />
<SpinBox Name="BottleAmount"
Access="Public"
Value="1" />
<Button Name="CreateBottleButton"
Value="1" />
<Button Name="CreatePillButton"
Access="Public"
Text="{Loc 'chem-master-window-create-pill-button'}" />
<Label Text="{Loc 'chem-master-window-max-pills-volume-text'}"
StyleClasses="LabelSecondaryColor" />
</BoxContainer>
<BoxContainer Orientation="Horizontal">
<Label Text="{Loc 'chem-master-window-bottles-label'}" />
<Control HorizontalExpand="True"
MinSize="50 0" />
<SpinBox Name="BottleAmount"
Access="Public"
Text="{Loc 'chem-master-window-create-bottle-button'}" />
<Label Text="{Loc 'chem-master-window-max-bottles-volume-text'}"
StyleClasses="LabelSecondaryColor" />
</BoxContainer>
Value="1" />
<Button Name="CreateBottleButton"
Access="Public"
Text="{Loc 'chem-master-window-create-bottle-button'}" />
<Label Text="{Loc 'chem-master-window-max-bottles-volume-text'}"
StyleClasses="LabelSecondaryColor" />
</BoxContainer>
</BoxContainer>
</PanelContainer>

View File

@@ -29,6 +29,7 @@ namespace Content.Client.Chemistry.UI
public partial class ChemMasterWindow : SS14Window
{
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
public event Action<string>? OnLabelEntered;
public event Action<BaseButton.ButtonEventArgs, ChemButton>? OnChemButtonPressed;
public readonly Button[] PillTypeButtons;
@@ -47,6 +48,7 @@ namespace Content.Client.Chemistry.UI
{
RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this);
LabelLineEdit.OnTextEntered += e => OnLabelEntered?.Invoke(e.Text);
//Pill type selection buttons, in total there are 20 pills.
//Pill rsi file should have states named as pill1, pill2, and so on.
@@ -75,7 +77,6 @@ namespace Content.Client.Chemistry.UI
Group = pillTypeGroup
};
//Generate buttons textures
var specifier = new SpriteSpecifier.Rsi(resourcePath, "pill" + (i + 1));
TextureRect pillTypeTexture = new TextureRect
@@ -111,6 +112,7 @@ namespace Content.Client.Chemistry.UI
{
var castState = (ChemMasterBoundUserInterfaceState) state;
Title = castState.DispenserName;
LabelLine = castState.Label;
UpdatePanelInfo(castState);
if (Contents.Children != null)
{
@@ -194,7 +196,8 @@ namespace Content.Client.Chemistry.UI
if (!state.BufferReagents.Any())
{
BufferInfo.Children.Add(new Label {Text = Loc.GetString("chem-master-window-buffer-empty-text") });
BufferInfo.Children.Add(new Label { Text = Loc.GetString("chem-master-window-buffer-empty-text") });
return;
}
@@ -250,6 +253,18 @@ namespace Content.Client.Chemistry.UI
}
}
}
public String LabelLine
{
get
{
return LabelLineEdit.Text;
}
set
{
LabelLineEdit.Text = value;
}
}
}
public class ChemButton : Button