DayZ 1.24
Loading...
Searching...
No Matches
ScriptConsoleVicinityTab.c
Go to the documentation of this file.
2{
3 protected static float m_Distance = 30;
4 protected static Object m_Selected = null;
5
10
11 protected ref ContextMenu m_ContextMenu;
12
14 {
15 m_VicinityListbox = TextListboxWidget.Cast(root.FindAnyWidget("VicinityListbox"));
16 m_WatchItem = ButtonWidget.Cast(root.FindAnyWidget("WatchItemButton"));
17 m_DistanceWidget = EditBoxWidget.Cast(root.FindAnyWidget("DistanceInput"));
18
19 m_DistanceWidget.SetText(m_Distance.ToString());
20
21 m_ContextMenu = new ContextMenu();
22 m_ContextMenu.Init(root.FindAnyWidget("VicinityContextMenu"), true);
23
24 m_ContextMenu.SetSize(1, 1);
25 m_ContextMenu.Show(0, 0);
26
27 RenderList();
28 }
29
30 override void OnSelected()
31 {
33 }
34
36 {
37 float radius = m_DistanceWidget.GetText().ToFloat();
38 if (!radius)
39 return;
42
43 vector playerPos = GetGame().GetCurrentCameraPosition();
44 GetGame().GetObjectsAtPosition3D(playerPos, radius, objects, cargo);
45 m_VicinityListbox.ClearItems();
46 m_VicinityItems.Clear();
47
48 if (m_Selected && objects.Find(m_Selected) == -1)
49 objects.Insert(m_Selected);
50
53
54 foreach (int x, Object obj: objects)
55 {
56 int dist = vector.Distance(playerPos, obj.GetPosition()) * 1000;
57
58 while (objectsMap.Contains(dist))//hacking for when multiple objects are at the same distance from the player, otherwise sorting using map will fail
59 dist++;
60 objectsMap.Insert(dist, obj);
61 distances.Insert(dist);
62 }
63
64 distances.Sort();
65
66 foreach (int dst: distances)
67 {
68 Object o = objectsMap.Get(dst);
69 if (!o)
70 continue;
71 int i = 0;
72 if (o.Type() != Object)
73 {
74 m_VicinityItems.Insert(o);//insert at the end
75 int indx = m_VicinityListbox.AddItem(o.GetType(), null, 0, -1);
76 float distanceMeters = dst / 1000;
77 m_VicinityListbox.SetItem(indx, distanceMeters.ToString(), null, 1);
78 i++;
79
80 if (m_Selected == o)
81 m_VicinityListbox.SelectRow(indx);
82 }
83 }
84
86 }
87
89 {
90 int row = m_VicinityListbox.GetSelectedRow();
91
93 if (m_VicinityItems.IsValidIndex(row))
95
97 if (entity)
98 {
99 m_ContextMenu.BuildContextMenu(entity, m_VicinityListbox, this);
100
101 m_ContextMenu.SetSize(1, 1);
102 m_ContextMenu.Show(0, 0);
103 }
104 else
105 m_ContextMenu.Hide();
106 }
107
108 override bool OnClick(Widget w, int x, int y, int button)
109 {
110 super.OnClick(w, x, y, button);
111
113
114 int row = m_VicinityListbox.GetSelectedRow();
115 if (w == m_WatchItem)
116 {
117 if (m_VicinityItems.IsValidIndex(row))
118 {
119 if (m_Selected)
120 {
121 PluginDeveloper.SetDeveloperItemClientEx(m_Selected);
122 return true;
123 }
124 }
125 }
126
127 return false;
128 }
129
130 override bool OnChange(Widget w, int x, int y, bool finished)
131 {
132 super.OnChange(w, x, y, finished);
133
135
136 if (w == m_DistanceWidget)
137 {
138 RenderList();
139 m_Distance = m_DistanceWidget.GetText().ToFloat();
140 }
141 return false;
142 }
143
145 {
146#ifdef DIAG_DEVELOPER
148 player.GetActionManager().OnInstantAction(ActionDebug, new Param2<EntityAI, int>(ent, actionId));
149#endif
150 }
151}
Icon x
Icon y
PlayerBase GetPlayer()
void OnSelectAction(EntityAI ent, int actionId)
override bool OnClick(Widget w, int x, int y, int button)
ref array< Object > m_VicinityItems
void ScriptConsoleVicinityTab(Widget root, ScriptConsole console, Widget button, ScriptConsoleTabBase parent=null)
override bool OnChange(Widget w, int x, int y, bool finished)
static proto native float Distance(vector v1, vector v2)
Returns the distance between tips of two 3D vectors.
class LOD Object
proto native CGame GetGame()