Skip to content
Snippets Groups Projects
Commit 3e3fddb9 authored by Heine, Eric R's avatar Heine, Eric R
Browse files

Fixed an issue with Int and Float inputs to handle someone typing in negative...

Fixed an issue with Int and Float inputs to handle someone typing in negative numbers and decimals as they would in normal forms.
parent 17304cfa
No related branches found
No related tags found
No related merge requests found
......@@ -17,6 +17,8 @@ namespace Shared.SEUI {
// Temporary callback to bridge value changes in the UI and the variable
private UnityAction<string> valueConverter;
private bool blockUIChanges = false;
//---------------------------------------------------------------------------
void Start() {
// Make sure the input handles the right content type
......@@ -27,11 +29,20 @@ namespace Shared.SEUI {
protected override void AddUIListener(UnityAction<float> callback) {
// Define the value converting bridge callback to add to the UI listener
valueConverter = delegate(string value) {
if (!String.IsNullOrEmpty(input.text)) {
callback(Convert.ToSingle(value));
// If the user is trying to make it a negative number or a decimal,
// the string will just be "-" or end in "." at one point,
// so wait until it is a parsable number
if (value != "-" && !value.EndsWith(".")) {
blockUIChanges = false;
if (!String.IsNullOrEmpty(input.text)) {
callback(Convert.ToSingle(value));
}
else {
callback(0);
}
}
else {
callback(0.0f);
blockUIChanges = true;
}
};
......@@ -48,12 +59,14 @@ namespace Shared.SEUI {
//---------------------------------------------------------------------------
protected override bool DoValuesMatch() {
return !String.IsNullOrEmpty(input.text) && Convert.ToSingle(input.text) == variable.Value;
return !String.IsNullOrEmpty(input.text) && input.text == variable.Value.ToString();
}
//---------------------------------------------------------------------------
protected override void UpdateUIValue() {
input.SetTextWithoutNotify(variable.Value.ToString());
if (!blockUIChanges) {
input.SetTextWithoutNotify(variable.Value.ToString());
}
}
//---------------------------------------------------------------------------
......
......@@ -17,6 +17,8 @@ namespace Shared.SEUI {
// Temporary callback to bridge value changes in the UI and the variable
private UnityAction<string> valueConverter;
private bool blockUIChanges = false;
//---------------------------------------------------------------------------
void Start() {
// Make sure the input handles the right content type
......@@ -27,11 +29,19 @@ namespace Shared.SEUI {
protected override void AddUIListener(UnityAction<int> callback) {
// Define the value converting bridge callback to add to the UI listener
valueConverter = delegate(string value) {
if (!String.IsNullOrEmpty(input.text)) {
callback(Convert.ToInt32(value));
// If the user is trying to make it a negative number, the string will just be "-" at one point,
// so wait until it is a parsable number
if (value != "-") {
blockUIChanges = false;
if (!String.IsNullOrEmpty(input.text)) {
callback(Convert.ToInt32(value));
}
else {
callback(0);
}
}
else {
callback(0);
blockUIChanges = true;
}
};
......@@ -53,7 +63,9 @@ namespace Shared.SEUI {
//---------------------------------------------------------------------------
protected override void UpdateUIValue() {
input.SetTextWithoutNotify(variable.Value.ToString());
if (!blockUIChanges) {
input.SetTextWithoutNotify(variable.Value.ToString());
}
}
//---------------------------------------------------------------------------
......
......@@ -2,7 +2,7 @@
"name": "com.futuretech.shared",
"displayName": "FutureTech Shared",
"description": "Contains shared items such as the Scriptable Variables.",
"version": "0.1.27",
"version": "0.1.28",
"unity": "2019.3",
"license": "MIT",
"repository": {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment