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

Settings - Fix decimal formatting not pushed to variable #1564

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
27 changes: 23 additions & 4 deletions addons/settings/fnc_gui_settingSlider.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ params ["_controlsGroup", "_setting", "_source", "_currentValue", "_settingData"
_settingData params ["_min", "_max", "_trailingDecimals", "_isPercentage"];

private _range = _max - _min;
private _arrowStep = [(0.05 * _range), _trailingDecimals] call BIS_fnc_cutDecimals;
private _sliderSpeed = [(0.1 * _range), _trailingDecimals] call BIS_fnc_cutDecimals;

private _ctrlSlider = _controlsGroup controlsGroupCtrl IDC_SETTING_SLIDER;
_ctrlSlider sliderSetRange [_min, _max];
_ctrlSlider sliderSetPosition _currentValue;
_ctrlSlider sliderSetSpeed [0.05 * _range, 0.1 * _range];
_ctrlSlider sliderSetSpeed [_arrowStep, _sliderSpeed];

_ctrlSlider setVariable [QGVAR(params), [_setting, _source, _trailingDecimals, _isPercentage]];
_ctrlSlider ctrlAddEventHandler ["SliderPosChanged", {
Expand All @@ -20,9 +22,11 @@ _ctrlSlider ctrlAddEventHandler ["SliderPosChanged", {
} else {
if (_trailingDecimals < 0) then {
_value = round _value;
} else {
_value = [_value, _trailingDecimals] call BIS_fnc_cutDecimals;
};

[_value, 1, _trailingDecimals max 0] call CBA_fnc_formatNumber
[_value, 1, _trailingDecimals max 0] call CBA_fnc_formatNumber;
};

private _controlsGroup = ctrlParentControlsGroup _ctrlSlider;
Expand All @@ -45,6 +49,12 @@ _ctrlSlider ctrlAddEventHandler ["SliderPosChanged", {
private _editText = if (_isPercentage) then {
format [localize "STR_3DEN_percentageUnit", round (_currentValue * 100), "%"]
} else {
if (_trailingDecimals < 0) then {
_currentValue = round _currentValue;
} else {
_currentValue = [_currentValue, _trailingDecimals] call BIS_fnc_cutDecimals;
};

[_currentValue, 1, _trailingDecimals max 0] call CBA_fnc_formatNumber
};

Expand All @@ -63,6 +73,8 @@ _ctrlSliderEdit ctrlAddEventHandler ["KeyUp", {
} else {
if (_trailingDecimals < 0) then {
_value = round _value;
} else {
_value = [_value, _trailingDecimals] call BIS_fnc_cutDecimals;
};
};

Expand Down Expand Up @@ -99,6 +111,8 @@ _ctrlSliderEdit ctrlAddEventHandler ["KillFocus", {
} else {
if (_trailingDecimals < 0) then {
_value = round _value;
} else {
_value = [_value, _trailingDecimals] call BIS_fnc_cutDecimals;
};

[_value, 1, _trailingDecimals max 0] call CBA_fnc_formatNumber
Expand All @@ -120,14 +134,19 @@ _controlsGroup setVariable [QFUNC(updateUI), {
private _ctrlSlider = _controlsGroup controlsGroupCtrl IDC_SETTING_SLIDER;
private _ctrlSliderEdit = _controlsGroup controlsGroupCtrl IDC_SETTING_SLIDER_EDIT;

_ctrlSlider sliderSetPosition _value;

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

[_value, 1, _trailingDecimals max 0] call CBA_fnc_formatNumber
};

_ctrlSlider sliderSetPosition _value;
_ctrlSliderEdit ctrlSetText _editText;

// if new value is same as default value, grey out the default button
Expand Down