Files
wwdpublic/Content.Client/UserInterface/Controls/AlternatingBGContainer.xaml.cs
DEATHB4DEFEAT dd52b11780 General Character Editor Improvements (#2252)
# Description

This sucked, this sucks less now.

---

# TODO

- [x] Use ABGC on Jobs
- [x] Use ABGC on Antags
- [x] Improve marking editor
	- [x] Make it use real toggleable Buttons
	- [x] Remove the enabled/sort order side
	- [x] Make buttons bigger and improve previews
- Move it to the Appearance tab
https://github.com/Simple-Station/Einstein-Engines/pull/2241
	- [x] Add a Clear button to the search
- [x] Display all 4 sprite directions at once instead of using the
stupid rotation thing
- [x] Move import/export/save buttons
- [x] Move name somewhere within the tabs
- Load markings after other stuff in the profile

<!--
Another PR
CharacterRequirements don't need to be given dependencies
Markings use CharacterRequirements
-->

---

<details><summary><h1>Media</h1></summary>
<p>

![image](https://github.com/user-attachments/assets/c2d0e8dd-7f8a-4a21-a7f2-c1ca93f20a74)

![image](https://github.com/user-attachments/assets/3024b84d-2114-4659-92d1-fd22a75cac78)

![image](https://github.com/user-attachments/assets/f471ab02-eabb-4d1b-92d7-22e15b74110b)

![image](https://github.com/user-attachments/assets/225ab764-40d7-4c64-825a-d88e0aeab4c9)

![image](https://github.com/user-attachments/assets/e5ccc05c-3c86-43ec-bbc7-9cbf500044a0)

![image](https://github.com/user-attachments/assets/e1e3562f-9bcc-405a-82e4-a35838e63b8a)

</p>
</details>

---

# Changelog

🆑
- tweak: Improved readability of many parts of the character editor with
colored rows
- tweak: Cleaned up some little bits of the character editor, most
notably removing a tiny margin that was shrinking every tab
- fix: Fixed the style of the Background tab of the character editor
being very wonky due to misplaced UI elements
- tweak: Made the Jobs tab use proper headers for the department titles
- tweak: Improved the Marking editor
- tweak: Improved the layout of the character editor
- tweak: Improved some button names in the character editor
- add: The character editor now shows all 4 directions of your character
preview at once

---------

Co-authored-by: VMSolidus <evilexecutive@gmail.com>

(cherry picked from commit 7e5b3345409dfdabde4ea56d3ecdd34a5ecdd46f)
2025-04-26 12:12:47 +03:00

111 lines
3.5 KiB
C#

using System.Linq;
using System.Numerics;
using Robust.Client.AutoGenerated;
using Robust.Client.Graphics;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Timing;
namespace Content.Client.UserInterface.Controls;
/// <summary>
/// A box container that gives every child an alternating background color
/// </summary>
[GenerateTypedNameReferences]
public sealed partial class AlternatingBGContainer : BoxContainer
{
/// If the <see cref="ContentContainer"/>'s horizontal scroll is enabled
public bool HScrollEnabled => ContentScrollContainer.HScrollEnabled;
/// If the <see cref="ContentContainer"/>'s vertical scroll is enabled
public bool VScrollEnabled => ContentScrollContainer.VScrollEnabled;
public new bool HorizontalExpand
{
get => base.HorizontalExpand;
set
{
base.HorizontalExpand = value;
Container.HorizontalExpand = value;
ContentScrollContainer.HorizontalExpand = value;
ContentContainer.HorizontalExpand = value;
}
}
public new bool VerticalExpand
{
get => base.VerticalExpand;
set
{
base.VerticalExpand = value;
Container.VerticalExpand = value;
ContentScrollContainer.VerticalExpand = value;
ContentContainer.VerticalExpand = value;
}
}
public Thickness ItemMargins = new(4);
/// The list of colors to alternate between
public List<Color> Colors = new()
{
Color.FromHex("#25252A"),
// Color.FromHex("#202025"),
Color.FromHex("#1B1B1E"),
};
/// <inheritdoc cref="AlternatingBGContainer"/>
public AlternatingBGContainer()
{
RobustXamlLoader.Load(this);
}
private bool _initialized;
/// Stupid hack, when will I get an initialized event?
/// This makes anything added via AddControl before first frame show up before children
protected override void FrameUpdate(FrameEventArgs args)
{
base.FrameUpdate(args);
if (_initialized)
return;
foreach (var child in Children.ToArray())
if (child != Container)
AddControl(child);
UpdateColors(); // Just in case
_initialized = true;
}
/// Move a control to the container and set their background color
public void AddControl(Control control)
{
var panel = new PanelContainer
{
PanelOverride = new StyleBoxFlat { BackgroundColor = Colors[ContentContainer.Children.Count(c => c.Visible) % Colors.Count], },
HorizontalExpand = true,
VerticalExpand = true,
Visible = control.Visible,
};
// Please let me add Thicknesses
control.Margin = new(control.Margin.Left + ItemMargins.Left, control.Margin.Top + ItemMargins.Top, control.Margin.Right + ItemMargins.Right, control.Margin.Bottom + ItemMargins.Bottom);
control.Orphan();
panel.AddChild(control);
ContentContainer.AddChild(panel);
}
/// Updates the colors of every child
public void UpdateColors()
{
var list = ContentContainer.Children.Where(c => c.Visible).ToList();
foreach (var child in list)
{
if (child is PanelContainer panel)
((StyleBoxFlat) panel.PanelOverride!).BackgroundColor = Colors[list.IndexOf(panel) % Colors.Count];
child.Visible = child.Children.First().Visible;
}
}
}