From 791e66f811e2b9525361fff8c155bbe366ba1924 Mon Sep 17 00:00:00 2001 From: mharis001 <34453221+mharis001@users.noreply.github.com> Date: Fri, 2 Dec 2022 22:40:45 -0500 Subject: [PATCH] Add mod icons to create unit trees (#684) * Add mod icons to create unit trees * Add German translations * Fix comment Co-authored-by: Kex --- addons/editor/XEH_PREP.hpp | 1 + addons/editor/functions/fnc_addModIcons.sqf | 82 +++++++++++++++++++++ addons/editor/functions/fnc_handleLoad.sqf | 5 +- addons/editor/initSettings.sqf | 9 +++ addons/editor/stringtable.xml | 8 ++ 5 files changed, 104 insertions(+), 1 deletion(-) create mode 100644 addons/editor/functions/fnc_addModIcons.sqf diff --git a/addons/editor/XEH_PREP.hpp b/addons/editor/XEH_PREP.hpp index c35e8d435..938cffb7c 100644 --- a/addons/editor/XEH_PREP.hpp +++ b/addons/editor/XEH_PREP.hpp @@ -1,4 +1,5 @@ PREP(addGroupIcons); +PREP(addModIcons); PREP(declutterEmptyTree); PREP(fixSideButtons); PREP(handleKeyDown); diff --git a/addons/editor/functions/fnc_addModIcons.sqf b/addons/editor/functions/fnc_addModIcons.sqf new file mode 100644 index 000000000..84f13a042 --- /dev/null +++ b/addons/editor/functions/fnc_addModIcons.sqf @@ -0,0 +1,82 @@ +#include "script_component.hpp" +/* + * Author: mharis001 + * Adds mod icons to the create unit trees. + * + * Arguments: + * 0: Display + * + * Return Value: + * None + * + * Example: + * [DISPLAY] call zen_editor_fnc_addModIcons + * + * Public: No + */ + +if (!GVAR(addModIcons)) exitWith {}; + +BEGIN_COUNTER(addModIcons); + +params ["_display"]; + +// Cache to store mod icons by object type +if (isNil QGVAR(modIcons)) then { + GVAR(modIcons) = createHashMap; +}; + +private _cfgVehicles = configFile >> "CfgVehicles"; + +{ + private _ctrlTree = _display displayCtrl _x; + + for "_i" from 0 to (_ctrlTree tvCount []) - 1 do { + for "_j" from 0 to ((_ctrlTree tvCount [_i]) - 1) do { + for "_k" from 0 to ((_ctrlTree tvCount [_i, _j]) - 1) do { + private _path = [_i, _j, _k]; + private _type = _ctrlTree tvData _path; + private _icon = GVAR(modIcons) get _type; + + if (isNil "_icon") then { + private _mod = [_cfgVehicles >> _type] call EFUNC(common,getDLC); + + // modParams command prints warning in RPT if used with empty mod + if (_mod != "") then { + _icon = modParams [_mod, ["logoSmall"]] param [0, ""]; + + // Attempt to optimize the mod icon's file path. modParams returns file paths without the + // leading backslash however, tvSetPictureRight and other commands that deal with pictures + // perform significantly better (from testing, ~20 times faster) when the file path starts + // with a backslash. We can't take advantage of this difference when the mod icon is in the + // root directory of the mod, instead of a PBO. In this situation, the file path is an + // absolute path (i.e. with a drive letter on Windows). From testing, base game and popular + // asset mods specify the mod's logo as an image inside of one of its PBOs. This optimization + // combined with the icons cache allows us to add mod icons without significantly increasing + // load times after the initial load (base game: ~28 ms, with RHS and CUP: ~67 ms) when + // the icons are contained inside PBOs. It should be noted that the benefits of this optimization + // quickly deteriorate when asset mods that contain the icon in the root directory are loaded. + if (_icon != "" && {_icon select [0, 1] != "\"} && {_icon select [1, 1] != ":"}) then { + private _sanitizedIcon = "\" + toLower _icon; + + // Ensure that the icon file exists just in case + if (fileExists _sanitizedIcon) then { + _icon = _sanitizedIcon; + }; + }; + } else { + _icon = ""; + }; + + GVAR(modIcons) set [_type, _icon]; + }; + + if (_icon != "") then { + _ctrlTree tvSetPictureRight [_path, _icon]; + }; + }; + }; + }; +} forEach IDCS_UNIT_TREES; + +END_COUNTER(addModIcons); diff --git a/addons/editor/functions/fnc_handleLoad.sqf b/addons/editor/functions/fnc_handleLoad.sqf index 11d69ca3c..58525ce2d 100644 --- a/addons/editor/functions/fnc_handleLoad.sqf +++ b/addons/editor/functions/fnc_handleLoad.sqf @@ -148,8 +148,11 @@ GVAR(iconsVisible) = true; [QGVAR(treesLoaded), _display] call CBA_fnc_localEvent; - [_display] call FUNC(addGroupIcons); + // Decluttering empty tree first since this will potentially reduce the number + // of entries that need to be processed by the subsequent functions [_display] call FUNC(declutterEmptyTree); + [_display] call FUNC(addGroupIcons); + [_display] call FUNC(addModIcons); // Initially fix side buttons (can be hidden if a tree has no entries) [FUNC(fixSideButtons), _display] call CBA_fnc_execNextFrame; diff --git a/addons/editor/initSettings.sqf b/addons/editor/initSettings.sqf index 82e980d64..5fbe4fe59 100644 --- a/addons/editor/initSettings.sqf +++ b/addons/editor/initSettings.sqf @@ -43,6 +43,15 @@ false ] call CBA_fnc_addSetting; +[ + QGVAR(addModIcons), + "CHECKBOX", + [LSTRING(AddModIcons), LSTRING(AddModIcons_Description)], + [ELSTRING(main,DisplayName), LSTRING(DisplayName)], + false, + false +] call CBA_fnc_addSetting; + [ QGVAR(randomizeCopyPaste), "CHECKBOX", diff --git a/addons/editor/stringtable.xml b/addons/editor/stringtable.xml index 8b0e5e451..74734f6fb 100644 --- a/addons/editor/stringtable.xml +++ b/addons/editor/stringtable.xml @@ -126,6 +126,14 @@ 將小隊圖標添加到創建一組樹。 Visualizza i simboli di gruppo nell'albero dei gruppi. + + Add Mod Icons + Modsymbole anzeigen + + + Adds mod icons to the create unit trees. WARNING: Can significantly increase display load times. + Zeigt Modsymbole im Einheitenbaum an. WARNUNG: Kann die Ladezeit des Baums deutlich erhöhen. + Randomize Deep Copy/Paste Zufallsgenerator für komplette Kopien