Various code cleanups and switch to player UIDs instead of sanitized names

This commit is contained in:
Michael Braun 2015-08-24 17:03:47 +02:00
parent 3646654ff3
commit 7217d5ec10
12 changed files with 67 additions and 78 deletions

View File

@ -7,5 +7,6 @@ class Extended_PreInit_EventHandlers {
class Extended_PostInit_EventHandlers { class Extended_PostInit_EventHandlers {
class ADDON { class ADDON {
init = QUOTE(call COMPILE_FILE(XEH_postInit)); init = QUOTE(call COMPILE_FILE(XEH_postInit));
serverInit = QUOTE(call COMPILE_FILE(XEH_serverPostInit));
}; };
}; };

View File

@ -11,7 +11,6 @@ PREP(isValidColorArray);
PREP(moduleGroupSettings); PREP(moduleGroupSettings);
PREP(moduleSettings); PREP(moduleSettings);
PREP(receiverInit); PREP(receiverInit);
PREP(sanitizeName);
PREP(transmit); PREP(transmit);
PREP(transmitterInit); PREP(transmitterInit);

View File

@ -0,0 +1,3 @@
#include "script_component.hpp"
[MAP_GESTURES_NO_OWNER_ID_EVENT, FUNC(assignClientIDOnServer)] call EFUNC(common,addEventHandler)

View File

@ -18,7 +18,7 @@
params ["_unitName"]; params ["_unitName"];
{ {
if (name _x == _unitName) then { if (name _x == _unitName) exitWith {
_x setVariable [QGVAR(owner_id), owner _x, true]; _x setVariable [QGVAR(owner_id), owner _x, true];
}; };
} count playableUnits; } count playableUnits;

View File

@ -15,23 +15,35 @@
*/ */
#include "script_component.hpp" #include "script_component.hpp"
if (!GVAR(enabled)) exitWith {}; #define ICON_RENDER_SIZE 55
if (!visibleMap) exitWith {}; #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"]; 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); // Data variable name for unit
_drawPosVariableName = format [QGVAR(%1_DrawPos), _nameSane]; _unitUID = getPlayerUID _x;
if (!isNil _drawPosVariableName) then { _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]];}; if (isNil {missionNamespace getVariable _drawPosVariableName}) then {missionNamespace setVariable [_drawPosVariableName, [1, 1, 1]];};
_pos = missionNamespace getVariable _drawPosVariableName; _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; _group = group _x;
_grpName = groupID _group; _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 { _color = if (_grpName in GVAR(GroupColorConfigurationsGroups)) then {
_grpNameIndex = GVAR(GroupColorConfigurationsGroups) find _grpName; _grpNameIndex = GVAR(GroupColorConfigurationsGroups) find _grpName;
(GVAR(GroupColorConfigurations) select (GVAR(GroupColorConfigurationsGroupIndex) select _grpNameIndex)) select (_x != leader _group) (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)}; 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"]; // Render icon and player name
_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"]; _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 nil
} count _proximityPlayers; } count ([ACE_player, GVAR(maxRange)] call FUNC(getProximityPlayers));

View File

@ -19,5 +19,6 @@
params ["_unit", "_range"]; params ["_unit", "_range"];
_proximityPlayers = (getPos _unit) nearEntities [["CAMAnBase"], _range]; _proximityPlayers = (getPos _unit) nearEntities [["CAMAnBase"], _range];
_proximityPlayers = _proximityPlayers - [_unit]; _proximityPlayers deleteAt (_proximityPlayers find _unit);
(_proximityPlayers + (crew vehicle _unit)) _proximityPlayers append (crew vehicle _unit)
_proximityPlayers

View File

@ -19,22 +19,24 @@
params ["_logic", "_units", "_activated"]; params ["_logic", "_units", "_activated"];
diag_log "Running"; if (!_activated || !isServer) exitWith {};
if (!_activated) exitWith {};
if (!isServer) exitWith {};
// Transcode string setting into usable array. Example: "1,1,1,1" -> [1, 1, 1, 1]
_leadColor = call compile ("[" + (_logic getVariable ["leadColor", ""]) + "]"); _leadColor = call compile ("[" + (_logic getVariable ["leadColor", ""]) + "]");
if (!([_leadColor] call FUNC(isValidColorArray))) exitWith {ERROR("leadColor is not a valid color array.")}; if (!([_leadColor] call FUNC(isValidColorArray))) exitWith {ERROR("leadColor is not a valid color array.")};
_color = call compile ("[" + (_logic getVariable ["color", ""]) + "]"); _color = call compile ("[" + (_logic getVariable ["color", ""]) + "]");
if (!([_color] call FUNC(isValidColorArray))) exitWith {ERROR("color is not a valid color array.")}; 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) }; _configurations = if (isNil QGVAR(GroupColorConfigurations)) then { [] } else { +GVAR(GroupColorConfigurations) };
_configurationGroups = if (isNil QGVAR(GroupColorConfigurationsGroups)) then { [] } else { +GVAR(GroupColorConfigurationsGroups) }; _configurationGroups = if (isNil QGVAR(GroupColorConfigurationsGroups)) then { [] } else { +GVAR(GroupColorConfigurationsGroups) };
_configurationGroupsIndex = if (isNil QGVAR(GroupColorConfigurationsGroupIndex)) then { [] } else { +GVAR(GroupColorConfigurationsGroupIndex) }; _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]; _configurationIndex = _configurations pushBack [_leadColor, _color];
// Add all synchronized groups and reference custom configuration for them
_completedGroups = [];
{ {
private "_group"; private "_group";
_group = groupID (group _x); _group = groupID (group _x);

View File

@ -15,14 +15,6 @@
*/ */
#include "script_component.hpp" #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]; ACE_player setVariable [QGVAR(Transmit), false, true];
GVAR(EnableTransmit) = false; GVAR(EnableTransmit) = false;

View File

@ -1,30 +0,0 @@
/*
* Author: Dslyecxi, MikeMatrix
* Cleans up unit names to be usable within variable names.
*
* Arguments:
* 0: Name <STRING>
*
* Return Value:
* Sanitized name <STRING>
*
* 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

View File

@ -16,26 +16,30 @@
*/ */
#include "script_component.hpp" #include "script_component.hpp"
private ["_proximityPlayers", "_ownerID", "_nameSane"]; private ["_proximityPlayers", "_ownerID", "_unitUID", "_drawPosVariableName"];
params ["", "_pfhId"]; params ["", "_pfhId"];
if (!GVAR(EnableTransmit) || !visibleMap) exitWith { if (!visibleMap) then {
call FUNC(endTransmit); call FUNC(endTransmit);
}
if (!GVAR(EnableTransmit) || !visibleMap) exitWith {
[_pfhId] call CBA_fnc_removePerFrameHandler; [_pfhId] call CBA_fnc_removePerFrameHandler;
}; };
_proximityPlayers = [ACE_player, GVAR(maxRange)] call FUNC(getProximityPlayers);
TRACE_1("Near",_proximityPlayers)
{ {
_ownerID = _x getVariable QGVAR(owner_id); _ownerID = _x getVariable QGVAR(owner_id);
if (isNil "_ownerID") then { 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 { } else {
if (_ownerID != ACE_player getVariable QGVAR(owner_id)) then { _playerOwnerID = ACE_player getVariable QGVAR(owner_id);
_nameSane = [name ACE_player] call FUNC(sanitizeName); if (!isNil "_playerOwnerID" && _ownerID != _playerOwnerID) then {
_ownerID publicVariableClient format [QGVAR(%1_DrawPos), _nameSane]; _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));

View File

@ -15,7 +15,7 @@
*/ */
#include "script_component.hpp" #include "script_component.hpp"
private ["_mapCtrl", "_nameSane"]; private ["_mapCtrl", "_unitUID", "_drawPosVariableName"];
disableSerialization; disableSerialization;
@ -24,19 +24,19 @@ _mapCtrl = findDisplay 12 displayCtrl 51;
// MouseMoving EH. // MouseMoving EH.
if (!isNil QGVAR(MouseMoveHandlerID)) then {_mapCtrl ctrlRemoveEventHandler ["MouseMoving", GVAR(MouseMoveHandlerID)]; GVAR(MouseMoveHandlerID) = nil;}; if (!isNil QGVAR(MouseMoveHandlerID)) then {_mapCtrl ctrlRemoveEventHandler ["MouseMoving", GVAR(MouseMoveHandlerID)]; GVAR(MouseMoveHandlerID) = nil;};
GVAR(MouseMoveHandlerID) = _mapCtrl ctrlAddEventHandler ["MouseMoving", { GVAR(MouseMoveHandlerID) = _mapCtrl ctrlAddEventHandler ["MouseMoving", {
if (EGVAR(maptools,drawing_isDrawing)) exitWith {}; // Don't transmit any data if we're using the map tools
if (EGVAR(maptools,mapTool_isDragging)) exitWith {}; if (!GVAR(EnableTransmit) || EGVAR(maptools,drawing_isDrawing) || EGVAR(maptools,mapTool_isDragging) || EGVAR(maptools,mapTool_isRotating)) exitWith {};
if (EGVAR(maptools,mapTool_isRotating)) exitWith {};
params ["_control", "_posX", "_posY"]; params ["_control", "_posX", "_posY"];
if (GVAR(EnableTransmit)) then {
if (!(ACE_player getVariable QGVAR(Transmit))) then { if (!(ACE_player getVariable QGVAR(Transmit))) then {
ACE_player setVariable [QGVAR(Transmit), true, true]; ACE_player setVariable [QGVAR(Transmit), true, true];
}; };
_nameSane = [name ACE_player] call FUNC(sanitizeName); _unitUID = getPlayerUID ACE_player;
missionNamespace setVariable [format [QGVAR(%1_DrawPos), _nameSane], _control ctrlMapScreenToWorld [_posX, _posY]]; _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 // MouseUp EH
if (!isNil QGVAR(MouseUpHandlerID)) then {_mapCtrl ctrlRemoveEventHandler ["MouseButtonUp", GVAR(MouseUpHandlerID)]; GVAR(MouseUpHandlerID) = nil;}; if (!isNil QGVAR(MouseUpHandlerID)) then {_mapCtrl ctrlRemoveEventHandler ["MouseButtonUp", GVAR(MouseUpHandlerID)]; GVAR(MouseUpHandlerID) = nil;};
GVAR(MouseUpHandlerID) = _mapCtrl ctrlAddEventHandler ["MouseButtonUp", { GVAR(MouseUpHandlerID) = _mapCtrl ctrlAddEventHandler ["MouseButtonUp", {
if (!GVAR(enabled)) exitWith {};
params ["", "_button"]; params ["", "_button"];
if (_button == 0) then {call FUNC(endTransmit);}; if (_button == 0) then {call FUNC(endTransmit);};

View File

@ -10,3 +10,5 @@
#endif #endif
#include "\z\ace\addons\main\script_macros.hpp" #include "\z\ace\addons\main\script_macros.hpp"
#define MAP_GESTURES_NO_OWNER_ID_EVENT "PlayerNameHasNoOwnerID"