2018-09-17 19:19:29 +00:00
|
|
|
#include "script_component.hpp"
|
2015-08-11 17:49:39 +00:00
|
|
|
/*
|
2016-06-18 00:18:06 +00:00
|
|
|
* Author: voiper
|
|
|
|
* Draw nearby lighting and sexy flashlight beams on main map.
|
|
|
|
*
|
|
|
|
* Arguments:
|
|
|
|
* 0: Map control <CONTROL>
|
|
|
|
* 1: Map zoom level <NUMBER>
|
|
|
|
* 2: Current map centre <ARRAY>
|
|
|
|
* 3: Light level from ace_map_fnc_determineMapLight <ARRAY>
|
|
|
|
*
|
|
|
|
* Return Value:
|
|
|
|
* None
|
|
|
|
*
|
2017-06-08 13:31:51 +00:00
|
|
|
* Example:
|
2018-07-27 17:24:56 +00:00
|
|
|
* [CONTROL, 5, [5, 4, 6], []] call ace_map_fnc_simulateMapLight
|
2017-06-08 13:31:51 +00:00
|
|
|
*
|
2016-06-18 00:18:06 +00:00
|
|
|
* Public: No
|
|
|
|
*/
|
2015-08-11 17:49:39 +00:00
|
|
|
|
|
|
|
params ["_mapCtrl", "_mapScale", "_mapCentre", "_lightLevel"];
|
|
|
|
|
2016-06-18 00:18:06 +00:00
|
|
|
private _unitLight = ACE_player getVariable [QGVAR(flashlight), ["", objNull]];
|
|
|
|
_unitLight params ["_flashlight", ""];
|
2015-08-11 17:49:39 +00:00
|
|
|
|
|
|
|
//map width (on screen) in pixels
|
2016-06-18 00:18:06 +00:00
|
|
|
private _screenSize = 640 * safeZoneWAbs;
|
2015-08-11 17:49:39 +00:00
|
|
|
|
|
|
|
//resolution params (every frame in case resolution change)
|
|
|
|
getResolution params ["_resX", "_resY", "_viewPortX", "_viewPortY", "", "_uiScale"];
|
|
|
|
|
|
|
|
//engine rounds the viewport ratios, when they should be fractions; this can cause problems
|
2016-06-18 00:18:06 +00:00
|
|
|
private _realViewPortY = _resY * _uiScale;
|
|
|
|
private _realViewPortX = _realViewPortY * 4/3;
|
2015-08-11 17:49:39 +00:00
|
|
|
|
|
|
|
//textures
|
2016-06-18 00:18:06 +00:00
|
|
|
private _fillTex = "#(rgb,8,8,3)color(0,0,0,1)";
|
2015-08-11 17:49:39 +00:00
|
|
|
|
|
|
|
//colour/alpha
|
|
|
|
_lightLevel params ["_r", "_g", "_b", "_a"];
|
2016-06-18 00:18:06 +00:00
|
|
|
private _colourAlpha = (_r + _g + _b) min _a;
|
|
|
|
private _shadeAlpha = _a;
|
2015-08-11 17:49:39 +00:00
|
|
|
|
2021-10-12 08:31:46 +00:00
|
|
|
private _maxColour = selectMax [_r, _g, _b];
|
|
|
|
private _ambientColor = if (_maxColour == 0) then {
|
|
|
|
[1, 1, 1, _colourAlpha];
|
|
|
|
} else {
|
|
|
|
[_r / _maxColour, _g / _maxColour, _b / _maxColour, _colourAlpha];
|
|
|
|
};
|
2015-08-11 17:49:39 +00:00
|
|
|
|
2015-08-11 18:08:01 +00:00
|
|
|
//ambient colour fill
|
2021-10-12 08:31:46 +00:00
|
|
|
_mapCtrl drawIcon ["#(rgb,8,8,3)color(1,1,1,1)", _ambientColor, _mapCentre, _screenSize, _screenSize, 0, "", 0];
|
2015-08-11 17:49:39 +00:00
|
|
|
|
2015-08-11 18:08:01 +00:00
|
|
|
if (_flashlight == "") then {
|
|
|
|
//ambient shade fill
|
|
|
|
_mapCtrl drawIcon [_fillTex, [1,1,1,_shadeAlpha], _mapCentre, _screenSize, _screenSize, 0, "", 0];
|
2015-08-11 17:49:39 +00:00
|
|
|
} else {
|
2016-06-18 00:18:06 +00:00
|
|
|
private _mousePos = GVAR(mousePos);
|
2015-08-11 17:49:39 +00:00
|
|
|
|
2015-08-11 18:08:01 +00:00
|
|
|
//flashlight settings
|
2018-10-25 16:39:27 +00:00
|
|
|
private _cfg = configFile >> "CfgWeapons" >> _flashlight >> "ItemInfo" >> "FlashLight";
|
|
|
|
private _size = [_cfg >> "ACE_Flashlight_Size", "number", DEFAULT_FLASHLIGHT_SIZE] call CBA_fnc_getConfigEntry;
|
|
|
|
private _flashTex = [_cfg >> "ACE_Flashlight_Beam", "text", QPATHTOF(UI\Flashlight_beam_white_ca.paa)] call CBA_fnc_getConfigEntry;
|
2016-06-18 00:18:06 +00:00
|
|
|
private _beamSize = (safeZoneW/safeZoneWAbs) * _screenSize / _size;
|
2015-08-11 17:49:39 +00:00
|
|
|
|
2015-08-11 18:08:01 +00:00
|
|
|
//after 5x zoom, it's simulated to be fixed (it actually gets bigger relative to zoom)
|
|
|
|
if (_mapScale < 0.2) then {_beamSize = _beamSize / (_mapScale * (1 / 0.2))};
|
2015-08-11 17:49:39 +00:00
|
|
|
|
2015-08-11 18:08:01 +00:00
|
|
|
//assign corrective ratio to fix sub-pixel gaps/overlaps (symptom of viewport * X/Y resolution rounding)
|
2016-06-18 00:18:06 +00:00
|
|
|
private _viewPortRatioFixY = if (_realViewPortY != _viewPortY) then {
|
2015-08-11 18:08:01 +00:00
|
|
|
_realViewPortX / (_realViewPortY / _viewPortY * _viewPortX)
|
2015-08-11 17:49:39 +00:00
|
|
|
} else {
|
2015-08-11 18:08:01 +00:00
|
|
|
if (_realViewPortX != _viewPortX) then {
|
|
|
|
_realViewPortX / _viewPortX
|
2015-08-11 17:49:39 +00:00
|
|
|
} else {
|
2015-08-11 18:08:01 +00:00
|
|
|
1
|
2015-08-11 17:49:39 +00:00
|
|
|
};
|
|
|
|
};
|
2015-08-11 18:08:01 +00:00
|
|
|
|
|
|
|
//offset the elements
|
2016-06-18 00:18:06 +00:00
|
|
|
private _offsetX = _mapScale * GVAR(worldSize) * (_screenSize * 2 + _beamSize);
|
|
|
|
private _offsetYDown = _mapScale * GVAR(worldSize) * (_screenSize + _beamSize) * _viewPortRatioFixY;
|
2015-08-11 18:08:01 +00:00
|
|
|
//up is bigger because of a potential exploit
|
2016-06-18 00:18:06 +00:00
|
|
|
private _offsetYUp = _mapScale * GVAR(worldSize) * (_screenSize * 4 + _beamSize) * _viewPortRatioFixY;
|
2015-08-11 18:08:01 +00:00
|
|
|
|
|
|
|
//draw the matrix /whoa
|
|
|
|
_mapCtrl drawIcon [_flashTex, [1,1,1,_shadeAlpha], _mousePos, _beamSize, _beamSize, 0, "", 0]; //centre beam
|
|
|
|
_mapCtrl drawIcon [_fillTex, [1,1,1,_shadeAlpha], [(_mousePos select 0) - _offsetX, (_mousePos select 1)], _screenSize * 2, _beamSize, 0, "", 0]; //left
|
|
|
|
_mapCtrl drawIcon [_fillTex, [1,1,1,_shadeAlpha], [(_mousePos select 0) + _offsetX, (_mousePos select 1)], _screenSize * 2, _beamSize, 0, "", 0]; //right
|
|
|
|
_mapCtrl drawIcon [_fillTex, [1,1,1,_shadeAlpha], [(_mousePos select 0), (_mousePos select 1) - _offsetYDown], _screenSize * 4, _screenSize, 0, "", 0]; //down
|
|
|
|
_mapCtrl drawIcon [_fillTex, [1,1,1,_shadeAlpha], [(_mousePos select 0), (_mousePos select 1) + _offsetYUp], _screenSize * 4, _screenSize * 4, 0, "", 0]; //up
|
2015-10-14 17:56:54 +00:00
|
|
|
};
|