CatStation/Content.Client/Power/UI/BatteryStatusControl.cs
Samuka 838984971c
Xenoborg guided missile (#45247)
* update math

* target finder system

* ports

* guns with projectiles

* make sure

* custom sprites for the laser

* add auto link

* add module

* sprite for the missile

* update animation speed

* ops

* make it glow

* overlay sprite

* stuff that doesn't work

* update launcher

* fix it

* make it see from far

* make it work

* sprite for the module

* 30 seconds is too much

* sprite for the range finder

* why was that here?

* update sprite of the missile

* update module icon

* ops

* update missile and missile launcher

* make it look like the launcher item

* remove ammo counter from range finder

* increase to 15 seconds

* no longer show the battery percentage

* use comp

* change summary

* ops

* new line

* make it last longer

* commentary

* acme moment

* fix bug when shooter was also the target and the projectile wouldn't move

* empty commit

* fix test fail

* replace with global behavior

* forgot to remove from the yml

* important

* check to see if the target exists

* fix autorefill bug

* remove unused system

* make it reload a tad slower

---------

Co-authored-by: beck-thompson <beck314159@hotmail.com>
2026-08-16 05:10:57 +00:00

82 lines
3 KiB
C#

using Content.Client.Items.UI;
using Content.Client.Message;
using Content.Client.Power.EntitySystems;
using Content.Client.Stylesheets;
using Content.Client.Weapons.Ranged.Components;
using Content.Shared.Item.ItemToggle.Components;
using Content.Shared.PowerCell;
using Content.Shared.PowerCell.Components;
using Content.Shared.Power.EntitySystems;
using Robust.Client.UserInterface.Controls;
namespace Content.Client.Power.UI;
/// <summary>
/// Displays battery charge information for entities with <see cref="BatteryItemStatusComponent"/>.
/// </summary>
/// <seealso cref="BatteryItemStatusSystem"/>
public sealed partial class BatteryStatusControl : PollingItemStatusControl<BatteryStatusControl.Data>
{
private readonly EntityUid _parent;
private readonly IEntityManager _entityManager;
private readonly SharedBatterySystem _battery;
private readonly PowerCellSystem _powerCell;
private readonly RichTextLabel _label;
public BatteryStatusControl(
EntityUid parent,
IEntityManager entityManager,
SharedBatterySystem battery,
PowerCellSystem powerCell)
{
_parent = parent;
_entityManager = entityManager;
_battery = battery;
_powerCell = powerCell;
_label = new RichTextLabel { StyleClasses = { StyleClass.ItemStatus } };
AddChild(_label);
}
protected override Data PollData()
{
// Do not add battery status to guns that already show an ammo counter.
if (_entityManager.HasComponent<AmmoCounterComponent>(_parent))
return default;
// Battery charge level.
int? chargePercent = null;
if (_powerCell.TryGetBatteryFromEntityOrSlot(_parent, out var battery))
chargePercent = (int)(_battery.GetChargeLevel(battery.Value.AsNullable()) * 100);
if (battery is not null && !battery.Value.Comp.ShowItemStatus)
return default;
// On/off state.
bool? toggleState = null;
if (_entityManager.TryGetComponent<ItemToggleComponent>(_parent, out var toggle))
toggleState = toggle.Activated;
else if (_entityManager.TryGetComponent<PowerCellDrawComponent>(_parent, out var powerDraw))
toggleState = powerDraw.Enabled;
return new Data(chargePercent, toggleState);
}
protected override void Update(in Data data)
{
var markup = "";
if (data.ChargePercent.HasValue)
markup = Loc.GetString("battery-status-charge", ("percent", data.ChargePercent));
if (data.ToggleState.HasValue)
{
var stateValue = data.ToggleState.Value ? "on" : "off";
var stateColor = Loc.GetString("battery-status-switchable-state", ("state", stateValue));
var stateLine = Loc.GetString("battery-status-state", ("state", stateColor));
markup += "\n" + stateLine;
}
_label.SetMarkup(markup);
}
public readonly record struct Data(int? ChargePercent, bool? ToggleState);
}