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 dialog to export and import settings text files #832

Merged
merged 7 commits into from
Dec 18, 2017
Merged
Show file tree
Hide file tree
Changes from 6 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
1 change: 1 addition & 0 deletions addons/settings/XEH_PREP.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ if (hasInterface) then {
PREP(gui_refresh);
PREP(gui_preset);
PREP(gui_saveTempData);
PREP(gui_export);

PREP(gui_settingCheckbox);
PREP(gui_settingEditbox);
Expand Down
6 changes: 6 additions & 0 deletions addons/settings/XEH_preInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ ADDON = false;

#include "XEH_PREP.sqf"

//#define DEBUG_MODE_FULL
#ifdef DEBUG_MODE_FULL
private _fnc_sanitizeValue = {
params ["_value"];
Expand All @@ -26,6 +27,11 @@ ADDON = false;
["Test_4", "EDITBOX", "setting 4", "Test Category", "null", nil, {systemChat str [4, _this]}] call cba_settings_fnc_init;
["Test_5", "EDITBOX", "setting 5", "Test Category", "null", 1, {systemChat str [5, _this]}] call cba_settings_fnc_init;
["Test_6", "EDITBOX", "setting 6", "Test Category", "null", 2, {systemChat str [6, _this]}] call cba_settings_fnc_init;

["Test_A", "EDITBOX", "setting 1", "Test Category 1", "a", nil, {systemChat str [1, _this]}] call cba_settings_fnc_init;
["Test_B", "EDITBOX", "setting 2", "Test Category 1", "b", nil, {systemChat str [2, _this]}] call cba_settings_fnc_init;
["Test_C", "EDITBOX", "setting 3", "Test Category 3", "c", nil, {systemChat str [3, _this]}] call cba_settings_fnc_init;
["Test_D", "EDITBOX", "setting 4", "Test Category 3", "d", nil, {systemChat str [4, _this]}] call cba_settings_fnc_init;
#endif

// --- init settings namespaces
Expand Down
35 changes: 32 additions & 3 deletions addons/settings/fnc_export.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Description:

Parameters:
_source - Can be "client", "mission" or "server" (optional, default: "client") <STRING>
_exportDefault - true: export all settings,
false: only changed settings (optional, default: false) <BOOL>

Returns:
Formatted setting info. <STRING>
Expand All @@ -15,9 +17,10 @@ Author:
---------------------------------------------------------------------------- */
#include "script_component.hpp"

params [["_source", "client", [""]]];
params [["_source", "client", [""]], ["_exportDefault", false, [false]]];

private _info = "";
private _temp = [];

{
private _setting = _x;
Expand All @@ -33,7 +36,33 @@ private _info = "";
_priority = [_setting, _source] call FUNC(priority);
};

_info = _info + ((["", "force ", "force force "] select _priority) + _setting + " = " + str _value + ";" + NEWLINE);
(GVAR(default) getVariable _setting) params ["_defaultValue", "", "", "", "_category"];

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

if (_exportDefault || {
!(_value isEqualTo _defaultValue) ||
_priority > [0,1] select IS_GLOBAL_SETTING(_setting)
}) then {
_temp pushBack [_category, _setting, _value, _priority];
};
} forEach GVAR(allSettings);

_info
_temp sort true;

private _last = "";

{
_x params ["_category", "_setting", "_value", "_priority"];

if (_category != _last) then {
_last = _category;
_info = _info + NEWLINE + "// " + _category + NEWLINE;
};

_info = _info + ((["", "force ", "force force "] select _priority) + _setting + " = " + str _value + ";" + NEWLINE);
} forEach _temp;

_info select [1] // return
71 changes: 71 additions & 0 deletions addons/settings/fnc_gui_export.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#include "script_component.hpp"

params ["_parentDisplay", "_mode"];

_display = _parentDisplay createDisplay QGVAR(export);

private _ctrlPresetsGroup = _display displayCtrl IDC_EXPORT_GROUP;
private _ctrlTitle = _display displayCtrl IDC_EXPORT_TITLE;
private _ctrlValue = _display displayCtrl IDC_EXPORT_VALUE;
private _ctrlOK = _display displayCtrl IDC_EXPORT_OK;
private _ctrlCancel = _display displayCtrl IDC_EXPORT_CANCEL;
private _ctrlToggleDefault = _display displayCtrl IDC_EXPORT_TOGGLE_DEFAULT;
private _ctrlToggleDefaultText = _display displayCtrl IDC_EXPORT_TOGGLE_DEFAULT_TEXT;

// --- scripted buttons
if (_mode == "import") then {
_ctrlTitle ctrlSetText localize LSTRING(ButtonImport);

_ctrlToggleDefault ctrlEnable false;
_ctrlToggleDefault ctrlShow false;
_ctrlToggleDefaultText ctrlEnable false;
_ctrlToggleDefaultText ctrlShow false;

_ctrlOK ctrlAddEventHandler ["ButtonClick", {
params ["_control"];
private _display = ctrlParent _control;

private _ctrlValue = _display displayCtrl IDC_EXPORT_VALUE;
[ctrlText _ctrlValue, uiNamespace getVariable QGVAR(source)] call FUNC(import);

_display closeDisplay IDC_OK;
}];
} else {
_ctrlTitle ctrlSetText localize LSTRING(ButtonExport);

_ctrlToggleDefault cbSetChecked (uiNamespace getVariable [QGVAR(showDefault), true]);
_ctrlToggleDefault ctrlAddEventHandler ["CheckedChanged", {
params ["_ctrlToggleDefault", "_state"];
_state = _state isEqualTo 1;

uiNamespace setVariable [QGVAR(showDefault), _state];

private _ctrlValue = ctrlParent _ctrlToggleDefault displayCtrl IDC_EXPORT_VALUE;
_ctrlValue ctrlSetText ([uiNamespace getVariable QGVAR(source), _state] call FUNC(export));
}];

_ctrlValue ctrlSetText ([uiNamespace getVariable QGVAR(source), cbChecked _ctrlToggleDefault] call FUNC(export));

if (isServer) then {
_ctrlOK ctrlSetText localize LSTRING(copy_to_clipboard);
_ctrlOK ctrlAddEventHandler ["ButtonClick", {
params ["_control"];
private _display = ctrlParent _control;

private _ctrlValue = _display displayCtrl IDC_EXPORT_VALUE;
copyToClipboard ctrlText _ctrlValue;

_display closeDisplay IDC_OK;
}];
} else {
_ctrlOK ctrlEnable false;
_ctrlOK ctrlShow false;
};
};

_ctrlCancel ctrlAddEventHandler ["ButtonClick", {
params ["_control"];
private _display = ctrlParent _control;

_display closeDisplay IDC_CANCEL;
}];
74 changes: 34 additions & 40 deletions addons/settings/fnc_initDisplayGameOptions.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -105,47 +105,41 @@ _ctrlButtonLoad ctrlShow false;
_ctrlButtonLoad ctrlAddEventHandler ["ButtonClick", {[ctrlParent (_this select 0), "load"] call FUNC(gui_preset)}];

// ----- create export and import buttons
// copyFromClipboard has no effect in MP, so only add button in SP
if (!isMultiplayer) then {
private _ctrlButtonImport = _display ctrlCreate ["RscButtonMenu", IDC_BTN_IMPORT];

_ctrlButtonImport ctrlSetPosition [
POS_X(26.4),
POS_Y(20.5),
POS_W(6),
POS_H(1)
];

_ctrlButtonImport ctrlCommit 0;
_ctrlButtonImport ctrlSetText localize LSTRING(ButtonImport);
_ctrlButtonImport ctrlSetTooltip localize LSTRING(ButtonImport_tooltip);
_ctrlButtonImport ctrlEnable false;
_ctrlButtonImport ctrlShow false;
_ctrlButtonImport ctrlAddEventHandler ["ButtonClick", {
[copyFromClipboard, uiNamespace getVariable QGVAR(source)] call FUNC(import);
}];
};
private _ctrlButtonImport = _display ctrlCreate ["RscButtonMenu", IDC_BTN_IMPORT];

// copyToClipboard only works in SP or on the server, so only add button if isServer
if (isServer) then {
private _ctrlButtonExport = _display ctrlCreate ["RscButtonMenu", IDC_BTN_EXPORT];

_ctrlButtonExport ctrlSetPosition [
POS_X(32.5),
POS_Y(20.5),
POS_W(6),
POS_H(1)
];

_ctrlButtonExport ctrlCommit 0;
_ctrlButtonExport ctrlSetText localize LSTRING(ButtonExport);
_ctrlButtonExport ctrlSetTooltip localize LSTRING(ButtonExport_tooltip);
_ctrlButtonExport ctrlEnable false;
_ctrlButtonExport ctrlShow false;
_ctrlButtonExport ctrlAddEventHandler ["ButtonClick", {
copyToClipboard ([uiNamespace getVariable QGVAR(source)] call FUNC(export));
}];
};
_ctrlButtonImport ctrlSetPosition [
POS_X(26.4),
POS_Y(20.5),
POS_W(6),
POS_H(1)
];

_ctrlButtonImport ctrlCommit 0;
_ctrlButtonImport ctrlSetText localize LSTRING(ButtonImport);
_ctrlButtonImport ctrlSetTooltip localize LSTRING(ButtonImport_tooltip);
_ctrlButtonImport ctrlEnable false;
_ctrlButtonImport ctrlShow false;
_ctrlButtonImport ctrlAddEventHandler ["ButtonClick", {
[ctrlParent (_this select 0), "import"] call FUNC(gui_export);
}];

private _ctrlButtonExport = _display ctrlCreate ["RscButtonMenu", IDC_BTN_EXPORT];

_ctrlButtonExport ctrlSetPosition [
POS_X(32.5),
POS_Y(20.5),
POS_W(6),
POS_H(1)
];

_ctrlButtonExport ctrlCommit 0;
_ctrlButtonExport ctrlSetText localize LSTRING(ButtonExport);
_ctrlButtonExport ctrlSetTooltip localize LSTRING(ButtonExport_tooltip);
_ctrlButtonExport ctrlEnable false;
_ctrlButtonExport ctrlShow false;
_ctrlButtonExport ctrlAddEventHandler ["ButtonClick", {
[ctrlParent (_this select 0), "export"] call FUNC(gui_export);
}];

// ----- source buttons (server, mission, client)
{
Expand Down
84 changes: 84 additions & 0 deletions addons/settings/gui.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -514,3 +514,87 @@ class GVAR(MainMenuHelper): RscDisplayEmpty {
(_this select 0) closeDisplay 0;\
);
};

class GVAR(export) {
idd = -1;
movingEnable = 1;
enableSimulation = 0;

class controls {
class Presets: RscControlsGroup {
idc = IDC_EXPORT_GROUP;
x = POS_X(5);
y = POS_Y(-5.1);
w = POS_W(30);
h = POS_H(32.2);

class controls {
class Title: RscTitle {
colorBackground[] = {
"(profileNamespace getVariable ['GUI_BCG_RGB_R',0.77])",
"(profileNamespace getVariable ['GUI_BCG_RGB_G',0.51])",
"(profileNamespace getVariable ['GUI_BCG_RGB_B',0.08])",
"(profileNamespace getVariable ['GUI_BCG_RGB_A',0.8])"
};
idc = IDC_EXPORT_TITLE;
text = "";
x = POS_W(0);
y = POS_H(0);
w = POS_W(30);
h = POS_H(1);
};
class Background: RscText {
idc = -1;
colorBackground[] = {0,0,0,0.8};
x = POS_W(0);
y = POS_H(1.1);
w = POS_W(30);
h = POS_H(30);
};
class Value: RscEdit {
idc = IDC_EXPORT_VALUE;
style = ST_MULTI + ST_NO_RECT;
colorDisabled[] = {0.95,0.95,0.95,1};
colorBackground[] = {1,1,1,0.2};
x = POS_W(0.5);
y = POS_H(1.6);
w = POS_W(29);
h = POS_H(29);
sizeEx = POS_H(0.8);
};
class ButtonOK: RscButtonMenu {
idc = IDC_EXPORT_OK;
text = "$STR_DISP_OK";
x = POS_W(20);
y = POS_H(31.2);
w = POS_W(10);
h = POS_H(1);
};
class ButtonCancel: RscButtonMenu {
idc = IDC_EXPORT_CANCEL;
text = "$STR_DISP_CANCEL";
x = POS_W(0);
y = POS_H(31.2);
w = POS_W(10);
h = POS_H(1);
};
class ToggleDefaultText: RscText {
idc = IDC_EXPORT_TOGGLE_DEFAULT_TEXT;
style = ST_RIGHT;
text = CSTRING(show_default);
x = POS_W(19);
y = POS_H(0);
w = POS_W(10);
h = POS_H(1);
};
class ToggleDefault: GVAR(CheckboxSound) {
idc = IDC_EXPORT_TOGGLE_DEFAULT;
x = POS_W(29);
y = POS_H(0);
w = POS_W(1);
h = POS_H(1);
};
};
};
};
};
12 changes: 10 additions & 2 deletions addons/settings/gui_createCategory.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,16 @@ private _lists = _display getVariable QGVAR(lists);

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

private _currentValue = GET_TEMP_NAMESPACE_VALUE(_setting,_source);
if (isNil "_currentValue") then {
_currentValue = [_setting, _source] call FUNC(get);
};

private _currentPriority = GET_TEMP_NAMESPACE_PRIORITY(_setting,_source);
if (isNil "_currentPriority") then {
_currentPriority = [_setting, _source] call FUNC(priority);
};

// ----- create or retrieve options "list" controls group
private _list = [QGVAR(list), _category, _source] joinString "$";
Expand Down
8 changes: 8 additions & 0 deletions addons/settings/script_component.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@
#define IDC_PRESETS_CANCEL 8006
#define IDC_PRESETS_DELETE 8007

#define IDC_EXPORT_GROUP 8100
#define IDC_EXPORT_TITLE 8101
#define IDC_EXPORT_VALUE 8104
#define IDC_EXPORT_OK 8106
#define IDC_EXPORT_CANCEL 8107
#define IDC_EXPORT_TOGGLE_DEFAULT_TEXT 8200
#define IDC_EXPORT_TOGGLE_DEFAULT 8201

#define POS_X(N) ((N) * GUI_GRID_W + GUI_GRID_CENTER_X)
#define POS_Y(N) ((N) * GUI_GRID_H + GUI_GRID_CENTER_Y)
#define POS_W(N) ((N) * GUI_GRID_W)
Expand Down
8 changes: 8 additions & 0 deletions addons/settings/stringtable.xml
Original file line number Diff line number Diff line change
Expand Up @@ -218,5 +218,13 @@
<Chinesesimp>此项设定被客户端给覆写并仅适用于伺服器。</Chinesesimp>
<Portuguese>Esta configuração é sobrescrita pelos clientes e é apenas aplicada no servidor.</Portuguese>
</Key>
<Key ID="STR_cba_settings_copy_to_clipboard">
<English>Copy to clipboard</English>
<German>In Zwischenablage</German>
</Key>
<Key ID="STR_cba_settings_show_default">
<English>Show default values:</English>
<German>Zeige Standardeinstellungen:</German>
</Key>
</Package>
</Project>