Refactor a bunch of stuff.

This commit is contained in:
zumorica
2020-05-19 13:55:52 +02:00
parent 06c7030514
commit 06d2cc74ed
17 changed files with 153 additions and 347 deletions

View File

@@ -181,27 +181,27 @@ namespace Content.Client.Construction
break;
case ConstructionStepTool tool:
switch (tool.Tool)
switch (tool.ToolQuality)
{
case Tool.Wrench:
case ToolQuality.Anchoring:
icon = ResourceCache.GetResource<TextureResource>("/Textures/Objects/Tools/wrench.png");
text = "Wrench";
break;
case Tool.Crowbar:
case ToolQuality.Prying:
icon = ResourceCache.GetResource<TextureResource>("/Textures/Objects/Tools/crowbar.png");
text = "Crowbar";
break;
case Tool.Screwdriver:
case ToolQuality.Screwing:
icon = ResourceCache.GetResource<TextureResource>(
"/Textures/Objects/Tools/screwdriver.png");
text = "Screwdriver";
break;
case Tool.Welder:
case ToolQuality.Welding:
icon = ResourceCache.GetResource<RSIResource>("/Textures/Objects/tools.rsi")
.RSI["welder"].Frame0;
text = $"Welding tool ({tool.Amount} fuel)";
break;
case Tool.Wirecutter:
case ToolQuality.Cutting:
icon = ResourceCache.GetResource<TextureResource>(
"/Textures/Objects/Tools/wirecutter.png");
text = "Wirecutters";

View File

@@ -1,6 +1,7 @@
using System;
using Content.Client.UserInterface.Stylesheets;
using Content.Client.Utility;
using Content.Shared.GameObjects;
using Content.Shared.GameObjects.Components.Interactable;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
@@ -13,26 +14,29 @@ using Robust.Shared.ViewVariables;
namespace Content.Client.GameObjects.Components.Interactable
{
[RegisterComponent]
public class ToolComponent : SharedToolComponent, IItemStatus
public class MultiToolComponent : Component, IItemStatus
{
private Tool _behavior;
private ToolQuality _behavior;
private bool _statusShowBehavior;
[ViewVariables(VVAccess.ReadWrite)] private bool _uiUpdateNeeded;
[ViewVariables] public bool StatusShowBehavior => _statusShowBehavior;
[ViewVariables] public override Tool Behavior => _behavior;
[ViewVariables] public ToolQuality Behavior => _behavior;
public override string Name => "MultiTool";
public override uint? NetID => ContentNetIDs.MULTITOOLS;
public override void ExposeData(ObjectSerializer serializer)
{
base.ExposeData(serializer);
serializer.DataField(ref _statusShowBehavior, "statusShowBehavior", false);
serializer.DataField(ref _statusShowBehavior, "statusShowBehavior", true);
}
public override void HandleComponentState(ComponentState curState, ComponentState nextState)
{
if (!(curState is ToolComponentState tool)) return;
if (!(curState is MultiToolComponentState tool)) return;
_behavior = tool.Behavior;
_behavior = tool.Quality;
_uiUpdateNeeded = true;
}
@@ -41,10 +45,10 @@ namespace Content.Client.GameObjects.Components.Interactable
private sealed class StatusControl : Control
{
private readonly ToolComponent _parent;
private readonly MultiToolComponent _parent;
private readonly RichTextLabel _label;
public StatusControl(ToolComponent parent)
public StatusControl(MultiToolComponent parent)
{
_parent = parent;
_label = new RichTextLabel {StyleClasses = {StyleNano.StyleClassItemStatus}};

View File

@@ -14,18 +14,17 @@ using Robust.Shared.ViewVariables;
namespace Content.Client.GameObjects.Components.Interactable
{
[RegisterComponent]
[ComponentReference(typeof(ToolComponent))]
public class WelderComponent : ToolComponent, IItemStatus
public class WelderComponent : SharedToolComponent, IItemStatus
{
public override string Name => "Welder";
public override uint? NetID => ContentNetIDs.WELDER;
private Tool _behavior;
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 Tool Behavior => _behavior;
[ViewVariables] public override ToolQuality Qualities => _behavior;
public override void ExposeData(ObjectSerializer serializer)
{
@@ -39,7 +38,7 @@ namespace Content.Client.GameObjects.Components.Interactable
FuelCapacity = weld.FuelCapacity;
Fuel = weld.Fuel;
Activated = weld.Activated;
_behavior = weld.Behavior;
_behavior = weld.Quality;
_uiUpdateNeeded = true;
}
@@ -70,14 +69,11 @@ namespace Content.Client.GameObjects.Components.Interactable
_parent._uiUpdateNeeded = false;
if (_parent.Behavior == Tool.Welder)
{
var fuelCap = _parent.FuelCapacity;
var fuel = _parent.Fuel;
var fuelCap = _parent.FuelCapacity;
var fuel = _parent.Fuel;
_label.SetMarkup(Loc.GetString("Fuel: [color={0}]{1}/{2}[/color]",
fuel < fuelCap / 4f ? "darkorange" : "orange", Math.Round(fuel), fuelCap));
}
_label.SetMarkup(Loc.GetString("Fuel: [color={0}]{1}/{2}[/color]",
fuel < fuelCap / 4f ? "darkorange" : "orange", Math.Round(fuel), fuelCap));
}
}
}