From bc70571765d55cff925714aee3c679e643bb5389 Mon Sep 17 00:00:00 2001 From: jonpas Date: Sat, 25 Feb 2017 17:16:40 +0100 Subject: [PATCH] Use CBA Accessory Functions for Laser mode switching (#4855) * Use CBA Accessory Functions for Laser mode switching * Use CBA ACC EH to prevent switching to unusable lzr (#4860) * Use CBA ACC EH to prevent switching to unusable lzr * Re-call CBA_accessory_fnc_switchAttachment * Require CBA 3.2.0 --- addons/laserpointer/CfgEventHandlers.hpp | 1 - addons/laserpointer/CfgWeapons.hpp | 20 ++++--- addons/laserpointer/XEH_PREP.hpp | 2 - addons/laserpointer/XEH_postInit.sqf | 17 ++++-- .../functions/fnc_switchLaserLightMode.sqf | 54 ------------------- addons/laserpointer/initKeybinds.sqf | 13 ----- addons/main/script_mod.hpp | 2 +- 7 files changed, 25 insertions(+), 84 deletions(-) delete mode 100644 addons/laserpointer/functions/fnc_switchLaserLightMode.sqf delete mode 100644 addons/laserpointer/initKeybinds.sqf diff --git a/addons/laserpointer/CfgEventHandlers.hpp b/addons/laserpointer/CfgEventHandlers.hpp index becf395052..0d3301d6e0 100644 --- a/addons/laserpointer/CfgEventHandlers.hpp +++ b/addons/laserpointer/CfgEventHandlers.hpp @@ -1,4 +1,3 @@ - class Extended_PreStart_EventHandlers { class ADDON { init = QUOTE(call COMPILE_FILE(XEH_preStart)); diff --git a/addons/laserpointer/CfgWeapons.hpp b/addons/laserpointer/CfgWeapons.hpp index 608d025a01..c86887e1c3 100644 --- a/addons/laserpointer/CfgWeapons.hpp +++ b/addons/laserpointer/CfgWeapons.hpp @@ -9,16 +9,18 @@ class CfgWeapons { class InventoryFlashLightItem_Base_F; class acc_pointer_IR: ItemCore { - ACE_nextModeClass = "ACE_acc_pointer_red"; - ACE_modeDescription = CSTRING(IRLaser); + MRT_SwitchItemNextClass = "ACE_acc_pointer_red"; + MRT_SwitchItemPrevClass = "ACE_acc_pointer_red"; + MRT_switchItemHintText = CSTRING(IRLaser); displayName = CSTRING(red); descriptionUse = CSTRING(useLaser); }; class ACE_acc_pointer_red: ItemCore { - ACE_nextModeClass = "acc_pointer_IR"; - ACE_modeDescription = CSTRING(Laser); + MRT_SwitchItemNextClass = "acc_pointer_IR"; + MRT_SwitchItemPrevClass = "acc_pointer_IR"; + MRT_switchItemHintText = CSTRING(Laser); ACE_laserpointer = 1; @@ -68,8 +70,9 @@ class CfgWeapons { }; class ACE_acc_pointer_green_IR: acc_pointer_IR { - ACE_nextModeClass = "ACE_acc_pointer_green"; - ACE_modeDescription = CSTRING(IRLaser); + MRT_SwitchItemNextClass = "ACE_acc_pointer_green"; + MRT_SwitchItemPrevClass = "ACE_acc_pointer_green"; + MRT_switchItemHintText = CSTRING(IRLaser); author = ECSTRING(common,ACETeam); _generalMacro = "ACE_acc_pointer_green"; @@ -78,8 +81,9 @@ class CfgWeapons { }; class ACE_acc_pointer_green: ACE_acc_pointer_red { - ACE_nextModeClass = "ACE_acc_pointer_green_IR"; - ACE_modeDescription = CSTRING(Laser); + MRT_SwitchItemNextClass = "ACE_acc_pointer_green_IR"; + MRT_SwitchItemPrevClass = "ACE_acc_pointer_green_IR"; + MRT_switchItemHintText = CSTRING(Laser); ACE_laserpointer = 2; diff --git a/addons/laserpointer/XEH_PREP.hpp b/addons/laserpointer/XEH_PREP.hpp index 3237967007..59a28bb4cc 100644 --- a/addons/laserpointer/XEH_PREP.hpp +++ b/addons/laserpointer/XEH_PREP.hpp @@ -1,5 +1,3 @@ - PREP(drawLaserpoint); PREP(getNearUnits); PREP(onDraw); -PREP(switchLaserLightMode); diff --git a/addons/laserpointer/XEH_postInit.sqf b/addons/laserpointer/XEH_postInit.sqf index 1a5a2df597..d8857da32a 100644 --- a/addons/laserpointer/XEH_postInit.sqf +++ b/addons/laserpointer/XEH_postInit.sqf @@ -2,7 +2,7 @@ #include "script_component.hpp" // fixes laser when being captured. Needed, because the selectionPosition of the right hand is used -[QEGVAR(captives,setHandcuffed), {if (_this select 1) then {(_this select 0) action ["ace_gunLightOff", _this select 0]};}] call CBA_fnc_addEventHandler; +[QEGVAR(captives,setHandcuffed), {if (_this select 1) then {(_this select 0) action ["GunLightOff", _this select 0]};}] call CBA_fnc_addEventHandler; if (!hasInterface) exitWith {}; @@ -12,11 +12,18 @@ GVAR(laserClassesCache) = [] call CBA_fnc_createNamespace; GVAR(redLaserUnits) = []; GVAR(greenLaserUnits) = []; -#include "initKeybinds.sqf" - ["ace_settingsInitialized", { - // if not enabled, dont't add draw eventhandler or PFEH (for performance) - if !(GVAR(enabled)) exitWith {}; + // If not enabled, dont't add draw eventhandler or PFEH (for performance) + if (!GVAR(enabled)) exitWith { + ["CBA_attachmentSwitched", { + params ["_unit", "_prevItem", "_newItem", "_currWeaponType"]; + TRACE_4("CBA_attachmentSwitched eh",_unit,_prevItem,_newItem,_currWeaponType); + if ((getNumber (configFile >> "CfgWeapons" >> _newItem >> "ACE_laserpointer")) > 0) then { + TRACE_1("removing ACE_laserpointer",getNumber (configFile >> "CfgWeapons" >> _newItem >> "ACE_laserpointer")); + [1, "prev"] call CBA_accessory_fnc_switchAttachment; + }; + }] call CBA_fnc_addEventHandler; + }; [{ private _oldNearUnits = GVAR(nearUnits); diff --git a/addons/laserpointer/functions/fnc_switchLaserLightMode.sqf b/addons/laserpointer/functions/fnc_switchLaserLightMode.sqf deleted file mode 100644 index 2469f64352..0000000000 --- a/addons/laserpointer/functions/fnc_switchLaserLightMode.sqf +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Author: Commy2 - * Switch between laser modes. - * - * Arguments: - * 0: Unit - * 1: Weapon - * - * Return Value: - * None - * - * Public: No - */ -#include "script_component.hpp" - -params ["_unit", "_weapon"]; - -private _pointer = (_unit weaponAccessories _weapon) select 1; - -if (_pointer == "") exitWith {}; - -private _config = configFile >> "CfgWeapons" >> _pointer; - -private _nextPointer = getText (_config >> "ACE_nextModeClass"); - -if (_nextPointer == "") exitWith {}; - -//If system disabled, don't switch to a laser: -private _nextPointerIsLaser = getNumber (configFile >> "CfgWeapons" >> _nextPointer >> "ACE_laserpointer"); -if ((!GVAR(enabled)) && {_nextPointerIsLaser == 1}) exitWith {}; - -// disable inheritance for this entry, because addons claim this as a base class for convenience -if !((_config >> "ACE_nextModeClass") in configProperties [_config, "true", false]) exitWith {}; - -_unit addWeaponItem [_weapon, _nextPointer]; - -private _error = false; - -if ((_unit weaponAccessories _weapon) select 1 != _nextPointer) then { - ERROR("NextPointer not compatible"); - _unit addWeaponItem [_weapon, _pointer]; - _error = true; -}; - -if (!_error) then { - private _description = getText (configFile >> "CfgWeapons" >> _nextPointer >> "ACE_modeDescription"); - private _picture = getText (configFile >> "CfgWeapons" >> _nextPointer >> "picture"); - - [_description, _picture] call EFUNC(common,displayTextPicture); -} else { - ERROR_3("Failed to add %1 to %2 - reverting to %3",_nextPointer,_weapon,_pointer); -}; - -playSound "ACE_Sound_Click"; diff --git a/addons/laserpointer/initKeybinds.sqf b/addons/laserpointer/initKeybinds.sqf deleted file mode 100644 index 2251ddfb71..0000000000 --- a/addons/laserpointer/initKeybinds.sqf +++ /dev/null @@ -1,13 +0,0 @@ -// by commy2 - -["ACE3 Weapons", QGVAR(switchLaserLightMode), localize LSTRING(switchLaserLight), -{ - // Conditions: canInteract - if !([ACE_player, objNull, ["isNotInside", "isNotSitting"]] call EFUNC(common,canInteractWith)) exitWith {false}; - // Conditions: specific - if !([ACE_player] call CBA_fnc_canUseWeapon) exitWith {false}; - - [ACE_player, currentWeapon ACE_player] call FUNC(switchLaserLightMode); - true -}, -{false}, [38, [false, true, false]], false] call CBA_fnc_addKeybind; diff --git a/addons/main/script_mod.hpp b/addons/main/script_mod.hpp index 32a78372b0..72e7f53e48 100644 --- a/addons/main/script_mod.hpp +++ b/addons/main/script_mod.hpp @@ -10,7 +10,7 @@ // MINIMAL required version for the Mod. Components can specify others.. #define REQUIRED_VERSION 1.64 -#define REQUIRED_CBA_VERSION {3,1,2} +#define REQUIRED_CBA_VERSION {3,2,0} #ifdef COMPONENT_BEAUTIFIED #define COMPONENT_NAME QUOTE(ACE3 - COMPONENT_BEAUTIFIED)