Files
wwdpublic/Content.Client/Robotics/UI/RoboticsConsoleWindow.xaml.cs
Kai5 b86ec297b2 [Port Feature] И снова ИИ кукловод (#567)
* B.O.R.I.S ai remote control brain (#380)

* ai remote brain

* system fixes, code formatting

* fixes

(cherry picked from commit 1fc1d81e74254df82b48e57af272a0abaf795843)

* B.O.R.I.S ai remote control brain (#380)

* ai remote brain

* system fixes, code formatting

* fixes

(cherry picked from commit 1fc1d81e74254df82b48e57af272a0abaf795843)

* Фикс локализации

* Фикс локализации 2

* Update Content.Shared/Silicons/StationAi/SharedStationAiSystem.Held.cs

Co-authored-by: Spatison <137375981+Spatison@users.noreply.github.com>

* Update Content.Shared/Robotics/RoboticsConsoleUi.cs

Co-authored-by: Spatison <137375981+Spatison@users.noreply.github.com>

* Update Content.Shared/_CorvaxNext/Silicons/Borgs/Components/AiRemoteBrainComponent.cs

Co-authored-by: Spatison <137375981+Spatison@users.noreply.github.com>

* Update Content.Shared/Robotics/RoboticsConsoleUi.cs

Co-authored-by: Spatison <137375981+Spatison@users.noreply.github.com>

* Update Content.Shared/Robotics/RoboticsConsoleUi.cs

Co-authored-by: Spatison <137375981+Spatison@users.noreply.github.com>

* Update Content.Shared/Silicons/Laws/SharedSiliconLawSystem.cs

Co-authored-by: Spatison <137375981+Spatison@users.noreply.github.com>

* Update Content.Shared/_CorvaxNext/Silicons/Borgs/Components/SharedAiRemoteControllerComponent.cs

Co-authored-by: Spatison <137375981+Spatison@users.noreply.github.com>

* Да

* Теперь должно работать

* Окончательный перенос всякого

* неймспейсы

* Some fix

* fix locale

* blya

---------

Co-authored-by: KillanGenifer <157119956+killangenifer@users.noreply.github.com>
Co-authored-by: Spatison <137375981+Spatison@users.noreply.github.com>
2025-06-16 21:12:42 +03:00

167 lines
5.0 KiB
C#

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!;
private readonly LockSystem _lock;
private readonly SpriteSystem _sprite;
public Action<string>? OnDisablePressed;
public Action<string>? OnDestroyPressed;
private string? _selected;
private Dictionary<string, CyborgControlData> _cyborgs = new();
public EntityUid Entity;
public RoboticsConsoleWindow()
{
RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this);
_lock = _entMan.System<LockSystem>();
_sprite = _entMan.System<SpriteSystem>();
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 SetEntity(EntityUid uid)
{
Entity = uid;
}
public void UpdateState(RoboticsConsoleState state)
{
_cyborgs = state.Cyborgs;
// clear invalid selection
if (_selected is {} selected && !_cyborgs.ContainsKey(selected))
_selected = null;
// WD edit - AiRemoteControl-Start
var isAiControllable = false;
if (_selected != null)
{
_cyborgs.TryGetValue(_selected, out var data);
isAiControllable = data.IsAiControllable;
}
// WD edit - AiRemoteControl-End
var hasCyborgs = _cyborgs.Count > 0;
NoCyborgs.Visible = !hasCyborgs;
CyborgsContainer.Visible = hasCyborgs;
PopulateCyborgs();
PopulateData();
var locked = _lock.IsLocked(Entity);
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 && data.CanDisable);
}
protected override void FrameUpdate(FrameEventArgs args)
{
base.FrameUpdate(args);
if (_entMan.TryGetComponent(Entity, out RoboticsConsoleComponent? console))
{
DestroyButton.Disabled = _timing.CurTime < console.NextDestroy;
}
else
{
DestroyButton.Disabled = true;
}
}
}