Skip to content

Instantly share code, notes, and snippets.

@commy2
Last active May 19, 2018 19:46
Show Gist options
  • Select an option

  • Save commy2/a9c38e87084d385e7e402203a14f6f83 to your computer and use it in GitHub Desktop.

Select an option

Save commy2/a9c38e87084d385e7e402203a14f6f83 to your computer and use it in GitHub Desktop.
// toggle: close old radar if present
private _display = uiNamespace getVariable ["commy_SquadRadar", displayNull];
if (!isNull _display) exitWith {
"commy_SquadRadar" cutText ["", "PLAIN"];
false
};
// otherwise create canvas
"commy_SquadRadar" cutRsc ["RscTitleDisplayEmpty", "PLAIN", 0, false];
_display = uiNamespace getVariable "RscTitleDisplayEmpty";
uiNamespace setVariable ["commy_SquadRadar", _display];
// kill duplicate vignette
private _vignette = _display displayCtrl 1202;
_vignette ctrlShow false;
// radar control
private _control = _display ctrlCreate ["RscPicture", -1];
_display setVariable ["commy_SquadRadar", _control];
private _width = 8 * (((safezoneW / safezoneH) min 1.2) / 40);
private _height = 8 * ((((safezoneW / safezoneH) min 1.2) / 1.2) / 25);
private _left = (0.5 - _width/2);
private _top = (safezoneY + safezoneH - 1.2 * _height);
_control ctrlSetPosition [_left, _top, _width, _height];
_control ctrlCommit 0;
// squad member markers
private _markers = [];
_control setVariable ["commy_SquadRadarMarkers", _markers];
for "_i" from 1 to 20 do {
private _marker = _display ctrlCreate ["RscPicture", -1];
_marker ctrlSetText "\a3\ui_f\data\IGUI\Cfg\SquadRadar\SquadRadarOtherGroupUnit_ca.paa";
_marker ctrlShow false;
_markers pushBack _marker;
};
// draw script
private _script = _display ctrlCreate ["RscMapControl", -1];
_script ctrlSetPosition [0,0,0,0];
_script ctrlCommit 0;
_script ctrlAddEventHandler ["Draw", {
params ["_script"];
private _display = ctrlParent _script;
private _control = _display getVariable "commy_SquadRadar";
private _markers = _control getVariable "commy_SquadRadarMarkers";
private _unit = missionNamespace getVariable ["bis_fnc_moduleRemoteControl_unit", player];
private _radius = 40;
private _nearUnits = nearestObjects [_unit, ["CAManBase"], _radius] select {_unit knowsAbout _x >= 4};
// show or hide cardinal directions if unit owns compass
if ("ItemCompass" in assignedItems _unit) then {
_control ctrlSetText "\a3\ui_f\data\IGUI\Cfg\SquadRadar\SquadRadarCompassBackgroundTexture_ca.paa";
private _view = AGLToASL positionCameraToWorld [0,0,0] vectorFromTo AGLToASL positionCameraToWorld [0,0,1];
private _viewHorizontal = vectorNormalized (_view vectorCrossProduct [0,0,1]);
private _dir = acos (_viewHorizontal select 0);
if (_viewHorizontal select 1 > 0) then {
_dir = 360 - _dir;
};
_control ctrlSetAngle [-_dir,0.5,0.5];
} else {
_control ctrlSetText "\a3\ui_f\data\IGUI\Cfg\SquadRadar\SquadRadarBackgroundTexture_ca.paa";
};
// update positions of squad members
ctrlPosition _control params ["_left", "_top", "_width", "_height"];
private _center = [_left + _width/2, _top + _height/2];
{
private _target = _nearUnits param [_forEachIndex, objNull];
if (isNull _target) then {
_x ctrlShow false;
} else {
private _dir = _unit getRelDir _target;
private _dist = (_unit distance2D _target) / (_radius*2);
_x ctrlSetPosition [
(_center select 0) + _width * (sin _dir * _dist) - _width/8,
(_center select 1) - _height * (cos _dir * _dist) - _height/8,
_width/4,
_height/4
];
_x ctrlCommit 0;
_x ctrlShow true;
};
} forEach _markers;
}];
true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment