- add: change genitals on appearance
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
<humanoidProfileEditorExt:GenitalBoxView
|
||||
xmlns="https://spacestation14.io"
|
||||
xmlns:humanoidProfileEditorExt="clr-namespace:Content.Client._Amour.HumanoidProfileEditorExt">
|
||||
<BoxContainer Orientation="Vertical">
|
||||
<Label Text="{Loc 'genitals-group'}"/>
|
||||
<BoxContainer Name="Container" Orientation="Vertical"></BoxContainer>
|
||||
</BoxContainer>
|
||||
</humanoidProfileEditorExt:GenitalBoxView>
|
||||
@@ -0,0 +1,25 @@
|
||||
using Robust.Client.AutoGenerated;
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Client.UserInterface.XAML;
|
||||
|
||||
namespace Content.Client._Amour.HumanoidProfileEditorExt;
|
||||
|
||||
[GenerateTypedNameReferences]
|
||||
public sealed partial class GenitalBoxView : Control
|
||||
{
|
||||
public GenitalBoxView()
|
||||
{
|
||||
RobustXamlLoader.Load(this);
|
||||
}
|
||||
|
||||
public void AddChild(Control control)
|
||||
{
|
||||
Container.AddChild(control);
|
||||
}
|
||||
|
||||
public void ClearChilds()
|
||||
{
|
||||
Container.RemoveAllChildren();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
<controls:GenitalController
|
||||
xmlns="https://spacestation14.io"
|
||||
xmlns:controls="clr-namespace:Content.Client._Amour.HumanoidProfileEditorExt">
|
||||
<BoxContainer Orientation="Vertical" Margin="15 15 15 15">
|
||||
<Label Text="Meow" Name="Label"/>
|
||||
<BoxContainer Margin="15 15 15 15">
|
||||
<Button Text="Назад" Name="BackButton"/>
|
||||
<LineEdit Name="Input" MinWidth="45" SetWidth="45"/>
|
||||
<Label Text="/"/>
|
||||
<Label Text="0" Name="Count"/>
|
||||
<Button Text="Вперед" Name="GoButton"/>
|
||||
<Label Name="GenitalName"/>
|
||||
</BoxContainer>
|
||||
<CheckBox Text="{Loc 'genitals-same-color'}" Name="CheckBox"/>
|
||||
<ColorSelectorSliders Name="Color"/>
|
||||
</BoxContainer>
|
||||
|
||||
</controls:GenitalController>
|
||||
@@ -0,0 +1,153 @@
|
||||
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;
|
||||
};
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
using System.Linq;
|
||||
using Content.Client._Amour.HumanoidProfileEditorExt;
|
||||
using Content.Shared._Amour.Hole;
|
||||
|
||||
namespace Content.Client.Preferences.UI;
|
||||
|
||||
public sealed partial class HumanoidProfileEditor
|
||||
{
|
||||
private Dictionary<string, Genital> _genitals = new();
|
||||
|
||||
private void InitializeGenitals()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void UpdateGenitalsControls()
|
||||
{
|
||||
if (Profile is null)
|
||||
return;
|
||||
|
||||
_genitals.Clear();
|
||||
GenitalBoxView.ClearChilds();
|
||||
|
||||
Logger.Debug(Profile.Appearance.Genitals.Count + "<<");
|
||||
|
||||
foreach (var prototype in _prototypeManager.EnumeratePrototypes<GenitalsGroupPrototype>())
|
||||
{
|
||||
var selected = 0;
|
||||
foreach (var genital in Profile.Appearance.Genitals.Where(genital => prototype.Prototypes.Contains(genital.GenitalId)))
|
||||
{
|
||||
selected = prototype.Prototypes.IndexOf(genital.GenitalId);
|
||||
}
|
||||
|
||||
var controller = new GenitalController();
|
||||
controller.GenitalsCollectionPrototype = prototype;
|
||||
controller.InChange += ControllerOnInChange;
|
||||
controller.SelectedId = selected;
|
||||
|
||||
GenitalBoxView.AddChild(controller);
|
||||
}
|
||||
}
|
||||
|
||||
private void ControllerOnInChange(GenitalChangedEventArgs obj)
|
||||
{
|
||||
SelectGenital(obj.GenitalId,obj.Group,obj.Color);
|
||||
}
|
||||
|
||||
private void SelectGenital(string? id, string group,Color? color)
|
||||
{
|
||||
if(Profile is null)
|
||||
return;
|
||||
|
||||
if (id is null)
|
||||
{
|
||||
_genitals.Remove(group);
|
||||
}
|
||||
else
|
||||
{
|
||||
_genitals[group] = new Genital(id, color);
|
||||
}
|
||||
|
||||
Profile = Profile.WithCharacterAppearance(Profile.Appearance.WithGenitals(_genitals.Values.ToList()));
|
||||
ShowClothes.Pressed = false;
|
||||
IsDirty = true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user