2020-01-20 09:20:36 +01:00
|
|
|
|
using System.Linq;
|
2020-08-13 14:40:27 +02:00
|
|
|
|
using Content.Client.GameObjects.Components.HUD.Inventory;
|
2020-01-20 09:20:36 +01:00
|
|
|
|
using Content.Client.GameObjects.Components.Mobs;
|
2020-01-18 01:54:13 +01:00
|
|
|
|
using Content.Client.Interfaces;
|
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-12-24 13:42:40 +00:00
|
|
|
|
using static Content.Shared.GameObjects.Components.Inventory.EquipmentSlotDefines;
|
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;
|
2020-01-18 01:54:13 +01:00
|
|
|
|
|
|
|
|
|
|
namespace Content.Client.UserInterface
|
|
|
|
|
|
{
|
|
|
|
|
|
public class LobbyCharacterPreviewPanel : Control
|
|
|
|
|
|
{
|
|
|
|
|
|
private readonly IClientPreferencesManager _preferencesManager;
|
|
|
|
|
|
private IEntity _previewDummy;
|
|
|
|
|
|
private readonly Label _summaryLabel;
|
2020-11-21 14:02:00 +01:00
|
|
|
|
private readonly VBoxContainer _loaded;
|
|
|
|
|
|
private readonly Label _unloaded;
|
2020-01-18 01:54:13 +01:00
|
|
|
|
|
|
|
|
|
|
public LobbyCharacterPreviewPanel(IEntityManager entityManager,
|
|
|
|
|
|
IClientPreferencesManager preferencesManager)
|
|
|
|
|
|
{
|
|
|
|
|
|
_preferencesManager = preferencesManager;
|
2020-01-24 16:10:48 -08:00
|
|
|
|
_previewDummy = entityManager.SpawnEntity("HumanMob_Dummy", MapCoordinates.Nullspace);
|
2020-01-18 01:54:13 +01:00
|
|
|
|
|
|
|
|
|
|
var header = new NanoHeading
|
|
|
|
|
|
{
|
2020-12-02 08:45:07 +00:00
|
|
|
|
Text = Loc.GetString("Character")
|
2020-01-18 01:54:13 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
CharacterSetupButton = new Button
|
|
|
|
|
|
{
|
2020-02-26 16:42:12 +01:00
|
|
|
|
Text = Loc.GetString("Customize"),
|
2020-01-18 01:54:13 +01:00
|
|
|
|
SizeFlagsHorizontal = SizeFlags.None
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
_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);
|
|
|
|
|
|
|
|
|
|
|
|
var vBox = new VBoxContainer();
|
|
|
|
|
|
|
|
|
|
|
|
vBox.AddChild(header);
|
|
|
|
|
|
|
2020-06-26 03:46:08 +02:00
|
|
|
|
_unloaded = new Label {Text = "Your character preferences have not yet loaded, please stand by."};
|
|
|
|
|
|
|
|
|
|
|
|
_loaded = new VBoxContainer {Visible = false};
|
|
|
|
|
|
|
|
|
|
|
|
_loaded.AddChild(CharacterSetupButton);
|
|
|
|
|
|
_loaded.AddChild(_summaryLabel);
|
2020-01-18 01:54:13 +01:00
|
|
|
|
|
|
|
|
|
|
var hBox = new HBoxContainer();
|
|
|
|
|
|
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();
|
|
|
|
|
|
_previewDummy = null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
2020-11-26 14:33:31 +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;
|
|
|
|
|
|
var component = _previewDummy.GetComponent<HumanoidAppearanceComponent>();
|
|
|
|
|
|
component.UpdateFromProfile(selectedCharacter);
|
|
|
|
|
|
|
|
|
|
|
|
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 entityMan = IoCManager.Resolve<IEntityManager>();
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
var job = protoMan.Index<JobPrototype>(highPriorityJob ?? SharedGameTicker.OverflowJob);
|
|
|
|
|
|
var gear = protoMan.Index<StartingGearPrototype>(job.StartingGear);
|
|
|
|
|
|
|
|
|
|
|
|
inventory.ClearAllSlotVisuals();
|
|
|
|
|
|
|
2020-12-24 13:42:40 +00:00
|
|
|
|
foreach (var slot in AllSlots)
|
2020-01-20 09:20:36 +01:00
|
|
|
|
{
|
2020-12-24 13:42:40 +00:00
|
|
|
|
var itemType = gear.GetGear(slot, profile);
|
|
|
|
|
|
if (itemType != "")
|
|
|
|
|
|
{
|
|
|
|
|
|
var item = entityMan.SpawnEntity(itemType, MapCoordinates.Nullspace);
|
|
|
|
|
|
inventory.SetSlotVisuals(slot, item);
|
|
|
|
|
|
item.Delete();
|
|
|
|
|
|
}
|
2020-01-18 01:54:13 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|