2018-09-17 19:19:29 +00:00
#include "script_component.hpp"
2015-03-28 01:51:30 +00:00
/*
2018-09-17 18:52:24 +00:00
* Author: BIS, commy2, Timi007
2015-03-28 01:51:30 +00:00
* Sets up the marker placement
2015-03-28 04:19:03 +00:00
* Run instead of \a3\ui_f\scripts\GUI\RscDisplayInsertMarker.sqf
2015-03-28 01:51:30 +00:00
*
* Arguments:
* 0: RscDisplayInsertMarker <DISPLAY>
*
* Return Value:
2015-08-22 12:08:35 +00:00
* None
2015-03-28 01:51:30 +00:00
*
* Example:
* [onLoad] call ace_markers_fnc_initInsertMarker;
*
* Public: No
*/
2015-01-18 16:17:06 +00:00
2015-12-10 14:32:31 +00:00
#define BORDER 0.005
2015-01-18 16:17:06 +00:00
[{
2015-01-19 15:59:00 +00:00
disableserialization;
2015-08-22 12:08:35 +00:00
params ["_display"];
2015-08-23 19:25:41 +00:00
TRACE_1("params",_display);
2016-05-03 00:32:44 +00:00
2015-03-28 01:51:30 +00:00
//Can't place markers when can't interact
2015-12-10 14:32:31 +00:00
if !([ACE_player, objNull, ["notOnMap", "isNotInside", "isNotSitting"]] call EFUNC(common,canInteractWith)) exitWith {
2021-02-26 23:17:00 +00:00
_display closeDisplay 2; //emulate "Cancel" button
2015-03-28 01:51:30 +00:00
};
2015-01-19 15:59:00 +00:00
2015-03-28 01:51:30 +00:00
//BIS Controls:
2021-02-26 23:17:00 +00:00
private _text = _display displayctrl IDC_INSERT_MARKER;
private _picture = _display displayctrl IDC_INSERT_MARKER_PICTURE;
private _channel = _display displayctrl IDC_INSERT_MARKER_CHANNELS;
private _buttonOK = _display displayctrl IDC_OK;
private _buttonCancel = _display displayctrl IDC_CANCEL;
private _description = _display displayctrl 1100;
private _title = _display displayctrl 1001;
private _descriptionChannel = _display displayctrl 1101;
2015-03-28 00:22:49 +00:00
2015-03-28 01:51:30 +00:00
//ACE Controls:
2021-02-26 23:17:00 +00:00
private _ctrlTimestamp = _display displayCtrl IDC_ACE_INSERT_MARKER_TIMESTAMP;
private _ctrlTimestampText = _display displayCtrl IDC_ACE_INSERT_MARKER_TIMESTAMP_TEXT;
private _aceShapeLB = _display displayctrl IDC_ACE_INSERT_MARKER_SHAPE;
private _aceColorLB = _display displayctrl IDC_ACE_INSERT_MARKER_COLOR;
private _aceAngleSlider = _display displayctrl IDC_ACE_INSERT_MARKER_ANGLE;
private _aceAngleSliderText = _display displayctrl IDC_ACE_INSERT_MARKER_ANGLE_TEXT;
2021-04-21 20:36:08 +00:00
private _aceScaleSlider = _display displayctrl IDC_ACE_INSERT_MARKER_SCALE;
private _aceScaleSliderText = _display displayctrl IDC_ACE_INSERT_MARKER_SCALE_TEXT;
2021-02-26 23:17:00 +00:00
private _mapDisplay = displayParent _display;
2018-09-17 18:52:24 +00:00
if (isNull _mapDisplay) exitWith {ERROR("No Map");};
2020-10-29 16:36:59 +00:00
private _mapCtrl = _mapDisplay displayCtrl IDC_MAP;
2015-03-28 03:55:19 +00:00
2018-09-17 18:52:24 +00:00
GVAR(editingMarker) = "";
(ctrlMapMouseOver _mapCtrl) params ["_mouseOverType", "_marker"];
2015-12-10 14:32:31 +00:00
2018-09-17 18:52:24 +00:00
//check if entity under mouse is a user marker
if (_mouseOverType isEqualTo "marker") then {
2021-02-27 17:05:05 +00:00
if (((_marker find "_USER_DEFINED") isNotEqualTo -1) && ((markerShape _marker) isEqualTo "ICON")) then {
2018-09-17 18:52:24 +00:00
GVAR(editingMarker) = _marker;
//hide marker which is being edited because if the user cancels editing, it will still exist unchanged
GVAR(editingMarker) setMarkerAlphaLocal 0;
};
2015-12-10 14:32:31 +00:00
};
2018-09-17 18:52:24 +00:00
////////////////////
// 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
2015-03-28 03:55:19 +00:00
};
2015-12-10 14:32:31 +00:00
////////////////////
// Calculate center position of the marker placement ctrl
2021-02-27 17:05:05 +00:00
if (GVAR(editingMarker) isNotEqualTo "") then {
2018-09-17 18:52:24 +00:00
//prevent changing the original marker position
GVAR(currentMarkerPosition) = markerPos GVAR(editingMarker);
} else {
private _pos = ctrlPosition _picture;
2020-10-29 16:36:59 +00:00
_pos = [
(_pos select 0) + (_pos select 2) / 2,
(_pos select 1) + (_pos select 3) / 2
];
2018-09-17 18:52:24 +00:00
GVAR(currentMarkerPosition) = _mapCtrl ctrlMapScreenToWorld _pos;
};
2015-03-28 03:55:19 +00:00
//Hide the bis picture:
_picture ctrlShow false;
2015-03-28 04:24:11 +00:00
2015-03-28 03:55:19 +00:00
// prevent vanilla key input
_display displayAddEventHandler ["KeyDown", {(_this select 1) in [200, 208]}];
2021-02-26 23:17:00 +00:00
private _markerText = markerText GVAR(editingMarker);
if (_markerText != "") then {
2020-10-29 16:36:59 +00:00
// fill text input with text from marker which is being edited
2021-02-26 23:17:00 +00:00
_markerText = _markerText call FUNC(removeTimestamp);
_text ctrlSetText _markerText;
2018-09-17 18:52:24 +00:00
};
2015-03-28 03:55:19 +00:00
//Focus on the text input
2015-01-19 15:59:00 +00:00
ctrlSetFocus _text;
//--- Background
2018-09-17 18:52:24 +00:00
private _pos = ctrlposition _text;
2015-12-10 14:32:31 +00:00
_pos params ["_posX", "_posY", "_posW", "_posH"];
2015-08-22 12:08:35 +00:00
_posX = _posX + 0.01;
2021-04-21 20:36:08 +00:00
_posY = _posY min ((safeZoneH + safeZoneY) - (11 * _posH + 11 * BORDER)); //prevent buttons being placed below bottom edge of screen
2015-12-10 14:32:31 +00:00
_pos set [0, _posX];
_pos set [1, _posY];
_text ctrlSetPosition _pos;
_text ctrlCommit 0;
2015-01-19 15:59:00 +00:00
//--- Title
2015-12-10 14:32:31 +00:00
_pos set [1, _posY - 2 * _posH - BORDER];
_pos set [3, _posH];
_title ctrlSetPosition _pos;
_title ctrlCommit 0;
2015-01-19 15:59:00 +00:00
//--- Description
2015-12-10 14:32:31 +00:00
_pos set [1, _posY - 1 * _posH];
2020-10-29 16:36:59 +00:00
if (GVAR(timestampEnabled)) then {
2021-04-21 20:36:08 +00:00
_pos set [3,9 * _posH + 9 * BORDER];
2020-10-29 16:36:59 +00:00
} else {
2021-04-21 20:36:08 +00:00
_pos set [3,10 * _posH + 10 * BORDER];
2020-10-29 16:36:59 +00:00
};
2015-12-10 14:32:31 +00:00
_description ctrlEnable false;
_description ctrlSetPosition _pos;
_description ctrlSetStructuredText parseText format ["<t size='0.8'>%1</t>", localize "str_lib_label_description"];
_description ctrlCommit 0;
2015-01-19 15:59:00 +00:00
2020-10-29 16:36:59 +00:00
//--- Timestamp
private _timestampOffset = 0;
if (GVAR(timestampEnabled)) then {
_timestampOffset = _posH + BORDER;
2021-02-26 23:17:00 +00:00
private _left = _posX;
private _top = _posY + 1 * _posH + 2 * BORDER;
private _width = _posH * safeZoneH / safeZoneW;
private _height = _posH;
2020-10-29 16:36:59 +00:00
2021-02-26 23:17:00 +00:00
_ctrlTimestamp ctrlSetPosition [_left, _top, _width, _height];
_ctrlTimestamp ctrlCommit 0;
_ctrlTimestampText ctrlSetStructuredText parseText format ["<t size='0.8'>%1</t>", LLSTRING(Timestamp)];
_left = _left + _width;
_width = _posW - _width;
_top = _top + 0.1 * _height;
_ctrlTimestampText ctrlSetPosition [_left, _top, _width, _height];
_ctrlTimestampText ctrlCommit 0;
2020-10-29 16:36:59 +00:00
if !([ACE_player] call FUNC(canTimestamp)) then {
2021-02-26 23:17:00 +00:00
_ctrlTimestamp ctrlEnable false;
_ctrlTimestamp ctrlSetTooltip LLSTRING(TimestampTooltipNoWatch);
2020-10-29 16:36:59 +00:00
} else {
2021-02-26 23:17:00 +00:00
_ctrlTimestamp cbSetChecked (uiNamespace getVariable [QGVAR(timestampChecked), false]);
2020-10-29 16:36:59 +00:00
};
} else {
2021-02-26 23:17:00 +00:00
_ctrlTimestampText ctrlEnable false;
_ctrlTimestampText ctrlShow false;
_ctrlTimestamp ctrlEnable false;
_ctrlTimestamp ctrlShow false;
2020-10-29 16:36:59 +00:00
};
2015-01-19 15:59:00 +00:00
//--- Shape
2020-10-29 16:36:59 +00:00
_pos set [0, _posX];
_pos set [1, _posY + 1 * _posH + 2 * BORDER + _timestampOffset];
2015-12-10 14:32:31 +00:00
_pos set [2, _posW];
_pos set [3, _posH];
_aceShapeLB ctrlSetPosition _pos;
_aceShapeLB ctrlCommit 0;
2015-01-19 15:59:00 +00:00
//--- Color
2020-10-29 16:36:59 +00:00
_pos set [1, _posY + 2 * _posH + 3 * BORDER + _timestampOffset];
2015-12-10 14:32:31 +00:00
_pos set [2, _posW];
_aceColorLB ctrlSetPosition _pos;
_aceColorLB ctrlCommit 0;
2015-01-19 15:59:00 +00:00
//--- Angle
2020-10-29 16:36:59 +00:00
_pos set [1, _posY + 3 * _posH + 4 * BORDER + _timestampOffset];
2015-12-10 14:32:31 +00:00
_pos set [2, _posW];
_aceAngleSlider ctrlSetPosition _pos;
_aceAngleSlider ctrlCommit 0;
2015-01-19 15:59:00 +00:00
//--- Angle Text
2020-10-29 16:36:59 +00:00
_pos set [1, _posY + 4 * _posH + 5 * BORDER + _timestampOffset];
2015-12-10 14:32:31 +00:00
_pos set [2, _posW];
_aceAngleSliderText ctrlSetPosition _pos;
_aceAngleSliderText ctrlCommit 0;
2021-04-21 20:36:08 +00:00
//--- Scale
_pos set [1, _posY + 5 * _posH + 6 * BORDER + _timestampOffset];
_pos set [2, _posW];
_aceScaleSlider ctrlSetPosition _pos;
_aceScaleSlider ctrlCommit 0;
//--- Scale Text
_pos set [1, _posY + 6 * _posH + 7 * BORDER + _timestampOffset];
_pos set [2, _posW];
_aceScaleSliderText ctrlSetPosition _pos;
_aceScaleSliderText ctrlCommit 0;
2015-12-10 14:32:31 +00:00
private _offsetButtons = 0;
2015-01-19 15:59:00 +00:00
2015-03-28 01:51:30 +00:00
if (isMultiplayer) then {
2021-04-21 20:36:08 +00:00
_pos set [1,_posY + 7 * _posH + 9 * BORDER + _timestampOffset];
2015-03-28 00:22:49 +00:00
_pos set [3,_posH];
2015-12-10 14:32:31 +00:00
_descriptionChannel ctrlSetStructuredText parseText format ["<t size='0.8'>%1:</t>", localize "str_a3_cfgvehicles_modulerespawnposition_f_arguments_marker_0"];
_descriptionChannel ctrlSetPosition _pos;
_descriptionChannel ctrlCommit 0;
2015-03-28 00:22:49 +00:00
2021-04-21 20:36:08 +00:00
_pos set [1,_posY + 8 * _posH + 9 * BORDER + _timestampOffset];
2015-03-28 00:22:49 +00:00
_pos set [3,_posH];
2015-12-10 14:32:31 +00:00
_channel ctrlSetPosition _pos;
_channel ctrlCommit 0;
// channels are added by engine and not script. we have to manually delete them. requires channel names to be unique?
private _enabledChannels = true call FUNC(getEnabledChannels);
private _i = 0;
while {_i < lbSize _channel} do {
private _channelName = _channel lbText _i;
// _enabledChannels can not include custom channels names. Therefore also check if it's a custom one. Blame BI if the unit should not access the channel.
if (_channelName in _enabledChannels || {!(_channelName in CHANNEL_NAMES)}) then {
_i = _i + 1;
} else {
_channel lbDelete _i;
};
};
2021-02-27 17:05:05 +00:00
private _selectChannel = if (GVAR(editingMarker) isNotEqualTo "") then {
2018-09-17 18:52:24 +00:00
//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"];
2015-12-10 14:32:31 +00:00
// 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;
2018-09-17 18:52:24 +00:00
setCurrentChannel (CHANNEL_NAMES find _currentChannelName);
2015-12-10 14:32:31 +00:00
};
};
_channel ctrlAddEventHandler ["LBSelChanged", {_this call FUNC(onLBSelChangedChannel)}];
2021-04-21 20:36:08 +00:00
_offsetButtons = 9 * _posH + 10 * BORDER;
2015-03-28 00:22:49 +00:00
} else {
2015-12-10 14:32:31 +00:00
_descriptionChannel ctrlShow false;
_channel ctrlShow false;
2021-04-21 20:36:08 +00:00
_offsetButtons = 7 * _posH + 9 * BORDER;
2015-03-28 00:22:49 +00:00
};
2015-01-19 15:59:00 +00:00
//--- ButtonOK
2020-10-29 16:36:59 +00:00
_pos set [1, _posY + _offsetButtons + _timestampOffset];
2015-12-10 14:32:31 +00:00
_pos set [2, _posW / 2 - BORDER];
_pos set [3, _posH];
_buttonOk ctrlSetPosition _pos;
_buttonOk ctrlCommit 0;
2015-01-19 15:59:00 +00:00
//--- ButtonCancel
2015-12-10 14:32:31 +00:00
_pos set [0, _posX + _posW / 2];
2020-10-29 16:36:59 +00:00
_pos set [1, _posY + _offsetButtons + _timestampOffset];
2015-12-10 14:32:31 +00:00
_pos set [2, _posW / 2];
_pos set [3, _posH];
_buttonCancel ctrlSetPosition _pos;
_buttonCancel ctrlCommit 0;
2020-10-29 16:36:59 +00:00
////////////////////
// init marker timestamp cb
2021-02-26 23:17:00 +00:00
_buttonOK ctrlAddEventHandler ["ButtonClick", FUNC(onButtonClickConfirm)];
_ctrlTimestamp ctrlAddEventHandler ["CheckedChanged", FUNC(onCheckedChangedTimestamp)];
2020-10-29 16:36:59 +00:00
2015-12-10 14:32:31 +00:00
////////////////////
2015-01-19 15:59:00 +00:00
// init marker shape lb
2015-03-28 01:51:30 +00:00
lbClear _aceShapeLB;
2015-01-19 15:59:00 +00:00
{
2018-09-17 18:52:24 +00:00
_x params ["_add", "_set", "_pic", "_classname"];
2015-08-22 12:08:35 +00:00
_aceShapeLB lbAdd _add;
_aceShapeLB lbSetValue [_forEachIndex, _set];
_aceShapeLB lbSetPicture [_forEachIndex, _pic];
2018-09-17 18:52:24 +00:00
if ((markerType GVAR(editingMarker)) isEqualTo _classname) then {
//if the marker is being edited then get the original shape
GVAR(curSelMarkerShape) = _forEachIndex;
};
2015-01-19 15:59:00 +00:00
} forEach GVAR(MarkersCache);
2015-12-10 14:32:31 +00:00
private _curSelShape = GETGVAR(curSelMarkerShape,0);
2015-03-28 01:51:30 +00:00
_aceShapeLB lbSetCurSel _curSelShape;
//Update now and add eventHandler:
[_aceShapeLB, _curSelShape] call FUNC(onLBSelChangedShape);
_aceShapeLB ctrlAddEventHandler ["LBSelChanged", {_this call FUNC(onLBSelChangedShape)}];
2015-01-19 15:59:00 +00:00
2015-12-10 14:32:31 +00:00
////////////////////
2015-01-19 15:59:00 +00:00
// init marker color lb
2015-03-28 01:51:30 +00:00
lbClear _aceColorLB;
2015-01-19 15:59:00 +00:00
{
2018-09-17 18:52:24 +00:00
_x params ["_add", "_set", "_pic", "_classname"];
2015-08-22 12:08:35 +00:00
_aceColorLB lbAdd _add;
_aceColorLB lbSetValue [_forEachIndex, _set];
_aceColorLB lbSetPicture [_forEachIndex, _pic];
2018-09-17 18:52:24 +00:00
if ((markerColor GVAR(editingMarker)) isEqualTo _classname) then {
//if the marker is being edited then get the original color
GVAR(curSelMarkerColor) = _forEachIndex;
};
2015-01-19 15:59:00 +00:00
} forEach GVAR(MarkerColorsCache);
2015-12-10 14:32:31 +00:00
private _curSelColor = GETGVAR(curSelMarkerColor,0);
2015-03-28 01:51:30 +00:00
_aceColorLB lbSetCurSel _curSelColor;
2015-01-18 16:17:06 +00:00
2015-03-28 01:51:30 +00:00
//Update now and add eventHandler:
[_aceColorLB, _curSelColor] call FUNC(onLBSelChangedColor);
_aceColorLB ctrlAddEventHandler ["LBSelChanged", {_this call FUNC(onLBSelChangedColor)}];
2015-01-19 15:59:00 +00:00
2015-12-10 14:32:31 +00:00
////////////////////
2015-03-28 01:51:30 +00:00
// init marker angle slider
_aceAngleSlider sliderSetRange [-180, 180];
2015-12-10 14:32:31 +00:00
2021-02-27 17:05:05 +00:00
if (GVAR(editingMarker) isNotEqualTo "") then {
2018-09-17 18:52:24 +00:00
//get the original direction
GVAR(currentMarkerAngle) = markerDir GVAR(editingMarker);
};
2015-12-10 14:32:31 +00:00
private _curSelAngle = GETGVAR(currentMarkerAngle,0);
2015-03-28 01:51:30 +00:00
_aceAngleSlider sliderSetPosition _curSelAngle;
2021-07-23 13:06:31 +00:00
_aceAngleSlider ctrlSetTooltip LLSTRING(MarkerDirectionScaleSlider_Tooltip);
2015-12-10 14:32:31 +00:00
2015-03-28 01:51:30 +00:00
//Update now and add eventHandler:
[_aceAngleSlider, _curSelAngle] call FUNC(onSliderPosChangedAngle);
_aceAngleSlider ctrlAddEventHandler ["SliderPosChanged", {_this call FUNC(onSliderPosChangedAngle)}];
2021-07-23 13:06:31 +00:00
_aceAngleSlider ctrlAddEventHandler ["MouseButtonUp", {_this call FUNC(onSliderMouseButtonUpAngle)}];
2021-04-21 20:36:08 +00:00
////////////////////
// init marker scale slider
_aceScaleSlider sliderSetRange [0.5, 2.0];
2021-12-18 23:15:32 +00:00
if (GVAR(editingMarker) isNotEqualTo "") then {
2021-04-21 20:36:08 +00:00
//get the original scale
2021-04-26 22:31:59 +00:00
GVAR(currentMarkerScale) = (markerSize GVAR(editingMarker)) param [0, 1];
2021-04-21 20:36:08 +00:00
};
private _curSelScale = GETGVAR(currentMarkerScale,1);
_aceScaleSlider sliderSetPosition _curSelScale;
2021-07-23 13:06:31 +00:00
_aceScaleSlider ctrlSetTooltip LLSTRING(MarkerDirectionScaleSlider_Tooltip);
2021-04-21 20:36:08 +00:00
//Update now and add eventHandler:
[_aceScaleSlider, _curSelScale] call FUNC(onSliderPosChangedScale);
_aceScaleSlider ctrlAddEventHandler ["SliderPosChanged", {_this call FUNC(onSliderPosChangedScale)}];
2021-07-23 13:06:31 +00:00
_aceScaleSlider ctrlAddEventHandler ["MouseButtonUp", {_this call FUNC(onSliderMouseButtonUpScale)}];
2016-05-22 13:27:24 +00:00
}, _this] call CBA_fnc_execNextFrame;