* THE RETURN OF ITEM STATUS Item status is now inline with the hands again. You can now see item status for both hands at once. If you have more than 2 hands, the last active hand of that side is displayed in the respective item status. The item status for the active hand is also highlighted. Item status has been given a new look so it looks unique and matches every UI theme. * Shrink item status to 125px This is going to require fixing the existing controls. Do that later. * New bullet item status rendering sex * Make gun item status look just a little bit nicer. Avoid only one or two bullets ending up on a single row of an item status. * Delete Eris theme files * More improvements Fixed the fact that left/right were flipped around when assigning status panel locations. Involved renaming all the UI textures. Redid how content margins are set from the theme. Less complex and cleaner now. Made the item name always left-aligned, just looks better since other UI elements don't adapt anyways. * Compact down item status text Now it fits 3 lines of text on one line. Yay. This is achieved by compacting RichTextLabels by reducing their line height and giving them a negative bottom margin. * Add item status sprites for Ashen theme. * Add status control to show beaker/bucket/jug solution/transfer volumes Also PollingItemStatusControl I'll be using that more. * Fix welder item status, clean up welder code The item status control implementation was ancient and bad. That's why it was buggy. Removed all the complex dated networking stuff for welders, we just sync the solution contents now anyways so none of that is needed anymore. This moves a buncha stuff to shared and just removes code. Cleanup. The code was doing some really dumb stuff. * Spray bottles show contents in item status. * cowtools * Fix plasmafire and clockwork themes. Actual git gaslighting wtf. --------- Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
179 lines
6.9 KiB
C#
179 lines
6.9 KiB
C#
using Content.Shared.Chemistry.Components;
|
|
using Content.Shared.Chemistry.Components.SolutionManager;
|
|
using Content.Shared.Database;
|
|
using Content.Shared.DoAfter;
|
|
using Content.Shared.Examine;
|
|
using Content.Shared.FixedPoint;
|
|
using Content.Shared.Interaction;
|
|
using Content.Shared.Item.ItemToggle.Components;
|
|
using Content.Shared.Tools.Components;
|
|
|
|
namespace Content.Shared.Tools.Systems;
|
|
|
|
public abstract partial class SharedToolSystem
|
|
{
|
|
public void InitializeWelder()
|
|
{
|
|
SubscribeLocalEvent<WelderComponent, ExaminedEvent>(OnWelderExamine);
|
|
SubscribeLocalEvent<WelderComponent, AfterInteractEvent>(OnWelderAfterInteract);
|
|
SubscribeLocalEvent<WelderComponent, DoAfterAttemptEvent<ToolDoAfterEvent>>(OnWelderToolUseAttempt);
|
|
SubscribeLocalEvent<WelderComponent, ToolDoAfterEvent>(OnWelderDoAfter);
|
|
SubscribeLocalEvent<WelderComponent, ItemToggledEvent>(OnToggle);
|
|
SubscribeLocalEvent<WelderComponent, ItemToggleActivateAttemptEvent>(OnActivateAttempt);
|
|
}
|
|
|
|
public virtual void TurnOn(Entity<WelderComponent> entity, EntityUid? user)
|
|
{
|
|
if (!SolutionContainerSystem.TryGetSolution(entity.Owner, entity.Comp.FuelSolutionName, out var solutionComp, out _))
|
|
return;
|
|
|
|
SolutionContainerSystem.RemoveReagent(solutionComp.Value, entity.Comp.FuelReagent, entity.Comp.FuelLitCost);
|
|
AdminLogger.Add(LogType.InteractActivate, LogImpact.Low,
|
|
$"{ToPrettyString(user):user} toggled {ToPrettyString(entity.Owner):welder} on");
|
|
|
|
entity.Comp.Enabled = true;
|
|
Dirty(entity, entity.Comp);
|
|
}
|
|
|
|
public void TurnOff(Entity<WelderComponent> entity, EntityUid? user)
|
|
{
|
|
AdminLogger.Add(LogType.InteractActivate, LogImpact.Low,
|
|
$"{ToPrettyString(user):user} toggled {ToPrettyString(entity.Owner):welder} off");
|
|
entity.Comp.Enabled = false;
|
|
Dirty(entity, entity.Comp);
|
|
}
|
|
|
|
public (FixedPoint2 fuel, FixedPoint2 capacity) GetWelderFuelAndCapacity(EntityUid uid, WelderComponent? welder = null, SolutionContainerManagerComponent? solutionContainer = null)
|
|
{
|
|
if (!Resolve(uid, ref welder, ref solutionContainer))
|
|
return default;
|
|
|
|
if (!SolutionContainer.TryGetSolution(
|
|
(uid, solutionContainer),
|
|
welder.FuelSolutionName,
|
|
out _,
|
|
out var fuelSolution))
|
|
{
|
|
return default;
|
|
}
|
|
|
|
return (fuelSolution.GetTotalPrototypeQuantity(welder.FuelReagent), fuelSolution.MaxVolume);
|
|
}
|
|
|
|
private void OnWelderExamine(Entity<WelderComponent> entity, ref ExaminedEvent args)
|
|
{
|
|
using (args.PushGroup(nameof(WelderComponent)))
|
|
{
|
|
if (ItemToggle.IsActivated(entity.Owner))
|
|
{
|
|
args.PushMarkup(Loc.GetString("welder-component-on-examine-welder-lit-message"));
|
|
}
|
|
else
|
|
{
|
|
args.PushMarkup(Loc.GetString("welder-component-on-examine-welder-not-lit-message"));
|
|
}
|
|
|
|
if (args.IsInDetailsRange)
|
|
{
|
|
var (fuel, capacity) = GetWelderFuelAndCapacity(entity.Owner, entity.Comp);
|
|
|
|
args.PushMarkup(Loc.GetString("welder-component-on-examine-detailed-message",
|
|
("colorName", fuel < capacity / FixedPoint2.New(4f) ? "darkorange" : "orange"),
|
|
("fuelLeft", fuel),
|
|
("fuelCapacity", capacity),
|
|
("status", string.Empty))); // Lit status is handled above
|
|
}
|
|
}
|
|
}
|
|
|
|
private void OnWelderAfterInteract(Entity<WelderComponent> entity, ref AfterInteractEvent args)
|
|
{
|
|
if (args.Handled)
|
|
return;
|
|
|
|
if (args.Target is not { Valid: true } target || !args.CanReach)
|
|
return;
|
|
|
|
if (TryComp(target, out ReagentTankComponent? tank)
|
|
&& tank.TankType == ReagentTankType.Fuel
|
|
&& SolutionContainerSystem.TryGetDrainableSolution(target, out var targetSoln, out var targetSolution)
|
|
&& SolutionContainerSystem.TryGetSolution(entity.Owner, entity.Comp.FuelSolutionName, out var solutionComp, out var welderSolution))
|
|
{
|
|
var trans = FixedPoint2.Min(welderSolution.AvailableVolume, targetSolution.Volume);
|
|
if (trans > 0)
|
|
{
|
|
var drained = SolutionContainerSystem.Drain(target, targetSoln.Value, trans);
|
|
SolutionContainerSystem.TryAddSolution(solutionComp.Value, drained);
|
|
_audioSystem.PlayPredicted(entity.Comp.WelderRefill, entity, user: args.User);
|
|
_popup.PopupClient(Loc.GetString("welder-component-after-interact-refueled-message"), entity, args.User);
|
|
}
|
|
else if (welderSolution.AvailableVolume <= 0)
|
|
{
|
|
_popup.PopupClient(Loc.GetString("welder-component-already-full"), entity, args.User);
|
|
}
|
|
else
|
|
{
|
|
_popup.PopupClient(Loc.GetString("welder-component-no-fuel-in-tank", ("owner", args.Target)), entity, args.User);
|
|
}
|
|
|
|
args.Handled = true;
|
|
}
|
|
}
|
|
|
|
private void OnWelderToolUseAttempt(Entity<WelderComponent> entity, ref DoAfterAttemptEvent<ToolDoAfterEvent> args)
|
|
{
|
|
var user = args.DoAfter.Args.User;
|
|
|
|
if (!ItemToggle.IsActivated(entity.Owner))
|
|
{
|
|
_popup.PopupClient(Loc.GetString("welder-component-welder-not-lit-message"), entity, user);
|
|
args.Cancel();
|
|
return;
|
|
}
|
|
|
|
var (fuel, _) = GetWelderFuelAndCapacity(entity);
|
|
|
|
if (args.Event.Fuel > fuel)
|
|
{
|
|
_popup.PopupClient(Loc.GetString("welder-component-cannot-weld-message"), entity, user);
|
|
args.Cancel();
|
|
}
|
|
}
|
|
|
|
private void OnWelderDoAfter(Entity<WelderComponent> ent, ref ToolDoAfterEvent args)
|
|
{
|
|
if (args.Cancelled)
|
|
return;
|
|
|
|
if (!SolutionContainerSystem.TryGetSolution(ent.Owner, ent.Comp.FuelSolutionName, out var solution))
|
|
return;
|
|
|
|
SolutionContainerSystem.RemoveReagent(solution.Value, ent.Comp.FuelReagent, FixedPoint2.New(args.Fuel));
|
|
}
|
|
|
|
private void OnToggle(Entity<WelderComponent> entity, ref ItemToggledEvent args)
|
|
{
|
|
if (args.Activated)
|
|
TurnOn(entity, args.User);
|
|
else
|
|
TurnOff(entity, args.User);
|
|
}
|
|
|
|
private void OnActivateAttempt(Entity<WelderComponent> entity, ref ItemToggleActivateAttemptEvent args)
|
|
{
|
|
if (!SolutionContainerSystem.TryGetSolution(entity.Owner, entity.Comp.FuelSolutionName, out _, out var solution))
|
|
{
|
|
args.Cancelled = true;
|
|
args.Popup = Loc.GetString("welder-component-no-fuel-message");
|
|
return;
|
|
}
|
|
|
|
var fuel = solution.GetTotalPrototypeQuantity(entity.Comp.FuelReagent);
|
|
if (fuel == FixedPoint2.Zero || fuel < entity.Comp.FuelLitCost)
|
|
{
|
|
args.Popup = Loc.GetString("welder-component-no-fuel-message");
|
|
args.Cancelled = true;
|
|
}
|
|
}
|
|
}
|