Skip to content

Commit

Permalink
Markers - Fix issues with custom channels (acemod#9383)
Browse files Browse the repository at this point in the history
  • Loading branch information
LinkIsGrim authored Sep 13, 2023
1 parent 7a3e5dd commit f7b520b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 33 deletions.
36 changes: 11 additions & 25 deletions addons/markers/functions/fnc_getEnabledChannels.sqf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "..\script_component.hpp"
/*
* Author: commy2, Timi007
* Author: commy2, Timi007, LinkIsGrim
* Return enabled channels.
*
* Arguments:
Expand All @@ -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";
};

if (setCurrentChannel 1) then {
_enabledChannels pushBack localize "str_channel_side";
};

if (setCurrentChannel 2) then {
_enabledChannels pushBack localize "str_channel_command";
};
// Micro-optimization so we don't rebuild the array and localize in each iteration
private _engineChannels = CHANNEL_NAMES;

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;
};
};
};
Expand Down
10 changes: 5 additions & 5 deletions addons/markers/functions/fnc_initInsertMarker.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
};
};

Expand Down
6 changes: 3 additions & 3 deletions addons/markers/functions/fnc_onLBSelChangedChannel.sqf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "..\script_component.hpp"
/*
* Author: commy2
* Author: commy2, LinkIsGrim
* When the channel list box is changed.
*
* Arguments:
Expand All @@ -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);

0 comments on commit f7b520b

Please sign in to comment.