using System.Numerics; using Content.Client.UserInterface.Controls; using Content.Shared.CCVar; 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.Controls; using Robust.Client.UserInterface.XAML; using Robust.Shared.Configuration; using Robust.Shared.Player; using Robust.Shared.Prototypes; using Robust.Shared.Random; using Content.Shared._NF.Bank; // Frontier namespace Content.Client.Lobby.UI.Loadouts; [GenerateTypedNameReferences] public sealed partial class LoadoutWindow : FancyWindow { public event Action? OnNameChanged; public event Action, ProtoId>? OnLoadoutPressed; public event Action, ProtoId>? OnLoadoutUnpressed; private List _groups = new(); public HumanoidCharacterProfile Profile; // CCvar. private int _maxLoadoutNameLength; public LoadoutWindow(HumanoidCharacterProfile profile, RoleLoadout loadout, RoleLoadoutPrototype proto, ICommonSession session, IDependencyCollection collection) { RobustXamlLoader.Load(this); Profile = profile; var protoManager = collection.Resolve(); var configManager = collection.Resolve(); _maxLoadoutNameLength = configManager.GetCVar(CCVars.MaxLoadoutNameLength); RoleNameEdit.IsValid = text => text.Length <= _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", _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); }; } } //Frontier - we inject our label here but it needs recalculating every time a new item is selected, //so we add a new method and call it there too. CalculateLoadoutCost(loadout, collection); // Frontier - update bank balance label text - value should not change. Balance.Margin = new Thickness(5, 2, 5, 5); Balance.Text = Loc.GetString("frontier-loadout-balance", ("balance", BankSystemExtensions.ToSpesoString(Profile.BankBalance))); } public void RefreshLoadouts(RoleLoadout loadout, ICommonSession session, IDependencyCollection collection) { foreach (var group in _groups) { group.RefreshLoadouts(Profile, loadout, session, collection); } CalculateLoadoutCost(loadout, collection); //Frontier } /// /// Frontier function to calculate and update the label. /// /// The currently selected loadout /// IDependency Collection of various dependencies private void CalculateLoadoutCost(RoleLoadout loadout, IDependencyCollection collection) { var protoManager = collection.Resolve(); var cost = 0; foreach (var loadoutGroup in loadout.SelectedLoadouts) { foreach (var equipment in loadoutGroup.Value) { if (protoManager.TryIndex(equipment.Prototype, out var equipProto)) { cost += equipProto.Price; } } } Cost.Margin = new Thickness(5, 2, 5, 5); Cost.Text = Loc.GetString("frontier-loadout-cost", ("cost", BankSystemExtensions.ToSpesoString(cost))); } // End Frontier }