From 4b8f203f9b1f29a4058933c02c701cc6d0514dfd Mon Sep 17 00:00:00 2001 From: jonpas Date: Sun, 24 Jul 2016 20:00:33 +0200 Subject: [PATCH] Add quick tag keybind and setting --- addons/tagging/ACE_Settings.hpp | 11 ++++ addons/tagging/CfgVehicles.hpp | 43 +++++++++++++++- addons/tagging/XEH_PREP.hpp | 3 +- addons/tagging/XEH_postInit.sqf | 10 ++++ addons/tagging/config.cpp | 5 +- .../tagging/functions/fnc_addTagActions.sqf | 7 +-- addons/tagging/functions/fnc_moduleInit.sqf | 25 +++++++++ addons/tagging/functions/fnc_quickTag.sqf | 51 +++++++++++++++++++ addons/tagging/functions/fnc_tagRandom.sqf | 23 --------- addons/tagging/script_component.hpp | 10 ++-- addons/tagging/stringtable.xml | 23 ++++++++- 11 files changed, 175 insertions(+), 36 deletions(-) create mode 100644 addons/tagging/ACE_Settings.hpp create mode 100644 addons/tagging/functions/fnc_moduleInit.sqf create mode 100644 addons/tagging/functions/fnc_quickTag.sqf delete mode 100644 addons/tagging/functions/fnc_tagRandom.sqf diff --git a/addons/tagging/ACE_Settings.hpp b/addons/tagging/ACE_Settings.hpp new file mode 100644 index 0000000000..a536718795 --- /dev/null +++ b/addons/tagging/ACE_Settings.hpp @@ -0,0 +1,11 @@ +class ACE_Settings { + class GVAR(quickTag) { + category = CSTRING(Tagging); + displayName = CSTRING(QuickTag); + description = CSTRING(QuickTagDesc); + typeName = "SCALAR"; + value = 1; + values[] = {ECSTRING(Common,Disabled), CSTRING(LastUsed), CSTRING(RandomX), CSTRING(Random)}; + isClientSettable = 1; + }; +}; diff --git a/addons/tagging/CfgVehicles.hpp b/addons/tagging/CfgVehicles.hpp index f73a2ed3ab..038e0a3f85 100644 --- a/addons/tagging/CfgVehicles.hpp +++ b/addons/tagging/CfgVehicles.hpp @@ -1,11 +1,52 @@ class CfgVehicles { + class ACE_Module; + class ACE_ModuleTagging: ACE_Module { + author = ECSTRING(common,ACETeam); + category = "ACE"; + displayName = CSTRING(Tagging); + function = QFUNC(moduleInit); + scope = 2; + isGlobal = 1; + //icon = QPATHTOF(UI\Icon_Module_Tagging_ca.paa);//@todo + class Arguments { + class quickTag { + displayName = CSTRING(QuickTag); + description = CSTRING(QuickTagDesc); + typeName = "NUMBER"; + class values { + class disabled { + name = ECSTRING(Common,Disabled); + value = 0; + }; + class lastUsed { + name = CSTRING(LastUsed); + value = 1; + default = 1; + }; + class randomX { + name = CSTRING(RandomX); + value = 2; + }; + class random { + name = CSTRING(Random); + value = 3; + }; + }; + }; + }; + class ModuleDescription { + description = CSTRING(ModuleDescription); + }; + }; + + class Man; class CAManBase: Man { class ACE_SelfActions { class ACE_Tags { displayName = CSTRING(Tag); condition = QUOTE(_player call FUNC(checkTaggable)); - statement = QUOTE(_player call FUNC(tagRandom)); + statement = QUOTE(_player call FUNC(quickTag)); icon = QPATHTOF(UI\icons\iconTaggingBlack.paa); insertChildren = QUOTE(_player call FUNC(addTagActions)); }; diff --git a/addons/tagging/XEH_PREP.hpp b/addons/tagging/XEH_PREP.hpp index d5dd3571d0..44bd74b992 100644 --- a/addons/tagging/XEH_PREP.hpp +++ b/addons/tagging/XEH_PREP.hpp @@ -4,6 +4,7 @@ PREP(applyCustomTag); PREP(checkTaggable); PREP(compileConfigTags); PREP(createTag); +PREP(moduleInit); +PREP(quickTag); PREP(tag); -PREP(tagRandom); PREP(tagTestingThread); diff --git a/addons/tagging/XEH_postInit.sqf b/addons/tagging/XEH_postInit.sqf index 57b35f2e59..ddac9b9ab9 100644 --- a/addons/tagging/XEH_postInit.sqf +++ b/addons/tagging/XEH_postInit.sqf @@ -45,6 +45,16 @@ if (hasInterface) then { // Scripted tag adding EH [QGVAR(applyCustomTag), FUNC(applyCustomTag)] call CBA_fnc_addEventHandler; + + // Keybind + ["ACE3 Equipment", QGVAR(quickTag), localize LSTRING(QuickTag), { + // Conditions + if !(ACE_player call FUNC(checkTaggable)) exitWith {false}; + + // Statement + ACE_player call FUNC(quickTag); + true + }, {false}, [0, [false, false, false]], false] call CBA_fnc_addKeybind; // Unbound }; if (!isServer) exitWith {}; diff --git a/addons/tagging/config.cpp b/addons/tagging/config.cpp index f894808ed7..e066bcafe5 100644 --- a/addons/tagging/config.cpp +++ b/addons/tagging/config.cpp @@ -8,16 +8,17 @@ class CfgPatches { requiredVersion = REQUIRED_VERSION; requiredAddons[] = {"ace_interaction"}; author = ECSTRING(common,ACETeam); - authors[] = {"BaerMitUmlaut","esteldunedain"}; + authors[] = {"BaerMitUmlaut", "esteldunedain", "Jonpas"}; url = ECSTRING(main,URL); VERSION_CONFIG; }; }; +#include "ACE_Settings.hpp" +#include "ACE_Tags.hpp" #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_addTagActions.sqf b/addons/tagging/functions/fnc_addTagActions.sqf index 35624d6d05..82acf253ad 100644 --- a/addons/tagging/functions/fnc_addTagActions.sqf +++ b/addons/tagging/functions/fnc_addTagActions.sqf @@ -27,15 +27,16 @@ private _actions = []; _displayName, _icon, { - (_this select 2) params ["_unit", "_textures"]; + (_this select 2) params ["_unit", "_class", "_textures"]; [_unit, selectRandom _textures] call FUNC(tag); + _unit setVariable [QGVAR(lastUsedTag), _class]; }, { - (_this select 2) params ["_unit", "", "_requiredItem"]; + (_this select 2) params ["_unit", "", "", "_requiredItem"]; _requiredItem in ((items _unit) apply {toLower _x}) }, {}, - [_unit, _textures, _requiredItem] + [_unit, _class, _textures, _requiredItem] ] call EFUNC(interact_menu,createAction), [], _unit diff --git a/addons/tagging/functions/fnc_moduleInit.sqf b/addons/tagging/functions/fnc_moduleInit.sqf new file mode 100644 index 0000000000..c9d3172d57 --- /dev/null +++ b/addons/tagging/functions/fnc_moduleInit.sqf @@ -0,0 +1,25 @@ +/* + * Author: Jonpas + * Initializes the Tagging module. + * + * Arguments: + * 0: The module logic + * 1: Units + * 2: Activated + * + * Return Value: + * None + * + * Public: No + */ +#include "script_component.hpp" + +if (!isServer) exitWith {}; + +params ["_logic", "", "_activated"]; + +if (!_activated) exitWith {}; + +[_logic, QGVAR(quickTag), "quickTag"] call EFUNC(common,readSettingFromModule); + +ACE_LOGINFO("Tagging Module Initialized."); diff --git a/addons/tagging/functions/fnc_quickTag.sqf b/addons/tagging/functions/fnc_quickTag.sqf new file mode 100644 index 0000000000..7f0a1d706e --- /dev/null +++ b/addons/tagging/functions/fnc_quickTag.sqf @@ -0,0 +1,51 @@ +/* + * Author: Jonpas + * Selects random tag and applies it. + * + * Arguments: + * 0: Unit + * + * Return Value: + * None + * + * Example: + * [player] call ace_tagging_fnc_quickTag + * + * Public: No + */ + +#include "script_component.hpp" + +// Exit if Quick Tag disabled +if (GVAR(quickTag) == 0) exitWith {}; + +params ["_unit"]; + +private _possibleTags = []; + +// Last Used +if (GVAR(quickTag) == 1) then { + private _lastUsedTagClass = _unit getVariable [QGVAR(lastUsedTag), nil]; + + if (!isNil "_lastUsedTagClass") then { + private _lastUsedTag = GVAR(cachedTags) select {(_x select 0) == _lastUsedTagClass}; + _possibleTags = _lastUsedTag; + }; +}; + +// Random X +if (GVAR(quickTag == 2)) then { + private _xTags = GVAR(cachedTags) select {(_x select 0) in ["ACE_XBlack", "ACE_XRed", "ACE_XGreen", "ACE_XBlue"]}; + _possibleTags = _xTags; +}; + +// Random +if (GVAR(quickTag) == 3) then { + _possibleTags = GVAR(cachedTags); +}; + +// Tag +if !(_possibleTags isEqualTo []) then { + private _availableTags = _possibleTags select {(_x select 2) in ((items _unit) apply {toLower _x})}; + [_unit, selectRandom ((selectRandom _availableTags) select 3)] call FUNC(tag); +}; diff --git a/addons/tagging/functions/fnc_tagRandom.sqf b/addons/tagging/functions/fnc_tagRandom.sqf deleted file mode 100644 index 2aa2f66222..0000000000 --- a/addons/tagging/functions/fnc_tagRandom.sqf +++ /dev/null @@ -1,23 +0,0 @@ -/* - * 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/script_component.hpp b/addons/tagging/script_component.hpp index 18066d4c0d..35f973d2fc 100644 --- a/addons/tagging/script_component.hpp +++ b/addons/tagging/script_component.hpp @@ -2,17 +2,17 @@ #define COMPONENT_BEAUTIFIED Tagging #include "\z\ace\addons\main\script_mod.hpp" -// #define DEBUG_MODE_FULL -// #define DISABLE_COMPILE_CACHE +#define DEBUG_MODE_FULL +#define DISABLE_COMPILE_CACHE // #define CBA_DEBUG_SYNCHRONOUS // #define ENABLE_PERFORMANCE_COUNTERS -#ifdef DEBUG_ENABLED_BLANK +#ifdef DEBUG_ENABLED_TAGGING #define DEBUG_MODE_FULL #endif -#ifdef DEBUG_SETTINGS_BLANK - #define DEBUG_SETTINGS DEBUG_SETTINGS_BLANK +#ifdef DEBUG_SETTINGS_TAGGING + #define DEBUG_SETTINGS DEBUG_SETTINGS_TAGGING #endif #include "\z\ace\addons\main\script_macros.hpp" diff --git a/addons/tagging/stringtable.xml b/addons/tagging/stringtable.xml index 2edddb2bf8..29eee8771f 100644 --- a/addons/tagging/stringtable.xml +++ b/addons/tagging/stringtable.xml @@ -1,6 +1,27 @@  + + Tagging + + + Configure how the tagging system will operate by default. + + + Quick Tag + + + Action performed on main tag interaction point. + + + Last Used + + + Random X + + + Random + Tag Markieren @@ -12,7 +33,7 @@ Marcar - X Black + X black Schwarz X X en negro X na czarno