diff --git a/addons/map_gestures/CfgEventHandlers.hpp b/addons/map_gestures/CfgEventHandlers.hpp index e75956f440..7e0c8d2ce3 100644 --- a/addons/map_gestures/CfgEventHandlers.hpp +++ b/addons/map_gestures/CfgEventHandlers.hpp @@ -7,5 +7,6 @@ class Extended_PreInit_EventHandlers { class Extended_PostInit_EventHandlers { class ADDON { init = QUOTE(call COMPILE_FILE(XEH_postInit)); + serverInit = QUOTE(call COMPILE_FILE(XEH_serverPostInit)); }; }; diff --git a/addons/map_gestures/XEH_preInit.sqf b/addons/map_gestures/XEH_preInit.sqf index ad4da44998..8154106fd6 100644 --- a/addons/map_gestures/XEH_preInit.sqf +++ b/addons/map_gestures/XEH_preInit.sqf @@ -11,7 +11,6 @@ PREP(isValidColorArray); PREP(moduleGroupSettings); PREP(moduleSettings); PREP(receiverInit); -PREP(sanitizeName); PREP(transmit); PREP(transmitterInit); diff --git a/addons/map_gestures/XEH_serverPostInit.sqf b/addons/map_gestures/XEH_serverPostInit.sqf new file mode 100644 index 0000000000..9bbf84911e --- /dev/null +++ b/addons/map_gestures/XEH_serverPostInit.sqf @@ -0,0 +1,3 @@ +#include "script_component.hpp" + +[MAP_GESTURES_NO_OWNER_ID_EVENT, FUNC(assignClientIDOnServer)] call EFUNC(common,addEventHandler) diff --git a/addons/map_gestures/functions/fnc_assignClientIDOnServer.sqf b/addons/map_gestures/functions/fnc_assignClientIDOnServer.sqf index c686c17b79..92b1e95ab5 100644 --- a/addons/map_gestures/functions/fnc_assignClientIDOnServer.sqf +++ b/addons/map_gestures/functions/fnc_assignClientIDOnServer.sqf @@ -18,7 +18,7 @@ params ["_unitName"]; { - if (name _x == _unitName) then { + if (name _x == _unitName) exitWith { _x setVariable [QGVAR(owner_id), owner _x, true]; }; } count playableUnits; diff --git a/addons/map_gestures/functions/fnc_drawMapGestures.sqf b/addons/map_gestures/functions/fnc_drawMapGestures.sqf index 54efd878ce..31c41ca995 100644 --- a/addons/map_gestures/functions/fnc_drawMapGestures.sqf +++ b/addons/map_gestures/functions/fnc_drawMapGestures.sqf @@ -15,23 +15,35 @@ */ #include "script_component.hpp" -if (!GVAR(enabled)) exitWith {}; -if (!visibleMap) exitWith {}; +#define ICON_RENDER_SIZE 55 +#define ICON_TEXT_ALIGN "left" +#define ICON_ANGLE 0 +#define ICON_SHADOW 1 +#define TEXT_FONT "PuristaBold" +#define TEXT_ICON_RENDER_SIZE 20 +#define TEXT_SIZE 0.030 +#define TEXT_SHADOW 0 + +if (!GVAR(enabled) || !visibleMap) exitWith {}; params ["_mapHandle"]; -_proximityPlayers = [ACE_player, GVAR(maxRange)] call FUNC(getProximityPlayers); +// Iterate over all nearby players and render their pointer if player is transmitting. { - _nameSane = [name _x] call FUNC(sanitizeName); - _drawPosVariableName = format [QGVAR(%1_DrawPos), _nameSane]; - if (!isNil _drawPosVariableName) then { + // Data variable name for unit + _unitUID = getPlayerUID _x; + _drawPosVariableName = if (!isNil "_unitUID" && _unitUID != "") then {format [QGVAR(%1_DrawPos), _unitUID]} else {nil}; + + if (!isNil "_drawPosVariableName") then { if (isNil {missionNamespace getVariable _drawPosVariableName}) then {missionNamespace setVariable [_drawPosVariableName, [1, 1, 1]];}; _pos = missionNamespace getVariable _drawPosVariableName; - if (alive _x && - {_x getVariable QGVAR(Transmit)}) then { + + // Only render if the unit is alive and transmitting + if (alive _x && {_x getVariable QGVAR(Transmit)}) then { _group = group _x; _grpName = groupID _group; + // If color settings for the group exist, then use those, otherwise fall back to the default colors _color = if (_grpName in GVAR(GroupColorConfigurationsGroups)) then { _grpNameIndex = GVAR(GroupColorConfigurationsGroups) find _grpName; (GVAR(GroupColorConfigurations) select (GVAR(GroupColorConfigurationsGroupIndex) select _grpNameIndex)) select (_x != leader _group) @@ -39,9 +51,10 @@ _proximityPlayers = [ACE_player, GVAR(maxRange)] call FUNC(getProximityPlayers); if (_x == leader _group) then {GVAR(defaultLeadColor)} else {GVAR(defaultColor)}; }; - _mapHandle drawIcon ["\a3\ui_f\data\gui\cfg\Hints\icon_text\group_1_ca.paa", _color, _pos, 55, 55, 0, "", 1, 0.030, "PuristaBold", "left"]; - _mapHandle drawIcon ["#(argb,8,8,3)color(0,0,0,0)", [.2,.2,.2,.3], _pos, 20, 20, 0, name _x, 0, 0.030, "PuristaBold", "left"]; + // Render icon and player name + _mapHandle drawIcon ["\a3\ui_f\data\gui\cfg\Hints\icon_text\group_1_ca.paa", _color, _pos, ICON_RENDER_SIZE, ICON_RENDER_SIZE, ICON_ANGLE, "", ICON_SHADOW, TEXT_SIZE, TEXT_FONT, ICON_TEXT_ALIGN]; + _mapHandle drawIcon ["#(argb,8,8,3)color(0,0,0,0)", [.2,.2,.2,.3], _pos, TEXT_ICON_RENDER_SIZE, TEXT_ICON_RENDER_SIZE, ICON_ANGLE, name _x, TEXT_SHADOW, TEXT_SIZE, TEXT_FONT, ICON_TEXT_ALIGN]; }; }; nil -} count _proximityPlayers; +} count ([ACE_player, GVAR(maxRange)] call FUNC(getProximityPlayers)); diff --git a/addons/map_gestures/functions/fnc_getProximityPlayers.sqf b/addons/map_gestures/functions/fnc_getProximityPlayers.sqf index 3ac8803a70..43d78f3506 100644 --- a/addons/map_gestures/functions/fnc_getProximityPlayers.sqf +++ b/addons/map_gestures/functions/fnc_getProximityPlayers.sqf @@ -19,5 +19,6 @@ params ["_unit", "_range"]; _proximityPlayers = (getPos _unit) nearEntities [["CAMAnBase"], _range]; -_proximityPlayers = _proximityPlayers - [_unit]; -(_proximityPlayers + (crew vehicle _unit)) +_proximityPlayers deleteAt (_proximityPlayers find _unit); +_proximityPlayers append (crew vehicle _unit) +_proximityPlayers diff --git a/addons/map_gestures/functions/fnc_moduleGroupSettings.sqf b/addons/map_gestures/functions/fnc_moduleGroupSettings.sqf index 32f7e73143..013f076347 100644 --- a/addons/map_gestures/functions/fnc_moduleGroupSettings.sqf +++ b/addons/map_gestures/functions/fnc_moduleGroupSettings.sqf @@ -19,22 +19,24 @@ params ["_logic", "_units", "_activated"]; -diag_log "Running"; - -if (!_activated) exitWith {}; -if (!isServer) exitWith {}; +if (!_activated || !isServer) exitWith {}; +// Transcode string setting into usable array. Example: "1,1,1,1" -> [1, 1, 1, 1] _leadColor = call compile ("[" + (_logic getVariable ["leadColor", ""]) + "]"); if (!([_leadColor] call FUNC(isValidColorArray))) exitWith {ERROR("leadColor is not a valid color array.")}; _color = call compile ("[" + (_logic getVariable ["color", ""]) + "]"); if (!([_color] call FUNC(isValidColorArray))) exitWith {ERROR("color is not a valid color array.")}; +// If we already have color configurations from another source, use those, otherwise use default. _configurations = if (isNil QGVAR(GroupColorConfigurations)) then { [] } else { +GVAR(GroupColorConfigurations) }; _configurationGroups = if (isNil QGVAR(GroupColorConfigurationsGroups)) then { [] } else { +GVAR(GroupColorConfigurationsGroups) }; _configurationGroupsIndex = if (isNil QGVAR(GroupColorConfigurationsGroupIndex)) then { [] } else { +GVAR(GroupColorConfigurationsGroupIndex) }; -_completedGroups = []; +// Save custom color configuration and keep the index of the entry. _configurationIndex = _configurations pushBack [_leadColor, _color]; + +// Add all synchronized groups and reference custom configuration for them +_completedGroups = []; { private "_group"; _group = groupID (group _x); diff --git a/addons/map_gestures/functions/fnc_receiverInit.sqf b/addons/map_gestures/functions/fnc_receiverInit.sqf index 719e5a727b..a14efbffc1 100644 --- a/addons/map_gestures/functions/fnc_receiverInit.sqf +++ b/addons/map_gestures/functions/fnc_receiverInit.sqf @@ -15,14 +15,6 @@ */ #include "script_component.hpp" -{ - if (isPlayer _x) then { - _nameSane = [name _x] call FUNC(sanitizeName); - missionNamespace setVariable [format [QGVAR(%1_DrawPos), _nameSane], [1, 1, 1]]; - }; - nil -} count allUnits; - ACE_player setVariable [QGVAR(Transmit), false, true]; GVAR(EnableTransmit) = false; diff --git a/addons/map_gestures/functions/fnc_sanitizeName.sqf b/addons/map_gestures/functions/fnc_sanitizeName.sqf deleted file mode 100644 index f36e626102..0000000000 --- a/addons/map_gestures/functions/fnc_sanitizeName.sqf +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Author: Dslyecxi, MikeMatrix - * Cleans up unit names to be usable within variable names. - * - * Arguments: - * 0: Name - * - * Return Value: - * Sanitized name - * - * Example: - * ["I am a non valid variable name"] call ace_map_gestures_fnc_sanitizeName - * - * Public: No - */ -#include "script_component.hpp" - -private ["_alphabet", "_nameSanitized"]; - -params ["_name"]; - -_alphabet = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]; - -_nameSanitized = []; -{ - if (toString [_x] in _alphabet) then {_nameSanitized pushBack _x}; - nil -} count (toArray _name); - -toString _nameSanitized diff --git a/addons/map_gestures/functions/fnc_transmit.sqf b/addons/map_gestures/functions/fnc_transmit.sqf index 4d99caa160..56adbe4266 100644 --- a/addons/map_gestures/functions/fnc_transmit.sqf +++ b/addons/map_gestures/functions/fnc_transmit.sqf @@ -16,26 +16,30 @@ */ #include "script_component.hpp" -private ["_proximityPlayers", "_ownerID", "_nameSane"]; +private ["_proximityPlayers", "_ownerID", "_unitUID", "_drawPosVariableName"]; params ["", "_pfhId"]; -if (!GVAR(EnableTransmit) || !visibleMap) exitWith { +if (!visibleMap) then { call FUNC(endTransmit); +} + +if (!GVAR(EnableTransmit) || !visibleMap) exitWith { [_pfhId] call CBA_fnc_removePerFrameHandler; }; -_proximityPlayers = [ACE_player, GVAR(maxRange)] call FUNC(getProximityPlayers); -TRACE_1("Near",_proximityPlayers) - { _ownerID = _x getVariable QGVAR(owner_id); if (isNil "_ownerID") then { - [0, {[_this] call FUNC(assignClientIDOnServer)}, name _x] call cba_fnc_GlobalExecute; + [MAP_GESTURES_NO_OWNER_ID_EVENT, [name _x]] call EFUNC(common,serverEvent); } else { - if (_ownerID != ACE_player getVariable QGVAR(owner_id)) then { - _nameSane = [name ACE_player] call FUNC(sanitizeName); - _ownerID publicVariableClient format [QGVAR(%1_DrawPos), _nameSane]; + _playerOwnerID = ACE_player getVariable QGVAR(owner_id); + if (!isNil "_playerOwnerID" && _ownerID != _playerOwnerID) then { + _unitUID = getPlayerUID ACE_Player; + _drawPosVariableName = if (!isNil "_unitUID" && _unitUID != "") then {format [QGVAR(%1_DrawPos), _unitUID]} else {nil}; + if (!isNil "_drawPosVariableName") then { + _ownerID publicVariableClient _drawPosVariableName; + }; }; }; -} count _proximityPlayers; +} count ([ACE_player, GVAR(maxRange)] call FUNC(getProximityPlayers)); diff --git a/addons/map_gestures/functions/fnc_transmitterInit.sqf b/addons/map_gestures/functions/fnc_transmitterInit.sqf index 828261e017..251e6d2619 100644 --- a/addons/map_gestures/functions/fnc_transmitterInit.sqf +++ b/addons/map_gestures/functions/fnc_transmitterInit.sqf @@ -15,7 +15,7 @@ */ #include "script_component.hpp" -private ["_mapCtrl", "_nameSane"]; +private ["_mapCtrl", "_unitUID", "_drawPosVariableName"]; disableSerialization; @@ -24,19 +24,19 @@ _mapCtrl = findDisplay 12 displayCtrl 51; // MouseMoving EH. if (!isNil QGVAR(MouseMoveHandlerID)) then {_mapCtrl ctrlRemoveEventHandler ["MouseMoving", GVAR(MouseMoveHandlerID)]; GVAR(MouseMoveHandlerID) = nil;}; GVAR(MouseMoveHandlerID) = _mapCtrl ctrlAddEventHandler ["MouseMoving", { - if (EGVAR(maptools,drawing_isDrawing)) exitWith {}; - if (EGVAR(maptools,mapTool_isDragging)) exitWith {}; - if (EGVAR(maptools,mapTool_isRotating)) exitWith {}; + // Don't transmit any data if we're using the map tools + if (!GVAR(EnableTransmit) || EGVAR(maptools,drawing_isDrawing) || EGVAR(maptools,mapTool_isDragging) || EGVAR(maptools,mapTool_isRotating)) exitWith {}; params ["_control", "_posX", "_posY"]; - if (GVAR(EnableTransmit)) then { - if (!(ACE_player getVariable QGVAR(Transmit))) then { - ACE_player setVariable [QGVAR(Transmit), true, true]; - }; + if (!(ACE_player getVariable QGVAR(Transmit))) then { + ACE_player setVariable [QGVAR(Transmit), true, true]; + }; - _nameSane = [name ACE_player] call FUNC(sanitizeName); - missionNamespace setVariable [format [QGVAR(%1_DrawPos), _nameSane], _control ctrlMapScreenToWorld [_posX, _posY]]; + _unitUID = getPlayerUID ACE_player; + _drawPosVariableName = if (!isNil "_unitUID" && _unitUID != "") then {format [QGVAR(%1_DrawPos), _unitUID]} else {nil}; + if (!isNil "_drawPosVariableName") then { + missionNamespace setVariable [_drawPosVariableName, _control ctrlMapScreenToWorld [_posX, _posY]]; }; }]; @@ -53,6 +53,8 @@ GVAR(MouseDownHandlerID) = _mapCtrl ctrlAddEventHandler ["MouseButtonDown", { // MouseUp EH if (!isNil QGVAR(MouseUpHandlerID)) then {_mapCtrl ctrlRemoveEventHandler ["MouseButtonUp", GVAR(MouseUpHandlerID)]; GVAR(MouseUpHandlerID) = nil;}; GVAR(MouseUpHandlerID) = _mapCtrl ctrlAddEventHandler ["MouseButtonUp", { + if (!GVAR(enabled)) exitWith {}; + params ["", "_button"]; if (_button == 0) then {call FUNC(endTransmit);}; diff --git a/addons/map_gestures/script_component.hpp b/addons/map_gestures/script_component.hpp index 7c6f3a5b2f..50f155ccc1 100644 --- a/addons/map_gestures/script_component.hpp +++ b/addons/map_gestures/script_component.hpp @@ -10,3 +10,5 @@ #endif #include "\z\ace\addons\main\script_macros.hpp" + +#define MAP_GESTURES_NO_OWNER_ID_EVENT "PlayerNameHasNoOwnerID"