Skip to content

Commit

Permalink
Area Markers - Only allow editing when in markers mode (#765)
Browse files Browse the repository at this point in the history
  • Loading branch information
mharis001 authored Jul 14, 2024
1 parent 0c21be4 commit 2b1a22b
Show file tree
Hide file tree
Showing 21 changed files with 129 additions and 74 deletions.
6 changes: 4 additions & 2 deletions addons/area_markers/XEH_PREP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@ PREP(configure);
PREP(createIcon);
PREP(createMarker);
PREP(deleteIcon);
PREP(initDisplayCurator);
PREP(isEditable);
PREP(isInEditMode);
PREP(onDraw);
PREP(onKeyDown);
PREP(onMapToggled);
PREP(onLoad);
PREP(onMarkerCreated);
PREP(onMarkerDeleted);
PREP(onMarkerUpdated);
PREP(onMouseButtonDown);
PREP(onMouseButtonUp);
PREP(onMouseDblClick);
PREP(onMouseMoving);
PREP(onUnload);
PREP(onVisibilityPFH);
PREP(updateIcon);
8 changes: 2 additions & 6 deletions addons/area_markers/XEH_postInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,8 @@ if (isServer) then {
};

if (hasInterface) then {
["zen_curatorDisplayLoaded", LINKFUNC(initDisplayCurator)] call CBA_fnc_addEventHandler;

// Add EHs to update visibility of area marker icons when the map is toggled
// Need both activate and deactivate to deal with issues around rapidly toggling the map
addUserActionEventHandler ["showMap", "Activate", {call FUNC(onMapToggled)}];
addUserActionEventHandler ["showMap", "Deactivate", {call FUNC(onMapToggled)}];
["zen_curatorDisplayLoaded", LINKFUNC(onLoad)] call CBA_fnc_addEventHandler;
["zen_curatorDisplayUnloaded", LINKFUNC(onUnload)] call CBA_fnc_addEventHandler;

// Add EHs to automatically make any area markers editable
addMissionEventHandler ["MarkerCreated", {call FUNC(onMarkerCreated)}];
Expand Down
4 changes: 0 additions & 4 deletions addons/area_markers/functions/fnc_configure.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,6 @@ private _keyDownEH = _display displayAddEventHandler ["KeyDown", {
_display displayRemoveEventHandler ["KeyDown", _keyDownEH];

ctrlDelete _ctrlConfigure;

// Despite returning true to override default handling, pressing ESCAPE
// appears to be hard coded to close the map
call FUNC(onMapToggled);
};

true // handled
Expand Down
2 changes: 1 addition & 1 deletion addons/area_markers/functions/fnc_createIcon.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ if (isNull _display) exitWith {};

private _ctrlIcon = _display ctrlCreate [QGVAR(icon), IDC_ICON_GROUP];
_ctrlIcon setVariable [QGVAR(marker), _marker];
_ctrlIcon ctrlShow visibleMap;
_ctrlIcon ctrlShow call FUNC(isInEditMode);

GVAR(icons) set [_marker, _ctrlIcon];

Expand Down
21 changes: 21 additions & 0 deletions addons/area_markers/functions/fnc_isInEditMode.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include "script_component.hpp"
/*
* Author: mharis001
* Checks if the Zeus display is in marker editing mode.
*
* Arguments:
* None
*
* Return Value:
* In Marker Editing Mode <BOOL>
*
* Example:
* [] call zen_area_markers_fnc_isInEditMode
*
* Public: No
*/

visibleMap
&& {!dialog}
&& {!call EFUNC(common,isInScreenshotMode)}
&& {RscDisplayCurator_sections select 0 == CURATOR_MODE_MARKERS}
7 changes: 0 additions & 7 deletions addons/area_markers/functions/fnc_onKeyDown.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,4 @@ if (visibleMap && {_keyCode == DIK_DELETE}) exitWith {
false
};

// Map visibility can be toggled with the ESCAPE key
// Appears to be hard coded and independent of the "ingamePause" user action
// Also, update the icons when the interface's visibility is toggled
if (_keyCode == DIK_ESCAPE || {_keyCode in actionKeys "curatorToggleInterface"}) then {
call FUNC(onMapToggled);
};

false
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "script_component.hpp"
/*
* Author: mharis001
* Initializes the Zeus display.
* Handles initializing the Zeus Display.
*
* Arguments:
* 0: Display <DISPLAY>
Expand All @@ -10,7 +10,7 @@
* None
*
* Example:
* [DISPLAY] call zen_area_markers_fnc_initDisplayCurator
* [DISPLAY] call zen_area_markers_fnc_onLoad
*
* Public: No
*/
Expand All @@ -24,6 +24,9 @@ _ctrlMap ctrlAddEventHandler ["Draw", {call FUNC(onDraw)}];
// Add EH to handle deleting area marker by pressing the DELETE key
_display displayAddEventHandler ["KeyDown", {call FUNC(onKeyDown)}];

// Add PFH to update visibility of area marker icons
GVAR(visibilityPFH) = [LINKFUNC(onVisibilityPFH), 0, [false]] call CBA_fnc_addPerFrameHandler;

// Create area marker icons for all area markers
{
{
Expand Down
28 changes: 0 additions & 28 deletions addons/area_markers/functions/fnc_onMapToggled.sqf

This file was deleted.

19 changes: 19 additions & 0 deletions addons/area_markers/functions/fnc_onUnload.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include "script_component.hpp"
/*
* Author: mharis001
* Handles unloading the Zeus Display.
*
* Arguments:
* 0: Display (not used) <DISPLAY>
*
* Return Value:
* None
*
* Example:
* [DISPLAY] call zen_area_markers_fnc_onUnload
*
* Public: No
*/

GVAR(visibilityPFH) call CBA_fnc_removePerFrameHandler;
GVAR(visibilityPFH) = nil;
34 changes: 34 additions & 0 deletions addons/area_markers/functions/fnc_onVisibilityPFH.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include "script_component.hpp"
/*
* Author: mharis001
* Handles updating the visibility of area marker icons.
*
* Arguments:
* 0: Arguments <ARRAY>
* 0: Current Visibility <BOOL>
*
* Return Value:
* None
*
* Example:
* [[false]] call zen_area_markers_fnc_onVisibilityPFH
*
* Public: No
*/

BEGIN_COUNTER(onVisibilityPFH);

params ["_args"];
_args params ["_oldVisibility"];

private _newVisibility = call FUNC(isInEditMode);

if (_oldVisibility isNotEqualTo _newVisibility) then {
{
_y ctrlShow _newVisibility;
} forEach GVAR(icons);

_args set [0, _newVisibility];
};

END_COUNTER(onVisibilityPFH);
2 changes: 1 addition & 1 deletion addons/area_markers/gui.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class GVAR(icon): RscControlsGroupNoScrollbars {
w = QUOTE(ICON_WIDTH);
h = QUOTE(ICON_HEIGHT);
class controls {
class Icon: RscPicture {
class Image: RscPicture {
idc = IDC_ICON_IMAGE;
text = ICON_CENTER;
x = 0;
Expand Down
20 changes: 10 additions & 10 deletions addons/common/functions/fnc_getActiveTree.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,20 @@ if (isNull _display) exitWith {controlNull};
RscDisplayCurator_sections params ["_mode", "_side"];

private _treeIDC = switch (_mode) do {
case 0: {
IDCS_UNIT_TREES select _side;
case CURATOR_MODE_UNITS: {
IDCS_UNIT_TREES select _side
};
case 1: {
IDCS_GROUP_TREES select _side;
case CURATOR_MODE_GROUPS: {
IDCS_GROUP_TREES select _side
};
case 2: {
IDC_RSCDISPLAYCURATOR_CREATE_MODULES;
case CURATOR_MODE_MODULES: {
IDC_RSCDISPLAYCURATOR_CREATE_MODULES
};
case 3: {
IDC_RSCDISPLAYCURATOR_CREATE_MARKERS;
case CURATOR_MODE_MARKERS: {
IDC_RSCDISPLAYCURATOR_CREATE_MARKERS
};
case 4: {
IDC_RSCDISPLAYCURATOR_CREATE_RECENT;
case CURATOR_MODE_RECENT: {
IDC_RSCDISPLAYCURATOR_CREATE_RECENT
};
};

Expand Down
1 change: 0 additions & 1 deletion addons/common/functions/fnc_isPlacementActive.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,4 @@ RscDisplayCurator_sections params ["_mode"];

// Get the path length necessary for placement based on the current mode
private _pathLength = [3, 4, 2, 1, 1] select _mode;

count tvCurSel call FUNC(getActiveTree) == _pathLength
2 changes: 1 addition & 1 deletion addons/compositions/functions/fnc_initDisplayCurator.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
};

// Initially hide the custom compositions panel if the compositions tree is not active
if (GETMVAR(RscDisplayCurator_sections,[]) isNotEqualTo [1, 4]) then {
if (GETMVAR(RscDisplayCurator_sections,[]) isNotEqualTo [CURATOR_MODE_GROUPS, CURATOR_SIDE_EMPTY]) then {
private _ctrlPanel = _display displayCtrl IDC_PANEL_GROUP;
_ctrlPanel ctrlShow false;
};
Expand Down
2 changes: 1 addition & 1 deletion addons/editor/functions/fnc_handleLoad.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ _display displayAddEventHandler ["KeyUp", {call FUNC(handleKeyUp)}];
{
private _ctrl = _display displayCtrl _x;
_ctrl ctrlAddEventHandler ["MouseButtonDown", {
if (RscDisplayCurator_sections select 0 == 1) then {
if (RscDisplayCurator_sections select 0 == CURATOR_MODE_GROUPS) then {
private _ctrlTree = call EFUNC(common,getActiveTree);
private _path = tvCurSel _ctrlTree;

Expand Down
8 changes: 7 additions & 1 deletion addons/editor/functions/fnc_handleObjectPlaced.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,13 @@ if (!GVAR(iconsVisible)) then {

RscDisplayCurator_sections params ["_mode"];

if (!GVAR(includeCrew) && {_mode == 0 || {_mode == 4 && {isClass (configFile >> "CfgVehicles" >> GVAR(recentTreeData))}}}) then {
if (
!GVAR(includeCrew)
&& {
_mode == CURATOR_MODE_UNITS
|| {_mode == CURATOR_MODE_RECENT && {isClass (configFile >> "CfgVehicles" >> GVAR(recentTreeData))}}
}
) then {
deleteVehicleCrew _object;
};

Expand Down
4 changes: 2 additions & 2 deletions addons/editor/functions/fnc_handleTreeButtons.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ params ["", "_expand"];
RscDisplayCurator_sections params ["_mode"];

// Can't collapse or expand marker or recent trees
if (_mode > 2) exitWith {};
if (_mode > CURATOR_MODE_MODULES) exitWith {};

// Collapse or expand current tree
private _ctrlTree = call EFUNC(common,getActiveTree);
Expand All @@ -32,7 +32,7 @@ if (_expand) then {
_ctrlTree call EFUNC(common,collapseTree);

// For QOL, keep factions of group trees visible
if (_mode == 1) then {
if (_mode == CURATOR_MODE_GROUPS) then {
_ctrlTree tvExpand [0];
};
};
18 changes: 18 additions & 0 deletions addons/main/script_curator.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Create Tree Tabs (Modes and Sides)
#define CURATOR_MODE_UNITS 0
#define CURATOR_MODE_GROUPS 1
#define CURATOR_MODE_MODULES 2
#define CURATOR_MODE_MARKERS 3
#define CURATOR_MODE_RECENT 4

#define CURATOR_SIDE_BLUFOR 0
#define CURATOR_SIDE_OPFOR 1
#define CURATOR_SIDE_INDEPENDENT 2
#define CURATOR_SIDE_CIVILIAN 3
#define CURATOR_SIDE_EMPTY 4

// Selected Entities
#define SELECTED_OBJECTS (curatorSelected select 0)
#define SELECTED_GROUPS (curatorSelected select 1)
#define SELECTED_WAYPOINTS (curatorSelected select 2)
#define SELECTED_MARKERS (curatorSelected select 3)
6 changes: 1 addition & 5 deletions addons/main/script_macros.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,6 @@

#define ZEN_isHC (!hasInterface && !isDedicated)

#define SELECTED_OBJECTS (curatorSelected select 0)
#define SELECTED_GROUPS (curatorSelected select 1)
#define SELECTED_WAYPOINTS (curatorSelected select 2)
#define SELECTED_MARKERS (curatorSelected select 3)

#define GUI_THEME_RGB_R "(profileNamespace getVariable ['GUI_BCG_RGB_R',0.13])"
#define GUI_THEME_RGB_G "(profileNamespace getVariable ['GUI_BCG_RGB_G',0.54])"
#define GUI_THEME_RGB_B "(profileNamespace getVariable ['GUI_BCG_RGB_B',0.21])"
Expand Down Expand Up @@ -115,4 +110,5 @@
#define PREP(fncName) [QPATHTOF(functions\DOUBLES(fnc,fncName).sqf), QFUNC(fncName)] call CBA_fnc_compileFunction
#endif

#include "script_curator.hpp"
#include "script_debug.hpp"
2 changes: 1 addition & 1 deletion addons/markers_tree/functions/fnc_handleTreeButtons.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
params ["_display", "_expand"];

// Only handle the custom icon markers tree, rest are handled by editor component
if (RscDisplayCurator_sections select 0 != 3 || {GVAR(mode) != 0}) exitWith {};
if (RscDisplayCurator_sections select 0 != CURATOR_MODE_MARKERS || {GVAR(mode) != 0}) exitWith {};

private _ctrlTreeIcons = _display displayCtrl IDC_MARKERS_TREE_ICONS;

Expand Down
2 changes: 1 addition & 1 deletion addons/markers_tree/functions/fnc_initDisplayCurator.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ missionNamespace getVariable ["RscDisplayCurator_sections", [0, 0]] params ["_mo

// Need frame delay workaround for usage of ctrlActivate by RscDisplayCurator.sqf
// to properly hide the empty side control when initially in markers mode
if (_mode == 3) then {
if (_mode == CURATOR_MODE_MARKERS) then {
private _ctrlSideEmpty = _display displayCtrl IDC_RSCDISPLAYCURATOR_SIDEEMPTY;
[{_this ctrlShow false}, _ctrlSideEmpty, 3] call CBA_fnc_execAfterNFrames;
};

0 comments on commit 2b1a22b

Please sign in to comment.