Files
crystall-punk-14/Content.Shared/Tools/Systems/SharedToolSystem.Welder.cs

235 lines
9.0 KiB
C#
Raw Permalink Normal View History

using Content.Shared.ActionBlocker;
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
{
[Dependency] private readonly ActionBlockerSystem _actionBlocker = default!;
public void InitializeWelder()
{
SubscribeLocalEvent<WelderComponent, MapInitEvent>(OnWelderInit);
SubscribeLocalEvent<WelderComponent, ExaminedEvent>(OnWelderExamine);
SubscribeLocalEvent<WelderComponent, AfterInteractEvent>(OnWelderAfterInteract);
2024-06-02 22:28:53 -05:00
SubscribeLocalEvent<WelderComponent, ToolUseAttemptEvent>((uid, comp, ev) =>
{
2024-06-02 22:28:53 -05:00
CanCancelWelderUse((uid, comp), ev.User, ev.Fuel, ev);
});
SubscribeLocalEvent<WelderComponent, DoAfterAttemptEvent<ToolDoAfterEvent>>((uid, comp, ev) =>
{
2024-06-02 22:28:53 -05:00
CanCancelWelderUse((uid, comp), ev.Event.User, ev.Event.Fuel, ev);
});
SubscribeLocalEvent<WelderComponent, ToolDoAfterEvent>(OnWelderDoAfter);
2024-06-02 22:28:53 -05:00
SubscribeLocalEvent<WelderComponent, ItemToggledEvent>(OnToggle);
SubscribeLocalEvent<WelderComponent, ItemToggleActivateAttemptEvent>(OnActivateAttempt);
SubscribeLocalEvent<WelderComponent, ItemToggleDeactivateAttemptEvent>(OnDeactivateAttempt);
}
public void TurnOn(Entity<WelderComponent> entity, EntityUid? user)
{
THE RETURN OF ITEM STATUS (#22986) * 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>
2024-04-21 15:16:23 +02:00
if (!SolutionContainerSystem.TryGetSolution(entity.Owner, entity.Comp.FuelSolutionName, out var solutionComp, out _))
return;
THE RETURN OF ITEM STATUS (#22986) * 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>
2024-04-21 15:16:23 +02:00
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)
{
THE RETURN OF ITEM STATUS (#22986) * 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>
2024-04-21 15:16:23 +02:00
if (!Resolve(uid, ref welder, ref solutionContainer))
return default;
2024-09-29 03:25:21 +03:00
if (!SolutionContainerSystem.TryGetSolution(
THE RETURN OF ITEM STATUS (#22986) * 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>
2024-04-21 15:16:23 +02:00
(uid, solutionContainer),
welder.FuelSolutionName,
out _,
out var fuelSolution))
{
return default;
}
return (fuelSolution.GetTotalPrototypeQuantity(welder.FuelReagent), fuelSolution.MaxVolume);
}
private void OnWelderInit(Entity<WelderComponent> ent, ref MapInitEvent args)
{
ent.Comp.NextUpdate = _timing.CurTime + ent.Comp.WelderUpdateTimer;
Dirty(ent);
}
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)
THE RETURN OF ITEM STATUS (#22986) * 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>
2024-04-21 15:16:23 +02:00
&& 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);
THE RETURN OF ITEM STATUS (#22986) * 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>
2024-04-21 15:16:23 +02:00
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;
}
}
2024-06-02 22:28:53 -05:00
private void CanCancelWelderUse(Entity<WelderComponent> entity, EntityUid user, float requiredFuel, CancellableEntityEventArgs ev)
{
if (!ItemToggle.IsActivated(entity.Owner))
{
_popup.PopupClient(Loc.GetString("welder-component-welder-not-lit-message"), entity, user);
2024-06-02 22:28:53 -05:00
ev.Cancel();
}
2024-06-02 22:28:53 -05:00
var (currentFuel, _) = GetWelderFuelAndCapacity(entity);
2024-06-02 22:28:53 -05:00
if (requiredFuel > currentFuel)
{
_popup.PopupClient(Loc.GetString("welder-component-cannot-weld-message"), entity, user);
2024-06-02 22:28:53 -05:00
ev.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 (args.User != null && !_actionBlocker.CanComplexInteract(args.User.Value))
{
args.Cancelled = true;
return;
}
THE RETURN OF ITEM STATUS (#22986) * 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>
2024-04-21 15:16:23 +02:00
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;
}
}
private void OnDeactivateAttempt(Entity<WelderComponent> entity, ref ItemToggleDeactivateAttemptEvent args)
{
if (args.User != null && !_actionBlocker.CanComplexInteract(args.User.Value))
{
args.Cancelled = true;
}
}
private void UpdateWelders()
{
var query = EntityQueryEnumerator<WelderComponent, SolutionContainerManagerComponent>();
var curTime = _timing.CurTime;
while (query.MoveNext(out var uid, out var welder, out var solutionContainer))
{
if (curTime < welder.NextUpdate)
continue;
welder.NextUpdate += welder.WelderUpdateTimer;
Dirty(uid, welder);
if (!welder.Enabled)
continue;
if (!SolutionContainerSystem.TryGetSolution((uid, solutionContainer), welder.FuelSolutionName, out var solutionComp, out var solution))
continue;
SolutionContainerSystem.RemoveReagent(solutionComp.Value, welder.FuelReagent, welder.FuelConsumption * welder.WelderUpdateTimer.TotalSeconds);
if (solution.GetTotalPrototypeQuantity(welder.FuelReagent) <= FixedPoint2.Zero)
ItemToggle.Toggle(uid);
}
}
}