Files
tbd-station-14/Content.Client/Actions/UI/ActionAlertTooltip.cs
keronshb 2d692f47da Action Upgrade System (#22277)
* Adds uses before delay so actions can be used multiple times before cooldown

* adds methods to get remaining charges, to set uses before delay, and to set use delay

* adds method to change action name

* moves set usedelay

* action upgrade ECS

* adds method to reset remaining uses

* adds upgrade events

* refactors action upgrade event and adds logic to parse it

* fix serialization issue

* adds level up draft method

* adds action commands and a command to upgrade an action

* more warning lines to help

* Gets action to upgrade properly

* Removes unneeded fields from the action upgrade component and now properly raises the level of the new action

* Cleans up dead code and comments

* Fixes punctuation in actions-commands and adds a TryUpgradeAction method.

* removes TODO comment

* robust fix

* removes RT

* readds RT

* update RT to 190

* removes change name method

* removes remaining uses & related fields and adds that functionality to charges

* Adds Charges to action tooltips that require it
2023-12-15 02:41:44 -07:00

111 lines
4.0 KiB
C#

using Content.Client.Stylesheets;
using Robust.Client.UserInterface.Controls;
using Robust.Shared.Timing;
using Robust.Shared.Utility;
using static Robust.Client.UserInterface.Controls.BoxContainer;
namespace Content.Client.Actions.UI
{
/// <summary>
/// Tooltip for actions or alerts because they are very similar.
/// </summary>
public sealed class ActionAlertTooltip : PanelContainer
{
private const float TooltipTextMaxWidth = 350;
private readonly RichTextLabel _cooldownLabel;
private readonly IGameTiming _gameTiming;
/// <summary>
/// Current cooldown displayed in this tooltip. Set to null to show no cooldown.
/// </summary>
public (TimeSpan Start, TimeSpan End)? Cooldown { get; set; }
public ActionAlertTooltip(FormattedMessage name, FormattedMessage? desc, string? requires = null, FormattedMessage? charges = null)
{
_gameTiming = IoCManager.Resolve<IGameTiming>();
SetOnlyStyleClass(StyleNano.StyleClassTooltipPanel);
BoxContainer vbox;
AddChild(vbox = new BoxContainer
{
Orientation = LayoutOrientation.Vertical,
RectClipContent = true
});
var nameLabel = new RichTextLabel
{
MaxWidth = TooltipTextMaxWidth,
StyleClasses = {StyleNano.StyleClassTooltipActionTitle}
};
nameLabel.SetMessage(name);
vbox.AddChild(nameLabel);
if (desc != null && !string.IsNullOrWhiteSpace(desc.ToString()))
{
var description = new RichTextLabel
{
MaxWidth = TooltipTextMaxWidth,
StyleClasses = {StyleNano.StyleClassTooltipActionDescription}
};
description.SetMessage(desc);
vbox.AddChild(description);
}
if (charges != null && !string.IsNullOrWhiteSpace(charges.ToString()))
{
var chargesLabel = new RichTextLabel
{
MaxWidth = TooltipTextMaxWidth,
StyleClasses = { StyleNano.StyleClassTooltipActionCharges }
};
chargesLabel.SetMessage(charges);
vbox.AddChild(chargesLabel);
}
vbox.AddChild(_cooldownLabel = new RichTextLabel
{
MaxWidth = TooltipTextMaxWidth,
StyleClasses = {StyleNano.StyleClassTooltipActionCooldown},
Visible = false
});
if (!string.IsNullOrWhiteSpace(requires))
{
var requiresLabel = new RichTextLabel
{
MaxWidth = TooltipTextMaxWidth,
StyleClasses = {StyleNano.StyleClassTooltipActionRequirements}
};
requiresLabel.SetMessage(FormattedMessage.FromMarkup("[color=#635c5c]" +
requires +
"[/color]"));
vbox.AddChild(requiresLabel);
}
}
protected override void FrameUpdate(FrameEventArgs args)
{
base.FrameUpdate(args);
if (!Cooldown.HasValue)
{
_cooldownLabel.Visible = false;
return;
}
var timeLeft = Cooldown.Value.End - _gameTiming.CurTime;
if (timeLeft > TimeSpan.Zero)
{
var duration = Cooldown.Value.End - Cooldown.Value.Start;
_cooldownLabel.SetMessage(FormattedMessage.FromMarkup(
$"[color=#a10505]{(int) duration.TotalSeconds} sec cooldown ({(int) timeLeft.TotalSeconds + 1} sec remaining)[/color]"));
_cooldownLabel.Visible = true;
}
else
{
_cooldownLabel.Visible = false;
}
}
}
}