mirror of
https://github.com/WWhiteDreamProject/wwdpublic.git
synced 2026-04-16 21:17:39 +03:00
* - tweak: update StyleSheetify * - add: flexbox * - fix: size of flexbox in launchergui * - tweak: Profile editor: start. * - add: categories * - tweak: help me please with this shi... loadouts * - fix: container path think * - tweak: thinks for optimisation * - add: group selection for loadoutpicker * - tweak: change position of preview * - add: reason text * - fix: Кролькины фиксы * - fix: кролькины фиксы ч.2 * - fix: кролькины фиксы ч.3 * - кролькины фиксы - финал * - fix: Ворчливого дедушкины фиксы, удаление старого барахла и пометка wwdp * - tweak: some ui change for LoadoutCategories and LoadoutEntry * - ворчливый дед фиксы ч.2 * - fix: очередные кролькины фиксы * - add: loadout prototype validation * - fix: description read from edit field
203 lines
6.4 KiB
C#
203 lines
6.4 KiB
C#
using System.Diagnostics.CodeAnalysis;
|
|
using System.Linq;
|
|
using Content.Client.Stylesheets;
|
|
using Content.Shared.Clothing.Loadouts.Prototypes;
|
|
using Content.Shared.Clothing.Loadouts.Systems;
|
|
using Content.Shared.Labels.Components;
|
|
using Robust.Client.AutoGenerated;
|
|
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;
|
|
using Robust.Shared.Utility;
|
|
|
|
|
|
namespace Content.Client._White.Loadouts;
|
|
|
|
|
|
[GenerateTypedNameReferences]
|
|
public sealed partial class LoadoutEntry : Control, IComparable<LoadoutEntry>
|
|
{
|
|
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
|
[Dependency] private readonly IEntityManager _entityManager = default!;
|
|
|
|
public Action<LoadoutEntry>? OnLoadoutDirty;
|
|
public Action<LoadoutEntry>? OnEditLoadoutRequired;
|
|
|
|
private Loadout? _currentLoadout;
|
|
private EntityUid _loadoutUid;
|
|
|
|
public Loadout Loadout
|
|
{
|
|
get => _currentLoadout ?? throw new InvalidOperationException("Loadout not initialized. Call SetLoadout first.");
|
|
set => SetLoadout(value);
|
|
}
|
|
|
|
private int _cost;
|
|
|
|
public int Cost
|
|
{
|
|
get => _cost;
|
|
private set
|
|
{
|
|
LoadoutCostText.Text = value.ToString();
|
|
_cost = value;
|
|
}
|
|
}
|
|
|
|
public bool CanWear { get; private set; } = true;
|
|
|
|
public bool Selected
|
|
{
|
|
get => PreferenceButton.Pressed;
|
|
set => PreferenceButton.Pressed = value;
|
|
}
|
|
|
|
public string LoadoutName
|
|
{
|
|
get => LoadoutNameLabel.Text ?? string.Empty;
|
|
private set => LoadoutNameLabel.Text = value;
|
|
}
|
|
|
|
public string LoadoutDescription { get; private set; } = string.Empty;
|
|
|
|
private Tooltip _reasonTooltip = new();
|
|
|
|
public LoadoutEntry()
|
|
{
|
|
RobustXamlLoader.Load(this);
|
|
IoCManager.InjectDependencies(this);
|
|
MouseFilter = MouseFilterMode.Pass;
|
|
HeadingButton.OnPressed += HeadingButtonPressed;
|
|
PreferenceButton.OnPressed += PreferenceButtonPressed;
|
|
TooltipSupplier = OnTooltipSupplierRequired;
|
|
}
|
|
|
|
private Control? OnTooltipSupplierRequired(Control sender) => CanWear ? null : _reasonTooltip;
|
|
|
|
private void PreferenceButtonPressed(BaseButton.ButtonEventArgs obj)
|
|
{
|
|
OnLoadoutDirty?.Invoke(this);
|
|
}
|
|
|
|
public bool EnsureIsWearable(CharacterRequirementsArgs args, int loadoutPoint)
|
|
{
|
|
if (CheckIsWearable(args, loadoutPoint, out var reason))
|
|
{
|
|
if (CanWear)
|
|
return true;
|
|
|
|
PreferenceButton.RemoveStyleClass(StyleBase.ButtonDanger);
|
|
CanWear = true;
|
|
PreferenceButton.Disabled = false;
|
|
HeirloomButton.Visible = true;
|
|
HeadingButton.Visible = true;
|
|
PreferenceButton.MouseFilter = MouseFilterMode.Pass;
|
|
|
|
return true;
|
|
}
|
|
|
|
if (!CanWear)
|
|
return false;
|
|
|
|
PreferenceButton.AddStyleClass(StyleBase.ButtonDanger);
|
|
CanWear = false;
|
|
PreferenceButton.Disabled = true;
|
|
HeirloomButton.Visible = false;
|
|
HeadingButton.Visible = false;
|
|
PreferenceButton.MouseFilter = MouseFilterMode.Ignore;
|
|
_reasonTooltip.SetMessage(FormattedMessage.FromMarkupPermissive(reason));
|
|
|
|
return false;
|
|
}
|
|
|
|
public bool CheckIsWearable(CharacterRequirementsArgs characterRequirementsArgs, int loadoutPoint,[NotNullWhen(false)] out string? reason)
|
|
{
|
|
ProtoId<LoadoutPrototype> loadoutPrototype = Loadout.LoadoutName;
|
|
reason = null;
|
|
|
|
if (!_prototypeManager.TryIndex(loadoutPrototype, out var prototype))
|
|
{
|
|
reason = Loc.GetString("loadout-error-prototype-not-found");
|
|
return false;
|
|
}
|
|
|
|
if(prototype.Cost > loadoutPoint)
|
|
{
|
|
reason = Loc.GetString("loadout-error-too-expensive");
|
|
return false;
|
|
}
|
|
|
|
foreach (var requirement in prototype.Requirements)
|
|
{
|
|
if (!characterRequirementsArgs.IsValid(requirement, prototype, out reason))
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
private void HeadingButtonPressed(BaseButton.ButtonEventArgs obj)
|
|
{
|
|
OnEditLoadoutRequired?.Invoke(this);
|
|
}
|
|
public void SetLoadout(Loadout loadout)
|
|
{
|
|
_entityManager.DeleteEntity(_loadoutUid);
|
|
var loadoutProto = _prototypeManager.Index<LoadoutPrototype>(loadout.LoadoutName);
|
|
var firstItem = loadoutProto.Items.FirstOrDefault();
|
|
if (firstItem == default)
|
|
throw new InvalidOperationException($"Loadout {loadout.LoadoutName} has no items");
|
|
|
|
_loadoutUid = _entityManager.SpawnEntity(firstItem, MapCoordinates.Nullspace);
|
|
Cost = loadoutProto.Cost;
|
|
PreviewLoadout.SetEntity(_loadoutUid);
|
|
|
|
LoadoutName =
|
|
Loc.GetString($"loadout-name-{loadoutProto.ID}") == $"loadout-name-{loadoutProto.ID}"
|
|
? _entityManager.GetComponent<MetaDataComponent>(_loadoutUid).EntityName
|
|
: Loc.GetString($"loadout-name-{loadoutProto.ID}");
|
|
|
|
// Display the item's label if it's present
|
|
if (_entityManager.TryGetComponent(_loadoutUid, out LabelComponent? labelComponent))
|
|
{
|
|
var itemLabel = labelComponent.CurrentLabel;
|
|
if (!string.IsNullOrEmpty(itemLabel))
|
|
LoadoutName += $" ({Loc.GetString(itemLabel)})";
|
|
}
|
|
|
|
LoadoutDescription =
|
|
!Loc.TryGetString($"loadout-description-{loadoutProto.ID}", out var description)
|
|
? _entityManager.GetComponent<MetaDataComponent>(_loadoutUid).EntityDescription
|
|
: description;
|
|
|
|
_currentLoadout = loadout;
|
|
}
|
|
|
|
protected override void Dispose(bool disposing)
|
|
{
|
|
base.Dispose(disposing);
|
|
|
|
HeadingButton.OnPressed -= HeadingButtonPressed;
|
|
PreferenceButton.OnPressed -= PreferenceButtonPressed;
|
|
_entityManager.DeleteEntity(_loadoutUid);
|
|
}
|
|
|
|
public int CompareTo(LoadoutEntry? other)
|
|
{
|
|
if (ReferenceEquals(this, other))
|
|
return 0;
|
|
if (other is null)
|
|
return 1;
|
|
|
|
var canWearCompare = other.CanWear.CompareTo(CanWear);
|
|
if(canWearCompare != 0)
|
|
return canWearCompare;
|
|
|
|
return string.Compare(Loadout.LoadoutName, other.Loadout.LoadoutName, StringComparison.CurrentCulture);
|
|
}
|
|
}
|
|
|