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

add support for editbox setting filter script, close #795 #805

Merged
merged 5 commits into from
Nov 23, 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
10 changes: 9 additions & 1 deletion addons/settings/XEH_preInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,16 @@ ADDON = false;
#include "XEH_PREP.sqf"

#ifdef DEBUG_MODE_FULL
private _fnc_sanitizeValue = {
params ["_value"];

_value = toArray _value;
_value = _value - toArray "0123456789"; // remove all numbers
toString _value
};

["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]] 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_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;
Expand Down
19 changes: 15 additions & 4 deletions addons/settings/fnc_gui_settingEditbox.sqf
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#include "script_component.hpp"

params ["_controlsGroup", "_setting", "_source", "_currentValue", "_settingData"];
_settingData params ["_isPassword"];
_settingData params ["_isPassword", "_fnc_sanitizeValue"];

if (_isPassword isEqualTo true) then {
if (_isPassword) then {
if ((_source isEqualTo "server" && {!CAN_SET_SERVER_SETTINGS}) || {_source isEqualTo "mission" && {!CAN_SET_MISSION_SETTINGS}}) then {
_currentValue = "********";
};
Expand All @@ -12,12 +12,23 @@ if (_isPassword isEqualTo true) then {
private _ctrlEditbox = _controlsGroup controlsGroupCtrl IDC_SETTING_EDITBOX;
_ctrlEditbox ctrlSetText _currentValue;

_ctrlEditbox setVariable [QGVAR(params), [_setting, _source]];
_ctrlEditbox setVariable [QGVAR(params), [_setting, _source, _fnc_sanitizeValue]];
_ctrlEditbox ctrlAddEventHandler ["KeyDown", {
params ["_ctrlEditbox"];
(_ctrlEditbox getVariable QGVAR(params)) params ["", "", "_fnc_sanitizeValue"];

private _value = ctrlText _ctrlEditbox;
_value = _value call _fnc_sanitizeValue;
_ctrlEditbox ctrlSetText _value;
}];

_ctrlEditbox ctrlAddEventHandler ["KeyUp", {
params ["_ctrlEditbox"];
(_ctrlEditbox getVariable QGVAR(params)) params ["_setting", "_source"];
(_ctrlEditbox getVariable QGVAR(params)) params ["_setting", "_source", "_fnc_sanitizeValue"];

private _value = ctrlText _ctrlEditbox;
_value = _value call _fnc_sanitizeValue;
_ctrlEditbox ctrlSetText _value;
SET_TEMP_NAMESPACE_VALUE(_setting,_value,_source);

// if new value is same as default value, grey out the default button
Expand Down
5 changes: 3 additions & 2 deletions addons/settings/fnc_init.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,9 @@ switch (toUpper _settingType) do {
_defaultValue = _valueInfo param [0, false, [false]]; // don't use params - we want these variables to be private to the main scope
};
case "EDITBOX": {
_defaultValue = _valueInfo param [0, "", [""]]; // don't use params - we want these variables to be private to the main scope
_settingData pushBack (_valueInfo param [1, false]);
_valueInfo params [["_default", "", [""]], ["_isPassword", false, [false]], ["_fnc_sanitizeValue", {_this}, [{}]]];
_defaultValue = _default; // don't use params - we want these variables to be private to the main scope
_settingData append [_isPassword, _fnc_sanitizeValue];
};
case "LIST": {
_valueInfo params [["_values", [], [[]]], ["_labels", [], [[]]], ["_defaultIndex", 0, [0]]];
Expand Down