Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
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 
6  protected TextListboxWidget m_VicinityListbox;
7  protected ButtonWidget m_WatchItem;
8  protected EditBoxWidget m_DistanceWidget;
9  protected ref array<Object> m_VicinityItems = new array<Object>;
10 
11  protected ref ContextMenu m_ContextMenu;
12 
13  void ScriptConsoleVicinityTab(Widget root, ScriptConsole console, Widget button, ScriptConsoleTabBase parent = null)
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  {
32  UpdateSelected();
33  }
34 
35  void RenderList()
36  {
37  float radius = m_DistanceWidget.GetText().ToFloat();
38  if (!radius)
39  return;
40  array<Object> objects = new array<Object>();
41  array<CargoBase> cargo = new array<CargoBase>();
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  {
50  objects.Insert(m_Selected);
51  }
52 
53  map<int, Object> objectsMap = new map<int, Object>();
54  array<int> distances = new array<int>();
55 
56  foreach (int x, Object obj:objects)
57  {
58  int dist = vector.Distance(playerPos, obj.GetPosition()) * 1000;
59 
60  while (objectsMap.Contains(dist))//hacking for when multiple objects are at the same distance from the player, otherwise sorting using map will fail
61  dist++;
62  objectsMap.Insert(dist, obj);
63  distances.Insert(dist);
64  }
65 
66  distances.Sort();
67 
68  foreach (int dst:distances)
69  {
70  Object o = objectsMap.Get(dst);
71  if (!o)
72  continue;
73  int i = 0;
74  if (o.Type() != Object)
75  {
76  m_VicinityItems.Insert(o);//insert at the end
77  int indx = m_VicinityListbox.AddItem(o.GetType(),null,0,-1);
78  float distanceMeters = dst / 1000;
79  m_VicinityListbox.SetItem(indx, distanceMeters.ToString(),null,1);
80  i++;
81 
82  if (m_Selected == o)
83  {
84  m_VicinityListbox.SelectRow(indx);
85  }
86  }
87  }
88 
89  UpdateSelected();
90  }
91 
92  void UpdateSelected()
93  {
94  int row = m_VicinityListbox.GetSelectedRow();
95 
96  m_Selected = null;
97  if (m_VicinityItems.IsValidIndex(row))
98  {
99  m_Selected = m_VicinityItems.Get(row);
100  }
101 
102  EntityAI entity = EntityAI.Cast(m_Selected);
103  if (entity)
104  {
105  m_ContextMenu.BuildContextMenu(entity, m_VicinityListbox, this);
106 
107  m_ContextMenu.SetSize(1, 1);
108  m_ContextMenu.Show(0, 0);
109  }
110  else
111  {
112  m_ContextMenu.Hide();
113  }
114  }
115 
116  override bool OnClick(Widget w, int x, int y, int button)
117  {
118  super.OnClick(w,x,y,button);
119 
120  UpdateSelected();
121 
122  int row = m_VicinityListbox.GetSelectedRow();
123  if (w == m_WatchItem)
124  {
125  if (m_VicinityItems.IsValidIndex(row))
126  {
127  if (m_Selected)
128  {
129  PluginDeveloper.SetDeveloperItemClientEx(m_Selected);
130  return true;
131  }
132  }
133  }
134 
135  return false;
136  }
137 
138  override bool OnChange(Widget w, int x, int y, bool finished)
139  {
140  super.OnChange(w, x, y, finished);
141 
142  UpdateSelected();
143 
144  if (w == m_DistanceWidget)
145  {
146  RenderList();
147  m_Distance = m_DistanceWidget.GetText().ToFloat();
148  }
149  return false;
150  }
151 
152  void OnSelectAction(EntityAI ent, int actionId)
153  {
154  PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
155  player.GetActionManager().OnInstantAction(ActionDebug,new Param2<EntityAI,int>(ent,actionId));
156  }
157 }
Param2
Definition: ppeconstants.c:66
GetGame
proto native CGame GetGame()
m_DistanceWidget
ref TextWidget m_DistanceWidget[MAX_SIMULTANIOUS_PLAYERS]
Definition: pluginremoteplayerdebugclient.c:18
EditBoxWidget
Definition: enwidgets.c:353
y
Icon y
ActionDebug
Definition: actiondebug.c:14
m_ContextMenu
protected ref ContextMenu m_ContextMenu
Definition: inventory.c:43
PlayerBase
Definition: playerbaseclient.c:1
map
map
Definition: controlsxboxnew.c:3
vector
Definition: enconvert.c:105
Object
Definition: objecttyped.c:1
array< Object >
ScriptConsoleVicinityTab
Definition: scriptconsolevicinitytab.c:1
x
Icon x
GetPlayer
protected void GetPlayer()
Definition: crosshairselector.c:127
Widget
Definition: enwidgets.c:189
ScriptConsoleTabBase
Definition: scriptconsoletabbase.c:1
EntityAI
Definition: building.c:5