forked from space-wizards/space-station-14
-
-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1377 from Saeko-44/master
Added plant analyzer from new frontier
- Loading branch information
Showing
21 changed files
with
884 additions
and
4 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
Content.Client/_NF/PlantAnalyzer/UI/PlantAnalyzerBoundUserInterface.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using Content.Shared._NF.PlantAnalyzer; | ||
using JetBrains.Annotations; | ||
|
||
namespace Content.Client._NF.PlantAnalyzer.UI; | ||
|
||
[UsedImplicitly] | ||
public sealed class PlantAnalyzerBoundUserInterface : BoundUserInterface | ||
{ | ||
[ViewVariables] | ||
private PlantAnalyzerWindow? _window; | ||
|
||
public PlantAnalyzerBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) | ||
{ | ||
} | ||
|
||
protected override void Open() | ||
{ | ||
base.Open(); | ||
_window = new PlantAnalyzerWindow(this) | ||
{ | ||
Title = Loc.GetString("plant-analyzer-interface-title"), | ||
}; | ||
_window.OnClose += Close; | ||
_window.OpenCenteredLeft(); | ||
} | ||
|
||
protected override void ReceiveMessage(BoundUserInterfaceMessage message) | ||
{ | ||
if (_window == null) | ||
return; | ||
|
||
if (message is not PlantAnalyzerScannedSeedPlantInformation cast) | ||
return; | ||
_window.Populate(cast); | ||
} | ||
|
||
public void AdvPressed(bool scanMode) | ||
{ | ||
SendMessage(new PlantAnalyzerSetMode(scanMode)); | ||
} | ||
|
||
protected override void Dispose(bool disposing) | ||
{ | ||
base.Dispose(disposing); | ||
if (!disposing) | ||
return; | ||
|
||
if (_window != null) | ||
_window.OnClose -= Close; | ||
|
||
_window?.Dispose(); | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
Content.Client/_NF/PlantAnalyzer/UI/PlantAnalyzerWindow.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<controls:FancyWindow xmlns="https://spacestation14.io" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls" | ||
Title="{Loc 'plant-analyzer-interface-title'}"> | ||
<!-- Margin="left,top,right,bottom" --> | ||
<GridContainer Rows="3" Name ="GridCont" Margin="10 5 10 5" VerticalAlignment="Stretch" HorizontalExpand="True"> | ||
<BoxContainer Name="Toggle"> | ||
<Label Name="AdvMode" Text="{Loc 'plant-analyzer-window-scanmode'}" Margin="5 0 5 0"/> | ||
<Button Name="OnButton" Text="{Loc 'plant-analyzer-window-mode-on'}" StyleClasses="OpenRight"/> | ||
<Button Name="OffButton" Text="{Loc 'plant-analyzer-window-mode-off'}" StyleClasses="OpenLeft"/> | ||
</BoxContainer> | ||
<BoxContainer Name="Top"> | ||
<Label Name="NoData" Text="{Loc 'plant-analyzer-window-no-seed-information-text'}" Margin="10 0 0 0"/> | ||
</BoxContainer> | ||
<TabContainer Name="Tabs" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" HorizontalExpand="True"> | ||
<BoxContainer Name ="{Loc 'plant-analyzer-window-tab-basics'}" Orientation="Vertical" VerticalAlignment="Stretch" Margin="10 0 5 0"> | ||
<Label Name="PlantName" Margin="0 5 0 5"/> | ||
<Label Name="PlantYield" Margin="0 5 0 5"/> | ||
<Label Name="Potency" Margin="0 5 0 5"/> | ||
<Label Name="Repeat" Margin="0 5 0 5"/> | ||
<Label Name="Chemicals" Margin="0 5 0 5"/> | ||
<Label Name="ConsumeGases" Margin="0 5 0 5" /> | ||
<Label Name="ExudeGases" Margin="0 5 0 5" /> | ||
<Label Name="Lifespan" Margin="0 5 0 5"/> | ||
<Label Name="Maturation" Margin="0 5 0 5"/> | ||
<Label Name="Production" Margin="0 5 0 5"/> | ||
<Label Name="GrowthStages" Margin="0 5 0 5"/> | ||
<Label Name="Endurance" Margin="0 5 0 5"/> | ||
</BoxContainer> | ||
<BoxContainer Name="{Loc 'plant-analyzer-window-tab-tolerances'}" Orientation="Vertical" VerticalAlignment="Stretch" Margin="10 0 5 0"> | ||
<Label Name="NutrientUsage" Margin="0 5 0 5"/> | ||
<Label Name="WaterUsage" Margin="0 5 0 5"/> | ||
<Label Name="IdealHeat" Margin="0 5 0 5"/> | ||
<Label Name="HeatTolerance" Margin="0 5 0 5"/> | ||
<Label Name="IdealLight" Margin="0 5 0 5"/> | ||
<Label Name="LightTolerance" Margin="0 5 0 5"/> | ||
<Label Name="ToxinsTolerance" Margin="0 5 0 5"/> | ||
<Label Name="LowPressureTolerance" Margin="0 5 0 5"/> | ||
<Label Name="HighPressureTolerance" Margin="0 5 0 5"/> | ||
<Label Name="PestTolerance" Margin="0 5 0 5"/> | ||
<Label Name="WeedTolerance" Margin="0 5 0 5"/> | ||
</BoxContainer> | ||
<BoxContainer Name="{Loc 'plant-analyzer-window-tab-mutations'}" Orientation="Vertical" VerticalAlignment="Stretch" Margin="10 0 5 0"> | ||
<Label Name="PlantSpeciation" Margin="0 5 0 5"/> | ||
<Label Name="Traits" Margin="0 5 0 5"/> | ||
<Label Name="ExtraInfo" Margin="0 5 0 5"/> | ||
</BoxContainer> | ||
</TabContainer> | ||
</GridContainer> | ||
</controls:FancyWindow> |
203 changes: 203 additions & 0 deletions
203
Content.Client/_NF/PlantAnalyzer/UI/PlantAnalyzerWindow.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,203 @@ | ||
using Content.Shared._NF.PlantAnalyzer; | ||
using Robust.Client.AutoGenerated; | ||
using Robust.Client.GameObjects; | ||
using Robust.Client.ResourceManagement; | ||
using Robust.Client.UserInterface.Controls; | ||
using Robust.Client.UserInterface.XAML; | ||
using Robust.Shared.Prototypes; | ||
using System.Linq; | ||
using System.Text; | ||
using FancyWindow = Content.Client.UserInterface.Controls.FancyWindow; | ||
|
||
namespace Content.Client._NF.PlantAnalyzer.UI; | ||
|
||
[GenerateTypedNameReferences] | ||
public sealed partial class PlantAnalyzerWindow : FancyWindow | ||
{ | ||
private readonly IEntityManager _entityManager; | ||
private readonly ButtonGroup _buttonGroup = new(); | ||
|
||
private const string IndentedNewline = "\n "; | ||
|
||
public PlantAnalyzerWindow(PlantAnalyzerBoundUserInterface owner) | ||
{ | ||
RobustXamlLoader.Load(this); | ||
|
||
var dependencies = IoCManager.Instance!; | ||
_entityManager = dependencies.Resolve<IEntityManager>(); | ||
|
||
OnButton.Group = _buttonGroup; | ||
OnButton.ToggleMode = true; | ||
OffButton.Group = _buttonGroup; | ||
OffButton.ToggleMode = true; | ||
|
||
OnButton.OnPressed += _ => owner.AdvPressed(true); | ||
OffButton.OnPressed += _ => owner.AdvPressed(false); | ||
} | ||
|
||
public void Populate(PlantAnalyzerScannedSeedPlantInformation msg) | ||
{ | ||
var target = _entityManager.GetEntity(msg.TargetEntity); | ||
Title = Loc.GetString("plant-analyzer-interface-title"); | ||
|
||
if (target == null) | ||
{ | ||
NoData.Visible = true; | ||
return; | ||
} | ||
NoData.Visible = false; | ||
|
||
if (msg.AdvancedInfo is not null) | ||
{ | ||
OnButton.Pressed = true; | ||
} | ||
else | ||
{ | ||
OffButton.Pressed = true; | ||
} | ||
|
||
// Process message fields into strings. | ||
StringBuilder chemString = new(); | ||
if (msg.SeedChem != null) | ||
{ | ||
foreach (var chem in msg.SeedChem) | ||
{ | ||
chemString.Append(IndentedNewline); | ||
chemString.Append(chem); | ||
} | ||
} | ||
|
||
StringBuilder exudeGases = GetStringFromGasFlags(msg.ExudeGases); | ||
StringBuilder consudeGases = GetStringFromGasFlags(msg.ConsumeGases); | ||
|
||
if (msg.IsTray) | ||
PlantName.Text = Loc.GetString("plant-analyzer-window-label-name-scanned-plant", ("seedName", Loc.GetString(string.IsNullOrEmpty(msg.SeedName) ? "plant-analyzer-unknown-plant" : msg.SeedName))); | ||
else | ||
PlantName.Text = Loc.GetString("plant-analyzer-window-label-name-scanned-seed", ("seedName", Loc.GetString(string.IsNullOrEmpty(msg.SeedName) ? "plant-analyzer-unknown-plant" : msg.SeedName))); | ||
// Basics | ||
PlantYield.Text = Loc.GetString("plant-analyzer-plant-yield-text", ("seedYield", $"{msg.SeedYield:D0}")); | ||
Potency.Text = Loc.GetString("plant-analyzer-plant-potency-text", ("seedPotency", $"{msg.SeedPotency:F0}")); | ||
Repeat.Text = Loc.GetString("plant-analyzer-plant-harvest-text", ("plantHarvestType", Loc.GetString($"plant-analyzer-harvest-{msg.HarvestType}").ToString())); | ||
Endurance.Text = Loc.GetString("plant-analyzer-plant-endurance-text", ("seedEndurance", $"{msg.Endurance:F0}")); | ||
Chemicals.Text = Loc.GetString("plant-analyzer-plant-chemistry-text", ("seedChem", chemString)); | ||
ExudeGases.Text = Loc.GetString("plant-analyzer-plant-exude-text", ("gases", exudeGases.Length == 0 ? Loc.GetString("plant-analyzer-plant-gases-none") : exudeGases.ToString())); | ||
ConsumeGases.Text = Loc.GetString("plant-analyzer-plant-consume-text", ("gases", consudeGases.Length == 0 ? Loc.GetString("plant-analyzer-plant-gases-none") : consudeGases.ToString())); | ||
Lifespan.Text = Loc.GetString("plant-analyzer-plant-lifespan-text", ("lifespan", $"{msg.Lifespan:F1}")); | ||
Maturation.Text = Loc.GetString("plant-analyzer-plant-maturation-text", ("maturation", $"{msg.Maturation:F1}")); | ||
Production.Text = Loc.GetString("plant-analyzer-plant-production-text", ("production", $"{msg.Production:F1}")); | ||
GrowthStages.Text = Loc.GetString("plant-analyzer-plant-growthstages-text", ("growthStages", $"{msg.GrowthStages:D0}")); | ||
// Tolerances | ||
var adv = msg.AdvancedInfo; | ||
NutrientUsage.Text = Loc.GetString("plant-analyzer-tolerance-nutrient-usage", ("nutrientUsage", adv is null ? "-" : $"{adv.Value.NutrientConsumption:F2}")); | ||
WaterUsage.Text = Loc.GetString("plant-analyzer-tolerance-water-usage", ("waterUsage", adv is null ? "-" : $"{adv.Value.WaterConsumption:F2}")); | ||
IdealHeat.Text = Loc.GetString("plant-analyzer-tolerance-ideal-heat", ("idealHeat", adv is null ? "-" : $"{adv.Value.IdealHeat:F0}")); | ||
HeatTolerance.Text = Loc.GetString("plant-analyzer-tolerance-heat-tolerance", ("heatTolerance", adv is null ? "-" : $"{adv.Value.HeatTolerance:F1}")); | ||
IdealLight.Text = Loc.GetString("plant-analyzer-tolerance-ideal-light", ("idealLight", adv is null ? "-" : $"{adv.Value.IdealLight:F1}")); | ||
LightTolerance.Text = Loc.GetString("plant-analyzer-tolerance-light-tolerance", ("lightTolerance", adv is null ? "-" : $"{adv.Value.LightTolerance:F1}")); | ||
ToxinsTolerance.Text = Loc.GetString("plant-analyzer-tolerance-toxin-tolerance", ("toxinsTolerance", adv is null ? "-" : $"{adv.Value.ToxinsTolerance:F1}")); | ||
LowPressureTolerance.Text = Loc.GetString("plant-analyzer-tolerance-low-pressure", ("lowPressureTolerance", adv is null ? "-" : $"{adv.Value.LowPressureTolerance:F1}")); ; | ||
HighPressureTolerance.Text = Loc.GetString("plant-analyzer-tolerance-high-pressure", ("highPressureTolerance", adv is null ? "-" : $"{adv.Value.HighPressureTolerance:F1}")); | ||
PestTolerance.Text = Loc.GetString("plant-analyzer-tolerance-pest-tolerance", ("pestTolerance", adv is null ? "-" : $"{adv.Value.PestTolerance:F1}")); | ||
WeedTolerance.Text = Loc.GetString("plant-analyzer-tolerance-weed-tolerance", ("weedTolerance", adv is null ? "-" : $"{adv.Value.WeedTolerance:F1}")); | ||
// Misc | ||
|
||
if (adv != null) | ||
{ | ||
var advInst = adv.Value; | ||
StringBuilder mutations = new(); | ||
if (advInst.Mutations.HasFlag(MutationFlags.TurnIntoKudzu)) | ||
{ | ||
mutations.Append(IndentedNewline); | ||
mutations.Append(Loc.GetString("plant-analyzer-mutation-turnintokudzu")); | ||
} | ||
if (advInst.Mutations.HasFlag(MutationFlags.Seedless)) | ||
{ | ||
mutations.Append(IndentedNewline); | ||
mutations.Append(Loc.GetString("plant-analyzer-mutation-seedless")); | ||
} | ||
if (advInst.Mutations.HasFlag(MutationFlags.Ligneous)) | ||
{ | ||
mutations.Append(IndentedNewline); | ||
mutations.Append(Loc.GetString("plant-analyzer-mutation-ligneous")); | ||
} | ||
if (advInst.Mutations.HasFlag(MutationFlags.CanScream)) | ||
{ | ||
mutations.Append(IndentedNewline); | ||
mutations.Append(Loc.GetString("plant-analyzer-mutation-canscream")); | ||
} | ||
|
||
Traits.Text = Loc.GetString("plant-analyzer-plant-mutations-text", ("traits", mutations.ToString())); | ||
} | ||
else | ||
{ | ||
Traits.Text = Loc.GetString("plant-analyzer-plant-mutations-text", ("traits", "-")); | ||
} | ||
|
||
StringBuilder speciation = new(); | ||
if (msg.Speciation is null) | ||
{ | ||
speciation.Append("-"); | ||
} | ||
else | ||
{ | ||
foreach (var species in msg.Speciation) | ||
{ | ||
speciation.Append(IndentedNewline); | ||
speciation.Append(Loc.GetString(species)); | ||
} | ||
} | ||
|
||
PlantSpeciation.Text = Loc.GetString("plant-analyzer-plant-speciation-text", ("speciation", speciation.ToString())); | ||
} | ||
|
||
private StringBuilder GetStringFromGasFlags(GasFlags flags) | ||
{ | ||
StringBuilder output = new(); | ||
if (flags.HasFlag(GasFlags.Nitrogen)) | ||
{ | ||
output.Append(IndentedNewline); | ||
output.Append(Loc.GetString("gases-nitrogen")); | ||
} | ||
if (flags.HasFlag(GasFlags.Oxygen)) | ||
{ | ||
output.Append(IndentedNewline); | ||
output.Append(Loc.GetString("gases-oxygen")); | ||
} | ||
if (flags.HasFlag(GasFlags.CarbonDioxide)) | ||
{ | ||
output.Append(IndentedNewline); | ||
output.Append(Loc.GetString("gases-co2")); | ||
} | ||
if (flags.HasFlag(GasFlags.Plasma)) | ||
{ | ||
output.Append(IndentedNewline); | ||
output.Append(Loc.GetString("gases-plasma")); | ||
} | ||
if (flags.HasFlag(GasFlags.Tritium)) | ||
{ | ||
output.Append(IndentedNewline); | ||
output.Append(Loc.GetString("gases-tritium")); | ||
} | ||
if (flags.HasFlag(GasFlags.WaterVapor)) | ||
{ | ||
output.Append(IndentedNewline); | ||
output.Append(Loc.GetString("gases-water-vapor")); | ||
} | ||
if (flags.HasFlag(GasFlags.Ammonia)) | ||
{ | ||
output.Append(IndentedNewline); | ||
output.Append(Loc.GetString("gases-ammonia")); | ||
} | ||
if (flags.HasFlag(GasFlags.NitrousOxide)) | ||
{ | ||
output.Append(IndentedNewline); | ||
output.Append(Loc.GetString("gases-n2o")); | ||
} | ||
if (flags.HasFlag(GasFlags.Frezon)) | ||
{ | ||
output.Append(IndentedNewline); | ||
output.Append(Loc.GetString("gases-frezon")); | ||
} | ||
return output; | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
Content.Server/_NF/Botany/Components/PlantAnalyzerComponent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using Content.Shared.DoAfter; | ||
using Robust.Shared.Audio; | ||
|
||
namespace Content.Server.Botany.Components; | ||
|
||
/// <summary> | ||
/// After scanning, retrieves the target Uid to use with its related UI. | ||
/// </summary> | ||
[RegisterComponent] | ||
public sealed partial class PlantAnalyzerComponent : Component | ||
{ | ||
[DataDefinition] | ||
public partial struct PlantAnalyzerSetting | ||
{ | ||
[DataField] | ||
public bool AdvancedScan; | ||
|
||
[DataField] | ||
public float ScanDelay; | ||
|
||
[DataField] | ||
public float AdvScanDelay; | ||
} | ||
|
||
[DataField, ViewVariables] | ||
public PlantAnalyzerSetting Settings = new(); | ||
|
||
[DataField, ViewVariables(VVAccess.ReadOnly)] | ||
public DoAfterId? DoAfter; | ||
|
||
[DataField] | ||
public SoundSpecifier? ScanningEndSound; | ||
} |
Oops, something went wrong.