* Add ENERGYWATTHOURS() loc function Takes in joules (energy), displays as watt-hours. * Add simple OnOffButton control * Re-add Inset style class This was sloppily removed at some point?? Whatever, I need it. * Add helper functions for setting title/guidebook IDs on FancyWindow Reagent dispenser uses these, more in the next commits. * Add BuiPredictionState helper This enables me to implement coarse prediction manually in the battery UI. Basically it's a local buffer of predicted inputs that can easily be replayed against future BUI states from the server. * Add input coalescing infrastructure I ran into the following problem: Robust's Slider control absolutely *spams* input events, to such a degree that it actually causes issues for the networking layer if directly passed through. For something like a slider, we just need to send the most recent value. There is no good way for us to handle this in the control itself, as it *really* needs to happen in PreEngine. For simplicity reasons (for BUIs) I came to the conclusion it's best if it's there, as it's *before* any new states from the server can be applied. We can't just do this in Update() or something on the control as the timing just doesn't line up. I made a content system, BuiPreTickUpdateSystem, that runs in the ModRunLevel.PreEngine phase to achieve this. It runs a method on a new IBuiPreTickUpdate interface on all open BUIs. They can then implement their own coalescing logic. In the simplest case, this coalescing logic can just be "save the last value, and if we have any new value since the last update, send an input event." This is what the new InputCoalescer<T> type is for. Adding new coalescing logic should be possible in the future, of course. It's all just small helpers. * Battery interface This adds a proper interface to batteries (SMES/substation). Players can turn IO on and off, and they can change charge and discharge rate. There's also a ton of numbers and stuff. It looks great. This actually enables charge and discharge rates to be changed for these devices. The settings for both have been set between 5kW and 150kW. * Oops, forgot to remove these style class defs.
135 lines
4.7 KiB
C#
135 lines
4.7 KiB
C#
using System.Numerics;
|
|
using Content.Client.Guidebook;
|
|
using Content.Client.Guidebook.Components;
|
|
using Content.Shared.Guidebook;
|
|
using Robust.Client.AutoGenerated;
|
|
using Robust.Client.UserInterface.CustomControls;
|
|
using Robust.Client.UserInterface.XAML;
|
|
using Robust.Shared.Prototypes;
|
|
|
|
namespace Content.Client.UserInterface.Controls
|
|
{
|
|
[GenerateTypedNameReferences]
|
|
[Virtual]
|
|
public partial class FancyWindow : BaseWindow
|
|
{
|
|
[Dependency] private readonly IEntitySystemManager _sysMan = default!;
|
|
private GuidebookSystem? _guidebookSystem;
|
|
private const int DRAG_MARGIN_SIZE = 7;
|
|
public const string StyleClassWindowHelpButton = "windowHelpButton";
|
|
|
|
public FancyWindow()
|
|
{
|
|
RobustXamlLoader.Load(this);
|
|
|
|
CloseButton.OnPressed += _ => Close();
|
|
HelpButton.OnPressed += _ => Help();
|
|
XamlChildren = ContentsContainer.Children;
|
|
}
|
|
|
|
public string? Title
|
|
{
|
|
get => WindowTitle.Text;
|
|
set => WindowTitle.Text = value;
|
|
}
|
|
|
|
private List<ProtoId<GuideEntryPrototype>>? _helpGuidebookIds;
|
|
public List<ProtoId<GuideEntryPrototype>>? HelpGuidebookIds
|
|
{
|
|
get => _helpGuidebookIds;
|
|
set
|
|
{
|
|
_helpGuidebookIds = value;
|
|
HelpButton.Disabled = _helpGuidebookIds == null;
|
|
HelpButton.Visible = !HelpButton.Disabled;
|
|
}
|
|
}
|
|
|
|
public void Help()
|
|
{
|
|
if (HelpGuidebookIds is null)
|
|
return;
|
|
_guidebookSystem ??= _sysMan.GetEntitySystem<GuidebookSystem>();
|
|
_guidebookSystem.OpenHelp(HelpGuidebookIds);
|
|
}
|
|
|
|
protected override DragMode GetDragModeFor(Vector2 relativeMousePos)
|
|
{
|
|
var mode = DragMode.Move;
|
|
|
|
if (Resizable)
|
|
{
|
|
if (relativeMousePos.Y < DRAG_MARGIN_SIZE)
|
|
{
|
|
mode = DragMode.Top;
|
|
}
|
|
else if (relativeMousePos.Y > Size.Y - DRAG_MARGIN_SIZE)
|
|
{
|
|
mode = DragMode.Bottom;
|
|
}
|
|
|
|
if (relativeMousePos.X < DRAG_MARGIN_SIZE)
|
|
{
|
|
mode |= DragMode.Left;
|
|
}
|
|
else if (relativeMousePos.X > Size.X - DRAG_MARGIN_SIZE)
|
|
{
|
|
mode |= DragMode.Right;
|
|
}
|
|
}
|
|
|
|
return mode;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Helper functions for working with <see cref="FancyWindow"/>.
|
|
/// </summary>
|
|
public static class FancyWindowExt
|
|
{
|
|
/// <summary>
|
|
/// Sets information for a window (title and guidebooks) based on an entity.
|
|
/// </summary>
|
|
/// <param name="window">The window to modify.</param>
|
|
/// <param name="entityManager">Entity manager used to retrieve the information.</param>
|
|
/// <param name="entity">The entity that this window represents.</param>
|
|
/// <seealso cref="SetTitleFromEntity"/>
|
|
/// <seealso cref="SetGuidebookFromEntity"/>
|
|
public static void SetInfoFromEntity(this FancyWindow window, IEntityManager entityManager, EntityUid entity)
|
|
{
|
|
window.SetTitleFromEntity(entityManager, entity);
|
|
window.SetGuidebookFromEntity(entityManager, entity);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Set a window's title to the name of an entity.
|
|
/// </summary>
|
|
/// <param name="window">The window to modify.</param>
|
|
/// <param name="entityManager">Entity manager used to retrieve the information.</param>
|
|
/// <param name="entity">The entity that this window represents.</param>
|
|
/// <seealso cref="SetInfoFromEntity"/>
|
|
public static void SetTitleFromEntity(
|
|
this FancyWindow window,
|
|
IEntityManager entityManager,
|
|
EntityUid entity)
|
|
{
|
|
window.Title = entityManager.GetComponent<MetaDataComponent>(entity).EntityName;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Set a window's guidebook IDs to those of an entity.
|
|
/// </summary>
|
|
/// <param name="window">The window to modify.</param>
|
|
/// <param name="entityManager">Entity manager used to retrieve the information.</param>
|
|
/// <param name="entity">The entity that this window represents.</param>
|
|
/// <seealso cref="SetInfoFromEntity"/>
|
|
public static void SetGuidebookFromEntity(
|
|
this FancyWindow window,
|
|
IEntityManager entityManager,
|
|
EntityUid entity)
|
|
{
|
|
window.HelpGuidebookIds = entityManager.GetComponentOrNull<GuideHelpComponent>(entity)?.Guides;
|
|
}
|
|
}
|
|
}
|