Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dogtags - Add context menu action to check dog tag #10101

Merged
merged 5 commits into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
2 changes: 0 additions & 2 deletions addons/dogtags/XEH_PREP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ PREP(bloodType);
PREP(canCheckDogtag);
PREP(canTakeDogtag);
PREP(checkDogtag);
PREP(checkDogtagItem);
PREP(getDogtagData);
PREP(getDogtagItem);
PREP(sendDogtagData);
PREP(showDogtag);
PREP(ssn);
PREP(takeDogtag);
Expand Down
40 changes: 36 additions & 4 deletions addons/dogtags/XEH_postInit.sqf
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
#include "script_component.hpp"

[QGVAR(showDogtag), LINKFUNC(showDogtag)] call CBA_fnc_addEventHandler;
[QGVAR(sendDogtagData), LINKFUNC(sendDogtagData)] call CBA_fnc_addEventHandler;
[QGVAR(getDogtagItem), LINKFUNC(getDogtagItem)] call CBA_fnc_addEventHandler;
[QGVAR(addDogtagItem), LINKFUNC(addDogtagItem)] call CBA_fnc_addEventHandler;

[QGVAR(broadcastDogtagInfo), {
GVAR(dogtagsData) set _this;
}] call CBA_fnc_addEventHandler;

if (isServer) then {
// Sync dogtag data from server to client
[QGVAR(requestSyncDogtagDataJIP), {
params ["_clientOwner"];

{
[QGVAR(broadcastDogtagInfo), [_x, _y], _clientOwner] call CBA_fnc_ownerEvent;
} forEach GVAR(dogtagsData);
}] call CBA_fnc_addEventHandler;
} else {
[QGVAR(requestSyncDogtagDataJIP), clientOwner] call CBA_fnc_serverEvent;
};

// Add actions and event handlers only if ace_medical is enabled
// - Adding actions via config would create a dependency
["CBA_settingsInitialized", {
Expand Down Expand Up @@ -56,8 +72,6 @@ if (["ace_arsenal"] call EFUNC(common,isModLoaded)) then {
if (_leftPanelIDC in [2010, 2012, 2014] && {_rightPanelIDC == 38}) then {
LOG("passed");
private _rightPanel = _display displayCtrl 15;
private _allDogtags = missionNamespace getVariable [QGVAR(allDogtags), []];
private _allDogtagsData = missionNamespace getVariable [QGVAR(allDogtagDatas), []];
private _cfgWeapons = configFile >> "CfgWeapons";
private _item = "";
private _dogtagData = [];
Expand All @@ -66,7 +80,7 @@ if (["ace_arsenal"] call EFUNC(common,isModLoaded)) then {
_item = _rightPanel lnbData [_i, 0];

if (_item isKindOf ["ACE_dogtag", _cfgWeapons]) then {
private _name = (_allDogtagsData param [_allDogtags find _item, []]) param [0, ""];
private _name = (GVAR(dogtagsData) getOrDefault [_item, []]) param [0, ""];

// If data doesn't exist or body has no name, set name as "unknown"
if (_name == "") then {
Expand All @@ -80,5 +94,23 @@ if (["ace_arsenal"] call EFUNC(common,isModLoaded)) then {
}] call CBA_fnc_addEventHandler;
};

// Add context menu option
[
"ACE_dogtag",
["GROUND", "CARGO", "CONTAINER"],
LLSTRING(checkItem),
nil,
QPATHTOF(data\dogtag_icon_ca.paa),
[
{true},
{true}
],
{
[GVAR(dogtagsData) getOrDefault [_this select 2, []]] call FUNC(showDogtag);

false
}
] call CBA_fnc_addItemContextMenuOption;

// Disable dogtags for civilians
"CIV_F" call FUNC(disableFactionDogtags);
6 changes: 6 additions & 0 deletions addons/dogtags/XEH_preInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,10 @@ PREP_RECOMPILE_END;

GVAR(disabledFactions) = createHashMap;

GVAR(dogtagsData) = createHashMap;

if (isServer) then {
GVAR(idCounter) = 0;
};

ADDON = true;
4 changes: 3 additions & 1 deletion addons/dogtags/functions/fnc_addDogtagActions.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ private _fnc_getActions = {
private _displayName = getText (_config >> "displayName");
private _picture = getText (_config >> "picture");

private _action = [_x, _displayName, _picture, FUNC(checkDogtagItem), {true}, {}, _x] call EFUNC(interact_menu,createAction);
private _action = [_x, _displayName, _picture, {
[GVAR(dogtagsData) getOrDefault [_this select 2, []]] call FUNC(showDogtag);
}, {true}, {}, _x] call EFUNC(interact_menu,createAction);
_actions pushBack [_action, [], _player];
};
} forEach (_player call EFUNC(common,uniqueItems));
Expand Down
22 changes: 0 additions & 22 deletions addons/dogtags/functions/fnc_checkDogtagItem.sqf

This file was deleted.

17 changes: 7 additions & 10 deletions addons/dogtags/functions/fnc_getDogtagItem.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,16 @@ if(!isServer) exitWith {};
params ["_player", "_target"];
TRACE_2("getDogtagItem",_player,_target);

private _allDogtags = missionNamespace getVariable [QGVAR(allDogtags), []];
private _allDogtagDatas = missionNamespace getVariable [QGVAR(allDogtagDatas), []];
GVAR(idCounter) = GVAR(idCounter) + 1;

private _nextID = count _allDogtags + 1;

if (_nextID > 999) exitWith {ERROR("Ran out of IDs");};
if (GVAR(idCounter) > 999) exitWith {ERROR("Ran out of IDs");};

private _dogTagData = [_target] call FUNC(getDogTagData);
private _item = format ["ACE_dogtag_%1", _nextID];
_allDogtags pushBack _item;
_allDogtagDatas pushBack _dogTagData;
private _item = format ["ACE_dogtag_%1", GVAR(idCounter)];

missionNamespace setVariable [QGVAR(allDogtags), _allDogtags];
missionNamespace setVariable [QGVAR(allDogtagDatas), _allDogtagDatas];
GVAR(dogtagsData) set [_item, _dogTagData];

[QGVAR(addDogtagItem), [_item, _dogTagData], [_player]] call CBA_fnc_targetEvent;

// Broadcast data globally, so that clients can use it where needed
[QGVAR(broadcastDogtagInfo), [_item, _dogTagData]] call CBA_fnc_globalEvent;
33 changes: 0 additions & 33 deletions addons/dogtags/functions/fnc_sendDogtagData.sqf

This file was deleted.

Loading