@@ -33,15 +33,9 @@ _ctrlList ctrlAddEventHandler ["LBSelChanged", {
3333 _display call (_display getVariable QFUNC(verify));
3434}];
3535
36- private _categories = [];
37-
3836{
39- _x params [" _category" ];
40-
41- if (_categories pushBackUnique _category ! = - 1 ) then {
42- _ctrlList lbAdd _category ;
43- };
44- } forEach GET_COMPOSITIONS;
37+ _ctrlList lbAdd _x ;
38+ } forEach keys GET_COMPOSITIONS;
4539
4640// Verify entered values (not empty, unique category and name combination)
4741_display setVariable [QFUNC(verify), {
@@ -64,7 +58,7 @@ _display setVariable [QFUNC(verify), {
6458 _ctrlButtonOK ctrlSetTooltip localize LSTRING(NameCannotBeEmpty);
6559 };
6660
67- private _enabled = FIND_COMPOSITION (_category ,_name ) == - 1 ;
61+ private _enabled = isNil {GET_COMPOSITION (_category ,_name )} ;
6862 private _tooltip = if (_enabled ) then {" " } else {localize LSTRING(CompositionAlreadyExists)};
6963
7064 _ctrlButtonOK ctrlEnable _enabled ;
@@ -93,7 +87,7 @@ private _ctrlTitle = _display displayCtrl IDC_DISPLAY_TITLE;
9387_ctrlTitle ctrlSetText localize _title ;
9488
9589// Set the current composition category and name
96- _composition params [" _category" , " _name" ];
90+ _composition params [" _category" , " _name" , " _data " ];
9791_ctrlCategory ctrlSetText _category ;
9892_ctrlName ctrlSetText _name ;
9993
@@ -104,29 +98,31 @@ private _ctrlButtonOK = _display displayCtrl IDC_OK;
10498
10599[_ctrlButtonOK , " ButtonClick" , {
106100 params [" _ctrlButtonOK" ];
107- _thisArgs params [" _mode" , " _composition " ];
101+ _thisArgs params [" _mode" , " _data " ];
108102
109103 private _display = ctrlParent _ctrlButtonOK ;
110104 private _ctrlCategory = _display displayCtrl IDC_DISPLAY_CATEGORY;
111105 private _ctrlName = _display displayCtrl IDC_DISPLAY_NAME;
112106
113107 // Set the new composition category and name
114- _composition set [ 0 , ctrlText _ctrlCategory ] ;
115- _composition set [ 1 , ctrlText _ctrlName ] ;
116-
117- if ( _mode == " create " ) then {
118- // In create mode, add the composition to saved data
119- private _compositions = GET_COMPOSITIONS ;
120- _compositions pushBack _composition ;
121- SET_COMPOSITIONS( _compositions );
122- } else {
108+ private _category = ctrlText _ctrlCategory ;
109+ private _name = ctrlText _ctrlName ;
110+
111+ // Add the composition to saved data
112+ private _compositions = GET_COMPOSITIONS;
113+ private _categoryHash = _compositions getOrDefault [ _category , createHashMap , true ] ;
114+ _categoryHash set [ _name , _data ] ;
115+
116+ if ( _mode == " edit " ) then {
123117 // In edit mode, remove the old composition from the tree
124- [false ] call FUNC(removeFromTree);
118+ [true ] call FUNC(removeFromTree);
125119 };
126120
121+ SET_COMPOSITIONS(_compositions );
122+
127123 // Add the new/updated composition to the tree
128- GVAR(treeAdditions) pushBack + _composition ;
124+ GVAR(treeAdditions) pushBack [ _category , _name , + _data ] ;
129125 [findDisplay IDD_RSCDISPLAYCURATOR] call FUNC(processTreeAdditions);
130126
131127 saveProfileNamespace ;
132- }, _this ] call CBA_fnc_addBISEventHandler ;
128+ }, [ _mode , _data ] ] call CBA_fnc_addBISEventHandler ;
0 commit comments