DayZ 1.24
Loading...
Searching...
No Matches
ObjectFollower.c
Go to the documentation of this file.
1class ObjectFollower extends ScriptedWidgetEventHandler
2{
4
5 protected Widget m_Root;
7 protected bool m_Visible;
8
10 {
11 m_Visible = false;
12 //GetGame().GetUpdateQueue(CALL_CATEGORY_GUI).Insert(Update);
13 }
14
16 {
17 //GetGame().GetUpdateQueue(CALL_CATEGORY_GUI).Remove(Update);
18 }
19
20 protected void OnWidgetScriptInit(Widget w)
21 {
22 m_Root = w;
23 m_Root.SetHandler(this);
24 }
25
26 void SetTarget(Object obj)
27 {
28 m_TargetObject = obj;
29 }
30
31 override bool OnUpdate(Widget w)
32 {
33 if (m_Root == w)
34 {
35 Update();
36 return true;
37 }
38
39 return false;
40 }
41
42 void Update()
43 {
44 float x, y;
45
46 if (m_Visible)
47 {
50
51 m_Root.Show(true);
52 }
53 else
54 m_Root.Show(false);
55 }
56
57 protected void GetOnScreenPosition(out float x, out float y)
58 {
59 const float DEFAULT_HANDLE_OFFSET = 0.2;
60
61 float pivotYOffset = 0.0;
62
63 bool ignorePivot = false;
64 bool traceMatched = false;
65 bool isDefaultPos = false;
66
68
70 {
72
73 traceMatched = true;
74 objectPos = m_TargetObject.GetPosition();
75 if (pivotYOffset != 0.0)
77 else
79 }
80 else
81 {
82 // default position for the action cursor
83 traceMatched = false;
84 isDefaultPos = true;
85 }
86
88 {
89 // hides the widget if we are in situation that the widget will be displayed on pivot point
90 // and we do not want to display it
91 x = 0.0;
92 y = 0.0;
93 }
94 else
95 {
96 // calculate screen position from traced results
97 if (isDefaultPos)
98 {
99 int w, h;
100 GetScreenSize(w, h);
101 x = w / 2;
102 y = h / 2;
103 }
104 else
105 {
106 vector screen_pos = GetGame().GetScreenPos(objectPos);
107 x = screen_pos[0];
108 y = screen_pos[1];
109 }
110 }
111
112 objectPos = "0 0 0";
113 isDefaultPos = false;
114 }
115}
Object m_TargetObject
Targets - types.
Icon x
Icon y
Widget m_Root
Definition SizeToChild.c:85
map: item x vector(index, width, height)
Definition EnWidgets.c:651
void OnWidgetScriptInit(Widget w)
void GetOnScreenPosition(out float x, out float y)
override bool OnUpdate(Widget w)
proto native CGame GetGame()
bool m_Visible
Definition EnEntity.c:847
proto void GetScreenSize(out int x, out int y)