Hello! It has been a long time since I have made a code snippet!
I am going to start making a GUI tutorial soon (maybe a series) but I don't like several of the things I had to do when I started learning about GUI's in Arma. Like many, I read and followed Iceman77's guide (and even had the privilege of having him in my teamspeak server multiple times), and bangabob's video tutorial. However, these required you to download/copy some files that had been already created for you. For a long time while I was learning, I did not realize the freedom that was available to me. Of course, a fair amount of my misunderstanding was probably due to naivete with the engine. However, in my tutorial series I want to express how much freedom one has and teach people not to be scared of searching for information and trying new things, not just follow a guide. So to prevent having to provide some file(s) that won't teach the viewer anything, I wanted to write a function that will allow them to "export" a config straight from the game, using BIS's default values.
Note: This function must be compiled using the functions library with the Tag "DREAD" and the name "copyConfigClass" to work properly. As it is a recursive function, if you want to compile it with a different name, you will have to edit the self-call within the function yourself. The easiest way to use this script is to compile it using the functions library, using the names I have listed previously.
So without further delay, here's my script:
fn_copyConfigClass.sqf
///////////////////////////////////////
// Function file for Armed Assault 3 //
// Created by: DreadedEntity //
// //
// MUST BE COMPILED WITH THE //
// FUNCTIONS LIBRARY //
//Tag = DREAD Name = copyConfigClass//
///////////////////////////////////////
/*
TO USE:
_partialClass = [config] call DREAD_fnc_copyConfigClass;
INPUT:
config: TYPE - Config | Anything that is not a config class is rejected.
OUTPUT:
_partialClass: TYPE - STRING | USED BY THE FUNCTION TO CREATE OUTPUT, DO NOT OVERWRITE
HOWEVER, it is possible to save the result outside of the function, to run it multiple times
ex.
_textBoxClass = [configFile >> "RscText"] call DREAD_fnc_copyConfigClass;
_listBoxClass = [configFile >> "RscListBox"] call DREAD_fnc_copyConfigClass;
_buttonClass = [configFile >> "RscButton"] call DREAD_fnc_copyConfigClass;
TO CLIPBOARD:
Outputs a full class definition, even returning subclasses and their attributes, and it's nicely formatted with tabs. I'm such a god.
*/
private ["_parents","_numTabs","_numParams","_param","_newConfig","_params"];
_MAKE_TABS =
{
_tabs = "";
for "_t" from 1 to _this do
{
_tabs = _tabs + (toString [9]);
};
_tabs;
};
if (!isClass (_this select 0)) exitWith {"Input Was Not A Class"};
_newLine = toString [13, 10];
_parents = [_this select 0] call BIS_fnc_returnParents;
_numTabs = _this param [1, 0, [0]];
_output = _this param [2, "", [""]];
_output = _output + (_numTabs call _MAKE_TABS) + "class " + (configName (_this select 0)) + _newLine + (_numTabs call _MAKE_TABS) + "{" + _newline;
_params = [];
{
_numParams = (count _x) - 1;
for "_i" from 0 to _numParams do
{
_param = configName (_x select _i);
_newConfig = (_this select 0) >> _param;
if (isClass _newConfig) then
{
_output = [_newConfig, _numTabs + 1, _output] call DREAD_fnc_copyConfigClass;
} else
{
_newParam = _param;
_data = nil;
switch (true) do
{
case (isNumber _newConfig):
{
_data = getNumber _newConfig;
};
case (isText _newConfig):
{
_data = str(getText _newConfig);
};
case (isArray _newConfig):
{
_newParam = _newParam + "[]";
_data = str(getArray _newConfig);
_data = "{" + (_data select [1, (count _data) - 2]) + "}";
};
};
if (_params find _param == -1) then
{
_output = _output + ((_numTabs + 1) call _MAKE_TABS) + format["%1 = %2;%3", _newParam, _data, _newLine];
_params pushBack _param;
};
};
};
} forEach _parents;
_output = _output + (_numTabs call _MAKE_TABS) + "};" + _newline;
copyToClipboard _output;
_output;
Lastly, I'd like to thank the person who wrote the code for the Splendid Config Viewer; whose code was so bloated and unreadable I experienced the greatest headache of my life from reading it, and probably got cancer.