Skip to content

Commit

Permalink
Updating event handler logic, adding remove view camera
Browse files Browse the repository at this point in the history
  • Loading branch information
sethduda committed Jan 16, 2017
1 parent 128b1fa commit 9e6f95f
Show file tree
Hide file tree
Showing 20 changed files with 308 additions and 44 deletions.
22 changes: 21 additions & 1 deletion AICommand/cfgfunctions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,16 @@ class AICommand
class addCommandMenuAction {description = "";};
class executeCommandMenuAction {description = "";};
};


class EventHandler
{
file = "AICommand\functions\eventHandler";
class addManagedEventHandler {description = "";};
class addEventHandler {description = "";};
class removeEventHandler {description = "";};
class eventHandlerManager {description = "";};
};

class Actions
{
file = "AICommand\functions\actions";
Expand All @@ -57,6 +65,18 @@ class AICommand
class selectGroupControlPosition {description = "";};
class selectGroupControlVehicle {description = "";};
};



class RemoteCamera
{
file = "AICommand\functions\remoteCamera";
class disable3rdPersonCamera {description = "";};
class enable3rdPersonCamera {description = "";};
class cameraMouseMoveHandler {description = "";};
class cameraMouseZoomHandler {description = "";};
class cameraUpdatePosition {description = "";};
};

class CR
{
Expand Down
60 changes: 56 additions & 4 deletions AICommand/functions/actions/fn_commandMenuActionsInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -257,13 +257,13 @@ AIC_fnc_remoteControlActionHandler = {
_exitingRcUnit = missionNamespace getVariable ["AIC_Remote_Control_To_Unit",objNull];
if(!isNull _exitingRcUnit) then {
_exitingRcUnit removeEventHandler ["HandleDamage", (missionNamespace getVariable ["AIC_Remote_Control_To_Unit_Event_Handler",-1])];
AIC_MAIN_DISPLAY displayRemoveEventHandler ["KeyDown", (missionNamespace getVariable ["AIC_Remote_Control_Delete_Handler",-1])];
["MAIN_DISPLAY","KeyDown",(missionNamespace getVariable ["AIC_Remote_Control_Delete_Handler",-1])] call AIC_fnc_removeEventHandler;
};
missionNamespace setVariable ["AIC_Remote_Control_To_Unit",_rcUnit];

AIC_Remote_Control_From_Unit_Event_Handler = _fromUnit addEventHandler ["HandleDamage", "[] call AIC_fnc_terminateRemoteControl; _this select 2;"];
AIC_Remote_Control_To_Unit_Event_Handler = _rcUnit addEventHandler ["HandleDamage", "[] call AIC_fnc_terminateRemoteControl; _this select 2;"];
AIC_Remote_Control_Delete_Handler = AIC_MAIN_DISPLAY displayAddEventHandler ["KeyDown", "if(_this select 1 == 211) then { [] call AIC_fnc_terminateRemoteControl; }" ];
AIC_Remote_Control_Delete_Handler = ["MAIN_DISPLAY","KeyDown", "if(_this select 1 == 211) then { [] call AIC_fnc_terminateRemoteControl; }"] call AIC_fnc_addEventHandler;

BIS_fnc_feedback_allowPP = false;
selectPlayer _rcUnit;
Expand All @@ -275,7 +275,7 @@ AIC_fnc_remoteControlActionHandler = {
};

AIC_fnc_terminateRemoteControl = {
AIC_MAIN_DISPLAY displayRemoveEventHandler ["KeyDown", (missionNamespace getVariable ["AIC_Remote_Control_Delete_Handler",-1])];
["MAIN_DISPLAY","KeyDown",(missionNamespace getVariable ["AIC_Remote_Control_Delete_Handler",-1])] call AIC_fnc_removeEventHandler;
(missionNamespace getVariable ["AIC_Remote_Control_From_Unit",objNull]) removeEventHandler ["HandleDamage", (missionNamespace getVariable ["AIC_Remote_Control_From_Unit_Event_Handler",-1])];
(missionNamespace getVariable ["AIC_Remote_Control_To_Unit",objNull]) removeEventHandler ["HandleDamage", (missionNamespace getVariable ["AIC_Remote_Control_To_Unit_Event_Handler",-1])];
missionNamespace setVariable ["AIC_Remote_Control_To_Unit",nil];
Expand All @@ -285,7 +285,7 @@ AIC_fnc_terminateRemoteControl = {
["RemoteControl",["","Remote Control Terminated"]] call BIS_fnc_showNotification;
};

["GROUP","Remote Control",[],AIC_fnc_remoteControlActionHandler,[],{
["GROUP","Remote Control",["Remote"],AIC_fnc_remoteControlActionHandler,[],{
params ["_groupControlId"];
private ["_group"];
_group = AIC_fnc_getGroupControlGroup(_groupControlId);
Expand All @@ -300,6 +300,58 @@ AIC_fnc_terminateRemoteControl = {
_canControl;
}] call AIC_fnc_addCommandMenuAction;

AIC_fnc_remoteViewActionHandler = {
params ["_menuParams","_actionParams"];
_menuParams params ["_groupControlId"];
private ["_group"];
_group = AIC_fnc_getGroupControlGroup(_groupControlId);
private ["_fromUnit","_rcUnit","_exitingRcUnit"];

_fromUnit = missionNamespace getVariable ["AIC_Remote_View_From_Unit",objNull];
if(isNull _fromUnit || !alive _fromUnit) then {
_fromUnit = player;
missionNamespace setVariable ["AIC_Remote_View_From_Unit",_fromUnit];
};

_rcUnit = leader _group;
_exitingRcUnit = missionNamespace getVariable ["AIC_Remote_View_To_Unit",objNull];
if(!isNull _exitingRcUnit) then {
["MAIN_DISPLAY","KeyDown",(missionNamespace getVariable ["AIC_Remote_View_Delete_Handler",-1])] call AIC_fnc_removeEventHandler;
};
missionNamespace setVariable ["AIC_Remote_View_To_Unit",_rcUnit];

AIC_Remote_View_From_Unit_Event_Handler = _fromUnit addEventHandler ["HandleDamage", "[] call AIC_fnc_terminateRemoteView; _this select 2;"];
AIC_Remote_View_Delete_Handler = ["MAIN_DISPLAY","KeyDown", "if(_this select 1 == 211) then { [] call AIC_fnc_terminateRemoteView; }"] call AIC_fnc_addEventHandler;

openMap false;

[_rcUnit] call AIC_fnc_enable3rdPersonCamera;

["RemoteControl",["","Press DELETE to Exit Remote View"]] call BIS_fnc_showNotification;

};

AIC_fnc_terminateRemoteView = {
["MAIN_DISPLAY","KeyDown",(missionNamespace getVariable ["AIC_Remote_View_Delete_Handler",-1])] call AIC_fnc_removeEventHandler;
(missionNamespace getVariable ["AIC_Remote_View_From_Unit",objNull]) removeEventHandler ["HandleDamage", (missionNamespace getVariable ["AIC_Remote_View_From_Unit_Event_Handler",-1])];
missionNamespace setVariable ["AIC_Remote_View_To_Unit",nil];
selectPlayer (missionNamespace getVariable ["AIC_Remote_View_From_Unit",player]);
[] call AIC_fnc_disable3rdPersonCamera;
["RemoteControl",["","Remote View Terminated"]] call BIS_fnc_showNotification;
};

["GROUP","Remote View",["Remote"],AIC_fnc_remoteViewActionHandler,[],{
params ["_groupControlId"];
private ["_group"];
_group = AIC_fnc_getGroupControlGroup(_groupControlId);
private ["_canControl"];
_canControl = false;
if(player != leader _group) then {
_canControl = true;
};
_canControl;
}] call AIC_fnc_addCommandMenuAction;

AIC_fnc_assignVehicleActionHandler = {
params ["_menuParams","_actionParams"];
_menuParams params ["_groupControlId"];
Expand Down
6 changes: 2 additions & 4 deletions AICommand/functions/commandMenu/fn_commandMenuManager.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@

if(!hasInterface) exitWith {};

waitUntil {!isNull (findDisplay 46)};

// This function prevents left clicking from triggering the action on the command menu
AIC_fnc_commandMenuAction = {

Expand Down Expand Up @@ -66,7 +64,7 @@ AIC_fnc_commandMenuEventHandler = {

};

AIC_MAIN_DISPLAY displayAddEventHandler ["KeyDown", "[""KeyDown"",_this] call AIC_fnc_commandMenuEventHandler" ];
AIC_MAIN_DISPLAY displayAddEventHandler ["MouseButtonDown", "[""MouseButtonDown"",_this] call AIC_fnc_commandMenuEventHandler" ];
["MAIN_DISPLAY","KeyDown", "[""KeyDown"",_this] call AIC_fnc_commandMenuEventHandler"] spawn AIC_fnc_addManagedEventHandler;
["MAIN_DISPLAY","MouseButtonDown", "[""MouseButtonDown"",_this] call AIC_fnc_commandMenuEventHandler"] spawn AIC_fnc_addManagedEventHandler;

};
40 changes: 40 additions & 0 deletions AICommand/functions/eventHandler/fn_addEventHandler.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include "..\functions.h"

/*
Author: [SA] Duda
Description:
Add an event handler
Parameter(s):
_this select 0: STRING - Event handler type ("MAIN_DISPLAY","MAP_DISPLAY","MAP_CONTROL")
_this select 1: STRING - Event type (e.g. "KeyDown")
_this select 2: STRING - Event script
Returns:
NUMBER - Event handler id
*/

params ["_handlerType","_eventType","_eventScript"];

waitUntil {!isNull AIC_MAP_CONTROL && !isNull AIC_MAIN_DISPLAY && !isNull AIC_MAP_DISPLAY};

private _eventId = -1;
if(_handlerType == "MAIN_DISPLAY") then {
_eventId = AIC_MAIN_DISPLAY displayAddEventHandler [_eventType, _eventScript + "; false"];
};
if(_handlerType == "MAP_DISPLAY") then {
_eventId = AIC_MAP_DISPLAY displayAddEventHandler [_eventType, _eventScript+ "; false"];
};
if(_handlerType == "MAP_CONTROL") then {
_eventId = AIC_MAP_CONTROL ctrlAddEventHandler [_eventType, _eventScript+ "; false"];
};
_eventId;








33 changes: 33 additions & 0 deletions AICommand/functions/eventHandler/fn_addManagedEventHandler.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include "..\functions.h"

/*
Author: [SA] Duda
Description:
Add a managed event handler (will ensure that it doesn't get disabled by other addons)
Parameter(s):
_this select 0: STRING - Event handler type ("MAIN_DISPLAY","MAP_DISPLAY","MAP_CONTROL")
_this select 1: STRING - Event type (e.g. "KeyDown")
_this select 2: STRING - Event script
Returns:
Nothing
*/

if(isDedicated || !hasInterface) exitWith {};

params ["_handlerType","_eventType","_eventScript"];
waitUntil {!isNull AIC_MAP_CONTROL && !isNull AIC_MAIN_DISPLAY && !isNull AIC_MAP_DISPLAY};
private _eventHandlers = AIC_fnc_getEventHandlers();
private _eventHandlerId = _this call AIC_fnc_addEventHandler;
_eventHandlers pushBack [_eventHandlerId,_this];
AIC_fnc_setEventHandlers(_eventHandlers);








34 changes: 34 additions & 0 deletions AICommand/functions/eventHandler/fn_eventHandlerManager.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include "..\functions.h"

/*
Author: [SA] Duda
Description:
Event handler manager. Takes care of making sure other addons don't take over control of the event handlers.
Parameter(s):
Nothing
Returns:
Nothing
*/

if(isDedicated || !hasInterface) exitWith {};

[] spawn {
waitUntil {!isNull AIC_MAP_CONTROL && !isNull AIC_MAIN_DISPLAY && !isNull AIC_MAP_DISPLAY};
sleep 60;
while {true} do {
_eventHandlers = AIC_fnc_getEventHandlers();
_index = 0;
{
_x params ["_eventHandlerId","_handlerParams"];
_handlerParams params ["_handlerType","_eventType","_eventScript"];
[_handlerType, _eventType, _eventHandlerId] call AIC_fnc_removeEventHandler;
_eventHandlerId = _handlerParams call AIC_fnc_addEventHandler;
_eventHandlers set [_index,[_eventHandlerId,_handlerParams]];
_index = _index + 1;
} forEach _eventHandlers;
sleep (5 * 60);
};
};
32 changes: 32 additions & 0 deletions AICommand/functions/eventHandler/fn_removeEventHandler.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include "..\functions.h"

/*
Author: [SA] Duda
Description:
Remove an event handler
Parameter(s):
_this select 0: STRING - Event handler type ("MAIN_DISPLAY","MAP_DISPLAY","MAP_CONTROL")
_this select 1: STRING - Event type (e.g. "KeyDown")
_this select 2: NUMBER - Event handler id
Returns:
Nothing
*/

params ["_handlerType","_eventType","_eventHandlerId"];

waitUntil {!isNull AIC_MAP_CONTROL && !isNull AIC_MAIN_DISPLAY && !isNull AIC_MAP_DISPLAY};

if(_eventHandlerId >= 0) then {
if(_handlerType == "MAIN_DISPLAY") then {
AIC_MAIN_DISPLAY displayRemoveEventHandler [_eventType, _eventHandlerId];
};
if(_handlerType == "MAP_DISPLAY") then {
AIC_MAP_DISPLAY displayRemoveEventHandler [_eventType, _eventHandlerId];
};
if(_handlerType == "MAP_CONTROL") then {
AIC_MAP_CONTROL ctrlRemoveEventHandler [_eventType, _eventHandlerId];
};
};
3 changes: 3 additions & 0 deletions AICommand/functions/eventHandler/functions.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

#define AIC_fnc_getEventHandlers() missionNamespace getVariable ["AIC_Event_Handlers",[]]
#define AIC_fnc_setEventHandlers(_eventHandlers) missionNamespace setVariable ["AIC_Event_Handlers",(_eventHandlers)]
1 change: 1 addition & 0 deletions AICommand/functions/fn_initAICommand.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ params [["_autoConfigureCommanders",true]];
[] call AIC_fnc_inputControlManager;
[] call AIC_fnc_commandMenuManager;
[] call AIC_fnc_commandMenuActionsInit;
[] call AIC_fnc_eventHandlerManager;

AIC_INIT_STARTUP_SCRIPTS_EXECUTED = true;

Expand Down
2 changes: 2 additions & 0 deletions AICommand/functions/functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include "mapElements\functions.h"
#include "mapIcon\functions.h"
#include "vehicleIcon\functions.h"
#include "eventHandler\functions.h"
#include "remoteCamera\functions.h"

#define AIC_MAP_CONTROL (findDisplay 12 displayCtrl 51)
#define AIC_MAP_DISPLAY (findDisplay 12)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,7 @@ if(hasInterface) then {

// Setup UI event handlers

[] spawn {
waitUntil {!isNull AIC_MAP_CONTROL};
AIC_MAP_CONTROL ctrlAddEventHandler ["Draw", "_this call AIC_fnc_commandControlDrawHandler" ];
};
["MAP_CONTROL","Draw", "_this call AIC_fnc_commandControlDrawHandler"] spawn AIC_fnc_addManagedEventHandler;

// Check for command control group controls revision changes
[] spawn {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,10 @@ if(isDedicated || !hasInterface) exitWith {};

// Setup UI event handlers

[] spawn {
waitUntil {!isNull AIC_MAP_CONTROL};
AIC_MAP_CONTROL ctrlAddEventHandler ["MouseButtonDown", "[nil, ""MouseButtonDown"",_this] call AIC_fnc_groupControlEventHandler" ];
AIC_MAP_CONTROL ctrlAddEventHandler ["MouseButtonClick", "[nil, ""MouseButtonClick"",_this] call AIC_fnc_groupControlEventHandler" ];
AIC_MAP_CONTROL ctrlAddEventHandler ["MouseMoving", "[nil, ""MouseMoving"",_this] call AIC_fnc_groupControlEventHandler" ];
AIC_MAP_CONTROL ctrlAddEventHandler ["MouseHolding", "[nil, ""MouseHolding"",_this] call AIC_fnc_groupControlEventHandler" ];
};
["MAP_CONTROL","MouseButtonDown", "[nil, ""MouseButtonDown"",_this] call AIC_fnc_groupControlEventHandler"] spawn AIC_fnc_addManagedEventHandler;
["MAP_CONTROL","MouseButtonClick", "[nil, ""MouseButtonClick"",_this] call AIC_fnc_groupControlEventHandler"] spawn AIC_fnc_addManagedEventHandler;
["MAP_CONTROL","MouseMoving", "[nil, ""MouseMoving"",_this] call AIC_fnc_groupControlEventHandler"] spawn AIC_fnc_addManagedEventHandler;
["MAP_CONTROL","MouseHolding", "[nil, ""MouseHolding"",_this] call AIC_fnc_groupControlEventHandler"] spawn AIC_fnc_addManagedEventHandler;

// Manage updates to group waypoints

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,9 @@ if(isDedicated || !hasInterface) exitWith {};

// Setup UI event handlers

[] spawn {
waitUntil {!isNull AIC_MAP_CONTROL};
AIC_MAP_CONTROL ctrlAddEventHandler ["MouseButtonDown", "[nil, ""MouseButtonDown"",_this] call AIC_fnc_inputControlEventHandler" ];
AIC_MAP_CONTROL ctrlAddEventHandler ["MouseButtonClick", "[nil, ""MouseButtonClick"",_this] call AIC_fnc_inputControlEventHandler" ];
};

[] spawn {
waitUntil {!isNull AIC_MAIN_DISPLAY};
AIC_MAIN_DISPLAY displayAddEventHandler ["KeyDown", "[nil, ""KeyDown"",_this] call AIC_fnc_inputControlEventHandler" ];
};

["MAP_CONTROL","MouseButtonDown", "[nil, ""MouseButtonDown"",_this] call AIC_fnc_inputControlEventHandler"] spawn AIC_fnc_addManagedEventHandler;
["MAP_CONTROL","MouseButtonClick", "[nil, ""MouseButtonClick"",_this] call AIC_fnc_inputControlEventHandler"] spawn AIC_fnc_addManagedEventHandler;
["MAIN_DISPLAY","KeyDown", "[nil, ""KeyDown"",_this] call AIC_fnc_inputControlEventHandler"] spawn AIC_fnc_addManagedEventHandler;



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,9 @@

if(isDedicated || !hasInterface) exitWith {};

[] spawn {
waitUntil {!isNull AIC_MAP_CONTROL};
AIC_MAP_CONTROL ctrlAddEventHandler ["MouseButtonClick", "[""MouseButtonClick"",_this] call AIC_fnc_interactiveIconEventHandler" ];
AIC_MAP_CONTROL ctrlAddEventHandler ["MouseMoving", "[""MouseMoving"",_this] call AIC_fnc_interactiveIconEventHandler" ];
AIC_MAP_CONTROL ctrlAddEventHandler ["MouseButtonDown", "[""MouseButtonDown"",_this] call AIC_fnc_interactiveIconEventHandler" ];
AIC_MAP_CONTROL ctrlAddEventHandler ["MouseButtonUp", "[""MouseButtonUp"",_this] call AIC_fnc_interactiveIconEventHandler" ];
AIC_MAP_CONTROL ctrlAddEventHandler ["MouseHolding", "[""MouseHolding"",_this] call AIC_fnc_interactiveIconEventHandler" ];
};

[] spawn {
waitUntil {!isNull AIC_MAP_DISPLAY};
AIC_MAP_DISPLAY displayAddEventHandler ["KeyDown", "[""KeyDownDisplay"",_this] call AIC_fnc_interactiveIconEventHandler" ];
};
["MAP_CONTROL","MouseButtonClick", "[""MouseButtonClick"",_this] call AIC_fnc_interactiveIconEventHandler"] spawn AIC_fnc_addManagedEventHandler;
["MAP_CONTROL","MouseMoving", "[""MouseMoving"",_this] call AIC_fnc_interactiveIconEventHandler"] spawn AIC_fnc_addManagedEventHandler;
["MAP_CONTROL","MouseButtonDown", "[""MouseButtonDown"",_this] call AIC_fnc_interactiveIconEventHandler"] spawn AIC_fnc_addManagedEventHandler;
["MAP_CONTROL","MouseButtonUp", "[""MouseButtonUp"",_this] call AIC_fnc_interactiveIconEventHandler"] spawn AIC_fnc_addManagedEventHandler;
["MAP_CONTROL","MouseHolding", "[""MouseHolding"",_this] call AIC_fnc_interactiveIconEventHandler"] spawn AIC_fnc_addManagedEventHandler;
["MAP_DISPLAY","KeyDown", "[""KeyDownDisplay"",_this] call AIC_fnc_interactiveIconEventHandler"] spawn AIC_fnc_addManagedEventHandler;
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include "..\functions.h"
private ["_cam","_distance","_target"];
AIC_3rd_Person_Camera_X_Move_Total = AIC_FNC_CAMERA_X_TOTAL + (-(_this select 1)*0.16);
AIC_3rd_Person_Camera_Y_Move_Total = AIC_FNC_CAMERA_Y_TOTAL + (-(_this select 2)*0.16);
AIC_3rd_Person_Camera_Y_Move_Total = AIC_FNC_CAMERA_Y_TOTAL max 20 min 160;
[] spawn AIC_fnc_cameraUpdatePosition;
Loading

0 comments on commit 9e6f95f

Please sign in to comment.