Skip to content

Commit

Permalink
Add Debug Console component (#695)
Browse files Browse the repository at this point in the history
Co-authored-by: jonpas <[email protected]>
  • Loading branch information
Mike-MF and jonpas authored Jun 16, 2024
1 parent 75a7659 commit 8ff4c36
Show file tree
Hide file tree
Showing 16 changed files with 4,967 additions and 0 deletions.
1 change: 1 addition & 0 deletions addons/debug_console/$PBOPREFIX$
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
x\tac\addons\debug_console
24 changes: 24 additions & 0 deletions addons/debug_console/CfgEventHandlers.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class Extended_PreStart_EventHandlers {
class ADDON {
init = QUOTE(call COMPILE_SCRIPT(XEH_preStart));
};
};
class Extended_PreInit_EventHandlers {
class ADDON {
init = QUOTE(call COMPILE_SCRIPT(XEH_preInit));
};
};
class Extended_PostInit_EventHandlers {
class ADDON {
init = QUOTE(call COMPILE_SCRIPT(XEH_postInit));
};
};

class Extended_DisplayLoad_EventHandlers {
class RscDisplayInterrupt {
GVAR(init) = QUOTE(call (uiNamespace getVariable 'FUNC(initDebugConsole)'));
};
class RscDisplayMPInterrupt {
GVAR(init) = QUOTE(call (uiNamespace getVariable 'FUNC(initDebugConsole)'));
};
};
7 changes: 7 additions & 0 deletions addons/debug_console/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
## Debug_console

Enchancements for debug console. Adds a framework to add custom functionalities to the console.

### Authors

- [veteran29](http://github.com/veteran29)
4 changes: 4 additions & 0 deletions addons/debug_console/XEH_PREP.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
PREP(addButton);
PREP(addCurator);
PREP(handleDisconnect);
PREP(initDebugConsole);
32 changes: 32 additions & 0 deletions addons/debug_console/XEH_postInit.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include "script_component.hpp"

if (isServer) then {
addMissionEventHandler ["HandleDisconnect", FUNC(handleDisconnect)];
[QGVAR(createCurator), FUNC(addCurator)] call CBA_fnc_addEventHandler;
[QGVAR(stopRain), {
params ["_caller"];
INFO_1("Rain was stopped by '%1'",_caller);
0 setRain 0;
0 setOvercast 0;
forceWeatherChange;
}] call CBA_fnc_addEventHandler;
};

[QGVAR(massHeal), {
params ["_caller"];
if (isServer) exitWith {
INFO_1("Mass Heal was executed by '%1'",_caller);
};
[ace_player] call ACEFUNC(medical_treatment,fullHealLocal);
}] call CBA_fnc_addEventHandler;

// Limited to 6 buttons.
[["Curator", "Assigns as Curator"], {
[QGVAR(createCurator), ace_player] call CBA_fnc_serverEvent;
}] call FUNC(addButton);
[["Mass Heal", "Heals all Players"], {
[QGVAR(massHeal), ace_player] call CBA_fnc_globalEvent;
}] call FUNC(addButton);
[["Stop Rain", "Stops Rain"], {
[QGVAR(stopRain), ace_player] call CBA_fnc_serverEvent;
}] call FUNC(addButton);
11 changes: 11 additions & 0 deletions addons/debug_console/XEH_preInit.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include "script_component.hpp"
ADDON = false;

PREP_RECOMPILE_START;
#include "XEH_PREP.hpp"
PREP_RECOMPILE_END;

GVAR(buttons) = [];
GVAR(playerCurators) = [];

ADDON = true;
2 changes: 2 additions & 0 deletions addons/debug_console/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"
14 changes: 14 additions & 0 deletions addons/debug_console/config.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include "script_component.hpp"
class CfgPatches {
class ADDON {
name = COMPONENT_NAME;
units[] = {};
weapons[] = {};
requiredVersion = REQUIRED_VERSION;
requiredAddons[] = {"cba_diagnostic"};
author = "ArmaForces";
VERSION_CONFIG;
};
};

#include "CfgEventHandlers.hpp"
30 changes: 30 additions & 0 deletions addons/debug_console/functions/fnc_addButton.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include "..\script_component.hpp"
/*
* Author: veteran29
* Adds custom button to debug console
*
* Arguments:
* 0: Name <STRING, ARRAY>
* 0: Name <STRING>
* 1: Tooltip <STRING
* 1: Code to execute on button click <CODE>
*
* Return Value:
* None
*
* Example:
* [["Test", "This is a button"], {hint "Button was clicked"}] call FUNC(addButton)
*
* Public: Yes
*/

params [["_name", "", ["", []]], ["_code", "", [{}]]];
_name params [["_displayName", "", [""]], ["_tooltip", "", [""]]];

if (count GVAR(buttons) == 6) exitWith {
ERROR("Maximum amount of buttons reached.");
};

GVAR(buttons) pushBack [_displayName, _tooltip, _code];

nil
46 changes: 46 additions & 0 deletions addons/debug_console/functions/fnc_addCurator.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include "..\script_component.hpp"
/*
* Author: Mike
* Creates curator module for the local player.
*
* Arguments:
* 0: Player <OBJECT>
*
* Return Value:
* None
*
* Public: No
*/

params ["_player"];

private _playerName = name _player;

// Early exit if Module already assigned.
if (!isNull getAssignedCuratorLogic _player) exitWith {
INFO_1("Player '%1' already assigned as curator.",_playerName);
};

INFO_1("Player '%1' assigned as Curator",_playerName);

private _curatorGroup = createGroup sideLogic;
private _curatorModule = _curatorGroup createUnit ["ModuleCurator_F", _player, [], 0, "NONE"];
private _configFile = (configFile >> "CfgPatches");
private _allAddons = [];

GVAR(playerCurators) pushBack [_curatorModule, getPlayerUID _player];

for "_i" from 0 to (count _configFile - 1) do {
private _cfgName = configName (_configFile select _i);
_allAddons pushBack _cfgName;
};

_curatorModule addCuratorAddons _allAddons;
_curatorModule setVariable ["showNotification", false];
_curatorModule addCuratorEditableObjects [allUnits, true]; // all Players and AI.

{
_curatorModule setCuratorCoef [_x, 0];
} forEach ["Place", "Edit", "Delete", "Destroy", "Group", "Synchronize"];

_player assignCurator _curatorModule;
25 changes: 25 additions & 0 deletions addons/debug_console/functions/fnc_handleDisconnect.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include "..\script_component.hpp"
/*
* Author: Mike
* Handles deletion of curator modules on disconnect.
*
* Arguments:
* 0: Unit <OBJECT> (Unused)
* 1: ID <NUMBER> (Unused)
* 2: UID <STRING>
* 3: Name <STRING> (Unused)
*
* Return Value:
* None
*
* Public: No
*/

params ["_unit", "_id", "_uid", "_name"];

if (GVAR(playerCurators) isEqualTo []) exitWith {};

private _moduleData = GVAR(playerCurators) select {_uid in _x} select 0;
deleteVehicle (_moduleData select 0);

GVAR(playerCurators) deleteAt (GVAR(playerCurators) find _moduleData);
47 changes: 47 additions & 0 deletions addons/debug_console/functions/fnc_initDebugConsole.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#include "..\script_component.hpp"
/*
* Author: veteran29
* Initialize debug console display
*
* Arguments:
* 0: Debug console display <DISPLAY>
*
* Return Value:
* None
*
* Public: No
*/

#define ITEMS_PER_ROW 2
#define BUTTON_WIDTH 7.5

params ["_display"];
TRACE_1("initializing debug console",_display);

private _debugConsole = _display displayCtrl IDC_RSCDEBUGCONSOLE_RSCDEBUGCONSOLE;

private _basePositionRow1 = ctrlPosition (_display displayCtrl IDC_RSCDEBUGCONSOLE_BUTTONANIMATIONS);
private _basePositionRow2 = ctrlPosition (_display displayCtrl IDC_RSCDEBUGCONSOLE_BUTTONGUI);

// Create buttons in bottom row
{
_x params ["_text", "_tooltip", "_code"];
TRACE_3("adding debug console button",_text,_tooltip,_code);

private _col = floor (_forEachIndex / ITEMS_PER_ROW);
private _basePos = +([_basePositionRow1, _basePositionRow2] select (_forEachIndex % 2));

_basePos set [0, (_basePos select 0) + (BUTTON_WIDTH * (1 + _col)) * GUI_GRID_W]; // adjust X

private _button = _display ctrlCreate ["RscButtonMenu", -1, _debugConsole];

_button ctrlSetPosition _basePos;
_button ctrlCommit 0;

_button ctrlSetText _text;
_button ctrlSetTooltip _tooltip;
_button ctrlAddEventHandler ["ButtonClick", _code];

} forEach GVAR(buttons);

nil
21 changes: 21 additions & 0 deletions addons/debug_console/script_component.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#define COMPONENT debug_console
#define COMPONENT_BEAUTIFIED Debug Console
#include "\x\tac\addons\main\script_mod.hpp"

#include "\a3\ui_f\hpp\defineCommonGrids.inc"
#include "\a3\ui_f\hpp\defineResincl.inc"
#include "\a3\ui_f\hpp\defineResinclDesign.inc"

// #define DEBUG_MODE_FULL
// #define DISABLE_COMPILE_CACHE
// #define ENABLE_PERFORMANCE_COUNTERS

#ifdef DEBUG_ENABLED_DEBUG_CONSOLE
#define DEBUG_MODE_FULL
#endif

#ifdef DEBUG_SETTINGS_DEBUG_CONSOLE
#define DEBUG_SETTINGS DEBUG_SETTINGS_DEBUG_CONSOLE
#endif

#include "\x\tac\addons\main\script_macros.hpp"
Loading

0 comments on commit 8ff4c36

Please sign in to comment.