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:
@@ -38,13 +38,19 @@ namespace Content.Client.Chemistry.UI
|
||||
_window.OnClose += Close;
|
||||
|
||||
//Setup static button actions.
|
||||
_window.EjectButton.OnPressed += _ => PrepareData(UiAction.Eject, null, null, null);
|
||||
_window.BufferTransferButton.OnPressed += _ => PrepareData(UiAction.Transfer, null, null, null);
|
||||
_window.BufferDiscardButton.OnPressed += _ => PrepareData(UiAction.Discard, null, null, null);
|
||||
_window.CreatePillButton.OnPressed += _ => PrepareData(UiAction.CreatePills, null, _window.PillAmount.Value, null);
|
||||
_window.CreateBottleButton.OnPressed += _ => PrepareData(UiAction.CreateBottles, null, null, _window.BottleAmount.Value);
|
||||
_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.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>
|
||||
@@ -63,15 +69,15 @@ namespace Content.Client.Chemistry.UI
|
||||
_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)
|
||||
{
|
||||
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
|
||||
{
|
||||
SendMessage(new UiActionMessage(action, null, null, null, pillAmount, bottleAmount));
|
||||
SendMessage(new UiActionMessage(action, null, null, null, pillType, pillAmount, bottleAmount));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<SS14Window xmlns="https://spacestation14.io"
|
||||
<SS14Window xmlns="https://spacestation14.io"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:gfx="clr-namespace:Robust.Client.Graphics;assembly=Robust.Client"
|
||||
MinSize="400 525"
|
||||
@@ -72,6 +72,15 @@
|
||||
<!-- 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"
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ using Content.Server.Chemistry.Components.SolutionManager;
|
||||
using Content.Server.Chemistry.EntitySystems;
|
||||
using Content.Server.Hands.Components;
|
||||
using Content.Server.Items;
|
||||
using Content.Server.Sprite;
|
||||
using Content.Server.Power.Components;
|
||||
using Content.Server.UserInterface;
|
||||
using Content.Shared.ActionBlocker;
|
||||
@@ -37,6 +38,9 @@ namespace Content.Server.Chemistry.Components
|
||||
[ComponentReference(typeof(SharedChemMasterComponent))]
|
||||
public class ChemMasterComponent : SharedChemMasterComponent, IActivate
|
||||
{
|
||||
[ViewVariables]
|
||||
private uint _pillType = 1;
|
||||
|
||||
[ViewVariables]
|
||||
private bool _bufferModeTransfer = true;
|
||||
|
||||
@@ -103,7 +107,7 @@ namespace Content.Server.Chemistry.Components
|
||||
}
|
||||
|
||||
var msg = (UiActionMessage) obj.Message;
|
||||
var needsPower = msg.action switch
|
||||
var needsPower = msg.Action switch
|
||||
{
|
||||
UiAction.Eject => false,
|
||||
_ => true,
|
||||
@@ -112,13 +116,13 @@ namespace Content.Server.Chemistry.Components
|
||||
if (!PlayerCanUseChemMaster(obj.Session.AttachedEntity, needsPower))
|
||||
return;
|
||||
|
||||
switch (msg.action)
|
||||
switch (msg.Action)
|
||||
{
|
||||
case UiAction.Eject:
|
||||
EntitySystem.Get<ItemSlotsSystem>().TryEjectToHands(OwnerUid, BeakerSlot, obj.Session.AttachedEntityUid);
|
||||
break;
|
||||
case UiAction.ChemButton:
|
||||
TransferReagent(msg.id, msg.amount, msg.isBuffer);
|
||||
TransferReagent(msg.Id, msg.Amount, msg.IsBuffer);
|
||||
break;
|
||||
case UiAction.Transfer:
|
||||
_bufferModeTransfer = true;
|
||||
@@ -128,14 +132,18 @@ namespace Content.Server.Chemistry.Components
|
||||
_bufferModeTransfer = false;
|
||||
UpdateUserInterface();
|
||||
break;
|
||||
case UiAction.SetPillType:
|
||||
_pillType = msg.PillType;
|
||||
UpdateUserInterface();
|
||||
break;
|
||||
case UiAction.CreatePills:
|
||||
case UiAction.CreateBottles:
|
||||
TryCreatePackage(obj.Session.AttachedEntity, msg.action, msg.pillAmount, msg.bottleAmount);
|
||||
TryCreatePackage(obj.Session.AttachedEntity, msg.Action, msg.PillAmount, msg.BottleAmount);
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
|
||||
UpdateUserInterface();
|
||||
ClickSound();
|
||||
}
|
||||
|
||||
@@ -175,13 +183,13 @@ namespace Content.Server.Chemistry.Components
|
||||
{
|
||||
return new ChemMasterBoundUserInterfaceState(Powered, false, FixedPoint2.New(0), FixedPoint2.New(0),
|
||||
"", Owner.Name, new List<Solution.ReagentQuantity>(), BufferSolution.Contents, _bufferModeTransfer,
|
||||
BufferSolution.TotalVolume);
|
||||
BufferSolution.TotalVolume, _pillType);
|
||||
}
|
||||
|
||||
return new ChemMasterBoundUserInterfaceState(Powered, true, beakerSolution.CurrentVolume,
|
||||
beakerSolution.MaxVolume,
|
||||
beaker.Name, Owner.Name, beakerSolution.Contents, BufferSolution.Contents, _bufferModeTransfer,
|
||||
BufferSolution.TotalVolume);
|
||||
BufferSolution.TotalVolume, _pillType);
|
||||
}
|
||||
|
||||
public void UpdateUserInterface()
|
||||
@@ -310,6 +318,13 @@ namespace Content.Server.Chemistry.Components
|
||||
var pillSolution = EntitySystem.Get<SolutionContainerSystem>().EnsureSolution(pill.Uid, "food");
|
||||
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
|
||||
if (user.TryGetComponent<HandsComponent>(out var hands) &&
|
||||
pill.TryGetComponent<ItemComponent>(out var item))
|
||||
|
||||
@@ -43,9 +43,10 @@ namespace Content.Shared.Chemistry.Components
|
||||
public readonly bool BufferModeTransfer;
|
||||
|
||||
public readonly FixedPoint2 BufferCurrentVolume;
|
||||
public readonly uint SelectedPillType;
|
||||
|
||||
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;
|
||||
HasBeaker = hasBeaker;
|
||||
@@ -57,6 +58,7 @@ namespace Content.Shared.Chemistry.Components
|
||||
BufferReagents = bufferReagents;
|
||||
BufferModeTransfer = bufferModeTransfer;
|
||||
BufferCurrentVolume = bufferCurrentVolume;
|
||||
SelectedPillType = selectedPillType;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,34 +68,36 @@ namespace Content.Shared.Chemistry.Components
|
||||
[Serializable, NetSerializable]
|
||||
public class UiActionMessage : BoundUserInterfaceMessage
|
||||
{
|
||||
public readonly UiAction action;
|
||||
public readonly FixedPoint2 amount;
|
||||
public readonly string id = "";
|
||||
public readonly bool isBuffer;
|
||||
public readonly int pillAmount;
|
||||
public readonly int bottleAmount;
|
||||
public readonly UiAction Action;
|
||||
public readonly FixedPoint2 Amount;
|
||||
public readonly string Id = "";
|
||||
public readonly bool IsBuffer;
|
||||
public readonly uint PillType;
|
||||
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;
|
||||
if (action == UiAction.ChemButton)
|
||||
Action = action;
|
||||
if (Action == UiAction.ChemButton)
|
||||
{
|
||||
amount = _amount.GetValueOrDefault();
|
||||
if (_id == null)
|
||||
Amount = amount.GetValueOrDefault();
|
||||
if (id == null)
|
||||
{
|
||||
id = "null";
|
||||
Id = "null";
|
||||
}
|
||||
else
|
||||
{
|
||||
id = _id;
|
||||
Id = id;
|
||||
}
|
||||
|
||||
isBuffer = _isBuffer.GetValueOrDefault();
|
||||
isBuffer = isBuffer.GetValueOrDefault();
|
||||
}
|
||||
else
|
||||
{
|
||||
pillAmount = _pillAmount.GetValueOrDefault();
|
||||
bottleAmount = _bottleAmount.GetValueOrDefault();
|
||||
PillAmount = pillAmount.GetValueOrDefault();
|
||||
PillType = pillType.GetValueOrDefault();
|
||||
BottleAmount = bottleAmount.GetValueOrDefault();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -114,8 +118,8 @@ namespace Content.Shared.Chemistry.Components
|
||||
Discard,
|
||||
ChemButton,
|
||||
CreatePills,
|
||||
CreateBottles
|
||||
}
|
||||
|
||||
CreateBottles,
|
||||
SetPillType
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ chem-master-window-transfer-button = Transfer
|
||||
chem-master-window-discard-button = Discard
|
||||
chem-master-window-packaging-text = Packaging
|
||||
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-bottles-volume-text = max 30u/each
|
||||
chem-master-window-create-pill-button = Create
|
||||
|
||||
@@ -231,6 +231,7 @@
|
||||
sprite: Objects/Specific/Chemistry/pills.rsi
|
||||
state: pill
|
||||
- type: Item
|
||||
size: 1
|
||||
sprite: Objects/Specific/Chemistry/pills.rsi
|
||||
- type: Tag
|
||||
tags:
|
||||
@@ -243,3 +244,23 @@
|
||||
solutions:
|
||||
food:
|
||||
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
|
||||
|
||||
@@ -13,6 +13,39 @@
|
||||
{
|
||||
"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"
|
||||
},
|
||||
@@ -37,42 +70,6 @@
|
||||
{
|
||||
"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",
|
||||
"directions": 4
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 1.7 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 1.7 KiB |
@@ -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
|
||||
}
|
||||
]
|
||||
}
|
||||
|
Before Width: | Height: | Size: 225 B After Width: | Height: | Size: 225 B |
Reference in New Issue
Block a user