First iteration on implementing Dslyecxi's ST Map Gestures

This commit is contained in:
Michael Braun 2015-08-08 08:26:15 +02:00
parent 2b3c936e99
commit a38cdda8e3
21 changed files with 672 additions and 0 deletions

View File

@ -0,0 +1 @@
z\ace\addons\map_gestures

View File

@ -0,0 +1,50 @@
class ACE_Settings {
class GVAR(enabled) {
value = 1;
typeName = "BOOL";
displayName = CSTRING(enabled_displayName);
description = CSTRING(enabled_description);
};
class GVAR(maxRange) {
value = 7;
typeName = "SCALAR";
displayName = CSTRING(maxRange_displayName);
description = CSTRING(maxRange_description);
};
class GVAR(interval) {
value = 0.03;
typeName = "SCALAR";
displayName = CSTRING(interval_displayName);
description = CSTRING(interval_description);
};
class GVAR(defaultLeadColor) {
value[] = {1, 0.88, 0, 0.95};
typeName = "COLOR";
displayName = CSTRING(defaultLeadColor_displayName);
description = CSTRING(defaultLeadColor_description);
};
class GVAR(defaultColor) {
value[] = {1, 0.88, 0, 0.7};
typeName = "COLOR";
displayName = CSTRING(defaultColor_displayName);
description = CSTRING(defaultColor_description);
};
class GVAR(GroupColorConfigurations) {
value[] = {};
typeName = "ARRAY";
displayName = CSTRING(GroupColorConfigurations_displayName);
description = CSTRING(GroupColorConfigurations_description);
};
class GVAR(GroupColorConfigurationsGroups) {
value[] = {};
typeName = "ARRAY";
displayName = CSTRING(GroupColorConfigurationsGroups_displayName);
description = CSTRING(GroupColorConfigurationsGroups_description);
};
class GVAR(GroupColorConfigurationsGroupIndex) {
value[] = {};
typeName = "ARRAY";
displayName = CSTRING(GroupColorConfigurationsGroupIndex_displayName);
description = CSTRING(GroupColorConfigurationsGroupIndex_description);
};
};

View File

@ -0,0 +1,11 @@
class Extended_PreInit_EventHandlers {
class ADDON {
init = QUOTE(call COMPILE_FILE(XEH_preInit));
};
};
class Extended_PostInit_EventHandlers {
class ADDON {
init = QUOTE(call COMPILE_FILE(XEH_postInit));
};
};

View File

@ -0,0 +1,64 @@
class CfgVehicles {
class ACE_Module;
class GVAR(moduleSettings): ACE_Module {
scope = 2;
category = "ACE";
displayName = CSTRING(moduleSettings_displayName);
function = QFUNC(moduleSettings);
isGlobal = 0;
author = ECSTRING(common,ACETeam);
class Arguments {
class enabled {
displayName = CSTRING(enabled_DisplayName);
typeName = "BOOL";
defaultValue = 1;
};
class maxRange {
displayName = CSTRING(maxRange_displayName);
description = CSTRING(maxRange_description);
typeName = "NUMBER";
defaultValue = 4;
};
class interval {
displayName = CSTRING(interval_displayName);
description = CSTRING(interval_description);
typeName = "NUMBER";
defaultValue = 0.03;
};
class defaultLeadColor {
displayName = CSTRING(defaultLeadColor_displayName);
description = CSTRING(defaultLeadColor_description);
typeName = "STRING";
defaultValue = "0,0,0,0";
};
class defaultColor {
displayName = CSTRING(defaultColor_displayName);
description = CSTRING(defaultColor_description);
typeName = "STRING";
defaultValue = "0,0,0,0";
};
};
};
class GVAR(moduleGroupSettings): ACE_Module {
scope = 2;
category = "ACE";
displayName = CSTRING(moduleGroupSettings_displayName);
function = QFUNC(moduleGroupSettings);
isGlobal = 0;
author = ECSTRING(common,ACETeam);
class Arguments {
class leadColor {
displayName = CSTRING(leadColor_displayName);
description = CSTRING(leadColor_description);
typeName = "STRING";
defaultValue = "0,0,0,0";
};
class color {
displayName = CSTRING(color_displayName);
description = CSTRING(color_description);
typeName = "STRING";
defaultValue = "0,0,0,0";
};
};
};
};

View File

@ -0,0 +1,16 @@
#include "script_component.hpp"
if (!hasInterface) exitWith {};
["SettingsInitialized", {
[{
if (isNull (findDisplay 12)) exitWith {};
params ["", "_pfhId"];
call FUNC(receiverInit);
call FUNC(transmitterInit);
[_pfhId] call CBA_fnc_removePerFrameHandler;
}, 1, []] call CBA_fnc_addPerFrameHandler;
}] call EFUNC(common,addEventHandler);

View File

@ -0,0 +1,17 @@
#include "script_component.hpp"
ADDON = false;
PREP(assignClientIDOnServer);
PREP(drawMapGestures);
PREP(endTransmit);
PREP(getProximityPlayers);
PREP(initTransmit);
PREP(moduleGroupSettings);
PREP(moduleSettings);
PREP(receiverInit);
PREP(sanitizeName);
PREP(transmit);
PREP(transmitterInit);
ADDON = true;

View File

@ -0,0 +1,17 @@
#include "script_component.hpp"
class CfgPatches {
class ADDON {
units[] = {};
weapons[] = {};
requiredVersion = REQUIRED_VERSION;
requiredAddons[] = {"ace_common"};
author[] = {"Dslyecxi", "MikeMatrix"};
authorUrl = "https://github.com/MikeMatrix";
VERSION_CONFIG;
};
};
#include "ACE_Settings.hpp"
#include "CfgEventHandlers.hpp"
#include "CfgVehicles.hpp"

View File

@ -0,0 +1,24 @@
/*
* Author: 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) then {
_x setVariable [QGVAR(owner_id), owner _x, true];
};
} count playableUnits;

View File

@ -0,0 +1,48 @@
/*
* Author: MikeMatrix
* Receives and draws map gestures from nearby players.
*
* Arguments:
* 0: Map Handle <CONTROL>
*
* Return Value:
* None
*
* Example:
* [findDisplay 12 displayCtrl 51] call ace_map_gesutres_fnc_drawMapGestures
*
* Public: No
*/
#include "script_component.hpp"
if (!GVAR(enabled)) exitWith {};
if (!visibleMap) exitWith {};
params ["_mapHandle"];
_nearDudes = [ACE_player, GVAR(maxRange)] call FUNC(getProximityPlayers);
{
_nameSane = [name _x] call FUNC(sanitizeName);
_drawPosVariableName = format [QGVAR(%1_DrawPos), _nameSane];
if (!isNil _drawPosVariableName) then {
_pos = call compile _drawPosVariableName;
if (alive _x &&
(_pos distance [0, 0, 0]) > 50 &&
{_x getVariable QGVAR(Transmit)}) then {
_group = group _x;
_grpName = groupID _group;
_color = [1, 1, 1, 1];
if (_grpName in GVAR(GroupColorConfigurationsGroups)) then {
_grpNameIndex = GVAR(GroupColorConfigurationsGroups) find _grpName;
_color = (GVAR(GroupColorConfigurations) select (GVAR(GroupColorConfigurationsGroupIndex) select _grpNameIndex)) select (_x != leader _group);
} else {
_color = 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"];
};
};
nil
} count _nearDudes;

View File

@ -0,0 +1,21 @@
/*
* Author: MikeMatrix
* Ensure that all variables used to indicate transmission are disabled.
*
* Arguments:
* None
*
* Return Value:
* None
*
* Example:
* [] call ace_map_gestures_fnc_endTransmit
*
* Public: No
*/
#include "script_component.hpp"
if (!GVAR(enabled)) exitWith {};
ACE_player setVariable [QGVAR(Transmit), false, true];
GVAR(EnableTransmit) = false;

View File

@ -0,0 +1,23 @@
/*
* Author: MikeMatrix
* Returns all players in a given range and in the units vehicle.
*
* Arguments:
* 0: Unit <OBJECT>
* 1: Range <NUMBER>
*
* Return Value:
* All units in proximity <ARRAY>
*
* Example:
* ["example value"] call ace_module_fnc_functionName
*
* Public: No
*/
#include "script_component.hpp"
params ["_unit", "_range"];
_proximityPlayers = (getPos _unit) nearEntities [["CAMAnBase"], _range];
_proximityPlayers = _proximityPlayers - [_unit];
(_proximityPlayers + (crew vehicle _unit))

View File

@ -0,0 +1,21 @@
/*
* Author: MikeMatrix
* Initializes transmitting map gestures.
*
* Arguments:
* None
*
* Return Value:
* None
*
* Example:
* [] call ace_map_gestures_fnc_initTransmit
*
* Public: No
*/
#include "script_component.hpp"
if (!GVAR(enabled)) exitWith {};
GVAR(EnableTransmit) = true;
[FUNC(transmit), GVAR(interval), []] call CBA_fnc_addPerFrameHandler;

View File

@ -0,0 +1,53 @@
/*
* Author: MikeMatrix
* Initializes Settings for the groups modules and transcodes settings to a useable format.
*
* Arguments:
* 0: Logic <LOGIC>
* 1: Units <ARRAY>
* 2: Activated <BOOL>
*
* Return Value:
* None
*
* Example:
* [module, [player], true] call ace_map_gestures_fnc_moduleGroupSettings
*
* Public: No
*/
#include "script_component.hpp"
params ["_logic", "_units", "_activated"];
if (!_activated) exitWith {};
if (!isServer) exitWith {};
_leadColor = call compile ("[" + (_logic getVariable ["leadColor", ""]) + "]");
if (isNil "_leadColor" || !((typeName _leadColor) isEqualTo "ARRAY") || {count _leadColor != 4}) exitWith {};
_color = call compile ("[" + (_logic getVariable ["color", ""]) + "]");
if (isNil "_color" || !((typeName _color) isEqualTo "ARRAY") || {count _color != 4}) exitWith {};
_configurations = +GVAR(GroupColorConfigurations);
if (isNil "_configurations") then {_configurations = []};
_configurationIndex = _configurations pushBack [_leadColor, _color];
_configurationGroups = +GVAR(GroupColorConfigurationsGroups);
_configurationGroupsIndex = +GVAR(GroupColorConfigurationsGroupIndex);
if (isNil "_configurationGroups") then {_configurationGroups = [];};
if (isNil "_configurationGroupsIndex") then {_configurationGroupsIndex = [];};
_completedGroups = [];
{
private "_group";
_group = groupID (group _x);
if (!(_group in _completedGroups)) then {
_index = if (_group in _configurationGroups) then {_configurationGroups find _group} else {_configurationGroups pushBack _group};
_configurationGroupsIndex set [_index, _configurationIndex];
_completedGroups pushBack _group;
};
nil
} count _units;
[QGVAR(GroupColorConfigurations), _configurations, true, true] call EFUNC(common,setSetting);
[QGVAR(GroupColorConfigurationsGroups), _configurationGroups, true, true] call EFUNC(common,setSetting);
[QGVAR(GroupColorConfigurationsGroupIndex), _configurationGroupsIndex, true, true] call EFUNC(common,setSetting);

View File

@ -0,0 +1,35 @@
/*
* Author: MikeMatrix
* Initializes Settings for the module and transcodes settings to a useable format.
*
* Arguments:
* 0: Logic <LOGIC>
* 1: Units <ARRAY>
* 2: Activated <BOOL>
*
* Return Value:
* None
*
* Example:
* [module, [player], true] call ace_map_gestures_fnc_moduleGroupSettings
*
* Public: No
*/
#include "script_component.hpp"
params ["_logic", "_units", "_activated"];
if (!_activated) exitWith {};
if (!isServer) exitWith {};
[_logic, QGVAR(enabled), "enabled"] call EFUNC(common,readSettingFromModule);
[_logic, QGVAR(maxRange), "maxRange"] call EFUNC(common,readSettingFromModule);
[_logic, QGVAR(interval), "interval"] call EFUNC(common,readSettingFromModule);
_defaultLeadColor = call compile ("[" + (_logic getVariable ["defaultLeadColor", ""]) + "]");
if (isNil "_leadColor" || !((typeName _leadColor) isEqualTo "ARRAY") || {count _leadColor != 4}) exitWith {};
[QGVAR(defaultLeadColor), _defaultLeadColor, true, true] call EFUNC(common,setSetting);
_defaultColor = call compile ("[" + (_logic getVariable ["defaultColor", ""]) + "]");
if (isNil "_color" || !((typeName _color) isEqualTo "ARRAY") || {count _color != 4}) exitWith {};
[QGVAR(defaultColor), _defaultColor, true, true] call EFUNC(common,setSetting);

View File

@ -0,0 +1,32 @@
/*
* Author: MikeMatrix
* Initializes the receiver and hooks it to the Draw event of the map.
*
* Arguments:
* None
*
* Return Value:
* None
*
* Example:
* [] call ace_map_gestures_fnc_receiverInit
*
* Public: No
*/
#include "script_component.hpp"
{
if (isPlayer _x) then {
_nameSane = [name _x] call FUNC(sanitizeName);
call compile format [QUOTE(GVAR(%1_DrawPos) = [ARR_3(1,1,1)];), _nameSane];
};
nil
} count allUnits;
ACE_player setVariable [QGVAR(Transmit), false, true];
GVAR(EnableTransmit) = false;
if (!isNil QGVAR(DrawMapHandlerID)) then {
(findDisplay 12 displayCtrl 51) ctrlRemoveEventHandler ["Draw", GVAR(DrawMapHandlerID)]; GVAR(DrawMapHandlerID) = nil;
};
GVAR(DrawMapHandlerID) = findDisplay 12 displayCtrl 51 ctrlAddEventHandler ["Draw", FUNC(drawMapGestures)];

View File

@ -0,0 +1,30 @@
/*
* Author: 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

@ -0,0 +1,42 @@
/*
* Author: MikeMatrix
* Transmit PFH
*
* Arguments:
* 0: Arguments <ARRAY>
* 1: PFH ID <NUMBER>
*
* Return Value:
* Return description <TYPE>
*
* Example:
* [[], 2] call ace_map_gestures_fnc_transmit
*
* Public: No
*/
#include "script_component.hpp"
private ["_nearDudes", "_ownerID", "_nameSane"];
params ["", "_pfhId"];
if (!GVAR(EnableTransmit) || !visibleMap) exitWith {
call FUNC(endTransmit);
[_pfhId] call CBA_fnc_removePerFrameHandler;
};
_nearDudes = [ACE_player, GVAR(maxRange)] call FUNC(getProximityPlayers);
TRACE_1("Near",_nearDudes)
{
_ownerID = _x getVariable QGVAR(owner_id);
if (isNil _ownerID) exitWith {
[0, {[_this] call FUNC(assignClientIDOnServer)}, name _x] call cba_fnc_GlobalExecute;
};
_ownerID = _x getVariable QGVAR(owner_id);
if (_ownerID != ACE_player getVariable QGVAR(owner_id)) then {
_nameSane = [name ACE_player] call FUNC(sanitizeName);
_ownerID publicVariableClient format [QGVAR(%1_DrawPos), _nameSane];
};
} count _nearDudes;

View File

@ -0,0 +1,59 @@
/*
* Author: MikeMatrix
* Initializes the transmitting event handlers.
*
* Arguments:
* None
*
* Return Value:
* None
*
* Example:
* [] call ace_map_gestures_fnc_transmitterInit
*
* Public: No
*/
#include "script_component.hpp"
private ["_mapCtrl", "_nameSane"];
disableSerialization;
_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 {};
params ["_control", "_posX", "_posY"];
if (GVAR(EnableTransmit)) then {
if (!(ACE_player getVariable QGVAR(Transmit))) then {
ACE_player setVariable [QGVAR(Transmit), true, true];
};
_nameSane = [name ACE_player] call FUNC(sanitizeName);
call compile format [QUOTE(GVAR(%1_DrawPos) = %2), _nameSane, _control ctrlMapScreenToWorld [_posX, _posY]];
};
}];
// MouseDown EH
if (!isNil QGVAR(MouseDownHandlerID)) then {_mapCtrl ctrlRemoveEventHandler ["MouseButtonDown",GVAR(MouseDownHandlerID)]; GVAR(MouseDownHandlerID) = nil;};
GVAR(MouseDownHandlerID) = _mapCtrl ctrlAddEventHandler ["MouseButtonDown", {
if (!GVAR(enabled)) exitWith {};
params ["", "_button"];
if (_button == 0) then {call FUNC(initTransmit);};
}];
// MouseUp EH
if (!isNil QGVAR(MouseUpHandlerID)) then {_mapCtrl ctrlRemoveEventHandler ["MouseButtonUp", GVAR(MouseUpHandlerID)]; GVAR(MouseUpHandlerID) = nil;};
GVAR(MouseUpHandlerID) = _mapCtrl ctrlAddEventHandler ["MouseButtonUp", {
params ["", "_button"];
if (_button == 0) then {call FUNC(endTransmit);};
}];

View File

@ -0,0 +1 @@
#include "\z\ace\addons\map_gestures\script_component.hpp"

View File

@ -0,0 +1,12 @@
#define COMPONENT map_gestures
#include "\z\ace\addons\main\script_mod.hpp"
#ifdef DEBUG_ENABLED_MAP_GESTURES
#define DEBUG_MODE_FULL
#endif
#ifdef DEBUG_SETTINGS_MAP_GESTURES
#define DEBUG_SETTINGS DEBUG_SETTINGS_MAP_GESTURES
#endif
#include "\z\ace\addons\main\script_macros.hpp"

View File

@ -0,0 +1,95 @@
<?xml version="1.0" encoding="utf-8"?>
<Project name="ACE">
<Package name="map_gestures">
<Key ID="STR_ACE_map_gestures_moduleSettings_displayName">
<English>Map Gestures</English>
</Key>
<Key ID="STR_ACE_map_gestures_enabled_displayName">
<English>Enabled</English>
</Key>
<Key ID="STR_ACE_map_gestures_maxRange_displayName">
<English>Map Gesture Max Range</English>
</Key>
<Key ID="STR_ACE_map_gestures_maxRange_description">
<English>Max range between players to show the map gesture indicator [default: 7 meters]</English>
</Key>
<Key ID="STR_ACE_map_gestures_defaultLeadAlpha_displayName">
<English>Lead Default Alpha</English>
</Key>
<Key ID="STR_ACE_map_gestures_defaultLeadAlpha_description">
<English>Fallback Alpha value for group leaders.</English>
</Key>
<Key ID="STR_ACE_map_gestures_defaultAlpha_displayName">
<English>Default Alpha</English>
</Key>
<Key ID="STR_ACE_map_gestures_defaultAlpha_descriptions">
<English>Fallback Alpha value.</English>
</Key>
<Key ID="STR_ACE_map_gestures_defaultLeadColor_displayName">
<English>Lead Default Color</English>
</Key>
<Key ID="STR_ACE_map_gestures_defaultLeadColor_description">
<English>Fallback Color value for group leaders.</English>
</Key>
<Key ID="STR_ACE_map_gestures_defaultColor_displayName">
<English>Default Color</English>
</Key>
<Key ID="STR_ACE_map_gestures_defaultColor_description">
<English>Fallback Color value.</English>
</Key>
<Key ID="STR_ACE_map_gestures_leadAlpha_displayName">
<English>Lead Alpha</English>
</Key>
<Key ID="STR_ACE_map_gestures_leadAlpha_description">
<English>Alpha value for group leaders of groups synced with this module.</English>
</Key>
<Key ID="STR_ACE_map_gestures_alpha_displayName">
<English>Alpha</English>
</Key>
<Key ID="STR_ACE_map_gestures_alpha_description">
<English>Alpha value for group members of groups synced with this module.</English>
</Key>
<Key ID="STR_ACE_map_gestures_leadColor_displayName">
<English>Lead Color</English>
</Key>
<Key ID="STR_ACE_map_gestures_leadColor_description">
<English>Color value for group leaders of groups synced with this module.</English>
</Key>
<Key ID="STR_ACE_map_gestures_color_displayName">
<English>Color</English>
</Key>
<Key ID="STR_ACE_map_gestures_color_description">
<English>Color value for group members of groups synced with this module.</English>
</Key>
<Key ID="STR_ACE_map_gestures_moduleGroupSettings_displayName">
<English>Map Gestures - Group Settings</English>
</Key>
<Key ID="STR_ACE_map_gestures_interval_displayName">
<English>Update Interval</English>
</Key>
<Key ID="STR_ACE_map_gestures_interval_description">
<English>Time between data updates.</English>
</Key>
<Key ID="STR_ACE_map_gestures_GroupColorConfigurations_displayName">
<English>Group color configurations</English>
</Key>
<Key ID="STR_ACE_map_gestures_GroupColorConfigurations_description">
<English>Group color configuration containing arrays of color pairs ([leadColor, color]).</English>
</Key>
<Key ID="STR_ACE_map_gestures_GroupColorConfigurationsGroups_description">
<English>Group color group name index, containing names of groups with configurations attached to them.</English>
</Key>
<Key ID="STR_ACE_map_gestures_GroupColorConfigurationsGroups_displayName">
<English>Group color group name index</English>
</Key>
<Key ID="STR_ACE_map_gestures_GroupColorConfigurationsGroupIndex_displayName">
<English>Group color group name mapping index</English>
</Key>
<Key ID="STR_ACE_map_gestures_GroupColorConfigurationsGroupIndex_description">
<English>Group color group name mapping index, mapping the GroupColorConfigurationsGroups to the GroupColorConfigurations.</English>
</Key>
<Key ID="STR_ACE_map_gestures_enabled_description">
<English>Enables the Map Gestures.</English>
</Key>
</Package>
</Project>