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
41 changes: 41 additions & 0 deletions addons/comments/Cfg3DEN.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
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 {
collapsed = 1;
displayName = ECSTRING(main,DisplayName);

class Attributes {
class GVAR(3DENComments) {
property = QGVAR(3DENComments);
value = 0;
control = QGVAR(HiddenAttribute);
displayName = CSTRING(DisplayName);
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));
};
};
};
8 changes: 8 additions & 0 deletions addons/comments/CfgContext.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class EGVAR(context_menu,actions) {
class GVAR(createComment) {
displayName = STR_CREATE_COMMENT;
icon = COMMENT_ICON;
statement = QUOTE([_position] call FUNC(createCommentDialog));
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));
};
};
10 changes: 10 additions & 0 deletions addons/comments/CfgVehicles.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class CfgVehicles {
class EGVAR(modules,moduleBase);
class GVAR(module): EGVAR(modules,moduleBase) {
curatorCanAttach = 1;
category = "Curator";
displayName = STR_CREATE_COMMENT;
function = QFUNC(module);
icon = COMMENT_ICON;
};
};
15 changes: 15 additions & 0 deletions addons/comments/XEH_PREP.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
PREP(addDrawEventHandler);
PREP(createComment);
PREP(createCommentDialog);
PREP(createCommentLocal);
PREP(createIcon);
PREP(deleteComment);
PREP(deleteCommentLocal);
PREP(deleteIcon);
PREP(drawComments);
PREP(is3DENComment);
PREP(module);
PREP(onDraw);
PREP(onDraw3D);
PREP(save3DENComments);
PREP(showIcons);
19 changes: 19 additions & 0 deletions addons/comments/XEH_postInit.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include "script_component.hpp"

if (is3DEN) exitWith {};

if (isServer) then {
GVAR(nextId) = 0;
[QGVAR(createComment), LINKFUNC(createComment)] call CBA_fnc_addEventHandler;
[QGVAR(deleteComment), LINKFUNC(deleteComment)] call CBA_fnc_addEventHandler;
};

if (hasInterface) then {
[QGVAR(createCommentLocal), LINKFUNC(createCommentLocal)] call CBA_fnc_addEventHandler;
[QGVAR(deleteCommentLocal), LINKFUNC(deleteCommentLocal)] call CBA_fnc_addEventHandler;

["zen_curatorDisplayLoaded", LINKFUNC(addDrawEventHandler)] call CBA_fnc_addEventHandler;

GVAR(3DENComments) = getMissionConfigValue [QGVAR(3DENComments), []];
TRACE_1("Loaded 3DEN Comments from mission",GVAR(3DENComments));
};
15 changes: 15 additions & 0 deletions addons/comments/XEH_preInit.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include "script_component.hpp"

ADDON = false;

PREP_RECOMPILE_START;
#include "XEH_PREP.hpp"
PREP_RECOMPILE_END;

GVAR(icons) = createHashMap;
GVAR(draw3DAdded) = false;
GVAR(comments) = [];

#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"
25 changes: 25 additions & 0 deletions addons/comments/config.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#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 "CfgVehicles.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(enableComments) && !GVAR(enable3DENComments)) exitWith {};

{
[_display, _x] call FUNC(createIcon);
} forEach (GVAR(3DENComments) + GVAR(comments));

if (!GVAR(draw3DAdded)) then {
LOG("Adding Draw3D.");
addMissionEventHandler ["Draw3D", {call 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", {call FUNC(onDraw)}];
31 changes: 31 additions & 0 deletions addons/comments/functions/fnc_createComment.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include "script_component.hpp"
/*
* Author: Timi007
* Creates a comment in Zeus. Must be called on server.
*
* Arguments:
* 0: Comment position ASL <ARRAY>
* 1: Comment title <STRING>
* 2: Comment tooltip <STRING>
* 3: Name of the curator that created the comment <STRING>
*
* Return Value:
* None.
*
* Example:
* [[0,0,0], "My Comment", "This is a nice comment", "Joe"] call zen_comments_fnc_createComment
*
* Public: No
*/

params ["_posASL", "_title", ["_tooltip", "", [""]], ["_creator", "", [""]]];

if (!isServer) exitWith {};

GVAR(nextID) = GVAR(nextID) + 1;

private _id = format ["zeus:%1", GVAR(nextID)];
private _jipId = format [QGVAR(%1), _id];

TRACE_6("Create comment",_id,_posASL,_title,_tooltip,_creator,_jipId);
[QGVAR(createCommentLocal), [_id, _posASL, _title, _tooltip, _creator], _jipId] call CBA_fnc_globalEventJIP;
34 changes: 34 additions & 0 deletions addons/comments/functions/fnc_createCommentDialog.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include "script_component.hpp"
/*
* Author: Timi007
* Opens the dialog for creating a comment.
*
* Arguments:
* 0: Comment position ASL <ARRAY>
*
* Return Value:
* None
*
* Example:
* [[0,0,0]] call zen_comments_fnc_createCommentDialog
*
* Public: No
*/

params ["_posASL"];

[
localize STR_CREATE_COMMENT,
[
["EDIT", localize "str_3den_comment_attribute_name_displayname", [""], true],
["EDIT:MULTI", localize "str_3den_comment_attribute_name_tooltip", [""], true]
],
{
params ["_values", "_posASL"];
_values params ["_title", "_tooltip"];

[QGVAR(createComment), [_posASL, _title, _tooltip, profileName]] call CBA_fnc_serverEvent;
},
{},
_posASL
] call EFUNC(dialog,create);
29 changes: 29 additions & 0 deletions addons/comments/functions/fnc_createCommentLocal.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include "script_component.hpp"
/*
* Author: Timi007
* Creates a comment in Zeus locally.
*
* Arguments:
* 0: Unique comment id <STRING>
* 1: Comment position ASL <ARRAY>
* 2: Comment title <STRING>
* 3: Comment tooltip <STRING>
* 4: Name of the curator that created the comment <STRING>
*
* Return Value:
* None.
*
* Example:
* ["zeus:1", [0,0,0], "My Comment", "This is a nice comment", "Joe"] call zen_comments_fnc_createCommentLocal
*
* Public: No
*/

if (!hasInterface) exitWith {};

private _display = findDisplay IDD_RSCDISPLAYCURATOR;
if (!isNull _display) then {
[_display, _this] call FUNC(createIcon);
};

GVAR(comments) pushBack _this;
39 changes: 39 additions & 0 deletions addons/comments/functions/fnc_createIcon.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include "script_component.hpp"
/*
* Author: Timi007
* Creates an icon control for the comment.
*
* Arguments:
* 0: Zeus display <DISPLAY>
* 1: Comment <ARRAY>
*
* Return Value:
* None.
*
* Example:
* [_display, _comment] call zen_comments_fnc_createIcon
*
* Public: No
*/

params ["_display", "_comment"];
_comment params ["_id", "", "", "_tooltip"];

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

_ctrlIcon ctrlAddEventHandler ["KeyDown", {
params ["_ctrlIcon", "_key"];

if (_key isNotEqualTo DIK_DELETE) exitWith {};

private _id = _ctrlIcon getVariable [QGVAR(comment), ""];
if (_id isEqualTo "") exitWith {};

if (!GVAR(allowDeleting3DENComments) && {_id call FUNC(is3DENComment)}) exitWith {};

[QGVAR(deleteComment), [_id]] call CBA_fnc_serverEvent;
}];

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

params ["_id"];

if !(_id call FUNC(is3DENComment)) then {
private _jipId = format [QGVAR(%1), _id];
[_jipId] call CBA_fnc_removeGlobalEventJIP;
};

TRACE_1("Delete comment",_id);
[QGVAR(deleteCommentLocal), [_id]] call CBA_fnc_globalEvent;
Loading
Loading