Makes tools and welders ECS, add ToolQualityPrototype. (#4741)

This commit is contained in:
Vera Aguilera Puerto
2021-10-07 13:01:27 +02:00
committed by GitHub
parent f2760d0002
commit 365c7da4dc
44 changed files with 1144 additions and 863 deletions

View File

@@ -5,7 +5,8 @@ using Content.Client.HUD;
using Content.Client.Resources;
using Content.Shared.Construction.Prototypes;
using Content.Shared.Construction.Steps;
using Content.Shared.Tool;
using Content.Shared.Tools;
using Content.Shared.Tools.Components;
using Robust.Client.Graphics;
using Robust.Client.Placement;
using Robust.Client.ResourceManagement;
@@ -271,7 +272,7 @@ namespace Content.Client.Construction.UI
stepList.AddItem(Loc.GetString(
"construction-presenter-tool-step",
("step-number", stepNumber++),
("tool", toolStep.Tool.GetToolName())),
("tool", _prototypeManager.Index<ToolQualityPrototype>(toolStep.Tool).ToolName)),
icon);
break;
@@ -314,7 +315,7 @@ namespace Content.Client.Construction.UI
("step-number", stepNumber),
("parallel-number", parallelNumber),
("substep-number", subStepNumber++),
("tool", toolStep.Tool.GetToolName())),
("tool", _prototypeManager.Index<ToolQualityPrototype>(toolStep.Tool).ToolName)),
icon);
break;
@@ -341,7 +342,7 @@ namespace Content.Client.Construction.UI
}
}
private static Texture? GetTextureForStep(IResourceCache resourceCache, ConstructionGraphStep step)
private Texture? GetTextureForStep(IResourceCache resourceCache, ConstructionGraphStep step)
{
switch (step)
{
@@ -349,23 +350,7 @@ namespace Content.Client.Construction.UI
return materialStep.MaterialPrototype.Icon?.Frame0();
case ToolConstructionGraphStep toolStep:
switch (toolStep.Tool)
{
case ToolQuality.Anchoring:
return resourceCache.GetTexture("/Textures/Objects/Tools/wrench.rsi/icon.png");
case ToolQuality.Prying:
return resourceCache.GetTexture("/Textures/Objects/Tools/crowbar.rsi/icon.png");
case ToolQuality.Screwing:
return resourceCache.GetTexture("/Textures/Objects/Tools/screwdriver.rsi/screwdriver-map.png");
case ToolQuality.Cutting:
return resourceCache.GetTexture("/Textures/Objects/Tools/wirecutters.rsi/cutters-map.png");
case ToolQuality.Welding:
return resourceCache.GetTexture("/Textures/Objects/Tools/welder.rsi/icon.png");
case ToolQuality.Multitool:
return resourceCache.GetTexture("/Textures/Objects/Tools/multitool.rsi/icon.png");
}
break;
return _prototypeManager.Index<ToolQualityPrototype>(toolStep.Tool).Icon?.Frame0();
case ArbitraryInsertConstructionGraphStep arbitraryStep:
return arbitraryStep.Icon?.Frame0();

View File

@@ -22,11 +22,6 @@ namespace Content.Client.Entry
"FootstepModifier",
"HeatResistance",
"EntityStorage",
"Wirecutter",
"Screwdriver",
"Multitool",
"Wrench",
"Crowbar",
"MeleeWeapon",
"MeleeChemicalInjector",
"Dice",
@@ -91,6 +86,7 @@ namespace Content.Client.Entry
"TilePrying",
"RandomSpriteColor",
"ConditionalSpawner",
"DamageOnToolInteract",
"ExaminableBattery",
"PottedPlantHide",
"SecureEntityStorage",
@@ -119,7 +115,6 @@ namespace Content.Client.Entry
"SurgeryTool",
"EmitSoundOnThrow",
"Flash",
"DamageOnToolInteract",
"TrashSpawner",
"RCD",
"RCDDeconstructWhitelist",

View File

@@ -1,7 +1,7 @@
using Content.Client.Items.Components;
using Content.Client.Message;
using Content.Client.Stylesheets;
using Content.Shared.Tool;
using Content.Shared.Tools.Components;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Shared.GameObjects;
@@ -13,26 +13,23 @@ using Robust.Shared.ViewVariables;
namespace Content.Client.Tools.Components
{
[RegisterComponent]
[NetworkedComponent()]
public class MultiToolComponent : Component, IItemStatus
public class MultipleToolComponent : SharedMultipleToolComponent, IItemStatus
{
private ToolQuality _behavior;
private string? _behavior;
[DataField("statusShowBehavior")]
private bool _statusShowBehavior = true;
[ViewVariables(VVAccess.ReadWrite)] private bool _uiUpdateNeeded;
[ViewVariables] public bool StatusShowBehavior => _statusShowBehavior;
[ViewVariables] public ToolQuality? Behavior => _behavior;
public override string Name => "MultiTool";
[ViewVariables] public string? Behavior => _behavior;
public override void HandleComponentState(ComponentState? curState, ComponentState? nextState)
{
base.HandleComponentState(curState, nextState);
if (curState is not MultiToolComponentState tool) return;
if (curState is not MultipleToolComponentState tool) return;
_behavior = tool.Quality;
_behavior = tool.QualityName;
_uiUpdateNeeded = true;
}
@@ -41,10 +38,10 @@ namespace Content.Client.Tools.Components
private sealed class StatusControl : Control
{
private readonly MultiToolComponent _parent;
private readonly MultipleToolComponent _parent;
private readonly RichTextLabel _label;
public StatusControl(MultiToolComponent parent)
public StatusControl(MultipleToolComponent parent)
{
_parent = parent;
_label = new RichTextLabel {StyleClasses = {StyleNano.StyleClassItemStatus}};
@@ -64,7 +61,7 @@ namespace Content.Client.Tools.Components
_parent._uiUpdateNeeded = false;
_label.SetMarkup(_parent.StatusShowBehavior ? _parent.Behavior.ToString() ?? string.Empty : string.Empty);
_label.SetMarkup(_parent.StatusShowBehavior ? _parent.Behavior ?? string.Empty : string.Empty);
}
}
}

View File

@@ -2,43 +2,30 @@ using System;
using Content.Client.Items.Components;
using Content.Client.Message;
using Content.Client.Stylesheets;
using Content.Shared.Tool;
using Content.Shared.Tools.Components;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Shared.Analyzers;
using Robust.Shared.GameObjects;
using Robust.Shared.GameStates;
using Robust.Shared.Localization;
using Robust.Shared.Timing;
using Robust.Shared.ViewVariables;
namespace Content.Client.Tools.Components
{
[RegisterComponent]
[NetworkedComponent()]
public class WelderComponent : SharedToolComponent, IItemStatus
[RegisterComponent, Friend(typeof(ToolSystem), typeof(StatusControl))]
public class WelderComponent : SharedWelderComponent, IItemStatus
{
public override string Name => "Welder";
private ToolQuality _behavior;
[ViewVariables(VVAccess.ReadWrite)] private bool _uiUpdateNeeded;
[ViewVariables] public float FuelCapacity { get; private set; }
[ViewVariables] public float Fuel { get; private set; }
[ViewVariables] public bool Activated { get; private set; }
[ViewVariables] public override ToolQuality Qualities => _behavior;
[ViewVariables(VVAccess.ReadWrite)]
public bool UiUpdateNeeded { get; set; }
public override void HandleComponentState(ComponentState? curState, ComponentState? nextState)
{
base.HandleComponentState(curState, nextState);
[ViewVariables]
public float FuelCapacity { get; set; }
if (curState is not WelderComponentState weld)
return;
FuelCapacity = weld.FuelCapacity;
Fuel = weld.Fuel;
Activated = weld.Activated;
_behavior = weld.Quality;
_uiUpdateNeeded = true;
}
[ViewVariables]
public float Fuel { get; set; }
public Control MakeControl() => new StatusControl(this);
@@ -53,7 +40,7 @@ namespace Content.Client.Tools.Components
_label = new RichTextLabel {StyleClasses = {StyleNano.StyleClassItemStatus}};
AddChild(_label);
parent._uiUpdateNeeded = true;
parent.UiUpdateNeeded = true;
}
/// <inheritdoc />
@@ -61,12 +48,12 @@ namespace Content.Client.Tools.Components
{
base.FrameUpdate(args);
if (!_parent._uiUpdateNeeded)
if (!_parent.UiUpdateNeeded)
{
return;
}
_parent._uiUpdateNeeded = false;
_parent.UiUpdateNeeded = false;
var fuelCap = _parent.FuelCapacity;
var fuel = _parent.Fuel;

View File

@@ -0,0 +1,28 @@
using Content.Client.Tools.Components;
using Content.Shared.Tools.Components;
using Robust.Shared.GameObjects;
using Robust.Shared.GameStates;
namespace Content.Client.Tools
{
public class ToolSystem : EntitySystem
{
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<WelderComponent, ComponentHandleState>(OnWelderHandleState);
}
private void OnWelderHandleState(EntityUid uid, WelderComponent welder, ref ComponentHandleState args)
{
if (args.Current is not WelderComponentState state)
return;
welder.FuelCapacity = state.FuelCapacity;
welder.Fuel = state.Fuel;
welder.Lit = state.Lit;
welder.UiUpdateNeeded = true;
}
}
}