Skip to content

Commit ce592fc

Browse files
authored
Area Markers - Support editing all area markers (#676)
1 parent aa026ae commit ce592fc

18 files changed

+252
-110
lines changed

addons/area_markers/XEH_PREP.hpp

+7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
PREP(applyProperties);
22
PREP(configure);
33
PREP(createIcon);
4+
PREP(createMarker);
45
PREP(deleteIcon);
6+
PREP(initDisplayCurator);
7+
PREP(isEditable);
58
PREP(module);
69
PREP(onDraw);
710
PREP(onKeyDown);
11+
PREP(onMapToggled);
12+
PREP(onMarkerCreated);
13+
PREP(onMarkerDeleted);
14+
PREP(onMarkerUpdated);
815
PREP(onMouseButtonDown);
916
PREP(onMouseButtonUp);
1017
PREP(onMouseDblClick);

addons/area_markers/XEH_postInit.sqf

+17-75
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,24 @@
11
#include "script_component.hpp"
22

33
if (isServer) then {
4-
[QGVAR(create), {
5-
params ["_position"];
6-
7-
private _marker = createMarker [format [QGVAR(%1), GVAR(nextID)], _position];
8-
_marker setMarkerShape "RECTANGLE";
9-
_marker setMarkerSize [50, 50];
10-
11-
GVAR(markers) pushBack _marker;
12-
publicVariable QGVAR(markers);
13-
14-
GVAR(nextID) = GVAR(nextID) + 1;
15-
16-
[QGVAR(createIcon), _marker] call CBA_fnc_globalEvent;
17-
}] call CBA_fnc_addEventHandler;
18-
19-
[QGVAR(delete), {
20-
params ["_marker"];
21-
22-
private _index = GVAR(markers) find _marker;
23-
24-
if (_index != -1) then {
25-
GVAR(markers) deleteAt _index;
26-
publicVariable QGVAR(markers);
27-
28-
deleteMarker _marker;
29-
30-
[QGVAR(deleteIcon), _marker] call CBA_fnc_globalEvent;
31-
};
32-
}] call CBA_fnc_addEventHandler;
4+
[QGVAR(createMarker), LINKFUNC(createMarker)] call CBA_fnc_addEventHandler;
335
};
346

357
if (hasInterface) then {
36-
["zen_curatorDisplayLoaded", {
37-
params ["_display"];
38-
39-
// Namespace of marker names and their corresponding icon controls
40-
if (isNil QGVAR(icons)) then {
41-
GVAR(icons) = [] call CBA_fnc_createNamespace;
42-
};
43-
44-
// Add EH to update area marker icon positions when the map is shown
45-
private _ctrlMap = _display displayCtrl IDC_RSCDISPLAYCURATOR_MAINMAP;
46-
_ctrlMap ctrlAddEventHandler ["Draw", {call FUNC(onDraw)}];
47-
48-
// Add EH to handle deleting area marker by pressing the DELETE key
49-
_display displayAddEventHandler ["KeyDown", {call FUNC(onKeyDown)}];
50-
51-
// Create area marker icons for all area markers
52-
{
53-
{
54-
[_x] call FUNC(createIcon);
55-
} forEach GVAR(markers);
56-
} call CBA_fnc_execNextFrame;
57-
58-
// Add PFH to update visibility of area marker icons
59-
GVAR(visiblePFH) = [{
60-
params ["_args"];
61-
_args params ["_visible"];
62-
63-
if (_visible isEqualTo visibleMap) exitWith {};
64-
65-
_visible = visibleMap;
66-
{
67-
private _ctrlIcon = GVAR(icons) getVariable [_x, controlNull];
68-
_ctrlIcon ctrlShow _visible;
69-
} forEach GVAR(markers);
70-
71-
_args set [0, _visible];
72-
}, 0, [visibleMap]] call CBA_fnc_addPerFrameHandler;
73-
}] call CBA_fnc_addEventHandler;
74-
75-
["zen_curatorDisplayUnloaded", {
76-
GVAR(visiblePFH) call CBA_fnc_removePerFrameHandler;
77-
}] call CBA_fnc_addEventHandler;
78-
79-
[QGVAR(createIcon), LINKFUNC(createIcon)] call CBA_fnc_addEventHandler;
80-
[QGVAR(deleteIcon), LINKFUNC(deleteIcon)] call CBA_fnc_addEventHandler;
81-
[QGVAR(updateIcon), LINKFUNC(updateIcon)] call CBA_fnc_addEventHandler;
8+
["zen_curatorDisplayLoaded", LINKFUNC(initDisplayCurator)] call CBA_fnc_addEventHandler;
9+
10+
// Add EHs to update visibility of area marker icons when the map is toggled
11+
// Need both activate and deactivate to deal with issues around rapidly toggling the map
12+
addUserActionEventHandler ["showMap", "Activate", {call FUNC(onMapToggled)}];
13+
addUserActionEventHandler ["showMap", "Deactivate", {call FUNC(onMapToggled)}];
14+
15+
// Add EHs to automatically make any area markers editable
16+
addMissionEventHandler ["MarkerCreated", {call FUNC(onMarkerCreated)}];
17+
addMissionEventHandler ["MarkerDeleted", {call FUNC(onMarkerDeleted)}];
18+
addMissionEventHandler ["MarkerUpdated", {call FUNC(onMarkerUpdated)}];
19+
20+
// Manually trigger event for 3DEN placed and already existent (JIP) markers
21+
{
22+
_x call FUNC(onMarkerCreated);
23+
} forEach allMapMarkers;
8224
};

addons/area_markers/XEH_preInit.sqf

+13-7
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,26 @@ PREP_RECOMPILE_START;
77
PREP_RECOMPILE_END;
88

99
if (isServer) then {
10-
GVAR(markers) = [];
11-
publicVariable QGVAR(markers);
12-
10+
// Unique ID for creating markers
1311
GVAR(nextID) = 0;
1412
};
1513

1614
if (hasInterface) then {
17-
GVAR(colors) = [] call CBA_fnc_createNamespace;
15+
GVAR(colors) = createHashMap;
1816

1917
{
20-
if (getNumber (_x >> "scope") > 0) then {
21-
GVAR(colors) setVariable [configName _x, (_x >> "color") call BIS_fnc_colorConfigToRGBA];
22-
};
18+
GVAR(colors) set [configName _x, (_x >> "color") call BIS_fnc_colorConfigToRGBA];
2319
} forEach configProperties [configFile >> "CfgMarkerColors", "isClass _x"];
20+
21+
// List of editable area markers
22+
GVAR(markers) = [];
23+
24+
// List of marker names that are blacklisted from being edited through Zeus
25+
// A marker is blacklisted if its name contains any of strings in this list
26+
GVAR(blacklist) = [];
27+
28+
// Map of marker names and their corresponding icon controls
29+
GVAR(icons) = createHashMap;
2430
};
2531

2632
ADDON = true;

addons/area_markers/functions/fnc_applyProperties.sqf

-2
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,3 @@ _marker setMarkerColor _color;
4242
private _ctrlAlphaSlider = _ctrlConfigure controlsGroupCtrl IDC_CONFIGURE_ALPHA_SLIDER;
4343
private _alpha = sliderPosition _ctrlAlphaSlider;
4444
_marker setMarkerAlpha _alpha;
45-
46-
[QGVAR(updateIcon), [_marker, _rotation, _color]] call CBA_fnc_globalEvent;

addons/area_markers/functions/fnc_configure.sqf

+4
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,10 @@ private _keyDownEH = _display displayAddEventHandler ["KeyDown", {
162162
_display displayRemoveEventHandler ["KeyDown", _keyDownEH];
163163

164164
ctrlDelete _ctrlConfigure;
165+
166+
// Despite returning true to override default handling, pressing ESCAPE
167+
// appears to be hard coded to close the map
168+
call FUNC(onMapToggled);
165169
};
166170

167171
true // handled

addons/area_markers/functions/fnc_createIcon.sqf

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ private _ctrlIcon = _display ctrlCreate [QGVAR(icon), IDC_ICON_GROUP];
2424
_ctrlIcon setVariable [QGVAR(marker), _marker];
2525
_ctrlIcon ctrlShow visibleMap;
2626

27-
GVAR(icons) setVariable [_marker, _ctrlIcon];
27+
GVAR(icons) set [_marker, _ctrlIcon];
2828

29-
[_marker, markerDir _marker, markerColor _marker] call FUNC(updateIcon);
29+
_marker call FUNC(updateIcon);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include "script_component.hpp"
2+
/*
3+
* Author: mharis001
4+
* Creates an area marker.
5+
* Should only be called on the server for unique marker names.
6+
*
7+
* Arguments:
8+
* 0: Position <ARRAY>
9+
*
10+
* Return Value:
11+
* None
12+
*
13+
* Example:
14+
* [[0, 0, 0]] call zen_area_markers_fnc_createMarker
15+
*
16+
* Public: No
17+
*/
18+
19+
params ["_position"];
20+
21+
private _marker = createMarker [format [QGVAR(%1), GVAR(nextID)], _position];
22+
_marker setMarkerShape "RECTANGLE";
23+
_marker setMarkerSize [50, 50];
24+
25+
GVAR(nextID) = GVAR(nextID) + 1;

addons/area_markers/functions/fnc_deleteIcon.sqf

+4-6
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@
1717

1818
params ["_marker"];
1919

20-
private _ctrlIcon = GVAR(icons) getVariable _marker;
21-
if (isNil "_ctrlIcon" || {isNull _ctrlIcon}) exitWith {};
22-
23-
GVAR(icons) setVariable [_marker, nil];
24-
25-
ctrlDelete _ctrlIcon;
20+
if (_marker in GVAR(icons)) then {
21+
ctrlDelete (GVAR(icons) get _marker);
22+
GVAR(icons) deleteAt _marker;
23+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#include "script_component.hpp"
2+
/*
3+
* Author: mharis001
4+
* Initializes the Zeus display.
5+
*
6+
* Arguments:
7+
* 0: Display <DISPLAY>
8+
*
9+
* Return Value:
10+
* None
11+
*
12+
* Example:
13+
* [DISPLAY] call zen_area_markers_fnc_initDisplayCurator
14+
*
15+
* Public: No
16+
*/
17+
18+
params ["_display"];
19+
20+
// Add EH to update area marker icon positions when the map is shown
21+
private _ctrlMap = _display displayCtrl IDC_RSCDISPLAYCURATOR_MAINMAP;
22+
_ctrlMap ctrlAddEventHandler ["Draw", {call FUNC(onDraw)}];
23+
24+
// Add EH to handle deleting area marker by pressing the DELETE key
25+
_display displayAddEventHandler ["KeyDown", {call FUNC(onKeyDown)}];
26+
27+
// Create area marker icons for all area markers
28+
{
29+
{
30+
[_x] call FUNC(createIcon);
31+
} forEach GVAR(markers);
32+
} call CBA_fnc_execNextFrame;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include "script_component.hpp"
2+
/*
3+
* Author: mharis001
4+
* Checks if the given marker is an editable area marker.
5+
*
6+
* Arguments:
7+
* 0: Marker <STRING>
8+
*
9+
* Return Value:
10+
* Is Editable <BOOL>
11+
*
12+
* Example:
13+
* ["marker_0"] call zen_area_markers_fnc_isEditable
14+
*
15+
* Public: No
16+
*/
17+
18+
params ["_marker"];
19+
20+
markerShape _marker in ["RECTANGLE", "ELLIPSE"] && {GVAR(blacklist) findIf {_x in _marker} == -1}

addons/area_markers/functions/fnc_onDraw.sqf

+4-8
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,10 @@ BEGIN_COUNTER(onDraw);
2020
params ["_ctrlMap"];
2121

2222
{
23-
private _ctrlIcon = GVAR(icons) getVariable _x;
23+
(_ctrlMap ctrlMapWorldToScreen markerPos _x) params ["_posX", "_posY"];
2424

25-
if (!isNil "_ctrlIcon") then {
26-
(_ctrlMap ctrlMapWorldToScreen markerPos _x) params ["_posX", "_posY"];
27-
28-
_ctrlIcon ctrlSetPosition [_posX - OFFSET_X, _posY - OFFSET_Y];
29-
_ctrlIcon ctrlCommit 0;
30-
};
31-
} forEach GVAR(markers);
25+
_y ctrlSetPosition [_posX - OFFSET_X, _posY - OFFSET_Y];
26+
_y ctrlCommit 0;
27+
} forEach GVAR(icons);
3228

3329
END_COUNTER(onDraw);

addons/area_markers/functions/fnc_onKeyDown.sqf

+8-1
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,18 @@ if (visibleMap && {_keyCode == DIK_DELETE}) exitWith {
2323
ctrlMapMouseOver _ctrlMap params [["_type", ""], ["_marker", ""]];
2424

2525
if (_type == "marker" && {_marker in GVAR(markers)}) exitWith {
26-
[QGVAR(delete), _marker] call CBA_fnc_serverEvent;
26+
deleteMarker _marker;
2727
true
2828
};
2929

3030
false
3131
};
3232

33+
// Map visibility can be toggled with the ESCAPE key
34+
// Appears to be hard coded and independent of the "ingamePause" user action
35+
// Also, update the icons when the interface's visibility is toggled
36+
if (_keyCode == DIK_ESCAPE || {_keyCode in actionKeys "curatorToggleInterface"}) then {
37+
call FUNC(onMapToggled);
38+
};
39+
3340
false
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include "script_component.hpp"
2+
/*
3+
* Author: mharis001
4+
* Handles toggling the Zeus display's map.
5+
*
6+
* Arguments:
7+
* None
8+
*
9+
* Return Value:
10+
* None
11+
*
12+
* Example:
13+
* [] call zen_area_markers_fnc_onMapToggled
14+
*
15+
* Public: No
16+
*/
17+
18+
if (isNull findDisplay IDD_RSCDISPLAYCURATOR) exitWith {};
19+
20+
// Need frame delay because both the visisbleMap and the map control's
21+
// visibility are not updated until the next frame
22+
{
23+
private _show = visibleMap && {!call EFUNC(common,isInScreenshotMode)};
24+
25+
{
26+
_y ctrlShow _show;
27+
} forEach GVAR(icons);
28+
} call CBA_fnc_execNextFrame;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include "script_component.hpp"
2+
/*
3+
* Author: mharis001
4+
* Handles creating a marker.
5+
*
6+
* Arguments:
7+
* 0: Marker <STRING>
8+
*
9+
* Return Value:
10+
* None
11+
*
12+
* Example:
13+
* ["marker_0"] call zen_area_markers_fnc_onMarkerCreated
14+
*
15+
* Public: No
16+
*/
17+
18+
params ["_marker"];
19+
20+
if (_marker call FUNC(isEditable)) then {
21+
GVAR(markers) pushBack _marker;
22+
_marker call FUNC(createIcon);
23+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include "script_component.hpp"
2+
/*
3+
* Author: mharis001
4+
* Handles deleting a marker.
5+
*
6+
* Arguments:
7+
* 0: Marker <STRING>
8+
*
9+
* Return Value:
10+
* None
11+
*
12+
* Example:
13+
* ["marker_0"] call zen_area_markers_fnc_onMarkerDeleted
14+
*
15+
* Public: No
16+
*/
17+
18+
params ["_marker"];
19+
20+
GVAR(markers) deleteAt (GVAR(markers) find _marker);
21+
_marker call FUNC(deleteIcon);

0 commit comments

Comments
 (0)