Files
wwdpublic/Content.Client/Preferences/UI/LoadoutPreferenceSelector.cs
metalgearsloth 13e5c560f6 Loadouts redux (#25715)
* Loadouts redux

* Loadout window mockup

* More workout

* rent

* validation

* Developments

* bcs

* More cleanup

* Rebuild working

* Fix model and loading

* obsession

* efcore

* We got a stew goin

* Cleanup

* Optional + SeniorEngineering fix

* Fixes

* Update science.yml

* add

add

* Automatic naming

* Update nukeops

* Coming together

* Right now

* stargate

* rejig the UI

* weh

* Loadouts tweaks

* Merge conflicts + ordering fix

* yerba mate

* chocolat

* More updates

* Add multi-selection support

* test

h

* fikss

* a

* add tech assistant and hazard suit

* huh

* Latest changes

* add medical loadouts

* and science

* finish security loadouts

* cargo

* service done

* added wildcards

* add command

* Move restrictions

* Finalising

* Fix existing work

* Localise next batch

* clothing fix

* Fix storage names

* review

* the scooping room

* Test fixes

* Xamlify

* Xamlify this too

* Update Resources/Prototypes/Loadouts/Jobs/Medical/paramedic.yml

Co-authored-by: Mr. 27 <45323883+Dutch-VanDerLinde@users.noreply.github.com>

* Update Resources/Prototypes/Loadouts/loadout_groups.yml

Co-authored-by: Mr. 27 <45323883+Dutch-VanDerLinde@users.noreply.github.com>

* Update Resources/Prototypes/Loadouts/Jobs/Civilian/clown.yml

Co-authored-by: Mr. 27 <45323883+Dutch-VanDerLinde@users.noreply.github.com>

* Update Resources/Prototypes/Loadouts/Jobs/Civilian/clown.yml

Co-authored-by: Mr. 27 <45323883+Dutch-VanDerLinde@users.noreply.github.com>

* Update Resources/Prototypes/Loadouts/loadout_groups.yml

Co-authored-by: Mr. 27 <45323883+Dutch-VanDerLinde@users.noreply.github.com>

* Update Resources/Prototypes/Loadouts/Jobs/Security/detective.yml

Co-authored-by: Mr. 27 <45323883+Dutch-VanDerLinde@users.noreply.github.com>

* Update Resources/Prototypes/Loadouts/loadout_groups.yml

Co-authored-by: Mr. 27 <45323883+Dutch-VanDerLinde@users.noreply.github.com>

* ben

* Margins

---------
2024-07-12 02:28:31 -07:00

128 lines
4.5 KiB
C#

using System.Linq;
using System.Numerics;
using System.Text;
using Content.Client.Stylesheets;
using Content.Shared.Clothing.Loadouts.Prototypes;
using Content.Shared.Customization.Systems;
using Content.Shared.Preferences;
using Content.Shared.Roles;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.CustomControls;
using Robust.Shared.Configuration;
using Robust.Shared.Map;
using Robust.Shared.Prototypes;
using Robust.Shared.Utility;
namespace Content.Client.Preferences.UI;
public sealed class LoadoutPreferenceSelector : Control
{
public LoadoutPrototype Loadout { get; }
private readonly Button _button;
public bool Preference
{
get => _button.Pressed;
set => _button.Pressed = value;
}
public event Action<bool>? PreferenceChanged;
public LoadoutPreferenceSelector(LoadoutPrototype loadout, JobPrototype highJob,
HumanoidCharacterProfile profile, string style, IEntityManager entityManager, IPrototypeManager prototypeManager,
IConfigurationManager configManager, CharacterRequirementsSystem characterRequirementsSystem)
{
Loadout = loadout;
// Display the first item in the loadout as a preview
// TODO: Maybe allow custom icons to be specified in the prototype?
var dummyLoadoutItem = entityManager.SpawnEntity(loadout.Items.First(), MapCoordinates.Nullspace);
// Create a sprite preview of the loadout item
var previewLoadout = new SpriteView
{
Scale = new Vector2(1, 1),
OverrideDirection = Direction.South,
VerticalAlignment = VAlignment.Center,
SizeFlagsStretchRatio = 1,
};
previewLoadout.SetEntity(dummyLoadoutItem);
// Create a checkbox to get the loadout
_button = new Button
{
ToggleMode = true,
StyleClasses = { StyleBase.ButtonOpenLeft },
Children =
{
new BoxContainer
{
Children =
{
new Label
{
Text = loadout.Cost.ToString(),
StyleClasses = { StyleBase.StyleClassLabelHeading },
MinWidth = 32,
MaxWidth = 32,
ClipText = true,
Margin = new Thickness(0, 0, 8, 0),
},
new Label
{
Text = Loc.GetString($"loadout-name-{loadout.ID}") == $"loadout-name-{loadout.ID}"
? entityManager.GetComponent<MetaDataComponent>(dummyLoadoutItem).EntityName
: Loc.GetString($"loadout-name-{loadout.ID}"),
},
},
},
},
};
_button.OnToggled += OnButtonToggled;
_button.AddStyleClass(style);
var tooltip = new StringBuilder();
// Add the loadout description to the tooltip if there is one
var desc = !Loc.TryGetString($"loadout-description-{loadout.ID}", out var description)
? entityManager.GetComponent<MetaDataComponent>(dummyLoadoutItem).EntityDescription
: description;
if (!string.IsNullOrEmpty(desc))
tooltip.Append($"{Loc.GetString(desc)}");
// Get requirement reasons
characterRequirementsSystem.CheckRequirementsValid(loadout, loadout.Requirements, highJob, profile,
new Dictionary<string, TimeSpan>(),
entityManager, prototypeManager, configManager,
out var reasons);
// Add requirement reasons to the tooltip
foreach (var reason in reasons)
tooltip.Append($"\n{reason.ToMarkup()}");
// Combine the tooltip and format it in the checkbox supplier
if (tooltip.Length > 0)
{
var formattedTooltip = new Tooltip();
formattedTooltip.SetMessage(FormattedMessage.FromMarkupPermissive(tooltip.ToString()));
_button.TooltipSupplier = _ => formattedTooltip;
}
// Add the loadout preview and the checkbox to the control
AddChild(new BoxContainer
{
Orientation = BoxContainer.LayoutOrientation.Horizontal,
Children = { previewLoadout, _button },
});
}
private void OnButtonToggled(BaseButton.ButtonToggledEventArgs args)
{
PreferenceChanged?.Invoke(Preference);
}
}