Skip to content

Commit

Permalink
Merge pull request #867 from CBATeam/settings-list-tooltips
Browse files Browse the repository at this point in the history
add tooltips to list settings
  • Loading branch information
Killswitch00 authored Jan 5, 2018
2 parents a28ebb1 + f87187e commit 092a7f2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
2 changes: 1 addition & 1 deletion addons/settings/XEH_preInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ ADDON = false;

["Test_Setting_0", "CHECKBOX", ["-test checkbox-", "-tooltip-"], "My Category", true] call cba_settings_fnc_init;
["Test_Setting_1", "EDITBOX", ["-test editbox-", "-tooltip-"], "My Category", ["null", false, _fnc_sanitizeValue]] call cba_settings_fnc_init;
["Test_Setting_2", "LIST", ["-test list-", "-tooltip-"], "My Category", [[1, 0], ["enabled", "disabled"], 1]] call cba_settings_fnc_init;
["Test_Setting_2", "LIST", ["-test list-", "-tooltip-"], "My Category", [[1, 0], [["enabled", "tooltip 1"], ["disabled", "tooltip 2"]], 1]] call cba_settings_fnc_init;
["Test_Setting_3", "SLIDER", ["-test slider-", "-tooltip-"], "My Category", [0, 10, 5, 0]] call cba_settings_fnc_init;
["Test_Setting_4", "COLOR", ["-test color-", "-tooltip-"], "My Category", [1, 1 ,0], false, {diag_log text format ["Color Setting Changed: %1", _this];}] call cba_settings_fnc_init;
["Test_Setting_5", "COLOR", ["-test alpha-", "-tooltip-"], "My Category", [1, 0, 0, 0.5], false] call cba_settings_fnc_init;
Expand Down
12 changes: 11 additions & 1 deletion addons/settings/fnc_gui_settingList.sqf
Original file line number Diff line number Diff line change
@@ -1,23 +1,33 @@
#include "script_component.hpp"

params ["_controlsGroup", "_setting", "_source", "_currentValue", "_settingData"];
_settingData params ["_values", "_labels"];
_settingData params ["_values", "_labels", "_tooltips"];

private _ctrlList = _controlsGroup controlsGroupCtrl IDC_SETTING_LIST;

private _lbData = [];

{
private _label = _labels select _forEachIndex;
private _tooltip = _tooltips select _forEachIndex;

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

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

private _index = _ctrlList lbAdd _label;
_ctrlList lbSetTooltip [_index, _tooltip];
_lbData set [_index, _x];
} forEach _values;

// Don't show tooltip if lb is not expanded. It's bugged and shows the wrong one
// if the item was changed by command. E.g. by clicking the "Default"-button.
_ctrlList ctrlSetTooltip "";

_ctrlList lbSetCurSel (_values find _currentValue);

_ctrlList setVariable [QGVAR(params), [_setting, _source, _lbData]];
Expand Down
16 changes: 12 additions & 4 deletions addons/settings/fnc_init.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -102,21 +102,29 @@ switch (toUpper _settingType) do {
};

_labels resize count _values;
private _tooltips = [];

{
if (isNil "_x") then {
_x = _values select _forEachIndex;
};

if !(_x isEqualType "") then {
_x = str _x;
_x params ["_label", ["_tooltip", ""]];

if !(_label isEqualType "") then {
_label = str _label;
};

if !(_tooltip isEqualType "") then {
_tooltip = str _tooltip;
};

_labels set [_forEachIndex, _x];
_labels set [_forEachIndex, _label];
_tooltips pushBack _tooltip;
} forEach _labels;

_defaultValue = _values param [_defaultIndex];
_settingData append [_values, _labels];
_settingData append [_values, _labels, _tooltips];
};
case "SLIDER": {
_valueInfo params [["_min", 0, [0]], ["_max", 1, [0]], ["_default", 0, [0]], ["_trailingDecimals", 2, [0]]];
Expand Down

0 comments on commit 092a7f2

Please sign in to comment.