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

[MIRROR] Makes the restricted number input user friendlier #2043

Merged
merged 1 commit into from
Feb 19, 2024

Conversation

Steals-The-PRs
Copy link
Collaborator

Mirrored on Nova: NovaSector/NovaSector#1037
Original PR: tgstation/tgstation#81495

About The Pull Request

The modal number input is extremely user unfriendly in it's current state whenever used for negative and decimal numbers See #81457 for details. The code might not be the best and if someone has suggestions to optimize it, I'm all open for it, but it takes into aspect a lot of edge cases to make the input as user friendly as possible. I've also heard form some other code bases that they have issues with the tgui_input_number proc.

The RestrictedNumber will get a new event to listen to though:

onBlur={(_, value) => onBlur(value)}

This will run the number through the previous, hard sanitation and ensures that we always submit an allowed number and not a string value as we are using it shortly during input for the pure - input. (Especially important for the "Submit" button. Enter always handles it that way). During testing, all the tested numbers were handled properly, I could not see any issues on the inputs. We still keep some in Field replacement, but it's for a limited range where we can have the field handle numbers smart:

min <= 1 && max >= 0: Within that range, the field updates the value to the restrains on input. In all other cases only onBlur.

Testcase table:

Test case Field Limit Input InField OnEnter OnSubmit OnBlur
Float (smart) 1-20 0 1 1 1 1
    1.1 1.1 1.1 1.1 1.1
    20.1 20 20 20 20
    -   1 1 1
    . 1. 1. 1. 1.
    5 5 5 5 5
Float 2-20 0 0 2 2 2
    2.1 2.1 2.1 2.1 2.1
    5 5 5 5 5
    20.1 20.1 20 20 20
    -   2 2 2
    . 2. 2. 2. 2.
Float with decimal limit 20.2-200.2 0 0 20.2 20.2 20.2
    20. 20. 20.2 20.2 20.2
    50 50 50 50 50
    200.3 200.3 200.2 200.2 200.2
    - 20.2 20.2 20.2
    . 20. 20.2 20.2 20.2
Float with decimal limit (smart) 0-20.2 0 0 0 0 0
    20. 20. 20. 20. 20.
    5 5 5 5 5
    20.3 20.2 20.2 20.2 20.2
    -   0 0 0
    . 0. 0. 0. 0.
Negative Float (smart) -10-20 -10.2 -10 -10 -10 -10
    20. 20. 20. 20. 20.
    20.1 20 20 20 20
    0 0 0 0 0
    - - -10 -10 -10
    . -10 -10 -10 -10
    -. -10. -10. -10. -10.
    -10- 10 10 10 10
    10- -10 -10 -10 -10
Negative Float with decimal limit -10.2--20.2 -10.1 -10.1 -10.2 -10.2 -10.2
    -20. -20. -20. -20. -20.
    -20.3 -20.3 -20.2 -20.2 -20.2
    0 0 -10.2 -10.2 -10.2
    - - -20.2 -20.2 -20.2
    . -20. -20. -20. -20.
    -. -20. -20. -20. -20.
    -10.2- 10.2 -10.2 -10.2 -10.2
    10.2- -10.2 -10.2 -10.2 -10.2
Int (smart) 1-20 0 1 1 1 1
    1. 1 1 1 1
    21 20 20 20 20
    5 5 5 5 5
    -   1 1 1
    .   1 1 1
Int 20-200 19 19 20 20 20
    201 201 200 200 200
    50 50 50 50 50
    -   20 20 20
    .   20 20 20
Negative Int (smart) -10-20 -11 -10 -10 -10 -10
    0 0 0 0 0
    21 20 20 20 20
    - - -10 -10 -10
    .   -10 -10 -10
    -. - -10 -10 -10
    -10- 10 10 10 10
    10- -10 -10 -10 -10
Negative Int -200---20 -201 -201 -200 -200 -200
    -19 -19 -20 -20 -20
    -50 -50 -50 -50 -50
    - - -200 -200 -200
    .   -200 -200 -200
    -. - -200 -200 -200
    -20- 20 -20 -20 -20
    20- -20 -20 -20 -20

Why It's Good For The Game

Even though not used often on TG code, the modal inputs are used on other code bases and inputting numbers has been a hell if it was anything other than a positive integer. This PR aims to make the handling as user friendly as possible, even if it's a lot more edge case checking than the very simple code beforehand.

Changelog

fixes #81457
🆑 Kashargul
qol: makes the tgui_input_number user friendly for negative and decimal inputs
code: the onBlur={(_, value) => onBlur(value)} event should now be used on all uses of RestrictedInput to ensure that the number is fully sanitized whenever the user leaves the field or submits it through a button
/:cl:

* Makes the restricted number input user friendlier (#81495)

## About The Pull Request
The modal number input is extremely user unfriendly in it's current
state whenever used for negative and decimal numbers See #81457 for
details. The code might not be the best and if someone has suggestions
to optimize it, I'm all open for it, but it takes into aspect a lot of
edge cases to make the input as user friendly as possible. I've also
heard form some other code bases that they have issues with the
tgui_input_number proc.

The RestrictedNumber will get a new event to listen to though:

` onBlur={(_, value) => onBlur(value)}`

This will run the number through the previous, hard sanitation and
ensures that we always submit an allowed number and not a string value
as we are using it shortly during input for the pure `-` input.
(Especially important for the "Submit" button. Enter always handles it
that way). During testing, all the tested numbers were handled properly,
I could not see any issues on the inputs. We still keep some in Field
replacement, but it's for a limited range where we can have the field
handle numbers smart:

`min <= 1 && max >= 0`: Within that range, the field updates the value
to the restrains on input. In all other cases only onBlur.

Testcase table:


<html xmlns:v="urn:schemas-microsoft-com:vml"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns="http://www.w3.org/TR/REC-html40">

<head>

<meta name=ProgId content=Excel.Sheet>
<!--table
	{mso-displayed-decimal-separator:"\,";
	mso-displayed-thousand-separator:"\.";}
@page
	{margin:.79in .7in .79in .7in;
	mso-header-margin:.3in;
	mso-footer-margin:.3in;}
tr
	{mso-height-source:auto;}
col
	{mso-width-source:auto;}
br
	{mso-data-placement:same-cell;}
td
	{padding-top:1px;
	padding-right:1px;
	padding-left:1px;
	mso-ignore:padding;
	color:black;
	font-size:11.0pt;
	font-weight:400;
	font-style:normal;
	text-decoration:none;
	font-family:Calibri, sans-serif;
	mso-font-charset:0;
	mso-number-format:General;
	text-align:general;
	vertical-align:bottom;
	border:none;
	mso-background-source:auto;
	mso-pattern:auto;
	mso-protection:locked visible;
	white-space:nowrap;
	mso-rotate:0;}
.xl63
	{text-align:left;}
.xl64
	{mso-number-format:"dd\/\\ mmm";
	text-align:left;}
.xl65
	{text-align:left;
	vertical-align:top;}
.xl66
	{mso-number-format:"\#\,\#\#0";
	text-align:left;}
.xl67
	{mso-number-format:"\@";
	text-align:left;}
.xl68
	{mso-number-format:"mmm\\ yy";
	text-align:left;}
-->
</head>

<body link="#0563C1" vlink="#954F72">


Test case | Field Limit | Input | InField | OnEnter | OnSubmit | OnBlur
-- | -- | -- | -- | -- | -- | --
Float (smart) | 1-20 | 0 | 1 | 1 | 1 | 1
  |   | 1.1 | 1.1 | 1.1 | 1.1 | 1.1
  |   | 20.1 | 20 | 20 | 20 | 20
  |   | - |   | 1 | 1 | 1
  |   | . | 1. | 1. | 1. | 1.
  |   | 5 | 5 | 5 | 5 | 5
Float | 2-20 | 0 | 0 | 2 | 2 | 2
  |   | 2.1 | 2.1 | 2.1 | 2.1 | 2.1
  |   | 5 | 5 | 5 | 5 | 5
  |   | 20.1 | 20.1 | 20 | 20 | 20
  |   | - |   | 2 | 2 | 2
  |   | . | 2. | 2. | 2. | 2.
Float with decimal limit | 20.2-200.2 | 0 | 0 | 20.2 | 20.2 | 20.2
  |   | 20. | 20. | 20.2 | 20.2 | 20.2
  |   | 50 | 50 | 50 | 50 | 50
  |   | 200.3 | 200.3 | 200.2 | 200.2 | 200.2
  |   | - |   | 20.2 | 20.2 | 20.2
  |   | . | 20. | 20.2 | 20.2 | 20.2
Float with decimal limit   (smart) | 0-20.2 | 0 | 0 | 0 | 0 | 0
  |   | 20. | 20. | 20. | 20. | 20.
  |   | 5 | 5 | 5 | 5 | 5
  |   | 20.3 | 20.2 | 20.2 | 20.2 | 20.2
  |   | - |   | 0 | 0 | 0
  |   | . | 0. | 0. | 0. | 0.
Negative Float (smart) | -10-20 | -10.2 | -10 | -10 | -10 | -10
  |   | 20. | 20. | 20. | 20. | 20.
  |   | 20.1 | 20 | 20 | 20 | 20
  |   | 0 | 0 | 0 | 0 | 0
  |   | - | - | -10 | -10 | -10
  |   | . | -10 | -10 | -10 | -10
  |   | -. | -10. | -10. | -10. | -10.
  |   | -10- | 10 | 10 | 10 | 10
  |   | 10- | -10 | -10 | -10 | -10
Negative Float with decimal limit | -10.2--20.2 | -10.1 | -10.1 | -10.2
| -10.2 | -10.2
  |   | -20. | -20. | -20. | -20. | -20.
  |   | -20.3 | -20.3 | -20.2 | -20.2 | -20.2
  |   | 0 | 0 | -10.2 | -10.2 | -10.2
  |   | - | - | -20.2 | -20.2 | -20.2
  |   | . | -20. | -20. | -20. | -20.
  |   | -. | -20. | -20. | -20. | -20.
  |   | -10.2- | 10.2 | -10.2 | -10.2 | -10.2
  |   | 10.2- | -10.2 | -10.2 | -10.2 | -10.2
Int (smart) | 1-20 | 0 | 1 | 1 | 1 | 1
  |   | 1. | 1 | 1 | 1 | 1
  |   | 21 | 20 | 20 | 20 | 20
  |   | 5 | 5 | 5 | 5 | 5
  |   | - |   | 1 | 1 | 1
  |   | . |   | 1 | 1 | 1
Int | 20-200 | 19 | 19 | 20 | 20 | 20
  |   | 201 | 201 | 200 | 200 | 200
  |   | 50 | 50 | 50 | 50 | 50
  |   | - |   | 20 | 20 | 20
  |   | . |   | 20 | 20 | 20
Negative Int (smart) | -10-20 | -11 | -10 | -10 | -10 | -10
  |   | 0 | 0 | 0 | 0 | 0
  |   | 21 | 20 | 20 | 20 | 20
  |   | - | - | -10 | -10 | -10
  |   | . |   | -10 | -10 | -10
  |   | -. | - | -10 | -10 | -10
  |   | -10- | 10 | 10 | 10 | 10
  |   | 10- | -10 | -10 | -10 | -10
Negative Int | -200---20 | -201 | -201 | -200 | -200 | -200
  |   | -19 | -19 | -20 | -20 | -20
  |   | -50 | -50 | -50 | -50 | -50
  |   | - | - | -200 | -200 | -200
  |   | . |   | -200 | -200 | -200
  |   | -. | - | -200 | -200 | -200
  |   | -20- | 20 | -20 | -20 | -20
  |   | 20- | -20 | -20 | -20 | -20



</body>

</html>

## Why It's Good For The Game
Even though not used often on TG code, the modal inputs are used on
other code bases and inputting numbers has been a hell if it was
anything other than a positive integer. This PR aims to make the
handling as user friendly as possible, even if it's a lot more edge case
checking than the very simple code beforehand.
## Changelog
fixes #81457
🆑
qol: makes the tgui_input_number user friendly for negative and decimal
inputs
code: the onBlur={(_, value) => onBlur(value)} event should now be used
on all uses of RestrictedInput to ensure that the number is fully
sanitized whenever the user leaves the field or submits it through a
button
/🆑

* Makes the restricted number input user friendlier

---------

Co-authored-by: Kashargul <[email protected]>
@Iajret Iajret merged commit 840d5ed into master Feb 19, 2024
24 checks passed
AnywayFarus added a commit that referenced this pull request Feb 19, 2024
@Iajret Iajret deleted the upstream-mirror-1037 branch February 20, 2024 09:24
Iajret pushed a commit that referenced this pull request Apr 18, 2024
…ly been missing. Also Deviant Tastes dirty food re-nerf. (#2043)

* Adds "Strong Stomach" quirk, a core CDDA/PZ quirk we've sorely been missing. Also Deviant Tastes dirty food re-nerf. (#82562)

## About The Pull Request

- Adds Strong Stomach quirk. 
   - 4 points
   - You can eat dirty food without risk of getting disease. 
- You suffer less negative effects from vomiting. Vomit stuns you for
half the duration, and you lose half as much nutrition.

- Reverts tgstation/tgstation#76864 , integrates
its effects into Strong Stomach instead.

## Why It's Good For The Game

- Lotta people (namely Lizards and sometimes Felines with Deviant
Tastes) run gimmicks involving them being a gremlin person and eating
trash off the ground, and it's rather hard to accomplish this now since
it makes you a public medbay enemy # 1. This quirk should give them an
option to avoid that.
- Also (as mentioned in the title) both CDDA and PZ have this trait and
I can't believe we're missing it! This is something in
modifiable-character-traits/quirks-101.

- I moved the effects from #76864 to this quirk because 1. I thought it
was more fitting and 2. I thought the original PR was kinda wack for
what is (generally) a neutral quirk.

## Changelog

:cl: Melbert
add: Adds the Strong Stomach quirk, which allows you to eat grimy food
without worry about disease, and makes you a bit more resilient to the
effects of vomiting.
del: Deviant Tastes no longer prevents you from getting a negative
moodlet from eating dirty food. Strong Stomach does that now.
/:cl:

---------

Co-authored-by: Jacquerel <[email protected]>

* Adds "Strong Stomach" quirk, a core CDDA/PZ quirk we've sorely been missing. Also Deviant Tastes dirty food re-nerf.

---------

Co-authored-by: MrMelbert <[email protected]>
Co-authored-by: Jacquerel <[email protected]>
ReezeBL pushed a commit that referenced this pull request Apr 18, 2024
…ly been missing. Also Deviant Tastes dirty food re-nerf. (#2043) (#2940)

* Adds "Strong Stomach" quirk, a core CDDA/PZ quirk we've sorely been missing. Also Deviant Tastes dirty food re-nerf. (#82562)

## About The Pull Request

- Adds Strong Stomach quirk. 
   - 4 points
   - You can eat dirty food without risk of getting disease. 
- You suffer less negative effects from vomiting. Vomit stuns you for
half the duration, and you lose half as much nutrition.

- Reverts tgstation/tgstation#76864 , integrates
its effects into Strong Stomach instead.

## Why It's Good For The Game

- Lotta people (namely Lizards and sometimes Felines with Deviant
Tastes) run gimmicks involving them being a gremlin person and eating
trash off the ground, and it's rather hard to accomplish this now since
it makes you a public medbay enemy # 1. This quirk should give them an
option to avoid that.
- Also (as mentioned in the title) both CDDA and PZ have this trait and
I can't believe we're missing it! This is something in
modifiable-character-traits/quirks-101.

- I moved the effects from #76864 to this quirk because 1. I thought it
was more fitting and 2. I thought the original PR was kinda wack for
what is (generally) a neutral quirk.

## Changelog

:cl: Melbert
add: Adds the Strong Stomach quirk, which allows you to eat grimy food
without worry about disease, and makes you a bit more resilient to the
effects of vomiting.
del: Deviant Tastes no longer prevents you from getting a negative
moodlet from eating dirty food. Strong Stomach does that now.
/:cl:

---------



* Adds "Strong Stomach" quirk, a core CDDA/PZ quirk we've sorely been missing. Also Deviant Tastes dirty food re-nerf.

---------

Co-authored-by: NovaBot <[email protected]>
Co-authored-by: MrMelbert <[email protected]>
Co-authored-by: Jacquerel <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants