2021-06-21 02:13:54 +02:00
|
|
|
using System.Linq;
|
2021-10-03 23:48:29 +02:00
|
|
|
using Content.Client.Info;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Client.Lobby.UI;
|
|
|
|
|
using Content.Client.Resources;
|
2021-10-16 15:28:02 -07:00
|
|
|
using Content.Shared.CharacterAppearance.Systems;
|
2020-01-18 01:54:13 +01:00
|
|
|
using Content.Shared.Preferences;
|
2020-08-13 14:40:27 +02:00
|
|
|
using Content.Shared.Roles;
|
2022-01-08 19:53:14 -06:00
|
|
|
using Content.Shared.Species;
|
2021-10-16 06:40:25 -07:00
|
|
|
using Robust.Client.AutoGenerated;
|
2020-01-18 01:54:13 +01:00
|
|
|
using Robust.Client.GameObjects;
|
2021-02-11 01:13:03 -08:00
|
|
|
using Robust.Client.Graphics;
|
|
|
|
|
using Robust.Client.ResourceManagement;
|
2020-01-18 01:54:13 +01:00
|
|
|
using Robust.Client.UserInterface;
|
|
|
|
|
using Robust.Client.UserInterface.Controls;
|
2021-10-16 06:40:25 -07:00
|
|
|
using Robust.Client.UserInterface.XAML;
|
2021-02-11 01:13:03 -08:00
|
|
|
using Robust.Shared.GameObjects;
|
2020-01-20 10:21:59 +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-19 09:34:33 +01:00
|
|
|
using Robust.Shared.Prototypes;
|
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.Preferences.UI
|
2020-01-18 01:54:13 +01:00
|
|
|
{
|
2021-10-16 06:40:25 -07:00
|
|
|
[GenerateTypedNameReferences]
|
2022-02-16 00:23:23 -07:00
|
|
|
public sealed partial class CharacterSetupGui : Control
|
2020-01-18 01:54:13 +01:00
|
|
|
{
|
|
|
|
|
private readonly IClientPreferencesManager _preferencesManager;
|
2021-10-16 06:40:25 -07:00
|
|
|
private readonly IEntityManager _entityManager;
|
2022-01-08 19:53:14 -06:00
|
|
|
private readonly IPrototypeManager _prototypeManager;
|
2021-10-28 14:23:17 +02:00
|
|
|
private readonly Button _createNewCharacterButton;
|
|
|
|
|
private readonly HumanoidProfileEditor _humanoidProfileEditor;
|
2020-01-18 01:54:13 +01:00
|
|
|
|
2021-04-19 09:52:40 +02:00
|
|
|
public CharacterSetupGui(
|
|
|
|
|
IEntityManager entityManager,
|
2020-01-18 01:54:13 +01:00
|
|
|
IResourceCache resourceCache,
|
2020-01-19 09:34:33 +01:00
|
|
|
IClientPreferencesManager preferencesManager,
|
|
|
|
|
IPrototypeManager prototypeManager)
|
2020-01-18 01:54:13 +01:00
|
|
|
{
|
2021-10-16 06:40:25 -07:00
|
|
|
RobustXamlLoader.Load(this);
|
2020-01-18 01:54:13 +01:00
|
|
|
_entityManager = entityManager;
|
2022-01-08 19:53:14 -06:00
|
|
|
_prototypeManager = prototypeManager;
|
2020-01-18 01:54:13 +01:00
|
|
|
_preferencesManager = preferencesManager;
|
|
|
|
|
|
2020-07-07 13:19:00 -04:00
|
|
|
var panelTex = resourceCache.GetTexture("/Textures/Interface/Nano/button.svg.96dpi.png");
|
2020-01-18 01:54:13 +01:00
|
|
|
var back = new StyleBoxTexture
|
|
|
|
|
{
|
|
|
|
|
Texture = panelTex,
|
|
|
|
|
Modulate = new Color(37, 37, 42)
|
|
|
|
|
};
|
|
|
|
|
back.SetPatchMargin(StyleBox.Margin.All, 10);
|
|
|
|
|
|
2021-10-28 14:23:17 +02:00
|
|
|
BackgroundPanel.PanelOverride = back;
|
2020-01-18 01:54:13 +01:00
|
|
|
|
|
|
|
|
_createNewCharacterButton = new Button
|
|
|
|
|
{
|
2021-06-21 02:13:54 +02:00
|
|
|
Text = Loc.GetString("character-setup-gui-create-new-character-button"),
|
2020-01-18 01:54:13 +01:00
|
|
|
};
|
|
|
|
|
_createNewCharacterButton.OnPressed += args =>
|
|
|
|
|
{
|
2021-03-28 08:26:32 +02:00
|
|
|
preferencesManager.CreateCharacter(HumanoidCharacterProfile.Random());
|
2020-01-18 01:54:13 +01:00
|
|
|
UpdateUI();
|
2020-02-25 17:03:46 -08:00
|
|
|
args.Event.Handle();
|
2020-01-18 01:54:13 +01:00
|
|
|
};
|
|
|
|
|
|
2020-11-08 13:44:04 +01:00
|
|
|
_humanoidProfileEditor = new HumanoidProfileEditor(preferencesManager, prototypeManager, entityManager);
|
2021-03-08 03:07:53 +01:00
|
|
|
_humanoidProfileEditor.OnProfileChanged += ProfileChanged;
|
2021-10-28 14:23:17 +02:00
|
|
|
CharEditor.AddChild(_humanoidProfileEditor);
|
2020-01-18 01:54:13 +01:00
|
|
|
|
|
|
|
|
UpdateUI();
|
2020-06-26 03:46:08 +02:00
|
|
|
|
2021-12-09 14:22:49 -08:00
|
|
|
RulesButton.OnPressed += _ => new RulesAndInfoWindow().Open();
|
2020-06-26 03:46:08 +02:00
|
|
|
preferencesManager.OnServerDataLoaded += UpdateUI;
|
2020-01-18 01:54:13 +01:00
|
|
|
}
|
|
|
|
|
|
2020-11-08 13:44:04 +01:00
|
|
|
protected override void Dispose(bool disposing)
|
|
|
|
|
{
|
|
|
|
|
base.Dispose(disposing);
|
|
|
|
|
if (!disposing)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
_preferencesManager.OnServerDataLoaded -= UpdateUI;
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-26 16:42:12 +01:00
|
|
|
public void Save() => _humanoidProfileEditor.Save();
|
2020-01-19 14:54:11 +01:00
|
|
|
|
2021-03-08 03:07:53 +01:00
|
|
|
private void ProfileChanged(ICharacterProfile profile, int profileSlot)
|
|
|
|
|
{
|
|
|
|
|
_humanoidProfileEditor.UpdateControls();
|
|
|
|
|
UpdateUI();
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-18 01:54:13 +01:00
|
|
|
private void UpdateUI()
|
|
|
|
|
{
|
|
|
|
|
var numberOfFullSlots = 0;
|
|
|
|
|
var characterButtonsGroup = new ButtonGroup();
|
2021-10-28 14:23:17 +02:00
|
|
|
Characters.RemoveAllChildren();
|
2020-06-26 03:46:08 +02:00
|
|
|
|
|
|
|
|
if (!_preferencesManager.ServerDataLoaded)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_createNewCharacterButton.ToolTip =
|
2021-06-21 02:13:54 +02:00
|
|
|
Loc.GetString("character-setup-gui-create-new-character-button-tooltip",
|
|
|
|
|
("maxCharacters", _preferencesManager.Settings!.MaxCharacterSlots));
|
2020-06-26 03:46:08 +02:00
|
|
|
|
2021-03-10 14:48:29 +01:00
|
|
|
foreach (var (slot, character) in _preferencesManager.Preferences!.Characters)
|
2020-01-18 01:54:13 +01:00
|
|
|
{
|
|
|
|
|
if (character is null)
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
numberOfFullSlots++;
|
|
|
|
|
var characterPickerButton = new CharacterPickerButton(_entityManager,
|
|
|
|
|
_preferencesManager,
|
2022-01-08 19:53:14 -06:00
|
|
|
_prototypeManager,
|
2020-01-18 01:54:13 +01:00
|
|
|
characterButtonsGroup,
|
|
|
|
|
character);
|
2021-10-28 14:23:17 +02:00
|
|
|
Characters.AddChild(characterPickerButton);
|
2020-01-18 01:54:13 +01:00
|
|
|
|
2020-10-06 15:13:16 +02:00
|
|
|
var characterIndexCopy = slot;
|
2020-02-25 17:03:46 -08:00
|
|
|
characterPickerButton.OnPressed += args =>
|
2020-01-18 01:54:13 +01:00
|
|
|
{
|
|
|
|
|
_humanoidProfileEditor.Profile = (HumanoidCharacterProfile) character;
|
|
|
|
|
_humanoidProfileEditor.CharacterSlot = characterIndexCopy;
|
|
|
|
|
_humanoidProfileEditor.UpdateControls();
|
|
|
|
|
_preferencesManager.SelectCharacter(character);
|
2020-01-25 14:37:04 +01:00
|
|
|
UpdateUI();
|
2020-02-25 17:03:46 -08:00
|
|
|
args.Event.Handle();
|
2020-01-18 01:54:13 +01:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_createNewCharacterButton.Disabled =
|
|
|
|
|
numberOfFullSlots >= _preferencesManager.Settings.MaxCharacterSlots;
|
2021-10-28 14:23:17 +02:00
|
|
|
Characters.AddChild(_createNewCharacterButton);
|
2020-01-18 01:54:13 +01:00
|
|
|
}
|
|
|
|
|
|
2022-02-16 00:23:23 -07:00
|
|
|
private sealed class CharacterPickerButton : ContainerButton
|
2020-01-18 01:54:13 +01:00
|
|
|
{
|
2021-12-05 18:09:01 +01:00
|
|
|
private EntityUid _previewDummy;
|
2020-01-18 01:54:13 +01:00
|
|
|
|
|
|
|
|
public CharacterPickerButton(
|
|
|
|
|
IEntityManager entityManager,
|
|
|
|
|
IClientPreferencesManager preferencesManager,
|
2022-01-08 19:53:14 -06:00
|
|
|
IPrototypeManager prototypeManager,
|
2020-01-18 01:54:13 +01:00
|
|
|
ButtonGroup group,
|
|
|
|
|
ICharacterProfile profile)
|
|
|
|
|
{
|
2020-02-25 17:03:46 -08:00
|
|
|
AddStyleClass(StyleClassButton);
|
|
|
|
|
ToggleMode = true;
|
|
|
|
|
Group = group;
|
|
|
|
|
|
2020-01-20 10:21:59 +01:00
|
|
|
var humanoid = profile as HumanoidCharacterProfile;
|
2022-01-08 19:53:14 -06:00
|
|
|
if (humanoid is not null)
|
|
|
|
|
{
|
|
|
|
|
var dummy = prototypeManager.Index<SpeciesPrototype>(humanoid.Species).DollPrototype;
|
|
|
|
|
_previewDummy = entityManager.SpawnEntity(dummy, MapCoordinates.Nullspace);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_previewDummy = entityManager.SpawnEntity(prototypeManager.Index<SpeciesPrototype>(SpeciesManager.DefaultSpecies).DollPrototype, MapCoordinates.Nullspace);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
EntitySystem.Get<SharedHumanoidAppearanceSystem>().UpdateFromProfile(_previewDummy, profile);
|
|
|
|
|
|
2020-01-20 10:21:59 +01:00
|
|
|
if (humanoid != null)
|
2020-01-20 09:20:36 +01:00
|
|
|
{
|
|
|
|
|
LobbyCharacterPreviewPanel.GiveDummyJobClothes(_previewDummy, humanoid);
|
|
|
|
|
}
|
2020-01-18 01:54:13 +01:00
|
|
|
|
2021-03-10 14:48:29 +01:00
|
|
|
var isSelectedCharacter = profile == preferencesManager.Preferences?.SelectedCharacter;
|
2020-01-18 01:54:13 +01:00
|
|
|
|
|
|
|
|
if (isSelectedCharacter)
|
2020-02-25 17:03:46 -08:00
|
|
|
Pressed = true;
|
2020-01-18 01:54:13 +01:00
|
|
|
|
|
|
|
|
var view = new SpriteView
|
|
|
|
|
{
|
2021-12-08 12:43:38 +01:00
|
|
|
Sprite = entityManager.GetComponent<SpriteComponent>(_previewDummy),
|
2020-01-18 01:54:13 +01:00
|
|
|
Scale = (2, 2),
|
|
|
|
|
OverrideDirection = Direction.South
|
|
|
|
|
};
|
|
|
|
|
|
2020-01-20 10:21:59 +01:00
|
|
|
var description = profile.Name;
|
|
|
|
|
|
|
|
|
|
var highPriorityJob = humanoid?.JobPriorities.SingleOrDefault(p => p.Value == JobPriority.High).Key;
|
|
|
|
|
if (highPriorityJob != null)
|
|
|
|
|
{
|
|
|
|
|
var jobName = IoCManager.Resolve<IPrototypeManager>().Index<JobPrototype>(highPriorityJob).Name;
|
|
|
|
|
description = $"{description}\n{jobName}";
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-18 01:54:13 +01:00
|
|
|
var descriptionLabel = new Label
|
|
|
|
|
{
|
2020-01-21 03:37:27 +01:00
|
|
|
Text = description,
|
|
|
|
|
ClipText = true,
|
2021-02-21 12:38:56 +01:00
|
|
|
HorizontalExpand = true
|
2020-01-18 01:54:13 +01:00
|
|
|
};
|
|
|
|
|
var deleteButton = new Button
|
|
|
|
|
{
|
2021-06-21 02:13:54 +02:00
|
|
|
Text = Loc.GetString("character-setup-gui-character-picker-button-delete-button"),
|
2020-01-18 01:54:13 +01:00
|
|
|
Visible = !isSelectedCharacter,
|
|
|
|
|
};
|
2021-03-10 14:48:29 +01:00
|
|
|
deleteButton.OnPressed += _ =>
|
2020-01-18 01:54:13 +01:00
|
|
|
{
|
2021-03-10 14:48:29 +01:00
|
|
|
Parent?.RemoveChild(this);
|
2020-01-18 01:54:13 +01:00
|
|
|
preferencesManager.DeleteCharacter(profile);
|
|
|
|
|
};
|
|
|
|
|
|
2021-07-18 18:39:31 +02:00
|
|
|
var internalHBox = new BoxContainer
|
2020-01-18 01:54:13 +01:00
|
|
|
{
|
2021-07-18 18:39:31 +02:00
|
|
|
Orientation = LayoutOrientation.Horizontal,
|
2021-02-21 12:38:56 +01:00
|
|
|
HorizontalExpand = true,
|
2020-01-18 01:54:13 +01:00
|
|
|
SeparationOverride = 0,
|
|
|
|
|
Children =
|
|
|
|
|
{
|
|
|
|
|
view,
|
|
|
|
|
descriptionLabel,
|
|
|
|
|
deleteButton
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
AddChild(internalHBox);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void Dispose(bool disposing)
|
|
|
|
|
{
|
|
|
|
|
base.Dispose(disposing);
|
2020-11-08 13:44:04 +01:00
|
|
|
if (!disposing)
|
|
|
|
|
return;
|
|
|
|
|
|
2021-12-03 15:53:09 +01:00
|
|
|
IoCManager.Resolve<IEntityManager>().DeleteEntity((EntityUid) _previewDummy);
|
2021-12-05 18:09:01 +01:00
|
|
|
_previewDummy = default;
|
2020-01-18 01:54:13 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|