Adds pills type selection and pills canister (#5539)

* Added pill type selection

Ui textures missing for now

* bugfixes

* Pill type selection

* ui changes

* Added pills canister

* Change requests
This commit is contained in:
Spartak
2021-11-26 22:44:36 -08:00
committed by GitHub
parent 4359a083c5
commit b06becaf98
12 changed files with 204 additions and 80 deletions

View File

@@ -6,14 +6,17 @@ using Content.Shared.Chemistry.Components;
using Content.Shared.Chemistry.Reagent;
using Content.Shared.FixedPoint;
using Robust.Client.AutoGenerated;
using Robust.Client.ResourceManagement;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.CustomControls;
using Robust.Client.UserInterface.XAML;
using Robust.Client.Utility;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Prototypes;
using Robust.Shared.Utility;
using static Content.Shared.Chemistry.Components.SharedChemMasterComponent;
using static Robust.Client.UserInterface.Controls.BoxContainer;
@@ -27,6 +30,9 @@ namespace Content.Client.Chemistry.UI
{
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
public event Action<BaseButton.ButtonEventArgs, ChemButton>? OnChemButtonPressed;
public readonly Button[] PillTypeButtons;
private const string PillsRsiPath = "/Textures/Objects/Specific/Chemistry/pills.rsi";
private static bool IsSpinValid(int n)
{
@@ -42,6 +48,47 @@ namespace Content.Client.Chemistry.UI
RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this);
//Pill type selection buttons, in total there are 20 pills.
//Pill rsi file should have states named as pill1, pill2, and so on.
var resourcePath = new ResourcePath(PillsRsiPath);
var pillTypeGroup = new ButtonGroup();
PillTypeButtons = new Button[20];
for (uint i = 0; i < PillTypeButtons.Length; i++)
{
//For every button decide which stylebase to have
//Every row has 10 buttons
String styleBase = StyleBase.ButtonOpenBoth;
uint modulo = i % 10;
if (i > 0 && modulo == 0)
styleBase = StyleBase.ButtonOpenRight;
else if (i > 0 && modulo == 9)
styleBase = StyleBase.ButtonOpenLeft;
else if (i == 0)
styleBase = StyleBase.ButtonOpenRight;
//Generate buttons
PillTypeButtons[i] = new Button
{
Access = AccessLevel.Public,
StyleClasses = { styleBase },
MaxSize = (42, 28),
Group = pillTypeGroup
};
//Generate buttons textures
var specifier = new SpriteSpecifier.Rsi(resourcePath, "pill" + (i + 1));
TextureRect pillTypeTexture = new TextureRect
{
Texture = specifier.Frame0(),
TextureScale = (1.75f, 1.75f),
Stretch = TextureRect.StretchMode.KeepCentered,
};
PillTypeButtons[i].AddChild(pillTypeTexture);
Grid.AddChild(PillTypeButtons[i]);
}
PillAmount.IsValid = IsSpinValid;
BottleAmount.IsValid = IsSpinValid;
PillAmount.InitDefaultButtons();
@@ -70,6 +117,8 @@ namespace Content.Client.Chemistry.UI
ButtonHelpers.SetButtonDisabledRecursive(Contents, !castState.HasPower);
EjectButton.Disabled = !castState.HasBeaker;
}
PillTypeButtons[castState.SelectedPillType - 1].Pressed = true;
}
/// <summary>
@@ -206,15 +255,15 @@ namespace Content.Client.Chemistry.UI
public class ChemButton : Button
{
public FixedPoint2 Amount { get; set; }
public bool isBuffer = true;
public bool IsBuffer = true;
public string Id { get; set; }
public ChemButton(string _text, FixedPoint2 _amount, string _id, bool _isBuffer, string _styleClass)
public ChemButton(string text, FixedPoint2 amount, string id, bool isBuffer, string styleClass)
{
AddStyleClass(_styleClass);
Text = _text;
Amount = _amount;
Id = _id;
isBuffer = _isBuffer;
AddStyleClass(styleClass);
Text = text;
Amount = amount;
Id = id;
IsBuffer = isBuffer;
}
}