162 lines
4.1 KiB
C#
162 lines
4.1 KiB
C#
using System.Linq;
|
|
using Content.Shared._Amour.Hole;
|
|
using Robust.Client.AutoGenerated;
|
|
using Robust.Client.GameObjects;
|
|
using Robust.Client.Graphics;
|
|
using Robust.Client.UserInterface;
|
|
using Robust.Client.UserInterface.Controls;
|
|
using Robust.Client.UserInterface.XAML;
|
|
using Robust.Shared.Prototypes;
|
|
|
|
namespace Content.Client._Amour.HumanoidProfileEditorExt;
|
|
|
|
[GenerateTypedNameReferences]
|
|
public sealed partial class GenitalController : Control
|
|
{
|
|
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
|
[Dependency] private readonly IEntityManager _entityManager = default!;
|
|
[Dependency] private readonly IComponentFactory _componentFactory = default!;
|
|
|
|
public List<GenitalOption> GenitalOptions = new List<GenitalOption>();
|
|
|
|
private int _selectedId = 0;
|
|
|
|
public int SelectedId
|
|
{
|
|
get => _selectedId;
|
|
set
|
|
{
|
|
if(value < 0 || value > GenitalOptions.Count)
|
|
return;
|
|
_selectedId = value;
|
|
Input.Text = _selectedId.ToString();
|
|
|
|
RequireChange();
|
|
}
|
|
}
|
|
|
|
private GenitalsGroupPrototype? _genitalsCollectionPrototype;
|
|
public GenitalsGroupPrototype? GenitalsCollectionPrototype
|
|
{
|
|
get => _genitalsCollectionPrototype;
|
|
set
|
|
{
|
|
_genitalsCollectionPrototype = value;
|
|
Update();
|
|
}
|
|
}
|
|
|
|
public event Action<GenitalChangedEventArgs>? InChange;
|
|
|
|
public GenitalController()
|
|
{
|
|
RobustXamlLoader.Load(this);
|
|
IoCManager.InjectDependencies(this);
|
|
|
|
CheckBox.OnPressed += CheckBoxOnOnPressed;
|
|
Color.OnColorChanged += OnColorChanged;
|
|
|
|
BackButton.OnPressed += _ => SelectedId -= 1;
|
|
GoButton.OnPressed += _ => SelectedId += 1;
|
|
Input.OnTextChanged += args =>
|
|
{
|
|
if (int.TryParse(args.Text, out var i))
|
|
SelectedId = i;
|
|
};
|
|
}
|
|
|
|
public void SetColor(Color? color)
|
|
{
|
|
if (color is null)
|
|
CheckBox.Pressed = true;
|
|
else
|
|
Color.Color = color.Value;
|
|
}
|
|
|
|
private void OnColorChanged(Color obj)
|
|
{
|
|
if(!CheckBox.Pressed)
|
|
RequireChange();
|
|
}
|
|
|
|
private void CheckBoxOnOnPressed(BaseButton.ButtonEventArgs obj)
|
|
{
|
|
RequireChange();
|
|
}
|
|
|
|
|
|
private void RequireChange()
|
|
{
|
|
if(_genitalsCollectionPrototype is null)
|
|
return;
|
|
|
|
string? selectedGenital = null;
|
|
if (SelectedId != 0)
|
|
{
|
|
selectedGenital = GenitalOptions[SelectedId - 1].Genital;
|
|
GenitalName.Text = selectedGenital;
|
|
}
|
|
else
|
|
{
|
|
GenitalName.Text = Loc.GetString("genitals-none");
|
|
}
|
|
|
|
Color? color = null;
|
|
if (!CheckBox.Pressed)
|
|
color = Color.Color;
|
|
|
|
InChange?.Invoke(new GenitalChangedEventArgs(selectedGenital,color,_genitalsCollectionPrototype.ID));
|
|
}
|
|
|
|
public void Update()
|
|
{
|
|
GenitalOptions.Clear();
|
|
SelectedId = 0;
|
|
|
|
if(_genitalsCollectionPrototype is null)
|
|
return;
|
|
|
|
Label.Text = Loc.GetString("genitals-group-" + _genitalsCollectionPrototype.ID.ToLower());
|
|
|
|
Count.Text = _genitalsCollectionPrototype.Prototypes.Count.ToString();
|
|
|
|
foreach (var entityProtoId in _genitalsCollectionPrototype.Prototypes)
|
|
{
|
|
|
|
if (!_prototypeManager.TryIndex(entityProtoId, out var entityPrototype))
|
|
{
|
|
Logger.Error("PIZDA NOT FOUND " + entityProtoId);
|
|
continue;
|
|
}
|
|
|
|
GenitalOptions.Add(new GenitalOption(entityPrototype.ID,null));
|
|
}
|
|
}
|
|
}
|
|
|
|
public sealed class GenitalChangedEventArgs
|
|
{
|
|
public string? GenitalId;
|
|
public Color? Color;
|
|
public string Group;
|
|
|
|
public GenitalChangedEventArgs(string? genitalId, Color? color, string group)
|
|
{
|
|
GenitalId = genitalId;
|
|
Color = color;
|
|
Group = group;
|
|
}
|
|
}
|
|
|
|
public sealed class GenitalOption
|
|
{
|
|
public string Genital;
|
|
public Texture? Texture;
|
|
|
|
public GenitalOption(string genital, Texture? texture)
|
|
{
|
|
Genital = genital;
|
|
Texture = texture;
|
|
}
|
|
}
|