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

Disable default settings button if setting is already default #444

Merged
merged 2 commits into from
Jul 26, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions addons/settings/fnc_gui_refresh.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

private _display = uiNamespace getVariable [QGVAR(display), displayNull];
private _ctrlOptionsGroup = ((_display getVariable [QGVAR(controls), []]) select {ctrlShown _x}) param [0, controlNull];
private _contols = _ctrlOptionsGroup getVariable [QGVAR(controls), []];
private _controls = _ctrlOptionsGroup getVariable [QGVAR(controls), []];

{
private _linkedControls = _x getVariable QGVAR(linkedControls);
Expand All @@ -15,25 +15,31 @@ private _contols = _ctrlOptionsGroup getVariable [QGVAR(controls), []];
if (!isNil "_value") then {
switch (toUpper _settingType) do {
case ("CHECKBOX"): {
_linkedControls params ["_ctrlSetting"];
_linkedControls params ["_ctrlSetting", "_defaultControl"];

_ctrlSetting cbSetChecked _value;

_defaultControl ctrlEnable !(_value isEqualTo _defaultValue);
};
case ("LIST"): {
_settingData params ["_values"];
_linkedControls params ["_ctrlSetting"];
_linkedControls params ["_ctrlSetting", "_defaultControl"];

_ctrlSetting lbSetCurSel (_values find _value);

_defaultControl ctrlEnable !(_value isEqualTo _defaultValue);
};
case ("SLIDER"): {
_settingData params ["", "", "_trailingDecimals"];
_linkedControls params ["_ctrlSetting", "_ctrlSettingEdit"];
_linkedControls params ["_ctrlSetting", "_ctrlSettingEdit", "_defaultControl"];

_ctrlSetting sliderSetPosition _value;
_ctrlSettingEdit ctrlSetText ([_value, 1, _trailingDecimals] call CBA_fnc_formatNumber);

_defaultControl ctrlEnable !(_value isEqualTo _defaultValue);
};
case ("COLOR"): {
_linkedControls params ["_ctrlSettingPreview", "_settingControls"];
_linkedControls params ["_ctrlSettingPreview", "_settingControls", "_defaultControl"];

_value params [
["_r", 0, [0]],
Expand All @@ -51,6 +57,8 @@ private _contols = _ctrlOptionsGroup getVariable [QGVAR(controls), []];
_ctrlSetting sliderSetPosition _valueX;
_ctrlSettingEdit ctrlSetText ([_valueX, 1, 2] call CBA_fnc_formatNumber);
} forEach _settingControls;

_defaultControl ctrlEnable !(_value isEqualTo _defaultValue);
};
default {};
};
Expand All @@ -74,4 +82,4 @@ private _contols = _ctrlOptionsGroup getVariable [QGVAR(controls), []];
default {};
};
};
} forEach _contols;
} forEach _controls;
2 changes: 1 addition & 1 deletion addons/settings/gui_createMenu.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ _display setVariable [QGVAR(controls), []];
private _isOverwritten = [_setting, _source] call FUNC(isOverwritten);

// ----- create setting changer control
private _contols = _ctrlOptionsGroup getVariable QGVAR(controls);
private _controls = _ctrlOptionsGroup getVariable QGVAR(controls);
private _linkedControls = [];

switch (toUpper _settingType) do {
Expand Down
9 changes: 7 additions & 2 deletions addons/settings/gui_createMenu_checkbox.sqf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// inline function, don't include script_component.hpp

private _ctrlSetting = _display ctrlCreate ["RscCheckBox", count _contols + IDC_OFFSET_SETTING, _ctrlOptionsGroup];
_contols pushBack _ctrlSetting;
private _ctrlSetting = _display ctrlCreate ["RscCheckBox", count _controls + IDC_OFFSET_SETTING, _ctrlOptionsGroup];
_controls pushBack _ctrlSetting;

_ctrlSetting ctrlSetPosition [
POS_W(16),
Expand All @@ -24,6 +24,11 @@ _ctrlSetting ctrlAddEventHandler ["CheckedChanged", {

private _value = _state == 1;
SET_TEMP_NAMESPACE_VALUE(_setting,_value,_source);

//If new setting is same as default value, grey out the default button
(_control getVariable QGVAR(linkedControls)) params ["", "_defaultControl"];
(_defaultControl getVariable QGVAR(data)) params ["", "", "_defaultValue"];
_defaultControl ctrlEnable (!(_value isEqualTo _defaultValue));
}];

_linkedControls pushBack _ctrlSetting;
Expand Down
22 changes: 16 additions & 6 deletions addons/settings/gui_createMenu_color.sqf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// inline function, don't include script_component.hpp

private _ctrlSettingPreview = _display ctrlCreate ["RscText", count _contols + IDC_OFFSET_SETTING, _ctrlOptionsGroup];
_contols pushBack _ctrlSettingPreview;
private _ctrlSettingPreview = _display ctrlCreate ["RscText", count _controls + IDC_OFFSET_SETTING, _ctrlOptionsGroup];
_controls pushBack _ctrlSettingPreview;

_ctrlSettingPreview ctrlSetPosition [
POS_W(9.5),
Expand All @@ -28,8 +28,8 @@ _ctrlSettingPreview setVariable [QGVAR(data), _data];
_linkedControls append [_ctrlSettingPreview, []];

for "_index" from 0 to (((count _defaultValue max 3) min 4) - 1) do {
private _ctrlSetting = _display ctrlCreate [SLIDER_TYPES param [_index, "RscXSliderH"], count _contols + IDC_OFFSET_SETTING, _ctrlOptionsGroup];
_contols pushBack _ctrlSetting;
private _ctrlSetting = _display ctrlCreate [SLIDER_TYPES param [_index, "RscXSliderH"], count _controls + IDC_OFFSET_SETTING, _ctrlOptionsGroup];
_controls pushBack _ctrlSetting;

_ctrlSetting ctrlSetPosition [
POS_W(16),
Expand Down Expand Up @@ -60,10 +60,15 @@ for "_index" from 0 to (((count _defaultValue max 3) min 4) - 1) do {
_color set [_index, _value];
_ctrlSettingPreview ctrlSetBackgroundColor _color;
SET_TEMP_NAMESPACE_VALUE(_setting,_currentValue,_source);

//If new setting is same as default value, grey out the default button
(_control getVariable QGVAR(linkedControls)) params ["", "", "_defaultControl"];
(_defaultControl getVariable QGVAR(data)) params ["", "", "_defaultValue"];
_defaultControl ctrlEnable (!(_currentValue isEqualTo _defaultValue));
}];

private _ctrlSettingEdit = _display ctrlCreate ["RscEdit", count _contols + IDC_OFFSET_SETTING, _ctrlOptionsGroup];
_contols pushBack _ctrlSettingEdit;
private _ctrlSettingEdit = _display ctrlCreate ["RscEdit", count _controls + IDC_OFFSET_SETTING, _ctrlOptionsGroup];
_controls pushBack _ctrlSettingEdit;

_ctrlSettingEdit ctrlSetPosition [
POS_W(24),
Expand Down Expand Up @@ -98,6 +103,11 @@ for "_index" from 0 to (((count _defaultValue max 3) min 4) - 1) do {
_color set [_index, _value];
_ctrlSettingPreview ctrlSetBackgroundColor _color;
SET_TEMP_NAMESPACE_VALUE(_setting,_currentValue,_source);

//If new setting is same as default value, grey out the default button
(_control getVariable QGVAR(linkedControls)) params ["", "", "_defaultControl"];
Copy link
Contributor

@commy2 commy2 Jul 26, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be added to L55

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be added to L92/97

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. IDK why, but it keeps messing up the line of this ^ comment. Meant for L108.

(_defaultControl getVariable QGVAR(data)) params ["", "", "_defaultValue"];
_defaultControl ctrlEnable (!(_currentValue isEqualTo _defaultValue));
}];

_ctrlSettingEdit ctrlAddEventHandler ["KillFocus", {
Expand Down
8 changes: 5 additions & 3 deletions addons/settings/gui_createMenu_default.sqf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// inline function, don't include script_component.hpp

private _ctrlSettingDefault = _display ctrlCreate ["RscButtonMenu", count _contols + IDC_OFFSET_SETTING, _ctrlOptionsGroup];
_contols pushBack _ctrlSettingDefault;
private _ctrlSettingDefault = _display ctrlCreate ["RscButtonMenu", count _controls + IDC_OFFSET_SETTING, _ctrlOptionsGroup];
_controls pushBack _ctrlSettingDefault;

_ctrlSettingDefault ctrlSetPosition [
POS_W(27),
Expand All @@ -23,6 +23,8 @@ _ctrlSettingDefault ctrlAddEventHandler ["ButtonClick", {
(_control getVariable QGVAR(data)) params ["_setting", "_source", "_defaultValue", "_settingType", "_settingData"];
SET_TEMP_NAMESPACE_VALUE(_setting,_defaultValue,_source);

_control ctrlEnable false;

private _linkedControls = _control getVariable QGVAR(linkedControls);

// reset buttons to default state
Expand Down Expand Up @@ -71,6 +73,6 @@ _ctrlSettingDefault ctrlAddEventHandler ["ButtonClick", {

_linkedControls pushBack _ctrlSettingDefault;

if !(_enabled) then {
if ((!_enabled) || {_currentValue isEqualTo _defaultValue}) then {
_ctrlSettingDefault ctrlEnable false;
};
4 changes: 2 additions & 2 deletions addons/settings/gui_createMenu_force.sqf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// inline function, don't include script_component.hpp

private _ctrlSettingForce = _display ctrlCreate ["RscCheckBox", count _contols + IDC_OFFSET_SETTING, _ctrlOptionsGroup];
_contols pushBack _ctrlSettingForce;
private _ctrlSettingForce = _display ctrlCreate ["RscCheckBox", count _controls + IDC_OFFSET_SETTING, _ctrlOptionsGroup];
_controls pushBack _ctrlSettingForce;

_ctrlSettingForce ctrlSetPosition [
POS_W(33),
Expand Down
9 changes: 7 additions & 2 deletions addons/settings/gui_createMenu_list.sqf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// inline function, don't include script_component.hpp

private _ctrlSetting = _display ctrlCreate ["RscCombo", count _contols + IDC_OFFSET_SETTING, _ctrlOptionsGroup];
_contols pushBack _ctrlSetting;
private _ctrlSetting = _display ctrlCreate ["RscCombo", count _controls + IDC_OFFSET_SETTING, _ctrlOptionsGroup];
_controls pushBack _ctrlSetting;

_ctrlSetting ctrlSetPosition [
POS_W(16),
Expand Down Expand Up @@ -39,6 +39,11 @@ _ctrlSetting ctrlAddEventHandler ["LBSelChanged", {

private _value = _data select _index;
SET_TEMP_NAMESPACE_VALUE(_setting,_value,_source);

//If new setting is same as default value, grey out the default button
(_control getVariable QGVAR(linkedControls)) params ["", "_defaultControl"];
(_defaultControl getVariable QGVAR(data)) params ["", "", "_defaultValue"];
_defaultControl ctrlEnable (!(_value isEqualTo _defaultValue));
}];

_linkedControls pushBack _ctrlSetting;
Expand Down
18 changes: 14 additions & 4 deletions addons/settings/gui_createMenu_slider.sqf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// inline function, don't include script_component.hpp

private _ctrlSetting = _display ctrlCreate ["RscXSliderH", count _contols + IDC_OFFSET_SETTING, _ctrlOptionsGroup];
_contols pushBack _ctrlSetting;
private _ctrlSetting = _display ctrlCreate ["RscXSliderH", count _controls + IDC_OFFSET_SETTING, _ctrlOptionsGroup];
_controls pushBack _ctrlSetting;

_ctrlSetting ctrlSetPosition [
POS_W(16),
Expand Down Expand Up @@ -30,10 +30,15 @@ _ctrlSetting ctrlAddEventHandler ["SliderPosChanged", {
_linkedControl ctrlSetText ([_value, 1, _trailingDecimals] call CBA_fnc_formatNumber);

SET_TEMP_NAMESPACE_VALUE(_setting,_value,_source);

//If new setting is same as default value, grey out the default button
(_control getVariable QGVAR(linkedControls)) params ["", "", "_defaultControl"];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be moved to L29 and be used to define _linkedControl directly.

(_defaultControl getVariable QGVAR(data)) params ["", "", "_defaultValue"];
_defaultControl ctrlEnable (!(_value isEqualTo _defaultValue));
}];

private _ctrlSettingEdit = _display ctrlCreate ["RscEdit", count _contols + IDC_OFFSET_SETTING, _ctrlOptionsGroup];
_contols pushBack _ctrlSettingEdit;
private _ctrlSettingEdit = _display ctrlCreate ["RscEdit", count _controls + IDC_OFFSET_SETTING, _ctrlOptionsGroup];
_controls pushBack _ctrlSettingEdit;

_ctrlSettingEdit ctrlSetPosition [
POS_W(24),
Expand All @@ -59,6 +64,11 @@ _ctrlSettingEdit ctrlAddEventHandler ["KeyUp", {

_value = sliderPosition _linkedControl;
SET_TEMP_NAMESPACE_VALUE(_setting,_value,_source);

//If new setting is same as default value, grey out the default button
(_control getVariable QGVAR(linkedControls)) params ["", "", "_defaultControl"];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be moved to L57/62 and be used to define _linkedControl directly.

(_defaultControl getVariable QGVAR(data)) params ["", "", "_defaultValue"];
_defaultControl ctrlEnable (!(_value isEqualTo _defaultValue));
}];

_ctrlSettingEdit ctrlAddEventHandler ["KillFocus", {
Expand Down
39 changes: 21 additions & 18 deletions addons/settings/gui_initDisplay.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -65,24 +65,27 @@ _ctrlButtonLoad ctrlEnable false;
_ctrlButtonLoad ctrlShow false;
_ctrlButtonLoad ctrlAddEventHandler ["ButtonClick", {[ctrlParent (_this select 0), "load"] call FUNC(gui_preset)}];

// ----- create export and import buttons
private _ctrlButtonImport = _display ctrlCreate ["RscButtonMenu", IDC_BTN_IMPORT];

_ctrlButtonImport ctrlSetPosition [
POS_X(24.4),
POS_Y(20.5),
POS_W(6),
POS_H(1)
];

_ctrlButtonImport ctrlCommit 0;
_ctrlButtonImport ctrlSetText localize LSTRING(ButtonImport);
_ctrlButtonImport ctrlSetTooltip localize LSTRING(ButtonImport_tooltip);
_ctrlButtonImport ctrlEnable false;
_ctrlButtonImport ctrlShow false;
_ctrlButtonImport ctrlAddEventHandler ["ButtonClick", {[copyFromClipboard, uiNamespace getVariable QGVAR(source)] call FUNC(import)}];

uiNamespace setVariable [QGVAR(ctrlButtonImport), _ctrlButtonImport];
// copyFromClipboard has no effect in MP, so only add button in SP
if (!isMultiplayer) then {
// ----- create export and import buttons
private _ctrlButtonImport = _display ctrlCreate ["RscButtonMenu", IDC_BTN_IMPORT];

_ctrlButtonImport ctrlSetPosition [
POS_X(24.4),
POS_Y(20.5),
POS_W(6),
POS_H(1)
];

_ctrlButtonImport ctrlCommit 0;
_ctrlButtonImport ctrlSetText localize LSTRING(ButtonImport);
_ctrlButtonImport ctrlSetTooltip localize LSTRING(ButtonImport_tooltip);
_ctrlButtonImport ctrlEnable false;
_ctrlButtonImport ctrlShow false;
_ctrlButtonImport ctrlAddEventHandler ["ButtonClick", {[copyFromClipboard, uiNamespace getVariable QGVAR(source)] call FUNC(import)}];

uiNamespace setVariable [QGVAR(ctrlButtonImport), _ctrlButtonImport];
};

private _ctrlButtonExport = _display ctrlCreate ["RscButtonMenu", IDC_BTN_EXPORT];

Expand Down