fn_setSettings.sqf 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. Name: cTab_fnc_setSettings
  3. Author(s):
  4. Gundy
  5. Description:
  6. Write cTab settings. Will call cTab_updateInterface for any setting that changed.
  7. Parameters:
  8. 0: STRING - Name of uiNamespace display / dialog variable
  9. 1: ARRAY - Property pair(s) to write in the form of [["propertyName",propertyValue],[...]]
  10. (Optional)
  11. 2: BOOLEAN - If set to false, do not update interface (default true)
  12. 3: BOOLEAN - If set to true, update interface even if the values haven't changed (default false)
  13. Returns:
  14. BOOLEAN - If settings could be stored
  15. Example:
  16. ["cTab_Tablet_dlg",[["mapType","SAT"],["mapScaleDsp","4"]]] call cTab_fnc_setSettings;
  17. // Update mapWorldPos and update the interface even if the value has not changed
  18. ["cTab_Tablet_dlg",[["mapWorldPos",getPosASL vehicle player]],true,true] call cTab_fnc_setSettings;
  19. // Update mapWorldPos and mapScale, but do not update the interface
  20. ["cTab_Tablet_dlg",[["mapWorldPos",getPosASL vehicle player],["mapScaleDsp","2"]],false] call cTab_fnc_setSettings;
  21. */
  22. private ["_propertyGroupName","_commonProperties","_groupProperties","_properties","_commonPropertiesUpdate","_combinedPropertiesUpdate","_key","_value","_currentValue","_updateInterface","_forceInterfaceUpdate"];
  23. _propertyGroupName = [cTabDisplayPropertyGroups,_this select 0] call cTab_fnc_getFromPairs;
  24. // Exit with FALSE if uiNamespace variable cannot be found in cTabDisplayPropertyGroups
  25. if (isNil "_propertyGroupName") exitWith {false};
  26. _commonProperties = [cTabSettings,"COMMON"] call cTab_fnc_getFromPairs;
  27. _groupProperties = [cTabSettings,_propertyGroupName] call cTab_fnc_getFromPairs;
  28. if (isNil "_groupProperties") then {_groupProperties = [];};
  29. _properties = _this select 1;
  30. _updateInterface = if (count _this > 2) then {_this select 2} else {true};
  31. _forceInterfaceUpdate = if (count _this > 3) then {_this select 3} else {false};
  32. // Write multiple property pairs. If they exist in _groupProperties, write them there, else write them to COMMON. Only write if they exist and have changed.
  33. _commonPropertiesUpdate = [];
  34. _combinedPropertiesUpdate = [];
  35. {
  36. _key = _x select 0;
  37. _value = _x select 1;
  38. call {
  39. _currentValue = [_groupProperties,_key] call cTab_fnc_getFromPairs;
  40. if (!isNil "_currentValue") exitWith {
  41. call {
  42. if !(_currentValue isEqualTo _value) exitWith {
  43. [_combinedPropertiesUpdate,_key,_value] call BIS_fnc_setToPairs;
  44. [_groupProperties,_key,_value] call BIS_fnc_setToPairs;
  45. };
  46. if (_forceInterfaceUpdate) then {
  47. [_combinedPropertiesUpdate,_key,_value] call BIS_fnc_setToPairs;
  48. };
  49. };
  50. };
  51. _currentValue = [_commonProperties,_key] call cTab_fnc_getFromPairs;
  52. if (!isNil "_currentValue") then {
  53. call {
  54. if !(_currentValue isEqualTo _value) then {
  55. [_commonPropertiesUpdate,_key,_value] call BIS_fnc_setToPairs;
  56. [_commonProperties,_key,_value] call BIS_fnc_setToPairs;
  57. };
  58. if (_forceInterfaceUpdate) then {
  59. [_commonPropertiesUpdate,_key,_value] call BIS_fnc_setToPairs;
  60. };
  61. };
  62. };
  63. };
  64. } forEach _properties;
  65. [cTabSettings,_propertyGroupName,_groupProperties] call BIS_fnc_setToPairs;
  66. [cTabSettings,"COMMON",_commonProperties] call BIS_fnc_setToPairs;
  67. // Finally, call an interface update for the updated properties, but only if the currently interface uses the same property group, if not, pass changed common properties only.
  68. if (!isNil "cTabIfOpen") then {
  69. call {
  70. if (!_updateInterface) exitWith {};
  71. if ((([cTabDisplayPropertyGroups,cTabIfOpen select 1] call cTab_fnc_getFromPairs) == _propertyGroupName) && {count _combinedPropertiesUpdate > 0}) exitWith {
  72. [_combinedPropertiesUpdate] call cTab_fnc_updateInterface;
  73. };
  74. if (count _commonPropertiesUpdate > 0) then {
  75. [_commonPropertiesUpdate] call cTab_fnc_updateInterface;
  76. };
  77. };
  78. };
  79. if (_combinedPropertiesUpdate isEqualTo [] && _combinedPropertiesUpdate isEqualTo []) exitWith {false};
  80. true