Skip to content

Commit 34d103b

Browse files
mharis001Kexanone
andauthored
Add Faction Filter (#504)
* Add Faction Filter * Update stringtable.xml * Update stringtable.xml Co-authored-by: Kex <[email protected]>
1 parent d9c7ce2 commit 34d103b

12 files changed

+246
-27
lines changed

addons/editor/functions/fnc_fixSideButtons.sqf

+16-16
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,30 @@
55
*
66
* Arguments:
77
* 0: Display <DISPLAY>
8-
* 1: Mode <NUMBER>
98
*
109
* Return Value:
1110
* None
1211
*
1312
* Example:
14-
* [DISPLAY, 0] call zen_editor_fnc_fixSideButtons
13+
* [DISPLAY] call zen_editor_fnc_fixSideButtons
1514
*
1615
* Public: No
1716
*/
1817

19-
[{
20-
params ["_display", "_mode"];
18+
params ["_display"];
2119

22-
// Get side buttons to show based on mode
23-
private _idcs = switch (_mode) do {
24-
case 0;
25-
case 1: {IDCS_SIDE_BUTTONS};
26-
case 2;
27-
case 3: {[IDC_RSCDISPLAYCURATOR_SIDEEMPTY]};
28-
default {[]}
29-
};
20+
private _sections = missionNamespace getVariable ["RscDisplayCurator_sections", [0, 0]];
21+
_sections params ["_mode"];
3022

31-
{
32-
(_display displayCtrl _x) ctrlShow true;
33-
} forEach _idcs;
34-
}, _this] call CBA_fnc_execNextFrame;
23+
// Get side buttons to show based on mode
24+
private _idcs = switch (_mode) do {
25+
case 0;
26+
case 1: {IDCS_SIDE_BUTTONS};
27+
case 2;
28+
case 3: {[IDC_RSCDISPLAYCURATOR_SIDEEMPTY]};
29+
default {[]};
30+
};
31+
32+
{
33+
(_display displayCtrl _x) ctrlShow true;
34+
} forEach _idcs;

addons/editor/functions/fnc_handleLoad.sqf

+5
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,14 @@ GVAR(iconsVisible) = true;
137137

138138
if (isNull _display) exitWith {};
139139

140+
[QGVAR(treesLoaded), _display] call CBA_fnc_localEvent;
141+
140142
[_display] call FUNC(addGroupIcons);
141143
[_display] call FUNC(declutterEmptyTree);
142144

145+
// Initially fix side buttons (can be hidden if a tree has no entries)
146+
[FUNC(fixSideButtons), _display] call CBA_fnc_execNextFrame;
147+
143148
{
144149
private _ctrl = _display displayCtrl _x;
145150
_ctrl call EFUNC(common,collapseTree);

addons/editor/functions/fnc_handleModeButtons.sqf

+7-7
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515
* Public: No
1616
*/
1717

18-
[{
19-
params ["_ctrlButton"];
2018

21-
private _display = ctrlParent _ctrlButton;
22-
private _mode = IDCS_MODE_BUTTONS find ctrlIDC _ctrlButton;
23-
private _side = GETMVAR(RscDisplayCurator_sections,[]) param [1, 0];
19+
params ["_ctrlButton"];
20+
21+
private _display = ctrlParent _ctrlButton;
2422

25-
[QGVAR(modeChanged), [_display, _mode, _side]] call CBA_fnc_localEvent;
26-
}, _this] call CBA_fnc_execNextFrame;
23+
[{
24+
RscDisplayCurator_sections params ["_mode", "_side"];
25+
[QGVAR(modeChanged), [_this, _mode, _side]] call CBA_fnc_localEvent;
26+
}, _display] call CBA_fnc_execNextFrame;

addons/editor/functions/fnc_handleSideButtons.sqf

+3-4
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@ params ["_ctrlButton"];
2020
if !(_ctrlButton getVariable [QGVAR(hovered), false]) exitWith {};
2121

2222
private _display = ctrlParent _ctrlButton;
23-
private _mode = GETMVAR(RscDisplayCurator_sections,[]) param [0, 0];
24-
private _side = IDCS_SIDE_BUTTONS find ctrlIDC _ctrlButton;
2523

2624
[{
27-
[QGVAR(sideChanged), _this] call CBA_fnc_localEvent;
28-
}, [_display, _mode, _side]] call CBA_fnc_execNextFrame;
25+
RscDisplayCurator_sections params ["_mode", "_side"];
26+
[QGVAR(sideChanged), [_this, _mode, _side]] call CBA_fnc_localEvent;
27+
}, _display] call CBA_fnc_execNextFrame;

addons/faction_filter/$PBOPREFIX$

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
x\zen\addons\faction_filter
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Extended_PreStart_EventHandlers {
2+
class ADDON {
3+
init = QUOTE(call COMPILE_FILE(XEH_preStart));
4+
};
5+
};
6+
7+
class Extended_PreInit_EventHandlers {
8+
class ADDON {
9+
init = QUOTE(call COMPILE_FILE(XEH_preInit));
10+
};
11+
};
12+
13+
class Extended_PostInit_EventHandlers {
14+
class ADDON {
15+
init = QUOTE(call COMPILE_FILE(XEH_postInit));
16+
};
17+
};
+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#include "script_component.hpp"
2+
3+
["CBA_SettingChanged", {
4+
params ["_name"];
5+
6+
// Schedule the Zeus display to be reloaded when a faction filter setting is changed
7+
// Allows for changing faction filter settings mid-mission while the interface is forced
8+
if (QUOTE(ADDON) in _name && {!isNull findDisplay IDD_RSCDISPLAYCURATOR} && {isNil QGVAR(displayReload)}) then {
9+
GVAR(displayReload) = true;
10+
11+
{
12+
(findDisplay IDD_RSCDISPLAYCURATOR) closeDisplay IDC_CANCEL;
13+
14+
[{
15+
isNull findDisplay IDD_RSCDISPLAYCURATOR
16+
}, {
17+
openCuratorInterface;
18+
GVAR(displayReload) = nil;
19+
}] call CBA_fnc_waitUntilAndExecute;
20+
} call CBA_fnc_execNextFrame;
21+
};
22+
}] call CBA_fnc_addEventHandler;
23+
24+
[QEGVAR(editor,treesLoaded), {
25+
BEGIN_COUNTER(processTrees);
26+
27+
params ["_display"];
28+
29+
private _fnc_processTrees = {
30+
params ["_treeIDCs", "_basePath"];
31+
32+
{
33+
private _ctrlTree = _display displayCtrl _x;
34+
35+
for "_i" from (_ctrlTree tvCount _basePath) - 1 to 0 step -1 do {
36+
private _path = _basePath + [_i];
37+
private _name = _ctrlTree tvText _path;
38+
39+
// Get the setting variable name that corresponds to this faction's name and side
40+
private _varName = GVAR(map) getVariable [FACTION_ID(_forEachIndex,_name), ""];
41+
42+
if !(missionNamespace getVariable [_varName, true]) then {
43+
_ctrlTree tvDelete _path;
44+
};
45+
};
46+
} forEach _treeIDCs;
47+
};
48+
49+
[[
50+
IDC_RSCDISPLAYCURATOR_CREATE_UNITS_EAST,
51+
IDC_RSCDISPLAYCURATOR_CREATE_UNITS_WEST,
52+
IDC_RSCDISPLAYCURATOR_CREATE_UNITS_GUER,
53+
IDC_RSCDISPLAYCURATOR_CREATE_UNITS_CIV
54+
], []] call _fnc_processTrees;
55+
56+
[[
57+
IDC_RSCDISPLAYCURATOR_CREATE_GROUPS_EAST,
58+
IDC_RSCDISPLAYCURATOR_CREATE_GROUPS_WEST,
59+
IDC_RSCDISPLAYCURATOR_CREATE_GROUPS_GUER,
60+
IDC_RSCDISPLAYCURATOR_CREATE_GROUPS_CIV
61+
], [0]] call _fnc_processTrees;
62+
63+
END_COUNTER(processTrees);
64+
}] call CBA_fnc_addEventHandler;

addons/faction_filter/XEH_preInit.sqf

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include "script_component.hpp"
2+
3+
ADDON = false;
4+
5+
// Create trees do not provide the faction class name that a given node represents
6+
// Only the faction's name and side can be obtained from the tree
7+
// This namespace maps a faction's name and side to its corresponding setting variable name
8+
GVAR(map) = [] call CBA_fnc_createNamespace;
9+
10+
{
11+
_x params ["_name", "_faction", "_side"];
12+
13+
private _varName = format [QGVAR(%1_%2), _side, _faction];
14+
GVAR(map) setVariable [FACTION_ID(_side,_name), _varName];
15+
16+
private _sideName = ["str_east", "str_west", "str_guerrila", "str_civilian"] select _side;
17+
[_varName, "CHECKBOX", _name, [LSTRING(DisplayName), _sideName], true, false] call CBA_fnc_addSetting;
18+
} forEach (uiNamespace getVariable QGVAR(factions));
19+
20+
ADDON = true;
+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#include "script_component.hpp"
2+
3+
private _factions = [];
4+
private _cfgVehicles = configFile >> "CfgVehicles";
5+
private _cfgFactionClasses = configFile >> "CfgFactionClasses";
6+
private _cfgEditorCategories = configFile >> "CfgEditorCategories";
7+
8+
// Zeus only includes objects defined in the units array of CfgPatches classes
9+
{
10+
{
11+
// Classes that do not inherit from AllVehicles have thier side ignored and are considered props (Zeus also ignores animals)
12+
if (_x isKindOf "AllVehicles" && {!(_x isKindOf "Animal")}) then {
13+
private _config = _cfgVehicles >> _x;
14+
15+
// scopeCurator always has priority over scope, scope is only used if scopeCurator is not defined
16+
if (getNumber (_config >> "scopeCurator") == 2 || {getNumber (_config >> "scope") == 2 && {!isNumber (_config >> "scopeCurator")}}) then {
17+
private _side = getNumber (_config >> "side");
18+
19+
if (_side in [0, 1, 2, 3]) then {
20+
// Either editorCategory or faction can be used to set an object's category
21+
// Usually, faction is used for characters and vehicles and editorCategory is used for props
22+
// When both are present, editorCategory has priority and is used by Zeus
23+
private _factionConfig = if (isText (_config >> "editorCategory")) then {
24+
_cfgEditorCategories >> getText (_config >> "editorCategory")
25+
} else {
26+
_cfgFactionClasses >> getText (_config >> "faction")
27+
};
28+
29+
_factions pushBackUnique [getText (_factionConfig >> "displayName"), configName _factionConfig, _side];
30+
};
31+
};
32+
};
33+
} forEach getArray (_x >> "units");
34+
} forEach configProperties [configFile >> "CfgPatches", "isClass _x"];
35+
36+
// Group compositions do not necessarily use the same faction names as the object's they contain
37+
{
38+
private _side = getNumber (_x >> "side");
39+
40+
if (_side in [0, 1, 2, 3]) then {
41+
{
42+
private _name = getText (_x >> "name");
43+
44+
// Add the faction if one with this name and side does not exist yet
45+
if (_factions findIf {_x select 0 == _name && {_x select 2 == _side}} == -1) then {
46+
private _faction = configName _x;
47+
48+
// Add "_groups" suffix to the faction class name if it already exists
49+
// Happens when groups use the same faction class as objects but with a different display name
50+
if (_factions findIf {_x select 1 == _faction} != -1) then {
51+
_faction = _faction + "_groups";
52+
};
53+
54+
_factions pushBackUnique [_name, _faction, _side];
55+
};
56+
} forEach configProperties [_x, "isClass _x"];
57+
};
58+
} forEach configProperties [configFile >> "CfgGroups", "isClass _x"];
59+
60+
// Sort factions in ascending order by name
61+
_factions sort true;
62+
63+
uiNamespace setVariable [QGVAR(factions), _factions];

addons/faction_filter/config.cpp

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include "script_component.hpp"
2+
3+
class CfgPatches {
4+
class ADDON {
5+
name = COMPONENT_NAME;
6+
units[] = {};
7+
weapons[] = {};
8+
requiredVersion = REQUIRED_VERSION;
9+
requiredAddons[] = {"zen_editor"};
10+
author = ECSTRING(main,Author);
11+
authors[] = {"mharis001", "Kex"};
12+
url = ECSTRING(main,URL);
13+
VERSION_CONFIG;
14+
};
15+
};
16+
17+
PRELOAD_ADDONS;
18+
19+
#include "CfgEventHandlers.hpp"
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#define COMPONENT faction_filter
2+
#define COMPONENT_BEAUTIFIED Faction Filter
3+
#include "\x\zen\addons\main\script_mod.hpp"
4+
5+
// #define DEBUG_MODE_FULL
6+
// #define DISABLE_COMPILE_CACHE
7+
// #define ENABLE_PERFORMANCE_COUNTERS
8+
9+
#ifdef DEBUG_ENABLED_FACTION_FILTER
10+
#define DEBUG_MODE_FULL
11+
#endif
12+
13+
#ifdef DEBUG_SETTINGS_FACTION_FILTER
14+
#define DEBUG_SETTINGS DEBUG_SETTINGS_FACTION_FILTER
15+
#endif
16+
17+
#include "\x\zen\addons\main\script_macros.hpp"
18+
19+
#include "\x\zen\addons\common\defineResinclDesign.inc"
20+
21+
#define FACTION_ID(side,name) format [QGVAR(%1:%2), side, name]

addons/faction_filter/stringtable.xml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project name="ZEN">
3+
<Package name="Faction_Filter">
4+
<Key ID="STR_ZEN_Faction_Filter_DisplayName">
5+
<English>Zeus Enhanced - Faction Filter</English>
6+
<French>Zeus Enhanced - Filtre des Fractions</French>
7+
<German>Zeus Enhanced - Fraktionsfilter</German>
8+
</Key>
9+
</Package>
10+
</Project>

0 commit comments

Comments
 (0)