cba'fied nametags

This commit is contained in:
bux578 2015-01-13 12:29:13 +01:00
parent 621625b48d
commit 069eb7860a
16 changed files with 632 additions and 13 deletions

View File

@ -1,5 +1,11 @@
class Extended_PreInit_EventHandlers {
class ADDON {
init = QUOTE( call compile preprocessFileLineNumbers PATHTOF(XEH_preInit.sqf) );
init = QUOTE( call COMPILE_FILE(XEH_preInit) );
};
};
};
class Extended_PostInit_EventHandlers {
class ADDON {
postInit = QUOTE(call COMPILE_FILE(XEH_postInit) );
};
};

View File

@ -0,0 +1,56 @@
class CfgVehicles {
class Module_F;
class ACE_ModuleNameTags: Module_F {
author = "$STR_ACE_Core_ACETeam";
category = "ACE";
displayName = "Name Tags";
function = FUNC(moduleNameTags);
scope = 2;
isGlobal = 1;
icon = QUOTE(PATHTOF(UI\IconNameTags_ca.paa));
class Arguments {
class PlayerNamesViewDistance {
displayName = "Player Names View Dist.";
description = "Distance in meters at which player names are shown. Default: 5";
typeName = "NUMBER";
defaultValue = 5;
};
class ShowNamesForAI {
displayName = "Show name tags for AI?";
description = "Show the name and rank tags for friendly AI units? Default: No";
typeName = "BOOL";
class values {
class Yes {
name = "Yes";
value = 1;
};
class No {
default = 1;
name = "No";
value = 0;
};
};
};
class Visibility {
displayName = "Visibility of crew info";
description = "Forces visibility of vehicle crew info, or by default allows players to choose it on their own. Default: Do Not Force";
typeName = "INT";
class values {
class DoNotForce {
default = 1;
name = "Do Not Force";
value = 0;
};
class ForceShow {
name = "Force Show";
value = 1;
};
class ForceHide {
name = "Force Hide";
value = -1;
};
};
};
};
};
};

View File

@ -0,0 +1,41 @@
#define ACE_CrewInfo_TextIDC 11123
#define CT_STRUCTURED_TEXT 13
#define ST_LEFT 0
class RscTitles {
titles[]={"ACE_CrewInfo_dialog"};
class ACE_CrewInfo_dialog {
idd = -1;
movingEnable = 1;
duration = 1;
fadein = 0;
fadeout = 999999;
name = "ACE_CrewInfo_dialog";
controlsBackground[] = {"ACE_CrewInfo_text"};
onLoad = "uiNamespace setVariable ['ACE_CrewInfo_dialog', _this select 0]";
onUnload = "uiNamespace setVariable ['ACE_CrewInfo_dialog', objNull]";
class ACE_CrewInfo_text {
idc = ACE_CrewInfo_TextIDC;
type = CT_STRUCTURED_TEXT;
style = ST_LEFT;
x = SafeZonex + SafezoneW - 0.31;
y = SafeZoneY + SafeZoneH * 0.4;
w = 0.3;
h = 0.6;
size = 0.018;
colorBackground[] = { 0, 0, 0, 0 };
colortext[] = {
"(profilenamespace getvariable ['IGUI_TEXT_RGB_R',0])",
"(profilenamespace getvariable ['IGUI_TEXT_RGB_G',1])",
"(profilenamespace getvariable ['IGUI_TEXT_RGB_B',1])",
"(profilenamespace getvariable ['IGUI_TEXT_RGB_A',0.8])"
};
text="";
class Attributes {
align = right;
};
};
};
};

View File

@ -0,0 +1,62 @@
#include "script_component.hpp"
// by commy2 and CAA-Picard
if (!hasInterface) exitWith {};
GVAR(ShowNamesTime) = -10;
addMissionEventHandler ["Draw3D", {
if !(profileNamespace getVariable ["ACE_showPlayerNames", true]) exitWith {};
_player = ACE_player;
if (profileNamespace getVariable ["ACE_showPlayerNamesOnlyOnCursor", true]) then {
_target = cursorTarget;
_target = if (_target in allUnitsUAV) then {objNull} else {effectiveCommander _target};
if (!isNull _target && {side group _target == playerSide} && {_target != _player} && {isPlayer _target || {GVAR(ShowNamesForAI)}} && {!(_target getVariable ["ACE_hideName", false])}) then {
_distance = _player distance _target;
_alpha = ((1 - 0.2 * (_distance - GVAR(PlayerNamesViewDistance))) min 1) * GVAR(PlayerNamesMaxAlpha);
if (profileNamespace getVariable ["ACE_showPlayerNamesOnlyOnKeyPress", false]) then {
_alpha = _alpha min (1 - (time - GVAR(ShowNamesTime) - 1));
};
[_player, _target, _alpha, _distance * 0.026] call FUNC(drawNameTagIcon);
};
} else {
_pos = positionCameraToWorld [0, 0, 0];
_targets = _pos nearObjects ["Man", GVAR(PlayerNamesViewDistance) + 5];
if (!surfaceIsWater _pos) then {
_pos = ATLtoASL _pos;
};
_pos2 = positionCameraToWorld [0, 0, 1];
if (!surfaceIsWater _pos2) then {
_pos2 = ATLtoASL _pos2;
};
_vecy = _pos2 vectorDiff _pos;
{
_target = if (_x in allUnitsUAV) then {objNull} else {effectiveCommander _x};
if (!isNull _target && {side group _target == playerSide} && {_target != _player} && {isPlayer _target || {GVAR(ShowNamesForAI)}} && {!(_target getVariable ["ACE_hideName", false])}) then {
_relPos = (visiblePositionASL _target) vectorDiff _pos;
_distance = vectorMagnitude _relPos;
_projDist = _relPos vectorDistance (_vecy vectorMultiply (_relPos vectorDotProduct _vecy));
_alpha = ((1 - 0.2 * (_distance - GVAR(PlayerNamesViewDistance))) min (1 - 0.15 * (_projDist * 5 - _distance - 3)) min 1) * GVAR(PlayerNamesMaxAlpha);
if (profileNamespace getVariable ["ACE_showPlayerNamesOnlyOnKeyPress", false]) then {
_alpha = _alpha min (1 - (time - GVAR(ShowNamesTime) - 1));
};
// Check if there is line of sight
if (_alpha > 0) then {
if (lineIntersects [_pos, (visiblePositionASL _target) vectorAdd [0,0,1], vehicle _player, _target]) then {
_alpha = 0;
};
};
[_player, _target, _alpha, _distance * 0.026] call FUNC(drawNameTagIcon);
};
} forEach _targets;
};
}];

View File

@ -1,3 +1,9 @@
#include "script_component.hpp"
PREP(empty);
PREP(canShow);
PREP(doShow);
PREP(drawNameTagIcon);
PREP(getVehicleData);
PREP(moduleNameTags);
PREP(onMouseZChanged);
PREP(setText);

View File

@ -5,13 +5,61 @@ class CfgPatches {
units[] = {};
weapons[] = {};
requiredVersion = 0.60;
requiredAddons[] = {"ace_core"};
version = "0.95";
versionStr = "0.95";
versionAr[] = {0,95,0};
author[] = {""};
authorUrl = "";
requiredAddons[] = {"ace_main", "ace_common", "ace_interaction"};
version = QUOTE(VERSION);
versionStr = QUOTE(VERSION);
versionAr[] = {VERSION_AR};
author[] = {"commy2", "CAA-Picard"};
authorUrl = "https://github.com/commy2/";
};
};
#include "CfgEventHandlers.hpp"
#include "CfgEventHandlers.hpp"
#include "CfgVehicles.hpp"
class ACE_Core_Default_Keys {
class showNames {
displayName = "$STR_ACE_NameTags_ShowNames";
condition = "true";
statement = QUOTE( GVAR(ShowNamesTime) = time; if (call FUNC(canShow)) then {call FUNC(doShow);}; );
key = 29;
shift = 0;
control = 0;
alt = 0;
allowHolding = 1;
};
};
class ACE_Core_Options {
class showPlayerNames {
displayName = "$STR_ACE_NameTags_ShowPlayerNames";
default = 1;
};
class showPlayerNamesOnlyOnCursor {
displayName = "$STR_ACE_NameTags_ShowPlayerNamesOnlyOnCursor";
default = 1;
};
class showPlayerNamesOnlyOnKeyPress {
displayName = "$STR_ACE_NameTags_ShowPlayerNamesOnlyOnKeyPress";
default = 0;
};
class showPlayerRanks {
displayName = "$STR_ACE_NameTags_ShowPlayerRanks";
default = 1;
};
class showVehicleCrewInfo {
displayName = "$STR_ACE_CrewInfo_ShowVehicleCrewInfo";
default = 1;
};
};
class ACE_Parameters_Numeric {
GVAR(PlayerNamesViewDistance) = 5;
GVAR(PlayerNamesMaxAlpha) = 0.8;
GVAR(CrewInfoVisibility) = 0;
};
class ACE_Parameters_Boolean {
GVAR(ShowNamesForAI) = 0;
};
#include <RscTitles.hpp>

View File

@ -0,0 +1,26 @@
/*
Author: aeroson
Description:
Images, index in images and order of roles.
Defined number also implies order, lower number shows more on top of the list.
*/
#include "script_component.hpp"
#define PILOT 0
#define DRIVER 1
#define COPILOT PILOT
#define COMMANDER 2
#define GUNNER 3
#define FFV 4
#define CARGO 5
#define ROLE_IMAGES [ \
"a3\ui_f\data\IGUI\Cfg\Actions\getinpilot_ca.paa", \
"a3\ui_f\data\IGUI\Cfg\Actions\getindriver_ca.paa", \
"a3\ui_f\data\IGUI\Cfg\Actions\getincommander_ca.paa", \
"a3\ui_f\data\IGUI\Cfg\Actions\getingunner_ca.paa", \
QUOTE(PATHTOF(UI\icon_position_ffv.paa)), \
"a3\ui_f\data\IGUI\Cfg\Actions\getincargo_ca.paa" \
]

View File

@ -0,0 +1,27 @@
/*
Author: aeroson
Description:
Might be called several times a second
Parameters:
None
Returns:
true if CrewInfo can be shown, false otherwise
*/
#include "script_component.hpp"
private["_player"];
_player = ACE_player;
// AGM_NameTags_ShowVehicleCrewInfo: -1 force NO, 0 doesnt care, 1 force YES
vehicle _player != _player &&
{
(GVAR(CrewInfoVisibility) == 1) ||
(GVAR(CrewInfoVisibility) != -1 && profileNamespace getVariable ["ACE_showVehicleCrewInfo", false])
} &&
{!(vehicle _player isKindOf "ParachuteBase")};

View File

@ -0,0 +1,93 @@
/*
Author: aeroson
Description:
Shows the actual text and sets text the crew info
Parameters:
None
Returns:
Nothing
*/
#include "script_component.hpp"
#include QUOTE(PATHTOF(functions\common.sqf));
private["_roleImages", "_player", "_vehicle", "_type", "_config", "_text", "_data", "_isAir", "_turretUnits", "_turretRoles", "_index", "_roleType", "_unit", "_toShow"];
_player = ACE_player;
_vehicle = vehicle _player;
_type = typeOf _vehicle;
_config = configFile >> "CfgVehicles" >> _type;
_text = format["<t size='1.4'><img image='%1'></t> <t size='1.7' shadow='true'>%2</t><br/>", getText(_config>>"picture"), getText (_config >> "DisplayName")];
_data = [_type] call FUNC(getVehicleData);
_isAir = _data select 0;
_data = _data select 1;
_turretUnits = [_data, { _vehicle turretUnit (_x select 0) } ] call EFUNC(Core,map);
_turretRoles = [_data, { _x select 1 } ] call EFUNC(Core,map);
_roleType = CARGO;
_toShow = [];
{
switch (_x) do {
case commander _vehicle: {
_roleType = COMMANDER;
};
case gunner _vehicle: {
_roleType = GUNNER;
};
case driver _vehicle: {
_roleType = if(_isAir) then { PILOT } else { DRIVER };
};
default {
_index = _turretUnits find _x;
if(_index !=-1 ) then {
_roleType = _turretRoles select _index;
} else {
_roleType = CARGO;
};
};
};
_toShow pushBack [_x, _roleType];
} forEach crew _vehicle;
_toShow = [
_toShow,
[],
{
_x select 1
},
"ASCEND",
{
_unit = _x select 0;
alive _unit
}
] call BIS_fnc_sortBy;
_roleImages = ROLE_IMAGES;
{
_unit = _x select 0;
_roleType = _x select 1;
_text = _text + format["<t size='1.5' shadow='true'>%1</t> <t size='1.3'><img image='%2'></t><br/>", [_unit] call EFUNC(Core,getName), _roleImages select _roleType];
} forEach _toShow;
("ACE_CrewInfo_CrewInfo" call BIS_fnc_rscLayer) cutRsc ["ACE_CrewInfo_dialog", "PLAIN", 1, false];
terminate (missionNamespace getVariable [QGVAR(hideCrewInfoHandle), scriptNull]);
GVAR(hideCrewInfoHandle) = 0 spawn {
sleep 2;
("ACE_CrewInfo_CrewInfo" call BIS_fnc_rscLayer) cutFadeOut 2;
};
[_text] call FUNC(setText);

View File

@ -0,0 +1,63 @@
/*
* Author: commy2, CAA-Picard
*
* Draw the nametag and rank icon.
*
* Argument:
* 0: Unit (Array)
* 1: alpha (Number)
* 2: Height offset (Number)
*
* Return value:
* None.
*/
#include "script_component.hpp"
#define TEXTURES_RANKS [ \
"", \
"\A3\Ui_f\data\GUI\Cfg\Ranks\private_gs.paa", \
"\A3\Ui_f\data\GUI\Cfg\Ranks\corporal_gs.paa", \
"\A3\Ui_f\data\GUI\Cfg\Ranks\sergeant_gs.paa", \
"\A3\Ui_f\data\GUI\Cfg\Ranks\lieutenant_gs.paa", \
"\A3\Ui_f\data\GUI\Cfg\Ranks\captain_gs.paa", \
"\A3\Ui_f\data\GUI\Cfg\Ranks\major_gs.paa", \
"\A3\Ui_f\data\GUI\Cfg\Ranks\colonel_gs.paa" \
]
private ["_player", "_target", "_alpha", "_heightOffset", "_height", "_position", "_color", "_name", "_rank", "_size"];
_player = _this select 0;
_target = _this select 1;
_alpha = _this select 2;
_heightOffset = _this select 3;
_height = [2, 1.5, 1, 1.5, 1] select (["STAND", "CROUCH", "PRONE", "UNDEFINED", ""] find stance _target);
_position = visiblePositionASL _target;
// Convert position to ASLW (expected by drawIcon3D) and add height offsets
_position set [2, ((_target modelToWorld [0,0,0]) select 2) + _height + _heightOffset];
_color = if !(group _target == group _player) then {
[0.77, 0.51, 0.08, _alpha]
} else {
[[1, 1, 1, _alpha], [1, 0, 0, _alpha], [0, 1, 0, _alpha], [0, 0, 1, _alpha], [1, 1, 0, _alpha]] select (["MAIN", "RED", "GREEN", "BLUE", "YELLOW"] find (if (_target == _player) then {0} else {assignedTeam _target})) max 0
};
_name = [_target, true] call EFUNC(Core,getName);
_rank = TEXTURES_RANKS select ((["PRIVATE", "CORPORAL", "SERGEANT", "LIEUTENANT", "CAPTAIN", "MAJOR", "COLONEL"] find rank _target) + 1);
_size = [0, 1] select (profileNamespace getVariable ["ACE_showPlayerRanks", true]);
drawIcon3D [
_rank,
_color,
_position,
_size,
_size,
0,
_name,
2,
0.033,
"PuristaMedium"
];

View File

@ -1,3 +0,0 @@
#include "script_component.hpp"
diag_log text format["This is here as an example!!!"];

View File

@ -0,0 +1,123 @@
/*
Author: aeroson
Description:
Gathers and caches data needed by AGM_CrewInfo_fnc_doShow
What really does make difference for the engine is simulation of CfgAmmo
Priority of roles is: driver/pilot, gunner, copilot, commander, ffv, cargo
Parameters:
None
Returns:
[
Is vehicle inherited from Air ?
Array categorizing each vehicle's turret
]
*/
#include "script_component.hpp"
#include QUOTE(PATHTOF(functions\common.sqf));
private ["_type", "_varName", "_data"];
_type = _this select 0;
_varName = format ["AGM_CrewInfo_Cache_%1", _type];
_data = + (uiNamespace getVariable _varName);
if (!isNil "_data") exitWith {
_data
};
_data = [];
private ["_isAir", "_config", "_fnc_addTurret", "_fnc_addTurretUnit"];
_isAir = _type isKindOf "Air";
_fnc_addTurretUnit = {
private ["_config", "_path", "_role", "_simulationEmpty", "_simulationLaserDesignate", "_simulationOther", "_magazine", "_ammo", "_simulation"];
_config = _this select 0;
_path = _this select 1;
_role = CARGO;
_simulationEmpty = 0;
_simulationLaserDesignate = 0;
_simulationOther = 0;
{
{
_magazine = configFile >> "CfgMagazines" >> _x;
_ammo = configFile >> "CfgAmmo" >> getText (_magazine >> "ammo");
_simulation = getText (_ammo >> "simulation");
if(_simulation=="") then {
_simulationEmpty = _simulationEmpty + 1;
} else {
if(_simulation=="laserDesignate") then {
_simulationLaserDesignate = _simulationLaserDesignate + 1;
} else {
_simulationOther = _simulationOther + 1;
};
};
} forEach getArray (configFile >> "CfgWeapons" >> _x >> "magazines");
} forEach getArray (_config >> "weapons");
if(_simulationOther>0) then {
_role = GUNNER;
};
if (_role == CARGO && {getNumber (_config >> "isCopilot") == 1}) then {
_role = COPILOT;
};
if (_role == CARGO && {_simulationLaserDesignate>0 || getNumber (_config >> "primaryObserver") == 1}) then {
_role = COMMANDER;
};
if (_role == CARGO && {getNumber (_config >> "isPersonTurret") == 1}) then {
_role = FFV;
};
_data pushBack [_path, _role];
};
_fnc_addTurret = {
private ["_config", "_path", "_count", "_offset", "_index", "_turretPath", "_turretConfig"];
_config = _this select 0;
_path = _this select 1;
_config = _config >> "Turrets";
_count = count _config;
_offset = 0;
for "_index" from 0 to (_count - 1) do {
_turretPath = _path + [_index - _offset];
_turretConfig = _config select _index;
if (isClass _turretConfig) then {
[_turretConfig, _turretPath] call _fnc_addTurretUnit;
[_turretConfig, _turretPath] call _fnc_addTurret;
} else {
_offset = _offset + 1;
};
};
};
_config = configFile >> "CfgVehicles" >> _type;
[_config, []] call _fnc_addTurret;
_data = [_isAir, _data];
uiNamespace setVariable [_varName, _data];
_data

View File

@ -0,0 +1,29 @@
/*
* Author: CAA-Picard
*
* Initializes the name tags module.
*
* Arguments:
* Whatever the module provides.
*
* Return Value:
* None
*/
#include "script_component.hpp"
if !(isServer) exitWith {};
_logic = _this select 0;
_units = _this select 1;
_activated = _this select 2;
if !(_activated) exitWith {};
GVAR(Module) = true;
[_logic, QGVAR(PlayerNamesViewDistance), "PlayerNamesViewDistance" ] call EFUNC(Core,readNumericParameterFromModule);
[_logic, QGVAR(ShowNamesForAI), "ShowNamesForAI" ] call EFUNC(Core,readBooleanParameterFromModule);
[_logic, QGVAR(CrewInfoVisibility), "Visibility" ] call EFUNC(Core,readNumericParameterFromModule);
diag_log text "[ACE]: NameTags Module Initialized.";

View File

@ -0,0 +1,18 @@
/*
Author: aeroson
Description:
Callback for mouse wheel change
Parameters:
None
Returns:
Nothing
*/
#include "script_component.hpp"
if(call FUNC(canShow)) then {
call FUNC(doShow);
};

View File

@ -0,0 +1,23 @@
/*
Author: aeroson
Description:
Sets the text on the dialog
Parameters:
None
Returns:
Nothing
*/
#define GVAR(TextIDC) 11123
private["_text", "_ctrl"];
disableSerialization;
_text = _this select 0;
_ctrl = (uiNamespace getVariable QGVAR(dialog)) displayCtrl GVAR(TextIDC);
_ctrl ctrlSetStructuredText parseText _text;
_ctrl ctrlCommit 0;

View File

@ -0,0 +1 @@
#include "\z\ace\addons\nametags\script_component.hpp"