* Laws * positronic brain and PAI rewrite * MMI * MMI pt. 2 * borg brain transfer * Roleban support, Borg job (WIP), the end of mind shenaniganry * battery drain, item slot cleanup, alerts * visuals * fix this pt1 * fix this pt2 * Modules, Lingering Stacks, Better borg flashlight * Start on UI, fix battery alerts, expand activation/deactivation, low movement speed on no power. * sprotes * no zombie borgs * oh fuck yeah i love a good relay * charger * fix the tiniest of sprite issues * adjustable names * a functional UI???? * foobar * more modules * this shit for some reason * upstream * genericize selectable borg modules * upstream again * holy fucking shit * i love christ * proper construction * da job * AA borgs * and boom more shit * admin logs * laws redux * ok just do this rq * oh boy that looks like modules * oh shit research * testos passo * so much shit holy fuck * fuckit we SHIP * last minute snags * should've gotten me on a better day
166 lines
5.2 KiB
C#
166 lines
5.2 KiB
C#
using Content.Client.Stylesheets;
|
|
using Content.Client.UserInterface.Controls;
|
|
using Content.Shared.NameIdentifier;
|
|
using Content.Shared.Preferences;
|
|
using Content.Shared.Silicons.Borgs;
|
|
using Content.Shared.Silicons.Borgs.Components;
|
|
using Robust.Client.AutoGenerated;
|
|
using Robust.Client.UserInterface.Controls;
|
|
using Robust.Client.UserInterface.XAML;
|
|
using Robust.Shared.Timing;
|
|
|
|
namespace Content.Client.Silicons.Borgs;
|
|
|
|
[GenerateTypedNameReferences]
|
|
public sealed partial class BorgMenu : FancyWindow
|
|
{
|
|
[Dependency] private readonly IEntityManager _entity = default!;
|
|
|
|
public Action? BrainButtonPressed;
|
|
public Action? EjectBatteryButtonPressed;
|
|
public Action<string>? NameChanged;
|
|
public Action<EntityUid>? RemoveModuleButtonPressed;
|
|
|
|
private readonly BorgChassisComponent? _chassis;
|
|
public readonly EntityUid Entity;
|
|
public float AccumulatedTime;
|
|
private string _lastValidName;
|
|
|
|
public BorgMenu(EntityUid entity)
|
|
{
|
|
RobustXamlLoader.Load(this);
|
|
IoCManager.InjectDependencies(this);
|
|
|
|
Entity = entity;
|
|
|
|
if (_entity.TryGetComponent<BorgChassisComponent>(Entity, out var chassis))
|
|
_chassis = chassis;
|
|
|
|
BorgSprite.SetEntity(entity);
|
|
ChargeBar.MaxValue = 1f;
|
|
ChargeBar.Value = 1f;
|
|
|
|
if (_entity.TryGetComponent<NameIdentifierComponent>(Entity, out var nameIdentifierComponent))
|
|
{
|
|
NameIdentifierLabel.Visible = true;
|
|
NameIdentifierLabel.Text = nameIdentifierComponent.FullIdentifier;
|
|
|
|
var fullName = _entity.GetComponent<MetaDataComponent>(Entity).EntityName;
|
|
var name = fullName.Substring(0, fullName.Length - nameIdentifierComponent.FullIdentifier.Length - 1);
|
|
NameLineEdit.Text = name;
|
|
}
|
|
else
|
|
{
|
|
NameIdentifierLabel.Visible = false;
|
|
NameLineEdit.Text = _entity.GetComponent<MetaDataComponent>(Entity).EntityName;
|
|
}
|
|
|
|
_lastValidName = NameLineEdit.Text;
|
|
|
|
EjectBatteryButton.OnPressed += _ => EjectBatteryButtonPressed?.Invoke();
|
|
BrainButton.OnPressed += _ => BrainButtonPressed?.Invoke();
|
|
|
|
NameLineEdit.OnTextChanged += OnNameChanged;
|
|
NameLineEdit.OnTextEntered += OnNameEntered;
|
|
NameLineEdit.OnFocusExit += OnNameFocusExit;
|
|
|
|
UpdateBrainButton();
|
|
}
|
|
|
|
protected override void FrameUpdate(FrameEventArgs args)
|
|
{
|
|
base.FrameUpdate(args);
|
|
|
|
AccumulatedTime += args.DeltaSeconds;
|
|
BorgSprite.OverrideDirection = (Direction) ((int) AccumulatedTime % 4 * 2);
|
|
}
|
|
|
|
public void UpdateState(BorgBuiState state)
|
|
{
|
|
EjectBatteryButton.Disabled = !state.HasBattery;
|
|
ChargeBar.Value = state.ChargePercent;
|
|
ChargeLabel.Text = Loc.GetString("borg-ui-charge-label",
|
|
("charge", (int) MathF.Round(state.ChargePercent * 100)));
|
|
|
|
UpdateBrainButton();
|
|
UpdateModulePanel();
|
|
}
|
|
|
|
private void UpdateBrainButton()
|
|
{
|
|
if (_chassis?.BrainEntity is { } brain)
|
|
{
|
|
BrainButton.Text = _entity.GetComponent<MetaDataComponent>(brain).EntityName;
|
|
BrainView.Visible = true;
|
|
BrainView.SetEntity(brain);
|
|
BrainButton.Disabled = false;
|
|
BrainButton.AddStyleClass(StyleBase.ButtonOpenLeft);
|
|
}
|
|
else
|
|
{
|
|
BrainButton.Text = Loc.GetString("borg-ui-no-brain");
|
|
BrainButton.Disabled = true;
|
|
BrainView.Visible = false;
|
|
BrainButton.RemoveStyleClass(StyleBase.ButtonOpenLeft);
|
|
}
|
|
}
|
|
|
|
private void UpdateModulePanel()
|
|
{
|
|
if (_chassis == null)
|
|
return;
|
|
|
|
ModuleCounter.Text = Loc.GetString("borg-ui-module-counter",
|
|
("actual", _chassis.ModuleCount),
|
|
("max", _chassis.MaxModules));
|
|
|
|
ModuleContainer.Children.Clear();
|
|
foreach (var module in _chassis.ModuleContainer.ContainedEntities)
|
|
{
|
|
var control = new BorgModuleControl(module, _entity);
|
|
control.RemoveButtonPressed += () =>
|
|
{
|
|
RemoveModuleButtonPressed?.Invoke(module);
|
|
};
|
|
ModuleContainer.AddChild(control);
|
|
}
|
|
}
|
|
|
|
private void OnNameChanged(LineEdit.LineEditEventArgs obj)
|
|
{
|
|
if (obj.Text.Length == 0 ||
|
|
string.IsNullOrWhiteSpace(obj.Text) ||
|
|
string.IsNullOrEmpty(obj.Text))
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (obj.Text.Length > HumanoidCharacterProfile.MaxNameLength)
|
|
{
|
|
obj.Control.Text = obj.Text.Substring(0, HumanoidCharacterProfile.MaxNameLength);
|
|
}
|
|
|
|
_lastValidName = obj.Control.Text;
|
|
obj.Control.Text = _lastValidName;
|
|
}
|
|
|
|
private void OnNameEntered(LineEdit.LineEditEventArgs obj)
|
|
{
|
|
NameChanged?.Invoke(_lastValidName);
|
|
}
|
|
|
|
private void OnNameFocusExit(LineEdit.LineEditEventArgs obj)
|
|
{
|
|
if (obj.Text.Length > HumanoidCharacterProfile.MaxNameLength ||
|
|
obj.Text.Length == 0 ||
|
|
string.IsNullOrWhiteSpace(obj.Text) ||
|
|
string.IsNullOrEmpty(obj.Text))
|
|
{
|
|
obj.Control.Text = _lastValidName.Trim();
|
|
}
|
|
|
|
NameChanged?.Invoke(_lastValidName);
|
|
}
|
|
}
|
|
|