From d05a5f38c49c45e59aff91e4371436aac0662759 Mon Sep 17 00:00:00 2001 From: Timi007 Date: Thu, 26 Dec 2024 23:47:24 +0100 Subject: [PATCH 01/23] Show 3DEN comments in Zeus --- AUTHORS.txt | 1 + addons/comments/$PBOPREFIX$ | 1 + addons/comments/Cfg3DEN.hpp | 32 +++++ addons/comments/CfgEventHandlers.hpp | 17 +++ addons/comments/XEH_PREP.hpp | 2 + addons/comments/XEH_postInit.sqf | 9 ++ addons/comments/XEH_preInit.sqf | 18 +++ addons/comments/XEH_preStart.sqf | 3 + addons/comments/config.cpp | 20 ++++ .../functions/fnc_addDrawEventHandler.sqf | 109 ++++++++++++++++++ .../functions/fnc_save3DENComments.sqf | 44 +++++++ .../comments/functions/script_component.hpp | 1 + addons/comments/initSettings.inc.sqf | 17 +++ addons/comments/script_component.hpp | 22 ++++ addons/comments/stringtable.xml | 27 +++++ 15 files changed, 323 insertions(+) create mode 100644 addons/comments/$PBOPREFIX$ create mode 100644 addons/comments/Cfg3DEN.hpp create mode 100644 addons/comments/CfgEventHandlers.hpp create mode 100644 addons/comments/XEH_PREP.hpp create mode 100644 addons/comments/XEH_postInit.sqf create mode 100644 addons/comments/XEH_preInit.sqf create mode 100644 addons/comments/XEH_preStart.sqf create mode 100644 addons/comments/config.cpp create mode 100644 addons/comments/functions/fnc_addDrawEventHandler.sqf create mode 100644 addons/comments/functions/fnc_save3DENComments.sqf create mode 100644 addons/comments/functions/script_component.hpp create mode 100644 addons/comments/initSettings.inc.sqf create mode 100644 addons/comments/script_component.hpp create mode 100644 addons/comments/stringtable.xml diff --git a/AUTHORS.txt b/AUTHORS.txt index eff7e29bc..a51e668ea 100644 --- a/AUTHORS.txt +++ b/AUTHORS.txt @@ -50,6 +50,7 @@ PlayerBot Ryan180602 shukari SilentSpike +Timi007 Toinane Tuupertunut veteran29 diff --git a/addons/comments/$PBOPREFIX$ b/addons/comments/$PBOPREFIX$ new file mode 100644 index 000000000..89d5574df --- /dev/null +++ b/addons/comments/$PBOPREFIX$ @@ -0,0 +1 @@ +x\zen\addons\comments diff --git a/addons/comments/Cfg3DEN.hpp b/addons/comments/Cfg3DEN.hpp new file mode 100644 index 000000000..36d6ae128 --- /dev/null +++ b/addons/comments/Cfg3DEN.hpp @@ -0,0 +1,32 @@ +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 PREFIX { + 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]]"; + }; + }; + }; + }; + }; + }; +}; diff --git a/addons/comments/CfgEventHandlers.hpp b/addons/comments/CfgEventHandlers.hpp new file mode 100644 index 000000000..f6503c247 --- /dev/null +++ b/addons/comments/CfgEventHandlers.hpp @@ -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)); + }; +}; diff --git a/addons/comments/XEH_PREP.hpp b/addons/comments/XEH_PREP.hpp new file mode 100644 index 000000000..693693c0c --- /dev/null +++ b/addons/comments/XEH_PREP.hpp @@ -0,0 +1,2 @@ +PREP(addDrawEventHandler); +PREP(save3DENComments); diff --git a/addons/comments/XEH_postInit.sqf b/addons/comments/XEH_postInit.sqf new file mode 100644 index 000000000..082f53a43 --- /dev/null +++ b/addons/comments/XEH_postInit.sqf @@ -0,0 +1,9 @@ +#include "script_component.hpp" + +if (!hasInterface) exitWith {}; + +GVAR(draw3DAdded) = false; +["zen_curatorDisplayLoaded", LINKFUNC(addDrawEventHandler)] call CBA_fnc_addEventHandler; + +GVAR(3DENComments) = getMissionConfigValue [QGVAR(3DENComments), []]; +TRACE_1("Loaded 3DEN Comments from mission",GVAR(3DENComments)); diff --git a/addons/comments/XEH_preInit.sqf b/addons/comments/XEH_preInit.sqf new file mode 100644 index 000000000..e88ad4b2a --- /dev/null +++ b/addons/comments/XEH_preInit.sqf @@ -0,0 +1,18 @@ +#include "script_component.hpp" + +ADDON = false; + +PREP_RECOMPILE_START; +#include "XEH_PREP.hpp" +PREP_RECOMPILE_END; + +#include "initSettings.inc.sqf" + +// For 3DEN comments in Zeus +if (is3DEN) then { + // Arguments are for debugging + add3DENEventHandler ["OnMissionSave", {["OnMissionSave"] call FUNC(save3DENComments)}]; + add3DENEventHandler ["OnMissionAutosave", {["OnMissionAutosave"] call FUNC(save3DENComments)}]; +}; + +ADDON = true; diff --git a/addons/comments/XEH_preStart.sqf b/addons/comments/XEH_preStart.sqf new file mode 100644 index 000000000..022888575 --- /dev/null +++ b/addons/comments/XEH_preStart.sqf @@ -0,0 +1,3 @@ +#include "script_component.hpp" + +#include "XEH_PREP.hpp" diff --git a/addons/comments/config.cpp b/addons/comments/config.cpp new file mode 100644 index 000000000..612b5f855 --- /dev/null +++ b/addons/comments/config.cpp @@ -0,0 +1,20 @@ +#include "script_component.hpp" + +class CfgPatches { + class ADDON { + name = COMPONENT_NAME; + units[] = {}; + weapons[] = {}; + requiredVersion = REQUIRED_VERSION; + requiredAddons[] = {"zen_common"}; + author = ECSTRING(main,Author); + authors[] = {"Timi007"}; + url = ECSTRING(main,URL); + VERSION_CONFIG; + }; +}; + +PRELOAD_ADDONS; + +#include "CfgEventHandlers.hpp" +#include "Cfg3DEN.hpp" diff --git a/addons/comments/functions/fnc_addDrawEventHandler.sqf b/addons/comments/functions/fnc_addDrawEventHandler.sqf new file mode 100644 index 000000000..ce6de8401 --- /dev/null +++ b/addons/comments/functions/fnc_addDrawEventHandler.sqf @@ -0,0 +1,109 @@ +#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 + * + * Return Value: + * None + * + * Example: + * [_display] call zen_comments_fnc_addDrawEventHandler + * + * Public: No + */ + +params ["_display"]; +TRACE_1("Zeus display opened",_display); + +if (!GVAR(enable3DENComments)) exitWith {}; + +if (!GVAR(draw3DAdded)) then { + LOG("Adding 3DENComments Draw3D."); + addMissionEventHandler ["Draw3D", { + if (!GVAR(enable3DENComments)) exitWith { + removeMissionEventHandler [_thisEvent, _thisEventHandler]; + GVAR(draw3DAdded) = false; + LOG("Removed 3DENComments Draw3D."); + }; + + // Not in Zeus, in pause menu or HUD is hidden + if ( + isNull (findDisplay IDD_RSCDISPLAYCURATOR) || + {!isNull (findDisplay IDD_INTERRUPT)} || + {call EFUNC(common,isInScreenshotMode)} + ) exitWith {}; + + private _camPosASL = getPosASLVisual curatorCamera; + private _color = GVAR(3DENCommentsColor); // Copy global var for slightly better performance + + { + _x params ["_id", "_name", "_description", "_posASL"]; + + private _d = _posASL distance _camPosASL; + private _scale = linearConversion [300, 750, _d, 0.8, 0, true]; // 300m => 0.8, 750m => 0 + private _posAGL = ASLToAGL _posASL; + + // Don't draw icon if it's too small or outside screen + if (_scale < 0.01 || {(curatorCamera worldToScreen _posAGL) isEqualTo []}) then { + continue; + }; + + drawIcon3D [ + "a3\3den\Data\Cfg3DEN\Comment\texture_ca.paa", + _color, + _posAGL, + _scale, // Width + _scale, // Height + 0, // Angle + _name, // Text + 1, // Shadow + -1, // Text Size + "RobotoCondensed" // Font + ]; + + // Draw ground-icon connection line only for icons higher than 0.5 m + if ((_posAGL select 2) > 0.5) then { + drawLine3D [_posAGL, [_posAGL select 0, _posAGL select 1, 0], _color]; + }; + } count GVAR(3DENComments); // Use count for slightly better performance + }]; +}; + +// MapDraw EH needs to be added every time the Zeus display is opened. +LOG("Adding 3DENComments map draw."); +(_display displayCtrl IDC_RSCDISPLAYCURATOR_MAINMAP) ctrlAddEventHandler ["Draw", { + params ["_mapCtrl"]; + + if (!GVAR(enable3DENComments)) exitWith { + _mapCtrl ctrlRemoveEventHandler [_thisEvent, _thisEventHandler]; + LOG("Removed 3DENComments map draw."); + }; + + // Draw is only called when map is open + if (call EFUNC(common,isInScreenshotMode)) exitWith {}; // HUD is hidden + + private _color = GVAR(3DENCommentsColor); // Copy global var for slightly better performance + + { + _x params ["_id", "_name", "_description", "_posASL"]; + + _mapCtrl drawIcon [ + "a3\3den\Data\Cfg3DEN\Comment\texture_ca.paa", + _color, + _posASL, + 24, // Width + 24, // Height + 0, // Angle + _name, // Text + 1, // Shadow + -1, // Text Size + "RobotoCondensed" // Font + ]; + } count GVAR(3DENComments); // Use count for slightly better performance +}]; + +GVAR(draw3DAdded) = true; diff --git a/addons/comments/functions/fnc_save3DENComments.sqf b/addons/comments/functions/fnc_save3DENComments.sqf new file mode 100644 index 000000000..0a4fd1fad --- /dev/null +++ b/addons/comments/functions/fnc_save3DENComments.sqf @@ -0,0 +1,44 @@ +#include "script_component.hpp" +/* + * Author: Timi007 + * Function called when 3DEN save event is triggered. + * Handles saving comments into scenario space for later use. + * + * Arguments: + * 0: Event that triggered this function (for debug purposes) + * + * Return Value: + * None + * + * Example: + * call zen_comments_fnc_save3DENComments + * + * Public: No + */ + +params [["_event", "", [""]]]; + +if (!is3DEN) exitWith {}; + +private _comments = []; +{ + private _id = _x; + // all3DENEntities includes always includes this id, ignore + if (_id isEqualTo -999) then { + continue; + }; + + private _name = (_id get3DENAttribute "name") select 0; + private _description = (_id get3DENAttribute "description") select 0; + private _positionASL = (_id get3DENAttribute "position") select 0; + + // Ignore comments with special ignore directive in the description/tooltip + if (IGNORE_3DEN_COMMENT_STRING in _description) then { + continue; + }; + + _comments pushBack [_id, _name, _description, _positionASL]; +} forEach (all3DENEntities param [7, []]); + +set3DENMissionAttributes [["Scenario", QGVAR(3DENComments), _comments]]; +TRACE_2("Saved 3DEN comments",_event,_comments); diff --git a/addons/comments/functions/script_component.hpp b/addons/comments/functions/script_component.hpp new file mode 100644 index 000000000..b85e1ce6d --- /dev/null +++ b/addons/comments/functions/script_component.hpp @@ -0,0 +1 @@ +#include "\x\zen\addons\comments\script_component.hpp" diff --git a/addons/comments/initSettings.inc.sqf b/addons/comments/initSettings.inc.sqf new file mode 100644 index 000000000..e24912050 --- /dev/null +++ b/addons/comments/initSettings.inc.sqf @@ -0,0 +1,17 @@ +[ + QGVAR(enable3DENComments), + "CHECKBOX", + [LLSTRING(3DENComments), LLSTRING(3DENComments_Description)], + [ELSTRING(main,DisplayName), LSTRING(DisplayName)], + true, + 0 +] call CBA_fnc_addSetting; + +[ + QGVAR(3DENCommentsColor), + "COLOR", + [LLSTRING(3DENCommentsColor), LLSTRING(3DENCommentsColor_Description)], + [ELSTRING(main,DisplayName), LSTRING(DisplayName)], + [0, 1, 0.75, 1], + 0 +] call CBA_fnc_addSetting; diff --git a/addons/comments/script_component.hpp b/addons/comments/script_component.hpp new file mode 100644 index 000000000..26c9e17da --- /dev/null +++ b/addons/comments/script_component.hpp @@ -0,0 +1,22 @@ +#define COMPONENT comments +#define COMPONENT_BEAUTIFIED Comments +#include "\x\zen\addons\main\script_mod.hpp" + +// #define DEBUG_MODE_FULL +// #define DISABLE_COMPILE_CACHE +// #define ENABLE_PERFORMANCE_COUNTERS + +#ifdef DEBUG_ENABLED_COMMENTS + #define DEBUG_MODE_FULL +#endif + +#ifdef DEBUG_SETTINGS_COMMENTS + #define DEBUG_SETTINGS DEBUG_SETTINGS_COMMENTS +#endif + +#include "\x\zen\addons\main\script_macros.hpp" + +#include "\x\zen\addons\common\defineResinclDesign.inc" + +// Ignore comments that include following string in the description/tooltip +#define IGNORE_3DEN_COMMENT_STRING "#ZEN_IGNORE#" diff --git a/addons/comments/stringtable.xml b/addons/comments/stringtable.xml new file mode 100644 index 000000000..2c6b0b93a --- /dev/null +++ b/addons/comments/stringtable.xml @@ -0,0 +1,27 @@ + + + + + Comments + Kommentare + + + + + Show 3DEN comments in Zeus + Zeige 3DEN-Kommentare im Zeus + + + Show 3DEN comments in Zeus. + Zeige 3DEN-Kommentare im Zeus an. + + + 3DEN comments color + Farbe der 3DEN-Kommentare + + + Color of 3DEN Kommentare in Zeus. + Farbe der 3DEN-Kommentare im Zeus. + + + From 28e4f2fa2b8684c542c04a6f535f2e84e198dfbd Mon Sep 17 00:00:00 2001 From: Timi007 Date: Thu, 26 Dec 2024 23:58:13 +0100 Subject: [PATCH 02/23] Make icons smaller and hide line behind icon --- addons/comments/functions/fnc_addDrawEventHandler.sqf | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/addons/comments/functions/fnc_addDrawEventHandler.sqf b/addons/comments/functions/fnc_addDrawEventHandler.sqf index ce6de8401..f036e3e38 100644 --- a/addons/comments/functions/fnc_addDrawEventHandler.sqf +++ b/addons/comments/functions/fnc_addDrawEventHandler.sqf @@ -44,7 +44,7 @@ if (!GVAR(draw3DAdded)) then { _x params ["_id", "_name", "_description", "_posASL"]; private _d = _posASL distance _camPosASL; - private _scale = linearConversion [300, 750, _d, 0.8, 0, true]; // 300m => 0.8, 750m => 0 + private _scale = linearConversion [300, 750, _d, 0.65, 0, true]; // 300m => 0.65, 750m => 0 private _posAGL = ASLToAGL _posASL; // Don't draw icon if it's too small or outside screen @@ -67,7 +67,8 @@ if (!GVAR(draw3DAdded)) then { // Draw ground-icon connection line only for icons higher than 0.5 m if ((_posAGL select 2) > 0.5) then { - drawLine3D [_posAGL, [_posAGL select 0, _posAGL select 1, 0], _color]; + // Hide line behind icon + drawLine3D [_posAGL vectorAdd [0, 0, -0.05], [_posAGL select 0, _posAGL select 1, 0], _color]; }; } count GVAR(3DENComments); // Use count for slightly better performance }]; From 0935239c9ad7b00af3faca241f97c26b4afbec44 Mon Sep 17 00:00:00 2001 From: Timi007 Date: Fri, 27 Dec 2024 00:20:32 +0100 Subject: [PATCH 03/23] Spelling --- addons/comments/functions/fnc_save3DENComments.sqf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/comments/functions/fnc_save3DENComments.sqf b/addons/comments/functions/fnc_save3DENComments.sqf index 0a4fd1fad..9e752848f 100644 --- a/addons/comments/functions/fnc_save3DENComments.sqf +++ b/addons/comments/functions/fnc_save3DENComments.sqf @@ -23,7 +23,7 @@ if (!is3DEN) exitWith {}; private _comments = []; { private _id = _x; - // all3DENEntities includes always includes this id, ignore + // all3DENEntities always includes this id, ignore it if (_id isEqualTo -999) then { continue; }; From d2b1a840150832da5bf90ed245aa502abbab1a22 Mon Sep 17 00:00:00 2001 From: Timi007 Date: Sun, 29 Dec 2024 18:53:27 +0100 Subject: [PATCH 04/23] Add tooltip to comments --- addons/comments/XEH_PREP.hpp | 2 + addons/comments/XEH_postInit.sqf | 3 +- addons/comments/XEH_preInit.sqf | 2 + addons/comments/config.cpp | 9 ++ .../functions/fnc_addDrawEventHandler.sqf | 91 +++++---------- .../comments/functions/fnc_canDraw3DIcons.sqf | 20 ++++ .../comments/functions/fnc_drawComments.sqf | 110 ++++++++++++++++++ addons/comments/initSettings.inc.sqf | 19 ++- addons/comments/script_component.hpp | 19 +++ 9 files changed, 210 insertions(+), 65 deletions(-) create mode 100644 addons/comments/functions/fnc_canDraw3DIcons.sqf create mode 100644 addons/comments/functions/fnc_drawComments.sqf diff --git a/addons/comments/XEH_PREP.hpp b/addons/comments/XEH_PREP.hpp index 693693c0c..2590ddf3b 100644 --- a/addons/comments/XEH_PREP.hpp +++ b/addons/comments/XEH_PREP.hpp @@ -1,2 +1,4 @@ PREP(addDrawEventHandler); +PREP(canDraw3DIcons); +PREP(drawComments); PREP(save3DENComments); diff --git a/addons/comments/XEH_postInit.sqf b/addons/comments/XEH_postInit.sqf index 082f53a43..125068684 100644 --- a/addons/comments/XEH_postInit.sqf +++ b/addons/comments/XEH_postInit.sqf @@ -1,8 +1,7 @@ #include "script_component.hpp" -if (!hasInterface) exitWith {}; +if (!hasInterface || is3DEN) exitWith {}; -GVAR(draw3DAdded) = false; ["zen_curatorDisplayLoaded", LINKFUNC(addDrawEventHandler)] call CBA_fnc_addEventHandler; GVAR(3DENComments) = getMissionConfigValue [QGVAR(3DENComments), []]; diff --git a/addons/comments/XEH_preInit.sqf b/addons/comments/XEH_preInit.sqf index e88ad4b2a..bce0d11cd 100644 --- a/addons/comments/XEH_preInit.sqf +++ b/addons/comments/XEH_preInit.sqf @@ -6,6 +6,8 @@ PREP_RECOMPILE_START; #include "XEH_PREP.hpp" PREP_RECOMPILE_END; +GVAR(draw3DAdded) = false; + #include "initSettings.inc.sqf" // For 3DEN comments in Zeus diff --git a/addons/comments/config.cpp b/addons/comments/config.cpp index 612b5f855..6dd40a773 100644 --- a/addons/comments/config.cpp +++ b/addons/comments/config.cpp @@ -18,3 +18,12 @@ PRELOAD_ADDONS; #include "CfgEventHandlers.hpp" #include "Cfg3DEN.hpp" + +class RscActivePicture; +class GVAR(RscActiveCommentIcon): RscActivePicture { + onMouseEnter = QUOTE((_this select 0) setVariable [ARR_2(QQGVAR(isActive),true)]); + onMouseExit = QUOTE((_this select 0) setVariable [ARR_2(QQGVAR(isActive),false)]); + shadow = 1; + text = COMMENT_ICON; + tooltipMaxWidth = QUOTE(POS_W(15)); +}; diff --git a/addons/comments/functions/fnc_addDrawEventHandler.sqf b/addons/comments/functions/fnc_addDrawEventHandler.sqf index f036e3e38..964cb3045 100644 --- a/addons/comments/functions/fnc_addDrawEventHandler.sqf +++ b/addons/comments/functions/fnc_addDrawEventHandler.sqf @@ -21,57 +21,41 @@ TRACE_1("Zeus display opened",_display); if (!GVAR(enable3DENComments)) exitWith {}; +GVAR(controls) = []; +{ + _x params ["_id", "_name", "_description", "_posASL"]; + + private _control = _display ctrlCreate [QGVAR(RscActiveCommentIcon), -1]; + _control ctrlSetTooltip _description; + + GVAR(controls) pushBack _control; +} forEach GVAR(3DENComments); + if (!GVAR(draw3DAdded)) then { LOG("Adding 3DENComments Draw3D."); addMissionEventHandler ["Draw3D", { if (!GVAR(enable3DENComments)) exitWith { removeMissionEventHandler [_thisEvent, _thisEventHandler]; + + {ctrlDelete _x} forEach GVAR(controls); + GVAR(draw3DAdded) = false; LOG("Removed 3DENComments Draw3D."); }; - // Not in Zeus, in pause menu or HUD is hidden - if ( - isNull (findDisplay IDD_RSCDISPLAYCURATOR) || - {!isNull (findDisplay IDD_INTERRUPT)} || - {call EFUNC(common,isInScreenshotMode)} - ) exitWith {}; - - private _camPosASL = getPosASLVisual curatorCamera; - private _color = GVAR(3DENCommentsColor); // Copy global var for slightly better performance - - { - _x params ["_id", "_name", "_description", "_posASL"]; - - private _d = _posASL distance _camPosASL; - private _scale = linearConversion [300, 750, _d, 0.65, 0, true]; // 300m => 0.65, 750m => 0 - private _posAGL = ASLToAGL _posASL; - - // Don't draw icon if it's too small or outside screen - if (_scale < 0.01 || {(curatorCamera worldToScreen _posAGL) isEqualTo []}) then { - continue; - }; - - drawIcon3D [ - "a3\3den\Data\Cfg3DEN\Comment\texture_ca.paa", - _color, - _posAGL, - _scale, // Width - _scale, // Height - 0, // Angle - _name, // Text - 1, // Shadow - -1, // Text Size - "RobotoCondensed" // Font - ]; + if (!(call FUNC(canDraw3DIcons))) exitWith { + {_x ctrlShow false} forEach GVAR(controls); + }; - // Draw ground-icon connection line only for icons higher than 0.5 m - if ((_posAGL select 2) > 0.5) then { - // Hide line behind icon - drawLine3D [_posAGL vectorAdd [0, 0, -0.05], [_posAGL select 0, _posAGL select 1, 0], _color]; - }; - } count GVAR(3DENComments); // Use count for slightly better performance + [ + GVAR(3DENComments), + GVAR(controls), + GVAR(3DENCommentsColor), + GVAR(3DENCommentsActiveColor) + ] call FUNC(drawComments); }]; + + GVAR(draw3DAdded) = true; }; // MapDraw EH needs to be added every time the Zeus display is opened. @@ -87,24 +71,11 @@ LOG("Adding 3DENComments map draw."); // Draw is only called when map is open if (call EFUNC(common,isInScreenshotMode)) exitWith {}; // HUD is hidden - private _color = GVAR(3DENCommentsColor); // Copy global var for slightly better performance - - { - _x params ["_id", "_name", "_description", "_posASL"]; - - _mapCtrl drawIcon [ - "a3\3den\Data\Cfg3DEN\Comment\texture_ca.paa", - _color, - _posASL, - 24, // Width - 24, // Height - 0, // Angle - _name, // Text - 1, // Shadow - -1, // Text Size - "RobotoCondensed" // Font - ]; - } count GVAR(3DENComments); // Use count for slightly better performance + [ + GVAR(3DENComments), + GVAR(controls), + GVAR(3DENCommentsColor), + GVAR(3DENCommentsActiveColor), + _mapCtrl + ] call FUNC(drawComments); }]; - -GVAR(draw3DAdded) = true; diff --git a/addons/comments/functions/fnc_canDraw3DIcons.sqf b/addons/comments/functions/fnc_canDraw3DIcons.sqf new file mode 100644 index 000000000..39cbdae68 --- /dev/null +++ b/addons/comments/functions/fnc_canDraw3DIcons.sqf @@ -0,0 +1,20 @@ +#include "script_component.hpp" +/* + * Author: Timi007 + * Checks if we can/should draw 3D icons in Zeus. + * + * Arguments: + * None + * + * Return Value: + * Can draw 3D icons. + * + * Example: + * call zen_comments_fnc_canDraw3DIcons + * + * Public: No + */ + +(!isNull (findDisplay IDD_RSCDISPLAYCURATOR)) && // We are in Zeus +{isNull (findDisplay IDD_INTERRUPT)} && // Pause menu is not opened +{!(call EFUNC(common,isInScreenshotMode))} // HUD is not hidden diff --git a/addons/comments/functions/fnc_drawComments.sqf b/addons/comments/functions/fnc_drawComments.sqf new file mode 100644 index 000000000..ae8b9b371 --- /dev/null +++ b/addons/comments/functions/fnc_drawComments.sqf @@ -0,0 +1,110 @@ +#include "script_component.hpp" +/* + * Author: Timi007 + * Draw comments on screen. Needs to be called every frame. + * + * Arguments: + * 0: Comments + * 1: Comment controls + * 2: Comment color (RGBA) + * 2: Comment color when mouse is hovered over it (RGBA) + * 2: Map control (Optional, default: Draw in 3D) + * + * Return Value: + * None + * + * Example: + * [_comments, _controls, [1, 0, 0, 0.7], [1, 0, 0, 1]] call zen_comments_fnc_drawComments + * + * Public: No + */ + +params ["_comments", "_controls", "_color", "_activeColor", ["_mapCtrl", controlNull, [controlNull]]]; + +private _drawIn3D = isNull _mapCtrl; + +private _d = 0; +private _scale = 0; +private _screenPos = []; + +{ + _x params ["_id", "_name", "_description", "_posASL"]; + + private _posAGL = ASLToAGL _posASL; + + if (_drawIn3D) then { + _d = _posASL distance (getPosASLVisual curatorCamera); + _scale = linearConversion [SCALE_DISTANCE_START, MAX_RENDER_DISTANCE, _d, ICON_SCALE, 0, true]; + + _screenPos = curatorCamera worldToScreen _posAGL; + } else { + _scale = MAP_ICON_SCALE; + + _screenPos = _mapCtrl ctrlMapWorldToScreen _posAGL; + }; + + private _control = _controls select _forEachIndex; + + // Don't draw icon if it's too small or outside screen + if (_scale < 0.01 || {_screenPos isEqualTo []}) then { + _control ctrlShow false; + continue; + }; + _control ctrlShow true; + + _control ctrlSetTextColor _color; + _control ctrlSetActiveColor _activeColor; + + _screenPos params ["_posX", "_posY"]; + private _posW = POS_W(_scale); + private _posH = POS_H(_scale); + + _control ctrlSetPosition [_posX - _posW / 2, _posY - _posH / 2, _posW, _posH]; + _control ctrlCommit 0; + + private _currentColor = [_color, _activeColor] select (_control getVariable [QGVAR(isActive), false]); + + if (_drawIn3D) then { + // Draw comment name and connection line in 3D + private _textOffsetScale = linearConversion [SCALE_DISTANCE_START, MAX_RENDER_DISTANCE, _d, 1, MIN_TEXT_OFFSET_SCALE, true]; + private _uiScale = getResolution select 5; + private _textOffsetY = TEXT_OFFSET_Y * _textOffsetScale * _uiScale; + + drawIcon3D [ + "", + _currentColor, + _posAGL, + _scale, // Width + _scale, // Height + 0, // Angle + _name, // Text + 1, // Shadow + -1, // Text Size + "RobotoCondensed", // Font + "center", // Align + false, // Arrows + 0, // Offset X + _textOffsetY // Offset Y + ]; + + // Draw ground-icon connection line only for icons higher than X m + if ((_posAGL select 2) > GROUND_ICON_CONNECTION_HEIGHT) then { + // Hide line behind icon + drawLine3D [_posAGL vectorAdd [0, 0, -0.05], [_posAGL select 0, _posAGL select 1, 0], _currentColor]; + }; + } else { + // Draw comment name on map + _mapCtrl drawIcon [ + "#(argb,8,8,3)color(0,0,0,0)", + _currentColor, + _posASL, + MAP_TEXT_SCALE, // Width + MAP_TEXT_SCALE, // Height + 0, // Angle + _name, // Text + 1, // Shadow + -1, // Text Size + "RobotoCondensed" // Font + ]; + }; +} forEach _comments; diff --git a/addons/comments/initSettings.inc.sqf b/addons/comments/initSettings.inc.sqf index e24912050..702f0ab77 100644 --- a/addons/comments/initSettings.inc.sqf +++ b/addons/comments/initSettings.inc.sqf @@ -4,7 +4,14 @@ [LLSTRING(3DENComments), LLSTRING(3DENComments_Description)], [ELSTRING(main,DisplayName), LSTRING(DisplayName)], true, - 0 + 0, + { + TRACE_1("Enable 3DEN comments setting changed",_this); + + private _display = findDisplay IDD_RSCDISPLAYCURATOR; + if (!_this || isNull _display || GVAR(draw3DAdded)) exitWith {}; + [_display] call FUNC(addDrawEventHandler); + } ] call CBA_fnc_addSetting; [ @@ -12,6 +19,12 @@ "COLOR", [LLSTRING(3DENCommentsColor), LLSTRING(3DENCommentsColor_Description)], [ELSTRING(main,DisplayName), LSTRING(DisplayName)], - [0, 1, 0.75, 1], - 0 + [0, 1, 0.75, 0.7], + 0, + { + TRACE_1("3DEN comment color setting changed",_this); + params ["_r", "_g", "_b", "_a"]; + + GVAR(3DENCommentsActiveColor) = [_r, _g, _b, 1]; + } ] call CBA_fnc_addSetting; diff --git a/addons/comments/script_component.hpp b/addons/comments/script_component.hpp index 26c9e17da..7e4d77821 100644 --- a/addons/comments/script_component.hpp +++ b/addons/comments/script_component.hpp @@ -16,7 +16,26 @@ #include "\x\zen\addons\main\script_macros.hpp" +#include "\a3\ui_f\hpp\defineCommonGrids.inc" #include "\x\zen\addons\common\defineResinclDesign.inc" +#define POS_X(N) ((N) * GUI_GRID_W + GUI_GRID_CENTER_X) +#define POS_Y(N) ((N) * GUI_GRID_H + GUI_GRID_CENTER_Y) +#define POS_W(N) ((N) * GUI_GRID_W) +#define POS_H(N) ((N) * GUI_GRID_H) + // Ignore comments that include following string in the description/tooltip #define IGNORE_3DEN_COMMENT_STRING "#ZEN_IGNORE#" + +#define COMMENT_ICON "a3\3den\Data\Cfg3DEN\Comment\texture_ca.paa" +#define ICON_SCALE 1 +#define MAP_ICON_SCALE 1.2 +#define MAP_TEXT_SCALE 24 + +#define TEXT_OFFSET_Y -0.076 +#define MIN_TEXT_OFFSET_SCALE 0.35 + +#define SCALE_DISTANCE_START 300 +#define MAX_RENDER_DISTANCE 750 + +#define GROUND_ICON_CONNECTION_HEIGHT 0.5 From be9ba0154a0db4fc8eba71c2e26c0fbf094b6c53 Mon Sep 17 00:00:00 2001 From: Timi007 Date: Sun, 29 Dec 2024 19:06:54 +0100 Subject: [PATCH 05/23] Fix 3DEN event handlers added again when returning from preview --- addons/comments/Cfg3DEN.hpp | 8 ++++++++ addons/comments/XEH_preInit.sqf | 7 ------- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/addons/comments/Cfg3DEN.hpp b/addons/comments/Cfg3DEN.hpp index 36d6ae128..8dc8eb289 100644 --- a/addons/comments/Cfg3DEN.hpp +++ b/addons/comments/Cfg3DEN.hpp @@ -29,4 +29,12 @@ class Cfg3DEN { }; }; }; + + class EventHandlers { + class PREFIX { + // Arguments are for debugging + onMissionSave = QUOTE(['OnMissionSave'] call FUNC(save3DENComments)); + onMissionAutoSave = QUOTE(['OnMissionAutosave'] call FUNC(save3DENComments)); + }; + }; }; diff --git a/addons/comments/XEH_preInit.sqf b/addons/comments/XEH_preInit.sqf index bce0d11cd..1db97c592 100644 --- a/addons/comments/XEH_preInit.sqf +++ b/addons/comments/XEH_preInit.sqf @@ -10,11 +10,4 @@ GVAR(draw3DAdded) = false; #include "initSettings.inc.sqf" -// For 3DEN comments in Zeus -if (is3DEN) then { - // Arguments are for debugging - add3DENEventHandler ["OnMissionSave", {["OnMissionSave"] call FUNC(save3DENComments)}]; - add3DENEventHandler ["OnMissionAutosave", {["OnMissionAutosave"] call FUNC(save3DENComments)}]; -}; - ADDON = true; From c6a094e9593fc2cb51be1c2c4a27edb7e3f2aef3 Mon Sep 17 00:00:00 2001 From: Timi007 Date: Sun, 29 Dec 2024 19:52:45 +0100 Subject: [PATCH 06/23] Save comment when starting preview --- addons/comments/Cfg3DEN.hpp | 9 +++++---- addons/comments/functions/fnc_save3DENComments.sqf | 1 + 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/addons/comments/Cfg3DEN.hpp b/addons/comments/Cfg3DEN.hpp index 8dc8eb289..86d3d0fa4 100644 --- a/addons/comments/Cfg3DEN.hpp +++ b/addons/comments/Cfg3DEN.hpp @@ -9,7 +9,7 @@ class Cfg3DEN { class Mission { class Scenario { class AttributeCategories { - class PREFIX { + class ADDON { collapsed = 1; displayName = ECSTRING(main,DisplayName); @@ -31,10 +31,11 @@ class Cfg3DEN { }; class EventHandlers { - class PREFIX { + class ADDON { // Arguments are for debugging - onMissionSave = QUOTE(['OnMissionSave'] call FUNC(save3DENComments)); - onMissionAutoSave = QUOTE(['OnMissionAutosave'] call FUNC(save3DENComments)); + onMissionSave = QUOTE(['onMissionSave'] call FUNC(save3DENComments)); + onMissionAutosave = QUOTE(['onMissionAutosave'] call FUNC(save3DENComments)); + onBeforeMissionPreview = QUOTE(['onBeforeMissionPreview'] call FUNC(save3DENComments)); }; }; }; diff --git a/addons/comments/functions/fnc_save3DENComments.sqf b/addons/comments/functions/fnc_save3DENComments.sqf index 9e752848f..8a08659bf 100644 --- a/addons/comments/functions/fnc_save3DENComments.sqf +++ b/addons/comments/functions/fnc_save3DENComments.sqf @@ -40,5 +40,6 @@ private _comments = []; _comments pushBack [_id, _name, _description, _positionASL]; } forEach (all3DENEntities param [7, []]); +// This command does not work if the mission is not saved set3DENMissionAttributes [["Scenario", QGVAR(3DENComments), _comments]]; TRACE_2("Saved 3DEN comments",_event,_comments); From 58482f14bde5c915bb76d3da91c72ad301405ae6 Mon Sep 17 00:00:00 2001 From: Timi007 Date: Sun, 29 Dec 2024 19:55:17 +0100 Subject: [PATCH 07/23] Move gui to file --- addons/comments/config.cpp | 10 +--------- addons/comments/gui.hpp | 8 ++++++++ 2 files changed, 9 insertions(+), 9 deletions(-) create mode 100644 addons/comments/gui.hpp diff --git a/addons/comments/config.cpp b/addons/comments/config.cpp index 6dd40a773..f96043290 100644 --- a/addons/comments/config.cpp +++ b/addons/comments/config.cpp @@ -18,12 +18,4 @@ PRELOAD_ADDONS; #include "CfgEventHandlers.hpp" #include "Cfg3DEN.hpp" - -class RscActivePicture; -class GVAR(RscActiveCommentIcon): RscActivePicture { - onMouseEnter = QUOTE((_this select 0) setVariable [ARR_2(QQGVAR(isActive),true)]); - onMouseExit = QUOTE((_this select 0) setVariable [ARR_2(QQGVAR(isActive),false)]); - shadow = 1; - text = COMMENT_ICON; - tooltipMaxWidth = QUOTE(POS_W(15)); -}; +#include "gui.hpp" diff --git a/addons/comments/gui.hpp b/addons/comments/gui.hpp new file mode 100644 index 000000000..8e4b27024 --- /dev/null +++ b/addons/comments/gui.hpp @@ -0,0 +1,8 @@ +class RscActivePicture; +class GVAR(RscActiveCommentIcon): RscActivePicture { + onMouseEnter = QUOTE((_this select 0) setVariable [ARR_2(QQGVAR(isActive),true)]); + onMouseExit = QUOTE((_this select 0) setVariable [ARR_2(QQGVAR(isActive),false)]); + shadow = 1; + text = COMMENT_ICON; + tooltipMaxWidth = QUOTE(POS_W(15)); +}; From 4e8bd2d0dec360966fd2f627e4c42d115368f3a6 Mon Sep 17 00:00:00 2001 From: Timi007 Date: Mon, 30 Dec 2024 01:05:49 +0100 Subject: [PATCH 08/23] Add zeus comments --- addons/comments/CfgContext.hpp | 8 +++ addons/comments/CfgVehicles.hpp | 10 ++++ addons/comments/XEH_PREP.hpp | 12 +++- addons/comments/XEH_postInit.sqf | 19 ++++-- addons/comments/XEH_preInit.sqf | 2 + addons/comments/config.cpp | 8 ++- .../functions/fnc_addDrawEventHandler.sqf | 60 +++---------------- .../comments/functions/fnc_canDraw3DIcons.sqf | 20 ------- .../comments/functions/fnc_createComment.sqf | 31 ++++++++++ .../functions/fnc_createCommentDialog.sqf | 34 +++++++++++ .../functions/fnc_createCommentLocal.sqf | 29 +++++++++ addons/comments/functions/fnc_createIcon.sqf | 26 ++++++++ .../comments/functions/fnc_deleteComment.sqf | 23 +++++++ .../functions/fnc_deleteCommentLocal.sqf | 27 +++++++++ addons/comments/functions/fnc_deleteIcon.sqf | 22 +++++++ .../comments/functions/fnc_drawComments.sqf | 49 ++++++++++----- addons/comments/functions/fnc_module.sqf | 22 +++++++ addons/comments/functions/fnc_onDraw.sqf | 42 +++++++++++++ addons/comments/functions/fnc_onDraw3D.sqf | 51 ++++++++++++++++ .../functions/fnc_save3DENComments.sqf | 10 ++-- addons/comments/functions/fnc_showIcons.sqf | 26 ++++++++ addons/comments/initSettings.inc.sqf | 41 +++++++++++-- addons/comments/script_component.hpp | 2 + addons/comments/stringtable.xml | 36 +++++++++-- 24 files changed, 503 insertions(+), 107 deletions(-) create mode 100644 addons/comments/CfgContext.hpp create mode 100644 addons/comments/CfgVehicles.hpp delete mode 100644 addons/comments/functions/fnc_canDraw3DIcons.sqf create mode 100644 addons/comments/functions/fnc_createComment.sqf create mode 100644 addons/comments/functions/fnc_createCommentDialog.sqf create mode 100644 addons/comments/functions/fnc_createCommentLocal.sqf create mode 100644 addons/comments/functions/fnc_createIcon.sqf create mode 100644 addons/comments/functions/fnc_deleteComment.sqf create mode 100644 addons/comments/functions/fnc_deleteCommentLocal.sqf create mode 100644 addons/comments/functions/fnc_deleteIcon.sqf create mode 100644 addons/comments/functions/fnc_module.sqf create mode 100644 addons/comments/functions/fnc_onDraw.sqf create mode 100644 addons/comments/functions/fnc_onDraw3D.sqf create mode 100644 addons/comments/functions/fnc_showIcons.sqf diff --git a/addons/comments/CfgContext.hpp b/addons/comments/CfgContext.hpp new file mode 100644 index 000000000..d94db1b6a --- /dev/null +++ b/addons/comments/CfgContext.hpp @@ -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; + }; +}; diff --git a/addons/comments/CfgVehicles.hpp b/addons/comments/CfgVehicles.hpp new file mode 100644 index 000000000..100d3f5c0 --- /dev/null +++ b/addons/comments/CfgVehicles.hpp @@ -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; + }; +}; diff --git a/addons/comments/XEH_PREP.hpp b/addons/comments/XEH_PREP.hpp index 2590ddf3b..a0135974a 100644 --- a/addons/comments/XEH_PREP.hpp +++ b/addons/comments/XEH_PREP.hpp @@ -1,4 +1,14 @@ PREP(addDrawEventHandler); -PREP(canDraw3DIcons); +PREP(createComment); +PREP(createCommentDialog); +PREP(createCommentLocal); +PREP(createIcon); +PREP(deleteComment); +PREP(deleteCommentLocal); +PREP(deleteIcon); PREP(drawComments); +PREP(module); +PREP(onDraw); +PREP(onDraw3D); PREP(save3DENComments); +PREP(showIcons); diff --git a/addons/comments/XEH_postInit.sqf b/addons/comments/XEH_postInit.sqf index 125068684..e3330a578 100644 --- a/addons/comments/XEH_postInit.sqf +++ b/addons/comments/XEH_postInit.sqf @@ -1,8 +1,19 @@ #include "script_component.hpp" -if (!hasInterface || is3DEN) exitWith {}; +if (is3DEN) exitWith {}; -["zen_curatorDisplayLoaded", LINKFUNC(addDrawEventHandler)] call CBA_fnc_addEventHandler; +if (isServer) then { + GVAR(nextId) = 0; + [QGVAR(createComment), LINKFUNC(createComment)] call CBA_fnc_addEventHandler; + [QGVAR(deleteComment), LINKFUNC(deleteComment)] call CBA_fnc_addEventHandler; +}; -GVAR(3DENComments) = getMissionConfigValue [QGVAR(3DENComments), []]; -TRACE_1("Loaded 3DEN Comments from mission",GVAR(3DENComments)); +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)); +}; diff --git a/addons/comments/XEH_preInit.sqf b/addons/comments/XEH_preInit.sqf index 1db97c592..d9ab12fdd 100644 --- a/addons/comments/XEH_preInit.sqf +++ b/addons/comments/XEH_preInit.sqf @@ -6,7 +6,9 @@ PREP_RECOMPILE_START; #include "XEH_PREP.hpp" PREP_RECOMPILE_END; +GVAR(icons) = createHashMap; GVAR(draw3DAdded) = false; +GVAR(comments) = []; #include "initSettings.inc.sqf" diff --git a/addons/comments/config.cpp b/addons/comments/config.cpp index f96043290..bcd1094ab 100644 --- a/addons/comments/config.cpp +++ b/addons/comments/config.cpp @@ -3,10 +3,12 @@ class CfgPatches { class ADDON { name = COMPONENT_NAME; - units[] = {}; + units[] = { + QGVAR(module) + }; weapons[] = {}; requiredVersion = REQUIRED_VERSION; - requiredAddons[] = {"zen_common"}; + requiredAddons[] = {"zen_modules", "zen_dialog"}; author = ECSTRING(main,Author); authors[] = {"Timi007"}; url = ECSTRING(main,URL); @@ -18,4 +20,6 @@ PRELOAD_ADDONS; #include "CfgEventHandlers.hpp" #include "Cfg3DEN.hpp" +#include "CfgVehicles.hpp" +#include "CfgContext.hpp" #include "gui.hpp" diff --git a/addons/comments/functions/fnc_addDrawEventHandler.sqf b/addons/comments/functions/fnc_addDrawEventHandler.sqf index 964cb3045..5a3f43eef 100644 --- a/addons/comments/functions/fnc_addDrawEventHandler.sqf +++ b/addons/comments/functions/fnc_addDrawEventHandler.sqf @@ -19,63 +19,19 @@ params ["_display"]; TRACE_1("Zeus display opened",_display); -if (!GVAR(enable3DENComments)) exitWith {}; +if (!GVAR(enableComments) && !GVAR(enable3DENComments)) exitWith {}; -GVAR(controls) = []; { - _x params ["_id", "_name", "_description", "_posASL"]; - - private _control = _display ctrlCreate [QGVAR(RscActiveCommentIcon), -1]; - _control ctrlSetTooltip _description; - - GVAR(controls) pushBack _control; -} forEach GVAR(3DENComments); + [_display, _x] call FUNC(createIcon); +} forEach (GVAR(3DENComments) + GVAR(comments)); if (!GVAR(draw3DAdded)) then { - LOG("Adding 3DENComments Draw3D."); - addMissionEventHandler ["Draw3D", { - if (!GVAR(enable3DENComments)) exitWith { - removeMissionEventHandler [_thisEvent, _thisEventHandler]; - - {ctrlDelete _x} forEach GVAR(controls); - - GVAR(draw3DAdded) = false; - LOG("Removed 3DENComments Draw3D."); - }; - - if (!(call FUNC(canDraw3DIcons))) exitWith { - {_x ctrlShow false} forEach GVAR(controls); - }; - - [ - GVAR(3DENComments), - GVAR(controls), - GVAR(3DENCommentsColor), - GVAR(3DENCommentsActiveColor) - ] call FUNC(drawComments); - }]; - + 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 3DENComments map draw."); -(_display displayCtrl IDC_RSCDISPLAYCURATOR_MAINMAP) ctrlAddEventHandler ["Draw", { - params ["_mapCtrl"]; - - if (!GVAR(enable3DENComments)) exitWith { - _mapCtrl ctrlRemoveEventHandler [_thisEvent, _thisEventHandler]; - LOG("Removed 3DENComments map draw."); - }; - - // Draw is only called when map is open - if (call EFUNC(common,isInScreenshotMode)) exitWith {}; // HUD is hidden - - [ - GVAR(3DENComments), - GVAR(controls), - GVAR(3DENCommentsColor), - GVAR(3DENCommentsActiveColor), - _mapCtrl - ] call FUNC(drawComments); -}]; +LOG("Adding map draw."); +private _ctrlMap = _display displayCtrl IDC_RSCDISPLAYCURATOR_MAINMAP; +_ctrlMap ctrlAddEventHandler ["Draw", {call FUNC(onDraw)}]; diff --git a/addons/comments/functions/fnc_canDraw3DIcons.sqf b/addons/comments/functions/fnc_canDraw3DIcons.sqf deleted file mode 100644 index 39cbdae68..000000000 --- a/addons/comments/functions/fnc_canDraw3DIcons.sqf +++ /dev/null @@ -1,20 +0,0 @@ -#include "script_component.hpp" -/* - * Author: Timi007 - * Checks if we can/should draw 3D icons in Zeus. - * - * Arguments: - * None - * - * Return Value: - * Can draw 3D icons. - * - * Example: - * call zen_comments_fnc_canDraw3DIcons - * - * Public: No - */ - -(!isNull (findDisplay IDD_RSCDISPLAYCURATOR)) && // We are in Zeus -{isNull (findDisplay IDD_INTERRUPT)} && // Pause menu is not opened -{!(call EFUNC(common,isInScreenshotMode))} // HUD is not hidden diff --git a/addons/comments/functions/fnc_createComment.sqf b/addons/comments/functions/fnc_createComment.sqf new file mode 100644 index 000000000..b503f1b27 --- /dev/null +++ b/addons/comments/functions/fnc_createComment.sqf @@ -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 + * 1: Comment title + * 2: Comment tooltip + * 3: Name of the curator that created the comment + * + * 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("",_id,_posASL,_title,_tooltip,_creator,_jipId); +[QGVAR(createCommentLocal), [_id, _posASL, _title, _tooltip, _creator], _jipId] call CBA_fnc_globalEventJIP; diff --git a/addons/comments/functions/fnc_createCommentDialog.sqf b/addons/comments/functions/fnc_createCommentDialog.sqf new file mode 100644 index 000000000..145ffd381 --- /dev/null +++ b/addons/comments/functions/fnc_createCommentDialog.sqf @@ -0,0 +1,34 @@ +#include "script_component.hpp" +/* + * Author: Timi007 + * Opens the dialog for creating a comment. + * + * Arguments: + * 0: Comment position ASL + * + * 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); diff --git a/addons/comments/functions/fnc_createCommentLocal.sqf b/addons/comments/functions/fnc_createCommentLocal.sqf new file mode 100644 index 000000000..30a874dc8 --- /dev/null +++ b/addons/comments/functions/fnc_createCommentLocal.sqf @@ -0,0 +1,29 @@ +#include "script_component.hpp" +/* + * Author: Timi007 + * Creates a comment in Zeus locally. + * + * Arguments: + * 0: Unique comment id + * 1: Comment position ASL + * 2: Comment title + * 3: Comment tooltip + * 4: Name of the curator that created the comment + * + * 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; diff --git a/addons/comments/functions/fnc_createIcon.sqf b/addons/comments/functions/fnc_createIcon.sqf new file mode 100644 index 000000000..bf453bdfe --- /dev/null +++ b/addons/comments/functions/fnc_createIcon.sqf @@ -0,0 +1,26 @@ +#include "script_component.hpp" +/* + * Author: Timi007 + * Creates an icon control for the comment. + * + * Arguments: + * 0: Zeus display + * 1: Comment + * + * 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; + +GVAR(icons) set [_id, _ctrlIcon]; diff --git a/addons/comments/functions/fnc_deleteComment.sqf b/addons/comments/functions/fnc_deleteComment.sqf new file mode 100644 index 000000000..87a12f1c7 --- /dev/null +++ b/addons/comments/functions/fnc_deleteComment.sqf @@ -0,0 +1,23 @@ +#include "script_component.hpp" +/* + * Author: Timi007 + * Deletes a comment created in Zeus. Must be called on server. + * + * Arguments: + * 0: Comment id + * + * Return Value: + * None + * + * Example: + * call zen_comments_fnc_deleteComment + * + * Public: No + */ + +params ["_id"]; + +private _jipId = format [QGVAR(%1), _id]; +[_jipId] call CBA_fnc_removeGlobalEventJIP; + +[QGVAR(removeComment), [_id]] call CBA_fnc_globalEvent; diff --git a/addons/comments/functions/fnc_deleteCommentLocal.sqf b/addons/comments/functions/fnc_deleteCommentLocal.sqf new file mode 100644 index 000000000..8fdb54549 --- /dev/null +++ b/addons/comments/functions/fnc_deleteCommentLocal.sqf @@ -0,0 +1,27 @@ +#include "script_component.hpp" +/* + * Author: Timi007 + * Deletes the comment locally. + * + * Arguments: + * 0: Comment id + * + * Return Value: + * None + * + * Example: + * [_id] call zen_comments_fnc_deleteCommentLocal + * + * Public: No + */ + +params ["_id"]; + +if (!hasInterface) exitWith {}; + +private _index = GVAR(comments) findIf {(_x select 0) isEqualTo _id}; +if (_index < 0) exitWith {}; + +GVAR(comments) deleteAt _index; + +[_id] call FUNC(deleteIcon); diff --git a/addons/comments/functions/fnc_deleteIcon.sqf b/addons/comments/functions/fnc_deleteIcon.sqf new file mode 100644 index 000000000..19dcdfab3 --- /dev/null +++ b/addons/comments/functions/fnc_deleteIcon.sqf @@ -0,0 +1,22 @@ +#include "script_component.hpp" +/* + * Author: Timi007 + * Deletes the icon control of comment. + * + * Arguments: + * 0: Comment id + * + * Return Value: + * None + * + * Example: + * [_id] call zen_comments_fnc_deleteIcon + * + * Public: No + */ + +params ["_id"]; + +if (_id in GVAR(icons)) then { + ctrlDelete (GVAR(icons) deleteAt _id); +}; diff --git a/addons/comments/functions/fnc_drawComments.sqf b/addons/comments/functions/fnc_drawComments.sqf index ae8b9b371..1584fc414 100644 --- a/addons/comments/functions/fnc_drawComments.sqf +++ b/addons/comments/functions/fnc_drawComments.sqf @@ -5,7 +5,7 @@ * * Arguments: * 0: Comments - * 1: Comment controls + * 1: Comment controls * 2: Comment color (RGBA) * 2: Comment color when mouse is hovered over it (RGBA) * 2: Map control (Optional, default: Draw in 3D) @@ -14,12 +14,12 @@ * None * * Example: - * [_comments, _controls, [1, 0, 0, 0.7], [1, 0, 0, 1]] call zen_comments_fnc_drawComments + * [_comments, _icons, [1, 0, 0, 0.7], [1, 0, 0, 1]] call zen_comments_fnc_drawComments * * Public: No */ -params ["_comments", "_controls", "_color", "_activeColor", ["_mapCtrl", controlNull, [controlNull]]]; +params ["_comments", "_icons", "_color", "_activeColor", ["_mapCtrl", controlNull, [controlNull]]]; private _drawIn3D = isNull _mapCtrl; @@ -28,7 +28,7 @@ private _scale = 0; private _screenPos = []; { - _x params ["_id", "_name", "_description", "_posASL"]; + _x params ["_id", "_posASL", "_title", "_tooltip", ["_creator", ""]]; private _posAGL = ASLToAGL _posASL; @@ -43,26 +43,26 @@ private _screenPos = []; _screenPos = _mapCtrl ctrlMapWorldToScreen _posAGL; }; - private _control = _controls select _forEachIndex; + private _ctrlIcon = _icons get _id; // Don't draw icon if it's too small or outside screen if (_scale < 0.01 || {_screenPos isEqualTo []}) then { - _control ctrlShow false; + _ctrlIcon ctrlShow false; continue; }; - _control ctrlShow true; + _ctrlIcon ctrlShow true; - _control ctrlSetTextColor _color; - _control ctrlSetActiveColor _activeColor; + _ctrlIcon ctrlSetTextColor _color; + _ctrlIcon ctrlSetActiveColor _activeColor; _screenPos params ["_posX", "_posY"]; private _posW = POS_W(_scale); private _posH = POS_H(_scale); - _control ctrlSetPosition [_posX - _posW / 2, _posY - _posH / 2, _posW, _posH]; - _control ctrlCommit 0; + _ctrlIcon ctrlSetPosition [_posX - _posW / 2, _posY - _posH / 2, _posW, _posH]; + _ctrlIcon ctrlCommit 0; - private _currentColor = [_color, _activeColor] select (_control getVariable [QGVAR(isActive), false]); + private _currentColor = [_color, _activeColor] select (_ctrlIcon getVariable [QGVAR(isActive), false]); if (_drawIn3D) then { // Draw comment name and connection line in 3D @@ -77,7 +77,7 @@ private _screenPos = []; _scale, // Width _scale, // Height 0, // Angle - _name, // Text + _title, // Text 1, // Shadow -1, // Text Size "RobotoCondensed", // Font @@ -87,6 +87,21 @@ private _screenPos = []; _textOffsetY // Offset Y ]; + if (_creator isNotEqualTo "") then { + drawIcon3D [ + "", + _currentColor, + _posAGL, + _scale, // Width + _scale, // Height + 0, // Angle + _creator, // Text + 1, // Shadow + -1, // Text Size + "RobotoCondensedBold" // Font + ]; + }; + // Draw ground-icon connection line only for icons higher than X m if ((_posAGL select 2) > GROUND_ICON_CONNECTION_HEIGHT) then { // Hide line behind icon @@ -94,6 +109,12 @@ private _screenPos = []; }; } else { // Draw comment name on map + private _text = if (_creator isEqualTo "") then { + _title + } else { + format ["%1: %2", _creator, _title]; + }; + _mapCtrl drawIcon [ "#(argb,8,8,3)color(0,0,0,0)", _currentColor, @@ -101,7 +122,7 @@ private _screenPos = []; MAP_TEXT_SCALE, // Width MAP_TEXT_SCALE, // Height 0, // Angle - _name, // Text + _text, // Text 1, // Shadow -1, // Text Size "RobotoCondensed" // Font diff --git a/addons/comments/functions/fnc_module.sqf b/addons/comments/functions/fnc_module.sqf new file mode 100644 index 000000000..2e5248483 --- /dev/null +++ b/addons/comments/functions/fnc_module.sqf @@ -0,0 +1,22 @@ +#include "script_component.hpp" +/* + * Author: Timi007 + * Zeus module function to create a comment. + * + * Arguments: + * 0: Logic + * + * Return Value: + * None + * + * Example: + * [LOGIC] call zen_comments_fnc_module + * + * Public: No + */ + +params ["_logic"]; + +private _posASL = getPosASLVisual _logic; +deleteVehicle _logic; +[_posASL] call FUNC(createCommentDialog); diff --git a/addons/comments/functions/fnc_onDraw.sqf b/addons/comments/functions/fnc_onDraw.sqf new file mode 100644 index 000000000..793273996 --- /dev/null +++ b/addons/comments/functions/fnc_onDraw.sqf @@ -0,0 +1,42 @@ +#include "script_component.hpp" +/* + * Author: Timi007 + * Handles drawing the comments on the Zeus map. + * + * Arguments: + * 0: Zeus map + * + * Return Value: + * None + * + * Example: + * [_mapCtrl] call zen_comments_fnc_onDraw + * + * Public: No + */ + +BEGIN_COUNTER(onDraw); + +params ["_mapCtrl"]; + +if (!GVAR(enableComments) && !GVAR(enable3DENComments)) exitWith { + _mapCtrl ctrlRemoveEventHandler [_thisEvent, _thisEventHandler]; + LOG("Removed 3DENComments map draw."); +}; + +// Draw is only called when map is open +if (call EFUNC(common,isInScreenshotMode)) exitWith {}; // HUD is hidden + +{ + _x params ["_draw", "_comments", "_color", "_activeColor"]; + + if (_draw && _comments isNotEqualTo []) then { + [_comments, GVAR(icons), _color, _activeColor, _mapCtrl] call FUNC(drawComments); + }; + // Icons are hidden in 3D first, so we don't need to hide them here again +} forEach [ + [GVAR(enableComments), GVAR(comments), GVAR(commentColor), GVAR(commentsActiveColor)], + [GVAR(enable3DENComments), GVAR(3DENComments), GVAR(3DENCommentColor), GVAR(3DENCommentsActiveColor)] +]; + +END_COUNTER(onDraw); diff --git a/addons/comments/functions/fnc_onDraw3D.sqf b/addons/comments/functions/fnc_onDraw3D.sqf new file mode 100644 index 000000000..981a46eda --- /dev/null +++ b/addons/comments/functions/fnc_onDraw3D.sqf @@ -0,0 +1,51 @@ +#include "script_component.hpp" +/* + * Author: Timi007 + * Handles drawing the comments in Zeus 3D. + * + * Arguments: + * None. + * + * Return Value: + * None + * + * Example: + * call zen_comments_fnc_onDraw3D + * + * Public: No + */ + +BEGIN_COUNTER(onDraw3D); + +if (!GVAR(enableComments) && !GVAR(enable3DENComments)) exitWith { + removeMissionEventHandler [_thisEvent, _thisEventHandler]; + + {ctrlDelete _y} forEach GVAR(icons); + GVAR(icons) = createHashMap; + + GVAR(draw3DAdded) = false; + LOG("Removed Draw3D."); +}; + +if ( + isNull (findDisplay IDD_RSCDISPLAYCURATOR) || // We are in not Zeus + {!isNull (findDisplay IDD_INTERRUPT)} || // Pause menu is opened + {call EFUNC(common,isInScreenshotMode)} // HUD is hidden +) exitWith { + {_y ctrlShow false} forEach GVAR(icons); +}; + +{ + _x params ["_draw", "_comments", "_color", "_activeColor"]; + + if (_draw && _comments isNotEqualTo []) then { + [_comments, GVAR(icons), _color, _activeColor] call FUNC(drawComments); + } else { + [_comments, GVAR(icons), false] call FUNC(showIcons); + }; +} forEach [ + [GVAR(enableComments), GVAR(comments), GVAR(commentColor), GVAR(commentsActiveColor)], + [GVAR(enable3DENComments), GVAR(3DENComments), GVAR(3DENCommentColor), GVAR(3DENCommentsActiveColor)] +]; + +END_COUNTER(onDraw3D); diff --git a/addons/comments/functions/fnc_save3DENComments.sqf b/addons/comments/functions/fnc_save3DENComments.sqf index 8a08659bf..9e014162a 100644 --- a/addons/comments/functions/fnc_save3DENComments.sqf +++ b/addons/comments/functions/fnc_save3DENComments.sqf @@ -28,16 +28,16 @@ private _comments = []; continue; }; - private _name = (_id get3DENAttribute "name") select 0; - private _description = (_id get3DENAttribute "description") select 0; - private _positionASL = (_id get3DENAttribute "position") select 0; + private _posASL = (_id get3DENAttribute "position") select 0; + private _title = (_id get3DENAttribute "name") select 0; + private _tooltip = (_id get3DENAttribute "description") select 0; // Ignore comments with special ignore directive in the description/tooltip - if (IGNORE_3DEN_COMMENT_STRING in _description) then { + if (IGNORE_3DEN_COMMENT_STRING in _tooltip) then { continue; }; - _comments pushBack [_id, _name, _description, _positionASL]; + _comments pushBack [format ["3den:%1", _id], _posASL, _title, _tooltip]; } forEach (all3DENEntities param [7, []]); // This command does not work if the mission is not saved diff --git a/addons/comments/functions/fnc_showIcons.sqf b/addons/comments/functions/fnc_showIcons.sqf new file mode 100644 index 000000000..44825900f --- /dev/null +++ b/addons/comments/functions/fnc_showIcons.sqf @@ -0,0 +1,26 @@ +#include "script_component.hpp" +/* + * Author: Timi007 + * Shows or hides all icons of given comments. + * + * Arguments: + * 0: Comments + * 1: Comment controls + * 2: Show icons + * + * Return Value: + * None + * + * Example: + * [GVAR(comments), GVAR(icons), false] call zen_comments_fnc_showIcons + * + * Public: No + */ + +params ["_comments", "_icons", ["_show", true, [true]]]; + +{ + _x params ["_id"]; + + (_icons get _id) ctrlShow _show; +} forEach _comments; diff --git a/addons/comments/initSettings.inc.sqf b/addons/comments/initSettings.inc.sqf index 702f0ab77..ad64a3a65 100644 --- a/addons/comments/initSettings.inc.sqf +++ b/addons/comments/initSettings.inc.sqf @@ -1,24 +1,55 @@ +[ + QGVAR(enableComments), + "CHECKBOX", + [LLSTRING(Comments), LLSTRING(Comments_Description)], + [ELSTRING(main,DisplayName), LLSTRING(DisplayName)], + true, + 0, + { + TRACE_1("Enable comments setting changed",_this); + + private _display = findDisplay IDD_RSCDISPLAYCURATOR; + if (!_this || GVAR(enable3DENComments) || isNull _display || GVAR(draw3DAdded)) exitWith {}; + [_display] call FUNC(addDrawEventHandler); + } +] call CBA_fnc_addSetting; + +[ + QGVAR(commentColor), + "COLOR", + [LLSTRING(CommentColor), LLSTRING(CommentColor_Description)], + [ELSTRING(main,DisplayName), LLSTRING(DisplayName)], + [1, 1, 0, 0.7], + 0, + { + TRACE_1("Comment color setting changed",_this); + params ["_r", "_g", "_b", "_a"]; + + GVAR(commentsActiveColor) = [_r, _g, _b, 1]; + } +] call CBA_fnc_addSetting; + [ QGVAR(enable3DENComments), "CHECKBOX", [LLSTRING(3DENComments), LLSTRING(3DENComments_Description)], - [ELSTRING(main,DisplayName), LSTRING(DisplayName)], + [ELSTRING(main,DisplayName), LLSTRING(DisplayName)], true, 0, { TRACE_1("Enable 3DEN comments setting changed",_this); private _display = findDisplay IDD_RSCDISPLAYCURATOR; - if (!_this || isNull _display || GVAR(draw3DAdded)) exitWith {}; + if (!_this || GVAR(enableComments) || isNull _display || GVAR(draw3DAdded)) exitWith {}; [_display] call FUNC(addDrawEventHandler); } ] call CBA_fnc_addSetting; [ - QGVAR(3DENCommentsColor), + QGVAR(3DENCommentColor), "COLOR", - [LLSTRING(3DENCommentsColor), LLSTRING(3DENCommentsColor_Description)], - [ELSTRING(main,DisplayName), LSTRING(DisplayName)], + [LLSTRING(3DENCommentColor), LLSTRING(3DENCommentColor_Description)], + [ELSTRING(main,DisplayName), LLSTRING(DisplayName)], [0, 1, 0.75, 0.7], 0, { diff --git a/addons/comments/script_component.hpp b/addons/comments/script_component.hpp index 7e4d77821..216f774f3 100644 --- a/addons/comments/script_component.hpp +++ b/addons/comments/script_component.hpp @@ -39,3 +39,5 @@ #define MAX_RENDER_DISTANCE 750 #define GROUND_ICON_CONNECTION_HEIGHT 0.5 + +#define STR_CREATE_COMMENT "$STR_3den_display3den_entitymenu_createcomment_text" diff --git a/addons/comments/stringtable.xml b/addons/comments/stringtable.xml index 2c6b0b93a..3abe28616 100644 --- a/addons/comments/stringtable.xml +++ b/addons/comments/stringtable.xml @@ -3,7 +3,35 @@ Comments + Poznámky Kommentare + Комментарии + Komentarze + Commenti + Comentarios + Commentaires + 評論 + 댓글 + コメント + Comentários + 评论 + Yorumlar + + + Show comments in Zeus + Zeige Kommentare im Zeus + + + Show comments created in Zeus. + Zeige im Zeus erstelle Kommentare. + + + Comment color + Farbe der Kommentare + + + Color of comments created in Zeus. + Farbe der im Zeus erstellen Kommentare. @@ -15,12 +43,12 @@ Show 3DEN comments in Zeus. Zeige 3DEN-Kommentare im Zeus an. - - 3DEN comments color + + 3DEN comment color Farbe der 3DEN-Kommentare - - Color of 3DEN Kommentare in Zeus. + + Color of 3DEN comments in Zeus. Farbe der 3DEN-Kommentare im Zeus. From 83f9d1ef77730d74d1b72474b7b6411eb1f8d144 Mon Sep 17 00:00:00 2001 From: Timi007 Date: Mon, 30 Dec 2024 01:34:48 +0100 Subject: [PATCH 09/23] Allow deleting comments --- addons/comments/XEH_PREP.hpp | 1 + .../comments/functions/fnc_createComment.sqf | 2 +- addons/comments/functions/fnc_createIcon.sqf | 13 +++++++++++ .../comments/functions/fnc_deleteComment.sqf | 11 ++++++---- .../functions/fnc_deleteCommentLocal.sqf | 8 ++++--- addons/comments/functions/fnc_deleteIcon.sqf | 2 +- .../comments/functions/fnc_is3DENComment.sqf | 22 +++++++++++++++++++ addons/comments/gui.hpp | 2 +- addons/comments/initSettings.inc.sqf | 9 ++++++++ addons/comments/stringtable.xml | 8 +++++++ 10 files changed, 68 insertions(+), 10 deletions(-) create mode 100644 addons/comments/functions/fnc_is3DENComment.sqf diff --git a/addons/comments/XEH_PREP.hpp b/addons/comments/XEH_PREP.hpp index a0135974a..885ac13d9 100644 --- a/addons/comments/XEH_PREP.hpp +++ b/addons/comments/XEH_PREP.hpp @@ -7,6 +7,7 @@ PREP(deleteComment); PREP(deleteCommentLocal); PREP(deleteIcon); PREP(drawComments); +PREP(is3DENComment); PREP(module); PREP(onDraw); PREP(onDraw3D); diff --git a/addons/comments/functions/fnc_createComment.sqf b/addons/comments/functions/fnc_createComment.sqf index b503f1b27..98a041a2d 100644 --- a/addons/comments/functions/fnc_createComment.sqf +++ b/addons/comments/functions/fnc_createComment.sqf @@ -27,5 +27,5 @@ GVAR(nextID) = GVAR(nextID) + 1; private _id = format ["zeus:%1", GVAR(nextID)]; private _jipId = format [QGVAR(%1), _id]; -TRACE_6("",_id,_posASL,_title,_tooltip,_creator,_jipId); +TRACE_6("Create comment",_id,_posASL,_title,_tooltip,_creator,_jipId); [QGVAR(createCommentLocal), [_id, _posASL, _title, _tooltip, _creator], _jipId] call CBA_fnc_globalEventJIP; diff --git a/addons/comments/functions/fnc_createIcon.sqf b/addons/comments/functions/fnc_createIcon.sqf index bf453bdfe..2615d105d 100644 --- a/addons/comments/functions/fnc_createIcon.sqf +++ b/addons/comments/functions/fnc_createIcon.sqf @@ -23,4 +23,17 @@ 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]; diff --git a/addons/comments/functions/fnc_deleteComment.sqf b/addons/comments/functions/fnc_deleteComment.sqf index 87a12f1c7..b4c3c2df9 100644 --- a/addons/comments/functions/fnc_deleteComment.sqf +++ b/addons/comments/functions/fnc_deleteComment.sqf @@ -10,14 +10,17 @@ * None * * Example: - * call zen_comments_fnc_deleteComment + * ["zeus:2"] call zen_comments_fnc_deleteComment * * Public: No */ params ["_id"]; -private _jipId = format [QGVAR(%1), _id]; -[_jipId] call CBA_fnc_removeGlobalEventJIP; +if !(_id call FUNC(is3DENComment)) then { + private _jipId = format [QGVAR(%1), _id]; + [_jipId] call CBA_fnc_removeGlobalEventJIP; +}; -[QGVAR(removeComment), [_id]] call CBA_fnc_globalEvent; +TRACE_1("Delete comment",_id); +[QGVAR(deleteCommentLocal), [_id]] call CBA_fnc_globalEvent; diff --git a/addons/comments/functions/fnc_deleteCommentLocal.sqf b/addons/comments/functions/fnc_deleteCommentLocal.sqf index 8fdb54549..123fbd9ee 100644 --- a/addons/comments/functions/fnc_deleteCommentLocal.sqf +++ b/addons/comments/functions/fnc_deleteCommentLocal.sqf @@ -10,7 +10,7 @@ * None * * Example: - * [_id] call zen_comments_fnc_deleteCommentLocal + * ["zeus:2"] call zen_comments_fnc_deleteCommentLocal * * Public: No */ @@ -19,9 +19,11 @@ params ["_id"]; if (!hasInterface) exitWith {}; -private _index = GVAR(comments) findIf {(_x select 0) isEqualTo _id}; +private _namespace = [GVAR(comments), GVAR(3DENComments)] select (_id call FUNC(is3DENComment)); + +private _index = _namespace findIf {(_x select 0) isEqualTo _id}; if (_index < 0) exitWith {}; -GVAR(comments) deleteAt _index; +_namespace deleteAt _index; [_id] call FUNC(deleteIcon); diff --git a/addons/comments/functions/fnc_deleteIcon.sqf b/addons/comments/functions/fnc_deleteIcon.sqf index 19dcdfab3..c697dee6d 100644 --- a/addons/comments/functions/fnc_deleteIcon.sqf +++ b/addons/comments/functions/fnc_deleteIcon.sqf @@ -10,7 +10,7 @@ * None * * Example: - * [_id] call zen_comments_fnc_deleteIcon + * ["zeus:2"] call zen_comments_fnc_deleteIcon * * Public: No */ diff --git a/addons/comments/functions/fnc_is3DENComment.sqf b/addons/comments/functions/fnc_is3DENComment.sqf new file mode 100644 index 000000000..c6dbaf9ef --- /dev/null +++ b/addons/comments/functions/fnc_is3DENComment.sqf @@ -0,0 +1,22 @@ +#include "script_component.hpp" +/* + * Author: Timi007 + * Checks if comment with given id is an 3DEN comment. + * + * Arguments: + * 0: Comment id + * + * Return Value: + * Is an 3DEN comment + * + * Example: + * ["3den:2"] call zen_comments_fnc_is3DENComment + * + * Public: No + */ + +params ["_id"]; + +(_id splitString ":") params ["_type"]; + +_type isEqualTo "3den" diff --git a/addons/comments/gui.hpp b/addons/comments/gui.hpp index 8e4b27024..36039e657 100644 --- a/addons/comments/gui.hpp +++ b/addons/comments/gui.hpp @@ -1,6 +1,6 @@ class RscActivePicture; class GVAR(RscActiveCommentIcon): RscActivePicture { - onMouseEnter = QUOTE((_this select 0) setVariable [ARR_2(QQGVAR(isActive),true)]); + onMouseEnter = QUOTE((_this select 0) setVariable [ARR_2(QQGVAR(isActive),true)]; ctrlSetFocus (_this select 0)); // Set focus for KeyDown to register onMouseExit = QUOTE((_this select 0) setVariable [ARR_2(QQGVAR(isActive),false)]); shadow = 1; text = COMMENT_ICON; diff --git a/addons/comments/initSettings.inc.sqf b/addons/comments/initSettings.inc.sqf index ad64a3a65..21208e9d9 100644 --- a/addons/comments/initSettings.inc.sqf +++ b/addons/comments/initSettings.inc.sqf @@ -59,3 +59,12 @@ GVAR(3DENCommentsActiveColor) = [_r, _g, _b, 1]; } ] call CBA_fnc_addSetting; + +[ + QGVAR(allowDeleting3DENComments), + "CHECKBOX", + [LLSTRING(AllowDeleting3DENComments), LLSTRING(AllowDeleting3DENComments_Description)], + [ELSTRING(main,DisplayName), LLSTRING(DisplayName)], + false, + 0 +] call CBA_fnc_addSetting; diff --git a/addons/comments/stringtable.xml b/addons/comments/stringtable.xml index 3abe28616..533789752 100644 --- a/addons/comments/stringtable.xml +++ b/addons/comments/stringtable.xml @@ -51,5 +51,13 @@ Color of 3DEN comments in Zeus. Farbe der 3DEN-Kommentare im Zeus. + + Allow deleting 3DEN comments + Erlaube Löschen von 3DEN-Kommentaren + + + Allow any Zeus to delete 3DEN comments. + Erlaube jedem Zeus das Löschen von 3DEN-Kommentaren. + From 8256b2c6a001f7044df662ddfd726301de46c2a2 Mon Sep 17 00:00:00 2001 From: Timi007 Date: Mon, 30 Dec 2024 20:28:11 +0100 Subject: [PATCH 10/23] Add type for zeus/3DEN comment & cleanup --- .../comments/functions/fnc_addDrawEventHandler.sqf | 4 ++-- addons/comments/functions/fnc_createComment.sqf | 6 ++++-- .../comments/functions/fnc_createCommentLocal.sqf | 2 +- addons/comments/functions/fnc_createIcon.sqf | 4 +++- addons/comments/functions/fnc_deleteComment.sqf | 2 ++ .../comments/functions/fnc_deleteCommentLocal.sqf | 14 ++++++++------ addons/comments/functions/fnc_drawComments.sqf | 2 +- addons/comments/functions/fnc_is3DENComment.sqf | 2 +- addons/comments/functions/fnc_onDraw3D.sqf | 2 +- addons/comments/functions/fnc_save3DENComments.sqf | 2 +- addons/comments/script_component.hpp | 3 +++ 11 files changed, 27 insertions(+), 16 deletions(-) diff --git a/addons/comments/functions/fnc_addDrawEventHandler.sqf b/addons/comments/functions/fnc_addDrawEventHandler.sqf index 5a3f43eef..72f86c743 100644 --- a/addons/comments/functions/fnc_addDrawEventHandler.sqf +++ b/addons/comments/functions/fnc_addDrawEventHandler.sqf @@ -27,11 +27,11 @@ if (!GVAR(enableComments) && !GVAR(enable3DENComments)) exitWith {}; if (!GVAR(draw3DAdded)) then { LOG("Adding Draw3D."); - addMissionEventHandler ["Draw3D", {call FUNC(onDraw3D)}]; + 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", {call FUNC(onDraw)}]; +_ctrlMap ctrlAddEventHandler ["Draw", FUNC(onDraw)]; diff --git a/addons/comments/functions/fnc_createComment.sqf b/addons/comments/functions/fnc_createComment.sqf index 98a041a2d..9ea9dfdf6 100644 --- a/addons/comments/functions/fnc_createComment.sqf +++ b/addons/comments/functions/fnc_createComment.sqf @@ -10,7 +10,7 @@ * 3: Name of the curator that created the comment * * Return Value: - * None. + * Id of the created comment . * * Example: * [[0,0,0], "My Comment", "This is a nice comment", "Joe"] call zen_comments_fnc_createComment @@ -24,8 +24,10 @@ if (!isServer) exitWith {}; GVAR(nextID) = GVAR(nextID) + 1; -private _id = format ["zeus:%1", GVAR(nextID)]; +private _id = format ["%1:%2", COMMENT_TYPE_ZEUS, 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; + +_id diff --git a/addons/comments/functions/fnc_createCommentLocal.sqf b/addons/comments/functions/fnc_createCommentLocal.sqf index 30a874dc8..a39c3d3d0 100644 --- a/addons/comments/functions/fnc_createCommentLocal.sqf +++ b/addons/comments/functions/fnc_createCommentLocal.sqf @@ -11,7 +11,7 @@ * 4: Name of the curator that created the comment * * Return Value: - * None. + * None * * Example: * ["zeus:1", [0,0,0], "My Comment", "This is a nice comment", "Joe"] call zen_comments_fnc_createCommentLocal diff --git a/addons/comments/functions/fnc_createIcon.sqf b/addons/comments/functions/fnc_createIcon.sqf index 2615d105d..ae26d1e61 100644 --- a/addons/comments/functions/fnc_createIcon.sqf +++ b/addons/comments/functions/fnc_createIcon.sqf @@ -8,7 +8,7 @@ * 1: Comment * * Return Value: - * None. + * Icon control for the comment . * * Example: * [_display, _comment] call zen_comments_fnc_createIcon @@ -37,3 +37,5 @@ _ctrlIcon ctrlAddEventHandler ["KeyDown", { }]; GVAR(icons) set [_id, _ctrlIcon]; + +_ctrlIcon diff --git a/addons/comments/functions/fnc_deleteComment.sqf b/addons/comments/functions/fnc_deleteComment.sqf index b4c3c2df9..0aa7cc679 100644 --- a/addons/comments/functions/fnc_deleteComment.sqf +++ b/addons/comments/functions/fnc_deleteComment.sqf @@ -17,6 +17,8 @@ params ["_id"]; +if (!isServer) exitWith {}; + if !(_id call FUNC(is3DENComment)) then { private _jipId = format [QGVAR(%1), _id]; [_jipId] call CBA_fnc_removeGlobalEventJIP; diff --git a/addons/comments/functions/fnc_deleteCommentLocal.sqf b/addons/comments/functions/fnc_deleteCommentLocal.sqf index 123fbd9ee..7e9ab60a3 100644 --- a/addons/comments/functions/fnc_deleteCommentLocal.sqf +++ b/addons/comments/functions/fnc_deleteCommentLocal.sqf @@ -7,7 +7,7 @@ * 0: Comment id * * Return Value: - * None + * Success * * Example: * ["zeus:2"] call zen_comments_fnc_deleteCommentLocal @@ -17,13 +17,15 @@ params ["_id"]; -if (!hasInterface) exitWith {}; +if (!hasInterface) exitWith {false}; -private _namespace = [GVAR(comments), GVAR(3DENComments)] select (_id call FUNC(is3DENComment)); +private _collection = [GVAR(comments), GVAR(3DENComments)] select (_id call FUNC(is3DENComment)); -private _index = _namespace findIf {(_x select 0) isEqualTo _id}; -if (_index < 0) exitWith {}; +private _index = _collection findIf {(_x select 0) isEqualTo _id}; +if (_index < 0) exitWith {false}; -_namespace deleteAt _index; +_collection deleteAt _index; [_id] call FUNC(deleteIcon); + +true diff --git a/addons/comments/functions/fnc_drawComments.sqf b/addons/comments/functions/fnc_drawComments.sqf index 1584fc414..4ae5048ad 100644 --- a/addons/comments/functions/fnc_drawComments.sqf +++ b/addons/comments/functions/fnc_drawComments.sqf @@ -77,7 +77,7 @@ private _screenPos = []; _scale, // Width _scale, // Height 0, // Angle - _title, // Text + _title, // Text 1, // Shadow -1, // Text Size "RobotoCondensed", // Font diff --git a/addons/comments/functions/fnc_is3DENComment.sqf b/addons/comments/functions/fnc_is3DENComment.sqf index c6dbaf9ef..f477143f8 100644 --- a/addons/comments/functions/fnc_is3DENComment.sqf +++ b/addons/comments/functions/fnc_is3DENComment.sqf @@ -19,4 +19,4 @@ params ["_id"]; (_id splitString ":") params ["_type"]; -_type isEqualTo "3den" +_type isEqualTo COMMENT_TYPE_3DEN diff --git a/addons/comments/functions/fnc_onDraw3D.sqf b/addons/comments/functions/fnc_onDraw3D.sqf index 981a46eda..afe197ea9 100644 --- a/addons/comments/functions/fnc_onDraw3D.sqf +++ b/addons/comments/functions/fnc_onDraw3D.sqf @@ -4,7 +4,7 @@ * Handles drawing the comments in Zeus 3D. * * Arguments: - * None. + * None * * Return Value: * None diff --git a/addons/comments/functions/fnc_save3DENComments.sqf b/addons/comments/functions/fnc_save3DENComments.sqf index 9e014162a..c9ba7f4e5 100644 --- a/addons/comments/functions/fnc_save3DENComments.sqf +++ b/addons/comments/functions/fnc_save3DENComments.sqf @@ -37,7 +37,7 @@ private _comments = []; continue; }; - _comments pushBack [format ["3den:%1", _id], _posASL, _title, _tooltip]; + _comments pushBack [format ["%1:%2", COMMENT_TYPE_3DEN, _id], _posASL, _title, _tooltip]; } forEach (all3DENEntities param [7, []]); // This command does not work if the mission is not saved diff --git a/addons/comments/script_component.hpp b/addons/comments/script_component.hpp index 216f774f3..03bcad3b9 100644 --- a/addons/comments/script_component.hpp +++ b/addons/comments/script_component.hpp @@ -41,3 +41,6 @@ #define GROUND_ICON_CONNECTION_HEIGHT 0.5 #define STR_CREATE_COMMENT "$STR_3den_display3den_entitymenu_createcomment_text" + +#define COMMENT_TYPE_3DEN "3den" +#define COMMENT_TYPE_ZEUS "zeus" From d66d336674f441e471bdb3e34dc1c2a10c1c25c6 Mon Sep 17 00:00:00 2001 From: Timi007 Date: Mon, 30 Dec 2024 20:29:10 +0100 Subject: [PATCH 11/23] Merge to one package --- addons/comments/stringtable.xml | 2 -- 1 file changed, 2 deletions(-) diff --git a/addons/comments/stringtable.xml b/addons/comments/stringtable.xml index 533789752..b22b9e816 100644 --- a/addons/comments/stringtable.xml +++ b/addons/comments/stringtable.xml @@ -33,8 +33,6 @@ Color of comments created in Zeus. Farbe der im Zeus erstellen Kommentare. - - Show 3DEN comments in Zeus Zeige 3DEN-Kommentare im Zeus From 4c44b0357df659f5ac766a4e0479cfd066107873 Mon Sep 17 00:00:00 2001 From: Timi007 Date: Tue, 31 Dec 2024 18:02:38 +0100 Subject: [PATCH 12/23] Remove module --- addons/comments/CfgVehicles.hpp | 10 ---------- addons/comments/XEH_PREP.hpp | 1 - addons/comments/config.cpp | 1 - addons/comments/functions/fnc_module.sqf | 22 ---------------------- 4 files changed, 34 deletions(-) delete mode 100644 addons/comments/CfgVehicles.hpp delete mode 100644 addons/comments/functions/fnc_module.sqf diff --git a/addons/comments/CfgVehicles.hpp b/addons/comments/CfgVehicles.hpp deleted file mode 100644 index 100d3f5c0..000000000 --- a/addons/comments/CfgVehicles.hpp +++ /dev/null @@ -1,10 +0,0 @@ -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; - }; -}; diff --git a/addons/comments/XEH_PREP.hpp b/addons/comments/XEH_PREP.hpp index 885ac13d9..e1495b4d1 100644 --- a/addons/comments/XEH_PREP.hpp +++ b/addons/comments/XEH_PREP.hpp @@ -8,7 +8,6 @@ PREP(deleteCommentLocal); PREP(deleteIcon); PREP(drawComments); PREP(is3DENComment); -PREP(module); PREP(onDraw); PREP(onDraw3D); PREP(save3DENComments); diff --git a/addons/comments/config.cpp b/addons/comments/config.cpp index bcd1094ab..140da3c2a 100644 --- a/addons/comments/config.cpp +++ b/addons/comments/config.cpp @@ -20,6 +20,5 @@ PRELOAD_ADDONS; #include "CfgEventHandlers.hpp" #include "Cfg3DEN.hpp" -#include "CfgVehicles.hpp" #include "CfgContext.hpp" #include "gui.hpp" diff --git a/addons/comments/functions/fnc_module.sqf b/addons/comments/functions/fnc_module.sqf deleted file mode 100644 index 2e5248483..000000000 --- a/addons/comments/functions/fnc_module.sqf +++ /dev/null @@ -1,22 +0,0 @@ -#include "script_component.hpp" -/* - * Author: Timi007 - * Zeus module function to create a comment. - * - * Arguments: - * 0: Logic - * - * Return Value: - * None - * - * Example: - * [LOGIC] call zen_comments_fnc_module - * - * Public: No - */ - -params ["_logic"]; - -private _posASL = getPosASLVisual _logic; -deleteVehicle _logic; -[_posASL] call FUNC(createCommentDialog); From 045bc1aa5c0ae308038d1ef4f511620217580a23 Mon Sep 17 00:00:00 2001 From: Timi007 Date: Tue, 31 Dec 2024 18:59:35 +0100 Subject: [PATCH 13/23] Allow editing and pick color of comments --- addons/comments/CfgContext.hpp | 1 + addons/comments/XEH_PREP.hpp | 7 ++- addons/comments/XEH_postInit.sqf | 11 ++++- addons/comments/XEH_preInit.sqf | 2 +- .../functions/fnc_addDrawEventHandler.sqf | 8 ++-- .../comments/functions/fnc_createComment.sqf | 13 +++--- .../functions/fnc_createCommentDialog.sqf | 7 +-- .../functions/fnc_createCommentLocal.sqf | 17 ++++--- addons/comments/functions/fnc_createIcon.sqf | 30 ++++++------- .../comments/functions/fnc_deleteComment.sqf | 12 ++--- .../functions/fnc_deleteCommentLocal.sqf | 16 ++----- .../comments/functions/fnc_drawComments.sqf | 39 +++++++++++----- .../comments/functions/fnc_is3DENComment.sqf | 2 +- addons/comments/functions/fnc_onDraw.sqf | 14 +----- addons/comments/functions/fnc_onDraw3D.sqf | 16 ++----- addons/comments/functions/fnc_onKeyDown.sqf | 29 ++++++++++++ .../functions/fnc_onMouseDblClick.sqf | 29 ++++++++++++ .../functions/fnc_save3DENComments.sqf | 11 ++--- addons/comments/functions/fnc_showIcons.sqf | 26 ----------- .../comments/functions/fnc_updateComment.sqf | 30 +++++++++++++ .../functions/fnc_updateCommentDialog.sqf | 38 ++++++++++++++++ .../functions/fnc_updateCommentLocal.sqf | 23 ++++++++++ addons/comments/functions/fnc_updateIcon.sqf | 23 ++++++++++ addons/comments/initSettings.inc.sqf | 45 ++++++------------- addons/comments/script_component.hpp | 3 ++ addons/comments/stringtable.xml | 32 ++----------- 26 files changed, 297 insertions(+), 187 deletions(-) create mode 100644 addons/comments/functions/fnc_onKeyDown.sqf create mode 100644 addons/comments/functions/fnc_onMouseDblClick.sqf delete mode 100644 addons/comments/functions/fnc_showIcons.sqf create mode 100644 addons/comments/functions/fnc_updateComment.sqf create mode 100644 addons/comments/functions/fnc_updateCommentDialog.sqf create mode 100644 addons/comments/functions/fnc_updateCommentLocal.sqf create mode 100644 addons/comments/functions/fnc_updateIcon.sqf diff --git a/addons/comments/CfgContext.hpp b/addons/comments/CfgContext.hpp index d94db1b6a..ca8c1ce08 100644 --- a/addons/comments/CfgContext.hpp +++ b/addons/comments/CfgContext.hpp @@ -2,6 +2,7 @@ class EGVAR(context_menu,actions) { class GVAR(createComment) { displayName = STR_CREATE_COMMENT; icon = COMMENT_ICON; + condition = QGVAR(enabled); statement = QUOTE([_position] call FUNC(createCommentDialog)); priority = 35; }; diff --git a/addons/comments/XEH_PREP.hpp b/addons/comments/XEH_PREP.hpp index e1495b4d1..50932e84d 100644 --- a/addons/comments/XEH_PREP.hpp +++ b/addons/comments/XEH_PREP.hpp @@ -10,5 +10,10 @@ PREP(drawComments); PREP(is3DENComment); PREP(onDraw); PREP(onDraw3D); +PREP(onKeyDown); +PREP(onMouseDblClick); PREP(save3DENComments); -PREP(showIcons); +PREP(updateComment); +PREP(updateCommentDialog); +PREP(updateCommentLocal); +PREP(updateIcon); diff --git a/addons/comments/XEH_postInit.sqf b/addons/comments/XEH_postInit.sqf index e3330a578..3dbca9440 100644 --- a/addons/comments/XEH_postInit.sqf +++ b/addons/comments/XEH_postInit.sqf @@ -6,14 +6,21 @@ if (isServer) then { GVAR(nextId) = 0; [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 { [QGVAR(createCommentLocal), LINKFUNC(createCommentLocal)] call CBA_fnc_addEventHandler; [QGVAR(deleteCommentLocal), LINKFUNC(deleteCommentLocal)] call CBA_fnc_addEventHandler; + [QGVAR(updateCommentLocal), LINKFUNC(updateCommentLocal)] call CBA_fnc_addEventHandler; + + [QGVAR(commentCreated), LINKFUNC(createIcon)] call CBA_fnc_addEventHandler; + [QGVAR(commentDeleted), LINKFUNC(deleteIcon)] call CBA_fnc_addEventHandler; + [QGVAR(commentUpdated), LINKFUNC(updateIcon)] 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)); + GVAR(comments) = createHashMapFromArray getMissionConfigValue [QGVAR(3DENComments), []]; + + TRACE_1("Loaded 3DEN Comments from mission",GVAR(comments)); }; diff --git a/addons/comments/XEH_preInit.sqf b/addons/comments/XEH_preInit.sqf index d9ab12fdd..47b9818cb 100644 --- a/addons/comments/XEH_preInit.sqf +++ b/addons/comments/XEH_preInit.sqf @@ -7,8 +7,8 @@ PREP_RECOMPILE_START; PREP_RECOMPILE_END; GVAR(icons) = createHashMap; +GVAR(comments) = createHashMap; GVAR(draw3DAdded) = false; -GVAR(comments) = []; #include "initSettings.inc.sqf" diff --git a/addons/comments/functions/fnc_addDrawEventHandler.sqf b/addons/comments/functions/fnc_addDrawEventHandler.sqf index 72f86c743..e256d1894 100644 --- a/addons/comments/functions/fnc_addDrawEventHandler.sqf +++ b/addons/comments/functions/fnc_addDrawEventHandler.sqf @@ -19,11 +19,11 @@ params ["_display"]; TRACE_1("Zeus display opened",_display); -if (!GVAR(enableComments) && !GVAR(enable3DENComments)) exitWith {}; +if (!GVAR(enabled) && !GVAR(enabled3DEN)) exitWith {}; -{ - [_display, _x] call FUNC(createIcon); -} forEach (GVAR(3DENComments) + GVAR(comments)); +[{ + {([_x] + _y) 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."); diff --git a/addons/comments/functions/fnc_createComment.sqf b/addons/comments/functions/fnc_createComment.sqf index 9ea9dfdf6..54e209940 100644 --- a/addons/comments/functions/fnc_createComment.sqf +++ b/addons/comments/functions/fnc_createComment.sqf @@ -1,24 +1,25 @@ #include "script_component.hpp" /* * Author: Timi007 - * Creates a comment in Zeus. Must be called on server. + * Creates the comment. Must be called on server. * * Arguments: * 0: Comment position ASL * 1: Comment title * 2: Comment tooltip - * 3: Name of the curator that created the comment + * 3: Comment color (RGBA) + * 4: Name of the curator that created the comment * * Return Value: * Id of the created comment . * * Example: - * [[0,0,0], "My Comment", "This is a nice comment", "Joe"] call zen_comments_fnc_createComment + * [[0,0,0], "My Comment", "This is a nice comment", [1,0,0,0.7], "Joe"] call zen_comments_fnc_createComment * * Public: No */ -params ["_posASL", "_title", ["_tooltip", "", [""]], ["_creator", "", [""]]]; +params ["_posASL", "_title", ["_tooltip", "", [""]], ["_color", DEFAULT_COLOR, [[]], [4]], ["_creator", "", [""]]]; if (!isServer) exitWith {}; @@ -27,7 +28,7 @@ GVAR(nextID) = GVAR(nextID) + 1; private _id = format ["%1:%2", COMMENT_TYPE_ZEUS, 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; +TRACE_7("Create comment",_id,_posASL,_title,_tooltip,_color,_creator,_jipId); +[QGVAR(createCommentLocal), [_id, _posASL, _title, _tooltip, _color, _creator], _jipId] call CBA_fnc_globalEventJIP; _id diff --git a/addons/comments/functions/fnc_createCommentDialog.sqf b/addons/comments/functions/fnc_createCommentDialog.sqf index 145ffd381..6e0b65ec0 100644 --- a/addons/comments/functions/fnc_createCommentDialog.sqf +++ b/addons/comments/functions/fnc_createCommentDialog.sqf @@ -21,13 +21,14 @@ 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] + ["EDIT:MULTI", localize "str_3den_comment_attribute_name_tooltip", [""], true], + ["COLOR", localize "str_3den_marker_attribute_color_displayname", DEFAULT_COLOR] ], { params ["_values", "_posASL"]; - _values params ["_title", "_tooltip"]; + _values params ["_title", "_tooltip", "_color"]; - [QGVAR(createComment), [_posASL, _title, _tooltip, profileName]] call CBA_fnc_serverEvent; + [QGVAR(createComment), [_posASL, _title, _tooltip, _color, profileName]] call CBA_fnc_serverEvent; }, {}, _posASL diff --git a/addons/comments/functions/fnc_createCommentLocal.sqf b/addons/comments/functions/fnc_createCommentLocal.sqf index a39c3d3d0..d2ecde9c0 100644 --- a/addons/comments/functions/fnc_createCommentLocal.sqf +++ b/addons/comments/functions/fnc_createCommentLocal.sqf @@ -1,29 +1,28 @@ #include "script_component.hpp" /* * Author: Timi007 - * Creates a comment in Zeus locally. + * Creates the comment locally. * * Arguments: * 0: Unique comment id * 1: Comment position ASL * 2: Comment title * 3: Comment tooltip - * 4: Name of the curator that created the comment + * 4: Comment color (RGBA) + * 5: Name of the curator that created the comment * * Return Value: * None * * Example: - * ["zeus:1", [0,0,0], "My Comment", "This is a nice comment", "Joe"] call zen_comments_fnc_createCommentLocal + * ["zeus:1", [0,0,0], "My Comment", "This is a nice comment", [1,0,0,0.7], "Joe"] call zen_comments_fnc_createCommentLocal * * Public: No */ -if (!hasInterface) exitWith {}; +params ["_id"]; -private _display = findDisplay IDD_RSCDISPLAYCURATOR; -if (!isNull _display) then { - [_display, _this] call FUNC(createIcon); -}; +GVAR(comments) set [_id, _this select [1]]; -GVAR(comments) pushBack _this; +// Will create icon and provides hook +[QGVAR(commentCreated), _this] call CBA_fnc_localEvent; diff --git a/addons/comments/functions/fnc_createIcon.sqf b/addons/comments/functions/fnc_createIcon.sqf index ae26d1e61..0422d79a2 100644 --- a/addons/comments/functions/fnc_createIcon.sqf +++ b/addons/comments/functions/fnc_createIcon.sqf @@ -4,37 +4,33 @@ * Creates an icon control for the comment. * * Arguments: - * 0: Zeus display - * 1: Comment + * 0: Unique comment id + * 1: Comment position ASL + * 2: Comment title + * 3: Comment tooltip + * 4: Comment color (RGBA) + * 5: Name of the curator that created the comment * * Return Value: * Icon control for the comment . * * Example: - * [_display, _comment] call zen_comments_fnc_createIcon + * ["zeus:1", [0,0,0], "My Comment", "This is a nice comment", [1,0,0,0.7], "Joe"] call zen_comments_fnc_createIcon * * Public: No */ -params ["_display", "_comment"]; -_comment params ["_id", "", "", "_tooltip"]; +params ["_id", "", "", "_tooltip"]; + +private _display = findDisplay IDD_RSCDISPLAYCURATOR; +if (isNull _display) exitWith {}; 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; -}]; +_ctrlIcon ctrlAddEventHandler ["KeyDown", FUNC(onKeyDown)]; +_ctrlIcon ctrlAddEventHandler ["MouseButtonDblClick", FUNC(onMouseDblClick)]; GVAR(icons) set [_id, _ctrlIcon]; diff --git a/addons/comments/functions/fnc_deleteComment.sqf b/addons/comments/functions/fnc_deleteComment.sqf index 0aa7cc679..ee896a693 100644 --- a/addons/comments/functions/fnc_deleteComment.sqf +++ b/addons/comments/functions/fnc_deleteComment.sqf @@ -1,7 +1,7 @@ #include "script_component.hpp" /* * Author: Timi007 - * Deletes a comment created in Zeus. Must be called on server. + * Deletes the comment. Must be called on server. * * Arguments: * 0: Comment id @@ -19,10 +19,12 @@ params ["_id"]; if (!isServer) exitWith {}; -if !(_id call FUNC(is3DENComment)) then { +TRACE_1("Delete comment",_id); +if (_id call FUNC(is3DENComment)) then { + [QGVAR(deleteCommentLocal), [_id]] call CBA_fnc_globalEventJIP; +} else { private _jipId = format [QGVAR(%1), _id]; [_jipId] call CBA_fnc_removeGlobalEventJIP; -}; -TRACE_1("Delete comment",_id); -[QGVAR(deleteCommentLocal), [_id]] call CBA_fnc_globalEvent; + [QGVAR(deleteCommentLocal), [_id]] call CBA_fnc_globalEvent; +}; diff --git a/addons/comments/functions/fnc_deleteCommentLocal.sqf b/addons/comments/functions/fnc_deleteCommentLocal.sqf index 7e9ab60a3..256505bde 100644 --- a/addons/comments/functions/fnc_deleteCommentLocal.sqf +++ b/addons/comments/functions/fnc_deleteCommentLocal.sqf @@ -7,7 +7,7 @@ * 0: Comment id * * Return Value: - * Success + * None * * Example: * ["zeus:2"] call zen_comments_fnc_deleteCommentLocal @@ -17,15 +17,7 @@ params ["_id"]; -if (!hasInterface) exitWith {false}; +GVAR(comments) deleteAt _id; -private _collection = [GVAR(comments), GVAR(3DENComments)] select (_id call FUNC(is3DENComment)); - -private _index = _collection findIf {(_x select 0) isEqualTo _id}; -if (_index < 0) exitWith {false}; - -_collection deleteAt _index; - -[_id] call FUNC(deleteIcon); - -true +// Will delete icon and provides hook +[QGVAR(commentDeleted), [_id]] call CBA_fnc_localEvent; diff --git a/addons/comments/functions/fnc_drawComments.sqf b/addons/comments/functions/fnc_drawComments.sqf index 4ae5048ad..75129c814 100644 --- a/addons/comments/functions/fnc_drawComments.sqf +++ b/addons/comments/functions/fnc_drawComments.sqf @@ -1,25 +1,25 @@ #include "script_component.hpp" /* * Author: Timi007 - * Draw comments on screen. Needs to be called every frame. + * Draws comments on screen. Needs to be called every frame. * * Arguments: - * 0: Comments + * 0: Comments * 1: Comment controls - * 2: Comment color (RGBA) - * 2: Comment color when mouse is hovered over it (RGBA) - * 2: Map control (Optional, default: Draw in 3D) + * 2: Draw Zeus comments (Optional, default: true) + * 3: Draw 3DEN comments (Optional, default: true) + * 4: Map control (Optional, default: Draw in 3D) * * Return Value: * None * * Example: - * [_comments, _icons, [1, 0, 0, 0.7], [1, 0, 0, 1]] call zen_comments_fnc_drawComments + * [_comments, _icons] call zen_comments_fnc_drawComments * * Public: No */ -params ["_comments", "_icons", "_color", "_activeColor", ["_mapCtrl", controlNull, [controlNull]]]; +params ["_comments", "_icons", ["_drawZeus", true, [true]], ["_draw3DEN", true, [true]], ["_mapCtrl", controlNull, [controlNull]]]; private _drawIn3D = isNull _mapCtrl; @@ -28,7 +28,19 @@ private _scale = 0; private _screenPos = []; { - _x params ["_id", "_posASL", "_title", "_tooltip", ["_creator", ""]]; + private _id = _x; + _y params ["_posASL", "_title", "_tooltip", ["_color", []], ["_creator", ""]]; + + private _ctrlIcon = _icons getOrDefault [_id, controlNull]; + if (isNull _ctrlIcon) then { + continue; + }; + + private _is3DENComment = _creator isEqualTo ""; // Faster then calling FUNC(is3DENComment) + if ((!_is3DENComment && !_drawZeus) || (_is3DENComment && !_draw3DEN)) then { + _ctrlIcon ctrlShow false; + continue; + }; private _posAGL = ASLToAGL _posASL; @@ -43,8 +55,6 @@ private _screenPos = []; _screenPos = _mapCtrl ctrlMapWorldToScreen _posAGL; }; - private _ctrlIcon = _icons get _id; - // Don't draw icon if it's too small or outside screen if (_scale < 0.01 || {_screenPos isEqualTo []}) then { _ctrlIcon ctrlShow false; @@ -52,6 +62,15 @@ private _screenPos = []; }; _ctrlIcon ctrlShow true; + if (_color isEqualTo []) then { + if (_is3DENComment) then { + _color = GVAR(3DENColor); + } else { + _color = DEFAULT_COLOR; + }; + }; + private _activeColor = [_color select 0, _color select 1, _color select 2, 1]; + _ctrlIcon ctrlSetTextColor _color; _ctrlIcon ctrlSetActiveColor _activeColor; diff --git a/addons/comments/functions/fnc_is3DENComment.sqf b/addons/comments/functions/fnc_is3DENComment.sqf index f477143f8..1168849b8 100644 --- a/addons/comments/functions/fnc_is3DENComment.sqf +++ b/addons/comments/functions/fnc_is3DENComment.sqf @@ -17,6 +17,6 @@ params ["_id"]; -(_id splitString ":") params ["_type"]; +(_id splitString ":") params [["_type", "", [""]]]; _type isEqualTo COMMENT_TYPE_3DEN diff --git a/addons/comments/functions/fnc_onDraw.sqf b/addons/comments/functions/fnc_onDraw.sqf index 793273996..84de0b0c2 100644 --- a/addons/comments/functions/fnc_onDraw.sqf +++ b/addons/comments/functions/fnc_onDraw.sqf @@ -19,7 +19,7 @@ BEGIN_COUNTER(onDraw); params ["_mapCtrl"]; -if (!GVAR(enableComments) && !GVAR(enable3DENComments)) exitWith { +if (!GVAR(enabled) && !GVAR(enabled3DEN)) exitWith { _mapCtrl ctrlRemoveEventHandler [_thisEvent, _thisEventHandler]; LOG("Removed 3DENComments map draw."); }; @@ -27,16 +27,6 @@ if (!GVAR(enableComments) && !GVAR(enable3DENComments)) exitWith { // Draw is only called when map is open if (call EFUNC(common,isInScreenshotMode)) exitWith {}; // HUD is hidden -{ - _x params ["_draw", "_comments", "_color", "_activeColor"]; - - if (_draw && _comments isNotEqualTo []) then { - [_comments, GVAR(icons), _color, _activeColor, _mapCtrl] call FUNC(drawComments); - }; - // Icons are hidden in 3D first, so we don't need to hide them here again -} forEach [ - [GVAR(enableComments), GVAR(comments), GVAR(commentColor), GVAR(commentsActiveColor)], - [GVAR(enable3DENComments), GVAR(3DENComments), GVAR(3DENCommentColor), GVAR(3DENCommentsActiveColor)] -]; +[GVAR(comments), GVAR(icons), GVAR(enabled), GVAR(enabled3DEN), _mapCtrl] call FUNC(drawComments); END_COUNTER(onDraw); diff --git a/addons/comments/functions/fnc_onDraw3D.sqf b/addons/comments/functions/fnc_onDraw3D.sqf index afe197ea9..735f694c7 100644 --- a/addons/comments/functions/fnc_onDraw3D.sqf +++ b/addons/comments/functions/fnc_onDraw3D.sqf @@ -17,7 +17,7 @@ BEGIN_COUNTER(onDraw3D); -if (!GVAR(enableComments) && !GVAR(enable3DENComments)) exitWith { +if (!GVAR(enabled) && !GVAR(enabled3DEN)) exitWith { removeMissionEventHandler [_thisEvent, _thisEventHandler]; {ctrlDelete _y} forEach GVAR(icons); @@ -30,22 +30,12 @@ if (!GVAR(enableComments) && !GVAR(enable3DENComments)) exitWith { if ( isNull (findDisplay IDD_RSCDISPLAYCURATOR) || // We are in not Zeus {!isNull (findDisplay IDD_INTERRUPT)} || // Pause menu is opened + {dialog} || // We have a dialog open {call EFUNC(common,isInScreenshotMode)} // HUD is hidden ) exitWith { {_y ctrlShow false} forEach GVAR(icons); }; -{ - _x params ["_draw", "_comments", "_color", "_activeColor"]; - - if (_draw && _comments isNotEqualTo []) then { - [_comments, GVAR(icons), _color, _activeColor] call FUNC(drawComments); - } else { - [_comments, GVAR(icons), false] call FUNC(showIcons); - }; -} forEach [ - [GVAR(enableComments), GVAR(comments), GVAR(commentColor), GVAR(commentsActiveColor)], - [GVAR(enable3DENComments), GVAR(3DENComments), GVAR(3DENCommentColor), GVAR(3DENCommentsActiveColor)] -]; +[GVAR(comments), GVAR(icons), GVAR(enabled), GVAR(enabled3DEN)] call FUNC(drawComments); END_COUNTER(onDraw3D); diff --git a/addons/comments/functions/fnc_onKeyDown.sqf b/addons/comments/functions/fnc_onKeyDown.sqf new file mode 100644 index 000000000..1c1082d8a --- /dev/null +++ b/addons/comments/functions/fnc_onKeyDown.sqf @@ -0,0 +1,29 @@ +#include "script_component.hpp" +/* + * Author: Timi007 + * Handles the key down event for a comment. + * + * Arguments: + * 0: Icon control + * 1: Key pressed + * + * Return Value: + * None + * + * Example: + * _this call zen_comments_fnc_onKeyDown + * + * Public: No + */ + +params ["_ctrlIcon", "_key"]; +TRACE_1("params",_this); + +if (_key != DIK_DELETE) exitWith {}; + +private _id = _ctrlIcon getVariable [QGVAR(comment), ""]; +if (_id isEqualTo "") exitWith {}; + +if (!GVAR(allowDeleting3DEN) && {_id call FUNC(is3DENComment)}) exitWith {}; + +[QGVAR(deleteComment), [_id]] call CBA_fnc_serverEvent; diff --git a/addons/comments/functions/fnc_onMouseDblClick.sqf b/addons/comments/functions/fnc_onMouseDblClick.sqf new file mode 100644 index 000000000..f04b1de54 --- /dev/null +++ b/addons/comments/functions/fnc_onMouseDblClick.sqf @@ -0,0 +1,29 @@ +#include "script_component.hpp" +/* + * Author: Timi007 + * Handles the mouse button double click event for a comment. + * + * Arguments: + * 0: Icon control + * 1: Mouse button pressed + * + * Return Value: + * None + * + * Example: + * _this call zen_comments_fnc_onMouseDblClick + * + * Public: No + */ + +params ["_ctrlIcon", "_button"]; +TRACE_1("params",_this); + +if (_button != 0) exitWith {}; + +private _id = _ctrlIcon getVariable [QGVAR(comment), ""]; +if (_id isEqualTo "" || {_id call FUNC(is3DENComment)}) exitWith {}; + +TRACE_1("Edit comment",_id); + +[_id] call FUNC(updateCommentDialog); diff --git a/addons/comments/functions/fnc_save3DENComments.sqf b/addons/comments/functions/fnc_save3DENComments.sqf index c9ba7f4e5..3fcb13bde 100644 --- a/addons/comments/functions/fnc_save3DENComments.sqf +++ b/addons/comments/functions/fnc_save3DENComments.sqf @@ -28,16 +28,17 @@ private _comments = []; continue; }; - private _posASL = (_id get3DENAttribute "position") select 0; - private _title = (_id get3DENAttribute "name") select 0; - private _tooltip = (_id get3DENAttribute "description") select 0; - // Ignore comments with special ignore directive in the description/tooltip + private _tooltip = (_id get3DENAttribute "description") select 0; if (IGNORE_3DEN_COMMENT_STRING in _tooltip) then { continue; }; - _comments pushBack [format ["%1:%2", COMMENT_TYPE_3DEN, _id], _posASL, _title, _tooltip]; + private _posASL = (_id get3DENAttribute "position") select 0; + private _title = (_id get3DENAttribute "name") select 0; + + // Save in hashmap format with id as key + _comments pushBack [format ["%1:%2", COMMENT_TYPE_3DEN, _id], [_posASL, _title, _tooltip]]; } forEach (all3DENEntities param [7, []]); // This command does not work if the mission is not saved diff --git a/addons/comments/functions/fnc_showIcons.sqf b/addons/comments/functions/fnc_showIcons.sqf deleted file mode 100644 index 44825900f..000000000 --- a/addons/comments/functions/fnc_showIcons.sqf +++ /dev/null @@ -1,26 +0,0 @@ -#include "script_component.hpp" -/* - * Author: Timi007 - * Shows or hides all icons of given comments. - * - * Arguments: - * 0: Comments - * 1: Comment controls - * 2: Show icons - * - * Return Value: - * None - * - * Example: - * [GVAR(comments), GVAR(icons), false] call zen_comments_fnc_showIcons - * - * Public: No - */ - -params ["_comments", "_icons", ["_show", true, [true]]]; - -{ - _x params ["_id"]; - - (_icons get _id) ctrlShow _show; -} forEach _comments; diff --git a/addons/comments/functions/fnc_updateComment.sqf b/addons/comments/functions/fnc_updateComment.sqf new file mode 100644 index 000000000..b8834e2ef --- /dev/null +++ b/addons/comments/functions/fnc_updateComment.sqf @@ -0,0 +1,30 @@ +#include "script_component.hpp" +/* + * Author: Timi007 + * Updates the comment. Must be called on server. + * + * Arguments: + * 0: Unique comment id + * 1: Comment position ASL + * 2: Comment title + * 3: Comment tooltip + * 4: Comment color (RGBA) + * 5: Name of the curator that created the comment + * + * Return Value: + * None + * + * Example: + * ["zeus:2"] call zen_comments_fnc_updateComment + * + * Public: No + */ + +params ["_id", "_posASL", "_title", ["_tooltip", "", [""]], ["_color", DEFAULT_COLOR, [[]], [4]], ["_creator", "", [""]]]; + +if (!isServer) exitWith {}; + +private _jipId = format [QGVAR(update_%1), _id]; + +TRACE_7("Update comment",_id,_posASL,_title,_tooltip,_color,_creator,_jipId); +[QGVAR(updateCommentLocal), [_id, _posASL, _title, _tooltip, _color, _creator], _jipId] call CBA_fnc_globalEventJIP; diff --git a/addons/comments/functions/fnc_updateCommentDialog.sqf b/addons/comments/functions/fnc_updateCommentDialog.sqf new file mode 100644 index 000000000..8546acb12 --- /dev/null +++ b/addons/comments/functions/fnc_updateCommentDialog.sqf @@ -0,0 +1,38 @@ +#include "script_component.hpp" +/* + * Author: Timi007 + * Opens the dialog for editing a comment. + * + * Arguments: + * 0: Unique comment id + * + * Return Value: + * None + * + * Example: + * ["zeus:2"] call zen_comments_fnc_updateCommentDialog + * + * Public: No + */ + +params ["_id"]; + +if !(_id in GVAR(comments)) exitWith {}; +(GVAR(comments) get _id) params ["_posASL", "_title", ["_tooltip", "", [""]], ["_color", DEFAULT_COLOR, [[]], [4]]]; + +[ + localize STR_CREATE_COMMENT, + [ + ["EDIT", localize "str_3den_comment_attribute_name_displayname", [_title], true], + ["EDIT:MULTI", localize "str_3den_comment_attribute_name_tooltip", [_tooltip], true], + ["COLOR", localize "str_3den_marker_attribute_color_displayname", _color, true] + ], + { + (_this select 0) params ["_title", "_tooltip", "_color"]; + (_this select 1) params ["_id", "_posASL"]; + + [QGVAR(updateComment), [_id, _posASL, _title, _tooltip, _color, profileName]] call CBA_fnc_serverEvent; + }, + {}, + [_id, _posASL] +] call EFUNC(dialog,create); diff --git a/addons/comments/functions/fnc_updateCommentLocal.sqf b/addons/comments/functions/fnc_updateCommentLocal.sqf new file mode 100644 index 000000000..813b9758c --- /dev/null +++ b/addons/comments/functions/fnc_updateCommentLocal.sqf @@ -0,0 +1,23 @@ +#include "script_component.hpp" +/* + * Author: Timi007 + * Updates the comment locally. + * + * Arguments: + * 0: Comment id + * + * Return Value: + * None + * + * Example: + * ["zeus:2"] call zen_comments_fnc_updateCommentLocal + * + * Public: No + */ + +params ["_id"]; + +GVAR(comments) set [_id, _this select [1]]; + +// Will update icon and provides hook +[QGVAR(commentUpdated), _this] call CBA_fnc_localEvent; diff --git a/addons/comments/functions/fnc_updateIcon.sqf b/addons/comments/functions/fnc_updateIcon.sqf new file mode 100644 index 000000000..c00b7d216 --- /dev/null +++ b/addons/comments/functions/fnc_updateIcon.sqf @@ -0,0 +1,23 @@ +#include "script_component.hpp" +/* + * Author: Timi007 + * Updates the icon control of comment. + * + * Arguments: + * 0: Comment id + * + * Return Value: + * None + * + * Example: + * ["zeus:2"] call zen_comments_fnc_updateIcon + * + * Public: No + */ + +params ["_id"]; + +private _ctrlIcon = GVAR(icons) getOrDefault [_id, controlNull]; +if (isNull _ctrlIcon) exitWith {}; + +_ctrlIcon ctrlSetTooltip _tooltip; diff --git a/addons/comments/initSettings.inc.sqf b/addons/comments/initSettings.inc.sqf index 21208e9d9..7c0e2e9b6 100644 --- a/addons/comments/initSettings.inc.sqf +++ b/addons/comments/initSettings.inc.sqf @@ -1,70 +1,51 @@ +private _category = [ELSTRING(main,DisplayName), localize "STR_3DEN_Comment_textPlural"]; + [ - QGVAR(enableComments), + QGVAR(enabled), "CHECKBOX", [LLSTRING(Comments), LLSTRING(Comments_Description)], - [ELSTRING(main,DisplayName), LLSTRING(DisplayName)], + _category, true, 0, { TRACE_1("Enable comments setting changed",_this); private _display = findDisplay IDD_RSCDISPLAYCURATOR; - if (!_this || GVAR(enable3DENComments) || isNull _display || GVAR(draw3DAdded)) exitWith {}; + if (!_this || GVAR(enabled3DEN) || isNull _display || GVAR(draw3DAdded)) exitWith {}; [_display] call FUNC(addDrawEventHandler); } ] call CBA_fnc_addSetting; [ - QGVAR(commentColor), - "COLOR", - [LLSTRING(CommentColor), LLSTRING(CommentColor_Description)], - [ELSTRING(main,DisplayName), LLSTRING(DisplayName)], - [1, 1, 0, 0.7], - 0, - { - TRACE_1("Comment color setting changed",_this); - params ["_r", "_g", "_b", "_a"]; - - GVAR(commentsActiveColor) = [_r, _g, _b, 1]; - } -] call CBA_fnc_addSetting; - -[ - QGVAR(enable3DENComments), + QGVAR(enabled3DEN), "CHECKBOX", [LLSTRING(3DENComments), LLSTRING(3DENComments_Description)], - [ELSTRING(main,DisplayName), LLSTRING(DisplayName)], + _category, true, 0, { TRACE_1("Enable 3DEN comments setting changed",_this); private _display = findDisplay IDD_RSCDISPLAYCURATOR; - if (!_this || GVAR(enableComments) || isNull _display || GVAR(draw3DAdded)) exitWith {}; + if (!_this || GVAR(enabled) || isNull _display || GVAR(draw3DAdded)) exitWith {}; [_display] call FUNC(addDrawEventHandler); } ] call CBA_fnc_addSetting; [ - QGVAR(3DENCommentColor), + QGVAR(3DENColor), "COLOR", [LLSTRING(3DENCommentColor), LLSTRING(3DENCommentColor_Description)], - [ELSTRING(main,DisplayName), LLSTRING(DisplayName)], + _category, [0, 1, 0.75, 0.7], - 0, - { - TRACE_1("3DEN comment color setting changed",_this); - params ["_r", "_g", "_b", "_a"]; - - GVAR(3DENCommentsActiveColor) = [_r, _g, _b, 1]; - } + 0 ] call CBA_fnc_addSetting; [ - QGVAR(allowDeleting3DENComments), + QGVAR(allowDeleting3DEN), "CHECKBOX", [LLSTRING(AllowDeleting3DENComments), LLSTRING(AllowDeleting3DENComments_Description)], - [ELSTRING(main,DisplayName), LLSTRING(DisplayName)], + _category, false, 0 ] call CBA_fnc_addSetting; diff --git a/addons/comments/script_component.hpp b/addons/comments/script_component.hpp index 03bcad3b9..c73540aab 100644 --- a/addons/comments/script_component.hpp +++ b/addons/comments/script_component.hpp @@ -16,6 +16,7 @@ #include "\x\zen\addons\main\script_macros.hpp" +#include "\a3\ui_f\hpp\defineDIKCodes.inc" #include "\a3\ui_f\hpp\defineCommonGrids.inc" #include "\x\zen\addons\common\defineResinclDesign.inc" @@ -44,3 +45,5 @@ #define COMMENT_TYPE_3DEN "3den" #define COMMENT_TYPE_ZEUS "zeus" + +#define DEFAULT_COLOR [1, 1, 0, 0.7] diff --git a/addons/comments/stringtable.xml b/addons/comments/stringtable.xml index b22b9e816..a256533d3 100644 --- a/addons/comments/stringtable.xml +++ b/addons/comments/stringtable.xml @@ -1,37 +1,13 @@ - - Comments - Poznámky - Kommentare - Комментарии - Komentarze - Commenti - Comentarios - Commentaires - 評論 - 댓글 - コメント - Comentários - 评论 - Yorumlar - - Show comments in Zeus - Zeige Kommentare im Zeus + Enable comments in Zeus + Aktiviere Kommentare im Zeus - Show comments created in Zeus. - Zeige im Zeus erstelle Kommentare. - - - Comment color - Farbe der Kommentare - - - Color of comments created in Zeus. - Farbe der im Zeus erstellen Kommentare. + Allow creating comments in Zeus. + Erlaube das Erstellen von Kommentaren im Zeus. Show 3DEN comments in Zeus From f346539821c6477214b0a0c8f3b91209bb2a35d2 Mon Sep 17 00:00:00 2001 From: Timi007 Date: Sat, 4 Jan 2025 16:32:05 +0100 Subject: [PATCH 14/23] Adapt to be more consistent with area_markers --- addons/comments/Cfg3DEN.hpp | 9 ++-- addons/comments/CfgContext.hpp | 2 +- addons/comments/XEH_PREP.hpp | 9 ++-- addons/comments/XEH_postInit.sqf | 18 ++----- addons/comments/XEH_preInit.sqf | 16 ++++-- .../functions/fnc_addDrawEventHandler.sqf | 2 +- .../comments/functions/fnc_createComment.sqf | 34 +++++++----- .../functions/fnc_createCommentDialog.sqf | 35 ------------ .../functions/fnc_createCommentLocal.sqf | 28 ---------- addons/comments/functions/fnc_createIcon.sqf | 13 ++--- .../comments/functions/fnc_deleteComment.sqf | 24 +++++---- .../functions/fnc_onCommentCreated.sqf | 23 ++++++++ ...mentLocal.sqf => fnc_onCommentDeleted.sqf} | 5 +- .../functions/fnc_onCommentUpdated.sqf | 23 ++++++++ addons/comments/functions/fnc_onKeyDown.sqf | 1 - .../functions/fnc_onMouseDblClick.sqf | 3 +- addons/comments/functions/fnc_openDialog.sqf | 53 +++++++++++++++++++ .../functions/fnc_save3DENComments.sqf | 19 +++---- .../comments/functions/fnc_updateComment.sqf | 32 ++++++----- .../functions/fnc_updateCommentDialog.sqf | 38 ------------- .../functions/fnc_updateCommentLocal.sqf | 23 -------- addons/comments/functions/fnc_updateIcon.sqf | 4 +- addons/comments/initSettings.inc.sqf | 2 +- addons/comments/script_component.hpp | 1 + 24 files changed, 202 insertions(+), 215 deletions(-) delete mode 100644 addons/comments/functions/fnc_createCommentDialog.sqf delete mode 100644 addons/comments/functions/fnc_createCommentLocal.sqf create mode 100644 addons/comments/functions/fnc_onCommentCreated.sqf rename addons/comments/functions/{fnc_deleteCommentLocal.sqf => fnc_onCommentDeleted.sqf} (61%) create mode 100644 addons/comments/functions/fnc_onCommentUpdated.sqf create mode 100644 addons/comments/functions/fnc_openDialog.sqf delete mode 100644 addons/comments/functions/fnc_updateCommentDialog.sqf delete mode 100644 addons/comments/functions/fnc_updateCommentLocal.sqf diff --git a/addons/comments/Cfg3DEN.hpp b/addons/comments/Cfg3DEN.hpp index 86d3d0fa4..39b0cfc6d 100644 --- a/addons/comments/Cfg3DEN.hpp +++ b/addons/comments/Cfg3DEN.hpp @@ -1,7 +1,7 @@ class Cfg3DEN { class Attributes { class Default; - class GVAR(HiddenAttribute): Default { + class GVAR(hiddenAttribute): Default { onLoad = QUOTE((ctrlParentControlsGroup ctrlParentControlsGroup (_this select 0)) ctrlShow false); }; }; @@ -10,15 +10,14 @@ class Cfg3DEN { class Scenario { class AttributeCategories { class ADDON { + displayName = STR_DISPLAY_NAME; collapsed = 1; - displayName = ECSTRING(main,DisplayName); class Attributes { class GVAR(3DENComments) { + displayName = STR_DISPLAY_NAME; property = QGVAR(3DENComments); - value = 0; - control = QGVAR(HiddenAttribute); - displayName = CSTRING(DisplayName); + control = QGVAR(hiddenAttribute); tooltip = ""; defaultValue = "[]"; expression = ""; diff --git a/addons/comments/CfgContext.hpp b/addons/comments/CfgContext.hpp index ca8c1ce08..549a5fa28 100644 --- a/addons/comments/CfgContext.hpp +++ b/addons/comments/CfgContext.hpp @@ -3,7 +3,7 @@ class EGVAR(context_menu,actions) { displayName = STR_CREATE_COMMENT; icon = COMMENT_ICON; condition = QGVAR(enabled); - statement = QUOTE([_position] call FUNC(createCommentDialog)); + statement = QUOTE([_position] call FUNC(openDialog)); priority = 35; }; }; diff --git a/addons/comments/XEH_PREP.hpp b/addons/comments/XEH_PREP.hpp index 50932e84d..b743ae04d 100644 --- a/addons/comments/XEH_PREP.hpp +++ b/addons/comments/XEH_PREP.hpp @@ -1,19 +1,18 @@ PREP(addDrawEventHandler); PREP(createComment); -PREP(createCommentDialog); -PREP(createCommentLocal); PREP(createIcon); PREP(deleteComment); -PREP(deleteCommentLocal); 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(updateCommentDialog); -PREP(updateCommentLocal); PREP(updateIcon); diff --git a/addons/comments/XEH_postInit.sqf b/addons/comments/XEH_postInit.sqf index 3dbca9440..553de5f96 100644 --- a/addons/comments/XEH_postInit.sqf +++ b/addons/comments/XEH_postInit.sqf @@ -1,26 +1,18 @@ #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; [QGVAR(updateComment), LINKFUNC(updateComment)] call CBA_fnc_addEventHandler; }; if (hasInterface) then { - [QGVAR(createCommentLocal), LINKFUNC(createCommentLocal)] call CBA_fnc_addEventHandler; - [QGVAR(deleteCommentLocal), LINKFUNC(deleteCommentLocal)] call CBA_fnc_addEventHandler; - [QGVAR(updateCommentLocal), LINKFUNC(updateCommentLocal)] call CBA_fnc_addEventHandler; + GVAR(comments) = createHashMapFromArray getMissionConfigValue [QGVAR(3DENComments), []]; + TRACE_1("Loaded 3DEN Comments from mission",GVAR(comments)); - [QGVAR(commentCreated), LINKFUNC(createIcon)] call CBA_fnc_addEventHandler; - [QGVAR(commentDeleted), LINKFUNC(deleteIcon)] call CBA_fnc_addEventHandler; - [QGVAR(commentUpdated), LINKFUNC(updateIcon)] call CBA_fnc_addEventHandler; + [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; - - GVAR(comments) = createHashMapFromArray getMissionConfigValue [QGVAR(3DENComments), []]; - - TRACE_1("Loaded 3DEN Comments from mission",GVAR(comments)); }; diff --git a/addons/comments/XEH_preInit.sqf b/addons/comments/XEH_preInit.sqf index 47b9818cb..1ba78bf16 100644 --- a/addons/comments/XEH_preInit.sqf +++ b/addons/comments/XEH_preInit.sqf @@ -6,9 +6,19 @@ PREP_RECOMPILE_START; #include "XEH_PREP.hpp" PREP_RECOMPILE_END; -GVAR(icons) = createHashMap; -GVAR(comments) = createHashMap; -GVAR(draw3DAdded) = false; +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" diff --git a/addons/comments/functions/fnc_addDrawEventHandler.sqf b/addons/comments/functions/fnc_addDrawEventHandler.sqf index e256d1894..ebfd3e7ab 100644 --- a/addons/comments/functions/fnc_addDrawEventHandler.sqf +++ b/addons/comments/functions/fnc_addDrawEventHandler.sqf @@ -22,7 +22,7 @@ TRACE_1("Zeus display opened",_display); if (!GVAR(enabled) && !GVAR(enabled3DEN)) exitWith {}; [{ - {([_x] + _y) call FUNC(createIcon)} forEach GVAR(comments); + {_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 { diff --git a/addons/comments/functions/fnc_createComment.sqf b/addons/comments/functions/fnc_createComment.sqf index 54e209940..47e6e3b99 100644 --- a/addons/comments/functions/fnc_createComment.sqf +++ b/addons/comments/functions/fnc_createComment.sqf @@ -1,34 +1,42 @@ #include "script_component.hpp" /* * Author: Timi007 - * Creates the comment. Must be called on server. + * Creates a new comment in Zeus. * * Arguments: - * 0: Comment position ASL - * 1: Comment title - * 2: Comment tooltip - * 3: Comment color (RGBA) - * 4: Name of the curator that created the comment + * 0: Position ASL + * 1: Title + * 2: Tooltip (default: "") + * 3: Comment color (RGBA) (default: yellow) + * 4: Creator (default: "") * * Return Value: * Id of the created comment . * * Example: - * [[0,0,0], "My Comment", "This is a nice comment", [1,0,0,0.7], "Joe"] call zen_comments_fnc_createComment + * [[0, 0, 0], "My Comment", "This is a nice comment", [1, 0, 0, 0.7], "Joe"] call zen_comments_fnc_createComment * * Public: No */ -params ["_posASL", "_title", ["_tooltip", "", [""]], ["_color", DEFAULT_COLOR, [[]], [4]], ["_creator", "", [""]]]; +if (!isServer) exitWith { + [QGVAR(createComment), _this] call CBA_fnc_serverEvent; +}; -if (!isServer) exitWith {}; +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 _id = format ["%1:%2", COMMENT_TYPE_ZEUS, GVAR(nextID)]; private _jipId = format [QGVAR(%1), _id]; - -TRACE_7("Create comment",_id,_posASL,_title,_tooltip,_color,_creator,_jipId); -[QGVAR(createCommentLocal), [_id, _posASL, _title, _tooltip, _color, _creator], _jipId] call CBA_fnc_globalEventJIP; +[QGVAR(commentCreated), [_id, _data], _jipId] call CBA_fnc_globalEventJIP; +TRACE_2("Comment created",_id,_data); _id diff --git a/addons/comments/functions/fnc_createCommentDialog.sqf b/addons/comments/functions/fnc_createCommentDialog.sqf deleted file mode 100644 index 6e0b65ec0..000000000 --- a/addons/comments/functions/fnc_createCommentDialog.sqf +++ /dev/null @@ -1,35 +0,0 @@ -#include "script_component.hpp" -/* - * Author: Timi007 - * Opens the dialog for creating a comment. - * - * Arguments: - * 0: Comment position ASL - * - * 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], - ["COLOR", localize "str_3den_marker_attribute_color_displayname", DEFAULT_COLOR] - ], - { - params ["_values", "_posASL"]; - _values params ["_title", "_tooltip", "_color"]; - - [QGVAR(createComment), [_posASL, _title, _tooltip, _color, profileName]] call CBA_fnc_serverEvent; - }, - {}, - _posASL -] call EFUNC(dialog,create); diff --git a/addons/comments/functions/fnc_createCommentLocal.sqf b/addons/comments/functions/fnc_createCommentLocal.sqf deleted file mode 100644 index d2ecde9c0..000000000 --- a/addons/comments/functions/fnc_createCommentLocal.sqf +++ /dev/null @@ -1,28 +0,0 @@ -#include "script_component.hpp" -/* - * Author: Timi007 - * Creates the comment locally. - * - * Arguments: - * 0: Unique comment id - * 1: Comment position ASL - * 2: Comment title - * 3: Comment tooltip - * 4: Comment color (RGBA) - * 5: Name of the curator that created the comment - * - * Return Value: - * None - * - * Example: - * ["zeus:1", [0,0,0], "My Comment", "This is a nice comment", [1,0,0,0.7], "Joe"] call zen_comments_fnc_createCommentLocal - * - * Public: No - */ - -params ["_id"]; - -GVAR(comments) set [_id, _this select [1]]; - -// Will create icon and provides hook -[QGVAR(commentCreated), _this] call CBA_fnc_localEvent; diff --git a/addons/comments/functions/fnc_createIcon.sqf b/addons/comments/functions/fnc_createIcon.sqf index 0422d79a2..fc83b7146 100644 --- a/addons/comments/functions/fnc_createIcon.sqf +++ b/addons/comments/functions/fnc_createIcon.sqf @@ -5,25 +5,22 @@ * * Arguments: * 0: Unique comment id - * 1: Comment position ASL - * 2: Comment title - * 3: Comment tooltip - * 4: Comment color (RGBA) - * 5: Name of the curator that created the comment * * Return Value: * Icon control for the comment . * * Example: - * ["zeus:1", [0,0,0], "My Comment", "This is a nice comment", [1,0,0,0.7], "Joe"] call zen_comments_fnc_createIcon + * ["zeus:0"] call zen_comments_fnc_createIcon * * Public: No */ -params ["_id", "", "", "_tooltip"]; +params ["_id"]; private _display = findDisplay IDD_RSCDISPLAYCURATOR; -if (isNull _display) exitWith {}; +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]; diff --git a/addons/comments/functions/fnc_deleteComment.sqf b/addons/comments/functions/fnc_deleteComment.sqf index ee896a693..60e493e9c 100644 --- a/addons/comments/functions/fnc_deleteComment.sqf +++ b/addons/comments/functions/fnc_deleteComment.sqf @@ -15,16 +15,20 @@ * Public: No */ -params ["_id"]; +if (!isServer) exitWith { + [QGVAR(deleteComment), _this] call CBA_fnc_serverEvent; +}; -if (!isServer) exitWith {}; +params ["_id"]; -TRACE_1("Delete comment",_id); -if (_id call FUNC(is3DENComment)) then { - [QGVAR(deleteCommentLocal), [_id]] call CBA_fnc_globalEventJIP; -} else { - private _jipId = format [QGVAR(%1), _id]; - [_jipId] call CBA_fnc_removeGlobalEventJIP; +// Remove the JIP ID for updated comments +private _jipIdUpdates = format [QGVAR(update_%1), _id]; +[_jipIdUpdates] call CBA_fnc_removeGlobalEventJIP; - [QGVAR(deleteCommentLocal), [_id]] call CBA_fnc_globalEvent; -}; +// 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); diff --git a/addons/comments/functions/fnc_onCommentCreated.sqf b/addons/comments/functions/fnc_onCommentCreated.sqf new file mode 100644 index 000000000..f2234428a --- /dev/null +++ b/addons/comments/functions/fnc_onCommentCreated.sqf @@ -0,0 +1,23 @@ +#include "script_component.hpp" +/* + * Author: Timi007 + * Creates the comment locally. + * + * Arguments: + * 0: Unique comment id + * 1: Comment data + * + * Return Value: + * None + * + * Example: + * ["zeus:1", [[0,0,0], "My Comment", "This is a nice comment", [1,0,0,0.7], "Joe"]] call zen_comments_fnc_onCommentCreated + * + * Public: No + */ + +params ["_id", "_data"]; + +GVAR(comments) set [_id, _data]; + +[_id, _data] call FUNC(createIcon); diff --git a/addons/comments/functions/fnc_deleteCommentLocal.sqf b/addons/comments/functions/fnc_onCommentDeleted.sqf similarity index 61% rename from addons/comments/functions/fnc_deleteCommentLocal.sqf rename to addons/comments/functions/fnc_onCommentDeleted.sqf index 256505bde..88bdae2d3 100644 --- a/addons/comments/functions/fnc_deleteCommentLocal.sqf +++ b/addons/comments/functions/fnc_onCommentDeleted.sqf @@ -10,7 +10,7 @@ * None * * Example: - * ["zeus:2"] call zen_comments_fnc_deleteCommentLocal + * ["zeus:2"] call zen_comments_fnc_onCommentDeleted * * Public: No */ @@ -19,5 +19,4 @@ params ["_id"]; GVAR(comments) deleteAt _id; -// Will delete icon and provides hook -[QGVAR(commentDeleted), [_id]] call CBA_fnc_localEvent; +[_id] call FUNC(deleteIcon); diff --git a/addons/comments/functions/fnc_onCommentUpdated.sqf b/addons/comments/functions/fnc_onCommentUpdated.sqf new file mode 100644 index 000000000..fa3fd8276 --- /dev/null +++ b/addons/comments/functions/fnc_onCommentUpdated.sqf @@ -0,0 +1,23 @@ +#include "script_component.hpp" +/* + * Author: Timi007 + * Updates the comment locally. + * + * Arguments: + * 0: Comment id + * 1: Comment data + * + * Return Value: + * None + * + * Example: + * ["zeus:2", [[0,0,0], "My edited Comment", "This is a nice comment", [1,0,0,0.7], "Joe"]] call zen_comments_fnc_onCommentUpdated + * + * Public: No + */ + +params ["_id", "_data"]; + +GVAR(comments) set [_id, _data]; + +[_id] call FUNC(updateIcon); diff --git a/addons/comments/functions/fnc_onKeyDown.sqf b/addons/comments/functions/fnc_onKeyDown.sqf index 1c1082d8a..4385699e4 100644 --- a/addons/comments/functions/fnc_onKeyDown.sqf +++ b/addons/comments/functions/fnc_onKeyDown.sqf @@ -17,7 +17,6 @@ */ params ["_ctrlIcon", "_key"]; -TRACE_1("params",_this); if (_key != DIK_DELETE) exitWith {}; diff --git a/addons/comments/functions/fnc_onMouseDblClick.sqf b/addons/comments/functions/fnc_onMouseDblClick.sqf index f04b1de54..0a5549625 100644 --- a/addons/comments/functions/fnc_onMouseDblClick.sqf +++ b/addons/comments/functions/fnc_onMouseDblClick.sqf @@ -17,7 +17,6 @@ */ params ["_ctrlIcon", "_button"]; -TRACE_1("params",_this); if (_button != 0) exitWith {}; @@ -26,4 +25,4 @@ if (_id isEqualTo "" || {_id call FUNC(is3DENComment)}) exitWith {}; TRACE_1("Edit comment",_id); -[_id] call FUNC(updateCommentDialog); +[_id] call FUNC(openDialog); diff --git a/addons/comments/functions/fnc_openDialog.sqf b/addons/comments/functions/fnc_openDialog.sqf new file mode 100644 index 000000000..665d58a06 --- /dev/null +++ b/addons/comments/functions/fnc_openDialog.sqf @@ -0,0 +1,53 @@ +#include "script_component.hpp" +/* + * Author: Timi007 + * Opens the dialog for creating a comment. + * + * Arguments: + * 0: Position ASL or Comment ID + * + * Return Value: + * None + * + * Example: + * [[0, 0, 0]] call zen_comments_fnc_openDialog + * ["zeus:0"] call zen_comments_fnc_openDialog + * + * Public: No + */ + +params ["_positionOrId"]; + +private _id = ["", _positionOrId] select (_positionOrId isEqualType ""); + +(GVAR(comments) getOrDefault [_id, []]) params [ + ["_position", [], [[]], 3], + ["_title", "", [""]], + ["_tooltip", "", [""]], + ["_color", DEFAULT_COLOR, [[]], 4] +]; + +if (_positionOrId isEqualType [] && _position isEqualTo []) then { + _position = _positionOrId; +}; + +[ + localize STR_CREATE_COMMENT, + [ + ["EDIT", localize "str_3den_comment_attribute_name_displayname", [_title], true], + ["EDIT:MULTI", localize "str_3den_comment_attribute_name_tooltip", [_tooltip], true], + ["COLOR", localize "str_3den_marker_attribute_color_displayname", _color, (_id isNotEqualTo "")] // Force only when editing comment + ], + { + (_this select 0) params ["_title", "_tooltip", "_color"]; + (_this select 1) params ["_id", "_position"]; + + if (_id isEqualTo "") then { + [QGVAR(createComment), [_position, _title, _tooltip, _color, profileName]] call CBA_fnc_serverEvent; + } else { + [QGVAR(updateComment), [_id, _position, _title, _tooltip, _color, profileName]] call CBA_fnc_serverEvent; + }; + }, + {}, + [_id, _position] +] call EFUNC(dialog,create); diff --git a/addons/comments/functions/fnc_save3DENComments.sqf b/addons/comments/functions/fnc_save3DENComments.sqf index 3fcb13bde..a3e1dd599 100644 --- a/addons/comments/functions/fnc_save3DENComments.sqf +++ b/addons/comments/functions/fnc_save3DENComments.sqf @@ -22,24 +22,19 @@ if (!is3DEN) exitWith {}; private _comments = []; { - private _id = _x; // all3DENEntities always includes this id, ignore it - if (_id isEqualTo -999) then { - continue; - }; + if (_x isEqualTo -999) then {continue}; // Ignore comments with special ignore directive in the description/tooltip - private _tooltip = (_id get3DENAttribute "description") select 0; - if (IGNORE_3DEN_COMMENT_STRING in _tooltip) then { - continue; - }; + private _tooltip = (_x get3DENAttribute "description") select 0; + if (IGNORE_3DEN_COMMENT_STRING in _tooltip) then {continue}; - private _posASL = (_id get3DENAttribute "position") select 0; - private _title = (_id get3DENAttribute "name") select 0; + private _position = (_x get3DENAttribute "position") select 0; + private _title = (_x get3DENAttribute "name") select 0; // Save in hashmap format with id as key - _comments pushBack [format ["%1:%2", COMMENT_TYPE_3DEN, _id], [_posASL, _title, _tooltip]]; -} forEach (all3DENEntities param [7, []]); + _comments pushBack [format ["%1:%2", COMMENT_TYPE_3DEN, _x], [_position, _title, _tooltip]]; +} forEach (all3DENEntities select 7); // This command does not work if the mission is not saved set3DENMissionAttributes [["Scenario", QGVAR(3DENComments), _comments]]; diff --git a/addons/comments/functions/fnc_updateComment.sqf b/addons/comments/functions/fnc_updateComment.sqf index b8834e2ef..bc2ff4c24 100644 --- a/addons/comments/functions/fnc_updateComment.sqf +++ b/addons/comments/functions/fnc_updateComment.sqf @@ -1,30 +1,38 @@ #include "script_component.hpp" /* * Author: Timi007 - * Updates the comment. Must be called on server. + * Updates the comment. * * Arguments: * 0: Unique comment id - * 1: Comment position ASL - * 2: Comment title - * 3: Comment tooltip - * 4: Comment color (RGBA) - * 5: Name of the curator that created the comment + * 1: Title + * 2: Tooltip + * 3: Comment color (RGBA) + * 4: Creator * * Return Value: * None * * Example: - * ["zeus:2"] call zen_comments_fnc_updateComment + * ["zeus:2", "My updated Comment", "This is a nice comment", [1, 0, 0, 0.7], "Joe"] call zen_comments_fnc_updateComment * * Public: No */ -params ["_id", "_posASL", "_title", ["_tooltip", "", [""]], ["_color", DEFAULT_COLOR, [[]], [4]], ["_creator", "", [""]]]; +if (!isServer) exitWith { + [QGVAR(updateComment), _this] call CBA_fnc_serverEvent; +}; -if (!isServer) exitWith {}; +params [ + ["_id", "", [""]], + ["_position", [0, 0, 0], [[]], 3], + ["_title", "", [""]], + ["_tooltip", "", [""]], + ["_color", DEFAULT_COLOR, [[]], 4], + ["_creator", "", [""]] +]; private _jipId = format [QGVAR(update_%1), _id]; - -TRACE_7("Update comment",_id,_posASL,_title,_tooltip,_color,_creator,_jipId); -[QGVAR(updateCommentLocal), [_id, _posASL, _title, _tooltip, _color, _creator], _jipId] call CBA_fnc_globalEventJIP; +private _data = [_position, _title, _tooltip, _color, _creator]; +[QGVAR(commentUpdated), [_id, _data], _jipId] call CBA_fnc_globalEventJIP; +TRACE_2("Comment updated",_id,_data); diff --git a/addons/comments/functions/fnc_updateCommentDialog.sqf b/addons/comments/functions/fnc_updateCommentDialog.sqf deleted file mode 100644 index 8546acb12..000000000 --- a/addons/comments/functions/fnc_updateCommentDialog.sqf +++ /dev/null @@ -1,38 +0,0 @@ -#include "script_component.hpp" -/* - * Author: Timi007 - * Opens the dialog for editing a comment. - * - * Arguments: - * 0: Unique comment id - * - * Return Value: - * None - * - * Example: - * ["zeus:2"] call zen_comments_fnc_updateCommentDialog - * - * Public: No - */ - -params ["_id"]; - -if !(_id in GVAR(comments)) exitWith {}; -(GVAR(comments) get _id) params ["_posASL", "_title", ["_tooltip", "", [""]], ["_color", DEFAULT_COLOR, [[]], [4]]]; - -[ - localize STR_CREATE_COMMENT, - [ - ["EDIT", localize "str_3den_comment_attribute_name_displayname", [_title], true], - ["EDIT:MULTI", localize "str_3den_comment_attribute_name_tooltip", [_tooltip], true], - ["COLOR", localize "str_3den_marker_attribute_color_displayname", _color, true] - ], - { - (_this select 0) params ["_title", "_tooltip", "_color"]; - (_this select 1) params ["_id", "_posASL"]; - - [QGVAR(updateComment), [_id, _posASL, _title, _tooltip, _color, profileName]] call CBA_fnc_serverEvent; - }, - {}, - [_id, _posASL] -] call EFUNC(dialog,create); diff --git a/addons/comments/functions/fnc_updateCommentLocal.sqf b/addons/comments/functions/fnc_updateCommentLocal.sqf deleted file mode 100644 index 813b9758c..000000000 --- a/addons/comments/functions/fnc_updateCommentLocal.sqf +++ /dev/null @@ -1,23 +0,0 @@ -#include "script_component.hpp" -/* - * Author: Timi007 - * Updates the comment locally. - * - * Arguments: - * 0: Comment id - * - * Return Value: - * None - * - * Example: - * ["zeus:2"] call zen_comments_fnc_updateCommentLocal - * - * Public: No - */ - -params ["_id"]; - -GVAR(comments) set [_id, _this select [1]]; - -// Will update icon and provides hook -[QGVAR(commentUpdated), _this] call CBA_fnc_localEvent; diff --git a/addons/comments/functions/fnc_updateIcon.sqf b/addons/comments/functions/fnc_updateIcon.sqf index c00b7d216..3c987c3c3 100644 --- a/addons/comments/functions/fnc_updateIcon.sqf +++ b/addons/comments/functions/fnc_updateIcon.sqf @@ -18,6 +18,8 @@ params ["_id"]; private _ctrlIcon = GVAR(icons) getOrDefault [_id, controlNull]; -if (isNull _ctrlIcon) exitWith {}; +if (isNull _ctrlIcon || !(_id in GVAR(comments))) exitWith {}; + +(GVAR(comments) get _id) params ["", "", ["_tooltip", ""]]; _ctrlIcon ctrlSetTooltip _tooltip; diff --git a/addons/comments/initSettings.inc.sqf b/addons/comments/initSettings.inc.sqf index 7c0e2e9b6..ab10ab2c0 100644 --- a/addons/comments/initSettings.inc.sqf +++ b/addons/comments/initSettings.inc.sqf @@ -1,4 +1,4 @@ -private _category = [ELSTRING(main,DisplayName), localize "STR_3DEN_Comment_textPlural"]; +private _category = [ELSTRING(main,DisplayName), localize STR_DISPLAY_NAME]; [ QGVAR(enabled), diff --git a/addons/comments/script_component.hpp b/addons/comments/script_component.hpp index c73540aab..bec999b17 100644 --- a/addons/comments/script_component.hpp +++ b/addons/comments/script_component.hpp @@ -41,6 +41,7 @@ #define GROUND_ICON_CONNECTION_HEIGHT 0.5 +#define STR_DISPLAY_NAME "$STR_3DEN_Comment_textPlural" #define STR_CREATE_COMMENT "$STR_3den_display3den_entitymenu_createcomment_text" #define COMMENT_TYPE_3DEN "3den" From e5bcece03d33344d669c739f7246ada7a3c6548c Mon Sep 17 00:00:00 2001 From: Timi007 Date: Sat, 4 Jan 2025 18:25:32 +0100 Subject: [PATCH 15/23] Add 3DEN checkbox attribute for ignoring comments --- addons/comments/Cfg3DEN.hpp | 21 +++++++++++++++++++ .../functions/fnc_save3DENComments.sqf | 9 ++++---- addons/comments/script_component.hpp | 3 --- addons/comments/stringtable.xml | 8 +++++++ 4 files changed, 34 insertions(+), 7 deletions(-) diff --git a/addons/comments/Cfg3DEN.hpp b/addons/comments/Cfg3DEN.hpp index 39b0cfc6d..f1e7d2a3b 100644 --- a/addons/comments/Cfg3DEN.hpp +++ b/addons/comments/Cfg3DEN.hpp @@ -37,4 +37,25 @@ class Cfg3DEN { onBeforeMissionPreview = QUOTE(['onBeforeMissionPreview'] call FUNC(save3DENComments)); }; }; + + class Comment { + class AttributeCategories { + class ADDON { + displayName = ECSTRING(main,DisplayName); + collapsed = 0; + + class Attributes { + class GVAR(showComment) { + displayName = CSTRING(ShowCommentInZeus); + tooltip = CSTRING(ShowCommentInZeus_Description); + property = QGVAR(showComment); + control = "CheckboxState"; + defaultValue = "true"; + expression = ""; + wikiType = "[[Bool]]"; + }; + }; + }; + }; + }; }; diff --git a/addons/comments/functions/fnc_save3DENComments.sqf b/addons/comments/functions/fnc_save3DENComments.sqf index a3e1dd599..b21242d0e 100644 --- a/addons/comments/functions/fnc_save3DENComments.sqf +++ b/addons/comments/functions/fnc_save3DENComments.sqf @@ -25,15 +25,16 @@ private _comments = []; // all3DENEntities always includes this id, ignore it if (_x isEqualTo -999) then {continue}; - // Ignore comments with special ignore directive in the description/tooltip - private _tooltip = (_x get3DENAttribute "description") select 0; - if (IGNORE_3DEN_COMMENT_STRING in _tooltip) then {continue}; + private _show = (_x get3DENAttribute QGVAR(showComment)) select 0; + if (!_show) then {continue}; + private _id = format ["%1:%2", COMMENT_TYPE_3DEN, _x]; private _position = (_x get3DENAttribute "position") select 0; private _title = (_x get3DENAttribute "name") select 0; + private _tooltip = (_x get3DENAttribute "description") select 0; // Save in hashmap format with id as key - _comments pushBack [format ["%1:%2", COMMENT_TYPE_3DEN, _x], [_position, _title, _tooltip]]; + _comments pushBack [_id, [_position, _title, _tooltip]]; } forEach (all3DENEntities select 7); // This command does not work if the mission is not saved diff --git a/addons/comments/script_component.hpp b/addons/comments/script_component.hpp index bec999b17..23c9d181c 100644 --- a/addons/comments/script_component.hpp +++ b/addons/comments/script_component.hpp @@ -25,9 +25,6 @@ #define POS_W(N) ((N) * GUI_GRID_W) #define POS_H(N) ((N) * GUI_GRID_H) -// Ignore comments that include following string in the description/tooltip -#define IGNORE_3DEN_COMMENT_STRING "#ZEN_IGNORE#" - #define COMMENT_ICON "a3\3den\Data\Cfg3DEN\Comment\texture_ca.paa" #define ICON_SCALE 1 #define MAP_ICON_SCALE 1.2 diff --git a/addons/comments/stringtable.xml b/addons/comments/stringtable.xml index a256533d3..dc46a3d2c 100644 --- a/addons/comments/stringtable.xml +++ b/addons/comments/stringtable.xml @@ -33,5 +33,13 @@ Allow any Zeus to delete 3DEN comments. Erlaube jedem Zeus das Löschen von 3DEN-Kommentaren. + + Show comment in Zeus + Zeige Kommentar in Zeus + + + If selected, this comment will be shown in Zeus. + Wenn ausgewählt, wird dieser Kommentar in Zeus angezeigt. + From 6359e65f2d0a22675a80b12e936b0852641391e8 Mon Sep 17 00:00:00 2001 From: Timi007 Date: Mon, 6 Jan 2025 23:37:54 +0100 Subject: [PATCH 16/23] Use LINKFUNC --- addons/comments/functions/fnc_addDrawEventHandler.sqf | 4 ++-- addons/comments/functions/fnc_createIcon.sqf | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/addons/comments/functions/fnc_addDrawEventHandler.sqf b/addons/comments/functions/fnc_addDrawEventHandler.sqf index ebfd3e7ab..a94c42cd6 100644 --- a/addons/comments/functions/fnc_addDrawEventHandler.sqf +++ b/addons/comments/functions/fnc_addDrawEventHandler.sqf @@ -27,11 +27,11 @@ if (!GVAR(enabled) && !GVAR(enabled3DEN)) exitWith {}; if (!GVAR(draw3DAdded)) then { LOG("Adding Draw3D."); - addMissionEventHandler ["Draw3D", FUNC(onDraw3D)]; + addMissionEventHandler ["Draw3D", LINKFUNC(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)]; +_ctrlMap ctrlAddEventHandler ["Draw", LINKFUNC(onDraw)]; diff --git a/addons/comments/functions/fnc_createIcon.sqf b/addons/comments/functions/fnc_createIcon.sqf index fc83b7146..e6d87dfbe 100644 --- a/addons/comments/functions/fnc_createIcon.sqf +++ b/addons/comments/functions/fnc_createIcon.sqf @@ -26,8 +26,8 @@ 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)]; +_ctrlIcon ctrlAddEventHandler ["KeyDown", LINKFUNC(onKeyDown)]; +_ctrlIcon ctrlAddEventHandler ["MouseButtonDblClick", LINKFUNC(onMouseDblClick)]; GVAR(icons) set [_id, _ctrlIcon]; From 2fa657aa55ca4eebe644dea138bfeb16fb0d0123 Mon Sep 17 00:00:00 2001 From: Timi007 Date: Mon, 6 Jan 2025 23:38:03 +0100 Subject: [PATCH 17/23] Fix obsolete param --- addons/comments/functions/fnc_onCommentCreated.sqf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/comments/functions/fnc_onCommentCreated.sqf b/addons/comments/functions/fnc_onCommentCreated.sqf index f2234428a..47b6eb73a 100644 --- a/addons/comments/functions/fnc_onCommentCreated.sqf +++ b/addons/comments/functions/fnc_onCommentCreated.sqf @@ -20,4 +20,4 @@ params ["_id", "_data"]; GVAR(comments) set [_id, _data]; -[_id, _data] call FUNC(createIcon); +[_id] call FUNC(createIcon); From dbd3231bec22573d9dc776410ce6100171606419 Mon Sep 17 00:00:00 2001 From: Timi007 Date: Fri, 10 Jan 2025 00:53:40 +0100 Subject: [PATCH 18/23] Add ability to move comment --- addons/comments/XEH_PREP.hpp | 5 +++ addons/comments/XEH_postInit.sqf | 1 + addons/comments/XEH_preInit.sqf | 2 ++ addons/comments/functions/fnc_createIcon.sqf | 3 -- addons/comments/functions/fnc_moveComment.sqf | 34 +++++++++++++++++++ .../functions/fnc_onMouseButtonDown.sqf | 29 ++++++++++++++++ .../functions/fnc_onMouseButtonUp.sqf | 29 ++++++++++++++++ .../comments/functions/fnc_onMouseMoving.sqf | 26 ++++++++++++++ addons/comments/functions/fnc_onUnload.sqf | 24 +++++++++++++ .../comments/functions/fnc_updateComment.sqf | 9 ++--- addons/comments/gui.hpp | 12 +++++++ 11 files changed, 167 insertions(+), 7 deletions(-) create mode 100644 addons/comments/functions/fnc_moveComment.sqf create mode 100644 addons/comments/functions/fnc_onMouseButtonDown.sqf create mode 100644 addons/comments/functions/fnc_onMouseButtonUp.sqf create mode 100644 addons/comments/functions/fnc_onMouseMoving.sqf create mode 100644 addons/comments/functions/fnc_onUnload.sqf diff --git a/addons/comments/XEH_PREP.hpp b/addons/comments/XEH_PREP.hpp index b743ae04d..249276105 100644 --- a/addons/comments/XEH_PREP.hpp +++ b/addons/comments/XEH_PREP.hpp @@ -5,13 +5,18 @@ PREP(deleteComment); PREP(deleteIcon); PREP(drawComments); PREP(is3DENComment); +PREP(moveComment); PREP(onCommentCreated); PREP(onCommentDeleted); PREP(onCommentUpdated); PREP(onDraw); PREP(onDraw3D); PREP(onKeyDown); +PREP(onMouseButtonDown); +PREP(onMouseButtonUp); PREP(onMouseDblClick); +PREP(onMouseMoving); +PREP(onUnload); PREP(openDialog); PREP(save3DENComments); PREP(updateComment); diff --git a/addons/comments/XEH_postInit.sqf b/addons/comments/XEH_postInit.sqf index 553de5f96..e02720728 100644 --- a/addons/comments/XEH_postInit.sqf +++ b/addons/comments/XEH_postInit.sqf @@ -15,4 +15,5 @@ if (hasInterface) then { [QGVAR(commentUpdated), LINKFUNC(onCommentUpdated)] call CBA_fnc_addEventHandler; ["zen_curatorDisplayLoaded", LINKFUNC(addDrawEventHandler)] call CBA_fnc_addEventHandler; + ["zen_curatorDisplayUnloaded", LINKFUNC(onUnload)] call CBA_fnc_addEventHandler; }; diff --git a/addons/comments/XEH_preInit.sqf b/addons/comments/XEH_preInit.sqf index 1ba78bf16..b4eb1efd5 100644 --- a/addons/comments/XEH_preInit.sqf +++ b/addons/comments/XEH_preInit.sqf @@ -18,6 +18,8 @@ if (hasInterface) then { GVAR(icons) = createHashMap; GVAR(draw3DAdded) = false; + + GVAR(movingComment) = []; }; #include "initSettings.inc.sqf" diff --git a/addons/comments/functions/fnc_createIcon.sqf b/addons/comments/functions/fnc_createIcon.sqf index e6d87dfbe..993ed816d 100644 --- a/addons/comments/functions/fnc_createIcon.sqf +++ b/addons/comments/functions/fnc_createIcon.sqf @@ -26,9 +26,6 @@ private _ctrlIcon = _display ctrlCreate [QGVAR(RscActiveCommentIcon), -1]; _ctrlIcon setVariable [QGVAR(comment), _id]; _ctrlIcon ctrlSetTooltip _tooltip; -_ctrlIcon ctrlAddEventHandler ["KeyDown", LINKFUNC(onKeyDown)]; -_ctrlIcon ctrlAddEventHandler ["MouseButtonDblClick", LINKFUNC(onMouseDblClick)]; - GVAR(icons) set [_id, _ctrlIcon]; _ctrlIcon diff --git a/addons/comments/functions/fnc_moveComment.sqf b/addons/comments/functions/fnc_moveComment.sqf new file mode 100644 index 000000000..82c4d7ab7 --- /dev/null +++ b/addons/comments/functions/fnc_moveComment.sqf @@ -0,0 +1,34 @@ +#include "script_component.hpp" +/* + * Author: Timi007 + * Move a comment. + * + * Arguments: + * 0: Icon control + * 1: New position ASL + * 2: Move only locally (default: false) + * + * Return Value: + * None + * + * Example: + * ["zeus:0", [0, 0, 0], true] call zen_comments_fnc_moveComment + * + * Public: No + */ + +params [ + ["_id", "", [""]], + ["_position", [0, 0, 0], [[]], 3], + ["_local", false, [false]] +]; + +private _data = GVAR(comments) getOrDefault [_id, []]; +if (_data isEqualTo []) exitWith {}; +_data set [0, _position]; + +if (_local) then { + [QGVAR(commentUpdated), [_id, _data]] call CBA_fnc_localEvent; +} else { + [QGVAR(updateComment), [_id] + _data] call CBA_fnc_serverEvent; +}; diff --git a/addons/comments/functions/fnc_onMouseButtonDown.sqf b/addons/comments/functions/fnc_onMouseButtonDown.sqf new file mode 100644 index 000000000..3725f929b --- /dev/null +++ b/addons/comments/functions/fnc_onMouseButtonDown.sqf @@ -0,0 +1,29 @@ +#include "script_component.hpp" +/* + * Author: Timi007 + * Handles the mouse button down event for start moving a comment. + * + * Arguments: + * 0: Icon control + * 1: Button pressed + * + * Return Value: + * None + * + * Example: + * _this call zen_comments_fnc_onMouseButtonDown + * + * Public: No + */ + +params ["_ctrlIcon", "_button"]; + +if (_button != 0) exitWith {}; + +private _id = _ctrlIcon getVariable [QGVAR(comment), ""]; +if (_id isEqualTo "") exitWith {ERROR("Moving invalid comment.")}; + +if (_id call FUNC(is3DENComment)) exitWith {}; + +(GVAR(comments) get _id) params ["_position"]; +GVAR(movingComment) = [_id, +_position]; diff --git a/addons/comments/functions/fnc_onMouseButtonUp.sqf b/addons/comments/functions/fnc_onMouseButtonUp.sqf new file mode 100644 index 000000000..9ba969900 --- /dev/null +++ b/addons/comments/functions/fnc_onMouseButtonUp.sqf @@ -0,0 +1,29 @@ +#include "script_component.hpp" +/* + * Author: Timi007 + * Handles the mouse button down event for stop moving a comment. + * + * Arguments: + * 0: Icon control + * 1: Button pressed + * + * Return Value: + * None + * + * Example: + * _this call zen_comments_fnc_onMouseButtonUp + * + * Public: No + */ + +params ["_ctrlIcon", "_button"]; + +if (_button != 0 || GVAR(movingComment) isEqualTo []) exitWith {}; + +private _id = _ctrlIcon getVariable [QGVAR(comment), ""]; +if (_id isEqualTo "") exitWith {ERROR("Moving invalid comment.")}; + +private _position = [] call EFUNC(common,getPosFromScreen); +[_id, _position] call FUNC(moveComment); + +GVAR(movingComment) = []; diff --git a/addons/comments/functions/fnc_onMouseMoving.sqf b/addons/comments/functions/fnc_onMouseMoving.sqf new file mode 100644 index 000000000..03715e731 --- /dev/null +++ b/addons/comments/functions/fnc_onMouseMoving.sqf @@ -0,0 +1,26 @@ +#include "script_component.hpp" +/* + * Author: Timi007 + * Handles the mouse moving event for moving a comment. + * + * Arguments: + * 0: Icon control + * + * Return Value: + * None + * + * Example: + * _this call zen_comments_fnc_onMouseMoving + * + * Public: No + */ + +params ["_ctrlIcon"]; + +if (GVAR(movingComment) isEqualTo []) exitWith {}; + +private _id = _ctrlIcon getVariable [QGVAR(comment), ""]; +if (_id isEqualTo "") exitWith {ERROR("Moving invalid comment.")}; + +private _position = [] call EFUNC(common,getPosFromScreen); +[_id, _position, true] call FUNC(moveComment); diff --git a/addons/comments/functions/fnc_onUnload.sqf b/addons/comments/functions/fnc_onUnload.sqf new file mode 100644 index 000000000..5a3ec5d07 --- /dev/null +++ b/addons/comments/functions/fnc_onUnload.sqf @@ -0,0 +1,24 @@ +#include "script_component.hpp" +/* + * Author: Timi007 + * Handles unloading the Zeus Display. + * + * Arguments: + * 0: Display + * + * Return Value: + * None + * + * Example: + * [DISPLAY] call zen_comments_fnc_onUnload + * + * Public: No + */ + + +if (GVAR(movingComment) isNotEqualTo []) then { + // Zeus displayed closed before moving stopped + // Reset comment back to original position + GVAR(movingComment) call FUNC(moveComment); + GVAR(movingComment) = []; +}; diff --git a/addons/comments/functions/fnc_updateComment.sqf b/addons/comments/functions/fnc_updateComment.sqf index bc2ff4c24..de8fec391 100644 --- a/addons/comments/functions/fnc_updateComment.sqf +++ b/addons/comments/functions/fnc_updateComment.sqf @@ -5,16 +5,17 @@ * * Arguments: * 0: Unique comment id - * 1: Title - * 2: Tooltip - * 3: Comment color (RGBA) + * 1: Position ASL + * 2: Title + * 3: Tooltip + * 4: Comment color (RGBA) * 4: Creator * * Return Value: * None * * Example: - * ["zeus:2", "My updated Comment", "This is a nice comment", [1, 0, 0, 0.7], "Joe"] call zen_comments_fnc_updateComment + * ["zeus:2", [0, 0, 0], "My updated Comment", "This is a nice comment", [1, 0, 0, 0.7], "Joe"] call zen_comments_fnc_updateComment * * Public: No */ diff --git a/addons/comments/gui.hpp b/addons/comments/gui.hpp index 36039e657..b2a404dda 100644 --- a/addons/comments/gui.hpp +++ b/addons/comments/gui.hpp @@ -2,6 +2,18 @@ class RscActivePicture; class GVAR(RscActiveCommentIcon): RscActivePicture { onMouseEnter = QUOTE((_this select 0) setVariable [ARR_2(QQGVAR(isActive),true)]; ctrlSetFocus (_this select 0)); // Set focus for KeyDown to register onMouseExit = QUOTE((_this select 0) setVariable [ARR_2(QQGVAR(isActive),false)]); + + // For deleting comments + onKeyDown = QUOTE(call FUNC(onKeyDown)); + + // For editing comments + onMouseButtonDblClick = QUOTE(call FUNC(onMouseDblClick)); + + // For moving comments + onMouseButtonDown = QUOTE(call FUNC(onMouseButtonDown)); + onMouseButtonUp = QUOTE(call FUNC(onMouseButtonUp)); + onMouseMoving = QUOTE(call FUNC(onMouseMoving)); + shadow = 1; text = COMMENT_ICON; tooltipMaxWidth = QUOTE(POS_W(15)); From b3e916a00fbec2f5017fcaa7de34042a002a3042 Mon Sep 17 00:00:00 2001 From: Timi007 Date: Fri, 10 Jan 2025 18:43:47 +0100 Subject: [PATCH 19/23] Cleanup --- addons/comments/functions/fnc_addDrawEventHandler.sqf | 4 ++-- addons/comments/functions/fnc_deleteComment.sqf | 2 +- addons/comments/functions/fnc_drawComments.sqf | 8 ++++---- addons/comments/functions/fnc_onDraw.sqf | 5 ++--- addons/comments/functions/fnc_onUnload.sqf | 1 - 5 files changed, 9 insertions(+), 11 deletions(-) diff --git a/addons/comments/functions/fnc_addDrawEventHandler.sqf b/addons/comments/functions/fnc_addDrawEventHandler.sqf index a94c42cd6..5c8eb0651 100644 --- a/addons/comments/functions/fnc_addDrawEventHandler.sqf +++ b/addons/comments/functions/fnc_addDrawEventHandler.sqf @@ -27,11 +27,11 @@ if (!GVAR(enabled) && !GVAR(enabled3DEN)) exitWith {}; if (!GVAR(draw3DAdded)) then { LOG("Adding Draw3D."); - addMissionEventHandler ["Draw3D", LINKFUNC(onDraw3D)]; + 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", LINKFUNC(onDraw)]; +_ctrlMap ctrlAddEventHandler ["Draw", {call FUNC(onDraw)}]; diff --git a/addons/comments/functions/fnc_deleteComment.sqf b/addons/comments/functions/fnc_deleteComment.sqf index 60e493e9c..85902b27d 100644 --- a/addons/comments/functions/fnc_deleteComment.sqf +++ b/addons/comments/functions/fnc_deleteComment.sqf @@ -1,7 +1,7 @@ #include "script_component.hpp" /* * Author: Timi007 - * Deletes the comment. Must be called on server. + * Deletes the comment. * * Arguments: * 0: Comment id diff --git a/addons/comments/functions/fnc_drawComments.sqf b/addons/comments/functions/fnc_drawComments.sqf index 75129c814..3fd0c6eeb 100644 --- a/addons/comments/functions/fnc_drawComments.sqf +++ b/addons/comments/functions/fnc_drawComments.sqf @@ -128,10 +128,10 @@ private _screenPos = []; }; } else { // Draw comment name on map - private _text = if (_creator isEqualTo "") then { - _title - } else { - format ["%1: %2", _creator, _title]; + private _text = switch (true) do { + case (_creator isEqualTo ""): {_title}; // Case for 3DEN comment + case (_title isEqualTo ""): {_creator}; // Case for Zeus comment without title + default {format ["%1: %2", _creator, _title]}; // Case for Zeus comment with title }; _mapCtrl drawIcon [ diff --git a/addons/comments/functions/fnc_onDraw.sqf b/addons/comments/functions/fnc_onDraw.sqf index 84de0b0c2..49fb3912a 100644 --- a/addons/comments/functions/fnc_onDraw.sqf +++ b/addons/comments/functions/fnc_onDraw.sqf @@ -1,7 +1,7 @@ #include "script_component.hpp" /* * Author: Timi007 - * Handles drawing the comments on the Zeus map. + * Handles drawing the comments on the Zeus map. Is only called when map is open. * * Arguments: * 0: Zeus map @@ -24,8 +24,7 @@ if (!GVAR(enabled) && !GVAR(enabled3DEN)) exitWith { LOG("Removed 3DENComments map draw."); }; -// Draw is only called when map is open -if (call EFUNC(common,isInScreenshotMode)) exitWith {}; // HUD is hidden +if (dialog || {call EFUNC(common,isInScreenshotMode)}) exitWith {}; // Dialog is open or HUD is hidden [GVAR(comments), GVAR(icons), GVAR(enabled), GVAR(enabled3DEN), _mapCtrl] call FUNC(drawComments); diff --git a/addons/comments/functions/fnc_onUnload.sqf b/addons/comments/functions/fnc_onUnload.sqf index 5a3ec5d07..b00fc8de9 100644 --- a/addons/comments/functions/fnc_onUnload.sqf +++ b/addons/comments/functions/fnc_onUnload.sqf @@ -15,7 +15,6 @@ * Public: No */ - if (GVAR(movingComment) isNotEqualTo []) then { // Zeus displayed closed before moving stopped // Reset comment back to original position From f44d79c4b810d21100aa13e14f1f87c0550cec85 Mon Sep 17 00:00:00 2001 From: Timi007 Date: Fri, 10 Jan 2025 18:44:29 +0100 Subject: [PATCH 20/23] Add documentation --- docs/_sidebar.md | 1 + docs/home.md | 1 + docs/user_guide/comments.md | 29 +++++++++++++++++++++++++++++ docs/user_guide/context_actions.md | 4 ++++ 4 files changed, 35 insertions(+) create mode 100644 docs/user_guide/comments.md diff --git a/docs/_sidebar.md b/docs/_sidebar.md index 1529f158f..a0e01c0a4 100644 --- a/docs/_sidebar.md +++ b/docs/_sidebar.md @@ -6,6 +6,7 @@ - [ Compositions](/user_guide/compositions.md) - [ Vehicle Garage](/user_guide/garage.md) - [ Area Markers](/user_guide/area_markers.md) + - [ Comments](/user_guide/comments.md) - **Frameworks** - [ Context Menu](/frameworks/context_menu.md) - [ Custom Modules](/frameworks/custom_modules.md) diff --git a/docs/home.md b/docs/home.md index 3704ecdb7..88c35785c 100644 --- a/docs/home.md +++ b/docs/home.md @@ -26,3 +26,4 @@ Special thanks to the [ACE3 Team](http://ace3mod.com/team.html) for their open s - Settings to control Zeus camera properties such as speed and available vision modes. - Zeus camera flashlight for easier editing at night. - New waypoint types such as paradrop available through Zeus. +- Ability to place comments and see comments created in 3DEN. diff --git a/docs/user_guide/comments.md b/docs/user_guide/comments.md new file mode 100644 index 000000000..73332680d --- /dev/null +++ b/docs/user_guide/comments.md @@ -0,0 +1,29 @@ +# Comments + +Zeus Enhanced adds the ability to create and edit comments through Zeus. +In addition, comments created in 3DEN are imported into Zeus. + +### Creating + +Comments can be created by using the context menu action. +The context menu action is only shown when comments are enabled in the CBA settings. + +### Editing + +The properties of comments can be changed by double clicking on the icon of the comment. +This will open a menu which allows you to configure the comment's title, tooltip, and color. + +Comments can be moved by left clicking an dragging on the icon. +Comments created in 3DEN cannot be moved. + +### Deleting + +Comments can be deleted by hovering over the icon and pressing the DELETE key. +By default, comments created in 3DEN cannot be deleted. This can be changed in the CBA settings. + +## 3DEN Comments {docsify-ignore} + +All comments created in 3DEN will be imported into Zeus by default. +A comment can be excluded by unchecking the "Show comment in Zeus" option when creating/editing a comment in 3DEN. + +!> The mission must be saved, otherwise 3DEN comments will not be shown in Zeus! diff --git a/docs/user_guide/context_actions.md b/docs/user_guide/context_actions.md index 803ad90b1..0d7184882 100644 --- a/docs/user_guide/context_actions.md +++ b/docs/user_guide/context_actions.md @@ -60,6 +60,10 @@ Sub-actions allow for copying and pasting the hovered unit's loadout onto anothe Furthermore, the unit's current weapon can be switched between their rifle, handgun, or binoculars. The main action acts as a shortcut for the "Edit" sub-action. +## Place Comment + +Creates a [comment](/user_guide/comments.md) at the context menu's position. + ## Remote Control Starts the remote control process on the hovered unit or vehicle. From bdbc943dc5743c7056534519a31348ef6081aa51 Mon Sep 17 00:00:00 2001 From: Timi007 Date: Fri, 10 Jan 2025 18:48:14 +0100 Subject: [PATCH 21/23] Remove module dependency --- addons/comments/config.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/addons/comments/config.cpp b/addons/comments/config.cpp index 140da3c2a..38efcae04 100644 --- a/addons/comments/config.cpp +++ b/addons/comments/config.cpp @@ -3,12 +3,10 @@ class CfgPatches { class ADDON { name = COMPONENT_NAME; - units[] = { - QGVAR(module) - }; + units[] = {}; weapons[] = {}; requiredVersion = REQUIRED_VERSION; - requiredAddons[] = {"zen_modules", "zen_dialog"}; + requiredAddons[] = {"zen_dialog"}; author = ECSTRING(main,Author); authors[] = {"Timi007"}; url = ECSTRING(main,URL); From 98133f61c7a9747c9f66cf7502d6f280995c3bc9 Mon Sep 17 00:00:00 2001 From: Timi007 Date: Fri, 10 Jan 2025 19:54:14 +0100 Subject: [PATCH 22/23] Fix JIP problems --- addons/comments/functions/fnc_deleteComment.sqf | 6 +----- addons/comments/functions/fnc_onCommentUpdated.sqf | 9 +++++++-- addons/comments/functions/fnc_updateComment.sqf | 2 +- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/addons/comments/functions/fnc_deleteComment.sqf b/addons/comments/functions/fnc_deleteComment.sqf index 85902b27d..cdbe753cf 100644 --- a/addons/comments/functions/fnc_deleteComment.sqf +++ b/addons/comments/functions/fnc_deleteComment.sqf @@ -21,14 +21,10 @@ if (!isServer) exitWith { 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; +[QGVAR(commentDeleted), [_id], _jipId] call CBA_fnc_globalEventJIP; TRACE_1("Comment deleted",_id); diff --git a/addons/comments/functions/fnc_onCommentUpdated.sqf b/addons/comments/functions/fnc_onCommentUpdated.sqf index fa3fd8276..cd14b6e60 100644 --- a/addons/comments/functions/fnc_onCommentUpdated.sqf +++ b/addons/comments/functions/fnc_onCommentUpdated.sqf @@ -18,6 +18,11 @@ params ["_id", "_data"]; -GVAR(comments) set [_id, _data]; +if (_id in GVAR(comments)) then { + GVAR(comments) set [_id, _data]; -[_id] call FUNC(updateIcon); + [_id] call FUNC(updateIcon); +} else { + // Comment does not exist (JIP case). + [QGVAR(commentCreated), _this] call CBA_fnc_localEvent; +}; diff --git a/addons/comments/functions/fnc_updateComment.sqf b/addons/comments/functions/fnc_updateComment.sqf index de8fec391..e64ae08f6 100644 --- a/addons/comments/functions/fnc_updateComment.sqf +++ b/addons/comments/functions/fnc_updateComment.sqf @@ -33,7 +33,7 @@ params [ ["_creator", "", [""]] ]; -private _jipId = format [QGVAR(update_%1), _id]; private _data = [_position, _title, _tooltip, _color, _creator]; +private _jipId = format [QGVAR(%1), _id]; [QGVAR(commentUpdated), [_id, _data], _jipId] call CBA_fnc_globalEventJIP; TRACE_2("Comment updated",_id,_data); From 3bf6e7f640a5893f2d79d3dac25042b693b8d0a9 Mon Sep 17 00:00:00 2001 From: Timi007 Date: Fri, 10 Jan 2025 20:09:31 +0100 Subject: [PATCH 23/23] Fix spelling --- docs/user_guide/comments.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/user_guide/comments.md b/docs/user_guide/comments.md index 73332680d..9680ce8b5 100644 --- a/docs/user_guide/comments.md +++ b/docs/user_guide/comments.md @@ -11,9 +11,9 @@ The context menu action is only shown when comments are enabled in the CBA setti ### Editing The properties of comments can be changed by double clicking on the icon of the comment. -This will open a menu which allows you to configure the comment's title, tooltip, and color. +This will open a menu that allows you to configure the comment's title, tooltip, and color. -Comments can be moved by left clicking an dragging on the icon. +Comments can be moved by left clicking and dragging on the icon. Comments created in 3DEN cannot be moved. ### Deleting @@ -26,4 +26,4 @@ By default, comments created in 3DEN cannot be deleted. This can be changed in t All comments created in 3DEN will be imported into Zeus by default. A comment can be excluded by unchecking the "Show comment in Zeus" option when creating/editing a comment in 3DEN. -!> The mission must be saved, otherwise 3DEN comments will not be shown in Zeus! +!> The mission must be saved; otherwise, 3DEN comments will not be shown in Zeus!