Files
wwdpublic/Content.Client/_White/UserInterface/Controls/CvarToggleableBoxContainer.cs
RedFoxIV 50b19259b8 Re: ghost (#849)
* it just works

* why hasn't it catastrophically failed yet

* not just gotta do the ui

oh god the ui

* that was easier than expected

* a devious misdirection

* touchups

* svin

* loc+fix

* touchups

* shitfix

* touchups x3

* for further use

* i hate this piece of shit engine

* touchups x4

* ribbit

also i'm retarded x2

* big tard energy

* bb

* rabbitson

* ?

* forgor

* k

* whoops

* fug
2025-09-27 08:38:24 +03:00

55 lines
1.3 KiB
C#

using Robust.Client.UserInterface.Controls;
using Robust.Shared.Configuration;
namespace Content.Client._White.UserInterface.Controls;
public sealed class CvarToggleableBoxContainer : BoxContainer
{
[Dependency] private readonly IConfigurationManager _cfg = default!;
private string? _cvar;
[ViewVariables]
public string? CVar { get => _cvar; set => Subscribe(value); }
private bool _flip;
[ViewVariables]
public bool Flip
{
get => _flip;
set
{
_flip = value;
Refresh();
}
}
public CvarToggleableBoxContainer() : base()
{
IoCManager.InjectDependencies(this);
}
private void UpdateVisibility(bool value) => Visible = value ^ _flip;
private void Subscribe(string? newCVar)
{
if (_cvar is not null)
_cfg.UnsubValueChanged<bool>(_cvar, UpdateVisibility);
if (newCVar is not null)
_cfg.OnValueChanged<bool>(newCVar, UpdateVisibility, true);
_cvar = newCVar;
}
private void Refresh()
{
if (_cvar is not null)
UpdateVisibility(_cfg.GetCVar<bool>(_cvar));
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (_cvar is not null)
_cfg.UnsubValueChanged<bool>(_cvar, UpdateVisibility);
}
}