addGroupIcon: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
(added icon zooming to example 2)
m (Text replacement - " +\] +" to "] ")
 
(4 intermediate revisions by 3 users not shown)
Line 19: Line 19:


|descr= Adds icon to a group leader. Returns icon ID, Control icons visibility with [[setGroupIconsVisible]].
|descr= Adds icon to a group leader. Returns icon ID, Control icons visibility with [[setGroupIconsVisible]].
|pr= The icons will be hidden again after switching to a different unit ''via'' [[teamSwitch]]. Execute <sqf inline>setGroupIconsVisible [true, false]; setGroupIconsSelectable true;</sqf> to make them visible again.


|s1= group [[addGroupIcon]] [iconClass, offset]
|s1= group [[addGroupIcon]] [iconClass, offset]


|p1= group: [[Group]] - group to add icon to
|p1= group: [[Group]] - group to which add the icon


|p2= iconClass: [[String]] - class name of an icon from {{hl|CfgGroupIcons}}
|p2= iconClass: [[String]] - class name of an icon from {{hl|CfgGroupIcons}}


|p3= offset: [[Array]] - (Optional) X and Y offsets of the icon in form [offsetX, offsetY]
|p3= offset: [[Array]] of [[Number]]s - (Optional, default [0,0]) X and Y offsets of the icon in format [offsetX, offsetY]


|r1= [[Number]] - Icon ID
|r1= [[Number]] - icon ID


|x1= <sqf>groupName addGroupIcon ["b_inf", [offsetX, offsetY]];</sqf>
|x1= <sqf>groupName addGroupIcon ["b_inf", [offsetX, offsetY]];</sqf>


|x2= <sqf>// Enable icons in 2D and 3D  
|x2= <spoiler>
setGroupIconsVisible [true, true];  
<sqf>
setGroupIconsSelectable true;  
// enable icons in 2D and 3D
setGroupIconsVisible [true, true];
// Add the icon for all existing groups  
setGroupIconsSelectable true;
allGroups apply  
 
{  
// add the icon for all existing groups
  private _icon = ["o_inf", "b_inf", "n_inf", "c_unknown"] select (side _x call BIS_fnc_sideID);  
allGroups apply
  private _color = [side _x, false] call BIS_fnc_sideColor;  
{
  _x addGroupIcon [_icon, [0, 0]];  
private _icon = ["o_inf", "b_inf", "n_inf", "c_unknown"] select (side _x call BIS_fnc_sideID);
  _x setGroupIconParams [_color, groupID _x, linearConversion [1, 15, count units _x, 0.5, 3, false], true];  
private _color = [side _x, false] call BIS_fnc_sideColor;
};  
_x addGroupIcon [_icon, [0, 0]];
_x setGroupIconParams [_color, groupID _x, linearConversion [1, 15, count units _x, 0.5, 3, false], true];
// Add group event handler to all existing groups to handle to icon sizing  
};
allGroups apply
 
{  
// add group event handler to all existing groups to handle to icon sizing
  _x addEventHandler ["UnitLeft",
allGroups apply
  {  
{
    params ["_group"];  
_x addEventHandler ["UnitLeft",
    getGroupIconParams group player params ["_color", "_text", "_scale", "_visibility"];  
{
    _group setGroupIconParams [_color, _text, linearConversion [1, 15, count units _group, 0.5, 2, true], _visibility];  
params ["_group"];
  }];  
getGroupIconParams group player params ["_color", "_text", "_scale", "_visibility"];
};  
_group setGroupIconParams [_color, _text, linearConversion [1, 15, count units _group, 0.5, 2, true], _visibility];
}];
// Add the icons whenever a group get's created  
};
addMissionEventHandler ["GroupCreated",  
 
{  
// add the icons whenever a group gets created
  params ["_group"];  
addMissionEventHandler ["GroupCreated",
  _group spawn  
{
  {  
params ["_group"];
    params ["_group"];  
_group spawn
    private _start = diag_tickTime;  
{
    waitUntil {sleep 1; units _group isNotEqualTo [] || diag_tickTime - _start > 5};  
params ["_group"];
    if (units _group isEqualTo []) exitWith {};  
private _start = diag_tickTime;
waitUntil {sleep 1; units _group isNotEqualTo [] || diag_tickTime - _start > 5};
    private _icon = ["o_inf", "b_inf", "n_inf", "c_unknown"] select (side _group call BIS_fnc_sideID);  
if (units _group isEqualTo []) exitWith {};
    private _color = [side _group, false] call BIS_fnc_sideColor;  
 
private _icon = ["o_inf", "b_inf", "n_inf", "c_unknown"] select (side _group call BIS_fnc_sideID);
    _group addGroupIcon [_icon, [0, 0]];  
private _color = [side _group, false] call BIS_fnc_sideColor;
   
 
    // Scale icon depending on group size  
_group addGroupIcon [_icon, [0, 0]];
    _group setGroupIconParams [_color, groupID _group, linearConversion [1, 15, count units _group, 0.5, 2, true], true];  
 
// scale icon depending on group size
    _group addEventHandler ["UnitLeft",
_group setGroupIconParams [_color, groupID _group, linearConversion [1, 15, count units _group, 0.5, 2, true], true];
    {  
 
      params ["_group"];  
_group addEventHandler ["UnitLeft",
      getGroupIconParams group player params ["_color", "_text", "_scale", "_visibility"];  
{
      _group setGroupIconParams [_color, _text, linearConversion [1, 15, count units _group, 0.5, 2, true], _visibility];  
params ["_group"];
    }];  
getGroupIconParams group player params ["_color", "_text", "_scale", "_visibility"];
  };  
_group setGroupIconParams [_color, _text, linearConversion [1, 15, count units _group, 0.5, 2, true], _visibility];
}];  
}];
};
// Show group info when hovering over an icon (2D/3D)  
}];
addMissionEventHandler ["GroupIconOverEnter",  
 
{  
// show group info when hovering over an icon (2D/3D)
  params  
addMissionEventHandler ["GroupIconOverEnter",
  [  
{
    "_is3D", "_group", "_waypointId",  
params
    "_posX", "_posY",  
[
    "_shift", "_control", "_alt"  
"_is3D", "_group", "_waypointId",
  ];  
"_posX", "_posY",
  hintSilent parseText format  
"_shift", "_control", "_alt"
  [  
];
    "<t align='left' font='EtelkaMonospacePro'><br/><t size='1.2'>General Information:</t><br/>Callsign: %1<br/>Leader: %2<br/>No. of Units: %3<br/>Delete when Empty: %4<br/><br/><t size='1.2'>Group Status:</t><br/>Health: %5<br/>Fleeing: %6<br/>Attack Enabled: %7<br/>Combat Behaviour: %8<br/>Combat Mode: %9<br/>Formation: %10<br/>Speed: %11<br/><br/><t size='1.2'>Waypoints:</t><br/>No. of Waypoints: %12<br/>Current Waypoint: %13<br/>Speed: %14</t>",  
hintSilent parseText format
    format ["%1 (%2)",groupID _group, if (vehicle leader _group isNotEqualTo leader _group) then {[configFile >> "CfgVehicles" >> typeOf vehicle leader _group ] call BIS_fnc_displayName} else {"-"}],  
[
    name leader _group,  
"<t align='left' font='EtelkaMonospacePro'><br/><t size='1.2'>General Information:</t><br/>Callsign: %1<br/>Leader: %2<br/>No. of Units: %3<br/>Delete when Empty: %4<br/><br/><t size='1.2'>Group Status:</t><br/>Health: %5<br/>Fleeing: %6<br/>Attack Enabled: %7<br/>Combat Behaviour: %8<br/>Combat Mode: %9<br/>Formation: %10<br/>Speed: %11<br/><br/><t size='1.2'>Waypoints:</t><br/>No. of Waypoints: %12<br/>Current Waypoint: %13<br/>Speed: %14</t>",
    count units _group,  
format ["%1 (%2)",groupID _group, if (vehicle leader _group isNotEqualTo leader _group) then {[configFile >> "CfgVehicles" >> typeOf vehicle leader _group] call BIS_fnc_displayName} else {"-"}],
    isGroupDeletedWhenEmpty _group,  
name leader _group,
    units _group apply {str round ((1 - damage _x)* 100) + " %"},  
count units _group,
    fleeing leader _x,  
isGroupDeletedWhenEmpty _group,
    attackEnabled _group,  
units _group apply {str round ((1 - damage _x)* 100) + " %"},
    combatBehaviour _group,  
fleeing leader _x,
    combatMode _group,  
attackEnabled _group,
    formation _group,  
combatBehaviour _group,
    speedMode _group,  
combatMode _group,
    count waypoints _group,  
formation _group,
    waypointType [_group, currentWaypoint _group],  
speedMode _group,
    units _group apply {str round speed _x + " km/h"}  
count waypoints _group,
  ];
waypointType [_group, currentWaypoint _group],
units _group apply {str round speed _x + " km/h"}
];
 
if !(_group getVariable ["IconEnlarged", false]) then
{
_group setVariable ["IconEnlarged", true];
 
getGroupIconParams _group params ["_color", "_text", "_scale", "_visibility"];
_group setGroupIconParams [_color, _text, _scale * 1.25, _visibility];
};
}];
 
// remove the hint whenever the mouse is leaving the icon area (2D/3D)
addMissionEventHandler ["GroupIconOverLeave",
{
params
[
"_is3D", "_group", "_waypointId",
"_posX", "_posY",
"_shift", "_control", "_alt"
];
hintSilent "";


  if !(_group getVariable ["IconEnlarged", false]) then
if (_group getVariable ["IconEnlarged", false]) then
  {
{
    _group setVariable ["IconEnlarged", true];
_group setVariable ["IconEnlarged", false];


    getGroupIconParams _group params ["_color", "_text", "_scale", "_visibility"];  
getGroupIconParams _group params ["_color", "_text", "_scale", "_visibility"];
    _group setGroupIconParams [_color, _text, _scale * 1.25, _visibility];
_group setGroupIconParams [_color, _text, linearConversion [1, 15, count units _group, 0.5, 2, true], _visibility];
  };
};
}];
}];
// Remove the hint whenever the mouse is leaving the icon area (2D/3D)
addMissionEventHandler ["GroupIconOverLeave",
{
  params
  [
    "_is3D", "_group", "_waypointId",
    "_posX", "_posY",
    "_shift", "_control", "_alt"
  ];
  hintSilent "";


  if (_group getVariable ["IconEnlarged", false]) then
// delete group and its units when clicking on the icon
  {
addMissionEventHandler ["GroupIconClick",
    _group setVariable ["IconEnlarged", false];
{
params
[
"_is3D", "_group", "_waypointId",
"_mouseButton", "_posX", "_posY",
"_shift", "_control", "_alt"
];


    getGroupIconParams _group params ["_color", "_text", "_scale", "_visibility"];
if (!_shift && _control && !_alt) then
    _group setGroupIconParams [_color, _text, linearConversion [1, 15, count units _group, 0.5, 2, true], _visibility];
{
  };
units _group apply {deleteVehicle _x};
}];
deleteGroup _group;
};
// Delete group and its units when clicking on the icon
}];
addMissionEventHandler ["GroupIconClick",
</sqf>
{
</spoiler>
  params
  [
    "_is3D", "_group", "_waypointId",
    "_mouseButton", "_posX", "_posY",
    "_shift", "_control", "_alt"
  ];
  if (!_shift && _control && !_alt) then  
  {  
    units _group apply {deleteVehicle _x};  
    deleteGroup _group;  
  };  
}];</sqf>


|seealso= [[clearGroupIcons]] [[getGroupIcon]] [[getGroupIconParams]] [[groupIconSelectable]] [[groupIconsVisible]] [[onGroupIconClick]] [[removeGroupIcon]] [[setGroupIcon]] [[setGroupIconParams]] [[setGroupIconsSelectable]] [[setGroupIconsVisible]]
|seealso= [[clearGroupIcons]] [[getGroupIcon]] [[getGroupIcons]] [[getGroupIconParams]] [[groupIconSelectable]] [[groupIconsVisible]] [[onGroupIconClick]] [[removeGroupIcon]] [[setGroupIcon]] [[setGroupIconParams]] [[setGroupIconsSelectable]] [[setGroupIconsVisible]]
}}
}}

Latest revision as of 17:49, 8 November 2023

Hover & click on the images for description

Description

Description:
Adds icon to a group leader. Returns icon ID, Control icons visibility with setGroupIconsVisible.
Problems:
The icons will be hidden again after switching to a different unit via teamSwitch. Execute setGroupIconsVisible [true, false]; setGroupIconsSelectable true; to make them visible again.
Groups:
High Command

Syntax

Syntax:
group addGroupIcon [iconClass, offset]
Parameters:
group: Group - group to which add the icon
iconClass: String - class name of an icon from CfgGroupIcons
offset: Array of Numbers - (Optional, default [0,0]) X and Y offsets of the icon in format [offsetX, offsetY]
Return Value:
Number - icon ID

Examples

Example 1:
groupName addGroupIcon ["b_inf", [offsetX, offsetY]];
Example 2:

// enable icons in 2D and 3D setGroupIconsVisible [true, true]; setGroupIconsSelectable true; // add the icon for all existing groups allGroups apply { private _icon = ["o_inf", "b_inf", "n_inf", "c_unknown"] select (side _x call BIS_fnc_sideID); private _color = [side _x, false] call BIS_fnc_sideColor; _x addGroupIcon [_icon, [0, 0]]; _x setGroupIconParams [_color, groupID _x, linearConversion [1, 15, count units _x, 0.5, 3, false], true]; }; // add group event handler to all existing groups to handle to icon sizing allGroups apply { _x addEventHandler ["UnitLeft", { params ["_group"]; getGroupIconParams group player params ["_color", "_text", "_scale", "_visibility"]; _group setGroupIconParams [_color, _text, linearConversion [1, 15, count units _group, 0.5, 2, true], _visibility]; }]; }; // add the icons whenever a group gets created addMissionEventHandler ["GroupCreated", { params ["_group"]; _group spawn { params ["_group"]; private _start = diag_tickTime; waitUntil {sleep 1; units _group isNotEqualTo [] || diag_tickTime - _start > 5}; if (units _group isEqualTo []) exitWith {}; private _icon = ["o_inf", "b_inf", "n_inf", "c_unknown"] select (side _group call BIS_fnc_sideID); private _color = [side _group, false] call BIS_fnc_sideColor; _group addGroupIcon [_icon, [0, 0]]; // scale icon depending on group size _group setGroupIconParams [_color, groupID _group, linearConversion [1, 15, count units _group, 0.5, 2, true], true]; _group addEventHandler ["UnitLeft", { params ["_group"]; getGroupIconParams group player params ["_color", "_text", "_scale", "_visibility"]; _group setGroupIconParams [_color, _text, linearConversion [1, 15, count units _group, 0.5, 2, true], _visibility]; }]; }; }]; // show group info when hovering over an icon (2D/3D) addMissionEventHandler ["GroupIconOverEnter", { params [ "_is3D", "_group", "_waypointId", "_posX", "_posY", "_shift", "_control", "_alt" ]; hintSilent parseText format [ "<t align='left' font='EtelkaMonospacePro'><br/><t size='1.2'>General Information:</t><br/>Callsign: %1<br/>Leader: %2<br/>No. of Units: %3<br/>Delete when Empty: %4<br/><br/><t size='1.2'>Group Status:</t><br/>Health: %5<br/>Fleeing: %6<br/>Attack Enabled: %7<br/>Combat Behaviour: %8<br/>Combat Mode: %9<br/>Formation: %10<br/>Speed: %11<br/><br/><t size='1.2'>Waypoints:</t><br/>No. of Waypoints: %12<br/>Current Waypoint: %13<br/>Speed: %14</t>", format ["%1 (%2)",groupID _group, if (vehicle leader _group isNotEqualTo leader _group) then {[configFile >> "CfgVehicles" >> typeOf vehicle leader _group] call BIS_fnc_displayName} else {"-"}], name leader _group, count units _group, isGroupDeletedWhenEmpty _group, units _group apply {str round ((1 - damage _x)* 100) + " %"}, fleeing leader _x, attackEnabled _group, combatBehaviour _group, combatMode _group, formation _group, speedMode _group, count waypoints _group, waypointType [_group, currentWaypoint _group], units _group apply {str round speed _x + " km/h"} ]; if !(_group getVariable ["IconEnlarged", false]) then { _group setVariable ["IconEnlarged", true]; getGroupIconParams _group params ["_color", "_text", "_scale", "_visibility"]; _group setGroupIconParams [_color, _text, _scale * 1.25, _visibility]; }; }]; // remove the hint whenever the mouse is leaving the icon area (2D/3D) addMissionEventHandler ["GroupIconOverLeave", { params [ "_is3D", "_group", "_waypointId", "_posX", "_posY", "_shift", "_control", "_alt" ]; hintSilent ""; if (_group getVariable ["IconEnlarged", false]) then { _group setVariable ["IconEnlarged", false]; getGroupIconParams _group params ["_color", "_text", "_scale", "_visibility"]; _group setGroupIconParams [_color, _text, linearConversion [1, 15, count units _group, 0.5, 2, true], _visibility]; }; }]; // delete group and its units when clicking on the icon addMissionEventHandler ["GroupIconClick", { params [ "_is3D", "_group", "_waypointId", "_mouseButton", "_posX", "_posY", "_shift", "_control", "_alt" ]; if (!_shift && _control && !_alt) then { units _group apply {deleteVehicle _x}; deleteGroup _group; }; }];

↑ Back to spoiler's top

Additional Information

See also:
clearGroupIcons getGroupIcon getGroupIcons getGroupIconParams groupIconSelectable groupIconsVisible onGroupIconClick removeGroupIcon setGroupIcon setGroupIconParams setGroupIconsSelectable setGroupIconsVisible

Notes

Report bugs on the Feedback Tracker and/or discuss them on the Arma Discord or on the Forums.
Only post proven facts here! Add Note