Merge pull request #865 from Zumorica/2020-04-28-tool-component

Tool refactor, multi tools
This commit is contained in:
Víctor Aguilera Puerto
2020-05-24 13:42:02 +02:00
committed by GitHub
50 changed files with 925 additions and 580 deletions

View File

@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using Content.Client.GameObjects.Components.Construction;
using Content.Shared.Construction;
using Content.Shared.GameObjects.Components.Interactable;
using Robust.Client.Graphics;
using Robust.Client.Interfaces.Placement;
using Robust.Client.Interfaces.ResourceManagement;
@@ -180,27 +181,27 @@ namespace Content.Client.Construction
break;
case ConstructionStepTool tool:
switch (tool.Tool)
switch (tool.ToolQuality)
{
case ConstructionStepTool.ToolType.Wrench:
case ToolQuality.Anchoring:
icon = ResourceCache.GetResource<TextureResource>("/Textures/Objects/Tools/wrench.png");
text = "Wrench";
break;
case ConstructionStepTool.ToolType.Crowbar:
case ToolQuality.Prying:
icon = ResourceCache.GetResource<TextureResource>("/Textures/Objects/Tools/crowbar.png");
text = "Crowbar";
break;
case ConstructionStepTool.ToolType.Screwdriver:
case ToolQuality.Screwing:
icon = ResourceCache.GetResource<TextureResource>(
"/Textures/Objects/Tools/screwdriver.png");
text = "Screwdriver";
break;
case ConstructionStepTool.ToolType.Welder:
case ToolQuality.Welding:
icon = ResourceCache.GetResource<RSIResource>("/Textures/Objects/tools.rsi")
.RSI["welder"].Frame0;
text = $"Welding tool ({tool.Amount} fuel)";
break;
case ConstructionStepTool.ToolType.Wirecutters:
case ToolQuality.Cutting:
icon = ResourceCache.GetResource<TextureResource>(
"/Textures/Objects/Tools/wirecutter.png");
text = "Wirecutters";

View File

@@ -0,0 +1,79 @@
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;
using Robust.Shared.GameObjects;
using Robust.Shared.Localization;
using Robust.Shared.Serialization;
using Robust.Shared.Timing;
using Robust.Shared.ViewVariables;
namespace Content.Client.GameObjects.Components.Interactable
{
[RegisterComponent]
public class MultiToolComponent : Component, IItemStatus
{
private ToolQuality _behavior;
private bool _statusShowBehavior;
[ViewVariables(VVAccess.ReadWrite)] private bool _uiUpdateNeeded;
[ViewVariables] public bool StatusShowBehavior => _statusShowBehavior;
[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", true);
}
public override void HandleComponentState(ComponentState curState, ComponentState nextState)
{
if (!(curState is MultiToolComponentState tool)) return;
_behavior = tool.Quality;
_uiUpdateNeeded = true;
}
public Control MakeControl() => new StatusControl(this);
private sealed class StatusControl : Control
{
private readonly MultiToolComponent _parent;
private readonly RichTextLabel _label;
public StatusControl(MultiToolComponent parent)
{
_parent = parent;
_label = new RichTextLabel {StyleClasses = {StyleNano.StyleClassItemStatus}};
AddChild(_label);
parent._uiUpdateNeeded = true;
}
protected override void Update(FrameEventArgs args)
{
base.Update(args);
if (!_parent._uiUpdateNeeded)
{
return;
}
_parent._uiUpdateNeeded = false;
if(!_parent.StatusShowBehavior)
_label.SetMarkup(string.Empty);
else
_label.SetMarkup(_parent.Behavior.ToString());
}
}
}
}

View File

@@ -1,39 +1,44 @@
using System;
using Content.Client.UserInterface;
using System;
using Content.Client.UserInterface.Stylesheets;
using Content.Client.Utility;
using Content.Shared.GameObjects;
using Content.Shared.GameObjects.Components;
using Content.Shared.GameObjects.Components.Interactable;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Shared.GameObjects;
using Robust.Shared.Localization;
using Robust.Shared.Serialization;
using Robust.Shared.Timing;
using Robust.Shared.ViewVariables;
namespace Content.Client.GameObjects.Components
namespace Content.Client.GameObjects.Components.Interactable
{
[RegisterComponent]
public class WelderComponent : Component, IItemStatus
public class WelderComponent : SharedToolComponent, IItemStatus
{
public override string Name => "Welder";
public override uint? NetID => ContentNetIDs.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)] private bool _uiUpdateNeeded;
public override void ExposeData(ObjectSerializer serializer)
{
}
public override void HandleComponentState(ComponentState curState, ComponentState nextState)
{
if (!(curState is WelderComponentState cast))
if (!(curState is WelderComponentState weld))
return;
FuelCapacity = cast.FuelCapacity;
Fuel = cast.Fuel;
Activated = cast.Activated;
FuelCapacity = weld.FuelCapacity;
Fuel = weld.Fuel;
Activated = weld.Activated;
_behavior = weld.Quality;
_uiUpdateNeeded = true;
}