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

Fix settings menu slow loading #739

Merged
merged 2 commits into from
Sep 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions addons/settings/fnc_gui_addonChanged.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ uiNamespace setVariable [QGVAR(addonIndex), _index];
// toggle lists
private _selectedSource = uiNamespace getVariable QGVAR(source);

if !(_display getVariable [_selectedAddon, false]) then {
#include "gui_createCategory.sqf"
_display setVariable [_selectedAddon, true];
};

{
(_x splitString "$") params ["", "_addon", "_source"];

Expand Down
22 changes: 13 additions & 9 deletions addons/settings/fnc_initDisplayGameOptions.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,22 @@ private _ctrlAddonList = _display ctrlCreate [QGVAR(AddonsList), -1, _ctrlAddons

_ctrlAddonList ctrlAddEventHandler ["LBSelChanged", {_this call FUNC(gui_addonChanged)}];

private _categories = [];

// ----- create settings lists
#include "gui_createMenu.sqf"
// ----- Add lists
_display setVariable [QGVAR(lists),[]];

// ----- fill addons list
private _categories = [];
{
private _category = _x;
private _index = _ctrlAddonList lbAdd _category;
_ctrlAddonList lbSetData [_index, str _index];
_display setVariable [str _index, _category];
} forEach _categories;
(GVAR(default) getVariable _x) params ["", "", "", "", "_category"];

if !(_category in _categories) then {
private _index = _ctrlAddonList lbAdd _category;
_ctrlAddonList lbSetData [_index, str _index];
_display setVariable [str _index, _category];

_categories pushBack _category;
};
} forEach GVAR(allSettings);

lbSort _ctrlAddonList;
_ctrlAddonList lbSetCurSel (uiNamespace getVariable [QGVAR(addonIndex), 0]);
Expand Down
124 changes: 124 additions & 0 deletions addons/settings/gui_createCategory.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
// inline function, don't include script_component.hpp

private _fnc_controlSetTablePosY = {
params ["_control", "_tablePosY"];

private _config = configFile >> ctrlClassName _control;

private _posX = getNumber (_config >> "x");
private _posY = getNumber (_config >> "y") + _tablePosY;
private _posH = getNumber (_config >> "h");

_control ctrlSetPosition [_posX, _posY];
_control ctrlCommit 0;

_posY + _posH
};

private _lists = _display getVariable QGVAR(lists);

{
(GVAR(default) getVariable _x) params ["_defaultValue", "_setting", "_settingType", "_settingData", "_category", "_displayName", "_tooltip", "_isGlobal"];

if (_category == _selectedAddon) then {
if (isLocalized _category) then {
_category = localize _category;
};

if (isLocalized _displayName) then {
_displayName = localize _displayName;
};

if (isLocalized _tooltip) then {
_tooltip = localize _tooltip;
};

private _settingControlsGroups = [];

{
private _source = toLower _x;
private _currentValue = [_setting, _source] call FUNC(get);
private _currentPriority = [_setting, _source] call FUNC(priority);

// ----- create or retrieve options "list" controls group
private _list = [QGVAR(list), _category, _source] joinString "$";

private _ctrlOptionsGroup = controlNull;

if !(_list in _lists) then {
_ctrlOptionsGroup = _display ctrlCreate [QGVAR(OptionsGroup), -1, _display displayCtrl IDC_ADDONS_GROUP];
_ctrlOptionsGroup ctrlEnable false;
_ctrlOptionsGroup ctrlShow false;

_lists pushBack _list;
_display setVariable [_list, _ctrlOptionsGroup];
} else {
_ctrlOptionsGroup = _display getVariable _list;
};

// ----- create setting group
private _ctrlSettingGroup = switch (toUpper _settingType) do {
case "CHECKBOX": {
_display ctrlCreate [QGVAR(Row_Checkbox), IDC_SETTING_CONTROLS_GROUP, _ctrlOptionsGroup]
};
case "EDITBOX": {
_display ctrlCreate [QGVAR(Row_Editbox), IDC_SETTING_CONTROLS_GROUP, _ctrlOptionsGroup]
};
case "LIST": {
_display ctrlCreate [QGVAR(Row_List), IDC_SETTING_CONTROLS_GROUP, _ctrlOptionsGroup]
};
case "SLIDER": {
_display ctrlCreate [QGVAR(Row_Slider), IDC_SETTING_CONTROLS_GROUP, _ctrlOptionsGroup]
};
case "COLOR": {
_display ctrlCreate [[QGVAR(Row_Color), QGVAR(Row_ColorAlpha)] select (count _defaultValue > 3), IDC_SETTING_CONTROLS_GROUP, _ctrlOptionsGroup]
};
default {controlNull};
};

_ctrlSettingGroup setVariable [QGVAR(setting), _setting];
_ctrlSettingGroup setVariable [QGVAR(source), _source];
_ctrlSettingGroup setVariable [QGVAR(params), _settingData];
_ctrlSettingGroup setVariable [QGVAR(groups), _settingControlsGroups];
_settingControlsGroups pushBack _ctrlSettingGroup;

// ----- adjust y position in table
private _tablePosY = _ctrlOptionsGroup getVariable [QGVAR(tablePosY), TABLE_LINE_SPACING/2];
_tablePosY = [_ctrlSettingGroup, _tablePosY] call _fnc_controlSetTablePosY;
_ctrlOptionsGroup setVariable [QGVAR(tablePosY), _tablePosY];

// ----- set setting name
private _ctrlSettingName = _ctrlSettingGroup controlsGroupCtrl IDC_SETTING_NAME;
_ctrlSettingName ctrlSetText format ["%1:", _displayName];
_ctrlSettingName ctrlSetTooltip _tooltip;

// ----- execute setting script
private _script = getText (configFile >> ctrlClassName _ctrlSettingGroup >> QGVAR(script));
[_ctrlSettingGroup, _setting, _source, _currentValue, _settingData] call (uiNamespace getVariable _script);

// ----- default button
[_ctrlSettingGroup, _setting, _source, _currentValue, _defaultValue] call FUNC(gui_settingDefault);

// ----- priority list
[_ctrlSettingGroup, _setting, _source, _currentPriority, _isGlobal] call FUNC(gui_settingOverwrite);

// ----- check if setting can be altered
private _enabled = switch (_source) do {
case "client": {CAN_SET_CLIENT_SETTINGS && {isNil {GVAR(userconfig) getVariable _setting}}};
case "mission": {CAN_SET_MISSION_SETTINGS && {isNil {GVAR(missionConfig) getVariable _setting}}};
case "server": {CAN_SET_SERVER_SETTINGS && {isNil {GVAR(serverConfig) getVariable _setting}}};
};

if !(_enabled) then {
_ctrlSettingName ctrlSetTextColor COLOR_TEXT_DISABLED;

//private _ctrlSettingGroupControls = allControls ctrlParent _ctrlSettingGroup select {ctrlParentControlsGroup _x == _ctrlSettingGroup};
private _ctrlSettingGroupControls = "true" configClasses (configFile >> ctrlClassName _ctrlSettingGroup >> "controls") apply {_ctrlSettingGroup controlsGroupCtrl getNumber (_x >> "idc")};

{
_x ctrlEnable false;
} forEach _ctrlSettingGroupControls;
};
} forEach ["client", "mission", "server"];
};
} forEach GVAR(allSettings);
125 changes: 0 additions & 125 deletions addons/settings/gui_createMenu.sqf

This file was deleted.