Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
objectfollower.c
Go to the documentation of this file.
1 class ObjectFollower extends ScriptedWidgetEventHandler
2 {
3  reference int m_PivotYOffset;
4 
5  protected Widget m_Root;
6  protected Object m_TargetObject;
7  protected bool m_Visible;
8 
9  void ObjectFollower()
10  {
11  m_Visible = false;
12  //GetGame().GetUpdateQueue(CALL_CATEGORY_GUI).Insert(Update);
13  }
14 
15  void ~ObjectFollower()
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  {
48  if(m_TargetObject)
49  {
50  GetOnScreenPosition(x, y);
51  }
52 
53  m_Root.Show(true);
54  }
55  else
56  {
57  m_Root.Show(false);
58  }
59  }
60 
61  protected void GetOnScreenPosition(out float x, out float y)
62  {
63  const float DEFAULT_HANDLE_OFFSET = 0.2;
64 
65  float pivotYOffset = 0.0;
66 
67  bool ignorePivot = false;
68  bool traceMatched = false;
69  bool isDefaultPos = false;
70 
71  vector objectPos;
72 
73  if(m_TargetObject)
74  {
75  pivotYOffset = m_PivotYOffset;
76 
77  traceMatched = true;
78  objectPos = m_TargetObject.GetPosition();
79  if ( pivotYOffset != 0.0 )
80  { objectPos[1] = objectPos[1] + pivotYOffset; }
81  else
82  { objectPos[1] = objectPos[1] + DEFAULT_HANDLE_OFFSET; }
83  }
84  else
85  {
86  // default position for the action cursor
87  traceMatched = false;
88  isDefaultPos = true;
89  }
90 
91  if ( ignorePivot && !traceMatched )
92  {
93  // hides the widget if we are in situation that the widget will be displayed on pivot point
94  // and we do not want to display it
95  x = 0.0;
96  y = 0.0;
97  }
98  else
99  {
100  // calculate screen position from traced results
101  if( isDefaultPos )
102  {
103  int w,h;
104  GetScreenSize(w, h);
105  x = w/2;
106  y = h/2;
107  }
108  else
109  {
110  vector screen_pos = GetGame().GetScreenPos( objectPos );
111  x = screen_pos[0];
112  y = screen_pos[1];
113  }
114  }
115 
116  objectPos = "0 0 0";
117  isDefaultPos = false;
118  }
119 }
GetGame
proto native CGame GetGame()
OnWidgetScriptInit
void OnWidgetScriptInit(Widget w)
Definition: sizetochild.c:94
GetScreenSize
proto void GetScreenSize(out int x, out int y)
y
Icon y
SetTarget
protected void SetTarget(Object obj, vector hitPos, int hitZone)
Definition: dayzplayerimplementmeleecombat.c:519
vector
Definition: enconvert.c:105
m_Visible
bool m_Visible
Definition: enentity.c:850
OnUpdate
proto native void OnUpdate()
Definition: tools.c:349
m_TargetObject
protected Object m_TargetObject
Targets - types.
Definition: dayzplayerimplementmeleecombat.c:40
Object
Definition: objecttyped.c:1
Update
proto native volatile void Update()
Definition: playersoundmanager.c:125
x
Icon x
Widget
Definition: enwidgets.c:189
m_Root
protected Widget m_Root
Definition: sizetochild.c:91
ScriptedWidgetEventHandler
map: item x vector(index, width, height)
Definition: enwidgets.c:650