diff --git a/AUTHORS.txt b/AUTHORS.txt index 29a270aedf..70bd7af086 100644 --- a/AUTHORS.txt +++ b/AUTHORS.txt @@ -106,3 +106,4 @@ Valentin Torikian VyMajoris(W-Cephei) Winter zGuba +Drill diff --git a/addons/finger/$PBOPREFIX$ b/addons/finger/$PBOPREFIX$ new file mode 100644 index 0000000000..746f380ecc --- /dev/null +++ b/addons/finger/$PBOPREFIX$ @@ -0,0 +1 @@ +z\ace\addons\finger \ No newline at end of file diff --git a/addons/finger/ACE_Settings.hpp b/addons/finger/ACE_Settings.hpp new file mode 100644 index 0000000000..a4beb40eb8 --- /dev/null +++ b/addons/finger/ACE_Settings.hpp @@ -0,0 +1,27 @@ +class ACE_Settings { + class GVAR(enabled) { + value = 0; + typeName = "BOOL"; + displayName = CSTRING(enabled_displayName); + }; + class GVAR(maxRange) { + value = 4; + typeName = "SCALAR"; + displayName = CSTRING(maxRange_displayName); + description = CSTRING(maxRange_description); + }; + class GVAR(indicatorForSelf) { + value = 1; + typeName = "BOOL"; + isClientSettable = 1; + displayName = CSTRING(indicatorForSelf_name); + description = CSTRING(indicatorForSelf_description); + }; + class GVAR(indicatorColor) { + value[] = {0.83, 0.68, 0.21, 0.75}; + typeName = "COLOR"; + isClientSettable = 1; + displayName = CSTRING(indicatorColor_name); + description = CSTRING(indicatorColor_description); + }; +}; diff --git a/addons/finger/CfgEventHandlers.hpp b/addons/finger/CfgEventHandlers.hpp new file mode 100644 index 0000000000..917a0acbd7 --- /dev/null +++ b/addons/finger/CfgEventHandlers.hpp @@ -0,0 +1,10 @@ +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)); + }; +}; diff --git a/addons/finger/CfgVehicles.hpp b/addons/finger/CfgVehicles.hpp new file mode 100644 index 0000000000..99d9713f00 --- /dev/null +++ b/addons/finger/CfgVehicles.hpp @@ -0,0 +1,25 @@ +class CfgVehicles { + class ACE_Module; + class GVAR(moduleSettings): ACE_Module { + scope = 2; + category = "ACE"; + displayName = CSTRING(moduleSettings_displayName); + icon = QUOTE(PATHTOF(UI\Icon_Module_finger_ca.paa)); + 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; + }; + }; + }; +}; diff --git a/addons/finger/README.md b/addons/finger/README.md new file mode 100644 index 0000000000..6c5d55b7aa --- /dev/null +++ b/addons/finger/README.md @@ -0,0 +1,12 @@ +ace_finger +=========== + +Allows players to point and show a virtual spot in the distance to nearby players. + + +## Maintainers + +The people responsible for merging changes to this component or answering potential questions. + +- [Drill](https://github.com/TheDrill/) +- [PabstMirror](https://github.com/PabstMirror) diff --git a/addons/finger/XEH_postInit.sqf b/addons/finger/XEH_postInit.sqf new file mode 100644 index 0000000000..5d2fa5a261 --- /dev/null +++ b/addons/finger/XEH_postInit.sqf @@ -0,0 +1,23 @@ +#include "script_component.hpp" + +if (!hasInterface) exitWith {}; + +GVAR(lastFPTime) = -1; +GVAR(fingersHash) = HASH_CREATE; +GVAR(pfeh_id) = -1; + +["SettingsInitialized", { + //If not enabled, dont't bother adding keybind or eventhandler + if (!GVAR(enabled)) exitWith {}; + + [QGVAR(fingered), {_this call FUNC(incomingFinger)}] call EFUNC(common,addEventHandler); + + ["ACE3 Common", + QGVAR(finger), + [(localize LSTRING(keyComb)), (localize LSTRING(keyComb_description))], + { + _this call FUNC(keyPress); + }, + {false}, + [41, [true, false, false]], true] call cba_fnc_addKeybind; // Shift + Tilda (hold) +}] call EFUNC(common,addEventHandler); diff --git a/addons/finger/XEH_preInit.sqf b/addons/finger/XEH_preInit.sqf new file mode 100644 index 0000000000..e7e68cf8ec --- /dev/null +++ b/addons/finger/XEH_preInit.sqf @@ -0,0 +1,10 @@ +#include "script_component.hpp" + +ADDON = false; + +PREP(incomingFinger); +PREP(keyPress); +PREP(moduleSettings); +PREP(perFrameEH); + +ADDON = true; diff --git a/addons/finger/config.cpp b/addons/finger/config.cpp new file mode 100644 index 0000000000..2cc3be5ddd --- /dev/null +++ b/addons/finger/config.cpp @@ -0,0 +1,18 @@ +#include "script_component.hpp" + +class CfgPatches { + class ADDON { + units[] = {QGVAR(moduleSettings)}; + weapons[] = {}; + requiredVersion = REQUIRED_VERSION; + requiredAddons[] = {"ace_common"}; + author[] = {"Drill"}; + authorUrl = "https://github.com/TheDrill/"; + VERSION_CONFIG; + }; +}; + + +#include "ACE_Settings.hpp" +#include "CfgEventHandlers.hpp" +#include "CfgVehicles.hpp" diff --git a/addons/finger/functions/fnc_incomingFinger.sqf b/addons/finger/functions/fnc_incomingFinger.sqf new file mode 100644 index 0000000000..83e2916e4f --- /dev/null +++ b/addons/finger/functions/fnc_incomingFinger.sqf @@ -0,0 +1,35 @@ +/* + * Author: TheDrill, PabstMirror + * Recieve an finger event, adds to the array (or updates if already present) and starts PFEH if not already running + * + * Arguments: + * 0: Source Unit (can be self) + * 1: Position being pointed at (from positionCameraToWorld) + * + * Return Value: + * None + * + * Example: + * [bob, [1,2,3]] call ace_finger_fnc_incomingFinger; + * + * Public: No + */ +#include "script_component.hpp" + +PARAMS_2(_sourceUnit,_fingerPosPrecise); + +private ["_data", "_fingerPos"]; + +//add some random float to location if it's not our own finger: +_fingerPos = if (_sourceUnit == ACE_player) then { + _fingerPosPrecise +} else { + _fingerPosPrecise vectorAdd [random (2*FP_RANDOMIZATION_X) - FP_RANDOMIZATION_X, random (2*FP_RANDOMIZATION_X) - FP_RANDOMIZATION_X, random (2*FP_RANDOMIZATION_Y) - FP_RANDOMIZATION_Y] +}; + +_data = [ACE_diagTime, _fingerPos, ([_sourceUnit] call EFUNC(common,getName))]; +HASH_SET(GVAR(fingersHash), _sourceUnit, _data); + +if (GVAR(pfeh_id) == -1) then { + GVAR(pfeh_id) = [DFUNC(perFrameEH), 0, []] call CBA_fnc_addPerFrameHandler; +}; diff --git a/addons/finger/functions/fnc_keyPress.sqf b/addons/finger/functions/fnc_keyPress.sqf new file mode 100644 index 0000000000..8462eb7170 --- /dev/null +++ b/addons/finger/functions/fnc_keyPress.sqf @@ -0,0 +1,61 @@ +/* + * Author: TheDrill, PabstMirror + * On keypress, point and send position to nearby players + * + * Arguments: + * None + * + * Return Value: + * Key Handeled + * + * Example: + * [] call ace_finger_fnc_keyPress; + * + * Public: No + */ +#include "script_component.hpp" + +private["_fingerPosPrecise", "_playerEyePos", "_sendFingerToPlayers", "_nearbyMen"]; + +if (!alive ACE_player) exitWith {false}; +// Conditions: canInteract +if !([ACE_player, ACE_player, ["isNotInside"]] call EFUNC(common,canInteractWith)) exitWith {false}; +//make sure player is dismounted or in a static weapon: +if ((ACE_player != vehicle ACE_player) && {!((vehicle ACE_player) isKindOf "StaticWeapon")}) exitWith {false}; +//Check camera view (not in GUNNER) +if !(cameraView in ["INTERNAL", "EXTERNAL"]) exitWith {false}; +//Exit if run recently (run every 1 seconds) +if (ACE_diagTime < (GVAR(lastFPTime) + FP_ACTION_TIMEOUT)) exitWith {true}; + +GVAR(lastFPTime) = ACE_diagTime; + +_fingerPosPrecise = positionCameraToWorld [0, 0, FP_DISTANCE]; +_playerEyePos = eyePos ACE_player; + +_sendFingerToPlayers = []; + + +_nearbyMen = (ACE_player nearObjects ["CAManBase", (GVAR(maxRange) + 2)]); +{ + _nearbyMen append (crew _x); +} forEach (ACE_player nearObjects ["StaticWeapon", (GVAR(maxRange) + 2)]); + +{ + if ((((eyePos _x) vectorDistance _playerEyePos) < GVAR(maxRange)) && + {alive _x} && + {(_x == (vehicle _x)) || {(vehicle _x) isKindOf "StaticWeapon"}} && + {GVAR(indicatorForSelf) || {_x != ACE_player}} && + {!(lineIntersects [(eyePos _x), _playerEyePos, ACE_player, _x])} && + {[_x] call EFUNC(common,isPlayer)}) then { + + _sendFingerToPlayers pushBack _x; + }; +} forEach _nearbyMen; + +TRACE_1("sending finger to",_sendFingerToPlayers); + +[QGVAR(fingered), _sendFingerToPlayers, [ACE_player, _fingerPosPrecise]] call EFUNC(common,targetEvent); + +ACE_player playActionNow "GestureGo"; + +true diff --git a/addons/finger/functions/fnc_moduleSettings.sqf b/addons/finger/functions/fnc_moduleSettings.sqf new file mode 100644 index 0000000000..aa623ed58c --- /dev/null +++ b/addons/finger/functions/fnc_moduleSettings.sqf @@ -0,0 +1,21 @@ +/* + * Author: PabstMirror + * Module for fingering settings + * + * Arguments: + * 0: The module logic + * + * Return Value: + * None + * + * Public: No + */ + +#include "script_component.hpp" + +PARAMS_1(_logic); + +if !(isServer) exitWith {}; + +[_logic, QGVAR(enabled), "enabled"] call EFUNC(common,readSettingFromModule); +[_logic, QGVAR(maxRange), "maxRange"] call EFUNC(common,readSettingFromModule); diff --git a/addons/finger/functions/fnc_perFrameEH.sqf b/addons/finger/functions/fnc_perFrameEH.sqf new file mode 100644 index 0000000000..a35550db76 --- /dev/null +++ b/addons/finger/functions/fnc_perFrameEH.sqf @@ -0,0 +1,51 @@ +/* + * Author: TheDrill, PabstMirror + * The perFrameEventHandler to draw the icons + * + * Arguments: + * None + * + * Return Value: + * None + * + * Example: + * [fromCBA] call ace_finger_fnc_perFrameEH; + * + * Public: No + */ +#include "script_component.hpp" + +private["_drawColor", "_fovCorrection", "_iconSize", "_timeLeftToShow", "_cameraOffset"]; + +if (!alive ACE_player) then {GVAR(fingersHash) = HASH_CREATE;}; +// Conditions: canInteract +if !([ACE_player, ACE_player, ["isNotInside"]] call EFUNC(common,canInteractWith)) then {GVAR(fingersHash) = HASH_CREATE;}; +//make sure player is dismounted or in a static weapon: +if ((ACE_player != vehicle ACE_player) && {!((vehicle ACE_player) isKindOf "StaticWeapon")}) then {GVAR(fingersHash) = HASH_CREATE;}; + +_cameraOffset = worldToScreen (positionCameraToWorld [1000, 0, 10000]); +_fovCorrection = 0; +if (count _cameraOffset > 0) then {_fovCorrection = (_cameraOffset select 0) - 0.5;}; +_iconSize = BASE_SIZE * _fovCorrection; + +{ + _data = HASH_GET(GVAR(fingersHash), _x); + EXPLODE_3_PVT(_data,_lastTime,_pos,_name); + _timeLeftToShow = _lastTime + FP_TIMEOUT - ACE_diagTime; + if (_timeLeftToShow <= 0) then { + HASH_REM(GVAR(fingersHash), _x); + } else { + _drawColor = + GVAR(indicatorColor); + //Fade out: + if (_timeLeftToShow < 0.5) then { + _drawColor set [3, ((_drawColor select 3) * (_timeLeftToShow / 0.5))]; + }; + + drawIcon3D [QUOTE(PATHTOF(UI\fp_icon.paa)), _drawColor, _pos, _iconSize, _iconSize, 0, _name, 1, 0.03, "PuristaMedium"]; + }; +} forEach (GVAR(fingersHash) select 0); + +if ((count (GVAR(fingersHash) select 0)) == 0) then { + [GVAR(pfeh_id)] call CBA_fnc_removePerFrameHandler; + GVAR(pfeh_id) = -1; +}; diff --git a/addons/finger/functions/script_component.hpp b/addons/finger/functions/script_component.hpp new file mode 100644 index 0000000000..4d3625f072 --- /dev/null +++ b/addons/finger/functions/script_component.hpp @@ -0,0 +1 @@ +#include "\z\ace\addons\finger\script_component.hpp" \ No newline at end of file diff --git a/addons/finger/script_component.hpp b/addons/finger/script_component.hpp new file mode 100644 index 0000000000..ae96943943 --- /dev/null +++ b/addons/finger/script_component.hpp @@ -0,0 +1,21 @@ +#define COMPONENT finger +#include "\z\ace\addons\main\script_mod.hpp" + +#ifdef DEBUG_ENABLED_FINGER + #define DEBUG_MODE_FULL +#endif + +#ifdef DEBUG_SETTINGS_FINGER + #define DEBUG_SETTINGS DEBUG_SETTINGS_FINGER +#endif + +#include "\z\ace\addons\main\script_macros.hpp" + +#define BASE_SIZE 44 + +#define FP_TIMEOUT 2 +#define FP_ACTION_TIMEOUT 1 + +#define FP_DISTANCE 10000 +#define FP_RANDOMIZATION_X 350 +#define FP_RANDOMIZATION_Y 100 diff --git a/addons/finger/stringtable.xml b/addons/finger/stringtable.xml new file mode 100644 index 0000000000..bbc308fcd7 --- /dev/null +++ b/addons/finger/stringtable.xml @@ -0,0 +1,40 @@ + + + + + Show finger indicator to self + Отображать пальце-индикатор для показывающего игрока + + + Render the indicator for the pointing player. This option doesn't affect whether the other players would see the indicator + Отображать индикатор для показывающего игрока. Эта настройка не влияет на то, будутт ли другие игроки видеть индикатор + + + Finger indicator + Пальце-индикатор + + + Color of the finger-pointing indicator circle + Цвет индикатора пальце-указания + + + Action "point a finger at" + Действие "показать пальцем на" + + + Points, and shows a virtual marker of where you are looking to nearby units. Can be held down. + + + Finger Settings + + + Finger Pointing Enabled + + + Finger Max Range + + + How far away players can finger each other. [default: 4] + + + diff --git a/addons/finger/ui/Icon_Module_finger_ca.paa b/addons/finger/ui/Icon_Module_finger_ca.paa new file mode 100644 index 0000000000..2d8de25b9b Binary files /dev/null and b/addons/finger/ui/Icon_Module_finger_ca.paa differ diff --git a/addons/finger/ui/fp_icon.paa b/addons/finger/ui/fp_icon.paa new file mode 100644 index 0000000000..9fccb144f1 Binary files /dev/null and b/addons/finger/ui/fp_icon.paa differ