Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Saved selection for modules and Transfer Ownership Module #501

Open
wants to merge 33 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
4d6fd85
Saved Selection and Transfer Ownership
ampersand38 Jan 9, 2021
92f5c61
Toolbox for most Server and Curator targets
ampersand38 Jan 9, 2021
c85e34f
Check for players in selection
ampersand38 Jan 9, 2021
6b84b80
Added module description
ampersand38 Jan 9, 2021
40adda7
remove logging
ampersand38 Jan 9, 2021
3f4bcc2
Improved selection preview
Kexanone Jan 10, 2021
344c9d3
Force toolbox default value
ampersand38 Jan 10, 2021
ebffcfc
Clean-up
Kexanone Jan 10, 2021
f60054c
Merge branch 'save-selection-for-modules' of github-kex:ampersand38/Z…
Kexanone Jan 10, 2021
46a32a3
Add default value for icon cache
Kexanone Jan 10, 2021
bb41331
Naked unit bug fix
Kexanone Jan 11, 2021
c7d75d7
Revert "Naked unit bug fix"
Kexanone Jan 11, 2021
2a07065
add toolbox for hc scripts flags
ampersand38 Jan 12, 2021
84a8872
Update stringtable.xml
Kexanone Jan 13, 2021
30ad1c6
check CfgPatches instead of `acex_headless`
ampersand38 Jan 13, 2021
853b696
Update stringtable.xml
Kexanone Jan 13, 2021
ccf1ff6
Update stringtable.xml
Kexanone Jan 13, 2021
b535ee4
fix condition for objects
ampersand38 Jan 14, 2021
5c49b29
Switch to rendering time scope
Kexanone Jan 14, 2021
2124725
Use a single handler for selection icons
Kexanone Jan 23, 2021
46b755e
Fix syntax
Kexanone Jan 23, 2021
d9d8308
Remove _mehID
Kexanone Jan 23, 2021
e6a09c9
Single delete logic
Kexanone Jan 23, 2021
8feb8a7
Doc comment
Kexanone Jan 23, 2021
6b5755d
Remove correct event handler
Kexanone Jan 23, 2021
98916d6
Merge options
Kexanone Jan 23, 2021
e10c311
Sort player targets by name
Kexanone Jan 23, 2021
f6a5055
Prioritize HCs
Kexanone Jan 23, 2021
e6fe9bb
Change default values
ampersand38 Jan 25, 2021
5b458c4
Merge remote-tracking branch 'upstream/master' into save-selection-fo…
ampersand38 Feb 25, 2021
7d0f755
Update addons/modules/functions/fnc_moduleTransferOwnership.sqf
ampersand38 Mar 4, 2021
7e3f1d1
use select
ampersand38 Mar 4, 2021
a1696ce
Tooltip
ampersand38 Mar 4, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions addons/common/XEH_postInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,31 @@ if (isServer) then {
_object enableSimulationGlobal _enable;
}] call CBA_fnc_addEventHandler;

[QGVAR(transferOwnership), {
params ["_entities", "_target"];
if (!(_entities isEqualType [])) then {
_entities = [_entities];
};
private _clientID = 0;
if (_target isEqualType 0) then {
_clientID = _target;
};
if (_target isEqualType objNull) then {
_clientID = owner _target;
};
{
if (_x isEqualType grpNull) then {
_x setGroupOwner _clientID;
} else {
if (group _x == grpNull) then {
ampersand38 marked this conversation as resolved.
Show resolved Hide resolved
group _x setGroupOwner _clientID;
} else {
_x setOwner _clientID;
};
};
} forEach _entities;
}] call CBA_fnc_addEventHandler;

[QGVAR(setFriend), {
params ["_side1", "_side2", "_value"];
_side1 setFriend [_side2, _value];
Expand Down
2 changes: 2 additions & 0 deletions addons/dialog/functions/fnc_close.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,7 @@ if (_confirmed) then {
[_values, _args] call _onCancel;
};

[QGVAR(close), [_display, _confirmed]] call CBA_fnc_localEvent;

// Close dialog, returning false to not override engine driven IDC_OK and IDC_CANCEL
false
3 changes: 3 additions & 0 deletions addons/editor/XEH_PREP.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
PREP(addGroupIcons);
PREP(declutterEmptyTree);
PREP(fixSideButtons);
PREP(getSelection);
PREP(handleKeyDown);
PREP(handleLoad);
PREP(handleModeButtons);
Expand All @@ -9,6 +10,8 @@ PREP(handleSearchButton);
PREP(handleSearchClick);
PREP(handleSearchKeyDown);
PREP(handleSearchKeyUp);
PREP(handleSelectionChanged);
PREP(handleSideButtons);
PREP(handleTreeButtons);
PREP(handleUnload);
PREP(toggleSelectionPreview);
20 changes: 20 additions & 0 deletions addons/editor/XEH_preInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,33 @@ PREP_RECOMPILE_END;
#include "initSettings.sqf"
#include "initKeybinds.sqf"

GVAR(lastSelection) = [];
GVAR(savedSelection) = [];
GVAR(lastModuleIcon) = "";
GVAR(savedModuleIcon) = "";
GVAR(colour) = ["IGUI", "TEXT_RGB"] call BIS_fnc_displayColorGet;
GVAR(clipboard) = [];
GVAR(includeCrew) = true;

["ModuleCurator_F", "Init", {
params ["_logic"];

_logic addEventHandler ["CuratorObjectPlaced", {call FUNC(handleObjectPlaced)}];
_logic addEventHandler ["CuratorGroupSelectionChanged", {call FUNC(handleSelectionChanged)}];
_logic addEventHandler ["CuratorMarkerSelectionChanged", {call FUNC(handleSelectionChanged)}];
_logic addEventHandler ["CuratorObjectSelectionChanged", {call FUNC(handleSelectionChanged)}];
_logic addEventHandler ["CuratorWaypointSelectionChanged", {call FUNC(handleSelectionChanged)}];
}, true, [], true] call CBA_fnc_addClassEventHandler;

[QGVAR(ModuleSelChanged), {
params ["_moduleName"];

GVAR(savedModuleIcon) = GVAR(lastModuleIcon);
GVAR(lastModuleIcon) = getText (configFile >> "CfgVehicles" >> _moduleName >> "icon");

// Toggle selection preview
private _hasSelectionPreview = (getNumber (configFile >> "CfgVehicles" >> _moduleName >> QGVAR(hasSelectionPreview)) isEqualTo 1);
[_hasSelectionPreview] call FUNC(toggleSelectionPreview);
}] call CBA_fnc_addEventHandler;

ADDON = true;
54 changes: 54 additions & 0 deletions addons/editor/functions/fnc_getSelection.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#include "script_component.hpp"
/*
* Author: Ampersand, Kex
* Retrieves and marks the entities a module is applied to.
* This function is meant to be used inside module functions only.
*
* Arguments:
* None
*
* Return Value:
* 0: List of selected objects <ARRAY>
* 1: List of selected groups <ARRAY>
* 2: List of selected waypoints <ARRAY>
* 3: List of selected markers <ARRAY>
*
* Example:
* (call zen_editor_fnc_getSelection) params ["_objects", "_groups"];
*
* Public: No
*/

BIS_fnc_curatorObjectPlaced_mouseOver params [["_entityType", ""], ["_entity", nil]];

// Retrieve selection
GVAR(lastSelection) = switch (_entityType) do {
case "OBJECT": {
[[_entity], [], [], []];
};
case "GROUP": {
[[], [_entity], [], []];
};
case "ARRAY": {
[[], [], [_entity], []];
};
case "STRING": {
[[], [], [], [_entity]];
};
default {
GVAR(savedSelection);
};
};

// Turn on selection preview
GVAR(lastModuleIcon) = GVAR(savedModuleIcon);
[true] call FUNC(toggleSelectionPreview);

// Turn off selection preview when dialog is colosed
GVAR(endSelectionHandle) = [QEGVAR(dialog,close), {
[false] call FUNC(toggleSelectionPreview);
[QEGVAR(dialog,close), GVAR(endSelectionHandle)] call CBA_fnc_removeEventHandler;
GVAR(endSelectionHandle) = nil;
}] call CBA_fnc_addEventHandler;

GVAR(lastSelection)
21 changes: 18 additions & 3 deletions addons/editor/functions/fnc_handleLoad.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,30 @@ _display displayAddEventHandler ["KeyDown", {call FUNC(handleKeyDown)}];
IDC_RSCDISPLAYCURATOR_MAINMAP
];

// Add tree selection changed events
private _ctrlTreeModule = _display displayCtrl IDC_RSCDISPLAYCURATOR_CREATE_MODULES;
_ctrlTreeModule ctrlAddEventHandler ["TreeSelChanged", {
params ["_ctrlTreeModule", "_selectedPath"];

[QGVAR(ModuleSelChanged), _ctrlTreeModule tvData _selectedPath] call CBA_fnc_localEvent;
}];

private _ctrlTreeRecent = _display displayCtrl IDC_RSCDISPLAYCURATOR_CREATE_RECENT;
_ctrlTreeRecent ctrlAddEventHandler ["TreeSelChanged", {
params ["_ctrlTreeRecent", "_selectedPath"];
private _recentTreeData = _ctrlTreeRecent tvData _selectedPath;

// Store data of selected item to allow for deleting the of crew of objects placed through the recent tree
// tvCurSel is unavailable once the selected item has been placed, the empty path check ensures that the
// tvCurSel is unavailable once the selected item has been placed, the empty string check ensures that the
// data is not cleared since this event occurs before the object placed event
if !(_selectedPath isEqualTo []) then {
GVAR(recentTreeData) = _ctrlTreeRecent tvData _selectedPath;
if !(_recentTreeData isEqualTo "") then {
GVAR(recentTreeData) = _recentTreeData;
};

if (_recentTreeData isKindOf "Module_F") then {
[QGVAR(ModuleSelChanged), _recentTreeData] call CBA_fnc_localEvent;
} else {
[QGVAR(ModuleSelChanged), ""] call CBA_fnc_localEvent;
};
}];

Expand Down
23 changes: 23 additions & 0 deletions addons/editor/functions/fnc_handleSelectionChanged.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include "script_component.hpp"
/*
* Author: Ampersand
* Saves curator selected entities for use by modules.
*
* Arguments:
* 0: Curator <OBJECT>
* 0: Entity: group, marker, object, or waypoint <GROUP, STRING, OBJECT, ARRAY>
Kexanone marked this conversation as resolved.
Show resolved Hide resolved
*
* Return Value:
* Handled <BOOL>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this event handler be overridden?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, we don't store the index of the event anywhere, but we did the same for all other curator event handlers. We could consider bridging them with CBA event handlers, but I would make a separate PR for such a change.

*
* Example:
* [CONTROL] call zen_editor_fnc_handleSelectionChanged
*
* Public: No
*/

params ["_curator", "_entity"];
GVAR(savedSelection) = GVAR(lastSelection);
GVAR(lastSelection) = curatorSelected;

false
52 changes: 52 additions & 0 deletions addons/editor/functions/fnc_toggleSelectionPreview.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#include "script_component.hpp"
/*
* Author: Ampersand, Kex
* Toggle preview of the current selection
*
* Arguments:
* 0: Turn on preview <BOOL>
*
* Return Value:
* None
*
* Example:
* [true] call zen_editor_fnc_toggleSelectionPreview;
*
* Public: No
*/

params [["_turnOn", true, [true]]];

if (_turnOn) then {
if (isNil QGVAR(selectionIconHandler)) then {
GVAR(selectionIconHandler) = [{
// Show preview if mouse is not over an entity
if (curatorMouseOver isEqualTo [""]) then {
if (isNil QGVAR(drawSelectioIcons)) then {
GVAR(drawSelectioIcons) = addMissionEventHandler ["Draw3D", {
{
drawIcon3D [
GVAR(lastModuleIcon),
GVAR(colour), getPos _x, 1, 1, 0
];
} forEach (GVAR(lastSelection) select 0);
}];
};
} else {
if !(isNil QGVAR(drawSelectioIcons)) then {
removeMissionEventHandler ["Draw3D", GVAR(drawSelectioIcons)];
GVAR(drawSelectioIcons) = nil
};
};
}, 0] call CBA_fnc_addPerFrameHandler;
};
} else {
if !(isNil QGVAR(selectionIconHandler)) then {
[GVAR(selectionIconHandler)] call CBA_fnc_removePerFrameHandler;
GVAR(selectionIconHandler) = nil;
};
if !(isNil QGVAR(drawSelectioIcons)) then {
removeMissionEventHandler ["Draw3D", GVAR(drawSelectioIcons)];
GVAR(drawSelectioIcons) = nil;
};
};
9 changes: 9 additions & 0 deletions addons/modules/CfgVehicles.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,15 @@ class CfgVehicles {
function = QFUNC(moduleToggleLamps);
icon = QPATHTOF(ui\street_lamp_ca.paa);
};
class GVAR(moduleTransferOwnership): GVAR(moduleBase) {
curatorCanAttach = 1;
category = QGVAR(DevTools);
displayName = CSTRING(ModuleTransferOwnership);
function = QFUNC(moduleTransferOwnership);
icon = "\a3\ui_f\data\Map\VehicleIcons\iconVirtual_ca.paa";
portrait = "\a3\ui_f\data\Map\VehicleIcons\iconVirtual_ca.paa";
EGVAR(editor,hasSelectionPreview) = 1;
};
class GVAR(moduleTurretOptics): GVAR(moduleBase) {
curatorCanAttach = 1;
category = QGVAR(Equipment);
Expand Down
1 change: 1 addition & 0 deletions addons/modules/XEH_PREP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ PREP(moduleTeleportPlayers);
PREP(moduleToggleFlashlights);
PREP(moduleToggleIRLasers);
PREP(moduleToggleLamps);
PREP(moduleTransferOwnership);
PREP(moduleTurretOptics);
PREP(moduleUnGarrison);
PREP(moduleVisibility);
Expand Down
1 change: 1 addition & 0 deletions addons/modules/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class CfgPatches {
QGVAR(moduleToggleFlashlights),
QGVAR(moduleToggleIRLasers),
QGVAR(moduleToggleLamps),
QGVAR(ModuleTransferOwnership),
QGVAR(moduleTurretOptics),
QGVAR(moduleUnGarrison),
QGVAR(moduleVisibility),
Expand Down
Loading