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

Кастомизация СИИ #1154

Merged
merged 31 commits into from
Mar 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
68e2b39
add(src): Prototypes
FaDeOkno Feb 22, 2025
44d3f62
add(src, ui): Exsisting UI tweaks and SAI customization window
FaDeOkno Feb 22, 2025
88ffa4f
add(src, ui): Copy-paste of AnimatedTextureRect to make it scaled
FaDeOkno Feb 22, 2025
058d4cc
add(src, ui): Loadout overrides support in editor + SAI screen preview
FaDeOkno Feb 22, 2025
963f6d6
add(src): SAI customization applying
FaDeOkno Feb 22, 2025
658c9ef
tweak(proto): AI and silicon laws prototypes tweaks
FaDeOkno Feb 22, 2025
7abbce2
add(proto): Add screen prototypes and loadout override to AI role
FaDeOkno Feb 22, 2025
da2d58c
tweak(src): Move ILoadoutOverride to Content.Client
FaDeOkno Feb 23, 2025
74794de
refactor(src): Replace `StationAiData` with `RoleLoadout.ExtraData`
FaDeOkno Feb 24, 2025
d6103e4
refactor(src): i forgor
FaDeOkno Feb 24, 2025
e1f0800
refactor(src, ui): Loadout override changes to work properly with Ext…
FaDeOkno Feb 24, 2025
556635a
add(src, proto): Extra loadout data preview
FaDeOkno Feb 24, 2025
b546996
add(proto): Allow SAI to have it's loadout extras
FaDeOkno Feb 24, 2025
adabe85
add(lang): Locale
FaDeOkno Feb 24, 2025
009caee
fix(src): Fix save button click sound spam
FaDeOkno Feb 24, 2025
95782c8
tweak(ui, lang): Smol AI customization window improvements
FaDeOkno Feb 24, 2025
3188e22
add(texture): SAI screen sprites
FaDeOkno Feb 22, 2025
82a9296
style: Комментарии
FaDeOkno Feb 28, 2025
cbcf93b
style: Переместил созданные файлы в ADT папки
FaDeOkno Feb 28, 2025
8222f6f
style: Переместил спрайты в ADT папку
FaDeOkno Feb 28, 2025
890c5f7
fix(proto): Фикс невалидных спрайтов
FaDeOkno Feb 28, 2025
f23af2a
fix(ui): Фикс отображения "Объявить законы", когда объявлять их нечем…
FaDeOkno Feb 28, 2025
e0bcee6
fix(src): Фикс спрайта пустого ядра, если не выбирать ничего в меню
FaDeOkno Feb 28, 2025
40f6d2b
add(src): Миграция бд
FaDeOkno Feb 28, 2025
cdcbbc9
tweak(proto): Убрал спорные законы из раундстартовых
FaDeOkno Feb 28, 2025
44ace0f
tweak(src): Своё название меню кастомизации ИИ
FaDeOkno Feb 28, 2025
0526dc7
add(lang): Локаль
FaDeOkno Feb 28, 2025
b4332b3
style: Перенёс оставшиеся новые файлы в папку ADT
FaDeOkno Feb 28, 2025
b1788f2
style: Вот теперь точно последний перенос
FaDeOkno Feb 28, 2025
19a462b
fix: Я вспомнил, почему не переносил их никуда. Возвращаю на место.
FaDeOkno Feb 28, 2025
f35d949
style: Оставшиеся комменты
FaDeOkno Mar 1, 2025
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
using System.Numerics;
using Robust.Client.Graphics;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Client.Utility;
using Robust.Shared.Graphics.RSI;
using Robust.Shared.Timing;
using Robust.Shared.Utility;

namespace Content.Client.UserInterface.Controls
{
/// <summary>
/// Copy-paste of engine <see cref="AnimatedTextureRect"/> that can be scaled.
/// </summary>
public sealed class ScaledAnimatedTextureRect : Control
{
private IRsiStateLike? _state;
private int _curFrame;
private float _curFrameTime;

/// <summary>
/// Internal TextureRect used to do actual drawing of the texture.
/// You can use this property to change shaders or styling or such.
/// </summary>
public TextureRect DisplayRect { get; }

public RsiDirection RsiDirection { get; } = RsiDirection.South;

public ScaledAnimatedTextureRect()
{
IoCManager.InjectDependencies(this);

DisplayRect = new TextureRect()
{
TextureScale = new(1, 1)
};
AddChild(DisplayRect);
}

public void SetFromSpriteSpecifier(SpriteSpecifier specifier, Vector2 scale)
{
_curFrame = 0;
_state = specifier.RsiStateLike();
_curFrameTime = _state.GetDelay(0);
DisplayRect.Texture = _state.GetFrame(RsiDirection, 0);
DisplayRect.TextureScale = scale;
}

public void SetScale(Vector2 scale)
{
DisplayRect.TextureScale = scale;
}

protected override void FrameUpdate(FrameEventArgs args)
{
if (!VisibleInTree || _state == null || !_state.IsAnimated)
return;

var oldFrame = _curFrame;

_curFrameTime -= args.DeltaSeconds;
while (_curFrameTime < _state.GetDelay(_curFrame))
{
_curFrame = (_curFrame + 1) % _state.AnimationFrameCount;
_curFrameTime += _state.GetDelay(_curFrame);
}

if (_curFrame != oldFrame)
{
DisplayRect.Texture = _state.GetFrame(RsiDirection, _curFrame);
}
}
}
}
20 changes: 19 additions & 1 deletion Content.Client/Lobby/LobbyUIController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
using Content.Shared.Preferences;
using Content.Shared.Preferences.Loadouts;
using Content.Shared.Roles;
using Content.Shared.Silicons.StationAi;
using Content.Shared.Traits;
using Robust.Client.GameObjects;
using Robust.Client.Player;
using Robust.Client.ResourceManagement;
using Robust.Client.State;
Expand All @@ -40,6 +42,8 @@ public sealed partial class LobbyUIController : UIController, IOnStateEntered<Lo
[Dependency] private readonly IStateManager _stateManager = default!;
[Dependency] private readonly JobRequirementsManager _requirements = default!;
[Dependency] private readonly MarkingManager _markings = default!;
[Dependency] private readonly IDynamicTypeFactory _factory = default!;
[Dependency] private readonly IEntityManager _entMan = default!;
[UISystemDependency] private readonly HumanoidAppearanceSystem _humanoid = default!;
[UISystemDependency] private readonly ClientInventorySystem _inventory = default!;
[UISystemDependency] private readonly StationSpawningSystem _spawn = default!;
Expand Down Expand Up @@ -281,7 +285,8 @@ private void OpenSavePanel()
_prototypeManager,
_resourceCache,
_requirements,
_markings);
_markings,
_factory); // ADT SAI Custom

_profileEditor.OnOpenGuidebook += _guide.OpenHelp;

Expand Down Expand Up @@ -375,6 +380,8 @@ public void GiveDummyLoadout(EntityUid uid, RoleLoadout? roleLoadout)
_spawn.EquipStartingGear(uid, loadoutProto);
}
}

_spawn.ApplyLoadoutExtras(uid, roleLoadout); // ADT SAI Custom
}

/// <summary>
Expand Down Expand Up @@ -473,6 +480,17 @@ public EntityUid LoadProfileEntity(HumanoidCharacterProfile? humanoid, JobProtot
{
// Special type like borg or AI, do not spawn a human just spawn the entity.
dummyEnt = EntityManager.SpawnEntity(previewEntity, MapCoordinates.Nullspace);

// ADT SAI Custom start
// Applying loadout extras to dummy
if (_prototypeManager.HasIndex<RoleLoadoutPrototype>(LoadoutSystem.GetJobPrototype(job?.ID)))
{
var loadout = humanoid?.GetLoadoutOrDefault(LoadoutSystem.GetJobPrototype(job?.ID), _playerManager.LocalSession, humanoid.Species, EntityManager, _prototypeManager);
if (loadout != null)
_spawn.ApplyLoadoutExtras(dummyEnt, loadout);
}
// ADT SAI Custom end

return dummyEnt;
}
else if (humanoid is not null)
Expand Down
83 changes: 73 additions & 10 deletions Content.Client/Lobby/UI/HumanoidProfileEditor.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
using Content.Client.ADT.Lobby.UI;
using Content.Client.Corvax.Sponsors;
using Content.Client.Guidebook;
using System.Reflection;
using Content.Client.Humanoid;
using Content.Client.Lobby.UI.Loadouts;
using Content.Client.Lobby.UI.Roles;
using Content.Client.Message;
using Content.Client.Players.PlayTimeTracking;
using Content.Client.Sprite;
using Content.Client.Stylesheets;
using Content.Client.UserInterface.Controls;
using Content.Client.UserInterface.Systems.Guidebook;
using Content.Shared.ADT.CCVar;
using Content.Client.Corvax.Sponsors;
Expand All @@ -22,6 +24,7 @@
using Content.Shared.Humanoid;
using Content.Shared.Humanoid.Markings;
using Content.Shared.Humanoid.Prototypes;
using Content.Shared.Mobs;
using Content.Shared.Preferences;
using Content.Shared.Preferences.Loadouts;
using Content.Shared.Roles;
Expand All @@ -37,6 +40,7 @@
using Robust.Shared.ContentPack;
using Robust.Shared.Enums;
using Robust.Shared.Prototypes;
using Robust.Shared.Toolshed.Errors;
using Robust.Shared.Utility;
using Direction = Robust.Shared.Maths.Direction;

Expand All @@ -56,13 +60,14 @@ public sealed partial class HumanoidProfileEditor : BoxContainer
private readonly MarkingManager _markingManager;
private readonly JobRequirementsManager _requirements;
private readonly LobbyUIController _controller;
private readonly IDynamicTypeFactory _factory; // ADT SAI Custom
[Dependency] private readonly DocumentParsingManager _parsingMan = default!;

private FlavorText.FlavorText? _flavorText;
private TextEdit? _flavorTextEdit;

// One at a time.
private LoadoutWindow? _loadoutWindow;
private BaseLoadoutWindow? _loadoutWindow; // ADT SAI Custom

private bool _exporting;
private bool _imaging;
Expand Down Expand Up @@ -125,7 +130,8 @@ public HumanoidProfileEditor(
IPrototypeManager prototypeManager,
IResourceManager resManager,
JobRequirementsManager requirements,
MarkingManager markings)
MarkingManager markings,
IDynamicTypeFactory factory) // ADT SAI Custom
{
RobustXamlLoader.Load(this);
_sawmill = logManager.GetSawmill("profile.editor");
Expand All @@ -138,6 +144,7 @@ public HumanoidProfileEditor(
_preferencesManager = preferencesManager;
_resManager = resManager;
_requirements = requirements;
_factory = factory; // ADT SAI Custom
_controller = UserInterfaceManager.GetUIController<LobbyUIController>();

ImportButton.OnPressed += args =>
Expand Down Expand Up @@ -1103,6 +1110,11 @@ public void RefreshJobs()
var collection = IoCManager.Instance!;
var protoManager = collection.Resolve<IPrototypeManager>();

// ADT SAI Custom start
if (job.LoadoutButtonText != null)
loadoutWindowBtn.Text = Loc.GetString(job.LoadoutButtonText);
// ADT SAI Custom end

// If no loadout found then disabled button
if (!protoManager.TryIndex<RoleLoadoutPrototype>(LoadoutSystem.GetJobPrototype(job.ID), out var roleLoadoutProto))
{
Expand All @@ -1118,14 +1130,18 @@ public void RefreshJobs()
// Clone so we don't modify the underlying loadout.
Profile?.Loadouts.TryGetValue(LoadoutSystem.GetJobPrototype(job.ID), out loadout);
loadout = loadout?.Clone();

if (loadout == null)
{
loadout = new RoleLoadout(roleLoadoutProto.ID);
loadout.SetDefault(Profile, _playerManager.LocalSession, _prototypeManager);
}

OpenLoadout(job, loadout, roleLoadoutProto);
// ADT SAI Custom start
if (job.LoadoutOverride != null)
OpenLoadoutOverride(job, loadout, job.LoadoutOverride);
else
OpenLoadout(job, loadout, roleLoadoutProto);
// ADT SAI Custom end
};
}

Expand Down Expand Up @@ -1156,29 +1172,34 @@ private void OpenLoadout(JobPrototype? jobProto, RoleLoadout roleLoadout, RoleLo
Title = jobProto?.ID + "-loadout",
};

// ADT SAI Custom start
if (_loadoutWindow is not LoadoutWindow window)
return;
// ADT SAI Custom end

// Refresh the buttons etc.
_loadoutWindow.RefreshLoadouts(roleLoadout, session, collection);
window.RefreshLoadouts(roleLoadout, session, collection); // ADT SAI Custom tweaked
_loadoutWindow.OpenCenteredLeft();

_loadoutWindow.OnNameChanged += name =>
window.OnNameChanged += name => // ADT SAI Custom tweaked
{
roleLoadout.EntityName = name;
Profile = Profile.WithLoadout(roleLoadout);
SetDirty();
};

_loadoutWindow.OnLoadoutPressed += (loadoutGroup, loadoutProto) =>
window.OnLoadoutPressed += (loadoutGroup, loadoutProto) => // ADT SAI Custom tweaked
{
roleLoadout.AddLoadout(loadoutGroup, loadoutProto, _prototypeManager);
_loadoutWindow.RefreshLoadouts(roleLoadout, session, collection);
window.RefreshLoadouts(roleLoadout, session, collection); // ADT SAI Custom tweaked
Profile = Profile?.WithLoadout(roleLoadout);
ReloadPreview();
};

_loadoutWindow.OnLoadoutUnpressed += (loadoutGroup, loadoutProto) =>
window.OnLoadoutUnpressed += (loadoutGroup, loadoutProto) => // ADT SAI Custom tweaked
{
roleLoadout.RemoveLoadout(loadoutGroup, loadoutProto, _prototypeManager);
_loadoutWindow.RefreshLoadouts(roleLoadout, session, collection);
window.RefreshLoadouts(roleLoadout, session, collection); // ADT SAI Custom tweaked
Profile = Profile?.WithLoadout(roleLoadout);
ReloadPreview();
};
Expand All @@ -1198,6 +1219,48 @@ private void OpenLoadout(JobPrototype? jobProto, RoleLoadout roleLoadout, RoleLo
UpdateJobPriorities();
}

// ADT SAI Custom start
private void OpenLoadoutOverride(JobPrototype? jobProto, RoleLoadout roleLoadout, string windowName)
{
_loadoutWindow?.Dispose();
_loadoutWindow = null;

_loadoutWindow = _factory.CreateInstance(Type.GetType($"Content.Client.Lobby.UI.Loadouts.{windowName}")!) as BaseLoadoutWindow;
if (_loadoutWindow is not ILoadoutOverride loadoutWindow)
return;

loadoutWindow.Refresh(Profile, roleLoadout, _prototypeManager);
loadoutWindow.OnValueChanged += item =>
{
if (roleLoadout.ExtraData.ContainsKey(item.Key))
roleLoadout.ExtraData[item.Key] = item.Value;
else
roleLoadout.ExtraData.Add(item.Key, item.Value);

Profile = Profile?.WithLoadout(roleLoadout);
loadoutWindow.Refresh(Profile, roleLoadout, _prototypeManager);
ReloadPreview();
SetDirty();
};

_loadoutWindow.OpenCenteredLeft();

JobOverride = jobProto;
ReloadPreview();

_loadoutWindow.OnClose += () =>
{
JobOverride = null;
ReloadPreview();
};

if (Profile is null)
return;

UpdateJobPriorities();
}
// ADT SAI Custom end

private void OnFlavorTextChange(string content)
{
if (Profile is null)
Expand Down
7 changes: 7 additions & 0 deletions Content.Client/Lobby/UI/Loadouts/BaseLoadoutWindow.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
using Content.Client.UserInterface.Controls;

namespace Content.Client.Lobby.UI.Loadouts;

// ADT File
[Virtual]
public partial class BaseLoadoutWindow : FancyWindow;
14 changes: 14 additions & 0 deletions Content.Client/Lobby/UI/Loadouts/ILoadoutOverride.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Content.Shared.Preferences;
using Content.Shared.Preferences.Loadouts;
using Robust.Shared.Prototypes;

namespace Content.Client.Lobby.UI.Loadouts;

// ADT File
public interface ILoadoutOverride
{
public Action<KeyValuePair<string, string>>? OnValueChanged { get; set; }
HumanoidCharacterProfile? Profile { get; set; }

void Refresh(HumanoidCharacterProfile? profile, RoleLoadout loadout, IPrototypeManager protoMan);
}
6 changes: 3 additions & 3 deletions Content.Client/Lobby/UI/Loadouts/LoadoutWindow.xaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<controls:FancyWindow xmlns="https://spacestation14.io"
<loadout:BaseLoadoutWindow xmlns="https://spacestation14.io"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls"
xmlns:loadout="clr-namespace:Content.Client.Lobby.UI.Loadouts"
xmlns:graphics="clr-namespace:Robust.Client.Graphics;assembly=Robust.Client"
SetSize="800 800"
MinSize="800 128">
Expand All @@ -19,4 +19,4 @@
HorizontalExpand="True">
</VerticalTabContainer>
</BoxContainer>
</controls:FancyWindow>
</loadout:BaseLoadoutWindow>
2 changes: 1 addition & 1 deletion Content.Client/Lobby/UI/Loadouts/LoadoutWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
namespace Content.Client.Lobby.UI.Loadouts;

[GenerateTypedNameReferences]
public sealed partial class LoadoutWindow : FancyWindow
public sealed partial class LoadoutWindow : BaseLoadoutWindow // ADT SAI Custom tweaked
{
public event Action<string>? OnNameChanged;
public event Action<ProtoId<LoadoutGroupPrototype>, ProtoId<LoadoutPrototype>>? OnLoadoutPressed;
Expand Down
Loading
Loading