Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Station AI #30944

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
dc99cb3
Station AI overlay
metalgearsloth Aug 12, 2024
be541eb
implement
metalgearsloth Aug 12, 2024
0bb9a18
Bunch of ports
metalgearsloth Aug 14, 2024
f0a21a1
Fix a heap of bugs and basic scouting
metalgearsloth Aug 15, 2024
cbdfd2f
helldivers
metalgearsloth Aug 15, 2024
0a8d73f
Shuffle interactions a bit
metalgearsloth Aug 15, 2024
d1f89dd
navmap stuff
metalgearsloth Aug 15, 2024
3c32123
Revert "navmap stuff"
metalgearsloth Aug 15, 2024
45e87a4
AI wires implemented
metalgearsloth Aug 15, 2024
0c5b54f
Fix examines
metalgearsloth Aug 15, 2024
8222fc7
Optimise the overlay significantly
metalgearsloth Aug 16, 2024
d7a4a69
Back to old static
metalgearsloth Aug 16, 2024
951b4ee
BUI radial working
metalgearsloth Aug 18, 2024
128530a
lots of work
metalgearsloth Aug 18, 2024
31affd8
Saving work
metalgearsloth Aug 18, 2024
173ee91
thanks fork
metalgearsloth Aug 18, 2024
a817da9
alright
metalgearsloth Aug 19, 2024
df7a2b2
pc
metalgearsloth Aug 19, 2024
d88accf
AI upload console
metalgearsloth Aug 19, 2024
fc57c84
AI upload
metalgearsloth Aug 20, 2024
a3d03db
stuff
metalgearsloth Aug 20, 2024
e89b0fc
Merge remote-tracking branch 'upstream/master' into 2024-08-12-statio…
metalgearsloth Aug 22, 2024
ce88a0a
Merge remote-tracking branch 'upstream/master' into 2024-08-12-statio…
metalgearsloth Aug 22, 2024
f6ab795
Fix copy-paste shitcode
metalgearsloth Aug 22, 2024
9249980
AI actions
metalgearsloth Aug 22, 2024
6f63fea
navmap work
metalgearsloth Aug 23, 2024
8536cf4
Fixes
metalgearsloth Aug 24, 2024
e073883
Merge remote-tracking branch 'upstream/master' into 2024-08-12-statio…
metalgearsloth Aug 25, 2024
b19ce4e
first impressions
metalgearsloth Aug 25, 2024
d388ae5
a
metalgearsloth Aug 25, 2024
1ebc89d
reh
metalgearsloth Aug 25, 2024
67c79e8
Revert "navmap work"
metalgearsloth Aug 25, 2024
d61f206
OD
metalgearsloth Aug 25, 2024
f5cc305
radar
metalgearsloth Aug 25, 2024
225a694
weh
metalgearsloth Aug 25, 2024
91cad40
Fix examines
metalgearsloth Aug 25, 2024
99b3f0a
scoop mine eyes
metalgearsloth Aug 25, 2024
42bcb76
Merge remote-tracking branch 'upstream/master' into 2024-08-12-statio…
metalgearsloth Aug 25, 2024
a28fd8a
Merge remote-tracking branch 'upstream/master' into 2024-08-12-statio…
metalgearsloth Aug 25, 2024
05e0a96
fixes
metalgearsloth Aug 25, 2024
8b79225
reh
metalgearsloth Aug 25, 2024
2f1cd54
Merge remote-tracking branch 'upstream/master' into 2024-08-12-statio…
metalgearsloth Aug 26, 2024
4c635d4
Optimise
metalgearsloth Aug 26, 2024
369216e
Final round of optimisations
metalgearsloth Aug 26, 2024
b4b1a78
Merge remote-tracking branch 'upstream/master' into 2024-08-12-statio…
metalgearsloth Aug 27, 2024
05839d1
Fixes
metalgearsloth Aug 28, 2024
c394c76
fixes
metalgearsloth Aug 28, 2024
c6b7c8c
Merge remote-tracking branch 'upstream/master' into 2024-08-12-statio…
metalgearsloth Aug 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions Content.Client/Chat/UI/EmotesMenu.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,15 @@ public sealed partial class EmotesMenu : RadialMenu
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly ISharedPlayerManager _playerManager = default!;

private readonly SpriteSystem _spriteSystem;
private readonly EntityWhitelistSystem _whitelistSystem;

public event Action<ProtoId<EmotePrototype>>? OnPlayEmote;

public EmotesMenu()
{
IoCManager.InjectDependencies(this);
RobustXamlLoader.Load(this);

_spriteSystem = _entManager.System<SpriteSystem>();
_whitelistSystem = _entManager.System<EntityWhitelistSystem>();
var spriteSystem = _entManager.System<SpriteSystem>();
var whitelistSystem = _entManager.System<EntityWhitelistSystem>();

var main = FindControl<RadialContainer>("Main");

Expand All @@ -40,8 +37,8 @@ public EmotesMenu()
var player = _playerManager.LocalSession?.AttachedEntity;
if (emote.Category == EmoteCategory.Invalid ||
emote.ChatTriggers.Count == 0 ||
!(player.HasValue && _whitelistSystem.IsWhitelistPassOrNull(emote.Whitelist, player.Value)) ||
_whitelistSystem.IsBlacklistPass(emote.Blacklist, player.Value))
!(player.HasValue && whitelistSystem.IsWhitelistPassOrNull(emote.Whitelist, player.Value)) ||
whitelistSystem.IsBlacklistPass(emote.Blacklist, player.Value))
continue;

if (!emote.Available &&
Expand All @@ -63,7 +60,7 @@ public EmotesMenu()
{
VerticalAlignment = VAlignment.Center,
HorizontalAlignment = HAlignment.Center,
Texture = _spriteSystem.Frame0(emote.Icon),
Texture = spriteSystem.Frame0(emote.Icon),
TextureScale = new Vector2(2f, 2f),
};

Expand Down
20 changes: 17 additions & 3 deletions Content.Client/Lobby/UI/Loadouts/LoadoutWindow.xaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
<controls:FancyWindow xmlns="https://spacestation14.io"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls"
xmlns:graphics="clr-namespace:Robust.Client.Graphics;assembly=Robust.Client"
SetSize="800 800"
MinSize="800 64">
MinSize="800 128">
<BoxContainer Orientation="Vertical" VerticalExpand="True">
<!--
<BoxContainer Name="RoleNameBox" Orientation="Vertical" Margin="10">
<Label Name="LoadoutNameLabel" Text="{Loc 'loadout-name-edit-label'}"/>
<PanelContainer HorizontalExpand="True" SetHeight="24">
<PanelContainer.PanelOverride>
<graphics:StyleBoxFlat BackgroundColor="#1B1B1E" />
</PanelContainer.PanelOverride>
<LineEdit Name="RoleNameEdit" ToolTip="{Loc 'loadout-name-edit-tooltip'}" VerticalExpand="True" HorizontalExpand="True"/>
</PanelContainer>
</BoxContainer>
-->
<VerticalTabContainer Name="LoadoutGroupsContainer"
VerticalExpand="True"
HorizontalExpand="True">
VerticalExpand="True"
HorizontalExpand="True">
</VerticalTabContainer>
</BoxContainer>
</controls:FancyWindow>
43 changes: 27 additions & 16 deletions Content.Client/Lobby/UI/Loadouts/LoadoutWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using System.Numerics;
using Content.Client.UserInterface.Controls;
using Content.Shared.Preferences;
using Content.Shared.Preferences.Loadouts;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Player;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;

namespace Content.Client.Lobby.UI.Loadouts;

Expand All @@ -24,27 +26,36 @@ public LoadoutWindow(HumanoidCharacterProfile profile, RoleLoadout loadout, Role
Profile = profile;
var protoManager = collection.Resolve<IPrototypeManager>();

foreach (var group in proto.Groups)
// Hide if no groups
if (proto.Groups.Count == 0)
{
if (!protoManager.TryIndex(group, out var groupProto))
continue;
LoadoutGroupsContainer.Visible = false;
SetSize = Vector2.Zero;
}
else
{
foreach (var group in proto.Groups)
{
if (!protoManager.TryIndex(group, out var groupProto))
continue;

if (groupProto.Hidden)
continue;
if (groupProto.Hidden)
continue;

var container = new LoadoutGroupContainer(profile, loadout, protoManager.Index(group), session, collection);
LoadoutGroupsContainer.AddTab(container, Loc.GetString(groupProto.Name));
_groups.Add(container);
var container = new LoadoutGroupContainer(profile, loadout, protoManager.Index(group), session, collection);
LoadoutGroupsContainer.AddTab(container, Loc.GetString(groupProto.Name));
_groups.Add(container);

container.OnLoadoutPressed += args =>
{
OnLoadoutPressed?.Invoke(group, args);
};
container.OnLoadoutPressed += args =>
{
OnLoadoutPressed?.Invoke(group, args);
};

container.OnLoadoutUnpressed += args =>
{
OnLoadoutUnpressed?.Invoke(group, args);
};
container.OnLoadoutUnpressed += args =>
{
OnLoadoutUnpressed?.Invoke(group, args);
};
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Content.Client.Silicons.Laws.SiliconLawEditUi;

public sealed class SiliconLawEui : BaseEui
{
public readonly EntityManager _entityManager = default!;
private readonly EntityManager _entityManager;

private SiliconLawUi _siliconLawUi;
private EntityUid _target;
Expand Down
28 changes: 28 additions & 0 deletions Content.Client/Silicons/StationAi/StationAiBoundUserInterface.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using Content.Shared.Silicons.StationAi;
using Robust.Client.UserInterface;

namespace Content.Client.Silicons.StationAi;

public sealed class StationAiBoundUserInterface : BoundUserInterface
{
private StationAiMenu? _menu;

public StationAiBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
{
}

protected override void Open()
{
base.Open();
_menu = this.CreateWindow<StationAiMenu>();
_menu.Track(Owner);

_menu.OnAiRadial += args =>
{
SendPredictedMessage(new StationAiRadialMessage()
{
Event = args,
});
};
}
}
13 changes: 13 additions & 0 deletions Content.Client/Silicons/StationAi/StationAiMenu.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<ui:RadialMenu xmlns="https://spacestation14.io"
xmlns:ui="clr-namespace:Content.Client.UserInterface.Controls"
BackButtonStyleClass="RadialMenuBackButton"
CloseButtonStyleClass="RadialMenuCloseButton"
VerticalExpand="True"
HorizontalExpand="True"
MinSize="450 450">

<!-- Main -->
<ui:RadialContainer Name="Main" VerticalExpand="True" HorizontalExpand="True" Radius="64" ReserveSpaceForHiddenChildren="False">
</ui:RadialContainer>

</ui:RadialMenu>
128 changes: 128 additions & 0 deletions Content.Client/Silicons/StationAi/StationAiMenu.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
using System.Numerics;
using Content.Client.UserInterface.Controls;
using Content.Shared.Silicons.StationAi;
using Robust.Client.AutoGenerated;
using Robust.Client.GameObjects;
using Robust.Client.Graphics;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Timing;

namespace Content.Client.Silicons.StationAi;

[GenerateTypedNameReferences]
public sealed partial class StationAiMenu : RadialMenu
{
[Dependency] private readonly IClyde _clyde = default!;
[Dependency] private readonly IEntityManager _entManager = default!;
[Dependency] private readonly IEyeManager _eyeManager = default!;

public event Action<BaseStationAiAction>? OnAiRadial;

private EntityUid _tracked;

public StationAiMenu()
{
IoCManager.InjectDependencies(this);
RobustXamlLoader.Load(this);
}

public void Track(EntityUid owner)
{
_tracked = owner;

if (!_entManager.EntityExists(_tracked))
{
Close();
return;
}

BuildButtons();
UpdatePosition();
}

private void BuildButtons()
{
var ev = new GetStationAiRadialEvent();
_entManager.EventBus.RaiseLocalEvent(_tracked, ref ev);

var main = FindControl<RadialContainer>("Main");
main.DisposeAllChildren();
var sprites = _entManager.System<SpriteSystem>();

foreach (var action in ev.Actions)
{
// TODO: This radial boilerplate is quite annoying
var button = new StationAiMenuButton(action.Event)
{
StyleClasses = { "RadialMenuButton" },
SetSize = new Vector2(64f, 64f),
ToolTip = action.Tooltip != null ? Loc.GetString(action.Tooltip) : null,
};

if (action.Sprite != null)
{
var texture = sprites.Frame0(action.Sprite);
var scale = Vector2.One;

if (texture.Width <= 32)
{
scale *= 2;
}

var tex = new TextureRect
{
VerticalAlignment = VAlignment.Center,
HorizontalAlignment = HAlignment.Center,
Texture = texture,
TextureScale = scale,
};

button.AddChild(tex);
}

button.OnPressed += args =>
{
OnAiRadial?.Invoke(action.Event);
Close();
};
main.AddChild(button);
}
}

protected override void FrameUpdate(FrameEventArgs args)
{
base.FrameUpdate(args);
UpdatePosition();
}

private void UpdatePosition()
{
if (!_entManager.TryGetComponent(_tracked, out TransformComponent? xform))
{
Close();
return;
}

if (!xform.Coordinates.IsValid(_entManager))
{
Close();
return;
}

var coords = _entManager.System<SpriteSystem>().GetSpriteScreenCoordinates((_tracked, null, xform));

if (!coords.IsValid)
{
Close();
return;
}

OpenScreenAt(coords.Position, _clyde);
}
}

public sealed class StationAiMenuButton(BaseStationAiAction action) : RadialMenuTextureButton
{
public BaseStationAiAction Action = action;
}
23 changes: 16 additions & 7 deletions Content.Client/Silicons/StationAi/StationAiOverlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@
using Robust.Client.Player;
using Robust.Shared.Enums;
using Robust.Shared.Map.Components;
using Robust.Shared.Physics;
using Robust.Shared.Prototypes;
using Robust.Shared.Timing;

namespace Content.Client.Silicons.StationAi;

public sealed class StationAiOverlay : Overlay
{
[Dependency] private readonly IClyde _clyde = default!;
[Dependency] private readonly IEntityManager _entManager = default!;
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly IPlayerManager _player = default!;
[Dependency] private readonly IPrototypeManager _proto = default!;

Expand All @@ -22,6 +25,9 @@ public sealed class StationAiOverlay : Overlay
private IRenderTexture? _staticTexture;
private IRenderTexture? _stencilTexture;

private float _updateRate = 1f / 30f;
private float _accumulator;

public StationAiOverlay()
{
IoCManager.InjectDependencies(this);
Expand All @@ -47,19 +53,22 @@ protected override void Draw(in OverlayDrawArgs args)
_entManager.TryGetComponent(playerEnt, out TransformComponent? playerXform);
var gridUid = playerXform?.GridUid ?? EntityUid.Invalid;
_entManager.TryGetComponent(gridUid, out MapGridComponent? grid);
_entManager.TryGetComponent(gridUid, out BroadphaseComponent? broadphase);

var invMatrix = args.Viewport.GetWorldToLocalMatrix();
_accumulator -= (float) _timing.FrameTime.TotalSeconds;

if (grid != null)
if (grid != null && broadphase != null)
{
// TODO: Pass in attached entity's grid.
// TODO: Credit OD on the moved to code
// TODO: Call the moved-to code here.

_visibleTiles.Clear();
var lookups = _entManager.System<EntityLookupSystem>();
var xforms = _entManager.System<SharedTransformSystem>();
_entManager.System<StationAiVisionSystem>().GetView((gridUid, grid), worldBounds, _visibleTiles);

if (_accumulator <= 0f)
{
_accumulator = MathF.Max(0f, _accumulator + _updateRate);
_visibleTiles.Clear();
_entManager.System<StationAiVisionSystem>().GetView((gridUid, broadphase, grid), worldBounds, _visibleTiles);
}

var gridMatrix = xforms.GetWorldMatrix(gridUid);
var matty = Matrix3x2.Multiply(gridMatrix, invMatrix);
Expand Down
Loading
Loading