Skip to content

Commit 1ee7ccf

Browse files
mharis001Kexanone
andauthored
Visibility - Add during placement only mode and max distance setting (#686)
* Visibility - Add during placement only mode and max distance setting * Add German translations * Fix commented out code Co-authored-by: Kex <[email protected]>
1 parent 5a4ccf6 commit 1ee7ccf

File tree

8 files changed

+122
-56
lines changed

8 files changed

+122
-56
lines changed

addons/common/functions/fnc_getPosFromScreen.sqf

+35-17
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22
/*
33
* Author: mharis001
44
* Returns a world position based on the given screen position.
5-
* Will attempt to find a flat position on an intersecting surface if enabled.
5+
* Can attempt to find a flat position on an intersecting surface if enabled.
66
*
77
* Arguments:
88
* 0: Screen Position <ARRAY> (default: getMousePosition)
9-
* 1: Check Intersections <BOOL> (default: true)
9+
* 1: Check Intersections <BOOL|NUMBER> (default: true)
10+
* - 0, false: Do not check for intersections, return position on terrain.
11+
* - 1, true: Check for intersections with surfaces.
12+
* - 2: Check for intersections and attempt to find a flat surface.
1013
*
1114
* Return Value:
1215
* Position ASL <ARRAY>
@@ -19,26 +22,41 @@
1922

2023
#define MAX_RESULTS 5
2124

22-
params [["_screenPos", getMousePosition, [[]], 2], ["_checkIntersections", true, [true]]];
25+
params [["_screenPos", getMousePosition, [[]], 2], ["_checkIntersections", true, [true, 0]]];
26+
27+
if (_checkIntersections isEqualType true) then {
28+
_checkIntersections = parseNumber _checkIntersections;
29+
};
2330

2431
if (visibleMap) then {
2532
private _ctrlMap = findDisplay IDD_RSCDISPLAYCURATOR displayCtrl IDC_RSCDISPLAYCURATOR_MAINMAP;
26-
private _pos2D = _ctrlMap ctrlMapScreenToWorld _screenPos;
27-
28-
AGLtoASL (_pos2D + [0])
33+
AGLToASL (_ctrlMap posScreenToWorld _screenPos)
2934
} else {
30-
private _position = AGLtoASL screenToWorld _screenPos;
35+
private _position = AGLToASL screenToWorld _screenPos;
3136

32-
if (_checkIntersections) then {
33-
{
34-
_x params ["_intersectPos", "_surfaceNormal"];
37+
switch (_checkIntersections) do {
38+
case 0: {
39+
_position
40+
};
41+
case 1: {
42+
lineIntersectsSurfaces [getPosASL curatorCamera, _position] param [0, []] param [0, _position]
43+
};
44+
case 2: {
45+
{
46+
_x params ["_intersectPos", "_surfaceNormal"];
3547

36-
// Use the intersection position if the surface is relatively flat
37-
if (_surfaceNormal vectorDotProduct [0, 0, 1] > 0.5) exitWith {
38-
_position = _intersectPos;
39-
};
40-
} forEach lineIntersectsSurfaces [getPosASL curatorCamera, _position, objNull, objNull, true, MAX_RESULTS, "VIEW", "FIRE", false];
41-
};
48+
// Always keep the first intersection as a fallback
49+
if (_forEachIndex == 0) then {
50+
_position = _intersectPos;
51+
};
52+
53+
// Use the intersection position if the surface is relatively flat
54+
if (_surfaceNormal vectorDotProduct [0, 0, 1] > 0.5) exitWith {
55+
_position = _intersectPos;
56+
};
57+
} forEach lineIntersectsSurfaces [getPosASL curatorCamera, _position, objNull, objNull, true, MAX_RESULTS, "VIEW", "FIRE", false];
4258

43-
_position
59+
_position
60+
};
61+
};
4462
};

addons/common/functions/fnc_selectPosition.sqf

+4-4
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ private _mouseEH = [_display, "MouseButtonDown", {
8181

8282
if (_button != 0) exitWith {};
8383

84-
private _position = [] call FUNC(getPosFromScreen);
84+
private _position = [nil, 2] call FUNC(getPosFromScreen);
8585
_thisArgs params ["_objects", "_function", "_args"];
8686

8787
[true, _objects, _position, _args, _shift, _ctrl, _alt] call _function;
@@ -94,7 +94,7 @@ private _keyboardEH = [_display, "KeyDown", {
9494

9595
if (_key != DIK_ESCAPE) exitWith {false};
9696

97-
private _position = [] call FUNC(getPosFromScreen);
97+
private _position = [nil, 2] call FUNC(getPosFromScreen);
9898
_thisArgs params ["_objects", "_function", "_args"];
9999

100100
[false, _objects, _position, _args, _shift, _ctrl, _alt] call _function;
@@ -108,7 +108,7 @@ private _drawEH = [_ctrlMap, "Draw", {
108108
params ["_ctrlMap"];
109109
_thisArgs params ["_objects", "_args", "_visuals", "_modifierFunction"];
110110

111-
private _position = [] call FUNC(getPosFromScreen);
111+
private _position = [nil, 2] call FUNC(getPosFromScreen);
112112
[_objects, _position, _args, _visuals] call _modifierFunction;
113113
_visuals params ["_text", "_icon", "_angle", "_color"];
114114

@@ -155,7 +155,7 @@ private _drawEH = [_ctrlMap, "Draw", {
155155
// No 3D drawing needed if the map is visible
156156
if (visibleMap) exitWith {};
157157

158-
private _position = [] call FUNC(getPosFromScreen);
158+
private _position = [nil, 2] call FUNC(getPosFromScreen);
159159
[_objects, _position, _args, _visuals] call _modifierFunction;
160160
_visuals params ["_text", "_icon", "_angle", "_color"];
161161

addons/context_menu/script_component.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939

4040
// _contextPosASL and _selectedObjects, _selectedGroups .., kept for BWC
4141
#define SETUP_ACTION_VARS \
42-
private _position = [GVAR(mousePos)] call EFUNC(common,getPosFromScreen); \
42+
private _position = [GVAR(mousePos), 2] call EFUNC(common,getPosFromScreen); \
4343
private _hoveredEntity = GVAR(hovered); \
4444
+GVAR(selected) params ["_objects", "_groups", "_waypoints", "_markers"]; \
4545
private _contextPosASL = _position; \

addons/visibility/XEH_postInit.sqf

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include "script_component.hpp"
22

33
["zen_curatorDisplayLoaded", {
4-
if (GVAR(enabled)) then {
4+
if (GVAR(enabled) != INDICATOR_DISABLED) then {
55
call FUNC(start);
66
};
77
}] call CBA_fnc_addEventHandler;

addons/visibility/functions/fnc_draw.sqf

+30-27
Original file line numberDiff line numberDiff line change
@@ -15,46 +15,49 @@
1515
* Public: No
1616
*/
1717

18-
if (call EFUNC(common,isInScreenshotMode)) exitWith {};
18+
if (
19+
call EFUNC(common,isInScreenshotMode)
20+
|| {GVAR(enabled) == INDICATOR_PLACEMENT_ONLY && {!call EFUNC(common,isPlacementActive)}}
21+
) exitWith {};
1922

20-
// The cursor position in the world
21-
private _pos = AGLtoASL screenToWorld getMousePosition;
22-
private _intersections = lineIntersectsSurfaces [getPosASL curatorCamera, _pos];
23-
if (_intersections isNotEqualTo []) then {
24-
_pos = _intersections select 0 select 0;
25-
};
26-
27-
// Check 1.5 above the cursor to prevent a small object on the terrain blocking the view
23+
// Get the cursor's position in the world
24+
// Check 1.5 m above the position to check for small terrain objects blocking the view
25+
// Converting to AGL here to avoid repeated conversions in the loop
26+
private _pos = [] call EFUNC(common,getPosFromScreen);
2827
private _posHigh = _pos vectorAdd [0, 0, 1.5];
29-
private _draw = false;
28+
private _posAGL = ASLToAGL _pos;
29+
30+
private _visible = false;
3031

3132
{
3233
// Check if the cursor's position is in the player's view (filter the local player and virtual units)
33-
if (_x != player && {side _x != sideLogic} && {((_x getRelDir _posHigh) + 90) mod 360 < 180}) then {
34+
if (
35+
_x != player
36+
&& {side _x != sideLogic}
37+
&& {_x distance _posAGL <= GVAR(maxDistance)}
38+
&& {
39+
private _dir = _x getRelDir _pos;
40+
_dir <= 90 || {_dir >= 270}
41+
}
42+
) then {
3443
private _eyePos = eyePos _x;
35-
if (lineIntersectsSurfaces [_eyePos, _pos, _x, objNull] isEqualTo [] || {lineIntersectsSurfaces [_eyePos, _posHigh, _x, objNull] isEqualTo []}) then {
44+
45+
if (
46+
lineIntersectsSurfaces [_eyePos, _pos, _x] isEqualTo []
47+
|| {lineIntersectsSurfaces [_eyePos, _posHigh, _x] isEqualTo []}
48+
) then {
3649
// Check visibility through smoke
3750
private _visibility = [objNull, "VIEW"] checkVisibility [_eyePos, _posHigh];
3851

3952
// Draw a line from each player that can see the cursor
40-
drawLine3D [ASLToAGL _eyePos, ASLToAGL _pos, [1, 0, 0, _visibility]];
53+
drawLine3D [ASLToAGL _eyePos, _posAGL, [1, 0, 0, _visibility]];
4154

42-
_draw = true;
55+
_visible = true;
4356
};
4457
};
4558
} forEach allPlayers;
4659

47-
// Write visible under the cursor if any player can see the position
48-
if (_draw) then {
49-
drawIcon3D [
50-
"",
51-
[1, 0, 0, 1],
52-
ASLToAGL _pos,
53-
1, 1.3, 0,
54-
LLSTRING(Visible),
55-
2,
56-
0.04,
57-
"PuristaMedium",
58-
"center"
59-
];
60+
// Write visible under the cursor if a player can see the position
61+
if (_visible) then {
62+
drawIcon3D ["", [1, 0, 0, 1], _posAGL, 1, 1.3, 0, LLSTRING(Visible), 2, 0.04, "PuristaMedium", "center"];
6063
};

addons/visibility/initSettings.sqf

+25-4
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,40 @@
11
[
22
QGVAR(enabled),
3-
"CHECKBOX",
3+
"LIST",
44
[LSTRING(Enabled), LSTRING(Enabled_Description)],
5-
ELSTRING(main,DisplayName),
6-
false,
5+
[ELSTRING(main,DisplayName), LSTRING(DisplayName)],
6+
[
7+
[
8+
INDICATOR_DISABLED,
9+
INDICATOR_ENABLED,
10+
INDICATOR_PLACEMENT_ONLY
11+
],
12+
[
13+
ELSTRING(common,Disabled),
14+
ELSTRING(common,Enabled),
15+
[LSTRING(DuringPlacementOnly), LSTRING(DuringPlacementOnly_Description)]
16+
],
17+
0
18+
],
719
false,
820
{
921
params ["_value"];
1022

1123
if (isNull findDisplay IDD_RSCDISPLAYCURATOR) exitWith {};
1224

13-
if (_value) then {
25+
if (_value != INDICATOR_DISABLED) then {
1426
call FUNC(start);
1527
} else {
1628
call FUNC(stop);
1729
};
1830
}
1931
] call CBA_fnc_addSetting;
32+
33+
[
34+
QGVAR(maxDistance),
35+
"SLIDER",
36+
[LSTRING(MaxDistance), LSTRING(MaxDistance_Description)],
37+
[ELSTRING(main,DisplayName), LSTRING(DisplayName)],
38+
[100, 5000, 5000, -1],
39+
false
40+
] call CBA_fnc_addSetting;

addons/visibility/script_component.hpp

+4
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,7 @@
1717
#include "\x\zen\addons\main\script_macros.hpp"
1818

1919
#include "\x\zen\addons\common\defineResinclDesign.inc"
20+
21+
#define INDICATOR_DISABLED 0
22+
#define INDICATOR_ENABLED 1
23+
#define INDICATOR_PLACEMENT_ONLY 2

addons/visibility/stringtable.xml

+22-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project name="ZEN">
33
<Package name="Visibility">
4-
<Key ID="STR_ZEN_Visibility_Enabled">
4+
<Key ID="STR_ZEN_Visibility_DisplayName">
55
<English>Visibility Indicator</English>
66
<French>Indicateur de visibilité</French>
77
<German>Sichtbarkeitsindikator</German>
@@ -11,8 +11,12 @@
1111
<Chinese>能见度指标</Chinese>
1212
<Italian>Indicatore di visibilità</Italian>
1313
</Key>
14+
<Key ID="STR_ZEN_Visibility_Enabled">
15+
<English>Enable Visibility Indicator</English>
16+
<German>Aktiviere den Sichtbarkeitsindikator</German>
17+
</Key>
1418
<Key ID="STR_ZEN_Visibility_Enabled_Description">
15-
<English>Indicates when a player can see the Zeus' cursor.</English>
19+
<English>Enables showing an indicator when a player can see the Zeus cursor position.</English>
1620
<French>Indique quand un joueur peut voir le curseur de Zeus.</French>
1721
<German>Zeigt an, wann ein Spieler den Zeuszeiger sehen könnte.</German>
1822
<Polish>Wskazuje czy kursor Zeusa jest widoczny dla gracza.</Polish>
@@ -21,6 +25,22 @@
2125
<Chinese>顯示玩家何時能看到宙斯的光標。</Chinese>
2226
<Italian>Indica quando un giocatore può vedere il cursore 'Zeus'</Italian>
2327
</Key>
28+
<Key ID="STR_ZEN_Visibility_DuringPlacementOnly">
29+
<English>During Placement Only</English>
30+
<German>Nur während dem Platzieren</German>
31+
</Key>
32+
<Key ID="STR_ZEN_Visibility_DuringPlacementOnly_Description">
33+
<English>Only show the indicator while placing objects.</English>
34+
<German>Zeigt den Indikator nur an während dem Platzieren</German>
35+
</Key>
36+
<Key ID="STR_ZEN_Visibility_MaxDistance">
37+
<English>Max Check Distance</English>
38+
<German>Maximale Distanz</German>
39+
</Key>
40+
<Key ID="STR_ZEN_Visibility_MaxDistance_Description">
41+
<English>Controls the maximum distance from the cursor's position that players are considered for visibility checks.</English>
42+
<German>Die Maximale Distanz zwischen dem Mauszeiger and den Spielern, bei der die Sichtbarkeit überprüft wird.</German>
43+
</Key>
2444
<Key ID="STR_ZEN_Visibility_Visible">
2545
<English>VISIBLE</English>
2646
<French>VISIBLE</French>

0 commit comments

Comments
 (0)