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 Toggle Object Editability keybind #711

Merged
merged 1 commit into from
Mar 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions addons/common/XEH_PREP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,4 @@ PREP(setVehicleAmmo);
PREP(showMessage);
PREP(spawnLargeObject);
PREP(teleportIntoVehicle);
PREP(updateEditableObjects);
25 changes: 1 addition & 24 deletions addons/common/XEH_postInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -360,30 +360,6 @@ if (isServer) then {
_waypoint setWaypointSpeed _speedMode;
}] call CBA_fnc_addEventHandler;

[QGVAR(addObjects), {
params ["_objects", ["_curator", objNull]];

if (!isNull _curator) exitWith {
_curator addCuratorEditableObjects [_objects, true];
};

{
_x addCuratorEditableObjects [_objects, true];
} forEach allCurators;
}] call CBA_fnc_addEventHandler;

[QGVAR(removeObjects), {
params ["_objects", ["_curator", objNull]];

if (!isNull _curator) exitWith {
_curator removeCuratorEditableObjects [_objects, true];
};

{
_x removeCuratorEditableObjects [_objects, true];
} forEach allCurators;
}] call CBA_fnc_addEventHandler;

{
["AllVehicles", "InitPost", {
params ["_object"];
Expand All @@ -408,4 +384,5 @@ if (isServer) then {

[QGVAR(createZeus), LINKFUNC(createZeus)] call CBA_fnc_addEventHandler;
[QGVAR(deserializeObjects), LINKFUNC(deserializeObjects)] call CBA_fnc_addEventHandler;
[QGVAR(updateEditableObjects), LINKFUNC(updateEditableObjects)] call CBA_fnc_addEventHandler;
};
2 changes: 1 addition & 1 deletion addons/common/functions/fnc_deserializeObjects.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ private _fnc_deserializeObject = {
} forEach _objectData;

if (_makeEditable) then {
[QGVAR(addObjects), [_objects]] call CBA_fnc_serverEvent;
[_objects] call FUNC(updateEditableObjects);
};

_objects
54 changes: 54 additions & 0 deletions addons/common/functions/fnc_updateEditableObjects.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#include "script_component.hpp"
/*
* Author: mharis001
* Updates editable objects for the given (or all) curators.
*
* Arguments:
* 0: Object(s) <ARRAY|OBJECT>
* 1: Mode <BOOL> (default: true)
* - true: add objects, false: remove objects.
* 2: Curator(s) <ARRAY|OBJECT> (default: [])
* - When given [] or objNull, changes are applied to all curators.
* 3: Include Crew <BOOL> (default: true)
*
* Return Value:
* None
*
* Example:
* [_objects, true] call zen_common_fnc_updateEditableObjects
*
* Public: No
*/

if (!isServer) exitWith {
[QGVAR(updateEditableObjects), _this] call CBA_fnc_serverEvent;
};

params [
["_objects", [], [[], objNull]],
["_mode", true, [true]],
["_curators", [], [[], objNull]],
["_includeCrew", true, [true]]
];

if (_objects isEqualType objNull) then {
_objects = [_objects];
};

if (_curators in [[], objNull]) then {
_curators = allCurators;
};

if (_curators isEqualType objNull) then {
_curators = [_curators];
};

if (_mode) then {
{
_x addCuratorEditableObjects [_objects, _includeCrew];
} forEach _curators;
} else {
{
_x removeCuratorEditableObjects [_objects, _includeCrew];
} forEach _curators;
};
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,4 @@ params ["_position"];

private _logic = QEGVAR(modules,moduleEditableObjects) createVehicleLocal [0, 0, 0];
_logic setPosASL _position;

_logic call BIS_fnc_showCuratorAttributes;
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* None
*
* Example:
* [true, [0, 0, 0], 100] call zen_context_actions_fnc_editableObjects
* [true, [0, 0, 0], 100] call zen_context_actions_fnc_updateEditableObjects
*
* Public: No
*/
Expand All @@ -21,6 +21,4 @@ params ["_mode", "_position", "_radius"];

private _curator = getAssignedCuratorLogic player;
private _objects = nearestObjects [ASLtoAGL _position, ["All"], _radius, true];
private _eventName = [QEGVAR(common,removeObjects), QEGVAR(common,addObjects)] select _mode;

[_eventName, [_objects, _curator]] call CBA_fnc_serverEvent;
[_objects, _mode, _curator] call EFUNC(common,updateEditableObjects);
24 changes: 24 additions & 0 deletions addons/editor/initKeybinds.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,30 @@
};
}, {}, [DIK_X, [false, true, false]]] call CBA_fnc_addKeybind; // Default: CTRL + X

[ELSTRING(main,DisplayName), QGVAR(toggleEditability), [LSTRING(ToggleEditability), LSTRING(ToggleEditability_Description)], {
if (!isNull curatorCamera && {!GETMVAR(RscDisplayCurator_search,false)}) then {
curatorMouseOver params ["_type", "_entity"];

private _object = if (_type != "OBJECT") then {
if (!call EFUNC(common,isCursorOnMouseArea)) exitWith {objNull};

private _begPos = getPosASL curatorCamera;
private _endPos = AGLToASL screenToWorld getMousePosition;
lineIntersectsSurfaces [_begPos, _endPos, curatorCamera] param [0, []] param [2, objNull]
} else {
_entity
};

if (!isNull _object) then {
private _curator = getAssignedCuratorLogic player;
private _isEditable = _object in curatorEditableObjects _curator;
[_object, !_isEditable, _curator] call EFUNC(common,updateEditableObjects);
};

true // handled
};
}, {}, [0, [false, false, false]]] call CBA_fnc_addKeybind; // Default: Unbound

[ELSTRING(main,DisplayName), QGVAR(toggleIcons), [LSTRING(ToggleIcons), LSTRING(ToggleIcons_Description)], {
if (!isNull curatorCamera && {!GETMVAR(RscDisplayCurator_search,false)}) then {
GVAR(iconsVisible) = !GVAR(iconsVisible);
Expand Down
6 changes: 6 additions & 0 deletions addons/editor/stringtable.xml
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,12 @@
<Chinese>調整所有被選中的物體的方向,使之與它們位置上的地形坡度一致。</Chinese>
<Italian>Orienta tutti gli oggetti selezionati in modo che corrispondano alla pendenza del terreno nella loro posizione.</Italian>
</Key>
<Key ID="STR_ZEN_Editor_ToggleEditability">
<English>Toggle Object Editability</English>
</Key>
<Key ID="STR_ZEN_Editor_ToggleEditability_Description">
<English>Toggles the editability (i.e., whether an object is editable through Zeus) of the object currently under the cursor.</English>
</Key>
<Key ID="STR_ZEN_Editor_ToggleIcons">
<English>Toggle Editable Icons</English>
<German>Bearbeitbare Symbole umschalten</German>
Expand Down
2 changes: 1 addition & 1 deletion addons/modules/functions/fnc_moduleAmbientFlyby.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,4 @@ _waypoint setWaypointSpeed _speed;
_waypoint setWaypointStatements ["true", "private _group = group this; private _aircrafts = []; {_aircrafts pushBackUnique vehicle _x; deleteVehicle _x} forEach thisList; {deleteVehicle _x} forEach _aircrafts; deleteGroup _group"];

// Add aircrafts to curators
[QEGVAR(common,addObjects), [_aircrafts]] call CBA_fnc_serverEvent;
[_aircrafts] call EFUNC(common,updateEditableObjects);
2 changes: 1 addition & 1 deletion addons/modules/functions/fnc_moduleCreateIntel.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ if (isNull _object) then {

if (_object isEqualType []) then {
_object = createVehicle [_values deleteAt 0, _object, [], 0, "NONE"];
[QEGVAR(common,addObjects), [[_object]]] call CBA_fnc_serverEvent;
_object call EFUNC(common,updateEditableObjects);
};

// Handle no action type option when ACE is not loaded
Expand Down
2 changes: 1 addition & 1 deletion addons/modules/functions/fnc_moduleCreateMinefield.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ _minesCache params ["_configNames", "_displayNames"];
};

// Add created mines to editable objects
[QEGVAR(common,addObjects), [_mines]] call CBA_fnc_serverEvent;
[_mines] call EFUNC(common,updateEditableObjects);
}, {}, ASLtoAGL getPosASL _logic] call EFUNC(dialog,create);

deleteVehicle _logic;
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ params ["_object", "_position", "_name"];
// Create a flag pole object if an object wasn't given
if (isNull _object) then {
_object = createVehicle ["FlagPole_F", _position, [], 0, "NONE"];
[QEGVAR(common,addObjects), [[_object]]] call CBA_fnc_localEvent;
_object call EFUNC(common,updateEditableObjects);
};

// Add teleport action to new teleporter object
Expand Down
3 changes: 1 addition & 2 deletions addons/modules/functions/fnc_moduleEditableObjects.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,4 @@ if (_range == -1) then {
_objects = nearestObjects [_position, _types, _range, true];
};

private _eventName = [QEGVAR(common,removeObjects), QEGVAR(common,addObjects)] select _editingMode;
[_eventName, [_objects, _curator]] call CBA_fnc_serverEvent;
[_objects, _editingMode, _curator] call EFUNC(common,updateEditableObjects);
2 changes: 1 addition & 1 deletion addons/modules/functions/fnc_moduleEffectFireLocal.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ _color params ["_colorRed", "_colorGreen", "_colorBlue"];

if (isServer) then {
// Add logic object to all curators for QOL
[QEGVAR(common,addObjects), [[_logic]]] call CBA_fnc_localEvent;
[_logic] call EFUNC(common,updateEditableObjects);

// Create global fire sound effect if not created yet
private _sound = _logic getVariable QGVAR(fireSound);
Expand Down
2 changes: 1 addition & 1 deletion addons/modules/functions/fnc_moduleLightSource.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ _display closeDisplay IDC_CANCEL; // Close helper display
_logic setVariable [QGVAR(lightpoint), _lightpoint, true];

// Add logic object to all curators once it has lightpoint for QOL
[QEGVAR(common,addObjects), [[_logic]]] call CBA_fnc_serverEvent;
[_logic] call EFUNC(common,updateEditableObjects);

// Add event handler to delete lightpoint if logic is deleted
[QEGVAR(common,execute), [{
Expand Down
2 changes: 1 addition & 1 deletion addons/modules/functions/fnc_moduleSitOnChair.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ private _displayNames = _configNames apply {getText (_cfgVehicles >> _x >> "disp
[QEGVAR(common,setDir), [_unit, _sitDirection], _unit] call CBA_fnc_targetEvent;

// Add chair to editable objects so it can be moved around
[QEGVAR(common,addObjects), [[_chair]]] call CBA_fnc_serverEvent;
[_chair] call EFUNC(common,updateEditableObjects);

// Flag unit as sitting so module will make it stand up next time
_unit setVariable [QGVAR(isSitting), true, true];
Expand Down
2 changes: 1 addition & 1 deletion addons/modules/functions/fnc_moduleSpawnCarrier.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ params ["_logic"];
private _jipID = [QGVAR(carrierInit), _carrier] call CBA_fnc_globalEventJIP;
[_jipID, _carrier] call CBA_fnc_removeGlobalEventJIP;

[QEGVAR(common,addObjects), [[_carrier]]] call CBA_fnc_serverEvent;
[_carrier] call EFUNC(common,updateEditableObjects);

{
deleteVehicle _x;
Expand Down
2 changes: 1 addition & 1 deletion addons/modules/functions/fnc_moduleSpawnDestroyer.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ params ["_logic"];
private _jipID = [QGVAR(destroyerInit), _destroyer] call CBA_fnc_globalEventJIP;
[_jipID, _destroyer] call CBA_fnc_removeGlobalEventJIP;

[QEGVAR(common,addObjects), [[_destroyer]]] call CBA_fnc_serverEvent;
[_destroyer] call EFUNC(common,updateEditableObjects);

{
deleteVehicle _x;
Expand Down
2 changes: 1 addition & 1 deletion addons/modules/functions/fnc_moduleSpawnReinforcements.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,4 @@ private _objects = [_vehicle];
_objects append units _vehicleGroup;
_objects append units _infantryGroup;

[QEGVAR(common,addObjects), [_objects]] call CBA_fnc_serverEvent;
[_objects] call EFUNC(common,updateEditableObjects);
2 changes: 1 addition & 1 deletion addons/position_logics/functions/fnc_add.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ if (isServer) then {
[_jipID, _logic] call CBA_fnc_removeGlobalEventJIP;

// Make the logic editable for all curators
[QEGVAR(common,addObjects), [[_logic]]] call CBA_fnc_localEvent;
[_logic] call EFUNC(common,updateEditableObjects);

// Disable attributes for the logic
_logic setVariable [QEGVAR(attributes,disabled), true, true];
Expand Down