Character eye customization, scroll bar in appearance tab character setup. Fixes #2946 (#3403)

* A lot of unfinished work, trying to figure stuff out but it ain't really working

* The eye colors finally work on the sprite!

* Big refactor for HumanoidProfileEditor, crashes upon making a lobby

* Fixed Lobby crashing

* Moves the eye selection box to a new tab, which fixes selection the box from going off-screen and not expanding the bars

* uncommented something I shouldn't have commented out

* Moved eye colors back to the appearance tab, still some ui glitches

* Made it possible to scroll in the appearance tab

* Added "Eye color:" label

* Migrating some deprecated functions into their replacements

* Merged two private sealed classes into one public class, removing duplication
This commit is contained in:
RemberBL
2021-03-07 20:48:24 +01:00
committed by GitHub
parent b207162b25
commit 343f183b32
6 changed files with 510 additions and 400 deletions

View File

@@ -55,6 +55,11 @@ namespace Content.Client.GameObjects.Components
isFacialHair));
}
internal void EyeColorSelected(Color color)
{
SendMessage(new EyeColorSelectedMessage((color.RByte, color.GByte, color.BByte)));
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
@@ -66,6 +71,86 @@ namespace Content.Client.GameObjects.Components
}
}
public class ColorSlider : Control
{
private readonly Slider _slider;
private readonly LineEdit _textBox;
private byte _colorValue;
private bool _ignoreEvents;
public event Action OnValueChanged;
public byte ColorValue
{
get => _colorValue;
set
{
_ignoreEvents = true;
_colorValue = value;
_slider.Value = value;
_textBox.Text = value.ToString();
_ignoreEvents = false;
}
}
public ColorSlider(string styleClass)
{
_slider = new Slider
{
StyleClasses = { styleClass },
HorizontalExpand = true,
VerticalAlignment = VAlignment.Center,
MaxValue = byte.MaxValue
};
_textBox = new LineEdit
{
MinSize = (50, 0)
};
AddChild(new HBoxContainer
{
Children =
{
_slider,
_textBox
}
});
_slider.OnValueChanged += _ =>
{
if (_ignoreEvents)
{
return;
}
_colorValue = (byte) _slider.Value;
_textBox.Text = _colorValue.ToString();
OnValueChanged?.Invoke();
};
_textBox.OnTextChanged += ev =>
{
if (_ignoreEvents)
{
return;
}
if (int.TryParse(ev.Text, out var result))
{
result = MathHelper.Clamp(result, 0, byte.MaxValue);
_ignoreEvents = true;
_colorValue = (byte) result;
_slider.Value = result;
_ignoreEvents = false;
OnValueChanged?.Invoke();
}
};
}
}
public class FacialHairStylePicker : HairStylePicker
{
public override void Populate()
@@ -175,91 +260,64 @@ namespace Content.Client.GameObjects.Components
OnHairStylePicked?.Invoke(Items[args.ItemIndex].Text);
}
private sealed class ColorSlider : Control
// ColorSlider
}
public class EyeColorPicker : Control
{
public event Action<Color> OnEyeColorPicked;
private readonly ColorSlider _colorSliderR;
private readonly ColorSlider _colorSliderG;
private readonly ColorSlider _colorSliderB;
private Color _lastColor;
public void SetData(Color color)
{
private readonly Slider _slider;
private readonly LineEdit _textBox;
private byte _colorValue;
private bool _ignoreEvents;
_lastColor = color;
public event Action OnValueChanged;
public byte ColorValue
{
get => _colorValue;
set
{
_ignoreEvents = true;
_colorValue = value;
_slider.Value = value;
_textBox.Text = value.ToString();
_ignoreEvents = false;
}
}
public ColorSlider(string styleClass)
{
_slider = new Slider
{
StyleClasses = {styleClass},
HorizontalExpand = true,
VerticalAlignment = VAlignment.Center,
MaxValue = byte.MaxValue
};
_textBox = new LineEdit
{
MinSize = (50, 0)
};
AddChild(new HBoxContainer
{
Children =
{
_slider,
_textBox
}
});
_slider.OnValueChanged += _ =>
{
if (_ignoreEvents)
{
return;
}
_colorValue = (byte) _slider.Value;
_textBox.Text = _colorValue.ToString();
OnValueChanged?.Invoke();
};
_textBox.OnTextChanged += ev =>
{
if (_ignoreEvents)
{
return;
}
if (int.TryParse(ev.Text, out var result))
{
result = MathHelper.Clamp(result, 0, byte.MaxValue);
_ignoreEvents = true;
_colorValue = (byte) result;
_slider.Value = result;
_ignoreEvents = false;
OnValueChanged?.Invoke();
}
};
}
_colorSliderR.ColorValue = color.RByte;
_colorSliderG.ColorValue = color.GByte;
_colorSliderB.ColorValue = color.BByte;
}
public EyeColorPicker()
{
var vBox = new VBoxContainer();
AddChild(vBox);
vBox.AddChild(_colorSliderR = new ColorSlider(StyleNano.StyleClassSliderRed));
vBox.AddChild(_colorSliderG = new ColorSlider(StyleNano.StyleClassSliderGreen));
vBox.AddChild(_colorSliderB = new ColorSlider(StyleNano.StyleClassSliderBlue));
Action colorValueChanged = ColorValueChanged;
_colorSliderR.OnValueChanged += colorValueChanged;
_colorSliderG.OnValueChanged += colorValueChanged;
_colorSliderB.OnValueChanged += colorValueChanged;
}
private void ColorValueChanged()
{
var newColor = new Color(
_colorSliderR.ColorValue,
_colorSliderG.ColorValue,
_colorSliderB.ColorValue
);
OnEyeColorPicked?.Invoke(newColor);
_lastColor = newColor;
}
// ColorSlider
}
public class MagicMirrorWindow : SS14Window
{
private readonly HairStylePicker _hairStylePicker;
private readonly FacialHairStylePicker _facialHairStylePicker;
private readonly EyeColorPicker _eyeColorPicker;
public MagicMirrorWindow(MagicMirrorBoundUserInterface owner)
{
@@ -276,10 +334,13 @@ namespace Content.Client.GameObjects.Components
_facialHairStylePicker.OnHairStylePicked += newStyle => owner.HairSelected(newStyle, true);
_facialHairStylePicker.OnHairColorPicked += newColor => owner.HairColorSelected(newColor, true);
_eyeColorPicker = new EyeColorPicker {SizeFlagsHorizontal = SizeFlags.FillExpand};
_eyeColorPicker.OnEyeColorPicked += newColor => owner.EyeColorSelected(newColor);
Contents.AddChild(new HBoxContainer
{
SeparationOverride = 8,
Children = {_hairStylePicker, _facialHairStylePicker}
Children = {_hairStylePicker, _facialHairStylePicker, _eyeColorPicker}
});
}
@@ -291,6 +352,7 @@ namespace Content.Client.GameObjects.Components
{
_hairStylePicker.Dispose();
_facialHairStylePicker.Dispose();
_eyeColorPicker.Dispose();
}
}
@@ -298,6 +360,7 @@ namespace Content.Client.GameObjects.Components
{
_facialHairStylePicker.SetData(initialData.FacialHairColor, initialData.FacialHairName);
_hairStylePicker.SetData(initialData.HairColor, initialData.HairName);
_eyeColorPicker.SetData(initialData.EyeColor);
}
}
}