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 mod icons to create unit trees #684

Merged
merged 3 commits into from
Dec 3, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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/editor/XEH_PREP.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
PREP(addGroupIcons);
PREP(addModIcons);
PREP(declutterEmptyTree);
PREP(fixSideButtons);
PREP(handleKeyDown);
Expand Down
82 changes: 82 additions & 0 deletions addons/editor/functions/fnc_addModIcons.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#include "script_component.hpp"
/*
* Author: mharis001
* Adds mod icons to the create unit trees.
*
* Arguments:
* 0: Display <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 driver 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);
5 changes: 4 additions & 1 deletion addons/editor/functions/fnc_handleLoad.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 9 additions & 0 deletions addons/editor/initSettings.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 8 additions & 0 deletions addons/editor/stringtable.xml
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,14 @@
<Chinese>將小隊圖標添加到創建一組樹。</Chinese>
<Italian>Visualizza i simboli di gruppo nell'albero dei gruppi.</Italian>
</Key>
<Key ID="STR_ZEN_Editor_AddModIcons">
<English>Add Mod Icons</English>
<German>Modsymbole anzeigen</German>
</Key>
<Key ID="STR_ZEN_Editor_AddModIcons_Description">
<English>Adds mod icons to the create unit trees. WARNING: Can significantly increase display load times.</English>
<German>Zeigt Modsymbole im Einheitenbaum an. WARNUNG: Kann die Ladezeit des Baums deutlich erhöhen.</German>
</Key>
<Key ID="STR_ZEN_Editor_RandomizeCopyPaste">
<English>Randomize Deep Copy/Paste</English>
<German>Zufallsgenerator für komplette Kopien</German>
Expand Down