| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- using System.Numerics;
- using Content.Client.UserInterface.Controls;
- using Content.Shared.Dataset;
- using Content.Shared.Preferences;
- using Content.Shared.Preferences.Loadouts;
- using Content.Shared.Random.Helpers;
- using Robust.Client.AutoGenerated;
- using Robust.Client.UserInterface.XAML;
- using Robust.Shared.Player;
- using Robust.Shared.Prototypes;
- using Robust.Shared.Random;
- namespace Content.Client.Lobby.UI.Loadouts;
- [GenerateTypedNameReferences]
- public sealed partial class LoadoutWindow : FancyWindow
- {
- public event Action<string>? OnNameChanged;
- public event Action<ProtoId<LoadoutGroupPrototype>, ProtoId<LoadoutPrototype>>? OnLoadoutPressed;
- public event Action<ProtoId<LoadoutGroupPrototype>, ProtoId<LoadoutPrototype>>? OnLoadoutUnpressed;
- private List<LoadoutGroupContainer> _groups = new();
- public HumanoidCharacterProfile Profile;
- public LoadoutWindow(HumanoidCharacterProfile profile, RoleLoadout loadout, RoleLoadoutPrototype proto, ICommonSession session, IDependencyCollection collection)
- {
- RobustXamlLoader.Load(this);
- Profile = profile;
- var protoManager = collection.Resolve<IPrototypeManager>();
- RoleNameEdit.IsValid = text => text.Length <= HumanoidCharacterProfile.MaxLoadoutNameLength;
- // Hide if we can't edit the name.
- if (!proto.CanCustomizeName)
- {
- RoleNameBox.Visible = false;
- }
- else
- {
- var name = loadout.EntityName;
- LoadoutNameLabel.Text = proto.NameDataset == null ?
- Loc.GetString("loadout-name-edit-label") :
- Loc.GetString("loadout-name-edit-label-dataset");
- RoleNameEdit.ToolTip = Loc.GetString(
- "loadout-name-edit-tooltip",
- ("max", HumanoidCharacterProfile.MaxLoadoutNameLength));
- RoleNameEdit.Text = name ?? string.Empty;
- RoleNameEdit.OnTextChanged += args => OnNameChanged?.Invoke(args.Text);
- }
- // Hide if no groups
- if (proto.Groups.Count == 0)
- {
- LoadoutGroupsContainer.Visible = false;
- SetSize = Vector2.Zero;
- }
- else
- {
- foreach (var group in proto.Groups)
- {
- if (!protoManager.TryIndex(group, out var groupProto))
- continue;
- if (groupProto.Hidden)
- continue;
- var container = new LoadoutGroupContainer(profile, loadout, protoManager.Index(group), session, collection);
- LoadoutGroupsContainer.AddTab(container, Loc.GetString(groupProto.Name));
- _groups.Add(container);
- container.OnLoadoutPressed += args =>
- {
- OnLoadoutPressed?.Invoke(group, args);
- };
- container.OnLoadoutUnpressed += args =>
- {
- OnLoadoutUnpressed?.Invoke(group, args);
- };
- }
- }
- }
- public void RefreshLoadouts(RoleLoadout loadout, ICommonSession session, IDependencyCollection collection)
- {
- foreach (var group in _groups)
- {
- group.RefreshLoadouts(Profile, loadout, session, collection);
- }
- }
- }
|