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

Add Zeus and 3DEN comments #785

Draft
wants to merge 14 commits into
base: master
Choose a base branch
from
1 change: 1 addition & 0 deletions AUTHORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ PlayerBot
Ryan180602
shukari
SilentSpike
Timi007
Toinane
Tuupertunut
veteran29
Expand Down
1 change: 1 addition & 0 deletions addons/comments/$PBOPREFIX$
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
x\zen\addons\comments
40 changes: 40 additions & 0 deletions addons/comments/Cfg3DEN.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
class Cfg3DEN {
class Attributes {
class Default;
class GVAR(hiddenAttribute): Default {
onLoad = QUOTE((ctrlParentControlsGroup ctrlParentControlsGroup (_this select 0)) ctrlShow false);
};
};

class Mission {
class Scenario {
class AttributeCategories {
class ADDON {
displayName = STR_DISPLAY_NAME;
collapsed = 1;

class Attributes {
class GVAR(3DENComments) {
displayName = STR_DISPLAY_NAME;
property = QGVAR(3DENComments);
control = QGVAR(hiddenAttribute);
tooltip = "";
defaultValue = "[]";
expression = "";
wikiType = "[[Array]]";
};
};
};
};
};
};

class EventHandlers {
class ADDON {
// Arguments are for debugging
onMissionSave = QUOTE(['onMissionSave'] call FUNC(save3DENComments));
onMissionAutosave = QUOTE(['onMissionAutosave'] call FUNC(save3DENComments));
onBeforeMissionPreview = QUOTE(['onBeforeMissionPreview'] call FUNC(save3DENComments));
};
};
};
9 changes: 9 additions & 0 deletions addons/comments/CfgContext.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class EGVAR(context_menu,actions) {
class GVAR(createComment) {
displayName = STR_CREATE_COMMENT;
icon = COMMENT_ICON;
condition = QGVAR(enabled);
statement = QUOTE([_position] call FUNC(openDialog));
priority = 35;
};
};
17 changes: 17 additions & 0 deletions addons/comments/CfgEventHandlers.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
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));
};
};
18 changes: 18 additions & 0 deletions addons/comments/XEH_PREP.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
PREP(addDrawEventHandler);
PREP(createComment);
PREP(createIcon);
PREP(deleteComment);
PREP(deleteIcon);
PREP(drawComments);
PREP(is3DENComment);
PREP(onCommentCreated);
PREP(onCommentDeleted);
PREP(onCommentUpdated);
PREP(onDraw);
PREP(onDraw3D);
PREP(onKeyDown);
PREP(onMouseDblClick);
PREP(openDialog);
PREP(save3DENComments);
PREP(updateComment);
PREP(updateIcon);
18 changes: 18 additions & 0 deletions addons/comments/XEH_postInit.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include "script_component.hpp"

if (isServer) then {
[QGVAR(createComment), LINKFUNC(createComment)] call CBA_fnc_addEventHandler;
[QGVAR(deleteComment), LINKFUNC(deleteComment)] call CBA_fnc_addEventHandler;
[QGVAR(updateComment), LINKFUNC(updateComment)] call CBA_fnc_addEventHandler;
};

if (hasInterface) then {
GVAR(comments) = createHashMapFromArray getMissionConfigValue [QGVAR(3DENComments), []];
TRACE_1("Loaded 3DEN Comments from mission",GVAR(comments));

[QGVAR(commentCreated), LINKFUNC(onCommentCreated)] call CBA_fnc_addEventHandler;
[QGVAR(commentDeleted), LINKFUNC(onCommentDeleted)] call CBA_fnc_addEventHandler;
[QGVAR(commentUpdated), LINKFUNC(onCommentUpdated)] call CBA_fnc_addEventHandler;

["zen_curatorDisplayLoaded", LINKFUNC(addDrawEventHandler)] call CBA_fnc_addEventHandler;
};
25 changes: 25 additions & 0 deletions addons/comments/XEH_preInit.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include "script_component.hpp"

ADDON = false;

PREP_RECOMPILE_START;
#include "XEH_PREP.hpp"
PREP_RECOMPILE_END;

if (isServer) then {
// Unique ID for creating comments
GVAR(nextID) = 0;
};

if (hasInterface) then {
// Map of all comments
// Keys are comment IDs and values are the data
GVAR(comments) = createHashMap;
GVAR(icons) = createHashMap;

GVAR(draw3DAdded) = false;
};

#include "initSettings.inc.sqf"

ADDON = true;
3 changes: 3 additions & 0 deletions addons/comments/XEH_preStart.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#include "script_component.hpp"

#include "XEH_PREP.hpp"
24 changes: 24 additions & 0 deletions addons/comments/config.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include "script_component.hpp"

class CfgPatches {
class ADDON {
name = COMPONENT_NAME;
units[] = {
QGVAR(module)
};
weapons[] = {};
requiredVersion = REQUIRED_VERSION;
requiredAddons[] = {"zen_modules", "zen_dialog"};
author = ECSTRING(main,Author);
authors[] = {"Timi007"};
url = ECSTRING(main,URL);
VERSION_CONFIG;
};
};

PRELOAD_ADDONS;

#include "CfgEventHandlers.hpp"
#include "Cfg3DEN.hpp"
#include "CfgContext.hpp"
#include "gui.hpp"
37 changes: 37 additions & 0 deletions addons/comments/functions/fnc_addDrawEventHandler.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include "script_component.hpp"
/*
* Author: Timi007
* Function triggered every time the Zeus/Curator display is opened.
* Adds the draw event handlers to display 3DEN comments in 3D and on the map.
*
* Arguments:
* 0: Zeus Display <DISPLAY>
*
* Return Value:
* None
*
* Example:
* [_display] call zen_comments_fnc_addDrawEventHandler
*
* Public: No
*/

params ["_display"];
TRACE_1("Zeus display opened",_display);

if (!GVAR(enabled) && !GVAR(enabled3DEN)) exitWith {};

[{
{_x call FUNC(createIcon)} forEach GVAR(comments);
}] call CBA_fnc_execNextFrame; // Run next frame so display is loaded in FUNC(createIcon)

if (!GVAR(draw3DAdded)) then {
LOG("Adding Draw3D.");
addMissionEventHandler ["Draw3D", FUNC(onDraw3D)];
GVAR(draw3DAdded) = true;
};

// MapDraw EH needs to be added every time the Zeus display is opened.
LOG("Adding map draw.");
private _ctrlMap = _display displayCtrl IDC_RSCDISPLAYCURATOR_MAINMAP;
_ctrlMap ctrlAddEventHandler ["Draw", FUNC(onDraw)];
42 changes: 42 additions & 0 deletions addons/comments/functions/fnc_createComment.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include "script_component.hpp"
/*
* Author: Timi007
* Creates a new comment in Zeus.
*
* Arguments:
* 0: Position ASL <ARRAY>
* 1: Title <STRING>
* 2: Tooltip <STRING> (default: "")
* 3: Comment color (RGBA) <ARRAY> (default: yellow)
* 4: Creator <STRING> (default: "")
*
* Return Value:
* Id of the created comment <STRING>.
*
* Example:
* [[0, 0, 0], "My Comment", "This is a nice comment", [1, 0, 0, 0.7], "Joe"] call zen_comments_fnc_createComment
*
* Public: No
*/

if (!isServer) exitWith {
[QGVAR(createComment), _this] call CBA_fnc_serverEvent;
};

params [
["_position", [0, 0, 0], [[]], 3],
["_title", "", [""]],
["_tooltip", "", [""]],
["_color", DEFAULT_COLOR, [[]], 4],
["_creator", "", [""]]
];

private _id = format ["%1:%2", COMMENT_TYPE_ZEUS, GVAR(nextID)];
private _data = [_position, _title, _tooltip, _color, _creator];
GVAR(nextID) = GVAR(nextID) + 1;

private _jipId = format [QGVAR(%1), _id];
[QGVAR(commentCreated), [_id, _data], _jipId] call CBA_fnc_globalEventJIP;
TRACE_2("Comment created",_id,_data);

_id
34 changes: 34 additions & 0 deletions addons/comments/functions/fnc_createIcon.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include "script_component.hpp"
/*
* Author: Timi007
* Creates an icon control for the comment.
*
* Arguments:
* 0: Unique comment id <STRING>
*
* Return Value:
* Icon control for the comment <CONTROL>.
*
* Example:
* ["zeus:0"] call zen_comments_fnc_createIcon
*
* Public: No
*/

params ["_id"];

private _display = findDisplay IDD_RSCDISPLAYCURATOR;
if (isNull _display || !(_id in GVAR(comments))) exitWith {};

(GVAR(comments) get _id) params ["", "", ["_tooltip", ""]];

private _ctrlIcon = _display ctrlCreate [QGVAR(RscActiveCommentIcon), -1];
_ctrlIcon setVariable [QGVAR(comment), _id];
_ctrlIcon ctrlSetTooltip _tooltip;

_ctrlIcon ctrlAddEventHandler ["KeyDown", FUNC(onKeyDown)];
_ctrlIcon ctrlAddEventHandler ["MouseButtonDblClick", FUNC(onMouseDblClick)];

GVAR(icons) set [_id, _ctrlIcon];

_ctrlIcon
34 changes: 34 additions & 0 deletions addons/comments/functions/fnc_deleteComment.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include "script_component.hpp"
/*
* Author: Timi007
* Deletes the comment. Must be called on server.
*
* Arguments:
* 0: Comment id <STRING>
*
* Return Value:
* None
*
* Example:
* ["zeus:2"] call zen_comments_fnc_deleteComment
*
* Public: No
*/

if (!isServer) exitWith {
[QGVAR(deleteComment), _this] call CBA_fnc_serverEvent;
};

params ["_id"];

// Remove the JIP ID for updated comments
private _jipIdUpdates = format [QGVAR(update_%1), _id];
[_jipIdUpdates] call CBA_fnc_removeGlobalEventJIP;

// JIP event IDs are globally unique. For 3DEN comments, there won't be a created
// event but for Zeus ones the created JIP event will be overwritten with this
// deleted event that shares the same JIP ID, meaning that we don't have to remove
// the created JIP event.
private _jipId = format [QGVAR(%1), _id];
[QGVAR(commentDeleted), [_id]] call CBA_fnc_globalEventJIP;
TRACE_1("Comment deleted",_id);
22 changes: 22 additions & 0 deletions addons/comments/functions/fnc_deleteIcon.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include "script_component.hpp"
/*
* Author: Timi007
* Deletes the icon control of comment.
*
* Arguments:
* 0: Comment id <STRING>
*
* Return Value:
* None
*
* Example:
* ["zeus:2"] call zen_comments_fnc_deleteIcon
*
* Public: No
*/

params ["_id"];

if (_id in GVAR(icons)) then {
ctrlDelete (GVAR(icons) deleteAt _id);
};
Loading