Cleanup map gesture sync / color mapping (#4486)

* Cleanup map gesture sync / color mapping

- Adds ace_common_fnc_setPlayerOwner which syncs player's owner var
- Redo publicVarClient with CBA's ownerEvent
- Remove old ace_settings
- Make color module run globaly
- Ad public ace_map_gestures_fnc_addGroupColorMapping

* fix return
This commit is contained in:
PabstMirror 2016-10-27 12:54:58 -05:00 committed by Glowbal
parent d44770a27e
commit aeb0614e7e
17 changed files with 141 additions and 149 deletions

View File

@ -141,6 +141,7 @@ PREP(setHearingCapability);
PREP(setName);
PREP(setParameter);
PREP(setPitchBankYaw);
PREP(setPlayerOwner);
PREP(setProne);
PREP(setSetting);
PREP(setSettingFromConfig);

View File

@ -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;
};

View File

@ -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[] = {{}, {}};
};
};

View File

@ -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));
};
};

View File

@ -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 {

View File

@ -1,5 +1,5 @@
PREP(assignClientIDOnServer);
PREP(addGroupColorMapping);
PREP(drawMapGestures);
PREP(endTransmit);
PREP(getProximityPlayers);

View File

@ -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 {};

View File

@ -4,4 +4,6 @@ ADDON = false;
#include "XEH_PREP.hpp"
GVAR(GroupColorCfgMappingNew) = call CBA_fnc_createNamespace;
ADDON = true;

View File

@ -1,3 +0,0 @@
#include "script_component.hpp"
[QGVAR(noOwnerID), FUNC(assignClientIDOnServer)] call CBA_fnc_addEventHandler;

View File

@ -0,0 +1,30 @@
/*
* Author: Dslyecxi, MikeMatrix, PabstMirror
* Adds a group id color mapping.
*
* Arguments:
* 0: Group ID or group <STRING><GROUP>
* 1: Leader color array (4 numbers including alpha) <ARRAY>
* 2: Unit (non-leader) color array (4 numbers including alpha) <ARRAY>
*
* 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]];

View File

@ -1,24 +0,0 @@
/*
* Author: Dslyecxi, MikeMatrix
* Assign readable client ID to unit on the server.
*
* Arguments:
* 0: Unit name <STRING>
*
* 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;

View File

@ -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);

View File

@ -10,7 +10,7 @@
* All units in proximity <ARRAY>
*
* 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);}

View File

@ -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);

View File

@ -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);

View File

@ -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

View File

@ -177,51 +177,6 @@
<French>Temps entre les actualisations de données</French>
<Japanese>データの更新間隔</Japanese>
</Key>
<Key ID="STR_ACE_map_gestures_GroupColorConfigurations_displayName">
<English>Group color configurations</English>
<Portuguese>Configurações de cores de grupo</Portuguese>
<Polish>Konf. koloru grup</Polish>
<Russian>Конфигурация цвета групп</Russian>
<Czech>Konfigurace barvy pro skupinu</Czech>
<Italian>Configurazioni colori dei gruppi</Italian>
<German>Konfiguration der Gruppenfarbe</German>
<Spanish>Configuración de color de grupo</Spanish>
<French>Configuration des couleurs de groupe</French>
<Japanese>グループで使う色の設定</Japanese>
</Key>
<Key ID="STR_ACE_map_gestures_GroupColorConfigurations_description">
<English>Group color configuration containing arrays of color pairs ([leadColor, color]).</English>
<Portuguese>Configuração de cores de grupo contendo arrays com pares de cores ([leadColor, color]).</Portuguese>
<Polish>Konfiguracja kolorów grup zawierająca tablice par kolorów ([kolorLidera, kolor]).</Polish>
<Russian>Конфигурация цвета групп содержит массив цветовых пар ([лид. цвет, цвет]).</Russian>
<Italian>Configurazioni colori gruppi contenenti array di coppie di colori ([leadColor, color]).</Italian>
<German>Konfiguration der Gruppenfarbe mit zugeordneten Farbpaaren der Aufstellung ([leadColor, color]).</German>
<Spanish>Configuración de color de grupo conteniendo una lista de pares de colores ([colorLider, colo]).</Spanish>
<French>Configuration des couleurs de groupe contenant des tableaux de paires de couleurs ([couleurDeCommandement, couleur]).</French>
<Japanese>アライに格納された組によりグループの色を設定します。([leadColor, color])</Japanese>
</Key>
<Key ID="STR_ACE_map_gestures_GroupColorConfigurationMapping_description">
<English>Hash of Group ID mapped to the Group color configuration index.</English>
<Portuguese>Hashes de ID de grupos mapeados para o índice de configuração de cor de grupos.</Portuguese>
<Polish>Hasz ID grup zmapowanych w indeksie konfiguracji koloru grup.</Polish>
<Russian>Хеш ID групп, соответствующих индексам конфигурации цвета групп.</Russian>
<Italian>Hash degli ID Gruppi mappati nell'indice configurazioni colori gruppi.</Italian>
<German>Hashwert der Gruppen-ID, die dem Konfigurations-Index der Gruppenfarbe zugeordnet werden.</German>
<Spanish>ID de Grupo mapeado al índice de la configuración de color de grupo.</Spanish>
<French>Hash de l'identifiant du groupe mappé à l'index de la configuration de la couleur du groupe.</French>
<Japanese>グループ ID のハッシュはグループの色を設定するインデックスへマッピングされます。</Japanese>
</Key>
<Key ID="STR_ACE_map_gestures_GroupColorConfigurationMapping_displayName">
<English>GroupID Color configuration mapping</English>
<Portuguese>Mapeamento de configuração para cores de GroupID</Portuguese>
<Polish>Mapowanie kolorów poprzez GroupID</Polish>
<Russian>Соответствие ID групп конфигурации цвета групп</Russian>
<Italian>Mappatura configurazioni colori GroupID</Italian>
<German>Gruppen-ID-Farbe Konfigurationszuordnung</German>
<Spanish>Mapeado de ID de Grupo</Spanish>
<French>Configuration du mappage de l'identifiant de la couleur du groupe.</French>
<Japanese>GroupID の色への設定をマッピング</Japanese>
</Key>
<Key ID="STR_ACE_map_gestures_enabled_description">
<English>Enables the Map Gestures.</English>
<Portuguese>Ativa os gestos no mapa</Portuguese>
@ -270,4 +225,4 @@
<Japanese>マップ ジェスチャ</Japanese>
</Key>
</Package>
</Project>
</Project>