From c1b906c29d839633b9534c0d35173f410bd63e2c Mon Sep 17 00:00:00 2001 From: Dedmen Miller Date: Fri, 19 Jun 2020 17:36:47 +0200 Subject: [PATCH] Tagging - Add support for mission Tags (#7710) * [Tagging] Added ability to specify custom model * Update Tagging Framework doc * [Tagging] Added parsing tags from missionConfig * Update Tagging Framework doc * Apply suggestions from code review Co-authored-by: PabstMirror * Forgot passing a variable to WAE Co-authored-by: PabstMirror --- addons/tagging/XEH_PREP.hpp | 1 + addons/tagging/functions/fnc_addCustomTag.sqf | 6 +- .../tagging/functions/fnc_applyCustomTag.sqf | 1 + .../functions/fnc_compileConfigTags.sqf | 47 ++++------ addons/tagging/functions/fnc_createTag.sqf | 4 +- .../tagging/functions/fnc_parseConfigTag.sqf | 91 +++++++++++++++++++ addons/tagging/functions/fnc_quickTag.sqf | 4 +- addons/tagging/functions/fnc_tag.sqf | 6 +- docs/wiki/framework/tagging-framework.md | 25 +++++ 9 files changed, 146 insertions(+), 39 deletions(-) create mode 100644 addons/tagging/functions/fnc_parseConfigTag.sqf diff --git a/addons/tagging/XEH_PREP.hpp b/addons/tagging/XEH_PREP.hpp index 44bd74b992..449a0a6cb2 100644 --- a/addons/tagging/XEH_PREP.hpp +++ b/addons/tagging/XEH_PREP.hpp @@ -5,6 +5,7 @@ PREP(checkTaggable); PREP(compileConfigTags); PREP(createTag); PREP(moduleInit); +PREP(parseConfigTag); PREP(quickTag); PREP(tag); PREP(tagTestingThread); diff --git a/addons/tagging/functions/fnc_addCustomTag.sqf b/addons/tagging/functions/fnc_addCustomTag.sqf index 6dccf3bfb2..4de0fc016c 100644 --- a/addons/tagging/functions/fnc_addCustomTag.sqf +++ b/addons/tagging/functions/fnc_addCustomTag.sqf @@ -10,6 +10,7 @@ * 3: Textures Paths * 4: Icon Path (default: "") * 5: Material Paths (optional) + * 6: Tag Model (optional) * * Return Value: * Sucessfully Added Tag @@ -26,7 +27,8 @@ params [ ["_requiredItem", "", [""]], ["_textures", [], [[]]], ["_icon", "", [""]], - ["_materials", [], [[]]] + ["_materials", [], [[]]], + ["_tagModel", "UserTexture1m_F", [""]] ]; // Verify @@ -52,4 +54,4 @@ if (_textures isEqualTo []) exitWith { _identifier = [_identifier] call CBA_fnc_removeWhitespace; // Add -[QGVAR(applyCustomTag), [_identifier, _displayName, _requiredItem, _textures, _icon, _materials]] call CBA_fnc_globalEventJIP; +[QGVAR(applyCustomTag), [_identifier, _displayName, _requiredItem, _textures, _icon, _materials, _tagModel]] call CBA_fnc_globalEventJIP; diff --git a/addons/tagging/functions/fnc_applyCustomTag.sqf b/addons/tagging/functions/fnc_applyCustomTag.sqf index d7a14820a8..cfe4f55212 100644 --- a/addons/tagging/functions/fnc_applyCustomTag.sqf +++ b/addons/tagging/functions/fnc_applyCustomTag.sqf @@ -10,6 +10,7 @@ * 3: Textures Paths * 4: Icon Path (default: "") * 5: Material Paths + * 6: Tag Model (optional) * * Return Value: * None diff --git a/addons/tagging/functions/fnc_compileConfigTags.sqf b/addons/tagging/functions/fnc_compileConfigTags.sqf index df9f01ac45..be88a3df62 100644 --- a/addons/tagging/functions/fnc_compileConfigTags.sqf +++ b/addons/tagging/functions/fnc_compileConfigTags.sqf @@ -16,40 +16,25 @@ */ { - private _failure = false; private _class = configName _x; + private _result = [_x, false] call FUNC(parseConfigTag); - private _displayName = getText (_x >> "displayName"); - if (_displayName == "") then { - ERROR_1("Failed compiling ACE_Tags for tag: %1 - missing displayName",_class); - _failure = true; - }; + if !(_result isEqualTo []) then { + _result params ["_tagInfo", "_requiredItem"]; - private _requiredItem = getText (_x >> "requiredItem"); - if (_requiredItem == "") then { - ERROR_1("Failed compiling ACE_Tags for tag: %1 - missing requiredItem",_class); - _failure = true; - } else { - if (!isClass (configFile >> "CfgWeapons" >> _requiredItem)) then { - ERROR_2("Failed compiling ACE_Tags for tag: %1 - requiredItem %2 does not exist",_class,_requiredItem); - _failure = true; - } else { - _requiredItem = configName (configFile >> "CfgWeapons" >> _requiredItem); // convert to config case - }; - }; - - private _textures = getArray (_x >> "textures"); - if (_textures isEqualTo []) then { - ERROR_1("Failed compiling ACE_Tags for tag: %1 - missing textures",_class); - _failure = true; - }; - - private _materials = getArray (_x >> "materials"); - - private _icon = getText (_x >> "icon"); - - if (!_failure) then { - GVAR(cachedTags) pushBack [_class, _displayName, _requiredItem, _textures, _icon, _materials]; + GVAR(cachedTags) pushBack _tagInfo; GVAR(cachedRequiredItems) pushBackUnique _requiredItem; }; } forEach ("true" configClasses (configFile >> "ACE_Tags")); + +{ + private _class = configName _x; + private _result = [_x, true] call FUNC(parseConfigTag); + + if !(_result isEqualTo []) then { + _result params ["_tagInfo", "_requiredItem"]; + + GVAR(cachedTags) pushBack _tagInfo; + GVAR(cachedRequiredItems) pushBackUnique _requiredItem; + }; +} forEach ("true" configClasses (missionConfigFile >> "ACE_Tags")); diff --git a/addons/tagging/functions/fnc_createTag.sqf b/addons/tagging/functions/fnc_createTag.sqf index 032fdc69cc..a993e6675f 100644 --- a/addons/tagging/functions/fnc_createTag.sqf +++ b/addons/tagging/functions/fnc_createTag.sqf @@ -20,7 +20,7 @@ * Public: No */ -params ["_tagPosASL", "_vectorDirAndUp", "_texture", "_object", "_unit", ["_material","",[""]]]; +params ["_tagPosASL", "_vectorDirAndUp", "_texture", "_object", "_unit", ["_material","",[""]], ["_tagModel", "UserTexture1m_F", [""]]]; TRACE_5("createTag:",_tagPosASL,_vectorDirAndUp,_texture,_object,_unit); if (_texture == "") exitWith { @@ -28,7 +28,7 @@ if (_texture == "") exitWith { false }; -private _tag = createSimpleObject ["UserTexture1m_F", _tagPosASL]; +private _tag = createSimpleObject [_tagModel, _tagPosASL]; _tag setObjectTextureGlobal [0, _texture]; if (_material != "") then { _tag setObjectMaterialGlobal [0, _material] }; _tag setVectorDirAndUp _vectorDirAndUp; diff --git a/addons/tagging/functions/fnc_parseConfigTag.sqf b/addons/tagging/functions/fnc_parseConfigTag.sqf new file mode 100644 index 0000000000..41242529ee --- /dev/null +++ b/addons/tagging/functions/fnc_parseConfigTag.sqf @@ -0,0 +1,91 @@ +#include "script_component.hpp" +/* + * Author: Jonpas, Dedmen + * Parses tags from ACE_Tags config. + * + * Arguments: + * 0: The config class + * 1: Is Mission + * + * Return Value: + * Tag Information + * + * Example: + * [_x, false] call ace_tagging_fnc_parseConfigTag + * + * Public: No + */ + +#define GET_MOD_OR_MISSION_PATH(thing) \ + if (thing select [0,1] != "@") then { \ + getMissionPath thing; \ + } else { \ + thing select [1]; \ + } + +params ["_cfg", ["_isMission", false, [false]]]; + + +private _failure = false; +private _class = configName _cfg; + +private _displayName = getText (_cfg >> "displayName"); +if (_displayName == "") then { + ERROR_1("Failed compiling ACE_Tags for tag: %1 - missing displayName",_class); + _failure = true; +}; + +private _requiredItem = getText (_cfg >> "requiredItem"); +if (_requiredItem == "") then { + ERROR_1("Failed compiling ACE_Tags for tag: %1 - missing requiredItem",_class); + _failure = true; +} else { + if (!isClass (configFile >> "CfgWeapons" >> _requiredItem)) then { + ERROR_2("Failed compiling ACE_Tags for tag: %1 - requiredItem %2 does not exist",_class,_requiredItem); + _failure = true; + } else { + _requiredItem = configName (configFile >> "CfgWeapons" >> _requiredItem); // convert to config case + }; +}; + +private _textures = getArray (_cfg >> "textures"); +if (_textures isEqualTo []) then { + ERROR_1("Failed compiling ACE_Tags for tag: %1 - missing textures",_class); + _failure = true; +}; + +private _materials = getArray (_cfg >> "materials"); + +private _icon = getText (_cfg >> "icon"); + +private _tagModel = getText (_cfg >> "tagModel"); +if (_tagModel == "") then { + _tagModel = "UserTexture1m_F"; +}; + +// Need to parse mission vs mod path for mission config +if (_isMission) then { + _materials = _materials apply { + GET_MOD_OR_MISSION_PATH(_x); + }; + + _textures = _textures apply { + GET_MOD_OR_MISSION_PATH(_x); + }; + + // Only if path to model, either has subfolders or atleast a .p3d + if ("\" in _tagModel || {"." in _tagModel}) then { + _tagModel = GET_MOD_OR_MISSION_PATH(_tagModel); + }; +}; + + + +if (_failure) then { + [] +} else { + [ + [_class, _displayName, _requiredItem, _textures, _icon, _materials, _tagModel], + _requiredItem + ] +} diff --git a/addons/tagging/functions/fnc_quickTag.sqf b/addons/tagging/functions/fnc_quickTag.sqf index 1939ce1679..7c61dc7b37 100644 --- a/addons/tagging/functions/fnc_quickTag.sqf +++ b/addons/tagging/functions/fnc_quickTag.sqf @@ -49,7 +49,7 @@ if (GVAR(quickTag) == 3) then { // Tag if !(_possibleTags isEqualTo []) then { private _availableTags = _possibleTags select {(_x select 2) in (_unit call EFUNC(common,uniqueItems))}; - (selectRandom _availableTags) params ["", "", "", "_textures", "", "_materials"]; + (selectRandom _availableTags) params ["", "", "", "_textures", "", "_materials", "_tagModel"]; ( if (count _textures == count _materials) then { @@ -60,5 +60,5 @@ if !(_possibleTags isEqualTo []) then { } ) params ["_randomTexture", "_randomMaterial"]; - [_unit, _randomTexture, _randomMaterial] call FUNC(tag); + [_unit, _randomTexture, _randomMaterial, _tagModel] call FUNC(tag); }; diff --git a/addons/tagging/functions/fnc_tag.sqf b/addons/tagging/functions/fnc_tag.sqf index 8bf6ec16ab..7ea0ed2d38 100644 --- a/addons/tagging/functions/fnc_tag.sqf +++ b/addons/tagging/functions/fnc_tag.sqf @@ -7,6 +7,7 @@ * 0: Unit * 1: The colour of the tag (valid colours are black, red, green and blue or full path to custom texture) * 2: Material of the tag (Optional) + * 3: Tag Model (optional) * * Return Value: * Sucess @@ -20,7 +21,8 @@ params [ ["_unit", objNull, [objNull]], ["_texture", "", [""]], - ["_material", "", [""]] + ["_material", "", [""]], + ["_tagModel", "UserTexture1m_F", [""]] ]; if (isNull _unit || {_texture == ""}) exitWith { @@ -112,6 +114,6 @@ private _vectorDirAndUp = [_surfaceNormal vectorMultiply -1, _v3]; // Tell the server to create the tag and handle its destruction [QGVAR(createTag), _this] call CBA_fnc_serverEvent; -}, [_touchingPoint vectorAdd (_surfaceNormal vectorMultiply 0.06), _vectorDirAndUp, _texture, _object, _unit, _material], 0.6] call CBA_fnc_waitAndExecute; +}, [_touchingPoint vectorAdd (_surfaceNormal vectorMultiply 0.06), _vectorDirAndUp, _texture, _object, _unit, _material, _tagModel], 0.6] call CBA_fnc_waitAndExecute; true diff --git a/docs/wiki/framework/tagging-framework.md b/docs/wiki/framework/tagging-framework.md index 75a80da179..e263a2afaa 100644 --- a/docs/wiki/framework/tagging-framework.md +++ b/docs/wiki/framework/tagging-framework.md @@ -27,7 +27,9 @@ class ACE_Tags { displayName = "My Tag"; // Name of your tag being displayed in the interaction menu requiredItem = "ACE_SpraypaintBlack"; // Required item to have in the inventory to be able to spray your tag (eg. `"ACE_SpraypaintBlack"`, `"ACE_SpraypaintRed"`, `"ACE_SpraypaintGreen"`, `"ACE_SpraypaintBlue"` or any custom item from `CfgWeapons`) textures[] = {"path\to\texture1.paa", "path\to\texture2.paa"}; // List of texture variations (one is randomly selected when tagging) + materials[] = {"path\to\material.rvmat"}; // Optional: List of material variations (one is randomly selected). Keep empty if you don't need a custom material. icon = "path\to\icon.paa"; // Icon being displayed in the interaction menu + tagModel = "UserTexture1m_F"; // Optional: The 3D Model that will be spawned with the texture on it, can either be CfgVehicles classname or P3D file path. }; }; ``` @@ -46,6 +48,8 @@ class ACE_Tags { 2 | Required Item | String | Required 3 | Textures | Array | Required 4 | Icon | String | Optional (default: `""` - Default white point) +5 | Material Paths | Array | Optional (default: `[]] - No custom material) +6 | Tag Model | String | Optional (default: `"UserTexture1m_F"` - 1x1m texture surface) **R** | Successfully Added Tag | Boolean | Return value #### 2.1.1 Example @@ -59,3 +63,24 @@ class ACE_Tags { 2 | `"ACE_SpraypaintRed"` | Required item to have in the inventory to be able to spray your tag 3 | `["tagTexture1.paa", "tagTexture2.paa"]` | List of texture variants (one is randomly selected when tagging) 4 | `"icon.paa"` | Icon being displayed in the interaction menu + + +### 2.2 Tags in description.ext + +Tags can also be configured in description.ext like shown above. +File Paths will be relative to your mission, if you want to define Tags inside description.ext but use Addon paths for `Texture`/`Material`/`TagModel` you need to prefix the path with `@`. + +This is how above config would look when using Addon paths from description.ext: + +```cpp +class ACE_Tags { + class yourTagClass { + displayName = "My Tag"; // Name of your tag being displayed in the interaction menu + requiredItem = "ACE_SpraypaintBlack"; // Required item to have in the inventory to be able to spray your tag (eg. `"ACE_SpraypaintBlack"`, `"ACE_SpraypaintRed"`, `"ACE_SpraypaintGreen"`, `"ACE_SpraypaintBlue"` or any custom item from `CfgWeapons`) + textures[] = {"@path\to\texture1.paa", "@path\to\texture2.paa"}; // List of texture variations (one is randomly selected when tagging) + materials[] = {"@path\to\material.rvmat"}; // Optional: List of material variations (one is randomly selected). Keep empty if you don't need a custom material. + icon = "@path\to\icon.paa"; // Icon being displayed in the interaction menu + tagModel = "UserTexture1m_F"; // Optional: The 3D Model that will be spawned with the texture on it, can either be CfgVehicles classname or P3D file path. + }; +}; +```