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

@@ -38,13 +38,19 @@ namespace Content.Client.Chemistry.UI
_window.OnClose += Close; _window.OnClose += Close;
//Setup static button actions. //Setup static button actions.
_window.EjectButton.OnPressed += _ => PrepareData(UiAction.Eject, null, null, null); _window.EjectButton.OnPressed += _ => PrepareData(UiAction.Eject, null, null, null, null);
_window.BufferTransferButton.OnPressed += _ => PrepareData(UiAction.Transfer, null, null, null); _window.BufferTransferButton.OnPressed += _ => PrepareData(UiAction.Transfer, null, null, null, null);
_window.BufferDiscardButton.OnPressed += _ => PrepareData(UiAction.Discard, null, null, null); _window.BufferDiscardButton.OnPressed += _ => PrepareData(UiAction.Discard, null, null, null, null);
_window.CreatePillButton.OnPressed += _ => PrepareData(UiAction.CreatePills, null, _window.PillAmount.Value, null); _window.CreatePillButton.OnPressed += _ => PrepareData(UiAction.CreatePills, null, null, _window.PillAmount.Value, null);
_window.CreateBottleButton.OnPressed += _ => PrepareData(UiAction.CreateBottles, null, null, _window.BottleAmount.Value); _window.CreateBottleButton.OnPressed += _ => PrepareData(UiAction.CreateBottles, null, null, null, _window.BottleAmount.Value);
_window.OnChemButtonPressed += (args, button) => PrepareData(UiAction.ChemButton, button, null, null); 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.OnChemButtonPressed += (args, button) => PrepareData(UiAction.ChemButton, button, null, null, null);
} }
/// <summary> /// <summary>
@@ -63,15 +69,15 @@ namespace Content.Client.Chemistry.UI
_window?.UpdateState(castState); //Update window state _window?.UpdateState(castState); //Update window state
} }
private void PrepareData(UiAction action, ChemButton? button, int? pillAmount, int? bottleAmount) private void PrepareData(UiAction action, ChemButton? button, uint? pillType, int? pillAmount, int? bottleAmount)
{ {
if (button != null) if (button != null)
{ {
SendMessage(new UiActionMessage(action, button.Amount, button.Id, button.isBuffer, null, null)); SendMessage(new UiActionMessage(action, button.Amount, button.Id, button.IsBuffer, null, null, null));
} }
else else
{ {
SendMessage(new UiActionMessage(action, null, null, null, pillAmount, bottleAmount)); SendMessage(new UiActionMessage(action, null, null, null, pillType, pillAmount, bottleAmount));
} }
} }

View File

@@ -1,4 +1,4 @@
<SS14Window xmlns="https://spacestation14.io" <SS14Window xmlns="https://spacestation14.io"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:gfx="clr-namespace:Robust.Client.Graphics;assembly=Robust.Client" xmlns:gfx="clr-namespace:Robust.Client.Graphics;assembly=Robust.Client"
MinSize="400 525" MinSize="400 525"
@@ -72,6 +72,15 @@
<!-- Packaging Info --> <!-- Packaging Info -->
<BoxContainer Orientation="Vertical" <BoxContainer Orientation="Vertical"
HorizontalExpand="True"> 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"> <BoxContainer Orientation="Horizontal">
<Label Text="{Loc 'chem-master-window-pills-label'}" /> <Label Text="{Loc 'chem-master-window-pills-label'}" />
<Control HorizontalExpand="True" <Control HorizontalExpand="True"

View File

@@ -6,14 +6,17 @@ using Content.Shared.Chemistry.Components;
using Content.Shared.Chemistry.Reagent; using Content.Shared.Chemistry.Reagent;
using Content.Shared.FixedPoint; using Content.Shared.FixedPoint;
using Robust.Client.AutoGenerated; using Robust.Client.AutoGenerated;
using Robust.Client.ResourceManagement;
using Robust.Client.UserInterface; using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls; using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.CustomControls; using Robust.Client.UserInterface.CustomControls;
using Robust.Client.UserInterface.XAML; using Robust.Client.UserInterface.XAML;
using Robust.Client.Utility;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.IoC; using Robust.Shared.IoC;
using Robust.Shared.Localization; using Robust.Shared.Localization;
using Robust.Shared.Prototypes; using Robust.Shared.Prototypes;
using Robust.Shared.Utility;
using static Content.Shared.Chemistry.Components.SharedChemMasterComponent; using static Content.Shared.Chemistry.Components.SharedChemMasterComponent;
using static Robust.Client.UserInterface.Controls.BoxContainer; using static Robust.Client.UserInterface.Controls.BoxContainer;
@@ -27,6 +30,9 @@ namespace Content.Client.Chemistry.UI
{ {
[Dependency] private readonly IPrototypeManager _prototypeManager = default!; [Dependency] private readonly IPrototypeManager _prototypeManager = default!;
public event Action<BaseButton.ButtonEventArgs, ChemButton>? OnChemButtonPressed; 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) private static bool IsSpinValid(int n)
{ {
@@ -42,6 +48,47 @@ namespace Content.Client.Chemistry.UI
RobustXamlLoader.Load(this); RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(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; PillAmount.IsValid = IsSpinValid;
BottleAmount.IsValid = IsSpinValid; BottleAmount.IsValid = IsSpinValid;
PillAmount.InitDefaultButtons(); PillAmount.InitDefaultButtons();
@@ -70,6 +117,8 @@ namespace Content.Client.Chemistry.UI
ButtonHelpers.SetButtonDisabledRecursive(Contents, !castState.HasPower); ButtonHelpers.SetButtonDisabledRecursive(Contents, !castState.HasPower);
EjectButton.Disabled = !castState.HasBeaker; EjectButton.Disabled = !castState.HasBeaker;
} }
PillTypeButtons[castState.SelectedPillType - 1].Pressed = true;
} }
/// <summary> /// <summary>
@@ -206,15 +255,15 @@ namespace Content.Client.Chemistry.UI
public class ChemButton : Button public class ChemButton : Button
{ {
public FixedPoint2 Amount { get; set; } public FixedPoint2 Amount { get; set; }
public bool isBuffer = true; public bool IsBuffer = true;
public string Id { get; set; } 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); AddStyleClass(styleClass);
Text = _text; Text = text;
Amount = _amount; Amount = amount;
Id = _id; Id = id;
isBuffer = _isBuffer; IsBuffer = isBuffer;
} }
} }

View File

@@ -5,6 +5,7 @@ using Content.Server.Chemistry.Components.SolutionManager;
using Content.Server.Chemistry.EntitySystems; using Content.Server.Chemistry.EntitySystems;
using Content.Server.Hands.Components; using Content.Server.Hands.Components;
using Content.Server.Items; using Content.Server.Items;
using Content.Server.Sprite;
using Content.Server.Power.Components; using Content.Server.Power.Components;
using Content.Server.UserInterface; using Content.Server.UserInterface;
using Content.Shared.ActionBlocker; using Content.Shared.ActionBlocker;
@@ -37,6 +38,9 @@ namespace Content.Server.Chemistry.Components
[ComponentReference(typeof(SharedChemMasterComponent))] [ComponentReference(typeof(SharedChemMasterComponent))]
public class ChemMasterComponent : SharedChemMasterComponent, IActivate public class ChemMasterComponent : SharedChemMasterComponent, IActivate
{ {
[ViewVariables]
private uint _pillType = 1;
[ViewVariables] [ViewVariables]
private bool _bufferModeTransfer = true; private bool _bufferModeTransfer = true;
@@ -103,7 +107,7 @@ namespace Content.Server.Chemistry.Components
} }
var msg = (UiActionMessage) obj.Message; var msg = (UiActionMessage) obj.Message;
var needsPower = msg.action switch var needsPower = msg.Action switch
{ {
UiAction.Eject => false, UiAction.Eject => false,
_ => true, _ => true,
@@ -112,13 +116,13 @@ namespace Content.Server.Chemistry.Components
if (!PlayerCanUseChemMaster(obj.Session.AttachedEntity, needsPower)) if (!PlayerCanUseChemMaster(obj.Session.AttachedEntity, needsPower))
return; return;
switch (msg.action) switch (msg.Action)
{ {
case UiAction.Eject: case UiAction.Eject:
EntitySystem.Get<ItemSlotsSystem>().TryEjectToHands(OwnerUid, BeakerSlot, obj.Session.AttachedEntityUid); EntitySystem.Get<ItemSlotsSystem>().TryEjectToHands(OwnerUid, BeakerSlot, obj.Session.AttachedEntityUid);
break; break;
case UiAction.ChemButton: case UiAction.ChemButton:
TransferReagent(msg.id, msg.amount, msg.isBuffer); TransferReagent(msg.Id, msg.Amount, msg.IsBuffer);
break; break;
case UiAction.Transfer: case UiAction.Transfer:
_bufferModeTransfer = true; _bufferModeTransfer = true;
@@ -128,14 +132,18 @@ namespace Content.Server.Chemistry.Components
_bufferModeTransfer = false; _bufferModeTransfer = false;
UpdateUserInterface(); UpdateUserInterface();
break; break;
case UiAction.SetPillType:
_pillType = msg.PillType;
UpdateUserInterface();
break;
case UiAction.CreatePills: case UiAction.CreatePills:
case UiAction.CreateBottles: case UiAction.CreateBottles:
TryCreatePackage(obj.Session.AttachedEntity, msg.action, msg.pillAmount, msg.bottleAmount); TryCreatePackage(obj.Session.AttachedEntity, msg.Action, msg.PillAmount, msg.BottleAmount);
break; break;
default: default:
throw new ArgumentOutOfRangeException(); throw new ArgumentOutOfRangeException();
} }
UpdateUserInterface();
ClickSound(); ClickSound();
} }
@@ -175,13 +183,13 @@ namespace Content.Server.Chemistry.Components
{ {
return new ChemMasterBoundUserInterfaceState(Powered, false, FixedPoint2.New(0), FixedPoint2.New(0), return new ChemMasterBoundUserInterfaceState(Powered, false, FixedPoint2.New(0), FixedPoint2.New(0),
"", Owner.Name, new List<Solution.ReagentQuantity>(), BufferSolution.Contents, _bufferModeTransfer, "", Owner.Name, new List<Solution.ReagentQuantity>(), BufferSolution.Contents, _bufferModeTransfer,
BufferSolution.TotalVolume); BufferSolution.TotalVolume, _pillType);
} }
return new ChemMasterBoundUserInterfaceState(Powered, true, beakerSolution.CurrentVolume, return new ChemMasterBoundUserInterfaceState(Powered, true, beakerSolution.CurrentVolume,
beakerSolution.MaxVolume, beakerSolution.MaxVolume,
beaker.Name, Owner.Name, beakerSolution.Contents, BufferSolution.Contents, _bufferModeTransfer, beaker.Name, Owner.Name, beakerSolution.Contents, BufferSolution.Contents, _bufferModeTransfer,
BufferSolution.TotalVolume); BufferSolution.TotalVolume, _pillType);
} }
public void UpdateUserInterface() public void UpdateUserInterface()
@@ -310,6 +318,13 @@ namespace Content.Server.Chemistry.Components
var pillSolution = EntitySystem.Get<SolutionContainerSystem>().EnsureSolution(pill.Uid, "food"); var pillSolution = EntitySystem.Get<SolutionContainerSystem>().EnsureSolution(pill.Uid, "food");
EntitySystem.Get<SolutionContainerSystem>().TryAddSolution(pill.Uid, pillSolution, bufferSolution); EntitySystem.Get<SolutionContainerSystem>().TryAddSolution(pill.Uid, pillSolution, bufferSolution);
//Change pill Sprite component state
if (!pill.TryGetComponent(out SpriteComponent? sprite))
{
return;
}
sprite?.LayerSetState(0, "pill" + _pillType);
//Try to give them the bottle //Try to give them the bottle
if (user.TryGetComponent<HandsComponent>(out var hands) && if (user.TryGetComponent<HandsComponent>(out var hands) &&
pill.TryGetComponent<ItemComponent>(out var item)) pill.TryGetComponent<ItemComponent>(out var item))

View File

@@ -43,9 +43,10 @@ namespace Content.Shared.Chemistry.Components
public readonly bool BufferModeTransfer; public readonly bool BufferModeTransfer;
public readonly FixedPoint2 BufferCurrentVolume; public readonly FixedPoint2 BufferCurrentVolume;
public readonly uint SelectedPillType;
public ChemMasterBoundUserInterfaceState(bool hasPower, bool hasBeaker, FixedPoint2 beakerCurrentVolume, FixedPoint2 beakerMaxVolume, string containerName, public ChemMasterBoundUserInterfaceState(bool hasPower, bool hasBeaker, FixedPoint2 beakerCurrentVolume, FixedPoint2 beakerMaxVolume, string containerName,
string dispenserName, IReadOnlyList<Solution.ReagentQuantity> containerReagents, IReadOnlyList<Solution.ReagentQuantity> bufferReagents, bool bufferModeTransfer, FixedPoint2 bufferCurrentVolume) string dispenserName, IReadOnlyList<Solution.ReagentQuantity> containerReagents, IReadOnlyList<Solution.ReagentQuantity> bufferReagents, bool bufferModeTransfer, FixedPoint2 bufferCurrentVolume, uint selectedPillType)
{ {
HasPower = hasPower; HasPower = hasPower;
HasBeaker = hasBeaker; HasBeaker = hasBeaker;
@@ -57,6 +58,7 @@ namespace Content.Shared.Chemistry.Components
BufferReagents = bufferReagents; BufferReagents = bufferReagents;
BufferModeTransfer = bufferModeTransfer; BufferModeTransfer = bufferModeTransfer;
BufferCurrentVolume = bufferCurrentVolume; BufferCurrentVolume = bufferCurrentVolume;
SelectedPillType = selectedPillType;
} }
} }
@@ -66,34 +68,36 @@ namespace Content.Shared.Chemistry.Components
[Serializable, NetSerializable] [Serializable, NetSerializable]
public class UiActionMessage : BoundUserInterfaceMessage public class UiActionMessage : BoundUserInterfaceMessage
{ {
public readonly UiAction action; public readonly UiAction Action;
public readonly FixedPoint2 amount; public readonly FixedPoint2 Amount;
public readonly string id = ""; public readonly string Id = "";
public readonly bool isBuffer; public readonly bool IsBuffer;
public readonly int pillAmount; public readonly uint PillType;
public readonly int bottleAmount; public readonly int PillAmount;
public readonly int BottleAmount;
public UiActionMessage(UiAction _action, FixedPoint2? _amount, string? _id, bool? _isBuffer, int? _pillAmount, int? _bottleAmount) public UiActionMessage(UiAction action, FixedPoint2? amount, string? id, bool? isBuffer, uint? pillType, int? pillAmount, int? bottleAmount)
{ {
action = _action; Action = action;
if (action == UiAction.ChemButton) if (Action == UiAction.ChemButton)
{ {
amount = _amount.GetValueOrDefault(); Amount = amount.GetValueOrDefault();
if (_id == null) if (id == null)
{ {
id = "null"; Id = "null";
} }
else else
{ {
id = _id; Id = id;
} }
isBuffer = _isBuffer.GetValueOrDefault(); isBuffer = isBuffer.GetValueOrDefault();
} }
else else
{ {
pillAmount = _pillAmount.GetValueOrDefault(); PillAmount = pillAmount.GetValueOrDefault();
bottleAmount = _bottleAmount.GetValueOrDefault(); PillType = pillType.GetValueOrDefault();
BottleAmount = bottleAmount.GetValueOrDefault();
} }
} }
} }
@@ -114,8 +118,8 @@ namespace Content.Shared.Chemistry.Components
Discard, Discard,
ChemButton, ChemButton,
CreatePills, CreatePills,
CreateBottles CreateBottles,
} SetPillType
}
} }
} }

View File

@@ -19,6 +19,7 @@ chem-master-window-transfer-button = Transfer
chem-master-window-discard-button = Discard chem-master-window-discard-button = Discard
chem-master-window-packaging-text = Packaging chem-master-window-packaging-text = Packaging
chem-master-window-pills-label = Pills: chem-master-window-pills-label = Pills:
chem-master-window-pill-type-label = Pill type:
chem-master-window-max-pills-volume-text = max 50u/each chem-master-window-max-pills-volume-text = max 50u/each
chem-master-window-max-bottles-volume-text = max 30u/each chem-master-window-max-bottles-volume-text = max 30u/each
chem-master-window-create-pill-button = Create chem-master-window-create-pill-button = Create

View File

@@ -231,6 +231,7 @@
sprite: Objects/Specific/Chemistry/pills.rsi sprite: Objects/Specific/Chemistry/pills.rsi
state: pill state: pill
- type: Item - type: Item
size: 1
sprite: Objects/Specific/Chemistry/pills.rsi sprite: Objects/Specific/Chemistry/pills.rsi
- type: Tag - type: Tag
tags: tags:
@@ -243,3 +244,23 @@
solutions: solutions:
food: food:
maxVol: 50 maxVol: 50
- type: entity
name: pill canister
id: PillCanister
parent: BaseItem
description: Holds up to 12 pills.
components:
- type: Sprite
sprite: Objects/Specific/Chemistry/pills_canister.rsi
state: pill_canister
- type: Item
sprite: Objects/Specific/Chemistry/pills_canister.rsi
- type: Storage
capacity: 12
quickInsert: true
areaInsert: true
areaInsertRadius: 1
whitelist:
tags:
- Pill

View File

@@ -13,6 +13,39 @@
{ {
"name": "pill1" "name": "pill1"
}, },
{
"name": "pill2"
},
{
"name": "pill3"
},
{
"name": "pill4"
},
{
"name": "pill5"
},
{
"name": "pill6"
},
{
"name": "pill18"
},
{
"name": "pill19"
},
{
"name": "pill20"
},
{
"name": "pill7"
},
{
"name": "pill8"
},
{
"name": "pill9"
},
{ {
"name": "pill10" "name": "pill10"
}, },
@@ -37,42 +70,6 @@
{ {
"name": "pill17" "name": "pill17"
}, },
{
"name": "pill18"
},
{
"name": "pill19"
},
{
"name": "pill2"
},
{
"name": "pill20"
},
{
"name": "pill3"
},
{
"name": "pill4"
},
{
"name": "pill5"
},
{
"name": "pill6"
},
{
"name": "pill7"
},
{
"name": "pill8"
},
{
"name": "pill9"
},
{
"name": "pill_canister"
},
{ {
"name": "inhand-left", "name": "inhand-left",
"directions": 4 "directions": 4

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

View File

@@ -0,0 +1,22 @@
{
"version": 1,
"license": "CC-BY-SA-3.0",
"copyright": "Taken from cev-eris at https://github.com/discordia-space/CEV-Eris/blob/2b969adc2dfd3e9621bf3597c5cbffeb3ac8c9f0/icons/obj/chemical.dmi",
"size": {
"x": 32,
"y": 32
},
"states": [
{
"name": "pill_canister"
},
{
"name": "inhand-left",
"directions": 4
},
{
"name": "inhand-right",
"directions": 4
}
]
}