Merge pull request #139 from frosty-dev/sprite-for-station-records

[фича] Отображение спрайта в консоли учетов
This commit is contained in:
DocNight
2023-05-31 15:02:04 +03:00
committed by Remuchi
parent f15ef66659
commit 89a690c09c
3 changed files with 71 additions and 1 deletions

View File

@@ -1,10 +1,19 @@
using System.Linq;
using Content.Client.Humanoid;
using Content.Client.Inventory;
using Content.Shared.GameTicking;
using Content.Shared.Humanoid.Prototypes;
using Content.Shared.Preferences;
using Content.Shared.Roles;
using Content.Shared.StationRecords;
using Robust.Client.AutoGenerated;
using Robust.Client.GameObjects;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.CustomControls;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Map;
using Robust.Shared.Prototypes;
namespace Content.Client.StationRecords;
@@ -19,6 +28,8 @@ public sealed partial class GeneralStationRecordConsoleWindow : DefaultWindow
private GeneralStationRecordFilterType _currentFilterType;
private EntityUid _previewDummy;
public GeneralStationRecordConsoleWindow()
{
RobustXamlLoader.Load(this);
@@ -156,6 +167,7 @@ public sealed partial class GeneralStationRecordConsoleWindow : DefaultWindow
Text = record.Name,
StyleClasses = { "LabelBig" }
},
SetupCharacterSpriteView(record),
new Label()
{
Text = Loc.GetString("general-station-record-console-record-age", ("age", record.Age.ToString()))
@@ -189,6 +201,57 @@ public sealed partial class GeneralStationRecordConsoleWindow : DefaultWindow
}
}
private BoxContainer SetupCharacterSpriteView(GeneralStationRecord record)
{
IEntityManager entityManager = IoCManager.Resolve<IEntityManager>();
IPrototypeManager prototypeManager = IoCManager.Resolve<IPrototypeManager>();
HumanoidAppearanceSystem appearanceSystem = IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<HumanoidAppearanceSystem>();
entityManager.DeleteEntity(_previewDummy);
var profile = record.Profile ?? new HumanoidCharacterProfile();
_previewDummy = entityManager.SpawnEntity(prototypeManager.Index<SpeciesPrototype>(profile.Species).DollPrototype, MapCoordinates.Nullspace);
appearanceSystem.LoadProfile(_previewDummy, profile);
GiveDummyJobClothes(_previewDummy, record.JobPrototype, profile);
var spriteViewBox = new BoxContainer();
var sprite = entityManager.GetComponent<SpriteComponent>(_previewDummy);
spriteViewBox.AddChild(new SpriteView() { Sprite = sprite, Scale = (5, 5)});
spriteViewBox.AddChild(new SpriteView() { Sprite = sprite, Scale = (5, 5), OverrideDirection = Direction.East});
return spriteViewBox;
}
private void GiveDummyJobClothes(EntityUid dummy, string jobPrototype, HumanoidCharacterProfile profile)
{
IEntityManager entityManager = IoCManager.Resolve<IEntityManager>();
IPrototypeManager prototypeManager = IoCManager.Resolve<IPrototypeManager>();
ClientInventorySystem inventorySystem = IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<ClientInventorySystem>();
// ReSharper disable once NullCoalescingConditionIsAlwaysNotNullAccordingToAPIContract (what is resharper smoking?)
var job = prototypeManager.Index<JobPrototype>(jobPrototype ?? SharedGameTicker.FallbackOverflowJob);
if (job.StartingGear != null && inventorySystem.TryGetSlots(dummy, out var slots))
{
var gear = prototypeManager.Index<StartingGearPrototype>(job.StartingGear);
foreach (var slot in slots)
{
var itemType = gear.GetGear(slot.Name, profile);
if (inventorySystem.TryUnequip(dummy, slot.Name, out var unequippedItem, true, true))
{
entityManager.DeleteEntity(unequippedItem.Value);
}
if (itemType != string.Empty)
{
var item = entityManager.SpawnEntity(itemType, MapCoordinates.Nullspace);
inventorySystem.TryEquip(dummy, item, slot.Name, true, true);
}
}
}
}
private void FilterListingOfRecords(string text = "")
{
if (!_isPopulating)

View File

@@ -127,7 +127,8 @@ public sealed class StationRecordsSystem : SharedStationRecordsSystem
Gender = gender,
DisplayPriority = jobPrototype.Weight,
Fingerprint = mobFingerprint,
DNA = dna
DNA = dna,
Profile = profile
};
var key = AddRecordEntry(station, record);

View File

@@ -1,3 +1,4 @@
using Content.Shared.Preferences;
using Robust.Shared.Enums;
using Robust.Shared.Serialization;
@@ -77,4 +78,9 @@ public sealed class GeneralStationRecord
/// </summary>
[ViewVariables]
public string? DNA;
/// <sumary>
/// HumanoidCharacterProfile
/// </sumary>
[ViewVariables] public HumanoidCharacterProfile? Profile;
}