Created
November 7, 2016 15:15
-
-
Save jameslkingsley/f84db0e37b4db4e611385d7c211008e5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Author: Kingsley | |
* Draws all icons/lines needed in 3D space | |
* Called every frame from openEditor | |
* | |
* Arguments: | |
* None | |
* | |
* Return Value: | |
* None | |
* | |
* Example: | |
* [] call mars_editor_fnc_drawAll3D; | |
* | |
* Public: No | |
*/ | |
#include "script_component.hpp" | |
#include "\z\mars\addons\common\macros.hpp" | |
BEGIN_COUNTER(drawAll3D); | |
params ["_display"]; | |
private _camPosASL = GVAR(camPos); | |
GVAR(groupIcons) = []; | |
GVAR(unitIcons) = []; | |
{ctrlDelete _x;false} count GVAR(drawingControls); | |
private _ctrlCreate = { | |
params [ | |
["_display", displayNull], | |
["_size", 5, [0]], | |
["_pos", [], [[]]], | |
["_index", 0, [0]] | |
]; | |
if (_pos isEqualTo []) exitWith {}; | |
_size = [_size * GRID_W, _size * GRID_H]; | |
private _ctrl = _display ctrlCreate ["MARS_gui_ctrlStaticBackground", 55255 + _index]; | |
_ctrl ctrlSetBackgroundColor [0.5, 0, 0, 1]; | |
_ctrl ctrlSetPosition [_pos select 0, _pos select 1, _size select 0, _size select 1]; | |
_ctrl ctrlCommit 0; | |
GVAR(drawingControls) pushBack _ctrl; | |
}; | |
private _index = 0; | |
{ | |
private _object = _x; | |
private _objectClassname = typeOf _object; | |
private _objectPosAGL = getPosVisual _object; | |
private _objectPosASL = getPosASLVisual _object; | |
private _isPerson = _objectClassname call CBA_fnc_isPerson; | |
private _iconColor = [ | |
[COLOR_EMPTY_RGBA], | |
[COLOR_WEST_RGBA], | |
[COLOR_EAST_RGBA], | |
[COLOR_GUER_RGBA], | |
[COLOR_CIV_RGBA] | |
] select (([west, east, resistance, civilian] find (side _object)) + 1); | |
if (!alive _object) then { | |
_iconColor = [0,0,0,1]; | |
}; | |
private _objectIcon = getText (configfile >> "CfgVehicles" >> _objectClassname >> "icon"); | |
private _objectIconPath = [getText (configFile >> "CfgVehicleIcons" >> _objectIcon), _objectIcon] select ((toLower _objectIcon) find "\" > -1); | |
if (_isPerson && {vehicle _object == _object}) then { | |
private _playerColor = [0,0,0,0]; | |
if (isPlayer _object && {_object distance _camPosASL <= SMALL_ICON_DISTANCE}) then { | |
_playerColor = [ | |
[0,0,0,1], | |
[[1,0,0.5,1], [1,0,0,1]] select (local _object) | |
] select (alive _object); | |
// Player icon | |
[_display, 5, worldToScreen _objectPosAGL, _index] call _ctrlCreate; | |
/*drawIcon3D [ | |
"\A3\ui_f\data\igui\cfg\islandmap\iconplayer_ca.paa", | |
_playerColor, | |
_objectPosAGL, | |
1, | |
1, | |
0, | |
name _object, | |
0 | |
];*/ | |
}; | |
if (count units group _object > 1) then { | |
private _leader = leader _object; | |
if (_leader == _object) then { | |
private _groupIcon = [[group _object] call CFUNC(getMarkerType)] call CFUNC(getMarkerTexture); | |
if (!isNil "_groupIcon" && {_groupIcon != ""}) then { | |
[_display, 10, worldToScreen (_objectPosAGL vectorAdd [0, 0, 10]), _index] call _ctrlCreate; | |
/*drawIcon3D [ | |
_groupIcon, | |
_iconColor, | |
_objectPosAGL vectorAdd [0, 0, 10], | |
1, | |
1, | |
0, | |
"", | |
0 | |
];*/ | |
drawLine3D [ | |
_objectPosAGL, | |
_objectPosAGL vectorAdd [0, 0, 10], | |
[0,0,0,1] | |
]; | |
}; | |
} else { | |
if (!isNull _leader) then { | |
drawLine3D [ | |
_objectPosAGL, | |
getPos _leader, | |
_iconColor | |
]; | |
}; | |
}; | |
}; | |
if (_object distance _camPosASL <= SMALL_ICON_DISTANCE) then { | |
[_display, 5, worldToScreen _objectPosAGL, _index] call _ctrlCreate; | |
/*drawIcon3D [ | |
_objectIconPath, | |
_iconColor, | |
_objectPosAGL, | |
1, | |
1, | |
0, | |
"", | |
0 | |
];*/ | |
}; | |
} else { | |
private _vehicleIcon = [[group _object] call CFUNC(getMarkerType)] call CFUNC(getMarkerTexture); | |
if (crew _object isEqualTo []) then { | |
[_display, 5, worldToScreen _objectPosAGL, _index] call _ctrlCreate; | |
/*drawIcon3D [ | |
_objectIconPath, | |
[COLOR_EMPTY_RGBA], | |
_objectPosAGL, | |
1, | |
1, | |
0, | |
"", | |
0 | |
];*/ | |
} else { | |
private _vehicleLeader = ((crew _object) select {leader _x == _x}) param [0, objNull]; | |
private _vehicleGroupLeader = leader group _object; | |
if (!isNull _vehicleGroupLeader) then { | |
if ({_vehicleGroupLeader == _x} count (crew _object) > 0) then { | |
[_display, 5, worldToScreen _objectPosAGL, _index] call _ctrlCreate; | |
/*drawIcon3D [ | |
_vehicleIcon, | |
_iconColor, | |
_objectPosAGL, | |
1, | |
1, | |
0, | |
"", | |
0 | |
];*/ | |
drawLine3D [ | |
_objectPosAGL, | |
_objectPosAGL vectorAdd [0, 0, 10], | |
[0,0,0,1] | |
]; | |
}; | |
drawLine3D [ | |
_objectPosAGL, | |
getPos _vehicleGroupLeader, | |
_iconColor | |
]; | |
}; | |
if ({isPlayer _x} count (crew _object) > 0) then { | |
_playerColor = [[1,0,0.5,1], [1,0,0,1]] select (local _object); | |
// Player icon | |
[_display, 5, worldToScreen _objectPosAGL, _index] call _ctrlCreate; | |
/*drawIcon3D [ | |
"\A3\ui_f\data\igui\cfg\islandmap\iconplayer_ca.paa", | |
_playerColor, | |
_objectPosAGL, | |
1, | |
1, | |
0, | |
"", | |
0 | |
];*/ | |
}; | |
[_display, 5, worldToScreen _objectPosAGL, _index] call _ctrlCreate; | |
/*drawIcon3D [ | |
_objectIconPath, | |
_iconColor, | |
_objectPosAGL, | |
1, | |
1, | |
0, | |
"", | |
0 | |
];*/ | |
}; | |
}; | |
INC(_index); | |
false | |
} count ((entities "All") select { | |
!((worldToScreen (getPos _x)) isEqualTo []) && | |
{(_x distance GVAR(camera)) <= GVAR(iconDrawDistance)} | |
}); | |
/*{ | |
_x params [ | |
"_object", | |
["_icon", ""], | |
["_color", [0,0,0,0]], | |
["_zOffset", 0], | |
["_shadow", 1], | |
["_isGroupMarker", false], | |
["_fixedDistance", GVAR(iconDrawDistance)], | |
["_cursorScale", 0.033], | |
["_displayText", ""] | |
]; | |
private _pos = (getPosASLVisual _object) vectorAdd [0, 0, _zOffset]; | |
private _alpha = linearConversion [0, _fixedDistance, (_pos distance _camPosASL), 1, 0, true]; | |
private _width = 1; | |
private _height = 1; | |
if (_isGroupMarker) then { | |
GVAR(groupIcons) pushBack [ASLtoAGL _pos, group _object]; | |
if (_object in GVAR(selection)) then { | |
_alpha = 1; | |
_width = GVAR(iconHoverSize); | |
_height = GVAR(iconHoverSize); | |
} else { | |
if (_alpha > 0.25) then { | |
private _iconScreenPos = worldToScreen (ASLtoAGL _pos); | |
if (!(_iconScreenPos isEqualTo []) && {(_iconScreenPos distance2D GVAR(mousePos)) <= _cursorScale}) then { | |
_alpha = 1; | |
_width = GVAR(iconHoverSize); | |
_height = GVAR(iconHoverSize); | |
["select"] call FUNC(setCursor); | |
}; | |
}; | |
}; | |
} else { | |
GVAR(unitIcons) pushBack [ASLtoAGL _pos, _object]; | |
}; | |
_color set [3, [_alpha, 1] select (_object in GVAR(selection))]; | |
drawIcon3D [ | |
_icon, | |
_color, | |
ASLtoAGL _pos, | |
_width, | |
_height, | |
0, | |
_displayText, | |
_shadow, | |
0.031 | |
]; | |
_rendered = _rendered + 1; | |
false | |
} count GVAR(serializedIcons);*/ | |
// systemChat format ["Drew %1 / %2 Entities", _rendered, count (entities "All")]; | |
END_COUNTER(drawAll3D); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment