Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
191 changes: 89 additions & 102 deletions Content.Client/Lobby/UI/HumanoidProfileEditor.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1922,7 +1922,7 @@ public void UpdateTraits(bool? showUnusable = null, bool reload = false)
// Reset the whole UI and delete caches
if (reload)
{
foreach (var tab in TraitsTabs.Tabs)
foreach (var tab in TraitsTabs.TabContainer.Children)
TraitsTabs.RemoveTab(tab);
_loadoutPreferences.Clear();
}
Expand Down Expand Up @@ -2256,14 +2256,13 @@ public void UpdateLoadouts(bool? showUnusable = null, bool reload = false)
// Reset the whole UI and delete caches
if (reload)
{
foreach (var tab in LoadoutsTabs.Tabs)
foreach (var tab in LoadoutsTabs.TabContainer.Children)
LoadoutsTabs.RemoveTab(tab);
foreach (var uid in _dummyLoadouts)
_entManager.QueueDeleteEntity(uid.Value);
_loadoutPreferences.Clear();
}


// Get the highest priority job to use for loadout filtering
var highJob = _controller.GetPreferredJob(Profile ?? HumanoidCharacterProfile.DefaultWithSpecies());

Expand All @@ -2283,13 +2282,6 @@ public void UpdateLoadouts(bool? showUnusable = null, bool reload = false)
out _
);
_loadouts.Add(loadout, usable);

var list = _loadoutPreferences.ToList();
if (list.FindIndex(lps => lps.Loadout.ID == loadout.ID) is not (not -1 and var i))
continue;

var selector = list[i];
UpdateSelector(selector, usable);
}

if (_loadouts.Count == 0)
Expand All @@ -2299,39 +2291,33 @@ out _
return;
}


var uncategorized = LoadoutsTabs.Contents.FirstOrDefault(c => c.Name == "Uncategorized");
if (uncategorized == null)
{
uncategorized = new BoxContainer
uncategorized ??= new BoxContainer
{
Name = "Uncategorized",
Orientation = LayoutOrientation.Vertical,
HorizontalExpand = true,
VerticalExpand = true,
// I hate ScrollContainers
Children =
{
Name = "Uncategorized",
Orientation = LayoutOrientation.Vertical,
HorizontalExpand = true,
VerticalExpand = true,
// I hate ScrollContainers
Children =
new ScrollContainer
{
new ScrollContainer
HScrollEnabled = false,
HorizontalExpand = true,
VerticalExpand = true,
Children =
{
HScrollEnabled = false,
HorizontalExpand = true,
VerticalExpand = true,
Children =
new BoxContainer
{
new BoxContainer
{
Orientation = LayoutOrientation.Vertical,
HorizontalExpand = true,
VerticalExpand = true,
},
Orientation = LayoutOrientation.Vertical,
HorizontalExpand = true,
VerticalExpand = true,
},
},
},
};

LoadoutsTabs.AddTab(uncategorized, Loc.GetString("loadout-category-Uncategorized"));
}
},
};

// Create a Dictionary/tree of categories and subcategories
var cats = CreateTree(_prototypeManager.EnumeratePrototypes<LoadoutCategoryPrototype>()
Expand All @@ -2343,76 +2329,20 @@ out _
categories.Add(key, value);

// Create the UI elements for the category tree
CreateCategoryUI(categories, LoadoutsTabs);

// Fill categories with loadouts
foreach (var (loadout, usable) in _loadouts
var sortedLoadouts = _loadouts
.OrderBy(l => l.Key.ID)
.ThenBy(l => Loc.GetString($"loadout-name-{l.Key.ID}"))
.ThenBy(l => l.Key.Cost))
{
if (_loadoutPreferences.Select(lps => lps.Loadout.ID).Contains(loadout.ID))
{
var first = _loadoutPreferences.First(lps => lps.Loadout.ID == loadout.ID);
var prof = Profile?.LoadoutPreferences.FirstOrDefault(lp => lp.LoadoutName == loadout.ID);
first.Preference = new(loadout.ID, prof?.CustomName, prof?.CustomDescription, prof?.CustomColorTint, prof?.CustomHeirloom);
UpdateSelector(first, usable);
continue;
}

var selector = new LoadoutPreferenceSelector(
loadout, highJob ?? new JobPrototype(),
Profile ?? HumanoidCharacterProfile.DefaultWithSpecies(), ref _dummyLoadouts,
_entManager, _prototypeManager, _cfgManager, _characterRequirementsSystem, _requirements)
{ Preference = new(loadout.ID) };
UpdateSelector(selector, usable);
AddSelector(selector);

// Look for an existing category tab
var match = FindCategory(loadout.Category, LoadoutsTabs);

// If there is no category put it in Uncategorized (this shouldn't happen)
(match ?? uncategorized).Children.First().Children.First().AddChild(selector);
}
.ThenBy(l => l.Key.Cost);
LoadoutsTabs.AddTab(uncategorized, Loc.GetString("loadout-category-Uncategorized"),
false, () => LoadCategoryLoadouts((BoxContainer) uncategorized, "Uncategorized"));
CreateCategoryUI(categories, LoadoutsTabs);

// Hide any empty tabs
HideEmptyTabs(_prototypeManager.EnumeratePrototypes<LoadoutCategoryPrototype>().ToList());
// Hide any empty tabs //TODO: This is broken
// HideEmptyTabs(_prototypeManager.EnumeratePrototypes<LoadoutCategoryPrototype>().ToList());

UpdateLoadoutPreferences();
return;


void UpdateSelector(LoadoutPreferenceSelector selector, bool usable)
{
selector.Valid = usable;
selector.ShowUnusable = showUnusable.Value;

foreach (var item in selector.Loadout.Items)
{
if (_dummyLoadouts.TryGetValue(selector.Loadout.ID + selector.Loadout.Items.IndexOf(item), out var entity)
&& _entManager.GetComponent<MetaDataComponent>(entity).EntityPrototype!.ID == item)
{
if (!_entManager.HasComponent<ClothingComponent>(entity))
{
selector.Wearable = true;
continue;
}
selector.Wearable = _characterRequirementsSystem.CanEntityWearItem(PreviewDummy, entity);
continue;
}

entity = _entManager.SpawnEntity(item, MapCoordinates.Nullspace);
_dummyLoadouts[selector.Loadout.ID + selector.Loadout.Items.IndexOf(item)] = entity;

if (!_entManager.HasComponent<ClothingComponent>(entity))
{
selector.Wearable = true;
continue;
}
selector.Wearable = _characterRequirementsSystem.CanEntityWearItem(PreviewDummy, entity);
}
}

void CreateCategoryUI(Dictionary<string, object> tree, NeoTabContainer parent)
{
foreach (var (key, value) in tree)
Expand Down Expand Up @@ -2450,7 +2380,8 @@ void CreateCategoryUI(Dictionary<string, object> tree, NeoTabContainer parent)
},
};

parent.AddTab(category, Loc.GetString($"loadout-category-{key}"));
parent.AddTab(category, Loc.GetString($"loadout-category-{key}"),
initialize: () => LoadCategoryLoadouts(category, key));
}
// If the value is a dictionary, create a new tab for it and recursively call this function to fill it
else
Expand All @@ -2460,12 +2391,68 @@ void CreateCategoryUI(Dictionary<string, object> tree, NeoTabContainer parent)
Name = key,
HorizontalExpand = true,
VerticalExpand = true,
SeparatorMargin = new Thickness(0),
SeparatorMargin = new(0),
};

parent.AddTab(category, Loc.GetString($"loadout-category-{key}"));
CreateCategoryUI((Dictionary<string, object>) value, category);
parent.AddTab(category, Loc.GetString($"loadout-category-{key}"),
initialize: () => CreateCategoryUI((Dictionary<string, object>) value, category));
}
}
}

void LoadCategoryLoadouts(BoxContainer category, string key)
{
foreach (var (loadout, usable) in sortedLoadouts.Where(l => l.Key.Category == key))
{
if (_loadoutPreferences.Select(lps => lps.Loadout.ID).Contains(loadout.ID))
{
var first = _loadoutPreferences.First(lps => lps.Loadout.ID == loadout.ID);
var prof = Profile?.LoadoutPreferences.FirstOrDefault(lp => lp.LoadoutName == loadout.ID);
first.Preference = new(loadout.ID, prof?.CustomName, prof?.CustomDescription, prof?.CustomColorTint, prof?.CustomHeirloom);
UpdateSelector(first, usable);
continue;
}

var selector = new LoadoutPreferenceSelector(
loadout, highJob ?? new JobPrototype(),
Profile ?? HumanoidCharacterProfile.DefaultWithSpecies(), ref _dummyLoadouts,
_entManager, _prototypeManager, _cfgManager, _characterRequirementsSystem, _requirements)
{ Preference = new(loadout.ID), };
UpdateSelector(selector, usable);
AddSelector(selector);

category.Children.First().Children.First().AddChild(selector);
}
}

void UpdateSelector(LoadoutPreferenceSelector selector, bool usable)
{
selector.Valid = usable;
selector.ShowUnusable = showUnusable.Value;

foreach (var item in selector.Loadout.Items)
{
if (_dummyLoadouts.TryGetValue(selector.Loadout.ID + selector.Loadout.Items.IndexOf(item), out var entity)
&& _entManager.GetComponent<MetaDataComponent>(entity).EntityPrototype!.ID == item)
{
if (!_entManager.HasComponent<ClothingComponent>(entity))
{
selector.Wearable = true;
continue;
}
selector.Wearable = _characterRequirementsSystem.CanEntityWearItem(PreviewDummy, entity);
continue;
}

entity = _entManager.SpawnEntity(item, MapCoordinates.Nullspace);
_dummyLoadouts[selector.Loadout.ID + selector.Loadout.Items.IndexOf(item)] = entity;

if (!_entManager.HasComponent<ClothingComponent>(entity))
{
selector.Wearable = true;
continue;
}
selector.Wearable = _characterRequirementsSystem.CanEntityWearItem(PreviewDummy, entity);
}
}

Expand Down
10 changes: 6 additions & 4 deletions Content.Client/Lobby/UI/LoadoutPreferenceSelector.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,19 @@
Name="PreferenceButton"
Access="Public"
ToggleMode="True"
VerticalAlignment="Center" />
VerticalAlignment="Center"
StyleClasses="OpenRight" />

<Button
Name="HeirloomButton"
Access="Public"
Text="{Loc 'humanoid-profile-editor-loadouts-heirloom'}"
ToolTip="{Loc 'humanoid-profile-editor-loadouts-heirloom-tooltip'}"
ToggleMode="True"
VerticalAlignment="Center" />
VerticalAlignment="Center"
StyleClasses="OpenBoth" />

<!-- Yes I know I can use a TextureButton, but I'm doing this for style -->
<!-- Yes I know I can use a TextureButton, but that doesn't have styling -->
<Button
Name="GuidebookButton"
ToolTip="{Loc 'humanoid-profile-editor-loadouts-guidebook-button-tooltip'}"
Expand All @@ -35,7 +37,7 @@


<Collapsible Name="SpecialMenu" HorizontalExpand="True">
<Button Name="HeadingButton" Text="{Loc 'humanoid-profile-editor-loadouts-customize'}" ToggleMode="True" />
<Button Name="HeadingButton" Text="{Loc 'humanoid-profile-editor-loadouts-customize'}" ToggleMode="True" StyleClasses="OpenLeft" />

<CollapsibleBody HorizontalExpand="True" Margin="0 0 0 5">
<PanelContainer HorizontalExpand="True">
Expand Down
13 changes: 6 additions & 7 deletions Content.Client/Lobby/UI/LoadoutPreferenceSelector.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Numerics;
using System.Text;
using Content.Client.Guidebook;
using Content.Client.Paint;
using Content.Client.Players.PlayTimeTracking;
using Content.Client.Stylesheets;
using Content.Client.UserInterface.Systems.Guidebook;
Expand Down Expand Up @@ -112,9 +111,9 @@ public LoadoutPreferenceSelector(LoadoutPrototype loadout, JobPrototype highJob,
entities.Add(loadout.ID + 0, dummyLoadoutItem);

// Create a sprite preview of the loadout item
previewLoadout = new SpriteView
previewLoadout = new()
{
Scale = new Vector2(1, 1),
Scale = new(1, 1),
OverrideDirection = Direction.South,
VerticalAlignment = VAlignment.Center,
SizeFlagsStretchRatio = 1,
Expand All @@ -124,9 +123,9 @@ public LoadoutPreferenceSelector(LoadoutPrototype loadout, JobPrototype highJob,
else
{
// Create a sprite preview of the loadout item
previewLoadout = new SpriteView
previewLoadout = new()
{
Scale = new Vector2(1, 1),
Scale = new(1, 1),
OverrideDirection = Direction.South,
VerticalAlignment = VAlignment.Center,
SizeFlagsStretchRatio = 1,
Expand Down Expand Up @@ -316,9 +315,9 @@ protected override void FrameUpdate(FrameEventArgs args)
// Move the special editor
var heading = SpecialMenu.Heading;
heading.Orphan();
ButtonGroup.AddChild(heading);
ButtonGroup.AddButton(heading, false);
GuidebookButton.Orphan();
ButtonGroup.AddChild(GuidebookButton);
ButtonGroup.AddButton(GuidebookButton);

// These guys are here too for reasons
HeadingButton.SetHeight = HeirloomButton.SetHeight = GuidebookButton.SetHeight = PreferenceButton.Size.Y;
Expand Down
Loading