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

WIP: Port diagnostics component from legacy mod #204

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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/diagnostics/$PBOPREFIX$
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
z\afm\addons\diagnostics
15 changes: 15 additions & 0 deletions addons/diagnostics/CfgEventHandlers.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class Extended_PreStart_EventHandlers {
class ADDON {
init = QUOTE(call COMPILE_FILE(XEH_preStart));
};
};
class Extended_PreInit_EventHandlers {
class ADDON {
init = QUOTE(call COMPILE_FILE(XEH_preInit));
};
};
class Extended_PostInit_EventHandlers {
class ADDON {
init = QUOTE(call COMPILE_FILE(XEH_postInit));
};
};
8 changes: 8 additions & 0 deletions addons/diagnostics/XEH_PREP.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
PREP(dlcOpen);
PREP(dlcRequest);
PREP(dlcRespond);
PREP(dlcUpdate);
PREP(fpsOpen);
PREP(fpsRequest);
PREP(fpsRespond);
PREP(fpsUpdate);
1 change: 1 addition & 0 deletions addons/diagnostics/XEH_postInit.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "script_component.hpp"
64 changes: 64 additions & 0 deletions addons/diagnostics/XEH_preInit.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#include "script_component.hpp"
ADDON = false;
#include "XEH_PREP.hpp"
ADDON = true;

#include "initSettings.sqf"

GVAR(dlcList) = [
[288520, "Karts"],
[304380, "Helicopters"],
[332350, "Marksman"],
[395180, "Apex"],
[571710, "Laws of War"],
[601670, "Jets"],
[744950, "Tac Ops"],
[798390, "Tanks"],
[1021790, "Contact"],
[1042220, "GM"],
// TODO: IDs for remaining DLCs
[]
];

if (hasInterface) then {
["DLC List", QGVAR(dlcListDialog)] call CBA_fnc_addPauseMenuOption;
["FPS List", QGVAR(fpsListDialog)] call CBA_fnc_addPauseMenuOption;

[QGVAR(dlcRequest), FUNC(dlcRespond)] call CBA_fnc_addEventHandler;
[QGVAR(dlcResponse), FUNC(dlcUpdate)] call CBA_fnc_addEventHandler;

[QGVAR(fpsRequest), FUNC(fpsRespond)] call CBA_fnc_addEventHandler;
[QGVAR(fpsResponse), FUNC(fpsUpdate)] call CBA_fnc_addEventHandler;
};

if (!isServer) exitWith {};

if (!QGVAR(markersEnabled)) exitWith {};

// By default only server is an FPS diag target
GVAR(fpsTargets) = [2];

// Add headless clients to diag targets when they join
addMissionEventHandler ["PlayerConnected", {
params ["", "_uid", "", "", "_owner"];
if ((_uid select [0,2] != "HC")) exitWith {};

GVAR(fpsTargets) pushBack _owner;
}];

// Cleanup headless client markers on disconnect
addMissionEventHandler ["PlayerDisconnected", {
params ["", "_uid", "", "", "_owner"];
if ((_uid select [0,2] != "HC")) exitWith {};

GVAR(fpsTargets) = GVAR(fpsTargets) - [_owner];

private _fpsMarker = format ["%1_%2", QGVAR(fpsMarker), _owner];
deleteMarker _fpsMarker;
}];

[{
{
[_x, _forEachIndex] remoteExec [QFUNC(updateDiagnosticMarker), _x];
} forEach GVAR(fpsTargets);
}, 15] call CBA_fnc_addPerFrameHandler;
2 changes: 2 additions & 0 deletions addons/diagnostics/XEH_preStart.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#include "script_component.hpp"
#include "XEH_PREP.hpp"
30 changes: 30 additions & 0 deletions addons/diagnostics/config.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include "script_component.hpp"

class CfgPatches {
class ADDON {
name = COMPONENT_NAME;
units[] = {};
weapons[] = {};
requiredVersion = REQUIRED_VERSION;
requiredAddons[] = {
"afm_common"
};
author = "ArmaForces";
VERSION_CONFIG;
};
};

#include "CfgEventHandlers.hpp"

// TODO: Move this somewhere appropriate
class GVAR(fpsListDialog) {
idd = -1;
movingEnable = 0;
onLoad = QUOTE(_this call FUNC(fpsOpen));
};

class GVAR(dlcListDialog) {
idd = -1;
movingEnable = 0;
onLoad = QUOTE(_this call FUNC(dlcOpen));
};
92 changes: 92 additions & 0 deletions addons/diagnostics/functions/fn_dlc_open.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*
armaforces_diagnostics_fnc_dlc_open

File: fn_dlc_open.sqf
Date: 2019-06-21
Last Update: 2019-07-29
License: GNU General Public License v3.0 - https://www.gnu.org/licenses/gpl-3.0.html

Description:
Handle DLC List display open.

Parameter(s):
_display - DLC List display [DISPLAY, defaults to displayNull]

Returns:
NOTHING
*/
params [
["_display", displayNull, [displayNull]]
];

if !([] call BIS_fnc_isDebugConsoleAllowed) exitWith {
["No debug console access"] call CBA_fnc_notify;
};

private _width = safezoneW * 0.75;

// Confirm
private _confirm = _display ctrlCreate ["RscButtonMenu", 10];
uiNamespace setVariable [QGVAR(dlcConfirm), _confirm];

private _confirmHeight = safezoneH / 23;
private _confirmY = safezoneY + safezoneH/1.3 - 1.1 * _confirmHeight;

_confirm ctrlSetPosition [
0.5 - _width/2 + _width*0.2,
_confirmY,
_width*0.8, _confirmHeight
];
_confirm ctrlCommit 0;
_confirm ctrlSetText toUpper "REFRESH";

_confirm ctrlAddEventHandler ["MouseButtonDown", {
params ["_confirm", "_button"];
if (_button != 0) exitWith {};
_confirm ctrlEnable false;
[{_this ctrlEnable true}, _confirm, 2] call CBA_fnc_waitAndExecute;

[] call FUNC(dlcRequest);
}];

private _close = _display ctrlCreate ["RscButtonMenu", 1];
_close ctrlSetPosition [
0.5 - _width/2,
_confirmY,
_width*0.2, _confirmHeight
];
_close ctrlCommit 0;
_close ctrlSetText "CLOSE";

// List
private _listHeight = safezoneH/2;

private _listBg = _display ctrlCreate ["RscText", 2]; // centered RscListNBox
_listBg ctrlSetBackgroundColor [0,0,0,0.8];

private _list = _display ctrlCreate ["RscListNBox", 3]; // centered RscListNBox
uiNamespace setVariable [QGVAR(dlcListDialog), _list];

_list lnbAddRow (["Player"] + (GVAR(dlcList) apply {""}));

private _listColOffsets = [];
{
_x params ["", "_name"];

_listColOffsets pushBack 0.12 + ((1 - 0.12) / count GVAR(dlcList)) * _forEachIndex;
} forEach GVAR(dlcList);

_list lnbSetColumnsPos ([0] + _listColOffsets);

{
_x ctrlSetPosition [
0.5 - _width / 2,
_confirmY - _listHeight - _confirmHeight/10 ,
_width, _listHeight
];
_x ctrlCommit 0;
} forEach [_listBg, _list];

[] call FUNC(dlcRequest);

nil
28 changes: 28 additions & 0 deletions addons/diagnostics/functions/fn_dlc_request.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
armaforces_diagnostics_fnc_dlc_request

File: fn_dlc_request.sqf
Date: 2019-06-21
Last Update: 2019-07-29
License: GNU General Public License v3.0 - https://www.gnu.org/licenses/gpl-3.0.html

Description:
Request DLC ownership from clients.

Parameter(s):
NONE

Returns:
NOTHING
*/
private _list = uiNamespace getVariable [QGVAR(dlcListDialog), controlNull];

lnbClear _list;
_list lnbAddRow (["Player"] + (GVAR(dlcList) apply {"-"}));
_list lnbSetCurSelRow 1;

[{
[QGVAR(dlcRequest), player] call CBA_fnc_globalEvent;
}] call CBA_fnc_execNextFrame;

nil
37 changes: 37 additions & 0 deletions addons/diagnostics/functions/fn_dlc_respond.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
armaforces_diagnostics_fnc_dlc_respond

File: fn_dlc_respond.sqf
Date: 2019-07-28
Last Update: 2019-07-29
License: GNU General Public License v3.0 - https://www.gnu.org/licenses/gpl-3.0.html

Description:
Respond to DLC ownership request.

Parameter(s):
_requester - Player that requested DLC list [OBJECT, defaults to objNull]

Returns:
NOTHING
*/
params [
["_requester", objNull, [objNull]]
];

private _ownedIds = getDLCs 1;

private _DLCs = GVAR(dlcList);

private _DLCsData = _DLCs apply {
_x params ["_id", "_name"];

[_name, _id in _ownedIds];
};

[QGVAR(dlcResponse),
[name player, _DLCsData],
_requester
] call CBA_fnc_targetEvent;

nil
33 changes: 33 additions & 0 deletions addons/diagnostics/functions/fn_dlc_update.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
armaforces_diagnostics_fnc_dlc_update

File: fn_dlc_update.sqf
Date: 2019-06-21
Last Update: 2019-07-29
License: GNU General Public License v3.0 - https://www.gnu.org/licenses/gpl-3.0.html

Description:
Update DLC List display contents.

Parameter(s):
NONE

Returns:
NOTHING
*/
params [
["_playerName", "", [""]],
["_DLCsData", [], []]
];

private _list = uiNamespace getVariable [QGVAR(dlcListDialog), controlNull];

private _lastRow = _list lnbAddRow ([_playerName] + (_DLCsData apply {_x select 0}));

private ["_color"];
{
_color = [[1,0,0,1], [0,1,0,1]] select _x;
_list lnbSetColor [[_lastRow, _forEachIndex+1], _color];
} forEach (_DLCsData apply {_x select 1})


Loading