malf killer 9000 (robotics console) (#24855)
* create devicenet frequencies * create borg transponder and give it to all nt borgs * add robotics console * actually implement battery charge display + some fix * tab * real explosion * little safer * disable destroy button clientside too when on cooldown * m * how do i do this when i review things... Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> * webedit ops Co-authored-by: Nemanja <98561806+EmoGarbage404@users.noreply.github.com> * ui updates * oracle java * do a thing * update ui when a borg times out * maybe fix test * add IsLocked to LockSystem * make destroying gib the chassis again, so emagging isnt sus * use locking * require using alt click to unlock so normal click is open ui * the * use LogType.Action * take this L * pocket lint? * sharer * pro ops * robor pushmarkup * m * update and make it not use prototype anymore * frame0 * update yaml * untroll * bad * h --------- Co-authored-by: deltanedas <@deltanedas:kde.org> Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Co-authored-by: Nemanja <98561806+EmoGarbage404@users.noreply.github.com>
This commit is contained in:
148
Content.Client/Robotics/UI/RoboticsConsoleWindow.xaml.cs
Normal file
148
Content.Client/Robotics/UI/RoboticsConsoleWindow.xaml.cs
Normal file
@@ -0,0 +1,148 @@
|
||||
using Content.Client.Stylesheets;
|
||||
using Content.Client.UserInterface.Controls;
|
||||
using Content.Shared.Lock;
|
||||
using Content.Shared.Robotics;
|
||||
using Content.Shared.Robotics.Components;
|
||||
using Robust.Client.AutoGenerated;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Client.UserInterface.XAML;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Timing;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Client.Robotics.UI;
|
||||
|
||||
[GenerateTypedNameReferences]
|
||||
public sealed partial class RoboticsConsoleWindow : FancyWindow
|
||||
{
|
||||
[Dependency] private readonly IEntityManager _entMan = default!;
|
||||
[Dependency] private readonly IGameTiming _timing = default!;
|
||||
[Dependency] private readonly IPrototypeManager _proto = default!;
|
||||
private readonly LockSystem _lock;
|
||||
private readonly SpriteSystem _sprite;
|
||||
|
||||
public Action<string>? OnDisablePressed;
|
||||
public Action<string>? OnDestroyPressed;
|
||||
|
||||
private Entity<RoboticsConsoleComponent, LockComponent?> _console;
|
||||
private string? _selected;
|
||||
private Dictionary<string, CyborgControlData> _cyborgs = new();
|
||||
|
||||
public RoboticsConsoleWindow(EntityUid console)
|
||||
{
|
||||
RobustXamlLoader.Load(this);
|
||||
IoCManager.InjectDependencies(this);
|
||||
|
||||
_lock = _entMan.System<LockSystem>();
|
||||
_sprite = _entMan.System<SpriteSystem>();
|
||||
|
||||
_console = (console, _entMan.GetComponent<RoboticsConsoleComponent>(console), null);
|
||||
_entMan.TryGetComponent(_console, out _console.Comp2);
|
||||
|
||||
Cyborgs.OnItemSelected += args =>
|
||||
{
|
||||
if (Cyborgs[args.ItemIndex].Metadata is not string address)
|
||||
return;
|
||||
|
||||
_selected = address;
|
||||
PopulateData();
|
||||
};
|
||||
Cyborgs.OnItemDeselected += _ =>
|
||||
{
|
||||
_selected = null;
|
||||
PopulateData();
|
||||
};
|
||||
|
||||
// these won't throw since buttons are only visible if a borg is selected
|
||||
DisableButton.OnPressed += _ =>
|
||||
{
|
||||
OnDisablePressed?.Invoke(_selected!);
|
||||
};
|
||||
DestroyButton.OnPressed += _ =>
|
||||
{
|
||||
OnDestroyPressed?.Invoke(_selected!);
|
||||
};
|
||||
|
||||
// cant put multiple styles in xaml for some reason
|
||||
DestroyButton.StyleClasses.Add(StyleBase.ButtonCaution);
|
||||
}
|
||||
|
||||
public void UpdateState(RoboticsConsoleState state)
|
||||
{
|
||||
_cyborgs = state.Cyborgs;
|
||||
|
||||
// clear invalid selection
|
||||
if (_selected is {} selected && !_cyborgs.ContainsKey(selected))
|
||||
_selected = null;
|
||||
|
||||
var hasCyborgs = _cyborgs.Count > 0;
|
||||
NoCyborgs.Visible = !hasCyborgs;
|
||||
CyborgsContainer.Visible = hasCyborgs;
|
||||
PopulateCyborgs();
|
||||
|
||||
PopulateData();
|
||||
|
||||
var locked = _lock.IsLocked((_console, _console.Comp2));
|
||||
DangerZone.Visible = !locked;
|
||||
LockedMessage.Visible = locked;
|
||||
}
|
||||
|
||||
private void PopulateCyborgs()
|
||||
{
|
||||
// _selected might get set to null when recreating so copy it first
|
||||
var selected = _selected;
|
||||
Cyborgs.Clear();
|
||||
foreach (var (address, data) in _cyborgs)
|
||||
{
|
||||
var item = Cyborgs.AddItem(data.Name, _sprite.Frame0(data.ChassisSprite!), metadata: address);
|
||||
item.Selected = address == selected;
|
||||
}
|
||||
_selected = selected;
|
||||
}
|
||||
|
||||
private void PopulateData()
|
||||
{
|
||||
if (_selected is not {} selected)
|
||||
{
|
||||
SelectCyborg.Visible = true;
|
||||
BorgContainer.Visible = false;
|
||||
return;
|
||||
}
|
||||
|
||||
SelectCyborg.Visible = false;
|
||||
BorgContainer.Visible = true;
|
||||
|
||||
var data = _cyborgs[selected];
|
||||
var model = data.ChassisName;
|
||||
|
||||
BorgSprite.Texture = _sprite.Frame0(data.ChassisSprite!);
|
||||
|
||||
var batteryColor = data.Charge switch {
|
||||
< 0.2f => "red",
|
||||
< 0.4f => "orange",
|
||||
< 0.6f => "yellow",
|
||||
< 0.8f => "green",
|
||||
_ => "blue"
|
||||
};
|
||||
|
||||
var text = new FormattedMessage();
|
||||
text.PushMarkup(Loc.GetString("robotics-console-model", ("name", model)));
|
||||
text.AddMarkup(Loc.GetString("robotics-console-designation"));
|
||||
text.AddText($" {data.Name}\n"); // prevent players trolling by naming borg [color=red]satan[/color]
|
||||
text.PushMarkup(Loc.GetString("robotics-console-battery", ("charge", (int) (data.Charge * 100f)), ("color", batteryColor)));
|
||||
text.PushMarkup(Loc.GetString("robotics-console-brain", ("brain", data.HasBrain)));
|
||||
text.AddMarkup(Loc.GetString("robotics-console-modules", ("count", data.ModuleCount)));
|
||||
BorgInfo.SetMessage(text);
|
||||
|
||||
// how the turntables
|
||||
DisableButton.Disabled = !data.HasBrain;
|
||||
DestroyButton.Disabled = _timing.CurTime < _console.Comp1.NextDestroy;
|
||||
}
|
||||
|
||||
protected override void FrameUpdate(FrameEventArgs args)
|
||||
{
|
||||
base.FrameUpdate(args);
|
||||
|
||||
DestroyButton.Disabled = _timing.CurTime < _console.Comp1.NextDestroy;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user