Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ExtensionsInput.FilterRange() does not work right when there is a minimum specified #77

Closed
valkyrienyanko opened this issue Sep 6, 2022 · 1 comment
Labels
bug Something isn't working hard low priority Not to be tackled right away

Comments

@valkyrienyanko
Copy link
Contributor

valkyrienyanko commented Sep 6, 2022

⚠️ Note that this issue is on the "netcode" branch

Steps to reproduce

  1. Change port = (ushort)lineEditPort.FilterRange(ushort.MaxValue); to port = (ushort)lineEditPort.FilterRange(ushort.MaxValue, 3000);
  2. Run the game
  3. Press "Play"
  4. Once in map scene, press escape
  5. Try playing around with the port LineEdit
  6. Notice how you cannot enter numbers lower than the minimum specified in script

Code where FilterRange() is used

private void _on_Port_text_changed(string text)
{
port = (ushort)lineEditPort.FilterRange(ushort.MaxValue);
}

Code for FilterRange()

public static int FilterRange(this LineEdit lineEdit, int maxRange, int minRange = 0)
{
var text = lineEdit.Text;
var id = lineEdit.GetInstanceId();
if (string.IsNullOrWhiteSpace(text))
return minRange - 1;
if (text == "-")
return minRange - 1;
if (!int.TryParse(text.Trim(), out int numAttempts))
{
if (!_prevNums.ContainsKey(id))
{
lineEdit.ChangeLineEditText("");
return minRange - 1;
}
lineEdit.ChangeLineEditText($"{_prevNums[id]}");
return _prevNums[id];
}
if (text.Length > maxRange.ToString().Length && numAttempts <= maxRange)
{
var spliced = text.Remove(text.Length - 1);
_prevNums[id] = int.Parse(spliced);
lineEdit.Text = spliced;
lineEdit.CaretPosition = spliced.Length;
return _prevNums[id];
}
if (numAttempts > maxRange)
{
numAttempts = maxRange;
lineEdit.ChangeLineEditText($"{maxRange}");
}
if (numAttempts < minRange)
{
numAttempts = minRange;
lineEdit.ChangeLineEditText($"{minRange}");
}
_prevNums[id] = numAttempts;
return numAttempts;
}

@valkyrienyanko valkyrienyanko added bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed coding low priority Not to be tackled right away hard and removed good first issue Good for newcomers help wanted Extra attention is needed labels Sep 6, 2022
@valkyrienyanko
Copy link
Contributor Author

Removed the min range functionality, was too complex to implement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working hard low priority Not to be tackled right away
Projects
None yet
Development

No branches or pull requests

1 participant