Skip to content
Open
Show file tree
Hide file tree
Changes from 14 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/ace_interact/XEH_postInitClient.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ if (!hasInterface) exitWith {};

["ace_arsenal_displayClosed", {
EGVAR(sys_core,arsenalOpen) = false;
[] call DFUNC(monitorRadiosHandler);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leaving a note here: We have to think about API for this, copy-pasting those lines is far from ideal.

}] call CBA_fnc_addEventHandler;

["ace_arsenal_rightPanelFilled", {
Expand Down
1 change: 0 additions & 1 deletion addons/api/CfgFunctions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ class CfgFunctions {

PATHTO_FNC(filterUnitLoadout);

PATHTO_FNC(setItemRadioReplacement);
PATHTO_FNC(getDisplayName);

PATHTO_FNC(setGlobalVolume);
Expand Down
3 changes: 3 additions & 0 deletions addons/api/XEH_PREP.hpp
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
// Helpers
PREP(mapChannelFieldName);

// Obsolete
OBSOLETE_SYS(FUNC(setItemRadioReplacement),{params ['_radioType']; [QEGVAR(sys_radio,defaultItemRadioType), _radioType, 1, "mission"] call CBA_settings_fnc_set;});
7 changes: 4 additions & 3 deletions addons/api/fnc_basicMissionSetup.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,15 @@ private _addRadios = {
_player setVariable [QGVAR(basicMissionSetup), true, true];

private _cleanRadioList = [];
if !("ACRE_PRC343" in _defaultRadios) then {
private _defaultRadio = QEGVAR(sys_radio,defaultItemRadioType) call CBA_settings_fnc_get;
if !(_defaultRadio in _defaultRadios) then {
[_player, "ItemRadio"] call EFUNC(sys_core,removeGear);
[_player, "ACRE_PRC343"] call EFUNC(sys_core,removeGear);
[_player, _defaultRadio] call EFUNC(sys_core,removeGear);
_cleanRadioList = _defaultRadios;
} else {
private _countDefaultRadios = 0;
{
if (_x == "ACRE_PRC343") then {
if (_x == _defaultRadio) then {
_countDefaultRadios = _countDefaultRadios + 1;
if (_countDefaultRadios > 1) then {
_cleanRadioList pushBack _x;
Expand Down
23 changes: 1 addition & 22 deletions addons/api/fnc_getAllRadios.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,4 @@
* Public: Yes
*/

// Return cached if already ran
if (!isNil QGVAR(allRadios)) exitWith {
GVAR(allRadios)
};

// Compile and cache for later calls
private _classes = [];
private _names = [];
{
private _isRadio = getNumber (_x >> "type") == ACRE_COMPONENT_RADIO;
private _hasComponents = !(getArray (_x >> "defaultComponents") isEqualTo []); // Only non-base classes have that
private _name = getText (_x >> "name");

// Has name and isAcre, assume valid radio class
if (_isRadio && {_hasComponents} && {_name != ""}) then {
_classes pushBack (configName _x);
_names pushBack _name;
};
} forEach ("true" configClasses (configFile >> "CfgAcreComponents"));

GVAR(allRadios) = [_classes, _names];
GVAR(allRadios)
[] call EFUNC(sys_core,getAllRadios)
22 changes: 0 additions & 22 deletions addons/api/fnc_setItemRadioReplacement.sqf

This file was deleted.

1 change: 1 addition & 0 deletions addons/sys_core/XEH_PREP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ PREP(canUnderstand);
PREP(cycleLanguage);
PREP(findOcclusion);
PREP(getAlive);
PREP(getAllRadios);
PREP(getClientIdLoop);
PREP(getCompartment);
PREP(getGear);
Expand Down
2 changes: 2 additions & 0 deletions addons/sys_core/fnc_arsenalClose.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,5 @@ private _weapons = [acre_player] call EFUNC(sys_core,getGear);
ACRE_ARSENAL_RADIOS = [];
GVAR(arsenalRadios) = [];
GVAR(arsenalOpen) = false;

[] call EFUNC(sys_radio,monitorRadiosHandler);
40 changes: 40 additions & 0 deletions addons/sys_core/fnc_getAllRadios.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include "script_component.hpp"
/*
* Author: ACRE2Team
* Returns all radios defined in CfgAcreRadios. Caches result for future calls.
*
* Arguments:
* None
*
* Return Value:
* 1: Radio Class Names <ARRAY>
* 2: Radio Display Names <ARRAY>
*
* Example:
* [] call acre_sys_core_fnc_getAllRadios;
*
* Public: No
*/

// Return cached if already ran
if (!isNil QGVAR(allRadios)) exitWith {
GVAR(allRadios)
};

// Compile and cache for later calls
private _classes = [];
private _names = [];
{
private _isRadio = getNumber (_x >> "type") == ACRE_COMPONENT_RADIO;
private _hasComponents = !(getArray (_x >> "defaultComponents") isEqualTo []); // Only non-base classes have that
private _name = getText (_x >> "name");

// Has name and isAcre, assume valid radio class
if (_isRadio && {_hasComponents} && {_name != ""}) then {
_classes pushBack (configName _x);
_names pushBack _name;
};
} forEach ("true" configClasses (configFile >> "CfgAcreComponents"));

GVAR(allRadios) = [_classes, _names];
GVAR(allRadios)
1 change: 1 addition & 0 deletions addons/sys_gui/fnc_inventoryListMouseUp.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ params ["", "_button"];
if (_button == 1) then {
LOG("inventoryListMouseUp");
ACRE_HOLD_OFF_ITEMRADIO_CHECK = false;
[] call EFUNC(sys_radio,monitorRadiosHandler);
};
2 changes: 1 addition & 1 deletion addons/sys_radio/XEH_PREP.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PREP(monitorRadios);
PREP(monitorRadiosPFH);
PREP(monitorRadiosHandler);
PREP(setActiveRadio);

PREP(openRadio);
Expand Down
9 changes: 2 additions & 7 deletions addons/sys_radio/XEH_preInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ PREP_RECOMPILE_START;
#include "XEH_PREP.hpp"
PREP_RECOMPILE_END;

#include "initSettings.sqf"

// Define caches to save repetitive config lookups.
GVAR(radioUniqueCache) = HASH_CREATE;
GVAR(radioBaseClassCache) = HASH_CREATE;
Expand All @@ -30,13 +32,6 @@ if (hasInterface) then {

DVAR(ACRE_ACTIVE_RADIO) = "";
DVAR(ACRE_SPECTATOR_RADIOS) = [];

// this isn't used anymore i do not think?
// acre_player setVariable [QGVAR(currentRadioList), []];

if (isNil QGVAR(defaultItemRadioType)) then {
GVAR(defaultItemRadioType) = "ACRE_PRC343";
};
};

ADDON = true;
8 changes: 6 additions & 2 deletions addons/sys_radio/fnc_monitorRadios.sqf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "script_component.hpp"
/*
* Author: ACRE2Team
* Sets up the per frame event handler for monitoring the local player inventory for changes.
* Sets up the CBA loadout event handler for monitoring the local player inventory for changes.
*
* Arguments:
* None
Expand All @@ -22,5 +22,9 @@ GVAR(requestingNewId) = false;
LOG("Monitor Inventory Starting");

[{ACRE_DATA_SYNCED && {(!isNil "ACRE_SERVER_INIT")} && {time >= 1}},{
[DFUNC(monitorRadiosPFH), 0.25, []] call CBA_fnc_addPerFrameHandler;
[
"loadout",
DFUNC(monitorRadiosHandler),
true
] call CBA_fnc_addPlayerEventHandler;
},[]] call CBA_fnc_waitUntilAndExecute;
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* None
*
* Example:
* [] call acre_sys_radio_fnc_monitorRadiosPFH
* [] call acre_sys_radio_fnc_monitorRadiosHandler
*
* Public: No
*/
Expand Down Expand Up @@ -46,19 +46,28 @@ private _currentUniqueItems = [];
if (GVAR(requestingNewId)) exitWith { };
private _radio = _x;
private _hasUnique = _radio call EFUNC(sys_radio,isBaseClassRadio);
if (_hasUnique || {_radio == "ItemRadio"}) then {

GVAR(requestingNewId) = true;
if (_radio == "ItemRadio") then {
if (_radio == "ItemRadio") then {
if (GVAR(defaultItemRadioType) != "") then {
// Replace vanilla radio item
_radio = GVAR(defaultItemRadioType);
GVAR(requestingNewId) = true;
[acre_player, "ItemRadio", _radio] call EFUNC(sys_core,replaceGear);
["acre_getRadioId", [acre_player, _radio, QGVAR(returnRadioId)]] call CALLSTACK(CBA_fnc_serverEvent);
TRACE_1("Getting ID for", _radio);
} else {
// Vanilla radio item replacement disabled, simply remove it.
[acre_player, "ItemRadio"] call EFUNC(sys_core,removeGear);
};
} else {
if (_hasUnique) then {
GVAR(requestingNewId) = true;
["acre_getRadioId", [acre_player, _radio, QGVAR(returnRadioId)]] call CALLSTACK(CBA_fnc_serverEvent);
TRACE_1("Getting ID for", _radio);
};
TRACE_1("Getting ID for", _radio);

["acre_getRadioId", [acre_player, _radio, QGVAR(returnRadioId)]] call CALLSTACK(CBA_fnc_serverEvent);
};
private _isUnique = _radio call EFUNC(sys_radio,isUniqueRadio);
if (_isUnique) then {

if (_radio call EFUNC(sys_radio,isUniqueRadio)) then {
if !([_radio] call EFUNC(sys_data,isRadioInitialized)) then {
WARNING_1("%1 was found in personal inventory but is uninitialized! Trying to collect new ID.",_radio);
private _baseRadio = BASECLASS(_radio);
Expand Down
19 changes: 19 additions & 0 deletions addons/sys_radio/initSettings.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
private _allRadios = [] call EFUNC(sys_core,getAllRadios);
private _radioClasses = [""] + _allRadios # 0;
private _radioNames = [localize "str_a3_cfgglasses_none0"] + _allRadios # 1;

[
QGVAR(defaultItemRadioType),
"LIST",
[
LLSTRING(DefaultItemRadioType_DisplayName),
LLSTRING(DefaultItemRadioType_Description)
],
"ACRE2",
[
_radioClasses,
_radioNames,
(_radioClasses find "ACRE_PRC343") max 0
],
true
] call CBA_fnc_addSetting;
6 changes: 6 additions & 0 deletions addons/sys_radio/stringtable.xml
Original file line number Diff line number Diff line change
Expand Up @@ -144,5 +144,11 @@
<Chinesesimp>设定无线电为1%</Chinesesimp>
<Portuguese>Rádio configurado a %1</Portuguese>
</Key>
<Key ID="STR_ACRE_sys_radio_DefaultItemRadioType_DisplayName">
<English>Vanilla radio item replacement</English>
</Key>
<Key ID="STR_ACRE_sys_radio_DefaultItemRadioType_Description">
<English>ItemRadio inventory items will be replaced with this type of radio.</English>
</Key>
</Package>
</Project>