2021-06-21 02:13:54 +02:00
|
|
|
using System.Linq;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Client.HUD.UI;
|
|
|
|
|
using Content.Client.Inventory;
|
|
|
|
|
using Content.Client.Preferences;
|
2021-10-16 15:28:02 -07:00
|
|
|
using Content.Shared.CharacterAppearance.Systems;
|
2020-10-14 22:45:53 +02:00
|
|
|
using Content.Shared.GameTicking;
|
2020-01-18 01:54:13 +01:00
|
|
|
using Content.Shared.Preferences;
|
2020-08-13 14:40:27 +02:00
|
|
|
using Content.Shared.Roles;
|
2021-02-11 01:13:03 -08:00
|
|
|
using Robust.Client.GameObjects;
|
2020-01-18 01:54:13 +01:00
|
|
|
using Robust.Client.UserInterface;
|
|
|
|
|
using Robust.Client.UserInterface.Controls;
|
2021-02-11 01:13:03 -08:00
|
|
|
using Robust.Shared.GameObjects;
|
2020-01-20 09:20:36 +01:00
|
|
|
using Robust.Shared.IoC;
|
2020-01-18 01:54:13 +01:00
|
|
|
using Robust.Shared.Localization;
|
|
|
|
|
using Robust.Shared.Map;
|
|
|
|
|
using Robust.Shared.Maths;
|
2020-01-20 09:20:36 +01:00
|
|
|
using Robust.Shared.Prototypes;
|
2021-06-09 22:19:39 +02:00
|
|
|
using static Content.Shared.Inventory.EquipmentSlotDefines;
|
2021-07-18 18:39:31 +02:00
|
|
|
using static Robust.Client.UserInterface.Controls.BoxContainer;
|
2020-01-18 01:54:13 +01:00
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
namespace Content.Client.Lobby.UI
|
2020-01-18 01:54:13 +01:00
|
|
|
{
|
|
|
|
|
public class LobbyCharacterPreviewPanel : Control
|
|
|
|
|
{
|
|
|
|
|
private readonly IClientPreferencesManager _preferencesManager;
|
|
|
|
|
private IEntity _previewDummy;
|
|
|
|
|
private readonly Label _summaryLabel;
|
2021-07-18 18:39:31 +02:00
|
|
|
private readonly BoxContainer _loaded;
|
2020-11-21 14:02:00 +01:00
|
|
|
private readonly Label _unloaded;
|
2020-01-18 01:54:13 +01:00
|
|
|
|
|
|
|
|
public LobbyCharacterPreviewPanel(IEntityManager entityManager,
|
|
|
|
|
IClientPreferencesManager preferencesManager)
|
|
|
|
|
{
|
|
|
|
|
_preferencesManager = preferencesManager;
|
2021-10-07 11:59:59 -07:00
|
|
|
_previewDummy = entityManager.SpawnEntity("MobHumanDummy", MapCoordinates.Nullspace);
|
2020-01-18 01:54:13 +01:00
|
|
|
|
|
|
|
|
var header = new NanoHeading
|
|
|
|
|
{
|
2021-06-21 02:13:54 +02:00
|
|
|
Text = Loc.GetString("lobby-character-preview-panel-header")
|
2020-01-18 01:54:13 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
CharacterSetupButton = new Button
|
|
|
|
|
{
|
2021-06-21 02:13:54 +02:00
|
|
|
Text = Loc.GetString("lobby-character-preview-panel-character-setup-button"),
|
2021-02-21 12:38:56 +01:00
|
|
|
HorizontalAlignment = HAlignment.Left
|
2020-01-18 01:54:13 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
_summaryLabel = new Label();
|
|
|
|
|
|
|
|
|
|
var viewSouth = MakeSpriteView(_previewDummy, Direction.South);
|
|
|
|
|
var viewNorth = MakeSpriteView(_previewDummy, Direction.North);
|
|
|
|
|
var viewWest = MakeSpriteView(_previewDummy, Direction.West);
|
|
|
|
|
var viewEast = MakeSpriteView(_previewDummy, Direction.East);
|
|
|
|
|
|
2021-07-18 18:39:31 +02:00
|
|
|
var vBox = new BoxContainer
|
|
|
|
|
{
|
|
|
|
|
Orientation = LayoutOrientation.Vertical
|
|
|
|
|
};
|
2020-01-18 01:54:13 +01:00
|
|
|
|
|
|
|
|
vBox.AddChild(header);
|
|
|
|
|
|
2021-06-21 02:13:54 +02:00
|
|
|
_unloaded = new Label {Text = Loc.GetString("lobby-character-preview-panel-unloaded-preferences-label")};
|
2020-06-26 03:46:08 +02:00
|
|
|
|
2021-07-18 18:39:31 +02:00
|
|
|
_loaded = new BoxContainer
|
|
|
|
|
{
|
|
|
|
|
Orientation = LayoutOrientation.Vertical,
|
|
|
|
|
Visible = false
|
|
|
|
|
};
|
2020-06-26 03:46:08 +02:00
|
|
|
|
|
|
|
|
_loaded.AddChild(CharacterSetupButton);
|
|
|
|
|
_loaded.AddChild(_summaryLabel);
|
2020-01-18 01:54:13 +01:00
|
|
|
|
2021-07-18 18:39:31 +02:00
|
|
|
var hBox = new BoxContainer
|
|
|
|
|
{
|
|
|
|
|
Orientation = LayoutOrientation.Horizontal
|
|
|
|
|
};
|
2020-01-18 01:54:13 +01:00
|
|
|
hBox.AddChild(viewSouth);
|
|
|
|
|
hBox.AddChild(viewNorth);
|
|
|
|
|
hBox.AddChild(viewWest);
|
|
|
|
|
hBox.AddChild(viewEast);
|
|
|
|
|
|
2020-06-26 03:46:08 +02:00
|
|
|
_loaded.AddChild(hBox);
|
2020-01-18 01:54:13 +01:00
|
|
|
|
2020-06-26 03:46:08 +02:00
|
|
|
vBox.AddChild(_loaded);
|
|
|
|
|
vBox.AddChild(_unloaded);
|
2020-01-18 01:54:13 +01:00
|
|
|
AddChild(vBox);
|
|
|
|
|
|
|
|
|
|
UpdateUI();
|
2020-06-26 03:46:08 +02:00
|
|
|
|
|
|
|
|
_preferencesManager.OnServerDataLoaded += UpdateUI;
|
2020-01-18 01:54:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Button CharacterSetupButton { get; }
|
|
|
|
|
|
|
|
|
|
protected override void Dispose(bool disposing)
|
|
|
|
|
{
|
|
|
|
|
base.Dispose(disposing);
|
2020-08-20 22:37:48 +02:00
|
|
|
_preferencesManager.OnServerDataLoaded -= UpdateUI;
|
|
|
|
|
|
2020-01-18 01:54:13 +01:00
|
|
|
if (!disposing) return;
|
|
|
|
|
_previewDummy.Delete();
|
2021-03-10 14:48:29 +01:00
|
|
|
_previewDummy = null!;
|
2020-01-18 01:54:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static SpriteView MakeSpriteView(IEntity entity, Direction direction)
|
|
|
|
|
{
|
2020-11-27 11:00:49 +01:00
|
|
|
return new()
|
2020-01-18 01:54:13 +01:00
|
|
|
{
|
|
|
|
|
Sprite = entity.GetComponent<ISpriteComponent>(),
|
|
|
|
|
OverrideDirection = direction,
|
|
|
|
|
Scale = (2, 2)
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void UpdateUI()
|
|
|
|
|
{
|
2020-06-26 03:46:08 +02:00
|
|
|
if (!_preferencesManager.ServerDataLoaded)
|
2020-01-18 01:54:13 +01:00
|
|
|
{
|
2020-06-26 03:46:08 +02:00
|
|
|
_loaded.Visible = false;
|
|
|
|
|
_unloaded.Visible = true;
|
2020-01-18 01:54:13 +01:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-06-26 03:46:08 +02:00
|
|
|
_loaded.Visible = true;
|
|
|
|
|
_unloaded.Visible = false;
|
2021-03-10 14:48:29 +01:00
|
|
|
if (_preferencesManager.Preferences?.SelectedCharacter is not HumanoidCharacterProfile selectedCharacter)
|
2020-06-26 03:46:08 +02:00
|
|
|
{
|
|
|
|
|
_summaryLabel.Text = string.Empty;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_summaryLabel.Text = selectedCharacter.Summary;
|
2021-10-16 15:28:02 -07:00
|
|
|
EntitySystem.Get<SharedHumanoidAppearanceSystem>().UpdateFromProfile(_previewDummy.Uid, selectedCharacter);
|
2020-06-26 03:46:08 +02:00
|
|
|
GiveDummyJobClothes(_previewDummy, selectedCharacter);
|
|
|
|
|
}
|
2020-01-20 09:20:36 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void GiveDummyJobClothes(IEntity dummy, HumanoidCharacterProfile profile)
|
|
|
|
|
{
|
|
|
|
|
var protoMan = IoCManager.Resolve<IPrototypeManager>();
|
|
|
|
|
|
|
|
|
|
var inventory = dummy.GetComponent<ClientInventoryComponent>();
|
|
|
|
|
|
2020-12-02 10:41:55 +01:00
|
|
|
var highPriorityJob = profile.JobPriorities.FirstOrDefault(p => p.Value == JobPriority.High).Key;
|
2020-01-20 09:20:36 +01:00
|
|
|
|
2021-11-26 03:02:46 -06:00
|
|
|
var job = protoMan.Index<JobPrototype>(highPriorityJob ?? SharedGameTicker.FallbackOverflowJob);
|
2020-01-20 09:20:36 +01:00
|
|
|
|
|
|
|
|
inventory.ClearAllSlotVisuals();
|
|
|
|
|
|
2021-03-10 14:48:29 +01:00
|
|
|
if (job.StartingGear != null)
|
2020-01-20 09:20:36 +01:00
|
|
|
{
|
2021-03-10 14:48:29 +01:00
|
|
|
var entityMan = IoCManager.Resolve<IEntityManager>();
|
|
|
|
|
var gear = protoMan.Index<StartingGearPrototype>(job.StartingGear);
|
|
|
|
|
|
|
|
|
|
foreach (var slot in AllSlots)
|
2020-12-24 13:42:40 +00:00
|
|
|
{
|
2021-03-10 14:48:29 +01:00
|
|
|
var itemType = gear.GetGear(slot, profile);
|
2021-06-21 02:13:54 +02:00
|
|
|
if (itemType != string.Empty)
|
2021-03-10 14:48:29 +01:00
|
|
|
{
|
|
|
|
|
var item = entityMan.SpawnEntity(itemType, MapCoordinates.Nullspace);
|
|
|
|
|
inventory.SetSlotVisuals(slot, item);
|
|
|
|
|
item.Delete();
|
|
|
|
|
}
|
2020-12-24 13:42:40 +00:00
|
|
|
}
|
2020-01-18 01:54:13 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|