mirror of
https://github.com/bdunderscore/modular-avatar.git
synced 2025-04-11 23:19:00 +08:00
feat: enhance default value field input
This commit is contained in:
parent
fed6a22d72
commit
fcc46ace8e
@ -16,21 +16,20 @@ namespace nadena.dev.modular_avatar.core.editor
|
||||
private const string V_True = "ON";
|
||||
private const string V_False = "OFF";
|
||||
|
||||
private readonly TextField _visibleField;
|
||||
private readonly FloatField _defaultValueField;
|
||||
private readonly DropdownField _boolField;
|
||||
private readonly Toggle _hasExplicitDefaultSetField;
|
||||
private readonly TextField _notSyncedField;
|
||||
private readonly TextField _intField;
|
||||
private readonly TextField _floatField;
|
||||
private readonly DropdownField _boolField;
|
||||
|
||||
public DefaultValueField()
|
||||
{
|
||||
// Hidden binding elements
|
||||
_defaultValueField = new FloatField();
|
||||
_defaultValueField.style.display = DisplayStyle.None;
|
||||
_hasExplicitDefaultSetField = new Toggle();
|
||||
_boolField = new DropdownField();
|
||||
|
||||
_boolField.choices.Add(V_None);
|
||||
_boolField.choices.Add(V_True);
|
||||
_boolField.choices.Add(V_False);
|
||||
_hasExplicitDefaultSetField.style.display = DisplayStyle.None;
|
||||
|
||||
_defaultValueField.RegisterValueChangedCallback(
|
||||
evt => UpdateVisibleField(evt.newValue, _hasExplicitDefaultSetField.value));
|
||||
@ -40,43 +39,58 @@ namespace nadena.dev.modular_avatar.core.editor
|
||||
evt => UpdateVisibleField(_defaultValueField.value, evt.newValue));
|
||||
_hasExplicitDefaultSetField.bindingPath = nameof(ParameterConfig.hasExplicitDefaultValue);
|
||||
|
||||
_visibleField = new TextField();
|
||||
_visibleField.RegisterValueChangedCallback(evt =>
|
||||
// Visible elements for input
|
||||
_notSyncedField = new TextField();
|
||||
_notSyncedField.name = "default-value-not-synced";
|
||||
_notSyncedField.isDelayed = true;
|
||||
_intField = new TextField();
|
||||
_intField.name = "default-value-int";
|
||||
_intField.isDelayed = true;
|
||||
_floatField = new TextField();
|
||||
_floatField.name = "default-value-float";
|
||||
_floatField.isDelayed = true;
|
||||
_boolField = new DropdownField();
|
||||
_boolField.name = "default-value-bool";
|
||||
_boolField.choices.Add(V_None);
|
||||
_boolField.choices.Add(V_True);
|
||||
_boolField.choices.Add(V_False);
|
||||
|
||||
void NumberChangedCallback(ChangeEvent<string> evt)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(evt.newValue))
|
||||
{
|
||||
_hasExplicitDefaultSetField.value = false;
|
||||
_defaultValueField.value = 0;
|
||||
_hasExplicitDefaultSetField.value = false;
|
||||
}
|
||||
else if (float.TryParse(evt.newValue, NumberStyles.Float, CultureInfo.InvariantCulture, out var value))
|
||||
{
|
||||
_defaultValueField.value = value;
|
||||
_hasExplicitDefaultSetField.value = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
_hasExplicitDefaultSetField.value = true;
|
||||
_defaultValueField.value = float.Parse(evt.newValue, CultureInfo.InvariantCulture);
|
||||
UpdateVisibleField(_defaultValueField.value, _hasExplicitDefaultSetField.value);
|
||||
}
|
||||
});
|
||||
|
||||
_defaultValueField.style.width = 0;
|
||||
_defaultValueField.SetEnabled(false);
|
||||
_hasExplicitDefaultSetField.style.width = 0;
|
||||
_hasExplicitDefaultSetField.SetEnabled(false);
|
||||
}
|
||||
|
||||
_notSyncedField.RegisterValueChangedCallback(NumberChangedCallback);
|
||||
|
||||
_intField.RegisterValueChangedCallback(NumberChangedCallback);
|
||||
|
||||
_floatField.RegisterValueChangedCallback(NumberChangedCallback);
|
||||
|
||||
_boolField.RegisterValueChangedCallback(evt =>
|
||||
{
|
||||
if (evt.newValue == V_True)
|
||||
_defaultValueField.value = 1;
|
||||
else
|
||||
_defaultValueField.value = 0;
|
||||
|
||||
_defaultValueField.value = evt.newValue == V_True ? 1 : 0;
|
||||
_hasExplicitDefaultSetField.value = evt.newValue != V_None;
|
||||
});
|
||||
|
||||
|
||||
style.flexDirection = FlexDirection.Row;
|
||||
|
||||
Add(_visibleField);
|
||||
Add(_boolField);
|
||||
Add(_defaultValueField);
|
||||
Add(_hasExplicitDefaultSetField);
|
||||
Add(_notSyncedField);
|
||||
Add(_intField);
|
||||
Add(_floatField);
|
||||
Add(_boolField);
|
||||
}
|
||||
|
||||
public void ManualBindProperty(SerializedProperty property)
|
||||
@ -91,19 +105,22 @@ namespace nadena.dev.modular_avatar.core.editor
|
||||
{
|
||||
hasExplicitValue = true;
|
||||
}
|
||||
|
||||
var str = hasExplicitValue ? value.ToString(CultureInfo.InvariantCulture) : "";
|
||||
_visibleField.SetValueWithoutNotify(str);
|
||||
|
||||
string boolStr;
|
||||
if (!hasExplicitValue)
|
||||
boolStr = V_None;
|
||||
else if (value > 0.5)
|
||||
boolStr = V_True;
|
||||
else
|
||||
boolStr = V_False;
|
||||
_notSyncedField.SetValueWithoutNotify(hasExplicitValue
|
||||
? value.ToString(CultureInfo.InvariantCulture)
|
||||
: string.Empty);
|
||||
|
||||
_boolField.SetValueWithoutNotify(boolStr);
|
||||
_intField.SetValueWithoutNotify(hasExplicitValue
|
||||
? Mathf.FloorToInt(Mathf.Clamp(value, 0, 255)).ToString(CultureInfo.InvariantCulture)
|
||||
: string.Empty);
|
||||
|
||||
_floatField.SetValueWithoutNotify(hasExplicitValue
|
||||
? Mathf.Clamp(value, -1, 1).ToString(CultureInfo.InvariantCulture)
|
||||
: string.Empty);
|
||||
|
||||
_boolField.SetValueWithoutNotify(hasExplicitValue
|
||||
? value != 0 ? V_True : V_False
|
||||
: V_None);
|
||||
}
|
||||
}
|
||||
}
|
@ -79,25 +79,31 @@
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
DefaultValueField TextField {
|
||||
display: flex;
|
||||
DefaultValueField > * {
|
||||
width: 60px;
|
||||
height: 100%;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
DefaultValueField DropdownField {
|
||||
display: none;
|
||||
width: 60px;
|
||||
height: 100%;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.st-ty-Bool DefaultValueField TextField {
|
||||
.st-ty-Not-Synced DefaultValueField #default-value-int,
|
||||
.st-ty-Not-Synced DefaultValueField #default-value-float,
|
||||
.st-ty-Not-Synced DefaultValueField #default-value-bool,
|
||||
.st-ty-Int DefaultValueField #default-value-not-synced,
|
||||
.st-ty-Int DefaultValueField #default-value-float,
|
||||
.st-ty-Int DefaultValueField #default-value-bool,
|
||||
.st-ty-Float DefaultValueField #default-value-not-synced,
|
||||
.st-ty-Float DefaultValueField #default-value-int,
|
||||
.st-ty-Float DefaultValueField #default-value-bool,
|
||||
.st-ty-Bool DefaultValueField #default-value-not-synced,
|
||||
.st-ty-Bool DefaultValueField #default-value-int,
|
||||
.st-ty-Bool DefaultValueField #default-value-float {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.st-ty-Bool DefaultValueField DropdownField {
|
||||
.st-ty-Not-Synced DefaultValueField #default-value-not-synced,
|
||||
.st-ty-Int DefaultValueField #default-value-int,
|
||||
.st-ty-Float DefaultValueField #default-value-float,
|
||||
.st-ty-Bool DefaultValueField #default-value-bool {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user