Dayz Explorer 1.28.160049
Loading...
Searching...
No Matches
pluginitemdiagnostic.c
Go to the documentation of this file.
1class PluginItemDiagnosticEventHandler extends ScriptedWidgetEventHandler
2{
4 override bool OnMouseEnter(Widget w, int x, int y)
5 {
6 if( ButtonWidget.Cast(w))
7 {
8 GetGame().GetMission().AddActiveInputExcludes({"menu"});
9 }
10 return true;
11
12 }
13
14 override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
15 {
16 if( ButtonWidget.Cast(w))
17 {
18 GetGame().GetMission().RemoveActiveInputExcludes({"menu"},true);
19 }
20
21 return true;
22 }
23
24 override bool OnClick( Widget w, int x, int y, int button )
25 {
26 return m_Owner.OnClick( w, x, y, button );
27 }
28
29 override bool OnMouseButtonDown(Widget w, int x, int y, int button)
30 {
31 return m_Owner.OnMouseButtonDown( w, x, y, button );
32 }
33
34 override bool OnMouseButtonUp(Widget w, int x, int y, int button)
35 {
36 return m_Owner.OnMouseButtonUp( w, x, y, button );
37 }
38}
39
40
41
42class PluginItemDiagnostic extends PluginDeveloper
43{
45
53 bool m_IsActive = false;
56 ref PluginItemDiagnosticEventHandler m_EventHandler;
59
61 TextListboxWidget m_DebugAgentListWidget;
65 TextListboxWidget m_DebugClientVarsWidget;
67 TextWidget m_DistanceWidget;
69 ButtonWidget m_CloseButton;
70
73
75 {
76 #ifndef NO_GUI
78 ShowWidgets(false);
79 #endif
80 }
81
83 {
85 if (m_ItemLine)
86 {
87 m_ItemLine.Destroy();
88 m_ItemLine = null;
89 }
90 }
91
92 override void OnInit()
93 {
96 {
97 vector pos = m_ConfigDebugProfile.GetItemDebugPos();
98 if (m_DebugRootWidget && pos != vector.Zero)
99 {
100 float wx = pos[0];
101 float wy = pos[1];
102 m_DebugRootWidget.SetPos(wx, wy);
103 }
104 }
105 }
106
107 bool OnMouseButtonDown(Widget w, int x, int y, int button)
108 {
109 if (button == 0)
110 SetDragging(true);
111 if (button == 1)
112 {
113 if (m_Entity)
114 {
115 float xx, yy;
116 m_DebugRootWidget.GetPos(xx,yy);
117 ContextMenu.DisplayContextMenu(x - xx, y - yy, EntityAI.Cast(m_Entity), m_DebugRootWidget, this);
118 }
119 }
120 return true;
121 }
122
123 bool OnMouseButtonUp(Widget w, int x, int y, int button)
124 {
125 if (button == 0)
126 SetDragging(false);
127 return true;
128 }
129
130 void SetDragging(bool enable)
131 {
132 if(enable && !m_IsDragging)
134 else if (!enable && m_IsDragging)
136 m_IsDragging = enable;
137 }
138
140 {
141 int mx, my;
142 float wx, wy;
143 GetMousePos(mx,my);
144 m_DebugRootWidget.GetScreenPos(wx,wy);
145 m_DraggingOffset[0] = wx - mx;
146 m_DraggingOffset[1] = wy - my;
147 }
148
150 {
151 float wx, wy;
152 m_DebugRootWidget.GetScreenPos(wx,wy);
154 {
155 m_ConfigDebugProfile.SetItemDebugPos(Vector(wx,wy,0));
156 }
157 }
158
159 bool OnClick( Widget w, int x, int y, int button )
160 {
161 SetDragging(false);
162
163 if (w == m_CloseButton)
164 {
166 return true;
167 }
168 return true;
169 }
170
172 {
173 if(!myTimer1)
174 {
175 myTimer1 = new Timer();
176 myTimer1.Run(1, this, "Tick", NULL, true);
177 }
178
179 if(m_ObserversMap.Contains(player))
180 {
181 m_ObserversMap.Set(player,item);
182 }
183 else
184 {
185 m_ObserversMap.Insert(player,item);
186 }
187 #ifdef DEVELOPER
188 SetDebugDeveloper_item(item);
189 #endif
190 }
191
193 {
194 return m_ObserversMap.Get(player);
195 }
196
197 bool IsActive()
198 {
199 return m_IsActive;
200 }
201
202 void OnScriptMenuOpened(bool opened/*1 - opened , 0 - closed*/)
203 {
204 m_ScriptMenuOpened = opened;
205 }
206
207 void ShowWidgets(bool show)
208 {
209 m_IsActive = show;
210
212 m_DebugRootWidget.Show(show);
213 }
214
215 void OnSelectAction(EntityAI ent, int actionId)
216 {
217 #ifdef DIAG_DEVELOPER
218 PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
219 player.GetActionManager().OnInstantAction(ActionDebug,new Param2<EntityAI,int>(ent,actionId));
220 #endif
221 }
222
224 {
225 GetGame().GetInput().ResetGameFocus();
226 GetGame().GetUIManager().ShowUICursor(false);
227 if (GetGame().GetUIManager())
228 {
229 if (GetGame().GetUIManager().IsDialogVisible())
230 {
231 GetGame().GetUIManager().CloseDialog();
232 }
233 }
234 }
235
237 {
238 if (m_IsActive)
239 {
240 PlayerBase player = PlayerBase.Cast(GetGame().GetPlayer());
241 GetGame().RPCSingleParam(player, ERPCs.RPC_ITEM_DIAG_CLOSE,null, true);
242 ShowWidgets(false);
243 ClearWidgets();
244
245 GetGame().GetCallQueue( CALL_CATEGORY_GUI ).CallLater( ReleaseFocus, 100);
246 //m_IsActive = false;
247 SetDragging(false);
248 }
249 else
250 {
251 ShowWidgets(true);
252 //m_IsActive = true;
253 }
254 }
255
257 {
258 m_DebugAgentListWidget.ClearItems();
259 m_DebugOutputServer.SetText("");
260 m_DebugOutputClient.SetText("");
262 m_ItemPreviewWidget.SetItem(NULL);
263 m_ClassNameWidget.SetText("");
264 }
265
266 void Tick()
267 {
268 for(int i = 0; i < m_ObserversMap.Count();i++)
269 {
270 Object item = m_ObserversMap.GetElement(i);
271 PlayerBase player = m_ObserversMap.GetKey(i);
272
273 if (item && player)
274 {
276 SendRPC(item, player);
277 }
278 else
279 {
280 Debug.LogError("PluginItemDiagnostic: dead debug record, removing record");
281 m_ObserversMap.RemoveElement(i);
282 }
283 }
284
285 }
286
288 {
289 m_Properties.Clear();
290 }
291
297
298 void SendRPC(Object item, PlayerBase player)
299 {
300 Param1<Object> p1 = new Param1<Object>(item);
301 m_Properties.InsertAt(p1,0);
302 GetGame().RPC(player,ERPCs.RPC_ITEM_DIAG,m_Properties,true,player.GetIdentity());
303
304 if (!GetGame().IsMultiplayer())
305 {
306 m_Entity = item;
307 }
308 }
309
310 void StopWatchRequest(PlayerBase player)//called from player after an RPC call
311 {
312 if( m_ObserversMap.Contains(player) )
313 {
314 m_ObserversMap.Remove(player);
315 }
316 }
317
319 {
320
321 if (!GetGame().IsMultiplayer())
322 {
323 entity = m_Entity;
324 }
325 else
326 {
327 m_Entity = entity;
328 }
329
330 ItemBase item = ItemBase.Cast(entity);
331 #ifdef DEVELOPER
332 SetDebugDeveloper_item(entity);
333 #endif
334 if(!IsActive())
335 {
336 ShowWidgets(true);
337 }
338
339 ctx.Read(CachedObjectsParams.PARAM1_STRING);
340 string debug_output_server = CachedObjectsParams.PARAM1_STRING.param1;
341 array<ref Param> vars_client;
342 array<ref Param> vars_server;
343 if (item)
344 {
345 ctx.Read(CachedObjectsParams.PARAM1_INT);//hardcoded to index 1
346 int agents_count = CachedObjectsParams.PARAM1_INT.param1;
347
348 ctx.Read(CachedObjectsParams.PARAM1_INT);//hardcoded to index 2
349 int individual_items_count = CachedObjectsParams.PARAM1_INT.param1;
350
351 FillAgentArray(ctx, agents_count);
352
353 vars_server = new array<ref Param>;
354 FillServerFinalVars(individual_items_count, ctx, vars_server);
355
356 vars_client = new array<ref Param>;
357 GetLocalProperties(item, vars_client, true);
358 }
359
360 if (EntityAI.Cast(entity))
361 {
362 DisplayAll(EntityAI.Cast(entity), vars_server, vars_client, debug_output_server );
363 }
364
365 if (GetDayZGame().IsInventoryOpen() || GetGame().GetUIManager().FindMenu(MENU_SCRIPTCONSOLE))
366 {
367 m_DebugRootWidget.SetSort(-1);
368 }
369 else
370 {
371 m_DebugRootWidget.SetSort(10);
372 }
373 m_DebugRootWidget.Show(true);
374 }
375
377 {
378 for(int i = 0; i < count; i++)
379 {
381
382 ctx.Read(p2);
383 /*
384 string name = CachedObjectsParams.PARAM2_STRING_FLOAT.param1;
385 float value = CachedObjectsParams.PARAM2_STRING_FLOAT.param2;
386 PrintString(name+","+value.ToString());
387 */
388 params.Insert(p2);
389 }
390 //PrintString("----------------------------------------------------");
391 }
392
394 {
395 m_EventHandler = new PluginItemDiagnosticEventHandler;
396 m_EventHandler.m_Owner = this;
397
399 m_DebugRootWidget = GetGame().GetWorkspace().CreateWidgets("gui/layouts/debug/debug_item.layout");
400
402
403 m_DebugAgentListWidget = TextListboxWidget.Cast(m_DebugRootWidget.FindAnyWidget("AgentsList"));
404 m_DebugOutputServer = TextWidget.Cast(m_DebugRootWidget.FindAnyWidget("DebugOutputServer"));
405 m_DebugOutputClient = TextWidget.Cast(m_DebugRootWidget.FindAnyWidget("DebugOutputClient"));
406 m_DebugFloatsProperListWidget = TextListboxWidget.Cast(m_DebugRootWidget.FindAnyWidget("FloatsProperList"));
407 m_ItemPreviewWidget = ItemPreviewWidget.Cast(m_DebugRootWidget.FindAnyWidget("ItemPreview"));
408 m_ClassNameWidget = TextWidget.Cast(m_DebugRootWidget.FindAnyWidget("ClassName"));
409 m_DistanceWidget = TextWidget.Cast(m_DebugRootWidget.FindAnyWidget("Distance"));
410 m_CloseButton = ButtonWidget.Cast(m_DebugRootWidget.FindAnyWidget("CloseButton"));
411 }
412
413 override void OnUpdate(float delta_time)
414 {
415 super.OnUpdate(delta_time);
416
417 if (!m_Entity || !m_IsActive)
418 {
419 if (m_ItemLine)
420 {
421 m_ItemLine.Destroy();
422 m_ItemLine = null;
423 }
424 return;
425 }
426
428
429 if (m_IsDragging)
430 {
431 int x,y;
432 GetMousePos(x,y);
434 }
435
436 vector pts[2];
437 pts[0] = GetGame().GetPlayer().GetPosition();
438 pts[1] = m_Entity.GetPosition();
439 if (m_ItemLine)
440 {
441 m_ItemLine.Destroy();
442 m_ItemLine = null;
443
444 }
445
446 m_ItemLine = Shape.CreateLines(COLOR_BLUE, ShapeFlags.TRANSP|ShapeFlags.NOOUTLINE|ShapeFlags.NOZBUFFER, pts, 2);
447 m_DistanceWidget.SetText(vector.Distance(pts[0], pts[1]).ToString()+"m.");
448 }
449
450 void DisplayAll(EntityAI item, array<ref Param> vars_server, array<ref Param> vars_client, string debug_text_server)
451 {
452 m_ClassNameWidget.SetText( item.GetType() );
453 m_ItemPreviewWidget.SetItem(item);
455 //UpdateFloatWidget();
456 if (vars_server && vars_client)
457 UpdateNumericalVarsWidget(vars_server, vars_client);
458 m_DebugOutputServer.SetText(debug_text_server);
459 m_DebugOutputClient.SetText(item.GetDebugText());
460 }
461
462 void FillAgentArray(ParamsReadContext ctx, int agents_count)
463 {
464 m_Agents.Clear();
465 for(int i = 0; i < agents_count; i++)
466 {
467 if(ctx.Read(CachedObjectsParams.PARAM1_STRING))
468 {
469 string agent = CachedObjectsParams.PARAM1_STRING.param1;
470 m_Agents.Insert(agent);
471 }
472 }
473 }
474
476 {
477 m_DebugAgentListWidget.ClearItems();
478 for(int i = 0; i < m_Agents.Count(); i++)
479 {
480 string agent = m_Agents.Get(i);
481 m_DebugAgentListWidget.AddItem(agent,NULL,0);
482 }
483 }
484
486 {
488 for(int i = 0; i < vars_server.Count(); i++)
489 {
490 Param param_server = vars_server.Get(i);
491 Param2<string,float> p2_server = Param2<string,float>.Cast(param_server);
492
493 Param param_client = vars_client.Get(i);
494 Param2<string,float> p2_client = Param2<string,float>.Cast(param_client);
495
496 string name = p2_server.param1;
497 m_DebugFloatsProperListWidget.AddItem(name,NULL,0);
498 m_DebugFloatsProperListWidget.SetItem(i,p2_server.param2.ToString(),NULL,1);
499 m_DebugFloatsProperListWidget.SetItem(i,p2_client.param2.ToString(),NULL,2);
500 }
501 }
502
503 void PrintOut()
504 {
505 Debug.LogArrayString(m_Agents,"ItemDebug");
506 Debug.Log("----------------------","ItemDebug");
507 }
508
509 //-------------------------
510 // QUERY FOR DEBUG PROPERTIES
511 //-------------------------
512 void GetLocalProperties(EntityAI entity, array<ref Param> properties, bool client = false)
513 {
514 if(!entity)
515 return;
516 ItemBase item = ItemBase.Cast(entity);
517
518 if(!client)
519 {
520 // -------- DEBUG OUTPUT ------
521 Param1<string> debug_output = new Param1<string>(entity.GetDebugText());
522 properties.Insert(debug_output);
523 if(!item)
524 return;
525 // -------- AGENTS ------------
526 int num_of_agents = FillWithAgents(item, properties);
527 Param1<int> agents_count = new Param1<int>(num_of_agents);
528 properties.InsertAt(agents_count,1);// hard coded index 1 !!
529 }
530 if(!item)
531 return;
532 // ------ INDIVIDUAL VARS------
533 int number_of_items = 0;
534 Param2<string, float> quantity = new Param2<string, float>("quantity", item.GetQuantity() );
535 properties.Insert(quantity);
536 number_of_items++;
537 //-----------------------------
538 Param2<string, float> liquid_type = new Param2<string, float>("liquid_type", item.GetLiquidType() );
539 properties.Insert(liquid_type);
540 number_of_items++;
541 //-----------------------------
542 Param2<string, float> wetness = new Param2<string, float>("wetness", item.GetWet() );
543 properties.Insert(wetness);
544 number_of_items++;
545 //-----------------------------
546 Param2<string, float> temperature = new Param2<string, float>("temperature", item.GetTemperature() );
547 properties.Insert(temperature);
548 number_of_items++;
549 //-----------------------------
550 Param2<string, float> frozen = new Param2<string, float>("frozen", item.GetIsFrozen() );
551 properties.Insert(frozen);
552 number_of_items++;
553 //-----------------------------
554 Param2<string, float> FTProgress = new Param2<string, float>("F/T pgs", item.GetFreezeThawProgress() );
555 properties.Insert(FTProgress);
556 number_of_items++;
557 //-----------------------------
558 #ifdef DEVELOPER
559 Param2<string, float> FTChangeTime = new Param2<string, float>("LastChangeTime", item.m_LastFTChangeTime );
560 properties.Insert(FTChangeTime);
561 number_of_items++;
562 //-----------------------------
563 Param2<string, float> FTRemainingTime = new Param2<string, float>("FTTimeRemaining", item.m_PresumedTimeRemaining );
564 properties.Insert(FTRemainingTime);
565 number_of_items++;
566 #endif
567 //-----------------------------
568 Param2<string, float> OverheatPgs = new Param2<string, float>("Overheat pgs", item.GetItemOverheatProgress() );
569 properties.Insert(OverheatPgs);
570 number_of_items++;
571 //-----------------------------
572 Edible_Base food;
573 if (Class.CastTo(food,item) && food.GetFoodStage() != null)
574 {
575 Param2<string, float> CookingTime = new Param2<string, float>("CookingTime", food.GetCookingTime() );
576 properties.Insert(CookingTime);
577 number_of_items++;
578 //-----------------------------
579 Param2<string, float> DecayTime = new Param2<string, float>("DecayTime (remaining)", food.GetDecayTimer() );
580 properties.Insert(DecayTime);
581 number_of_items++;
582 //-----------------------------
583 Param2<string, float> DecayDelta = new Param2<string, float>("DecayDelta (last)", food.GetDecayDelta() );
584 properties.Insert(DecayDelta);
585 number_of_items++;
586 }
587 //-----------------------------
588 Param2<string, float> energy = new Param2<string, float>("energy", item.GetEnergy() );
589 properties.Insert(energy);
590 number_of_items++;
591 //-----------------------------
593 if(!client)
594 {
595 health = new Param2<string, float>("health", item.GetHealth("", "") );
596 }
597 else
598 {
599 health = new Param2<string, float>("NO SYNC",0 );
600 }
601 properties.Insert(health);
602 number_of_items++;
603 //-----------------------------
604 /*int r,g,b,a;
605 item.GetColor(r,g,b,a);
606 Param2<string, float> p2r = new Param2<string, float>("R",r);
607 properties.Insert(p2r);
608 number_of_items++;
609 Param2<string, float> p2g = new Param2<string, float>("G",g);
610 properties.Insert(p2g);
611 number_of_items++;
612 Param2<string, float> p2b = new Param2<string, float>("B",b);
613 properties.Insert(p2b);
614 number_of_items++;
615 Param2<string, float> p2a = new Param2<string, float>("A",a);
616 properties.Insert(p2a);
617 number_of_items++;*/
618 //-----------------------------
619 if(!client)
620 {
621 Param1<int> item_count = new Param1<int>(number_of_items);
622 properties.InsertAt(item_count,2);
623 }
624 }
625
627 {
628 if (!item)
629 {
630 return 0;
631 }
632
633 int agents = item.GetAgents();
634 if(agents == 0) return 0;
635 int num_of_agents = 0;
636 ref array<int> agents_aray = new array<int>;
637 PluginTransmissionAgents.BuildAgentArray(agents, agents_aray);
638 int agents_count = agents_aray.Count();
639
640 for(int i = 0; i < agents_count; i++)
641 {
642 //PluginTransmissionAgents mta = PluginTransmissionAgents.Cast(GetPlugin(PluginTransmissionAgents));
643 string agent_name = PluginTransmissionAgents.GetNameByID(agents_aray.Get(i));
644 Param1<string> param1 = new Param1<string>(agent_name);
645 properties.Insert(param1);
646 num_of_agents++;
647 }
648
649 return num_of_agents;
650 }
651}
652
653
override bool OnMouseEnter(Widget w, int x, int y)
override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
EntityAI m_Entity
Definition actiondebug.c:11
int m_Agents
PlayerSpawnPresetDiscreteItemSetSlotData name
one set for cargo
Super root of all classes in Enforce script.
Definition enscript.c:11
Definition debug.c:2
float GetDecayDelta()
float GetDecayTimer()
float GetCookingTime()
override FoodStage GetFoodStage()
Base Param Class with no parameters. Used as general purpose parameter overloaded with Param1 to Para...
Definition param.c:12
Serialization general interface. Serializer API works with:
Definition serializer.c:56
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
override void Tick()
DayZGame GetDayZGame()
Definition dayzgame.c:3870
override bool OnClick(Widget w, int x, int y, int button)
buttons clicks
Definition dayzgame.c:151
void SendRPC()
ERPCs
Definition erpcs.c:2
proto native CGame GetGame()
const int COLOR_BLUE
Definition constants.c:66
ShapeFlags
Definition endebug.c:126
class DiagMenu Shape
don't call destructor directly. Use Destroy() instead
proto native vector Vector(float x, float y, float z)
Vector constructor from components.
const int MENU_SCRIPTCONSOLE
Definition constants.c:185
proto void GetMousePos(out int x, out int y)
void OnInit()
Callback for user defined initialization. Called for all suites during TestHarness....
Definition freezestate.c:81
const int CALL_CATEGORY_GUI
Definition tools.c:9
Icon x
Icon y
bool m_IsActive
PlayerBase GetPlayer()
bool IsActive()
enum ProcessDirectDamageFlags m_Owner
override void OnRPC(ParamsReadContext ctx)
void ShowWidgets(bool show)
void ToggleDebugWindowEvent()
void RegisterDebugItem(ItemBase item, PlayerBase player)
void ReleaseFocus()
void UpdateNumericalVarsWidget(array< ref Param > vars_server, array< ref Param > vars_client)
Widget m_DebugRootWidget
ref map< string, float > m_Floats
void PrintOut()
ref map< string, float > m_VarsNumbersFinalServer
void GeneratePropertiesObject(EntityAI item)
void GetLocalProperties(EntityAI entity, array< ref Param > properties, bool client=false)
TextWidget m_ClassNameWidget
void OnDraggingStart()
ref map< string, float > m_VarsFinalClient
ButtonWidget m_CloseButton
void ClearWidgets()
PluginConfigDebugProfile m_ConfigDebugProfile
TextListboxWidget m_DebugFloatsProperListWidget
TextListboxWidget m_DebugClientVarsWidget
void SetDragging(bool enable)
bool m_ScriptMenuOpened
void FillServerFinalVars(int count, ParamsReadContext ctx, array< ref Param > params)
void OnSelectAction(EntityAI ent, int actionId)
TextWidget m_DebugOutputClient
Shape m_ItemLine
ItemPreviewWidget m_ItemPreviewWidget
void InitializeWidgets()
void PluginItemDiagnostic()
int FillWithAgents(ItemBase item, array< ref Param > properties)
TextListboxWidget m_DebugAgentListWidget
void UpdateAgentWidget()
void OnScriptMenuOpened(bool opened)
ref PluginItemDiagnosticEventHandler m_EventHandler
bool m_IsDragging
void FillAgentArray(ParamsReadContext ctx, int agents_count)
ref map< PlayerBase, Object > m_ObserversMap
Object GetWatchedItem(PlayerBase player)
void StopWatchRequest(PlayerBase player)
string m_NoteClient
TextWidget m_DebugOutputServer
void ClearProperties()
void DisplayAll(EntityAI item, array< ref Param > vars_server, array< ref Param > vars_client, string debug_text_server)
void OnDraggingEnd()
vector m_DraggingOffset
void ~PluginItemDiagnostic()
ref array< ref Param > m_Properties
ref Timer myTimer1
bool OnMouseButtonDown(Widget w, int x, int y, int button)
PluginBase GetPlugin(typename plugin_type)
ref TextWidget m_DistanceWidget[MAX_SIMULTANIOUS_PLAYERS]
override bool OnMouseButtonUp(Widget w, int x, int y, int button)
Definition radialmenu.c:668