diff --git a/addons/common/XEH_PREP.hpp b/addons/common/XEH_PREP.hpp index 44e6010b4e..3f6f264699 100644 --- a/addons/common/XEH_PREP.hpp +++ b/addons/common/XEH_PREP.hpp @@ -141,6 +141,7 @@ PREP(setHearingCapability); PREP(setName); PREP(setParameter); PREP(setPitchBankYaw); +PREP(setPlayerOwner); PREP(setProne); PREP(setSetting); PREP(setSettingFromConfig); diff --git a/addons/common/functions/fnc_setPlayerOwner.sqf b/addons/common/functions/fnc_setPlayerOwner.sqf new file mode 100644 index 0000000000..5b21db0190 --- /dev/null +++ b/addons/common/functions/fnc_setPlayerOwner.sqf @@ -0,0 +1,54 @@ +/* + * Author: PabstMirror + * Sets the player's owner id as a variable on his player ojbect. + * Should be called on all machines (including server) + * Note: Needs to wait for CBA_clientID to be recieved from server. + * + * Arguments: + * None + * + * Return Value: + * None + * + * Example: + * [] call ace_common_fnc_setPlayerOwner + * + * Public: No + */ + +// #define DEBUG_MODE_FULL +#include "script_component.hpp" + +if (missionNameSpace getVariable [QGVAR(setPlayerOwnerRunning), false]) exitWith {}; +GVAR(setPlayerOwnerRunning) = true; + +if (isServer) then { + addMissionEventHandler ["HandleDisconnect", { + params ["_dcPlayer"]; + TRACE_1("HandleDisconnect eh",_dcPlayer); + if (!isNil {_dcPlayer getVariable QGVAR(playerOwner)}) then { + _dcPlayer setVariable [QGVAR(playerOwner), nil, true]; + }; + }]; +}; + +if (hasInterface) then { + [{ + (!isNil "CBA_clientID") && {CBA_clientID > -1} + }, { + TRACE_1("CBA_clientID ready",CBA_clientID); + + ["unit", { + params ["_newUnit", "_oldUnit"]; + TRACE_2("unit changed",_newUnit,_oldUnit); + if ((_oldUnit getVariable [QGVAR(playerOwner), -1]) == CBA_clientID) then { + _oldUnit setVariable [QGVAR(playerOwner), nil, true]; + }; + if (alive _newUnit) then { + _newUnit setVariable [QGVAR(playerOwner), CBA_clientID, true]; + }; + }, true] call CBA_fnc_addPlayerEventHandler; + + }, []] call CBA_fnc_waitUntilAndExecute; +}; + diff --git a/addons/map_gestures/ACE_Settings.hpp b/addons/map_gestures/ACE_Settings.hpp index 3730c08c58..bb01592230 100644 --- a/addons/map_gestures/ACE_Settings.hpp +++ b/addons/map_gestures/ACE_Settings.hpp @@ -44,18 +44,4 @@ class ACE_Settings { typeName = "COLOR"; value[] = {1, 0.88, 0, 0.7}; }; - class GVAR(groupColorConfigurations) { - displayName = CSTRING(groupColorConfigurations_displayName); - description = CSTRING(groupColorConfigurations_description); - category = CSTRING(mapGestures_category); - typeName = "ARRAY"; - value[] = {}; - }; - class GVAR(groupColorConfigurationMapping) { - displayName = CSTRING(groupColorConfigurationMapping_displayName); - description = CSTRING(groupColorConfigurationMapping_description); - category = CSTRING(mapGestures_category); - typeName = "ARRAY"; - value[] = {{}, {}}; - }; }; diff --git a/addons/map_gestures/CfgEventHandlers.hpp b/addons/map_gestures/CfgEventHandlers.hpp index b0848d0248..becf395052 100644 --- a/addons/map_gestures/CfgEventHandlers.hpp +++ b/addons/map_gestures/CfgEventHandlers.hpp @@ -14,6 +14,5 @@ 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/CfgVehicles.hpp b/addons/map_gestures/CfgVehicles.hpp index 5593d66181..0745c70a16 100644 --- a/addons/map_gestures/CfgVehicles.hpp +++ b/addons/map_gestures/CfgVehicles.hpp @@ -47,7 +47,7 @@ class CfgVehicles { category = "ACE"; displayName = CSTRING(moduleGroupSettings_displayName); function = QFUNC(moduleGroupSettings); - isGlobal = 0; + isGlobal = 2; author = ECSTRING(common,ACETeam); icon = QPATHTOF(ui\icon_module_map_gestures_ca.paa); class Arguments { diff --git a/addons/map_gestures/XEH_PREP.hpp b/addons/map_gestures/XEH_PREP.hpp index eba9f5bfe8..8d457bd7e0 100644 --- a/addons/map_gestures/XEH_PREP.hpp +++ b/addons/map_gestures/XEH_PREP.hpp @@ -1,5 +1,5 @@ -PREP(assignClientIDOnServer); +PREP(addGroupColorMapping); PREP(drawMapGestures); PREP(endTransmit); PREP(getProximityPlayers); diff --git a/addons/map_gestures/XEH_postInit.sqf b/addons/map_gestures/XEH_postInit.sqf index 3d93337aa6..cc3daf6a06 100644 --- a/addons/map_gestures/XEH_postInit.sqf +++ b/addons/map_gestures/XEH_postInit.sqf @@ -8,6 +8,17 @@ if (!hasInterface) exitWith {}; ["ace_settingsInitialized", { if (!GVAR(enabled)) exitWith {}; + + // This will set QEGVAR(common,playerOwner) var on player objects + [] call EFUNC(common,setPlayerOwner); + + GVAR(pointPosition) = [0,0,0]; + + [QGVAR(syncPos), { + params ["_unit", "_pointPos"]; + _unit setVariable [QGVAR(pointPosition), _pointPos]; + }] call CBA_fnc_addEventHandler; + [{ if (isNull (findDisplay 12)) exitWith {}; diff --git a/addons/map_gestures/XEH_preInit.sqf b/addons/map_gestures/XEH_preInit.sqf index a7feade1c3..198d66e02d 100644 --- a/addons/map_gestures/XEH_preInit.sqf +++ b/addons/map_gestures/XEH_preInit.sqf @@ -4,4 +4,6 @@ ADDON = false; #include "XEH_PREP.hpp" +GVAR(GroupColorCfgMappingNew) = call CBA_fnc_createNamespace; + ADDON = true; diff --git a/addons/map_gestures/XEH_serverPostInit.sqf b/addons/map_gestures/XEH_serverPostInit.sqf deleted file mode 100644 index 1b70e24149..0000000000 --- a/addons/map_gestures/XEH_serverPostInit.sqf +++ /dev/null @@ -1,3 +0,0 @@ -#include "script_component.hpp" - -[QGVAR(noOwnerID), FUNC(assignClientIDOnServer)] call CBA_fnc_addEventHandler; diff --git a/addons/map_gestures/functions/fnc_addGroupColorMapping.sqf b/addons/map_gestures/functions/fnc_addGroupColorMapping.sqf new file mode 100644 index 0000000000..949aa60da1 --- /dev/null +++ b/addons/map_gestures/functions/fnc_addGroupColorMapping.sqf @@ -0,0 +1,30 @@ +/* + * Author: Dslyecxi, MikeMatrix, PabstMirror + * Adds a group id color mapping. + * + * Arguments: + * 0: Group ID or group + * 1: Leader color array (4 numbers including alpha) + * 2: Unit (non-leader) color array (4 numbers including alpha) + * + * Return Value: + * None + * + * Example: + * ["Alpha 1-1", [1,0,0,1], [0,1,0,1]] call ace_map_gestures_fnc_addGroupColorMapping + * + * Public: Yes + */ +#include "script_component.hpp" + +if (!params [["_group", "", [grpNull, ""]], ["_leadColor", [1,1,1,1], [[]], 4], ["_unitColor", [1,1,1,1], [[]], 4]]) exitWith { + ERROR_1("Bad Params: %1",_this); +}; +TRACE_3("params",_group,_leadColor,_unitColor); + +if (_group isEqualType grpNull) then {_group = groupID _group}; + +if (!([_leadColor] call FUNC(isValidColorArray))) exitWith {ERROR("leadColor is not a valid color array.")}; +if (!([_unitColor] call FUNC(isValidColorArray))) exitWith {ERROR("color is not a valid color array.")}; + +GVAR(GroupColorCfgMappingNew) setVariable [_group, [_leadColor, _unitColor]]; diff --git a/addons/map_gestures/functions/fnc_assignClientIDOnServer.sqf b/addons/map_gestures/functions/fnc_assignClientIDOnServer.sqf deleted file mode 100644 index 92b1e95ab5..0000000000 --- a/addons/map_gestures/functions/fnc_assignClientIDOnServer.sqf +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Author: Dslyecxi, MikeMatrix - * Assign readable client ID to unit on the server. - * - * Arguments: - * 0: Unit name - * - * Return Value: - * None - * - * Example: - * ["MikeMatrix"] call ace_map_gestures_fnc_assignClientIDOnServer - * - * Public: No - */ -#include "script_component.hpp" - -params ["_unitName"]; - -{ - 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 728126531e..237d0537f5 100644 --- a/addons/map_gestures/functions/fnc_drawMapGestures.sqf +++ b/addons/map_gestures/functions/fnc_drawMapGestures.sqf @@ -15,6 +15,8 @@ */ #include "script_component.hpp" +BEGIN_COUNTER(draw); + #define ICON_RENDER_SIZE 55 #define ICON_TEXT_ALIGN "left" #define ICON_ANGLE 0 @@ -26,36 +28,34 @@ if (!GVAR(enabled) || !visibleMap) exitWith {}; -private ["_color", "_drawPosVariableName", "_group", "_grpName", "_pos", "_unitUID"]; - params ["_mapHandle"]; // Iterate over all nearby players and render their pointer if player is transmitting. { - // 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; + // Only render if the unit is alive and transmitting + if (alive _x && {_x getVariable [QGVAR(Transmit), false]}) then { - // Only render if the unit is alive and transmitting - if (alive _x && {_x getVariable QGVAR(Transmit)}) then { - _group = group _x; - _grpName = groupID _group; + private _pos = _x getVariable [QGVAR(pointPosition), [0,0,0]]; - // If color settings for the group exist, then use those, otherwise fall back to the default colors - _color = if ([GVAR(GroupColorConfigurationMapping), _grpName] call CBA_fnc_hashHasKey) then { - (GVAR(GroupColorConfigurations) select ([GVAR(GroupColorConfigurationMapping), _grpName] call CBA_fnc_hashGet)) select (_x != leader _group) - } else { - if (_x == leader _group) then {GVAR(defaultLeadColor)} else {GVAR(defaultColor)}; - }; + private _group = group _x; + private _grpName = groupID _group; - // 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)", GVAR(nameTextColor), _pos, TEXT_ICON_RENDER_SIZE, TEXT_ICON_RENDER_SIZE, ICON_ANGLE, name _x, TEXT_SHADOW, TEXT_SIZE, TEXT_FONT, ICON_TEXT_ALIGN]; + // If color settings for the group exist, then use those, otherwise fall back to the default colors + private _colorMap = GVAR(GroupColorCfgMappingNew) getVariable _grpName; + private _color = if (isNil "_colorMap") then { + [GVAR(defaultLeadColor), GVAR(defaultColor)] select (_x != leader _group); + } else { + _colorMap select (_x != leader _group); }; + + TRACE_2("",_colorMap,_color); + + // 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)", GVAR(nameTextColor), _pos, TEXT_ICON_RENDER_SIZE, TEXT_ICON_RENDER_SIZE, ICON_ANGLE, name _x, TEXT_SHADOW, TEXT_SIZE, TEXT_FONT, ICON_TEXT_ALIGN]; }; nil } count ([ACE_player, GVAR(maxRange)] call FUNC(getProximityPlayers)); + +END_COUNTER(draw); diff --git a/addons/map_gestures/functions/fnc_getProximityPlayers.sqf b/addons/map_gestures/functions/fnc_getProximityPlayers.sqf index e4ec44837b..ea058f0f7e 100644 --- a/addons/map_gestures/functions/fnc_getProximityPlayers.sqf +++ b/addons/map_gestures/functions/fnc_getProximityPlayers.sqf @@ -10,7 +10,7 @@ * All units in proximity * * Example: - * ["example value"] call ace_module_fnc_functionName + * [player, 7] call ace_map_gestures_fnc_getProximityPlayers * * Public: No */ @@ -21,4 +21,5 @@ params ["_unit", "_range"]; private _proximityPlayers = (getPos _unit) nearEntities [["CAMAnBase"], _range]; _proximityPlayers deleteAt (_proximityPlayers find _unit); _proximityPlayers append (crew vehicle _unit); -_proximityPlayers + +_proximityPlayers select {[_x, false] call EFUNC(common,isPlayer);} diff --git a/addons/map_gestures/functions/fnc_moduleGroupSettings.sqf b/addons/map_gestures/functions/fnc_moduleGroupSettings.sqf index 52ae6d0a49..8f44cf5732 100644 --- a/addons/map_gestures/functions/fnc_moduleGroupSettings.sqf +++ b/addons/map_gestures/functions/fnc_moduleGroupSettings.sqf @@ -17,29 +17,18 @@ */ #include "script_component.hpp" -private ["_color", "_configurationGroupMappings", "_configurationIndex", "_configurations", "_leadColor"]; - params ["_logic", "_units", "_activated"]; +TRACE_3("params",_logic,_units,_activated); -if (!_activated || !isServer) exitWith {}; +if (!_activated) exitWith {}; // Transcode string setting into usable array. Example: "1,1,1,1" -> [1, 1, 1, 1] -_leadColor = call compile ("[" + (_logic getVariable ["leadColor", ""]) + "]"); +private _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", ""]) + "]"); +private _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) }; -_configurationGroupMappings = if(isNil QGVAR(GroupColorConfigurationMapping)) then { [] call CBA_fnc_hashCreate } else { +GVAR(GroupColorConfigurationMapping) }; - -// 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 { - [_configurationGroupMappings, groupID group _x, _configurationIndex] call CBA_fnc_hashSet; + [group _x, _leadColor, _color] call FUNC(addGroupColorMapping); } forEach _units; - -[QGVAR(GroupColorConfigurations), _configurations, false, true] call EFUNC(common,setSetting); -[QGVAR(GroupColorConfigurationMapping), _configurationGroupMappings, false, true] call EFUNC(common,setSetting); diff --git a/addons/map_gestures/functions/fnc_transmit.sqf b/addons/map_gestures/functions/fnc_transmit.sqf index aacff9e679..166b1cb375 100644 --- a/addons/map_gestures/functions/fnc_transmit.sqf +++ b/addons/map_gestures/functions/fnc_transmit.sqf @@ -16,7 +16,7 @@ */ #include "script_component.hpp" -private ["_ownerID", "_unitUID", "_drawPosVariableName", "_playerOwnerID"]; +BEGIN_COUNTER(transmit); params ["", "_pfhId"]; @@ -29,17 +29,14 @@ if (!GVAR(EnableTransmit) || !visibleMap) exitWith { }; { - _ownerID = _x getVariable QGVAR(owner_id); - if (isNil "_ownerID") then { - [QGVAR(noOwnerID), [name _x]] call CBA_fnc_serverEvent; - } else { - _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; - }; + private _owner = _x getVariable [QEGVAR(common,playerOwner), -1]; + if (_owner > -1) then { + private _remotePos = _x getVariable [QGVAR(remotePos), [0,0,0]]; + if ((_remotePos distance2d GVAR(pointPosition)) > 1) then { // Only transmit when actually moving + [QGVAR(syncPos), [ACE_Player, GVAR(pointPosition)], _owner] call CBA_fnc_ownerEvent; + _x setVariable [QGVAR(remotePos), GVAR(pointPosition)]; }; }; } count ([ACE_player, GVAR(maxRange)] call FUNC(getProximityPlayers)); + +END_COUNTER(transmit); diff --git a/addons/map_gestures/functions/fnc_transmitterInit.sqf b/addons/map_gestures/functions/fnc_transmitterInit.sqf index d115fb22c5..a75ebb6e34 100644 --- a/addons/map_gestures/functions/fnc_transmitterInit.sqf +++ b/addons/map_gestures/functions/fnc_transmitterInit.sqf @@ -15,11 +15,9 @@ */ #include "script_component.hpp" -private ["_mapCtrl", "_unitUID", "_drawPosVariableName"]; - disableSerialization; -_mapCtrl = findDisplay 12 displayCtrl 51; +private _mapCtrl = findDisplay 12 displayCtrl 51; // MouseMoving EH. if (!isNil QGVAR(MouseMoveHandlerID)) then { @@ -36,11 +34,7 @@ GVAR(MouseMoveHandlerID) = _mapCtrl ctrlAddEventHandler ["MouseMoving", { ACE_player setVariable [QGVAR(Transmit), true, true]; }; - _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]]; - }; + GVAR(pointPosition) = _control ctrlMapScreenToWorld [_posX, _posY]; }]; // MouseDown EH diff --git a/addons/map_gestures/stringtable.xml b/addons/map_gestures/stringtable.xml index 3cc1f6b33a..0264dfdc5b 100644 --- a/addons/map_gestures/stringtable.xml +++ b/addons/map_gestures/stringtable.xml @@ -177,51 +177,6 @@ Temps entre les actualisations de données データの更新間隔 - - Group color configurations - Configurações de cores de grupo - Konf. koloru grup - Конфигурация цвета групп - Konfigurace barvy pro skupinu - Configurazioni colori dei gruppi - Konfiguration der Gruppenfarbe - Configuración de color de grupo - Configuration des couleurs de groupe - グループで使う色の設定 - - - Group color configuration containing arrays of color pairs ([leadColor, color]). - Configuração de cores de grupo contendo arrays com pares de cores ([leadColor, color]). - Konfiguracja kolorów grup zawierająca tablice par kolorów ([kolorLidera, kolor]). - Конфигурация цвета групп содержит массив цветовых пар ([лид. цвет, цвет]). - Configurazioni colori gruppi contenenti array di coppie di colori ([leadColor, color]). - Konfiguration der Gruppenfarbe mit zugeordneten Farbpaaren der Aufstellung ([leadColor, color]). - Configuración de color de grupo conteniendo una lista de pares de colores ([colorLider, colo]). - Configuration des couleurs de groupe contenant des tableaux de paires de couleurs ([couleurDeCommandement, couleur]). - アライに格納された組によりグループの色を設定します。([leadColor, color]) - - - Hash of Group ID mapped to the Group color configuration index. - Hashes de ID de grupos mapeados para o índice de configuração de cor de grupos. - Hasz ID grup zmapowanych w indeksie konfiguracji koloru grup. - Хеш ID групп, соответствующих индексам конфигурации цвета групп. - Hash degli ID Gruppi mappati nell'indice configurazioni colori gruppi. - Hashwert der Gruppen-ID, die dem Konfigurations-Index der Gruppenfarbe zugeordnet werden. - ID de Grupo mapeado al índice de la configuración de color de grupo. - Hash de l'identifiant du groupe mappé à l'index de la configuration de la couleur du groupe. - グループ ID のハッシュはグループの色を設定するインデックスへマッピングされます。 - - - GroupID Color configuration mapping - Mapeamento de configuração para cores de GroupID - Mapowanie kolorów poprzez GroupID - Соответствие ID групп конфигурации цвета групп - Mappatura configurazioni colori GroupID - Gruppen-ID-Farbe Konfigurationszuordnung - Mapeado de ID de Grupo - Configuration du mappage de l'identifiant de la couleur du groupe. - GroupID の色への設定をマッピング - Enables the Map Gestures. Ativa os gestos no mapa @@ -270,4 +225,4 @@ マップ ジェスチャ - \ No newline at end of file +