From e4879af208bc3c3008d303e6525a37de2c666a9d Mon Sep 17 00:00:00 2001 From: mharis001 Date: Mon, 11 Jan 2021 22:37:39 -0500 Subject: [PATCH 1/3] Add Faction Filter --- .../editor/functions/fnc_fixSideButtons.sqf | 32 +++++----- addons/editor/functions/fnc_handleLoad.sqf | 5 ++ .../functions/fnc_handleModeButtons.sqf | 14 ++-- .../functions/fnc_handleSideButtons.sqf | 7 +- addons/faction_filter/$PBOPREFIX$ | 1 + addons/faction_filter/CfgEventHandlers.hpp | 17 +++++ addons/faction_filter/XEH_postInit.sqf | 64 +++++++++++++++++++ addons/faction_filter/XEH_preInit.sqf | 20 ++++++ addons/faction_filter/XEH_preStart.sqf | 63 ++++++++++++++++++ addons/faction_filter/config.cpp | 19 ++++++ addons/faction_filter/script_component.hpp | 21 ++++++ addons/faction_filter/stringtable.xml | 8 +++ 12 files changed, 244 insertions(+), 27 deletions(-) create mode 100644 addons/faction_filter/$PBOPREFIX$ create mode 100644 addons/faction_filter/CfgEventHandlers.hpp create mode 100644 addons/faction_filter/XEH_postInit.sqf create mode 100644 addons/faction_filter/XEH_preInit.sqf create mode 100644 addons/faction_filter/XEH_preStart.sqf create mode 100644 addons/faction_filter/config.cpp create mode 100644 addons/faction_filter/script_component.hpp create mode 100644 addons/faction_filter/stringtable.xml diff --git a/addons/editor/functions/fnc_fixSideButtons.sqf b/addons/editor/functions/fnc_fixSideButtons.sqf index ab977a7c3..97b98d6f6 100644 --- a/addons/editor/functions/fnc_fixSideButtons.sqf +++ b/addons/editor/functions/fnc_fixSideButtons.sqf @@ -5,30 +5,30 @@ * * Arguments: * 0: Display - * 1: Mode * * Return Value: * None * * Example: - * [DISPLAY, 0] call zen_editor_fnc_fixSideButtons + * [DISPLAY] call zen_editor_fnc_fixSideButtons * * Public: No */ -[{ - params ["_display", "_mode"]; +params ["_display"]; - // Get side buttons to show based on mode - private _idcs = switch (_mode) do { - case 0; - case 1: {IDCS_SIDE_BUTTONS}; - case 2; - case 3: {[IDC_RSCDISPLAYCURATOR_SIDEEMPTY]}; - default {[]} - }; +private _sections = missionNamespace getVariable ["RscDisplayCurator_sections", [0, 0]]; +_sections params ["_mode"]; - { - (_display displayCtrl _x) ctrlShow true; - } forEach _idcs; -}, _this] call CBA_fnc_execNextFrame; +// Get side buttons to show based on mode +private _idcs = switch (_mode) do { + case 0; + case 1: {IDCS_SIDE_BUTTONS}; + case 2; + case 3: {[IDC_RSCDISPLAYCURATOR_SIDEEMPTY]}; + default {[]}; +}; + +{ + (_display displayCtrl _x) ctrlShow true; +} forEach _idcs; diff --git a/addons/editor/functions/fnc_handleLoad.sqf b/addons/editor/functions/fnc_handleLoad.sqf index 899f86a0e..1d1e16b89 100644 --- a/addons/editor/functions/fnc_handleLoad.sqf +++ b/addons/editor/functions/fnc_handleLoad.sqf @@ -137,9 +137,14 @@ GVAR(iconsVisible) = true; if (isNull _display) exitWith {}; + [QGVAR(treesLoaded), _display] call CBA_fnc_localEvent; + [_display] call FUNC(addGroupIcons); [_display] call FUNC(declutterEmptyTree); + // Initially fix side buttons (can be hidden if a tree has no entries) + [FUNC(fixSideButtons), _display] call CBA_fnc_execNextFrame; + { private _ctrl = _display displayCtrl _x; _ctrl call EFUNC(common,collapseTree); diff --git a/addons/editor/functions/fnc_handleModeButtons.sqf b/addons/editor/functions/fnc_handleModeButtons.sqf index 70fd491b1..c5e47a570 100644 --- a/addons/editor/functions/fnc_handleModeButtons.sqf +++ b/addons/editor/functions/fnc_handleModeButtons.sqf @@ -15,12 +15,12 @@ * Public: No */ -[{ - params ["_ctrlButton"]; - private _display = ctrlParent _ctrlButton; - private _mode = IDCS_MODE_BUTTONS find ctrlIDC _ctrlButton; - private _side = GETMVAR(RscDisplayCurator_sections,[]) param [1, 0]; +params ["_ctrlButton"]; + +private _display = ctrlParent _ctrlButton; - [QGVAR(modeChanged), [_display, _mode, _side]] call CBA_fnc_localEvent; -}, _this] call CBA_fnc_execNextFrame; +[{ + RscDisplayCurator_sections params ["_mode", "_side"]; + [QGVAR(modeChanged), [_this, _mode, _side]] call CBA_fnc_localEvent; +}, _display] call CBA_fnc_execNextFrame; diff --git a/addons/editor/functions/fnc_handleSideButtons.sqf b/addons/editor/functions/fnc_handleSideButtons.sqf index 30a9cc2d2..1d67e8ab6 100644 --- a/addons/editor/functions/fnc_handleSideButtons.sqf +++ b/addons/editor/functions/fnc_handleSideButtons.sqf @@ -20,9 +20,8 @@ params ["_ctrlButton"]; if !(_ctrlButton getVariable [QGVAR(hovered), false]) exitWith {}; private _display = ctrlParent _ctrlButton; -private _mode = GETMVAR(RscDisplayCurator_sections,[]) param [0, 0]; -private _side = IDCS_SIDE_BUTTONS find ctrlIDC _ctrlButton; [{ - [QGVAR(sideChanged), _this] call CBA_fnc_localEvent; -}, [_display, _mode, _side]] call CBA_fnc_execNextFrame; + RscDisplayCurator_sections params ["_mode", "_side"]; + [QGVAR(sideChanged), [_this, _mode, _side]] call CBA_fnc_localEvent; +}, _display] call CBA_fnc_execNextFrame; diff --git a/addons/faction_filter/$PBOPREFIX$ b/addons/faction_filter/$PBOPREFIX$ new file mode 100644 index 000000000..a71bd1a1b --- /dev/null +++ b/addons/faction_filter/$PBOPREFIX$ @@ -0,0 +1 @@ +x\zen\addons\faction_filter diff --git a/addons/faction_filter/CfgEventHandlers.hpp b/addons/faction_filter/CfgEventHandlers.hpp new file mode 100644 index 000000000..0d3301d6e --- /dev/null +++ b/addons/faction_filter/CfgEventHandlers.hpp @@ -0,0 +1,17 @@ +class Extended_PreStart_EventHandlers { + class ADDON { + init = QUOTE(call COMPILE_FILE(XEH_preStart)); + }; +}; + +class Extended_PreInit_EventHandlers { + class ADDON { + init = QUOTE(call COMPILE_FILE(XEH_preInit)); + }; +}; + +class Extended_PostInit_EventHandlers { + class ADDON { + init = QUOTE(call COMPILE_FILE(XEH_postInit)); + }; +}; diff --git a/addons/faction_filter/XEH_postInit.sqf b/addons/faction_filter/XEH_postInit.sqf new file mode 100644 index 000000000..5e66e6405 --- /dev/null +++ b/addons/faction_filter/XEH_postInit.sqf @@ -0,0 +1,64 @@ +#include "script_component.hpp" + +["CBA_SettingChanged", { + params ["_name"]; + + // Schedule the Zeus display to be reloaded when a faction filter setting is changed + // Allows for changing faction filter settings mid-mission while the interface is forced + if (QUOTE(ADDON) in _name && {!isNull findDisplay IDD_RSCDISPLAYCURATOR} && {isNil QGVAR(displayReload)}) then { + GVAR(displayReload) = true; + + { + (findDisplay IDD_RSCDISPLAYCURATOR) closeDisplay IDC_CANCEL; + + [{ + isNull findDisplay IDD_RSCDISPLAYCURATOR + }, { + openCuratorInterface; + GVAR(displayReload) = nil; + }] call CBA_fnc_waitUntilAndExecute; + } call CBA_fnc_execNextFrame; + }; +}] call CBA_fnc_addEventHandler; + +[QEGVAR(editor,treesLoaded), { + BEGIN_COUNTER(processTrees); + + params ["_display"]; + + private _fnc_processTrees = { + params ["_treeIDCs", "_basePath"]; + + { + private _ctrlTree = _display displayCtrl _x; + + for "_i" from (_ctrlTree tvCount _basePath) - 1 to 0 step -1 do { + private _path = _basePath + [_i]; + private _name = _ctrlTree tvText _path; + + // Get the setting variable name that corresponds to this faction's name and side + private _varName = GVAR(map) getVariable [FACTION_ID(_forEachIndex,_name), ""]; + + if !(missionNamespace getVariable [_varName, true]) then { + _ctrlTree tvDelete _path; + }; + }; + } forEach _treeIDCs; + }; + + [[ + IDC_RSCDISPLAYCURATOR_CREATE_UNITS_EAST, + IDC_RSCDISPLAYCURATOR_CREATE_UNITS_WEST, + IDC_RSCDISPLAYCURATOR_CREATE_UNITS_GUER, + IDC_RSCDISPLAYCURATOR_CREATE_UNITS_CIV + ], []] call _fnc_processTrees; + + [[ + IDC_RSCDISPLAYCURATOR_CREATE_GROUPS_EAST, + IDC_RSCDISPLAYCURATOR_CREATE_GROUPS_WEST, + IDC_RSCDISPLAYCURATOR_CREATE_GROUPS_GUER, + IDC_RSCDISPLAYCURATOR_CREATE_GROUPS_CIV + ], [0]] call _fnc_processTrees; + + END_COUNTER(processTrees); +}] call CBA_fnc_addEventHandler; diff --git a/addons/faction_filter/XEH_preInit.sqf b/addons/faction_filter/XEH_preInit.sqf new file mode 100644 index 000000000..354566fc6 --- /dev/null +++ b/addons/faction_filter/XEH_preInit.sqf @@ -0,0 +1,20 @@ +#include "script_component.hpp" + +ADDON = false; + +// Create trees do not provide the faction class name that a given node represents +// Only the faction's name and side can be obtained from the tree +// This namespace maps a faction's name and side to its corresponding setting variable name +GVAR(map) = [] call CBA_fnc_createNamespace; + +{ + _x params ["_name", "_faction", "_side"]; + + private _varName = format [QGVAR(%1_%2), _side, _faction]; + GVAR(map) setVariable [FACTION_ID(_side,_name), _varName]; + + private _sideName = ["str_east", "str_west", "str_guerrila", "str_civilian"] select _side; + [_varName, "CHECKBOX", _name, [LSTRING(DisplayName), _sideName], true, false] call CBA_fnc_addSetting; +} forEach (uiNamespace getVariable QGVAR(factions)); + +ADDON = true; diff --git a/addons/faction_filter/XEH_preStart.sqf b/addons/faction_filter/XEH_preStart.sqf new file mode 100644 index 000000000..2ed911ff1 --- /dev/null +++ b/addons/faction_filter/XEH_preStart.sqf @@ -0,0 +1,63 @@ +#include "script_component.hpp" + +private _factions = []; +private _cfgVehicles = configFile >> "CfgVehicles"; +private _cfgFactionClasses = configFile >> "CfgFactionClasses"; +private _cfgEditorCategories = configFile >> "CfgEditorCategories"; + +// Zeus only includes objects defined in the units array of CfgPatches classes +{ + { + // Classes that do not inherit from AllVehicles have thier side ignored and are considered props (Zeus also ignores animals) + if (_x isKindOf "AllVehicles" && {!(_x isKindOf "Animal")}) then { + private _config = _cfgVehicles >> _x; + + // scopeCurator always has priority over scope, scope is only used if scopeCurator is not defined + if (getNumber (_config >> "scopeCurator") == 2 || {getNumber (_config >> "scope") == 2 && {!isNumber (_config >> "scopeCurator")}}) then { + private _side = getNumber (_config >> "side"); + + if (_side in [0, 1, 2, 3]) then { + // Either editorCategory or faction can be used to set an object's category + // Usually, faction is used for characters and vehicles and editorCategory is used for props + // When both are present, editorCategory has priority and is used by Zeus + private _factionConfig = if (isText (_config >> "editorCategory")) then { + _cfgEditorCategories >> getText (_config >> "editorCategory") + } else { + _cfgFactionClasses >> getText (_config >> "faction") + }; + + _factions pushBackUnique [getText (_factionConfig >> "displayName"), configName _factionConfig, _side]; + }; + }; + }; + } forEach getArray (_x >> "units"); +} forEach configProperties [configFile >> "CfgPatches", "isClass _x"]; + +// Group compositions do not necessarily use the same faction names as the object's they contain +{ + private _side = getNumber (_x >> "side"); + + if (_side in [0, 1, 2, 3]) then { + { + private _name = getText (_x >> "name"); + + // Add the faction if one with this name and side does not exist yet + if (_factions findIf {_x select 0 == _name && {_x select 2 == _side}} == -1) then { + private _faction = configName _x; + + // Add "_groups" suffix to the faction class name if it already exists + // Happens when groups use the same faction class as objects but with a different display name + if (_factions findIf {_x select 1 == _faction} != -1) then { + _faction = _faction + "_groups"; + }; + + _factions pushBackUnique [_name, _faction, _side]; + }; + } forEach configProperties [_x, "isClass _x"]; + }; +} forEach configProperties [configFile >> "CfgGroups", "isClass _x"]; + +// Sort factions in ascending order by name +_factions sort true; + +uiNamespace setVariable [QGVAR(factions), _factions]; diff --git a/addons/faction_filter/config.cpp b/addons/faction_filter/config.cpp new file mode 100644 index 000000000..622a02a3c --- /dev/null +++ b/addons/faction_filter/config.cpp @@ -0,0 +1,19 @@ +#include "script_component.hpp" + +class CfgPatches { + class ADDON { + name = COMPONENT_NAME; + units[] = {}; + weapons[] = {}; + requiredVersion = REQUIRED_VERSION; + requiredAddons[] = {"zen_editor"}; + author = ECSTRING(main,Author); + authors[] = {"mharis001", "Kex"}; + url = ECSTRING(main,URL); + VERSION_CONFIG; + }; +}; + +PRELOAD_ADDONS; + +#include "CfgEventHandlers.hpp" diff --git a/addons/faction_filter/script_component.hpp b/addons/faction_filter/script_component.hpp new file mode 100644 index 000000000..f23a1c50e --- /dev/null +++ b/addons/faction_filter/script_component.hpp @@ -0,0 +1,21 @@ +#define COMPONENT faction_filter +#define COMPONENT_BEAUTIFIED Faction Filter +#include "\x\zen\addons\main\script_mod.hpp" + +// #define DEBUG_MODE_FULL +// #define DISABLE_COMPILE_CACHE +// #define ENABLE_PERFORMANCE_COUNTERS + +#ifdef DEBUG_ENABLED_FACTION_FILTER + #define DEBUG_MODE_FULL +#endif + +#ifdef DEBUG_SETTINGS_FACTION_FILTER + #define DEBUG_SETTINGS DEBUG_SETTINGS_FACTION_FILTER +#endif + +#include "\x\zen\addons\main\script_macros.hpp" + +#include "\x\zen\addons\common\defineResinclDesign.inc" + +#define FACTION_ID(side,name) format [QGVAR(%1:%2), side, name] diff --git a/addons/faction_filter/stringtable.xml b/addons/faction_filter/stringtable.xml new file mode 100644 index 000000000..ccc8dc300 --- /dev/null +++ b/addons/faction_filter/stringtable.xml @@ -0,0 +1,8 @@ + + + + + Zeus Enhanced - Faction Filter + + + From 9809406c58109a016882cc1d268315e4c7108274 Mon Sep 17 00:00:00 2001 From: Kex Date: Wed, 13 Jan 2021 01:51:44 +0100 Subject: [PATCH 2/3] Update stringtable.xml --- addons/faction_filter/stringtable.xml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/addons/faction_filter/stringtable.xml b/addons/faction_filter/stringtable.xml index ccc8dc300..1dfc9c1a9 100644 --- a/addons/faction_filter/stringtable.xml +++ b/addons/faction_filter/stringtable.xml @@ -3,6 +3,8 @@ Zeus Enhanced - Faction Filter + Zeus Enhanced - Filtre de Fraction + Zeus Enhanced - Fraktionsfilter From de369f6ba7936e107654457ac9739d94de7cef4d Mon Sep 17 00:00:00 2001 From: Kex Date: Wed, 13 Jan 2021 02:08:03 +0100 Subject: [PATCH 3/3] Update stringtable.xml --- addons/faction_filter/stringtable.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/faction_filter/stringtable.xml b/addons/faction_filter/stringtable.xml index 1dfc9c1a9..614ae3611 100644 --- a/addons/faction_filter/stringtable.xml +++ b/addons/faction_filter/stringtable.xml @@ -3,7 +3,7 @@ Zeus Enhanced - Faction Filter - Zeus Enhanced - Filtre de Fraction + Zeus Enhanced - Filtre des Fractions Zeus Enhanced - Fraktionsfilter