Skip to content

Settings - Fix decimal formatting not pushed to variable#1564

Open
Daniel-H123 wants to merge 8 commits intoCBATeam:masterfrom
Daniel-H123:master
Open

Settings - Fix decimal formatting not pushed to variable#1564
Daniel-H123 wants to merge 8 commits intoCBATeam:masterfrom
Daniel-H123:master

Conversation

@Daniel-H123
Copy link
Copy Markdown

@Daniel-H123 Daniel-H123 commented Jan 10, 2023

When merged this pull request will:

  • Fixed bug that slider variable does not take in to account the decimal count

@Daniel-H123 Daniel-H123 changed the title Bugfix - Decimal formatting not pushed to variable Settings - Bugfix decimal formatting not pushed to variable Jan 10, 2023
@PabstMirror
Copy link
Copy Markdown
Contributor

    private _editText = if (_isPercentage) then {
        format [localize "STR_3DEN_percentageUnit", round (_value * 100), "%"]
    } else {
        if (_trailingDecimals < 0) then {
            _value = round _value;
        };
        _value = [_value, 1, _trailingDecimals max 0] call CBA_fnc_formatNumber;
    };

I think _editText will be nil?
Has this been tested?

@mharis001
Copy link
Copy Markdown
Contributor

And _value will be a string and not number.

@Daniel-H123
Copy link
Copy Markdown
Author

Daniel-H123 commented Jan 10, 2023

Yeah you're right. I assumed it too fast and looked over _editText. But the _value needs to be updated with the correct amount of decimals right?

@Daniel-H123
Copy link
Copy Markdown
Author

Daniel-H123 commented Jan 10, 2023

Maybe something like this:

private _editText = if (_isPercentage) then {
        format [localize "STR_3DEN_percentageUnit", round (_value * 100), "%"]
    } else {
        if (_trailingDecimals < 0) then {
            _value = round _value;
        } else {
            _value = round(_value * pow(10, _trailingDecimals)) / pow(10, _trailingDecimals);
       };
        [_value, 1, _trailingDecimals max 0] call CBA_fnc_formatNumber;
    };

@Daniel-H123
Copy link
Copy Markdown
Author

Or better:
_value = _value toFixed _trailingDecimals;

@Daniel-H123 Daniel-H123 marked this pull request as draft January 10, 2023 23:01
@Daniel-H123
Copy link
Copy Markdown
Author

Daniel-H123 commented Jan 10, 2023

The "bug" is definitly there, but my solution was obviously not the right one (thx for pointing out 💯).
I think I fixed it now, but changed it to a draft. I will test this as soon as I can. I'll update this after that.
Thought this would be an 'easy' fix 🤡

Daniel-H123 and others added 4 commits January 11, 2023 09:00
- Moved slidebar update to after rounding variable
- Applied decimal formatting to slider speed/step
@Daniel-H123 Daniel-H123 marked this pull request as ready for review January 11, 2023 11:43
@Daniel-H123
Copy link
Copy Markdown
Author

This is now working code. Updated that decimal count is enforced in:

  • Silder speed (when clicking inside slider)
  • Step count (amount changed when arrow keys are pressed)
  • All updates of the GUI

I tested it in-game and have tested the code for errors, but let me know if there are any problems.

@Daniel-H123 Daniel-H123 changed the title Settings - Bugfix decimal formatting not pushed to variable Settings - Fix decimal formatting not pushed to variable Dec 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants