Skip to content

Commit

Permalink
Overhaul Tracers module (#491)
Browse files Browse the repository at this point in the history
  • Loading branch information
ampersand38 authored Apr 20, 2021
1 parent 7b27ef2 commit 3b360af
Show file tree
Hide file tree
Showing 13 changed files with 568 additions and 0 deletions.
9 changes: 9 additions & 0 deletions addons/common/stringtable.xml
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,9 @@
<Japanese>目標</Japanese>
<Korean>목표</Korean>
</Key>
<Key ID="STR_ZEN_Common_Cursor">
<English>Cursor</English>
</Key>
<Key ID="STR_ZEN_Common_SelectedUnit">
<English>Selected Unit</English>
<German>Ausgewählte Einheit</German>
Expand Down Expand Up @@ -342,6 +345,12 @@
<Japanese>固定式</Japanese>
<Korean>고정</Korean>
</Key>
<Key ID="STR_ZEN_Common_Weapon">
<English>Weapon</English>
</Key>
<Key ID="STR_ZEN_Common_Magazine">
<English>Magazine</English>
</Key>
<Key ID="STR_ZEN_Common_Nearest">
<English>Nearest</English>
<French>Le plus proche</French>
Expand Down
11 changes: 11 additions & 0 deletions addons/modules/CfgVehicles.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ class CfgVehicles {
scopeCurator = 1;
};

class ModuleTracers_F: Module_F {
scopeCurator = 1;
};

class ModuleCAS_F;
class ModuleCASGun_F: ModuleCAS_F {
scopeCurator = 1;
Expand Down Expand Up @@ -428,6 +432,13 @@ class CfgVehicles {
function = QFUNC(moduleToggleLamps);
icon = QPATHTOF(ui\street_lamp_ca.paa);
};
class GVAR(moduleTracers): GVAR(moduleBase) {
category = "Effects";
displayName = "$STR_a3_cfgvehicles_moduletracers_f_0";
curatorInfoType = QGVAR(RscTracers);
icon = "\a3\modules_f_curator\Data\iconTracers_ca.paa";
portrait = "\a3\modules_f_curator\Data\portraitTracers_ca.paa";
};
class GVAR(moduleTurretOptics): GVAR(moduleBase) {
curatorCanAttach = 1;
category = QGVAR(Equipment);
Expand Down
3 changes: 3 additions & 0 deletions addons/modules/XEH_PREP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ PREP(compileEffects);
PREP(compileFlags);
PREP(compileMines);
PREP(compileReinforcements);
PREP(compileTracers);
PREP(gui_ambientFlyby);
PREP(gui_cas);
PREP(gui_damageBuildings);
Expand All @@ -18,6 +19,7 @@ PREP(gui_globalHint);
PREP(gui_setDate);
PREP(gui_sideRelations);
PREP(gui_spawnReinforcements);
PREP(gui_tracers);
PREP(initDisplay);
PREP(initModule);
PREP(moduleAddFullArsenal);
Expand Down Expand Up @@ -81,6 +83,7 @@ PREP(moduleTeleportPlayers);
PREP(moduleToggleFlashlights);
PREP(moduleToggleIRLasers);
PREP(moduleToggleLamps);
PREP(moduleTracers);
PREP(moduleTurretOptics);
PREP(moduleUnGarrison);
PREP(moduleVisibility);
Expand Down
1 change: 1 addition & 0 deletions addons/modules/XEH_postInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ if (isServer) then {
[QGVAR(moduleCAS), LINKFUNC(moduleCAS)] call CBA_fnc_addEventHandler;
[QGVAR(moduleEditableObjects), LINKFUNC(moduleEditableObjects)] call CBA_fnc_addEventHandler;
[QGVAR(moduleSpawnReinforcements), LINKFUNC(moduleSpawnReinforcements)] call CBA_fnc_addEventHandler;
[QGVAR(moduleTracers), LINKFUNC(moduleTracers)] call CBA_fnc_addEventHandler;

// Public variable to track created teleporter objects
missionNamespace setVariable [QGVAR(teleporters), [], true];
Expand Down
1 change: 1 addition & 0 deletions addons/modules/XEH_preStart.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ call FUNC(compileEffects);
call FUNC(compileFlags);
call FUNC(compileMines);
call FUNC(compileReinforcements);
call FUNC(compileTracers);
1 change: 1 addition & 0 deletions addons/modules/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class CfgPatches {
QGVAR(moduleToggleFlashlights),
QGVAR(moduleToggleIRLasers),
QGVAR(moduleToggleLamps),
QGVAR(moduleTracers),
QGVAR(moduleTurretOptics),
QGVAR(moduleUnGarrison),
QGVAR(moduleVisibility),
Expand Down
52 changes: 52 additions & 0 deletions addons/modules/functions/fnc_compileTracers.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#include "script_component.hpp"
/*
* Author: Ampersand, mharis001
* Compiles a list of weapons that have compatible tracer magazines.
*
* Arguments:
* None
*
* Return Value:
* None
*
* Example:
* [] call zen_modules_fnc_compileTracers
*
* Public: No
*/

private _tracersCache = createHashMap;
private _cfgMagazines = configFile >> "CfgMagazines";
private _cfgMagazineWells = configFile >> "CfgMagazineWells";

{
if (
getNumber (_x >> "scope") == 2
&& {getNumber (_x >> "type") == TYPE_WEAPON_PRIMARY}
&& {count getArray (_x >> "muzzles") == 1}
) then {
private _weapon = configName _x;

if (getText (_x >> "baseWeapon") == _weapon) then {
private _magazines = getArray (_x >> "magazines");

{
{
_magazines insert [-1, getArray _x, true];
} forEach configProperties [_cfgMagazineWells >> _x, "isArray _x", false];
} forEach getArray (_x >> "magazineWell");

private _tracerMagazines = _magazines select {
getNumber (_cfgMagazines >> _x >> "tracersEvery") == 1
} apply {
configName (_cfgMagazines >> _x)
};

if (_tracerMagazines isNotEqualTo []) then {
_tracersCache set [_weapon, _tracerMagazines];
};
};
};
} forEach configProperties [configFile >> "CfgWeapons", "isClass _x"];

uiNamespace setVariable [QGVAR(tracersCache), _tracersCache];
191 changes: 191 additions & 0 deletions addons/modules/functions/fnc_gui_tracers.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
#include "script_component.hpp"
/*
* Author: Ampersand, mharis001
* Initializes the "Tracers" Zeus module display.
*
* Arguments:
* 0: Display <DISPLAY>
* 1: Logic <OBJECT>
*
* Return Value:
* None
*
* Example:
* [DISPLAY, LOGIC] call zen_modules_fnc_gui_tracers
*
* Public: No
*/

params ["_display", "_logic"];

// Get the current tracer parameters (use default if module has not been initialized yet)
private _params = _logic getVariable QGVAR(tracersParams);
private _isInit = isNil "_params";

if (_isInit) then {
_params = ["LMG_Mk200_F", "200Rnd_65x39_cased_Box_Tracer_Red", [5, 10, 15], 2, objNull];
};

_params params ["_weapon", "_magazine", "_delay", "_dispersion", "_target"];

// Store the logic and target (in case the target is not changed)
_display setVariable [QGVAR(params), [_logic, _target]];

// Populate the weapons list
private _ctrlWeapon = _display displayCtrl IDC_TRACERS_WEAPON;
private _cfgWeapons = configFile >> "CfgWeapons";

{
private _config = _cfgWeapons >> _x;
private _name = getText (_config >> "displayName");
private _icon = getText (_config >> "picture");

private _index = _ctrlWeapon lnbAddRow ["", _name];
_ctrlWeapon lnbSetTooltip [[_index, 0], format ["%1\n%2", _name, _x]];
_ctrlWeapon lnbSetPicture [[_index, 0], _icon];
_ctrlWeapon lnbSetData [[_index, 0], _x];
} forEach keys (uiNamespace getVariable QGVAR(tracersCache));

_ctrlWeapon lnbSort [1];

// Refresh the magazines list when a weapon is selected
_ctrlWeapon ctrlAddEventHandler ["LBSelChanged", {
params ["_ctrlWeapon", "_index"];

private _display = ctrlParent _ctrlWeapon;
private _weapon = _ctrlWeapon lnbData [_index, 0];

private _ctrlMagazine = _display displayCtrl IDC_TRACERS_MAGAZINE;
private _cfgMagazines = configFile >> "CfgMagazines";

lnbClear _ctrlMagazine;

{
private _config = _cfgMagazines >> _x;
private _name = getText (_config >> "displayName");
private _icon = getText (_config >> "picture");

private _index = _ctrlMagazine lnbAddRow ["", _name];
_ctrlMagazine lnbSetTooltip [[_index, 0], format ["%1\n%2", _name, _x]];
_ctrlMagazine lnbSetPicture [[_index, 0], _icon];
_ctrlMagazine lnbSetData [[_index, 0], _x];
} forEach (uiNamespace getVariable QGVAR(tracersCache) get _weapon);

_ctrlMagazine lnbSort [1];
_ctrlMagazine lnbSetCurSelRow 0;
}];

// Select the current weapon in the list (also initially populates magazines list)
for "_i" from 0 to (lnbSize _ctrlWeapon select 0) - 1 do {
if (_ctrlWeapon lnbData [_i, 0] == _weapon) exitWith {
_ctrlWeapon lnbSetCurSelRow _i;
};
};

// Select the current magazine in the list
private _ctrlMagazine = _display displayCtrl IDC_TRACERS_MAGAZINE;

for "_i" from 0 to (lnbSize _ctrlMagazine select 0) - 1 do {
if (_ctrlMagazine lnbData [_i, 0] == _magazine) exitWith {
_ctrlMagazine lnbSetCurSelRow _i;
};
};

// Populate the burst delay edit boxes with the current values
{
private _ctrlDelay = _display displayCtrl _x;
_ctrlDelay ctrlSetText str parseNumber (_delay select _forEachIndex toFixed 3);
} forEach [IDC_TRACERS_DELAY_MIN, IDC_TRACERS_DELAY_MID, IDC_TRACERS_DELAY_MAX];

// Select the current dispersion value
private _ctrlDispersion = _display displayCtrl IDC_TRACERS_DISPERSION;
_ctrlDispersion lbSetCurSel _dispersion;

// Initialize the target toolbox based on if the module has been initialized already
private _ctrlTarget = _display displayCtrl IDC_TRACERS_TARGET;
private _ctrlChange = _display displayCtrl IDC_TRACERS_CHANGE;

if (_isInit) then {
// Hide the change target checkbox if the module has not been initialized
// In this situation, the user must select a target
_ctrlChange cbSetChecked true;
_ctrlChange ctrlShow false;
} else {
// Enable the target toolbox when change target checkbox is checked
_ctrlChange ctrlAddEventHandler ["CheckedChanged", {
params ["_ctrlChange", "_checked"];

private _display = ctrlParent _ctrlChange;
private _enabled = _checked == 1;

private _ctrlTarget = _display displayCtrl IDC_TRACERS_TARGET;
_ctrlTarget ctrlEnable _enabled;

private _ctrlOverlay = _display getVariable QGVAR(overlay);
_ctrlOverlay ctrlShow !_enabled;
}];

// Disable the target toolbox to leave the target unchanged by default
_ctrlTarget ctrlEnable false;

// Toolbox control by default does not look different when disabled
// Using an overlay control to better convey when the toolbox is disabled
private _ctrlOverlay = _display ctrlCreate ["RscText", -1, ctrlParentControlsGroup _ctrlTarget];
_ctrlOverlay ctrlSetBackgroundColor [0, 0, 0, 0.5];
_ctrlOverlay ctrlSetPosition ctrlPosition _ctrlTarget;
_ctrlOverlay ctrlCommit 0;

_display setVariable [QGVAR(overlay), _ctrlOverlay];
};

// Confirm options when the OK button is clicked
private _ctrlButtonOK = _display displayCtrl IDC_OK;
_ctrlButtonOK ctrlAddEventHandler ["ButtonClick", {
params ["_ctrlButtonOK"];

private _display = ctrlParent _ctrlButtonOK;
(_display getVariable QGVAR(params)) params ["_logic", "_target"];

private _ctrlWeapon = _display displayCtrl IDC_TRACERS_WEAPON;
private _weapon = _ctrlWeapon lnbData [lnbCurSelRow _ctrlWeapon, 0];

private _ctrlMagazine = _display displayCtrl IDC_TRACERS_MAGAZINE;
private _magazine = _ctrlMagazine lnbData [lnbCurSelRow _ctrlMagazine, 0];

private _delay = [IDC_TRACERS_DELAY_MIN, IDC_TRACERS_DELAY_MID, IDC_TRACERS_DELAY_MAX] apply {
parseNumber ctrlText (_display displayCtrl _x)
};

private _dispersion = lbCurSel (_display displayCtrl IDC_TRACERS_DISPERSION);

// Select tracers target based on checkbox and toolbox state
private _targetType = if (cbChecked (_display displayCtrl IDC_TRACERS_CHANGE)) then {
lbCurSel (_display displayCtrl IDC_TRACERS_TARGET)
} else {
-1 // Unchanged
};

if (_targetType == 2) exitWith {
[_logic, {
params ["_successful", "_logic", "_position", "_args"];
_args params ["_weapon", "_magazine", "_delay", "_dispersion"];

if (_successful) then {
curatorMouseOver params ["_type", "_entity"];

private _target = [_position, _entity] select (_type == "OBJECT");
[QGVAR(moduleTracers), [_logic, _weapon, _magazine, _delay, _dispersion, _target]] call CBA_fnc_serverEvent;
};
}, [_weapon, _magazine, _delay, _dispersion], LSTRING(Tracers_TracersTarget)] call EFUNC(common,selectPosition);
};

if (_targetType == 1) then {
_target = AGLToASL positionCameraToWorld [0, 0, 0];
};

if (_targetType == 0) then {
_target = objNull;
};

[QGVAR(moduleTracers), [_logic, _weapon, _magazine, _delay, _dispersion, _target]] call CBA_fnc_serverEvent;
}];
Loading

0 comments on commit 3b360af

Please sign in to comment.