Epoch/Sources/epoch_code/gui/scripts/Epoch_gui3DModelPos.sqf
2015-10-12 14:15:10 -05:00

63 lines
2.1 KiB
Plaintext

/*
Attaches picture and text to model's local space and projects on UI.
[_object, _time, _image, _text, _objectSpace, _distance, _externalBool] call epoch_gui3dModelPos;
*/
#include "\A3\ui_f\hpp\defineCommonGrids.inc"
_this spawn {
private ["_obj","_loc","_time","_pic","_txt","_dst","_bool","_display","_ctrl","_imgParsed","_txtParsed","_id","_tick"];
disableSerialization;
params
[
["_obj", objNull, [objNull]],
["_time", 10, [0]],
["_pic", "#(argb,8,8,3)color(0,0,0,0)", [""]],
["_txt", "", [""]],
["_loc", [0,0,0], [[]]],
["_dst", 10, [0]],
["_bool", "", [""]]
];
if (_obj isEqualTo objNull) exitWith {hint "Wrong params, missing object"};
_display = findDisplay 46;
_ctrl = _display ctrlCreate ["RscStructuredText",call epoch_getIDC];
_ctrl ctrlSetPosition [10 * GUI_GRID_W + GUI_GRID_X,10 * GUI_GRID_H + GUI_GRID_Y,10 * GUI_GRID_W,10 * GUI_GRID_H];
_ctrl ctrlCommit 0;
_imgParsed = parseText format ["<t size='4' align = 'center'><img image='%1' /></t>",_pic];
_txtParsed = parseText format ["<t size='1.5' align = 'center' color='#FFFFFF'>%1</t>",_txt];
_ctrl ctrlSetStructuredText (composeText [_imgParsed, parseText "<br>", _txtParsed]);
_id = call compile format
[
"
missionNamespace setVariable ['rmx_var_3DMP_temp%1',[_ctrl, _dst, _obj, _loc]];
_id = addMissionEventHandler ['Draw3D',{
_arr = missionNamespace getVariable 'rmx_var_3DMP_temp%1';
_pos = worldToScreen ((_arr select 2) modelToWorld (_arr select 3));
(_arr select 0) ctrlSetPosition _pos;
(_arr select 0) ctrlCommit 0;
_scale = linearConversion [0, (_arr select 1), player distance ((_arr select 2) modelToWorld (_arr select 3)), 1, 0, false];
[(_arr select 0), _scale, 0] call BIS_fnc_ctrlSetScale;
}];
[_id,'rmx_var_3DMP_temp%1']
"
,floor random 10000
];
_tick = diag_tickTime;
while {(diag_tickTime - _tick) < _time} do {
if !(missionNamespace getVariable [_bool, true]) exitWith {};
if ((player distance (_obj modelToWorld _loc)) > _dst) exitWith {};
};
removeMissionEventHandler ["Draw3D", _id select 0];
missionNamespace setVariable [_id select 1, nil];
_ctrl call epoch_getIDC;
ctrlDelete _ctrl;
};
true