diff --git a/addons/tagging/ACE_Tags.hpp b/addons/tagging/ACE_Tags.hpp new file mode 100644 index 0000000000..78762cf888 --- /dev/null +++ b/addons/tagging/ACE_Tags.hpp @@ -0,0 +1,26 @@ +class ACE_Tags { + class ACE_XBlack { + displayName = CSTRING(XBlack); + requiredItem = "ACE_SpraypaintBlack"; + textures[] = {QPATHTOF(UI\tags\black\0.paa), QPATHTOF(UI\tags\black\1.paa), QPATHTOF(UI\tags\black\2.paa)}; + icon = QPATHTOF(UI\icons\iconTaggingBlack.paa); + }; + class ACE_XRed { + displayName = CSTRING(XRed); + requiredItem = "ACE_SpraypaintRed"; + textures[] = {QPATHTOF(UI\tags\red\0.paa), QPATHTOF(UI\tags\red\1.paa), QPATHTOF(UI\tags\red\2.paa)}; + icon = QPATHTOF(UI\icons\iconTaggingRed.paa); + }; + class ACE_XGreen { + displayName = CSTRING(XGreen); + requiredItem = "ACE_SpraypaintGreen"; + textures[] = {QPATHTOF(UI\tags\green\0.paa), QPATHTOF(UI\tags\green\1.paa), QPATHTOF(UI\tags\green\2.paa)}; + icon = QPATHTOF(UI\icons\iconTaggingGreen.paa); + }; + class ACE_XBlue { + displayName = CSTRING(XBlue); + requiredItem = "ACE_SpraypaintBlue"; + textures[] = {QPATHTOF(UI\tags\blue\0.paa), QPATHTOF(UI\tags\blue\1.paa), QPATHTOF(UI\tags\blue\2.paa)}; + icon = QPATHTOF(UI\icons\iconTaggingBlue.paa); + }; +}; diff --git a/addons/tagging/CfgVehicles.hpp b/addons/tagging/CfgVehicles.hpp index 2a71c773a0..f73a2ed3ab 100644 --- a/addons/tagging/CfgVehicles.hpp +++ b/addons/tagging/CfgVehicles.hpp @@ -2,37 +2,17 @@ class CfgVehicles { class Man; class CAManBase: Man { class ACE_SelfActions { - class ACE_Equipment { - class ACE_TagBlack { - displayName = CSTRING(TagBlack); - condition = QUOTE(('ACE_SpraypaintBlack' in items ACE_player) && {[] call FUNC(checkTaggable)}); - statement = QUOTE([ARR_2(ACE_player,'black' call FUNC(getTexture))] call FUNC(tag)); - showDisabled = 0; - priority = 3; - icon = QPATHTOF(UI\icons\iconTaggingBlack.paa); - }; - class ACE_TagRed: ACE_TagBlack { - displayName = CSTRING(TagRed); - condition = QUOTE(('ACE_SpraypaintRed' in items ACE_player) && {[] call FUNC(checkTaggable)}); - statement = QUOTE([ARR_2(ACE_player,'red' call FUNC(getTexture))] call FUNC(tag)); - icon = QPATHTOF(UI\icons\iconTaggingRed.paa); - }; - class ACE_TagGreen: ACE_TagBlack { - displayName = CSTRING(TagGreen); - condition = QUOTE(('ACE_SpraypaintGreen' in items ACE_player) && {[] call FUNC(checkTaggable)}); - statement = QUOTE([ARR_2(ACE_player,'green' call FUNC(getTexture))] call FUNC(tag)); - icon = QPATHTOF(UI\icons\iconTaggingGreen.paa); - }; - class ACE_TagBlue: ACE_TagBlack { - displayName = CSTRING(TagBlue); - condition = QUOTE(('ACE_SpraypaintBlue' in items ACE_player) && {[] call FUNC(checkTaggable)}); - statement = QUOTE([ARR_2(ACE_player,'blue' call FUNC(getTexture))] call FUNC(tag)); - icon = QPATHTOF(UI\icons\iconTaggingBlue.paa); - }; + class ACE_Tags { + displayName = CSTRING(Tag); + condition = QUOTE(_player call FUNC(checkTaggable)); + statement = QUOTE(_player call FUNC(tagRandom)); + icon = QPATHTOF(UI\icons\iconTaggingBlack.paa); + insertChildren = QUOTE(_player call FUNC(addTagActions)); }; }; }; + class Item_Base_F; class ACE_Item_SpraypaintBlack: Item_Base_F { author = "jokoho48"; diff --git a/addons/tagging/XEH_PREP.hpp b/addons/tagging/XEH_PREP.hpp index f8a8598cd7..d794d2717a 100644 --- a/addons/tagging/XEH_PREP.hpp +++ b/addons/tagging/XEH_PREP.hpp @@ -1,5 +1,7 @@ +PREP(addCustomTag); +PREP(addTagActions); PREP(checkTaggable); PREP(createTag); -PREP(getTexture); PREP(tag); +PREP(tagRandom); PREP(tagTestingThread); diff --git a/addons/tagging/XEH_postInit.sqf b/addons/tagging/XEH_postInit.sqf index 055cb59cfd..15b1f66b67 100644 --- a/addons/tagging/XEH_postInit.sqf +++ b/addons/tagging/XEH_postInit.sqf @@ -39,6 +39,62 @@ for "_index" from 0 to (_countOptions - 1) do { }; }; +if (hasInterface) then { + // Cache tags + { + private _failure = false; + private _class = configName _x; + + private _displayName = getText (_x >> "displayName"); + if (_displayName == "") then { + ACE_LOGERROR_1("Failed compiling ACE_Tags for tag: %1 - missing displayName",_class); + _failure = true; + }; + + private _requiredItem = toLower (getText (_x >> "requiredItem")); + if (_requiredItem == "") then { + ACE_LOGERROR_1("Failed compiling ACE_Tags for tag: %1 - missing requiredItem",_class); + _failure = true; + } else { + if (!isClass (configFile >> "CfgWeapons" >> _requiredItem)) then { + ACE_LOGERROR_2("Failed compiling ACE_Tags for tag: %1 - requiredItem %2 does not exist",_class,_requiredItem); + _failure = true; + }; + }; + + private _textures = getArray (_x >> "textures"); + if (_textures isEqualTo []) then { + ACE_LOGERROR_1("Failed compiling ACE_Tags for tag: %1 - missing textures",_class); + _failure = true; + }; + + private _icon = getText (_x >> "icon"); + + if (!_failure) then { + GVAR(cachedTags) pushBack [_class, _displayName, _requiredItem, _textures, _icon]; + if !(_requiredItem in GVAR(cachedRequiredItems)) then { + GVAR(cachedRequiredItems) pushBack _requiredItem; + }; + }; + } forEach ("true" configClasses (configFile >> "ACE_Tags")); + + // Scripted tag adding + [QGVAR(addCustomTag), { + params ["_identifier", "_displayName", "_requiredItem"]; + + // Add only if tag not already added (compare identifiers) + if (GVAR(cachedTags) select {_x select 0 == _identifier} isEqualTo []) then { + GVAR(cachedTags) pushBack _this; + if !(_requiredItem in GVAR(cachedRequiredItems)) then { + GVAR(cachedRequiredItems) pushBack _requiredItem; + }; + TRACE_1("Added custom script tag",_this); + } else { + ACE_LOGINFO_2("Tag with selected identifier already exists: %1 (%2)",_identifier,_displayName) + }; + }] call CBA_fnc_addEventHandler; +}; + if (!isServer) exitWith {}; GVAR(testingThread) = false; diff --git a/addons/tagging/XEH_preInit.sqf b/addons/tagging/XEH_preInit.sqf index a7feade1c3..66458c6995 100644 --- a/addons/tagging/XEH_preInit.sqf +++ b/addons/tagging/XEH_preInit.sqf @@ -4,4 +4,7 @@ ADDON = false; #include "XEH_PREP.hpp" +GVAR(cachedTags) = []; +GVAR(cachedRequiredItems) = []; + ADDON = true; diff --git a/addons/tagging/config.cpp b/addons/tagging/config.cpp index 634f7c57af..f894808ed7 100644 --- a/addons/tagging/config.cpp +++ b/addons/tagging/config.cpp @@ -17,6 +17,7 @@ class CfgPatches { #include "CfgEventHandlers.hpp" #include "CfgVehicles.hpp" #include "CfgWeapons.hpp" +#include "ACE_Tags.hpp" class ACE_newEvents { createTag = QGVAR(createTag); diff --git a/addons/tagging/functions/fnc_addCustomTag.sqf b/addons/tagging/functions/fnc_addCustomTag.sqf new file mode 100644 index 0000000000..9cd17e475a --- /dev/null +++ b/addons/tagging/functions/fnc_addCustomTag.sqf @@ -0,0 +1,54 @@ +/* + * Author: Jonpas + * Adds custom tag. Has to be executed on one machine only. + * + * Arguments: + * 0: Unique Identifier + * 1: Display Name + * 2: Required Item + * 3: Textures Paths + * 4: Icon Path (default: "") + * + * Return Value: + * Sucessfully Added Tag + * + * Example: + * ["ace_victoryRed", "Victory Red", "ACE_SpraypaintRed", ["path\to\texture1.paa", "path\to\texture2.paa"], "path\to\icon.paa"] call ace_tagging_fnc_addCustomTag + * + * Public: Yes + */ +#include "script_component.hpp" + +params [ + ["_identifier", "", [""]], + ["_displayName", "", [""]], + ["_requiredItem", "", [""]], + ["_textures", [], [[]]], + ["_icon", "", [""]] +]; + +// Verify +if (_identifier == "") exitWith { + ACE_LOGERROR("Failed adding custom tag - missing identifier"); +}; + +if (_displayName == "") exitWith { + ACE_LOGERROR_1("Failed adding custom tag: %1 - missing displayName",_identifier); +}; + +if (_requiredItem == "") exitWith { + ACE_LOGERROR_1("Failed adding custom tag: %1 - missing requiredItem",_identifier); +}; +if (!isClass (configFile >> "CfgWeapons" >> _requiredItem)) exitWith { + ACE_LOGERROR_2("Failed adding custom tag: %1 - requiredItem %2 does not exist",_identifier,_requiredItem); +}; + +if (_textures isEqualTo []) exitWith { + ACE_LOGERROR_1("Failed adding custom tag: %1 - missing textures",_identifier); +}; + +_identifier = [_identifier] call EFUNC(common,stringRemoveWhiteSpace); +_requiredItem = toLower _requiredItem; + +// Add +[QGVAR(addCustomTag), [_identifier, _displayName, _requiredItem, _textures, _icon]] call CBA_fnc_globalEventJIP; diff --git a/addons/tagging/functions/fnc_addTagActions.sqf b/addons/tagging/functions/fnc_addTagActions.sqf new file mode 100644 index 0000000000..35624d6d05 --- /dev/null +++ b/addons/tagging/functions/fnc_addTagActions.sqf @@ -0,0 +1,45 @@ +/* + * Author: Jonpas + * Compiles tags from ACE_Tags and returns children actions. + * + * Arguments: + * 0: Unit + * + * Return Value: + * None + * + * Example: + * [unit] call ace_tagging_fnc_addTagActions + * + * Public: No + */ +#include "script_component.hpp" + +params ["_unit"]; + +private _actions = []; +{ + _x params ["_class", "_displayName", "_requiredItem", "_textures", "_icon"]; + + _actions pushBack [ + [ + format ["ACE_ConfigTag_%1", _class], + _displayName, + _icon, + { + (_this select 2) params ["_unit", "_textures"]; + [_unit, selectRandom _textures] call FUNC(tag); + }, + { + (_this select 2) params ["_unit", "", "_requiredItem"]; + _requiredItem in ((items _unit) apply {toLower _x}) + }, + {}, + [_unit, _textures, _requiredItem] + ] call EFUNC(interact_menu,createAction), + [], + _unit + ]; +} forEach GVAR(cachedTags); + +_actions diff --git a/addons/tagging/functions/fnc_checkTaggable.sqf b/addons/tagging/functions/fnc_checkTaggable.sqf index b77473f25b..d739bbfec5 100644 --- a/addons/tagging/functions/fnc_checkTaggable.sqf +++ b/addons/tagging/functions/fnc_checkTaggable.sqf @@ -3,26 +3,33 @@ * Checks if there is a taggable surface within 2.5m in front of the player. * * Arguments: - * None + * 0: Unit * * Return Value: - * Is wall taggable + * Is surface taggable * * Example: - * [] call ace_tagging_fnc_checkTaggable + * [unit] call ace_tagging_fnc_checkTaggable * * Public: No */ #include "script_component.hpp" -[[], { - private _startPosASL = eyePos ACE_player; +params ["_unit"]; + +[[_unit], { + params ["_unit"]; + + // Exit if no required item in inventory + if ((GVAR(cachedRequiredItems) arrayIntersect ((items _unit) apply {toLower _x})) isEqualTo []) exitWith {false}; + + private _startPosASL = eyePos _unit; private _cameraPosASL = AGLToASL positionCameraToWorld [0, 0, 0]; private _cameraDir = (AGLToASL positionCameraToWorld [0, 0, 1]) vectorDiff _cameraPosASL; private _endPosASL = _startPosASL vectorAdd (_cameraDir vectorMultiply 2.5); - private _intersections = lineIntersectsSurfaces [_startPosASL, _endPosASL, ACE_player, objNull, true, 1, "FIRE", "GEOM"]; + private _intersections = lineIntersectsSurfaces [_startPosASL, _endPosASL, _unit, objNull, true, 1, "FIRE", "GEOM"]; // If there's no intersections if (_intersections isEqualTo []) exitWith {false}; diff --git a/addons/tagging/functions/fnc_getTexture.sqf b/addons/tagging/functions/fnc_getTexture.sqf deleted file mode 100644 index f7f6d7e5e2..0000000000 --- a/addons/tagging/functions/fnc_getTexture.sqf +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Author: BaerMitUmlaut, esteldunedain, Jonpas - * Puts together a full path to the given tag color texture. Internal ACE3 textures only. - * - * Arguments: - * 0: The colour of the tag (valid colours are black, red, green and blue) - * - * Return Value: - * Texture (full path), "" if not found - * - * Example: - * texture = ["blue"] call ace_tagging_fnc_getTexture - * - * Public: No - */ - -#include "script_component.hpp" - -params ["_color"]; - -if !((toLower _color) in ["black", "red", "green", "blue"]) exitWith { - ACE_LOGERROR_1("%1 is not a valid tag colour.",_color); - "" -}; - -QUOTE(PATHTOF(UI)) + "\tags\" + _color + "\" + str (floor (random 3)) + ".paa" diff --git a/addons/tagging/functions/fnc_tagRandom.sqf b/addons/tagging/functions/fnc_tagRandom.sqf new file mode 100644 index 0000000000..2aa2f66222 --- /dev/null +++ b/addons/tagging/functions/fnc_tagRandom.sqf @@ -0,0 +1,23 @@ +/* + * Author: Jonpas + * Selects random tag and applies it. + * + * Arguments: + * 0: Unit + * + * Return Value: + * None + * + * Example: + * [player] call ace_tagging_fnc_tagRandom + * + * Public: No + */ + +#include "script_component.hpp" + +params ["_unit"]; + +private _possibleTags = GVAR(cachedTags) select {(_x select 2) in ((items _unit) apply {toLower _x})}; + +[_unit, selectRandom ((selectRandom _possibleTags) select 3)] call FUNC(tag); diff --git a/addons/tagging/stringtable.xml b/addons/tagging/stringtable.xml index 43f6a1e2d4..2edddb2bf8 100644 --- a/addons/tagging/stringtable.xml +++ b/addons/tagging/stringtable.xml @@ -1,45 +1,55 @@  - - Tag black - Schwarz markieren - Marcar en negro - Oznakuj na czarno - Tag noir - Marca nero - Označit černě - Marcar em preto + + Tag + Markieren + Marcar + Oznakuj + Tag + Marca + Označit + Marcar - - Tag red - Rot markieren - Marcar en rojo - Oznakuj na czerwono - Tag rouge - Marca rosso - Označit červeně - Marcar em vermelho + + X Black + Schwarz X + X en negro + X na czarno + X noir + X nero + X černě + X em preto - - Tag green - Grün markieren - Marcar en verde - Oznakuj na zielono - Tag vert - Marca verde - Označit zeleně - Marcar em verde + + X red + Rot X + X en rojo + X na czerwono + X rouge + X rosso + X červeně + X em vermelho - - Tag blue - Blau markieren - Marcar en azul - Oznakuj na niebiesko - Tag bleu - Marca blu - Označit modře - Marcar em azul + + X green + Grün X + X en verde + X na zielono + X vert + X verde + X zeleně + X em verde + + + X blue + Blau X + X en azul + X na niebiesko + X bleu + X blu + X modře + X em azul Black spray paint @@ -92,4 +102,4 @@ Uma lata de tinta spray para marcar paredes. - \ No newline at end of file +