diff --git a/addons/markers/functions/fnc_getEnabledChannels.sqf b/addons/markers/functions/fnc_getEnabledChannels.sqf index 226dfb37ec..291544f73e 100644 --- a/addons/markers/functions/fnc_getEnabledChannels.sqf +++ b/addons/markers/functions/fnc_getEnabledChannels.sqf @@ -1,6 +1,6 @@ #include "..\script_component.hpp" /* - * Author: commy2, Timi007 + * Author: commy2, Timi007, LinkIsGrim * Return enabled channels. * * Arguments: @@ -17,33 +17,19 @@ params [["_localize", false, [false]]]; -private _currentChannel = currentChannel; private _enabledChannels = []; +private _currentChannel = currentChannel; -if (_localize) then { - if (setCurrentChannel 0) then { - _enabledChannels pushBack localize "str_channel_global"; - }; +// Micro-optimization so we don't rebuild the array and localize in each iteration +private _engineChannels = CHANNEL_NAMES; - if (setCurrentChannel 1) then { - _enabledChannels pushBack localize "str_channel_side"; - }; - - if (setCurrentChannel 2) then { - _enabledChannels pushBack localize "str_channel_command"; - }; - - if (setCurrentChannel 3) then { - _enabledChannels pushBack localize "str_channel_group"; - }; - - if (setCurrentChannel 4) then { - _enabledChannels pushBack localize "str_channel_vehicle"; - }; -} else { - for "_i" from 0 to 4 do { - if (setCurrentChannel _i) then { - _enabledChannels pushBack _i; +for "_channelId" from 0 to 15 do { + if (_channelId == 5) then {continue}; // Direct channel, ignore + if (setCurrentChannel _channelId) then { + if (_localize) then { + _enabledChannels pushBack (_engineChannels param [_channelId, (radioChannelInfo (_channelId - 5)) select 1]); // radioChannelInfo works off custom IDs only, offset engine channels + } else { + _enabledChannels pushBack _channelId; }; }; }; diff --git a/addons/markers/functions/fnc_initInsertMarker.sqf b/addons/markers/functions/fnc_initInsertMarker.sqf index 9c43edeff1..a102502b24 100644 --- a/addons/markers/functions/fnc_initInsertMarker.sqf +++ b/addons/markers/functions/fnc_initInsertMarker.sqf @@ -223,8 +223,7 @@ while {_i < lbSize _channel} do { private _channelName = _channel lbText _i; - // _enabledChannels can not include custom channels names. Therefore also check if it's a custom one. Blame BI if the unit should not access the channel. - if (_channelName in _enabledChannels || {!(_channelName in CHANNEL_NAMES)}) then { + if (_channelName in _enabledChannels) then { _i = _i + 1; } else { _channel lbDelete _i; @@ -238,13 +237,14 @@ currentChannel }; - private _currentChannelName = CHANNEL_NAMES param [_selectChannel, localize "str_channel_group"]; + // engine channels (0-4) can use names directly, custom channels need an offset for radioChannelInfo + private _selectChannelName = CHANNEL_NAMES param [_selectChannel, radioChannelInfo (_selectChannel - 5) select 1]; // select current channel in list box, must be done after lbDelete for "_j" from 0 to (lbSize _channel - 1) do { - if (_channel lbText _j == _currentChannelName) then { + if (_channel lbText _j == _selectChannelName) then { _channel lbSetCurSel _j; - setCurrentChannel (CHANNEL_NAMES find _currentChannelName); + setCurrentChannel _selectChannel; }; }; diff --git a/addons/markers/functions/fnc_onLBSelChangedChannel.sqf b/addons/markers/functions/fnc_onLBSelChangedChannel.sqf index d975ddb753..d8c2bc71fb 100644 --- a/addons/markers/functions/fnc_onLBSelChangedChannel.sqf +++ b/addons/markers/functions/fnc_onLBSelChangedChannel.sqf @@ -1,6 +1,6 @@ #include "..\script_component.hpp" /* - * Author: commy2 + * Author: commy2, LinkIsGrim * When the channel list box is changed. * * Arguments: @@ -19,6 +19,6 @@ params ["_ctrl", "_index"]; TRACE_2("params",_ctrl,_index); -private _channelName = _ctrl lbText _index; +private _enabledChannels = false call FUNC(getEnabledChannels); -setCurrentChannel (CHANNEL_NAMES find _channelName); +setCurrentChannel (_enabledChannels select _index);