From 3da3543381b4e94a9c428098d73cd05717efd097 Mon Sep 17 00:00:00 2001 From: commy2 Date: Tue, 14 Apr 2015 00:32:09 +0200 Subject: [PATCH] toggle laser vs ir laser --- addons/laserpointer/CfgVehicles.hpp | 5 +- addons/laserpointer/CfgWeapons.hpp | 31 +++++++++- addons/laserpointer/XEH_postInit.sqf | 15 ++++- addons/laserpointer/XEH_preInit.sqf | 1 + addons/laserpointer/config.cpp | 2 +- .../functions/fnc_switchLaserLightMode.sqf | 58 +++++++++++++++++++ addons/laserpointer/stringtable.xml | 12 ++++ 7 files changed, 116 insertions(+), 8 deletions(-) create mode 100644 addons/laserpointer/functions/fnc_switchLaserLightMode.sqf diff --git a/addons/laserpointer/CfgVehicles.hpp b/addons/laserpointer/CfgVehicles.hpp index 8c81837fe2..5a0ece1b1f 100644 --- a/addons/laserpointer/CfgVehicles.hpp +++ b/addons/laserpointer/CfgVehicles.hpp @@ -2,7 +2,7 @@ class CfgVehicles { class NATO_Box_Base; class Box_NATO_Support_F: NATO_Box_Base { class TransportItems { - MACRO_ADDITEM(ACE_acc_pointer_red,4); + MACRO_ADDITEM(ACE_acc_pointer_green,4); }; }; @@ -23,13 +23,12 @@ class CfgVehicles { class FIA_Box_Base_F; class Box_FIA_Support_F: FIA_Box_Base_F { class TransportItems { - MACRO_ADDITEM(ACE_acc_pointer_red,4); + MACRO_ADDITEM(ACE_acc_pointer_green,4); }; }; class ACE_Box_Misc: Box_NATO_Support_F { class TransportItems { - MACRO_ADDITEM(ACE_acc_pointer_red,4); MACRO_ADDITEM(ACE_acc_pointer_green,4); }; }; diff --git a/addons/laserpointer/CfgWeapons.hpp b/addons/laserpointer/CfgWeapons.hpp index 364f4b2168..4f6a61c83a 100644 --- a/addons/laserpointer/CfgWeapons.hpp +++ b/addons/laserpointer/CfgWeapons.hpp @@ -1,17 +1,28 @@ class SlotInfo; class PointerSlot: SlotInfo { - compatibleItems[] += {"ACE_acc_pointer_red","ACE_acc_pointer_green"}; + compatibleItems[] += {"ACE_acc_pointer_red","ACE_acc_pointer_green_IR","ACE_acc_pointer_green"}; }; class CfgWeapons { class ItemCore; class InventoryFlashLightItem_Base_F; + class acc_pointer_IR: ItemCore { + ACE_nextModeClass = "ACE_acc_pointer_red"; + ACE_modeDescription = "$STR_ACE_Laserpointer_IRLaser"; + + displayName = "$STR_ACE_Laserpointer_red"; + descriptionUse = "$STR_ACE_Laserpointer_useLaser"; + }; + class ACE_acc_pointer_red: ItemCore { + ACE_nextModeClass = "acc_pointer_IR"; + ACE_modeDescription = "$STR_ACE_Laserpointer_Laser"; + author = "$STR_ACE_Common_ACETeam"; _generalMacro = "ACE_acc_pointer_red"; - scope = 2; + scope = 1; displayName = "$STR_ACE_Laserpointer_red"; descriptionUse = "$STR_ACE_Laserpointer_useLaser"; picture = "\A3\weapons_F\Data\UI\gear_accv_pointer_CA.paa"; @@ -54,9 +65,23 @@ class CfgWeapons { inertia = 0.1; }; - class ACE_acc_pointer_green: ACE_acc_pointer_red { + class ACE_acc_pointer_green_IR: acc_pointer_IR { + ACE_nextModeClass = "ACE_acc_pointer_green"; + ACE_modeDescription = "$STR_ACE_Laserpointer_IRLaser"; + author = "$STR_ACE_Common_ACETeam"; _generalMacro = "ACE_acc_pointer_green"; + scope = 1; + displayName = "$STR_ACE_Laserpointer_green"; + }; + + class ACE_acc_pointer_green: ACE_acc_pointer_red { + ACE_nextModeClass = "ACE_acc_pointer_green_IR"; + ACE_modeDescription = "$STR_ACE_Laserpointer_Laser"; + + author = "$STR_ACE_Common_ACETeam"; + _generalMacro = "ACE_acc_pointer_green"; + scope = 2; displayName = "$STR_ACE_Laserpointer_green"; }; }; diff --git a/addons/laserpointer/XEH_postInit.sqf b/addons/laserpointer/XEH_postInit.sqf index 14e4c384d8..eade50d670 100644 --- a/addons/laserpointer/XEH_postInit.sqf +++ b/addons/laserpointer/XEH_postInit.sqf @@ -11,7 +11,7 @@ GVAR(nearUnits) = []; // @todo. Maybe move to common? [{ private "_nearUnits"; - _nearUnits = nearestObjects [positionCameraToWorld [0,0,0], ["CAManBase"], 50]; + _nearUnits = nearestObjects [positionCameraToWorld [0,0,0], ["CAManBase"], 50]; // when moving this, search also for units inside vehicles. currently breaks the laser in FFV if (count _nearUnits > 10) then { _nearUnits resize 10; @@ -24,3 +24,16 @@ GVAR(nearUnits) = []; addMissionEventHandler ["Draw3D", { call FUNC(onDraw); }]; + +// init keybinds +["ACE3", QGVAR(switchLaserLightMode), localize "STR_ACE_Laserpointer_switchLaserLight", +{ + // Conditions: canInteract + if !([ACE_player, objNull, ["isNotInside"]] call EFUNC(common,canInteractWith)) exitWith {false}; + // Conditions: specific + if !([ACE_player] call EFUNC(common,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/laserpointer/XEH_preInit.sqf b/addons/laserpointer/XEH_preInit.sqf index e7c74d3445..1460abda36 100644 --- a/addons/laserpointer/XEH_preInit.sqf +++ b/addons/laserpointer/XEH_preInit.sqf @@ -4,5 +4,6 @@ ADDON = false; PREP(drawLaserpoint); PREP(onDraw); +PREP(switchLaserLightMode); ADDON = true; diff --git a/addons/laserpointer/config.cpp b/addons/laserpointer/config.cpp index b97587dac6..5ca5ce3470 100644 --- a/addons/laserpointer/config.cpp +++ b/addons/laserpointer/config.cpp @@ -3,7 +3,7 @@ class CfgPatches { class ADDON { units[] = {}; - weapons[] = {"ACE_acc_pointer_red","ACE_acc_pointer_green"}; + weapons[] = {"ACE_acc_pointer_red","ACE_acc_pointer_green","ACE_acc_pointer_green_IR"}; requiredVersion = REQUIRED_VERSION; requiredAddons[] = {"ace_common"}; author[] = {"commy2"}; diff --git a/addons/laserpointer/functions/fnc_switchLaserLightMode.sqf b/addons/laserpointer/functions/fnc_switchLaserLightMode.sqf new file mode 100644 index 0000000000..f996d6b270 --- /dev/null +++ b/addons/laserpointer/functions/fnc_switchLaserLightMode.sqf @@ -0,0 +1,58 @@ +// by commy2 +#include "script_component.hpp" + +private ["_unit", "_weapon"]; + +_unit = _this select 0; +_weapon = _this select 1; + +// 1 = primary, 2 = secondary, 3 = handgun +private "_currentWeaponType"; +_currentWeaponType = 0; + +private "_pointer"; +_pointer = switch (_weapon) do { + case (primaryWeapon _unit): { + _currentWeaponType = 1; + primaryWeaponItems _unit select 1 + }; + case (secondaryWeapon _unit): { + _currentWeaponType = 2; + secondaryWeaponItems _unit select 1 + }; + case (handgunWeapon _unit): { + _currentWeaponType = 3; + handgunItems _unit select 1 + }; + default {""}; +}; + +if (_pointer == "") exitWith {}; + +private "_nextPointer"; +_nextPointer = getText (configFile >> "CfgWeapons" >> _pointer >> "ACE_nextModeClass"); + +if (_nextPointer == "") exitWith {}; + +private ["_description", "_picture"]; + +_description = getText (configFile >> "CfgWeapons" >> _nextPointer >> "ACE_modeDescription"); +_picture = getText (configFile >> "CfgWeapons" >> _nextPointer >> "picture"); + +switch (_currentWeaponType) do { + case 1: { + _unit removePrimaryWeaponItem _pointer; + _unit addPrimaryWeaponItem _nextPointer; + }; + case 2: { + _unit removeSecondaryWeaponItem _pointer; + _unit addSecondaryWeaponItem _nextPointer; + }; + case 3: { + _unit removeHandgunItem _pointer; + _unit addHandgunItem _nextPointer; + }; +}; + +[_description, _picture] call EFUNC(common,displayTextPicture); +playSound "ACE_Sound_Click"; diff --git a/addons/laserpointer/stringtable.xml b/addons/laserpointer/stringtable.xml index a5a153aca4..169b5bb059 100644 --- a/addons/laserpointer/stringtable.xml +++ b/addons/laserpointer/stringtable.xml @@ -36,5 +36,17 @@ <t color='#9cf953'>Использовать: </t>вкл/выкл лазер <t color='#9cf953'>Usar: </t>encender/apagar láser + + Laser + Laser + + + IR Laser + IR-Laser + + + Switch Laser / IR Laser + Umschalten Laser / IR-Laser +