-
Notifications
You must be signed in to change notification settings - Fork 149
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #505 from CBATeam/add-marker-event-handler
add event handler for creating and deleting markers
- Loading branch information
Showing
3 changed files
with
96 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* ---------------------------------------------------------------------------- | ||
Function: CBA_fnc_addMarkerEventHandler | ||
Description: | ||
Adds an event handler that executes code when a marker is created or deleted. | ||
Parameters: | ||
_eventType - Type of event to add. Can be "created" or "deleted". <STRING> | ||
_function - Function to call when marker is created or deleted. <CODE> | ||
Returns: | ||
_eventId - Unique ID. Used with 'CBA_fnc_removeMarkerEventHandler'. | ||
Examples: | ||
(begin example) | ||
_id = ["created", {systemChat str _this}] call CBA_fnc_addMarkerEventHandler; | ||
(end) | ||
Author: | ||
commy2 | ||
---------------------------------------------------------------------------- */ | ||
#include "script_component.hpp" | ||
SCRIPT(addMarkerEventHandler); | ||
|
||
params [["_eventType", "", [""]], ["_function", {}, [{}]]]; | ||
|
||
if (isNil QGVAR(oldMarkers)) then { | ||
GVAR(oldMarkers) = allMapMarkers; | ||
|
||
[{ | ||
private _newAllMapMarkers = allMapMarkers; | ||
if !(_newAllMapMarkers isEqualTo GVAR(oldMarkers)) then { | ||
params ["_events"]; | ||
|
||
{ | ||
[QGVAR(markerDeleted), [_x]] call CBA_fnc_localEvent; | ||
} forEach (GVAR(oldMarkers) - _newAllMapMarkers); | ||
|
||
{ | ||
[QGVAR(markerCreated), [_x]] call CBA_fnc_localEvent; | ||
} forEach (_newAllMapMarkers - GVAR(oldMarkers)); | ||
|
||
GVAR(oldMarkers) = _newAllMapMarkers; | ||
}; | ||
}, 0] call CBA_fnc_addPerFrameHandler; | ||
}; | ||
|
||
if (_function isEqualTo {}) exitWith {-1}; | ||
|
||
switch (toLower _eventType) do { | ||
case "created": { | ||
[QGVAR(markerCreated), _function] call CBA_fnc_addEventHandler // return | ||
}; | ||
case "deleted": { | ||
[QGVAR(markerDeleted), _function] call CBA_fnc_addEventHandler // return | ||
}; | ||
default {-1}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* ---------------------------------------------------------------------------- | ||
Function: CBA_fnc_removeMarkerEventHandler | ||
Description: | ||
Removes an event handler previously registered with 'CBA_fnc_addMarkerEventHandler'. | ||
Parameters: | ||
_eventName - Type of event to remove. Can be "created" or "deleted". <STRING> | ||
_eventId - Unique ID of the event handler to remove. <NUMBER> | ||
Returns: | ||
None | ||
Examples: | ||
(begin example) | ||
["created", _id] call CBA_fnc_removeMarkerEventHandler; | ||
(end) | ||
Author: | ||
commy2 | ||
---------------------------------------------------------------------------- */ | ||
#include "script_component.hpp" | ||
SCRIPT(removeMarkerEventHandler); | ||
|
||
params [["_eventType", "", [""]], ["_eventId", -1, [0]]]; | ||
|
||
switch (toLower _eventType) do { | ||
case "created": { | ||
[QGVAR(markerCreated), _eventId] call CBA_fnc_removeEventHandler; | ||
}; | ||
case "deleted": { | ||
[QGVAR(markerDeleted), _eventId] call CBA_fnc_removeEventHandler; | ||
}; | ||
}; | ||
|
||
nil |