more common code cleanup

This commit is contained in:
commy2 2015-09-20 20:25:25 +02:00
parent 0a01bbdc76
commit 2348c25e1a
11 changed files with 152 additions and 144 deletions

View File

@ -1,24 +1,23 @@
/*
* Author: Glowbal
*
* Draw progress bar and execute given function if succesful.
* Finish/Failure/Conditional are all passed [args, elapsedTime, totalTime, errorCode]
*
* Argument:
* 0: icon ID <STRING>
* 1: show <BOOL>
* 2: Icon Path <STRING>
* 3: Icon color <ARRAY>
* 4: timeAlive. -1 = forever <NUMBER> <OPTIONAL>
*
* Return value:
* Nothing
*
* Example:
* ["myID", true, QUOTE(PATHTOF(data\icon_group.paa)), [1,1,1,1], 0] call ace_gui_fnc_displayIcon;
*/
* Author: Glowbal
* Draw progress bar and execute given function if succesful.
* Finish/Failure/Conditional are all passed [args, elapsedTime, totalTime, errorCode]
*
* Arguments:
* 0: icon ID <STRING>
* 1: show <BOOL>
* 2: Icon Path <STRING>
* 3: Icon color <ARRAY>
* 4: timeAlive. -1 = forever (default: 6) <NUMBER>
*
* Return Value:
* None
*
* Example:
* ["myID", true, QUOTE(PATHTOF(data\icon_group.paa)), [1,1,1,1], 0] call ace_gui_fnc_displayIcon;
*
* Public: Yes
*/
#include "script_component.hpp"
// positions for the icon UI
@ -42,31 +41,37 @@
// other constants
#define DEFAULT_TIME 6
private ["_allControls", "_refresh", "_timeAlive", "_list"];
PARAMS_4(_iconId,_show,_icon,_color);
_timeAlive = if (count _this > 4) then {_this select 4} else {DEFAULT_TIME};
disableSerialization;
_list = missionNamespace getvariable [QGVAR(displayIconList),[]];
params ["_iconId", "_show", "_icon", "_color", ["_timeAlive", DEFAULT_TIME]];
private ["_list", "_refresh"];
_list = missionNamespace getVariable [QGVAR(displayIconList), []];
_refresh = {
private ["_allControls"];
// Refreshing of all icons..
_allControls = missionNamespace getvariable [QGVAR(displayIconListControls), []];
private "_allControls";
_allControls = missionNamespace getVariable [QGVAR(displayIconListControls), []];
{
ctrlDelete _x;
}foreach _allControls;
false
} count _allControls;
_allControls = [];
private ["_ctrl", "_setting", "_position"];
_setting = missionNamespace getvariable[QGVAR(settingFeedbackIcons), 0];
private ["_setting", "_ctrl", "_position"];
_setting = missionNamespace getVariable [QGVAR(settingFeedbackIcons), 0];
if (_setting > 0) then {
{
_x params ["", "_xicon", "_xcolor"];
// +19000 because we want to make certain we are using free IDCs..
_ctrl = ((findDisplay 46) ctrlCreate ["RscPicture", _foreachIndex + 19000]);
_ctrl = (findDisplay 46) ctrlCreate ["RscPicture", _forEachIndex + 19000];
_position = switch (_setting) do {
case TOP_RIGHT_DOWN: {[X_POS_ICONS, Y_POS_ICONS + (_foreachIndex * DIFFERENCE_ICONS), ICON_WIDTH, ICON_WIDTH]};
case TOP_RIGHT_LEFT: {[X_POS_ICONS_SECOND - ((_foreachIndex+3) * DIFFERENCE_ICONS), Y_POS_ICONS_SECOND - (ICON_WIDTH / 2), ICON_WIDTH, ICON_WIDTH]};
@ -74,46 +79,53 @@ _refresh = {
case TOP_LEFT_RIGHT: {[LEFT_SIDE + (0.5 * ICON_WIDTH) - ((_foreachIndex+3) * DIFFERENCE_ICONS), Y_POS_ICONS_SECOND, ICON_WIDTH, ICON_WIDTH]};
default {[X_POS_ICONS, Y_POS_ICONS + (_foreachIndex * DIFFERENCE_ICONS), ICON_WIDTH, ICON_WIDTH]};
};
_ctrl ctrlSetPosition _position;
_ctrl ctrlsetText (_x select 1);
_ctrl ctrlSetTextColor (_x select 2);
_ctrl ctrlSetText _xicon;
_ctrl ctrlSetTextColor _xcolor;
_ctrl ctrlCommit 0;
_allControls pushback _ctrl;
}foreach (missionNamespace getvariable [QGVAR(displayIconList),[]]);
_allControls pushBack _ctrl;
false
} forEach (missionNamespace getVariable [QGVAR(displayIconList),[]]);
};
missionNamespace setvariable [QGVAR(displayIconListControls), _allControls];
missionNamespace setVariable [QGVAR(displayIconListControls), _allControls];
};
if (_show) then {
if ({(_x select 0 == _iconId)} count _list == 0) then {
_list pushback [_iconId, _icon, _color, ACE_time];
if ({_x select 0 == _iconId} count _list == 0) then {
_list pushBack [_iconId, _icon, _color, ACE_time];
} else {
{
if (_x select 0 == _iconId) exitwith {
_list set [_foreachIndex, [_iconId, _icon, _color, ACE_time]];
_list set [_forEachIndex, [_iconId, _icon, _color, ACE_time]];
};
} forEach _list;
};
missionNamespace setvariable [QGVAR(displayIconList), _list];
missionNamespace setVariable [QGVAR(displayIconList), _list];
call _refresh;
if (_timeAlive >= 0) then {
[{
[_this select 0, false, "", [0,0,0], 0] call FUNC(displayIcon);
}, [_iconId], _timeAlive, _timeAlive] call EFUNC(common,waitAndExecute);
[_this select 0, false, "", [0,0,0], 0] call FUNC(displayIcon);
}, [_iconId], _timeAlive, _timeAlive] call FUNC(waitAndExecute);
};
} else {
if ({(_x select 0 == _iconId)} count _list == 1) then {
if ({_x select 0 == _iconId} count _list == 1) then {
private "_newList";
_newList = [];
{
if (_x select 0 != _iconId) then {
_newList pushback _x;
_newList pushBack _x;
};
} forEach _list;
false
} count _list;
missionNamespace setvariable [QGVAR(displayIconList), _newList];
missionNamespace setVariable [QGVAR(displayIconList), _newList];
call _refresh;
};
};

View File

@ -1,42 +1,35 @@
/*
* Author: commy2
*
* Display a message.
*
* Argument:
* 0: Message (String)
* 1: Play a clicking sound (Bool, optional default: false)
* 2: How long before hiding the message in seconds (Number, optional default: 2 sec)
* 3: Priority, higher priority messages will override lesser important ones (Number, optional default: 0)
* Arguments:
* 0: Message <STRING>
* 1: Play a clicking sound (default: false) <BOOL>
* 2: How long before hiding the message in seconds (default: 2) <NUMBER>
* 3: Priority, higher priority messages will override lesser important ones (default: 0) <NUMBER>
*
* Return value:
* Nothing
* Return Value:
* None
*
* Public: Yes
*/
#include "script_component.hpp"
#define DEFAULT_PLAY_SOUND false
#define DEFAULT_DELAY 2
#define DEFAULT_PRIORITY 0
_this resize 4;
private ["_lastHintTime", "_lastHintPriority", "_time"];
PARAMS_4(_text,_sound,_delay,_priority);
params ["_text", ["_sound", false], ["_delay", 2], ["_priority", 0]];
if (isNil QGVAR(lastHint)) then {
GVAR(lastHint) = [0, 0];
};
if !(typeName _text in ["STRING", "TEXT"]) then {_text = str _text};
private ["_lastHintTime", "_lastHintPriority", "_time"];
_lastHintTime = GVAR(lastHint) select 0;
_lastHintPriority = GVAR(lastHint) select 1;
if !(typeName _text in ["STRING", "TEXT"]) then {_text = str _text};
if (isNil "_sound") then {_sound = DEFAULT_PLAY_SOUND};
if (isNil "_delay") then {_delay = DEFAULT_DELAY};
if (isNil "_priority") then {_priority = DEFAULT_PRIORITY};
_time = ACE_time;
if (_time > _lastHintTime + _delay || {_priority >= _lastHintPriority}) then {
hintSilent _text;
if (_sound) then {playSound "ACE_Sound_Click"};

View File

@ -4,11 +4,12 @@
* End radio transmissions of addons TFAR and ACRE2. TFAR v0.9.7, ACRE Public Beta 2.0.3.571
*
* Arguments:
* None.
* None
*
* Return Value:
* None.
* None
*
* Public: No
*/
#include "script_component.hpp"

View File

@ -13,6 +13,6 @@
*/
#include "script_component.hpp"
PARAMS_2(_namespace,_uid);
params ["_namespace", "_uid"];
_namespace setVariable [_uid, nil];

View File

@ -29,11 +29,7 @@ if (isNull (call BIS_fnc_displayMission)) exitWith {
}, 1, _this] call CBA_fnc_addPerFrameHandler;
};
private ["_onOK", "_onCancel"];
PARAMS_2(_textHeader,_textMessage);
_onOK = ARR_SELECT(_this,2,{});
_onCancel = ARR_SELECT(_this,3,{});
params ["_textHeader", "_textMessage", ["_onOK", {}], ["_onCancel", {}]];
if (typeName _textMessage == "STRING") then {
_textMessage = parseText _textMessage;

View File

@ -1,18 +1,19 @@
/*
* Author: esteldunedain
*
* Executes a code on the next frame
*
* Argument:
* 0: Code to execute (Code)
* 1: Parameters to run the code with (Array)
* Arguments:
* 0: Code to execute <CODE>
* 1: Parameters to run the code with <ARRAY>
*
* Return value:
* PFH handler ID
* Return Value:
* PFH handler ID <NUMBER>
*
* Public: Yes
*/
#include "script_component.hpp"
PARAMS_2(_func,_params);
params ["_func", "_params"];
if (diag_frameno != GVAR(nextFrameNo)) then {
GVAR(nextFrameBufferA) pushBack [_params, _func];

View File

@ -1,29 +1,29 @@
/*
* Author: commy2
*
* Execute a function on every machine. Function will also be called upon JIP (postInit). The arguments are stored in (_this select 0), while the assigned namespace is stored in (_this select 1).
*
* Argument:
* 0: Function arguments (Array)
* 1: Function to execute, has to be defined on the remote machine first (String)
* 2: Namespace to save that variable in (Object or Namespace)
* 3: Name. Will overwrite previously defined functions with that name (String)
* Arguments:
* 0: Function arguments <ARRAY>
* 1: Function to execute, has to be defined on the remote machine first <STRING>
* 2: Namespace to save that variable in <OBJECT, NAMESPACE>
* 3: Name. Will overwrite previously defined functions with that name <STRING>
*
* Return value:
* Nothing.
* Return Value:
* None
*
* Public: No
*
* Deprecated
*/
#include "script_component.hpp"
private ["_arguments", "_function", "_unit", "_name"];
GVAR(remoteFnc) = _this;
_arguments = _this select 0;
_function = call compile (_this select 1);
_unit = _this select 2;
_name = _this select 3;
params ["_arguments", "_function", "_unit", "_name"];
["Remote", [_arguments, _this select 1, _name], {format ["%1 call %2 id: %3", _this select 0, _this select 1, _this select 2]}, false] call FUNC(log);
_function = call compile _function;
//["Remote", [_arguments, _this select 1, _name], {format ["%1 call %2 id: %3", _this select 0, _this select 1, _this select 2]}, false] call FUNC(log);
// execute function on every currently connected machine
[[_arguments, _unit], _this select 1, 2] call FUNC(execRemoteFnc);

View File

@ -1,35 +1,32 @@
/*
* Author: commy2
*
* Execute a function on a remote machine in mp.
*
* Argument:
* 0: Function arguments (Array)
* 1: Function to execute, has to be defined on the remote machine first (String)
* 2: The function will be executed where this unit is local OR the mode were this function should be executed. (Object OR Number, optional default: 2)
* Mode 0: execute on this machine only
* Mode 1: execute on server
* Mode 2: execute on all clients + server
* Mode 3: execute on dedicated only
* Arguments:
* 0: Function arguments <ARRAY>
* 1: Function to execute, has to be defined on the remote machine first <STRING>
* 2: The function will be executed where this unit is local OR the mode were this function should be executed. (default: 2) <OBJECT, NUMBER>
* 0 = execute on this machine only
* 1 = execute on server
* 2 = execute on all clients + server
* 3 = execute on dedicated only
*
* Return value:
* Nothing
* Return Value:
* None
*
* Public: No
*
* Deprecated
*/
#include "script_component.hpp"
private ["_arguments", "_function", "_unit", "_id"];
GVAR(remoteFnc) = _this;
_arguments = _this select 0;
_function = call compile (_this select 1);
_unit = _this select 2;
params ["_arguments", "_function", ["_unit", 2]];
if (isNil "_unit") then {
_unit = 2;
};
_function = call compile _function;
["Remote", [_arguments, _this select 1, _unit], {format ["%1 call %2 to: %3", _this select 0, _this select 1, _this select 2]}, false] call FUNC(log);
//["Remote", [_arguments, _this select 1, _unit], {format ["%1 call %2 to: %3", _this select 0, _this select 1, _this select 2]}, false] call FUNC(log);
if (typeName _unit == "SCALAR") exitWith {
switch (_unit) do {
@ -63,8 +60,7 @@ if (local _unit) then {
_arguments call _function;
} else {
if (isServer) then {
_id = owner _unit;
_id publicVariableClient QGVAR(remoteFnc);
(owner _unit) publicVariableClient QGVAR(remoteFnc);
} else {
publicVariableServer QGVAR(remoteFnc);
};

View File

@ -1,11 +1,22 @@
// by commy2
/*
* Author: commy2
* Execute all Persistent Functions
*
* Arguments:
* ?
*
* Return Value:
* None
*
* Public: No
*/
#include "script_component.hpp"
PARAMS_1(_target);
params ["_target"];
{
if (isNil "_x") then {
ACE_LOGERROR_1("No argument and function for remote function. ID: %1",_forEachIndex);
ACE_LOGERROR_1("No arguments and function for remote function. ID: %1",_forEachIndex);
} else {
if (typeName _x == "ARRAY") then {
[_x select 0, _target] call (_x select 1);

View File

@ -1,17 +1,25 @@
// by commy2
/*
usage:
(configFile >> "CfgAmmo") call FUNC(exportConfig);
*/
* Author: commy2
* Export Config Entrys to RPT logs
*
* Arguments:
* Config Path <CONFIG>
*
* Return Value:
* None
*
* Example:
* [configFile >> "CfgAmmo"] call ace_common_fnc_exportConfig;
*
* Public: No
*/
#include "script_component.hpp"
private "_fnc_logEntries";
_fnc_logEntries = {
private ["_p", "_t", "_e", "_a", "_i"];
params ["_c", "_d"];
PARAMS_2(_c,_d);
private ["_p", "_t", "_e", "_a", "_i"];
_p = inheritsFrom _c;

View File

@ -14,14 +14,4 @@
params ["_array"];
private "_result";
_result = [];
{
if !(_x in _result) then {
_result pushBack _x;
};
false
} count _array;
_result
_array arrayIntersect _array // return