Handle unit icons and provide setting

This commit is contained in:
SilentSpike 2015-07-25 12:28:03 +01:00
parent 2f1639822c
commit 21ce877115
10 changed files with 89 additions and 33 deletions

View File

@ -1,11 +1,7 @@
class ACE_Settings {
class GVAR(enabledSystem) {
typeName = "BOOL";
value = 0;
};
class GVAR(filterUnits) {
typeName = "SCALAR";
value = 0;
value = 1;
values[] = {CSTRING(units_none), CSTRING(units_players), CSTRING(units_all)};
};
class GVAR(filterSides) {
@ -23,4 +19,8 @@ class ACE_Settings {
value = 0;
values[] = {CSTRING(modes_all), CSTRING(visions_nv), CSTRING(visions_ti), "$STR_Special_None"};
};
class GVAR(unitIcons) {
typeName = "BOOL";
value = 1;
};
};

View File

@ -9,12 +9,6 @@ class CfgVehicles {
isGlobal = 1;
author = ECSTRING(common,ACETeam);
class Arguments {
class spectatorSystem {
displayName = CSTRING(system_DisplayName);
description = CSTRING(system_Description);
typeName = "BOOL";
defaultValue = 0;
};
class unitsFilter {
displayName = CSTRING(units_DisplayName);
description = CSTRING(units_Description);
@ -23,11 +17,11 @@ class CfgVehicles {
class none {
name = CSTRING(units_none);
value = 0;
default = 1;
};
class players {
name = CSTRING(units_players);
value = 1;
default = 1;
};
class all {
name = CSTRING(units_all);
@ -111,6 +105,12 @@ class CfgVehicles {
};
};
};
class unitIcons {
displayName = CSTRING(icons_DisplayName);
description = CSTRING(icons_Description);
typeName = "BOOL";
defaultValue = 1;
};
};
class ModuleDescription {
description = CSTRING(Settings_Description);

View File

@ -4,16 +4,7 @@
// Add interaction menu exception
["isNotSpectating", {!((_this select 0) getVariable [QGVAR(isSpectator), false])}] call EFUNC(common,addCanInteractWithCondition);
// Run spectator framework if enabled
["SettingsInitialized", {
GVAR(availableModes) = [[0,1,2], [1,2], [0], [1], [2]] select GVAR(restrictModes);
GVAR(availableVisions) = [[-2,-1,0,1], [-2,-1], [-2,0,1], [-2]] select GVAR(restrictVisions);
if !(hasInterface) exitWith {};
if (GVAR(system)) then {
// Add event handlers to correctly enter spectator upon death
player addEventHandler ["Killed", FUNC(handleKilled)];
player addEventHandler ["Respawn", FUNC(handleRespawn)];
};
}] call EFUNC(common,addEventHandler);

View File

@ -6,6 +6,7 @@ PREP(cacheUnitInfo);
PREP(cycleCamera);
PREP(handleCamera);
PREP(handleCompass);
PREP(handleIcons);
PREP(handleInterface);
PREP(handleKilled);
PREP(handleMouse);

View File

@ -0,0 +1,57 @@
/*
* Author: SilentSpike
* Handles rendering the spectator 3D unit icons
*
* Arguments:
* 0: Parameters <ANY>
* 1: PFH handle <NUMBER>
*
* Return Value:
* None <NIL>
*
* Example:
* [ace_spectator_fnc_handleIcons, 0] call CBA_fnc_addPerFrameHandler;
*
* Public: No
*/
#include "script_component.hpp"
// Kill PFH when not in free cam (or display is closed)
if (isNil QGVAR(iconHandler)) exitWith { [_this select 1] call CBA_fnc_removePerFrameHandler; };
if !(GVAR(showIcons)) exitWith {};
private ["_cachedVehicles","_unit","_cameraPos","_cameraDir","_lambda","_uPos","_cmd","_txt"];
_cachedVehicles = [];
{
_unit = vehicle _x;
// Only try each vehicle once
if !(_unit in _cachedVehicles) then {
_cachedVehicles pushBack _unit;
// Within 200m
if ((GVAR(camera) distanceSqr _unit) < 40000) then {
_cameraPos = (positionCameraToWorld [0, 0, 0]) call EFUNC(common,positionToASL);
_cameraDir = ((positionCameraToWorld [0, 0, 1]) call EFUNC(common,positionToASL)) vectorDiff _cameraPos;
// Quick oclussion test (taken from interact_menu)
_lambda = ((getPosASL _x) vectorDiff _cameraPos) vectorDotProduct _cameraDir;
if (_lambda > -1) then {
_uPos = worldToScreen (visiblePosition _unit);
// Only draw if onscreen
if ((_uPos select 0 > safeZoneXAbs) && (_uPos select 0 < safeZoneXAbs + safeZoneWAbs)) then {
if ((_uPos select 1 > safeZoneY) && (_uPos select 1 < safeZoneY + safeZoneH)) then {
// Use commander's info if available
_cmd = [_x, effectiveCommander _unit] select ((effectiveCommander _unit) in GVAR(unitList));
_txt = ["", GETVAR(_cmd,GVAR(uName),"")] select (isPlayer _cmd);
drawIcon3D ["\A3\ui_f\data\map\markers\military\dot_CA.paa", GETVAR(_cmd,GVAR(uColor),[ARR_4(0,0,0,0)]), _unit modelToWorldVisual [0,0,3], 0.7, 0.7, 0, _txt, 1, 0.02];
};
};
};
};
};
} forEach GVAR(unitList);

View File

@ -154,6 +154,7 @@ switch (toLower _mode) do {
GVAR(camHandler) = nil;
GVAR(compHandler) = nil;
GVAR(iconHandler) = nil;
GVAR(toolHandler) = nil;
};
// Mouse events
@ -391,7 +392,7 @@ switch (toLower _mode) do {
_newPos = _map ctrlMapScreenToWorld [_x,_y];
_oldZ = (ASLtoATL GVAR(camPos)) select 2;
_newPos set [2, _oldZ];
GVAR(camPos) = (ATLtoASL _newPos);
[nil,nil,nil, _newPos] call FUNC(setCameraAttributes);
};
};
case "ondraw": {

View File

@ -19,8 +19,8 @@ params ["_logic", "_units", "_activated"];
if !(_activated) exitWith {};
[_logic, QGVAR(enabledSystem), "spectatorSystem"] call EFUNC(common,readSettingFromModule);
[_logic, QGVAR(filterUnits), "unitsFilter"] call EFUNC(common,readSettingFromModule);
[_logic, QGVAR(filterSides), "sidesFilter"] call EFUNC(common,readSettingFromModule);
[_logic, QGVAR(restrictModes), "cameraModes"] call EFUNC(common,readSettingFromModule);
[_logic, QGVAR(restrictVisions), "visionModes"] call EFUNC(common,readSettingFromModule);
[_logic, QGVAR(unitIcons), "unitIcons"] call EFUNC(common,readSettingFromModule);

View File

@ -24,7 +24,7 @@
params ["_display", ["_toggleComp",false], ["_toggleHelp",false], ["_toggleInterface",false], ["_toggleMap",false], ["_toggleTool",false], ["_toggleUnit",false]];
private ["_comp","_display","_help","_map","_tool","_unit"];
private ["_comp","_help","_map","_tool","_unit"];
_comp = _display displayCtrl IDC_COMP;
_help = _display displayCtrl IDC_HELP;
_map = _display displayCtrl IDC_MAP;
@ -75,15 +75,15 @@ if (GVAR(showMap)) then {
};
};
// Only run PFHs for toolbar and compass when respective control is shown, otherwise kill
// Only run PFHs when respective control is shown, otherwise kill
if (ctrlShown _comp) then {
if (isNil QGVAR(compHandler)) then { GVAR(compHandler) = [FUNC(handleCompass), 0] call CBA_fnc_addPerFrameHandler; };
if (isNil QGVAR(compHandler)) then { GVAR(compHandler) = [FUNC(handleCompass), 0, _display] call CBA_fnc_addPerFrameHandler; };
} else {
GVAR(compHandler) = nil;
};
if (ctrlShown _tool) then {
if (isNil QGVAR(toolHandler)) then { GVAR(toolHandler) = [FUNC(handleToolbar), 0] call CBA_fnc_addPerFrameHandler; };
if (isNil QGVAR(toolHandler)) then { GVAR(toolHandler) = [FUNC(handleToolbar), 0, _display] call CBA_fnc_addPerFrameHandler; };
} else {
GVAR(toolHandler) = nil;
};

View File

@ -75,6 +75,11 @@ if (_newMode == 0) then { // Free
// Handle camera movement
if (isNil QGVAR(camHandler)) then { GVAR(camHandler) = [FUNC(handleCamera), 0] call CBA_fnc_addPerFrameHandler; };
// Handle unit icons
if (GVAR(unitIcons)) then {
if (isNil QGVAR(iconHandler)) then { GVAR(iconHandler) = [FUNC(handleIcons), 0] call CBA_fnc_addPerFrameHandler; };
};
} else {
// When null unit is given choose random
if (isNull _newUnit) then {
@ -102,6 +107,7 @@ if (_newMode == 0) then { // Free
// Terminate camera view
GVAR(camera) cameraEffect ["terminate", "back"];
GVAR(camHandler) = nil;
GVAR(iconHandler) = nil;
cameraEffectEnableHUD true;
};

View File

@ -7,12 +7,6 @@
<Key ID="STR_ACE_Spectator_Settings_Descripton">
<English>Configure how the spectator system will operate by default.</English>
</Key>
<Key ID="STR_ACE_Spectator_system_DisplayName">
<English>Spectator System</English>
</Key>
<Key ID="STR_ACE_Spectator_system_Description">
<English>Enter spectator mode upon respawn.</English>
</Key>
<Key ID="STR_ACE_Spectator_units_DisplayName">
<English>Unit filter</English>
</Key>
@ -79,6 +73,12 @@
<Key ID="STR_ACE_Spectator_visions_ti">
<English>Thermal imaging</English>
</Key>
<Key ID="STR_ACE_Spectator_icons_DisplayName">
<English>Unit icons</English>
</Key>
<Key ID="STR_ACE_Spectator_icons_Description">
<English>Render icons above spectatable units.</English>
</Key>
<!-- Interface strings -->
<Key ID="STR_ACE_Spectator_HelpTitle">