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 - Rename inventory items #10102

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 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
6 changes: 6 additions & 0 deletions addons/dogtags/CfgEventHandlers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,9 @@ class Extended_PostInit_EventHandlers {
init = QUOTE(call COMPILE_SCRIPT(XEH_postInit));
};
};

class Extended_DisplayLoad_EventHandlers {
class RscDisplayInventory {
ADDON = QUOTE(_this call FUNC(inventoryDisplayLoad));
};
};
3 changes: 1 addition & 2 deletions addons/dogtags/XEH_PREP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ PREP(bloodType);
PREP(canCheckDogtag);
PREP(canTakeDogtag);
PREP(checkDogtag);
PREP(checkDogtagItem);
PREP(getDogtagData);
PREP(getDogtagItem);
PREP(sendDogtagData);
PREP(inventoryDisplayLoad);
PREP(showDogtag);
PREP(ssn);
PREP(takeDogtag);
Expand Down
22 changes: 18 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 {
_dogtagData = _allDogtagsData param [_allDogtags find _item, []];
_dogtagData = GVAR(dogtagsData) getOrDefault [_item, []];

// If data doesn't exist, put name as "unknown"
_rightPanel lnbSetText [[_i, 1], [LLSTRING(itemName), ": ", _dogtagData param [0, LELSTRING(common,unknown)]] joinString ""];
Expand Down
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;
50 changes: 50 additions & 0 deletions addons/dogtags/functions/fnc_inventoryDisplayLoad.sqf
Copy link
Contributor

Choose a reason for hiding this comment

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

IMO this should be a framework

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree, but frankly I don't want to invest the time and effort into making a framework. I saw the CBA one, but that seems to be stale.

Copy link
Member

Choose a reason for hiding this comment

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

It was mostly done at the time iirc, just needs someone to wrap it up and make any changes that need to be accounted for

Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#include "..\script_component.hpp"
/*
* Author: johnb43
* Executed every time an inventory display is opened.
*
* Arguments:
* 0: Inventory display <DISPLAY>
*
* Return Value:
* None
*
* Example:
* [DISPLAY] call ace_dogtags_fnc_inventoryDisplayLoad
*
* Public: No
*/

disableSerialization;

params ["_display"];

// Monitor changes that can happen and force our update
private _dummyControl = _display ctrlCreate ["RscMapControl", -1];

_dummyControl ctrlSetPosition [0, 0, 0, 0];
_dummyControl ctrlCommit 0;

_dummyControl ctrlAddEventHandler ["Draw", {
private _display = ctrlParent (_this select 0);
PabstMirror marked this conversation as resolved.
Show resolved Hide resolved

{
private _itemList = _display displayCtrl _x;

// If control isn't shown, skip
if (!ctrlShown _itemList) then {
continue;
};

for "_i" from (lbSize _itemList) to 0 step -1 do {
private _item = _itemList lbData _i;

if (_item find "ACE_dogtag_" == 0) then {
_dogtagData = GVAR(dogtagsData) getOrDefault [_item, []];
johnb432 marked this conversation as resolved.
Show resolved Hide resolved

// If data doesn't exist, put name as "unknown"
_itemList lbSetText [_i, [LLSTRING(itemName), ": ", _dogtagData param [0, LELSTRING(common,unknown)]] joinString ""];
};
};
} forEach [IDC_ITEMLIST_GROUND, IDC_ITEMLIST_SOLDIER, IDC_ITEMLIST_UNIFORM, IDC_ITEMLIST_VEST, IDC_ITEMLIST_BACKPACK];
}];
PabstMirror marked this conversation as resolved.
Show resolved Hide resolved
33 changes: 0 additions & 33 deletions addons/dogtags/functions/fnc_sendDogtagData.sqf

This file was deleted.

6 changes: 6 additions & 0 deletions addons/dogtags/script_component.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,9 @@
"a3\sounds_f\characters\ingame\AinvPpneMstpSlayWpstDnon_medic.wss",\
"a3\sounds_f\characters\ingame\AinvPpneMstpSlayWrflDnon_medic.wss"\
]

#define IDC_ITEMLIST_GROUND 632
#define IDC_ITEMLIST_SOLDIER 640
#define IDC_ITEMLIST_UNIFORM 633
#define IDC_ITEMLIST_VEST 638
#define IDC_ITEMLIST_BACKPACK 619
Loading