From 7988622635bf748df659f9134b17b4305f4e94bd Mon Sep 17 00:00:00 2001 From: Timi007 Date: Mon, 17 Sep 2018 20:52:24 +0200 Subject: [PATCH] Add the ability to edit user placed markers (#6564) * add the ability to edit user placed markers * remove direct channel from valid channels * add author * optimize get map display replace old method of getting the map display with displayParent * optimize code by adding isEqualTo * correct some spelling mistakes --- AUTHORS.txt | 1 + addons/markers/XEH_preInit.sqf | 10 ++- .../functions/fnc_getEnabledChannels.sqf | 8 +- .../functions/fnc_initInsertMarker.sqf | 80 +++++++++++++------ addons/markers/functions/fnc_placeMarker.sqf | 15 +++- addons/markers/script_component.hpp | 3 +- 6 files changed, 80 insertions(+), 37 deletions(-) diff --git a/AUTHORS.txt b/AUTHORS.txt index 11b34fff14..dafa0ba600 100644 --- a/AUTHORS.txt +++ b/AUTHORS.txt @@ -130,6 +130,7 @@ System98 SzwedzikPL Tachi Tessa Elieff +Timi007 Toaster Tonic Tourorist diff --git a/addons/markers/XEH_preInit.sqf b/addons/markers/XEH_preInit.sqf index abf28d6e8b..885a0a3068 100644 --- a/addons/markers/XEH_preInit.sqf +++ b/addons/markers/XEH_preInit.sqf @@ -17,11 +17,12 @@ if (isNil QGVAR(MarkersCache)) then { for "_a" from 0 to (count _config - 1) do { private _marker = _config select _a; - if (getNumber (_marker >> "scope") == 2) then { + if (getNumber (_marker >> "scope") isEqualTo 2) then { + private _class = configName _marker; private _name = getText (_marker >> "name"); private _icon = getText (_marker >> "icon"); - GVAR(MarkersCache) pushBack [_name, _a, _icon]; + GVAR(MarkersCache) pushBack [_name, _a, _icon, _class]; }; }; }; @@ -35,7 +36,8 @@ if (isNil QGVAR(MarkerColorsCache)) then { for "_a" from 0 to (count _config - 1) do { private _marker = _config select _a; - if (getNumber (_marker >> "scope") == 2) then { + if (getNumber (_marker >> "scope") isEqualTo 2) then { + private _class = configName _marker; private _name = getText (_marker >> "name"); private _rgba = getArray (_marker >> "color"); @@ -48,7 +50,7 @@ if (isNil QGVAR(MarkerColorsCache)) then { _rgba params ["_red", "_green", "_blue", "_alpha"]; private _icon = format ["#(argb,8,8,3)color(%1,%2,%3,%4)", _red, _green, _blue, _alpha]; - GVAR(MarkerColorsCache) pushBack [_name, _a, _icon]; + GVAR(MarkerColorsCache) pushBack [_name, _a, _icon, _class]; }; }; }; diff --git a/addons/markers/functions/fnc_getEnabledChannels.sqf b/addons/markers/functions/fnc_getEnabledChannels.sqf index eb4bcfd5ce..8919de5eae 100644 --- a/addons/markers/functions/fnc_getEnabledChannels.sqf +++ b/addons/markers/functions/fnc_getEnabledChannels.sqf @@ -1,5 +1,5 @@ /* - * Author: commy2 + * Author: commy2, Timi007 * Return enabled channels. * * Arguments: @@ -40,12 +40,8 @@ if (_localize) then { if (setCurrentChannel 4) then { _enabledChannels pushBack localize "str_channel_vehicle"; }; - - if (setCurrentChannel 5) then { - _enabledChannels pushBack localize "str_channel_direct"; - }; } else { - for "_i" from 0 to 5 do { + for "_i" from 0 to 4 do { if (setCurrentChannel _i) then { _enabledChannels pushBack _i; }; diff --git a/addons/markers/functions/fnc_initInsertMarker.sqf b/addons/markers/functions/fnc_initInsertMarker.sqf index 549a89730d..5263d2b73a 100644 --- a/addons/markers/functions/fnc_initInsertMarker.sqf +++ b/addons/markers/functions/fnc_initInsertMarker.sqf @@ -1,5 +1,5 @@ /* - * Author: BIS, commy2 + * Author: BIS, commy2, Timi007 * Sets up the marker placement * Run instead of \a3\ui_f\scripts\GUI\RscDisplayInsertMarker.sqf * @@ -46,32 +46,39 @@ private _aceAngleSlider = _display displayctrl 1220; private _aceAngleSliderText = _display displayctrl 1221; - //////////////////// - // Install MapDrawEH on current map - private _mapIDD = -1; + private _mapDisplay = displayParent _display; + if (isNull _mapDisplay) exitWith {ERROR("No Map");}; + private _mapCtrl = _mapDisplay displayCtrl 51; - { - if (!isNull (findDisplay _x)) exitWith { - _mapIDD = _x; + GVAR(editingMarker) = ""; + (ctrlMapMouseOver _mapCtrl) params ["_mouseOverType", "_marker"]; + + //check if entity under mouse is a user marker + if (_mouseOverType isEqualTo "marker") then { + if !((_marker find "_USER_DEFINED") isEqualTo -1) then { + GVAR(editingMarker) = _marker; + //hide marker which is being edited because if the user cancels editing, it will still exist unchanged + GVAR(editingMarker) setMarkerAlphaLocal 0; }; - false - } count [12, 37, 52, 53, 160]; - - if (_mapIDD == -1) exitWith { - ERROR("No Map?"); }; - if !(_mapIDD in GVAR(mapDisplaysWithDrawEHs)) then { - GVAR(mapDisplaysWithDrawEHs) pushBack _mapIDD; - ((finddisplay _mapIDD) displayctrl 51) ctrlAddEventHandler ["Draw", {_this call FUNC(mapDrawEH)}]; // @todo check if persistent + //////////////////// + // Install MapDrawEH on current map + if !((ctrlIDD _mapDisplay) in GVAR(mapDisplaysWithDrawEHs)) then { + GVAR(mapDisplaysWithDrawEHs) pushBack (ctrlIDD _mapDisplay); + _mapCtrl ctrlAddEventHandler ["Draw", {_this call FUNC(mapDrawEH)}]; // @todo check if persistent }; //////////////////// // Calculate center position of the marker placement ctrl - private _pos = ctrlPosition _picture; - _pos = [(_pos select 0) + (_pos select 2) / 2, (_pos select 1) + (_pos select 3) / 2]; - - GVAR(currentMarkerPosition) = ((findDisplay _mapIDD) displayCtrl 51) ctrlMapScreenToWorld _pos; + if !(GVAR(editingMarker) isEqualTo "") then { + //prevent changing the original marker position + GVAR(currentMarkerPosition) = markerPos GVAR(editingMarker); + } else { + private _pos = ctrlPosition _picture; + _pos = [(_pos select 0) + (_pos select 2) / 2, (_pos select 1) + (_pos select 3) / 2]; + GVAR(currentMarkerPosition) = _mapCtrl ctrlMapScreenToWorld _pos; + }; //Hide the bis picture: _picture ctrlShow false; @@ -79,12 +86,16 @@ // prevent vanilla key input _display displayAddEventHandler ["KeyDown", {(_this select 1) in [200, 208]}]; + if !((markerText GVAR(editingMarker)) isEqualTo "") then { + //fill text input with text from marker which is being edited + _text ctrlSetText (markerText GVAR(editingMarker)); + }; //Focus on the text input ctrlSetFocus _text; //--- Background - _pos = ctrlposition _text; + private _pos = ctrlposition _text; _pos params ["_posX", "_posY", "_posW", "_posH"]; _posX = _posX + 0.01; _posY = _posY min ((safeZoneH + safeZoneY) - (8 * _posH + 8 * BORDER)); //prevent buttons being placed below bottom edge of screen @@ -161,12 +172,20 @@ }; }; - private _currentChannelName = CHANNEL_NAMES param [currentChannel, localize "str_channel_group"]; + private _selectChannel = if !(GVAR(editingMarker) isEqualTo "") then { + //get the channel where the marker was placed in + parseNumber ((GVAR(editingMarker) splitString "/") param [2, "3"]) + } else { + currentChannel + }; + + private _currentChannelName = CHANNEL_NAMES param [_selectChannel, localize "str_channel_group"]; // select current channel in list box, must be done after lbDelete for "_j" from 0 to (lbSize _channel - 1) do { if (_channel lbText _j == _currentChannelName) then { _channel lbSetCurSel _j; + setCurrentChannel (CHANNEL_NAMES find _currentChannelName); }; }; @@ -198,10 +217,15 @@ // init marker shape lb lbClear _aceShapeLB; { - _x params ["_add", "_set", "_pic"]; + _x params ["_add", "_set", "_pic", "_classname"]; _aceShapeLB lbAdd _add; _aceShapeLB lbSetValue [_forEachIndex, _set]; _aceShapeLB lbSetPicture [_forEachIndex, _pic]; + + if ((markerType GVAR(editingMarker)) isEqualTo _classname) then { + //if the marker is being edited then get the original shape + GVAR(curSelMarkerShape) = _forEachIndex; + }; } forEach GVAR(MarkersCache); private _curSelShape = GETGVAR(curSelMarkerShape,0); @@ -215,10 +239,15 @@ // init marker color lb lbClear _aceColorLB; { - _x params ["_add", "_set", "_pic"]; + _x params ["_add", "_set", "_pic", "_classname"]; _aceColorLB lbAdd _add; _aceColorLB lbSetValue [_forEachIndex, _set]; _aceColorLB lbSetPicture [_forEachIndex, _pic]; + + if ((markerColor GVAR(editingMarker)) isEqualTo _classname) then { + //if the marker is being edited then get the original color + GVAR(curSelMarkerColor) = _forEachIndex; + }; } forEach GVAR(MarkerColorsCache); private _curSelColor = GETGVAR(curSelMarkerColor,0); @@ -232,6 +261,11 @@ // init marker angle slider _aceAngleSlider sliderSetRange [-180, 180]; + if !(GVAR(editingMarker) isEqualTo "") then { + //get the original direction + GVAR(currentMarkerAngle) = markerDir GVAR(editingMarker); + }; + private _curSelAngle = GETGVAR(currentMarkerAngle,0); _aceAngleSlider sliderSetPosition _curSelAngle; diff --git a/addons/markers/functions/fnc_placeMarker.sqf b/addons/markers/functions/fnc_placeMarker.sqf index 281953e104..0eca5bf35e 100644 --- a/addons/markers/functions/fnc_placeMarker.sqf +++ b/addons/markers/functions/fnc_placeMarker.sqf @@ -1,5 +1,5 @@ /* - * Author: commy2 + * Author: commy2, Timi007 * MarkerPlacement closed * * Arguments: @@ -20,7 +20,11 @@ disableserialization; params ["_display", "_closeNum"]; TRACE_2("params",_display,_closeNum); -if (_closeNum == 1) then { +if (_closeNum isEqualTo 1) then { + if !(GVAR(editingMarker) isEqualTo "") then { + //delete "old" marker + deleteMarker GVAR(editingMarker); + }; // set and send marker data the next frame. the actual marker isn't created yet [{ [QGVAR(setMarkerNetwork), [ @@ -33,4 +37,11 @@ if (_closeNum == 1) then { ]] call CBA_fnc_globalEvent; }, []] call CBA_fnc_execNextFrame; +} else { + if !(GVAR(editingMarker) isEqualTo "") then { + //editing was canceled show the original marker again + GVAR(editingMarker) setMarkerAlphaLocal 1; + }; }; + +GVAR(editingMarker) = ""; diff --git a/addons/markers/script_component.hpp b/addons/markers/script_component.hpp index c081cbcc39..fdb5f1614e 100644 --- a/addons/markers/script_component.hpp +++ b/addons/markers/script_component.hpp @@ -21,8 +21,7 @@ localize "str_channel_side", \ localize "str_channel_command", \ localize "str_channel_group", \ - localize "str_channel_vehicle", \ - localize "str_channel_direct" \ + localize "str_channel_vehicle" \ ] #define MOVE_RESTRICTION_NOBODY -1