ACE_Settings: updated optionsmenu to use the the new system

This commit is contained in:
Nicolás Badano 2015-02-03 00:44:34 -03:00
parent 173169bc3d
commit 91cfb40e6f
12 changed files with 64 additions and 182 deletions

View File

@ -3,9 +3,3 @@ class Extended_PreInit_EventHandlers {
init = QUOTE(call COMPILE_FILE(XEH_preInit));
};
};
class Extended_PostInit_EventHandlers {
class ADDON {
init = QUOTE(call COMPILE_FILE(XEH_postInit));
};
};

View File

@ -1,4 +0,0 @@
#include "script_component.hpp"
//Add Settings from configFile
[] call FUNC(addFromConfig);

View File

@ -2,16 +2,11 @@
ADDON = false;
PREP(addClientSideColor);
PREP(addClientSideOptions);
PREP(addFromConfig);
PREP(loadFromProfile);
PREP(onListBoxSettingsChanged);
PREP(onListBoxShowSelectionChanged);
PREP(onSettingsMenuOpen);
PREP(onSliderPosChanged);
PREP(resetSettings);
PREP(saveToProfile);
PREP(settingsMenuUpdateKeyView);
PREP(settingsMenuUpdateList);
PREP(updateSetting);

View File

@ -1,19 +0,0 @@
/**
* fnc_addClientSideColor.sqf
* @Descr: N/A
* @Author: PabstMirror
*
* @Arguments: []
* @Return:
* @PublicAPI: false
*/
#include "script_component.hpp"
private ["_currentValue"];
PARAMS_4(_name,_localizedName,_localizedDescription,_defaultValue);
GVAR(clientSideColors) pushBack [_name, _localizedName, _localizedDescription, [], _defaultValue];
//Get the current setting from profile (or default) and set it:
_currentValue = [MENU_TAB_COLORS, _name, _defaultValue] call FUNC(loadFromProfile);
[MENU_TAB_COLORS, _name, _currentValue] call FUNC(updateSetting);

View File

@ -1,19 +0,0 @@
/**
* fnc_addClientSideOptions.sqf
* @Descr: N/A
* @Author: Glowbal
*
* @Arguments: []
* @Return:
* @PublicAPI: false
*/
#include "script_component.hpp"
private ["_currentValue"];
PARAMS_5(_name,_localizedName,_localizedDescription,_possibleValues,_defaultValue);
GVAR(clientSideOptions) pushBack [_name, _localizedName, _localizedDescription, _possibleValues, -1, _defaultValue];
//Get the current setting from profile (or default) and set it:
_currentValue = [MENU_TAB_OPTIONS, _name, _defaultValue] call FUNC(loadFromProfile);
[MENU_TAB_OPTIONS, _name, _currentValue] call FUNC(updateSetting);

View File

@ -1,38 +0,0 @@
/**
* fnc_addFromConfig.sqf
* @Descr: N/A
* @Author: PabstMirror
*
* @Arguments: []
* @Return:
* @PublicAPI: false
*/
#include "script_component.hpp"
if (isClass (configFile >> "ACE_Options")) then {
_countOptions = count (configFile >> "ACE_Options");
for "_index" from 0 to (_countOptions - 1) do {
_optionEntry = (configFile >> "ACE_Options") select _index;
_name = configName _optionEntry;
_displayName = getText (_optionEntry >> "displayName");
_description = getText (_optionEntry >> "description");
_default = getNumber (_optionEntry >> "default");
_choices = getArray (_optionEntry >> "values");
if ((count _choices) == 0) then {
_choices = [(localize "STR_ACE_OptionsMenu_Disabled"), (localize "STR_ACE_OptionsMenu_Enabled")];
};
[_name, _displayName, _description, _choices, _default] call FUNC(addClientSideOptions);
};
};
if (isClass (configFile >> "ACE_Colors")) then {
_countOptions = count (configFile >> "ACE_Colors");
for "_index" from 0 to (_countOptions - 1) do {
_optionEntry = (configFile >> "ACE_Colors") select _index;
_name = configName _optionEntry;
_displayName = getText (_optionEntry >> "displayName");
_description = getText (_optionEntry >> "description");
_default = getArray (_optionEntry >> "default");
[_name, _displayName, _description, _default] call FUNC(addClientSideColor);
};
};

View File

@ -1,36 +0,0 @@
/**
* fnc_loadFromProfile.sqf
* @Descr: N/A
* @Author: Glowbal
*
* @Arguments: []
* @Return:
* @PublicAPI: false
*/
#include "script_component.hpp"
private ["_typeString", "_settingValue", "_badData"];
PARAMS_3(_type,_name,_default);
_typeString = "";
switch (_type) do {
case (MENU_TAB_OPTIONS): {_typeString = "option";};
case (MENU_TAB_COLORS): {_typeString = "color";};
};
_settingValue = profileNamespace getvariable [(format ["ace_%1_%2", _typeString, _name]), _default];
_badData = isNil "_settingValue";
if (!_badData) then {
switch (_type) do {
case (MENU_TAB_OPTIONS): {_badData = ((typeName _settingValue) != (typeName 0));};
case (MENU_TAB_COLORS): {_badData = (((typeName _settingValue) != (typeName [])) || {(count _settingValue) != 4});};
};
};
if (_badData) then {
_settingValue = _default;
systemChat format ["Bad Data in profile [ace_%1_%2] using default", _typeString, _name];
ERROR("Bad Value in profile");
};
_settingValue

View File

@ -9,5 +9,26 @@
*/
#include "script_component.hpp"
// Filter only user setable setting
GVAR(clientSideOptions) = [];
GVAR(clientSideColors) = [];
{
// If the setting is user setable
if (_x select 2) then {
// Append the current value to the setting metadata
_setting = + _x;
_setting pushBack (missionNamespace getVariable (_x select 0));
// Categorize the setting according to types
// @todo: allow the user to modify other types of parameters?
if ((_x select 1) == "SCALAR" || (_x select 1) == "BOOL") then {
GVAR(clientSideOptions) pushBack _setting;
};
if ((_x select 1) == "COLOR") then {
GVAR(clientSideColors) pushBack _setting;
};
};
} forEach EGVAR(common,settings);
//Delay a frame
[{ [MENU_TAB_OPTIONS] call FUNC(onListBoxShowSelectionChanged) }, []] call EFUNC(common,execNextFrame);

View File

@ -1,37 +0,0 @@
/**
* fnc_saveToProfile.sqf
* @Descr: Save the clientside option to the profile.
* @Author: Glowbal
*
* @Arguments: [name STRING (Name of setting)]
* @Return: BOOL True if saved.
* @PublicAPI: false
*/
#include "script_component.hpp"
private ["_nameSelected", "_saved"];
PARAMS_2(_type,_name);
_saved = false;
switch (_type) do {
case (MENU_TAB_OPTIONS): {
{
_nameSelected = _x select 0;
if (_nameSelected == _name) exitwith {
profileNamespace setvariable [(format ["ace_option_%1", _name]), (_x select 4)];
_saved = true;
};
}foreach GVAR(clientSideOptions);
};
case (MENU_TAB_COLORS): {
{
_nameSelected = _x select 0;
if (_nameSelected == _name) exitwith {
profileNamespace setvariable [(format ["ace_color_%1", _name]), (_x select 3)];
_saved = true;
};
}foreach GVAR(clientSideColors);
};
};
_saved

View File

@ -33,8 +33,8 @@ if (count _collection > 0) then {
_setting = _collection select _settingIndex;
_entryName = _setting select 0;
_localizedName = _setting select 1;
_localizedDescription = _setting select 2;
_localizedName = _setting select 3;
_localizedDescription = _setting select 4;
if (_localizedName == "") then {_localizedName = _entryName;};
(_settingsMenu displayCtrl 250) ctrlSetText _localizedName;
@ -43,15 +43,23 @@ if (count _collection > 0) then {
switch (GVAR(optionMenu_openTab)) do {
case (MENU_TAB_OPTIONS): {
_possibleValues = _setting select 3;
_settingsValue = _setting select 4;
lbClear 400;
{ lbAdd [400, _x]; } foreach _possibleValues;
_possibleValues = _setting select 5;
_settingsValue = _setting select 7;
// Created disable/enable options for bools
if ((_setting select 1) == "BOOL") then {
lbClear 400;
lbAdd [400, (localize "STR_ACE_OptionsMenu_Disabled")];
lbAdd [400, (localize "STR_ACE_OptionsMenu_Enabled")];
_settingsValue = [0, 1] select _settingsValue;
} else {
lbClear 400;
{ lbAdd [400, _x]; } foreach _possibleValues;
};
(_settingsMenu displayCtrl 400) lbSetCurSel _settingsValue;
};
case (MENU_TAB_COLORS): {
_currentColor = _setting select 3;
_currentColor = _setting select 7;
{
sliderSetPosition [_x, (255 * (_currentColor select _forEachIndex))];
} forEach [410, 411, 412, 413];

View File

@ -21,21 +21,30 @@ lbclear _ctrlList;
switch (GVAR(optionMenu_openTab)) do {
case (MENU_TAB_OPTIONS): {
{
_settingsText = ((_x select 3) select (_x select 4));
_ctrlList lbadd (_x select 1);
_ctrlList lbadd (_x select 3);
_settingsValue = _x select 7;
// Created disable/enable options for bools
_settingsText = if ((_x select 1) == "BOOL") then {
[(localize "STR_ACE_OptionsMenu_Disabled"), (localize "STR_ACE_OptionsMenu_Enabled")] select _settingsValue;
} else {
(_x select 5) select _settingsValue;
};
_ctrlList lbadd (_settingsText);
}foreach GVAR(clientSideOptions);
};
case (MENU_TAB_COLORS): {
{
_color = +(_x select 3);
_color = +(_x select 7);
{
_color set [_forEachIndex, ((round (_x * 100))/100)];
} forEach _color;
_settingsColor = str _color;
_ctrlList lbadd (_x select 1);
_ctrlList lbadd (_x select 3);
_ctrlList lbadd (_settingsColor);
_ctrlList lnbSetColor [[_forEachIndex, 1], (_x select 3)];
_ctrlList lnbSetColor [[_forEachIndex, 1], (_x select 7)];
}foreach GVAR(clientSideColors);
};
};

View File

@ -17,25 +17,33 @@ _changed = false;
switch (_type) do {
case (MENU_TAB_OPTIONS): {
{
if (((_x select 0) == _name) && {!((_x select 4) isEqualTo _newValue)}) then {
_changed = true;
_x set [4, _newValue];
if ((_x select 0) == _name) then {
if ((_x select 1) == "BOOL") then {
_newValue = [false, true] select _newValue;
};
if !((_x select 7) isEqualTo _newValue) then {
_changed = true;
_x set [7, _newValue];
} ;
};
} foreach GVAR(clientSideOptions);
};
case (MENU_TAB_COLORS): {
{
if (((_x select 0) == _name) && {!((_x select 3) isEqualTo _newValue)}) then {
if (((_x select 0) == _name) && {!((_x select 7) isEqualTo _newValue)}) then {
_changed = true;
_x set [3, _newValue];
_x set [7, _newValue];
};
} foreach GVAR(clientSideColors);
};
};
if (_changed) then {
profileNamespace setvariable [_name, _newValue];
missionNameSpace setVariable [_name, _newValue];
[_type, _name] call FUNC(saveToProfile);
["SettingChanged", [_name, _newValue]] call EFUNC(common,localEvent);
TRACE_2("Variable Updated",_name,_newValue);
};