From 8a47d7a9b6ee6fb62d9c631b52b3552474f8159b Mon Sep 17 00:00:00 2001 From: BaerMitUmlaut Date: Sun, 4 Sep 2016 20:50:12 +0200 Subject: [PATCH] Add fade nametags towards screen border (#4316) * Fade nametags towards screen border * Use distance2D instead of vector commands * Don't calculate fade when off screen * Made fade on border optional --- addons/nametags/ACE_Settings.hpp | 2 +- addons/nametags/CfgVehicles.hpp | 4 ++++ addons/nametags/functions/fnc_onDraw3d.sqf | 20 ++++++++++++++++++-- addons/nametags/stringtable.xml | 4 ++++ 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/addons/nametags/ACE_Settings.hpp b/addons/nametags/ACE_Settings.hpp index 354d5748bf..ab6220f131 100644 --- a/addons/nametags/ACE_Settings.hpp +++ b/addons/nametags/ACE_Settings.hpp @@ -12,7 +12,7 @@ class ACE_Settings { isClientSettable = 1; displayName = CSTRING(ShowPlayerNames); description = CSTRING(ShowPlayerNames_Desc); - values[] = {ECSTRING(common,Disabled), ECSTRING(common,Enabled), CSTRING(OnlyCursor), CSTRING(OnlyKeypress), CSTRING(OnlyCursorAndKeypress)}; + values[] = {ECSTRING(common,Disabled), ECSTRING(common,Enabled), CSTRING(OnlyCursor), CSTRING(OnlyKeypress), CSTRING(OnlyCursorAndKeypress), CSTRING(FadeOnBorder)}; category = CSTRING(Module_DisplayName); }; class GVAR(showPlayerRanks) { diff --git a/addons/nametags/CfgVehicles.hpp b/addons/nametags/CfgVehicles.hpp index 6b8b8956ae..47f530df68 100644 --- a/addons/nametags/CfgVehicles.hpp +++ b/addons/nametags/CfgVehicles.hpp @@ -28,6 +28,10 @@ class CfgVehicles { name = CSTRING(ForceShow); value = 1; }; + class ForceShowFadeOnBorder { + name = CSTRING(FadeOnBorder); + value = 5; + }; class ForceShowOnlyCursor { name = CSTRING(ForceShowOnlyCursor); value = 2; diff --git a/addons/nametags/functions/fnc_onDraw3d.sqf b/addons/nametags/functions/fnc_onDraw3d.sqf index d9d26cd0ac..7f3f04a0c4 100644 --- a/addons/nametags/functions/fnc_onDraw3d.sqf +++ b/addons/nametags/functions/fnc_onDraw3d.sqf @@ -57,6 +57,11 @@ switch (GVAR(showPlayerNames)) do { _enabledTagsNearby = (GVAR(showSoundWaves) == 2); _enabledTagsCursor = _onKeyPressAlphaMax > 0; }; + case 5: { + // Fade on border + _enabledTagsNearby = true; + _enabledTagsCursor = false; + }; }; private _ambientBrightness = ((([] call EFUNC(common,ambientBrightness)) + ([0, 0.4] select ((currentVisionMode ace_player) != 0))) min 1) max 0; @@ -132,7 +137,18 @@ if (_enabledTagsNearby) then { if !(isNull _target) then { private _relPos = (visiblePositionASL _target) vectorDiff _camPosASL; private _distance = vectorMagnitude _relPos; - private _projDist = _relPos vectorDistance (_vecy vectorMultiply (_relPos vectorDotProduct _vecy)); + + // Fade on border + private _centerOffsetFactor = 1; + if (GVAR(showPlayerNames) == 5) then { + private _screenPos = worldToScreen (_target modelToWorld (_target selectionPosition "head")); + if !(_screenPos isEqualTo []) then { + // Distance from center / half of screen width + _centerOffsetFactor = 1 - ((_screenPos distance2D [0.5, 0.5]) / (safezoneW / 3)); + } else { + _centerOffsetFactor = 0; + }; + }; private _drawSoundwave = (GVAR(showSoundWaves) > 0) && {[_target] call FUNC(isSpeaking)}; private _alphaMax = _onKeyPressAlphaMax; @@ -146,7 +162,7 @@ if (_enabledTagsNearby) then { // - decreases when _distance > _maxDistance // - increases when the unit is speaking // - it's clamped by the value of _onKeyPressAlphaMax unless soundwaves are forced on and the unit is talking - private _alpha = (((1 + ([0, 0.2] select _drawSoundwave) - 0.2 * (_distance - _maxDistance)) min 1) * GVAR(playerNamesMaxAlpha)) min _alphaMax; + private _alpha = (((1 + ([0, 0.2] select _drawSoundwave) - 0.2 * (_distance - _maxDistance)) min 1) * GVAR(playerNamesMaxAlpha) * _centerOffsetFactor) min _alphaMax; if (_alpha > 0) then { [ACE_player, _target, _alpha, _distance * 0.026, _drawName, _drawRank, _drawSoundwave] call FUNC(drawNameTagIcon); diff --git a/addons/nametags/stringtable.xml b/addons/nametags/stringtable.xml index 5f048eeb4e..c248dba636 100644 --- a/addons/nametags/stringtable.xml +++ b/addons/nametags/stringtable.xml @@ -396,5 +396,9 @@ Масштабирование размера текста и иконок Proporzione Dimensioni Testo ed Icone + + Fade on screen border + Am Bildschirmrand ausblenden +