ACE3/addons/maptools/functions/fnc_updateMapToolMarkers.sqf
b-mayr-1984 020cf2ddd8
maptools - Improve behaviour upon first open (show under mouse position instead of bottom-left corner) (#8848)
* open map tools in center of screen upon first open

Don't show the map tools at the bottom-left corner of the map when you first open it, but right where your mouse is.

* always move to mouse position when opened (not just once)

incorporated feedback from co-authors

Co-Authored-By: Drofseh <Drofseh@users.noreply.github.com>
Co-Authored-By: PabstMirror <pabstmirror@gmail.com>

* replace tabs by 4x whitespaces in order for checks to complete successfully

* move code to fnc_updateMapToolMarkers so it always runs

Co-authored-by: Drofseh <Drofseh@users.noreply.github.com>
Co-authored-by: PabstMirror <pabstmirror@gmail.com>
2022-04-06 16:49:27 -05:00

57 lines
2.0 KiB
Plaintext

#include "script_component.hpp"
/*
* Author: esteldunedain
* Update the map tool markers, position, size, rotation and visibility.
*
* Arguments:
* 0: The Map <CONTROL>
*
* Return Value:
* None
*
* Example:
* [CONTROL] call ACE_maptools_fnc_updateMapToolMarkers
*
* Public: No
*/
params ["_theMap"];
if ((GVAR(mapTool_Shown) == 0) || {!("ACE_MapTools" in (ACE_player call EFUNC(common,uniqueItems)))}) exitWith {};
// open map tools in center of screen when toggled to be shown
if (GVAR(mapTool_moveToMouse)) then {
private _mousePosition = _theMap ctrlMapScreenToWorld getMousePosition;
GVAR(mapTool_pos) = _mousePosition;
GVAR(mapTool_moveToMouse) = false; // we only need to do this once after opening the map tool
};
private _rotatingTexture = "";
private _textureWidth = 0;
if (GVAR(mapTool_Shown) == 1) then {
_rotatingTexture = QPATHTOF(data\mapToolRotatingNormal.paa);
_textureWidth = TEXTURE_WIDTH_IN_M;
} else {
_rotatingTexture = QPATHTOF(data\mapToolRotatingSmall.paa);
_textureWidth = TEXTURE_WIDTH_IN_M / 2;
};
if (GVAR(freedrawing)) then {[_theMap, _textureWidth] call FUNC(drawLinesOnRoamer);};
// Update scale of both parts
getResolution params ["_resWidth", "_resHeight", "", "", "_aspectRatio"];
private _scaleX = 32 * _textureWidth * CONSTANT_SCALE * (call FUNC(calculateMapScale));
private _scaleY = _scaleX * ((_resWidth / _resHeight) / _aspectRatio); //handle bad aspect ratios
// Position of the fixed part
private _xPos = GVAR(mapTool_pos) select 0;
private _yPos = (GVAR(mapTool_pos) select 1) + _textureWidth * CENTER_OFFSET_Y_PERC;
_theMap drawIcon [QPATHTOF(data\mapToolFixed.paa), [1,1,1,1], [_xPos,_yPos], _scaleX, _scaleY, 0, "", 0];
// Position and rotation of the rotating part
_xPos = (GVAR(mapTool_pos) select 0) + sin(GVAR(mapTool_angle)) * _textureWidth * CENTER_OFFSET_Y_PERC;
_yPos = (GVAR(mapTool_pos) select 1) + cos(GVAR(mapTool_angle)) * _textureWidth * CENTER_OFFSET_Y_PERC;
_theMap drawIcon [_rotatingTexture, [1,1,1,1], [_xPos,_yPos], _scaleX, _scaleY, GVAR(mapTool_angle), "", 0];