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

Editor - Prevent forced empty objects from being decluttered #783

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
30 changes: 30 additions & 0 deletions addons/editor/XEH_preStart.sqf
Original file line number Diff line number Diff line change
@@ -1,3 +1,33 @@
#include "script_component.hpp"

#include "XEH_PREP.hpp"

// Get faction names for west, east, independent, and civilian sides
private _cfgFactionClasses = configFile >> "CfgFactionClasses";
private _factionNames = configProperties [_cfgFactionClasses, "isClass _x"] select {
getNumber (_x >> "side") in [0, 1, 2, 3]
} apply {
getText (_x >> "displayName")
};

// Find objects that are forced empty. This relatively small number of objects are included only in
// the empty tree and, if we delete the entire faction node, then there is no way to place them.
private _forcedEmptyFactions = [];
private _forcedEmptyObjects = createHashMap;

{
if (
getNumber (_x >> "scope") != 2
|| {getNumber (_x >> "editorForceEmpty") != 1}
) then {continue};

private _faction = getText (_cfgFactionClasses >> getText (_x >> "faction") >> "displayName");
_forcedEmptyFactions pushBack _faction;
_forcedEmptyObjects set [configName _x, nil];
} forEach configProperties [configFile >> "CfgVehicles", "isClass _x"];

private _fastDeclutterFactions = (_factionNames - _forcedEmptyFactions) createHashMapFromArray [];
private _slowDeclutterFactions = _forcedEmptyFactions createHashMapFromArray [];
uiNamespace setVariable [QGVAR(fastDeclutterFactions), compileFinal _fastDeclutterFactions];
uiNamespace setVariable [QGVAR(slowDeclutterFactions), compileFinal _slowDeclutterFactions];
uiNamespace setVariable [QGVAR(forcedEmptyObjects), compileFinal _forcedEmptyObjects]
39 changes: 27 additions & 12 deletions addons/editor/functions/fnc_declutterEmptyTree.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,38 @@ if (!GVAR(declutterEmptyTree)) exitWith {};

params ["_display"];

// Get faction names for west, east, independent, and civilian sides
if (isNil QGVAR(factionNames)) then {
GVAR(factionNames) = configProperties [configFile >> "CfgFactionClasses", "isClass _x"] select {
getNumber (_x >> "side") in [0, 1, 2, 3]
} apply {
getText (_x >> "displayName")
};
};

private _factionNames = GVAR(factionNames);

// Remove factions from empty tree
// Backwards since tree item paths will change as items are deleted
private _ctrlTree = _display displayCtrl IDC_RSCDISPLAYCURATOR_CREATE_UNITS_EMPTY;
private _fastDeclutterFactions = uiNamespace getVariable [QGVAR(fastDeclutterFactions), createHashMap];
private _slowDeclutterFactions = uiNamespace getVariable [QGVAR(slowDeclutterFactions), createHashMap];
private _forcedEmptyObjects = uiNamespace getVariable [QGVAR(forcedEmptyObjects), createHashMap];

for "_i" from (_ctrlTree tvCount []) - 1 to 0 step -1 do {
if (_ctrlTree tvText [_i] in _factionNames) then {
private _faction = _ctrlTree tvText [_i];

// Delete entire node for factions that do not contain any forced empty objects (fast case)
if (_faction in _fastDeclutterFactions) then {
_ctrlTree tvDelete [_i];
continue;
};

// For factions that contain forced empty objects, need to check every leaf node individually (slow case)
if (_faction in _slowDeclutterFactions) then {
for "_j" from (_ctrlTree tvCount [_i]) - 1 to 0 step -1 do {
for "_k" from (_ctrlTree tvCount [_i, _j]) - 1 to 0 step -1 do {
private _data = _ctrlTree tvData [_i, _j, _k];
if (_data in _forcedEmptyObjects) then {continue};
_ctrlTree tvDelete [_i, _j, _k];
};

if (_ctrlTree tvCount [_i, _j] == 0) then {
_ctrlTree tvDelete [_i, _j];
};
};

if (_ctrlTree tvCount [_i] == 0) then {
_ctrlTree tvDelete [_i];
};
};
};
Loading