Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
scriptconsoleitemstab.c
Go to the documentation of this file.
1 typedef Param3<string, bool, bool> PresetParams;// param1 - ??, param2 - ??, param3 - ??
2 
4 {
5  protected const string CONST_DEFAULT_PRESET_PREFIX = "[Default]";
6  protected static int ITEMS_SELECTED_ROW = -1;
7  protected static int PRESETS_SELECTED_ROW = 0;
8  protected static int ITEMS_IN_PRESET_SELECTED_ROW;
9  protected static float DRAW_DISTANCE = 1000;
10  protected static bool CLEAR_IVN;
11  protected static int m_ObjectsScope = 2;
12  protected static string m_LastSelectedObject;
13  protected static int m_SelectedObjectIsPreset = -1;
14  protected static ref array<Shape> m_DebugShapes = new array<Shape>;
15  protected static EntityAI m_PreviewEntity;
16  protected static float m_ItemQuantity = 1;
17  protected static bool m_WithPhysics = false;
18 
19 
20  protected ref array<Widget> m_CategoryButtonsWidgets = new array<Widget>;
21  protected ref array<string> m_CategoryButtonsNames = {"FIREARMS","MELEE","ATTACHMENTS","MAGAZINES","AMMO","FOOD","MEDICAL","CARS","BACKPACKS","B-BUILDING"};
22  protected ref map<Widget, string> m_SpawnButtonsOriginalText = new map<Widget, string>();
23  protected int m_CategoryMask;
24  protected MissionGameplay m_MissionGameplay;
25  protected ref Timer m_RefreshFilterTimer = new Timer();
26  protected PluginDeveloper m_Developer;
27  protected bool m_FilterOrderReversed;
28  protected string m_SelectedObject;
29  protected bool m_IsShiftDown;
30  protected string m_FilterTextPrev;
31  //Widgets
32  protected CheckBoxWidget m_CategoryMergeType;
33  protected CheckBoxWidget m_ItemPreviewCheckbox;
34  protected CheckBoxWidget m_ShowProtected;
35  protected CheckBoxWidget m_ClearInventory;
36  protected TextListboxWidget m_ObjectsTextListbox;
37  protected TextListboxWidget m_PresetsTextListbox;
38  protected TextListboxWidget m_PresetItemsTextListbox;
39  protected ButtonWidget m_DrawInWorld;
40  protected ButtonWidget m_DrawInWorldClear;
41  protected ButtonWidget m_PresetNewButton;
42  protected ButtonWidget m_PresetDeleteButton;
43  protected ButtonWidget m_PresetRenameButton;
44  protected ButtonWidget m_PresetSetDefaultButton;
45  protected ButtonWidget m_PresetAddItemtButton;
46  protected ButtonWidget m_ItemNameCopy;
47  protected ButtonWidget m_PresetRemoveItemButton;
48  protected ButtonWidget m_ItemMoveUpButton;
49  protected ButtonWidget m_ItemMoveDownButton;
50  protected ButtonWidget m_FilterOrderButton;
51  protected ButtonWidget m_SpawnInInvButton;
52  protected ButtonWidget m_SpawnGroundButton;
53  protected ButtonWidget m_SpawnGroundPatternGrid;
54  protected ButtonWidget m_SpawnOnTarget;
55  protected ButtonWidget m_SpawnOnCursor;
56  protected ButtonWidget m_SpawnInHands;
57  protected ButtonWidget m_SpawnBatchButton;
58  protected ButtonWidget m_ListActions;
59  protected MultilineEditBoxWidget m_ObjectFilter;
60  protected EditBoxWidget m_SpawnDistanceEditBox;
61  protected EditBoxWidget m_RectSpawnRow;
62  protected EditBoxWidget m_RectSpawnColumn;
63  protected EditBoxWidget m_RectSpawnRowStep;
64  protected EditBoxWidget m_RectSpawnColumnStep;
65  protected EditBoxWidget m_DrawDistanceWidget;
66  protected EditBoxWidget m_QuantityEditBox;
67  protected EditBoxWidget m_DamageEditBox;
68  protected EditBoxWidget m_BatchSpawnQuantity;
69  protected CheckBoxWidget m_WithPhysicsCheckbox;
70  protected TextWidget m_ItemDamageLabel;
71  protected TextWidget m_ItemQuantityLabel;
72  protected TextWidget m_SelectedObjectText;
73  protected ItemPreviewWidget m_ItemPreviewWidget;
74  protected ImageWidget m_FilterOrderImage;
75 
76 
77  void ScriptConsoleItemsTab(Widget root, ScriptConsole console, Widget button, ScriptConsoleTabBase parent = null)
78  {
79  m_Developer = PluginDeveloper.Cast(GetPlugin(PluginDeveloper));
80 
81  m_DrawInWorld = ButtonWidget.Cast(root.FindAnyWidget("ButtonDrawItem"));
82  m_DrawInWorldClear = ButtonWidget.Cast(root.FindAnyWidget("ButtonDrawItemClear"));
83 
84  m_CategoryMergeType = CheckBoxWidget.Cast(root.FindAnyWidget("CategoryMergeType"));
85  m_ItemPreviewCheckbox = CheckBoxWidget.Cast(root.FindAnyWidget("ItemPreviewCheckbox"));
86  m_ShowProtected = CheckBoxWidget.Cast(root.FindAnyWidget("ShowProtectedCheckbox"));
87  m_FilterOrderImage = ImageWidget.Cast(root.FindAnyWidget("ObjectFilterSortPic"));
88  m_ClearInventory = CheckBoxWidget.Cast(root.FindAnyWidget("ForceClearCheckbox"));
89  m_DrawDistanceWidget = EditBoxWidget.Cast(root.FindAnyWidget("DrawItemDistance"));
90  m_ObjectFilter = MultilineEditBoxWidget.Cast(root.FindAnyWidget("ObjectFilter"));
91  m_SpawnDistanceEditBox = EditBoxWidget.Cast(root.FindAnyWidget("SpawnDistance"));
92  m_SelectedObjectText = TextWidget.Cast(root.FindAnyWidget("SelectedObject"));
93  m_ObjectsTextListbox = TextListboxWidget.Cast(root.FindAnyWidget("ObjectsList"));
94  m_PresetsTextListbox = TextListboxWidget.Cast(root.FindAnyWidget("PresetList"));
95  m_PresetItemsTextListbox = TextListboxWidget.Cast(root.FindAnyWidget("PresetItemsList"));
96  m_PresetNewButton = ButtonWidget.Cast(root.FindAnyWidget("NewPresetButton"));
97  m_PresetDeleteButton = ButtonWidget.Cast(root.FindAnyWidget("DeletePresetButton"));
98  m_PresetRenameButton = ButtonWidget.Cast(root.FindAnyWidget("RenamePresetButton"));
99  m_PresetSetDefaultButton = ButtonWidget.Cast(root.FindAnyWidget("SetDefaultPresetButton"));
100  m_PresetAddItemtButton = ButtonWidget.Cast(root.FindAnyWidget("AddToPresetButton"));
101  m_ItemNameCopy = ButtonWidget.Cast(root.FindAnyWidget("ItemNameCopy"));
102  m_PresetRemoveItemButton = ButtonWidget.Cast(root.FindAnyWidget("RemoveFromPresetButton"));
103  m_ItemMoveUpButton = ButtonWidget.Cast(root.FindAnyWidget("ItemMoveUpButton"));
104  m_ItemMoveDownButton = ButtonWidget.Cast(root.FindAnyWidget("ItemMoveDownButton"));
105  m_ItemPreviewWidget = ItemPreviewWidget.Cast(root.FindAnyWidget("ItemPreviewWidget"));
106 
107  m_QuantityEditBox = EditBoxWidget.Cast(root.FindAnyWidget("QuantityValue"));
108  m_DamageEditBox = EditBoxWidget.Cast(root.FindAnyWidget("DamageValue"));
109  m_ItemDamageLabel = TextWidget.Cast(root.FindAnyWidget("DamageLabel"));
110  m_ItemQuantityLabel = TextWidget.Cast(root.FindAnyWidget("QuantityLabel"));
111  m_WithPhysicsCheckbox = CheckBoxWidget.Cast(root.FindAnyWidget("WithPhysicsCheckbox"));
112 
113  m_SpawnInInvButton = ButtonWidget.Cast(root.FindAnyWidget("ButtonSpawnInInv"));
114  m_SpawnGroundButton = ButtonWidget.Cast(root.FindAnyWidget("ButtonSpawnInGround"));
115  m_SpawnOnTarget = ButtonWidget.Cast(root.FindAnyWidget("ButtonSpawnInTarget"));
116  m_SpawnOnCursor = ButtonWidget.Cast(root.FindAnyWidget("ButtonSpawnCursor"));
117  m_SpawnInHands = ButtonWidget.Cast(root.FindAnyWidget("ButtonSpawnHands"));
118  m_SpawnBatchButton = ButtonWidget.Cast(root.FindAnyWidget("ButtonSpawnBatch"));
119 
120  string text;
121  m_SpawnInInvButton.GetText(text);
122  m_SpawnButtonsOriginalText.Insert(m_SpawnInInvButton, text);
123  m_SpawnGroundButton.GetText(text);
124  m_SpawnButtonsOriginalText.Insert(m_SpawnGroundButton, text);
125  m_SpawnOnTarget.GetText(text);
126  m_SpawnButtonsOriginalText.Insert(m_SpawnOnTarget, text);
127  m_SpawnOnCursor.GetText(text);
128  m_SpawnButtonsOriginalText.Insert(m_SpawnOnCursor, text);
129  m_SpawnInHands.GetText(text);
130  m_SpawnButtonsOriginalText.Insert(m_SpawnInHands, text);
131  m_SpawnBatchButton.GetText(text);
132  m_SpawnButtonsOriginalText.Insert(m_SpawnBatchButton, text);
133 
134  m_ListActions = ButtonWidget.Cast(root.FindAnyWidget("ListActions"));
135 
136 
137  m_RectSpawnColumn = EditBoxWidget.Cast(root.FindAnyWidget("RectangleColumnValue"));
138  m_RectSpawnRow = EditBoxWidget.Cast(root.FindAnyWidget("RectangleRowValue"));
139  m_BatchSpawnQuantity = EditBoxWidget.Cast(root.FindAnyWidget("BatchCount"));
140 
141  m_RectSpawnColumnStep = EditBoxWidget.Cast(root.FindAnyWidget("RectangleStepXValue"));
142  m_RectSpawnRowStep = EditBoxWidget.Cast(root.FindAnyWidget("RectangleStepYValue"));
143 
144  m_FilterOrderButton = ButtonWidget.Cast(root.FindAnyWidget("ObjectFilterSortButton"));
145  Init();
146  }
147 
148  void ~ScriptConsoleItemsTab()
149  {
150  ITEMS_SELECTED_ROW = m_ObjectsTextListbox.GetSelectedRow();
151  PRESETS_SELECTED_ROW = m_PresetsTextListbox.GetSelectedRow();
152  ITEMS_IN_PRESET_SELECTED_ROW = m_PresetItemsTextListbox.GetSelectedRow();
153 
154  m_PresetsTextListbox.ClearItems();
155 
156  if (m_PreviewEntity)
157  {
158  m_PreviewEntity.Delete();
159  }
160 
161  m_RefreshFilterTimer.Stop();
162 
164  {
165  m_ConfigDebugProfile.SetItemCategoryFlag(m_CategoryMask);
166  }
167 
168  m_ItemQuantity = m_QuantityEditBox.GetText().ToFloat();
169  m_WithPhysics = m_WithPhysicsCheckbox.IsChecked();
170  }
171 
172 
173 
174  protected void Init()
175  {
176  m_RefreshFilterTimer.Run(0.85, this, "ChangeFilterItems", null, true);
177  m_PresetDeleteButton.Show(false);
178  m_PresetRenameButton.Show(false);
179  m_DrawDistanceWidget.SetText(DRAW_DISTANCE.ToString());
180 
181  m_QuantityEditBox.SetText(m_ItemQuantity.ToString());
182  m_WithPhysicsCheckbox.SetChecked(m_WithPhysics);
183 
185  {
186  string txt = (m_ConfigDebugProfile.GetItemSearch());
187  m_ObjectFilter.SetText(m_ConfigDebugProfile.GetItemSearch());
188  m_SpawnDistanceEditBox.SetText(m_ConfigDebugProfile.GetSpawnDistance().ToString());
189 
190 
191  SetFilterOrder(m_ConfigDebugProfile.GetFilterOrderReversed());
192  //m_ConfigDebugProfile.SetItemCategoryFlag(m_CategoryMask);
193 
194  m_BatchSpawnQuantity.SetText(m_ConfigDebugProfile.GetBatchSpawnQuantity().ToString());
195 
196  m_CategoryMask = m_ConfigDebugProfile.GetItemCategoryFlag();
197  if (m_ItemPreviewCheckbox)
198  {
199  m_ItemPreviewCheckbox.SetChecked(m_ConfigDebugProfile.GetShowItemPreview());
200  }
201 
202  array<ref CfgParam> params = m_ConfigDebugProfile.GetBatchSpawnRectangle();
203 
204  m_RectSpawnRow.SetText(CfgParamInt.Cast(params.Get(0)).GetValue().ToString());
205  m_RectSpawnColumn.SetText(CfgParamInt.Cast(params.Get(1)).GetValue().ToString());
206  m_RectSpawnRowStep.SetText(CfgParamFloat.Cast(params.Get(2)).GetValue().ToString());
207  m_RectSpawnColumnStep.SetText(CfgParamFloat.Cast(params.Get(3)).GetValue().ToString());
208  }
209 
210 
211  if (m_ObjectsScope == 1)
212  m_ShowProtected.SetChecked(true);
213  else
214  m_ShowProtected.SetChecked(false);
215 
216  int counter = 0;
217  foreach (string name: m_CategoryButtonsNames)
218  {
219  string widget_name = "ItemCategory" + counter;
220 
221  CheckBoxWidget btw = CheckBoxWidget.Cast(m_ParentRoot.FindAnyWidget(widget_name));
222  if (btw)
223  {
224  btw.SetText(name);
225  m_CategoryButtonsWidgets.Insert(btw);
226  int bit = 1 << counter;
227  if (bit & m_CategoryMask)
228  {
229  btw.SetChecked(true);
230  btw.SetTextColor(ARGB(255, 255, 0, 0));
231  }
232  }
233  counter++;
234  }
235 
236  if (ITEMS_IN_PRESET_SELECTED_ROW <= m_PresetItemsTextListbox.GetNumItems() && m_PresetItemsTextListbox.GetNumItems() > 0 && ITEMS_IN_PRESET_SELECTED_ROW > -1)
237  {
238  m_PresetItemsTextListbox.SelectRow(ITEMS_IN_PRESET_SELECTED_ROW);
239  m_PresetItemsTextListbox.EnsureVisible(ITEMS_IN_PRESET_SELECTED_ROW);
240 
241  m_SelectedObjectText.SetText("Object : " + GetCurrentItemName());
242  SetObject(GetCurrentItemName());
243  m_SelectedObjectIsPreset = 0;
244  }
245 
246  ChangeFilterItems(true);
247 
248  RenderPresets();
249  //RenderPresetItems();
250 
251  m_MissionGameplay = MissionGameplay.Cast(GetGame().GetMission());
252 
253  if (!m_SelectedObjectIsPreset == 1 && ITEMS_SELECTED_ROW < m_ObjectsTextListbox.GetNumItems() && m_ObjectsTextListbox.GetNumItems() > 0 && ITEMS_SELECTED_ROW > -1)
254  {
255  m_ObjectsTextListbox.SelectRow(ITEMS_SELECTED_ROW);
256  m_ObjectsTextListbox.EnsureVisible(ITEMS_SELECTED_ROW);
257 
258 
259  m_SelectedObjectText.SetText(GetCurrentObjectName());
260 
261 
262  SetObject(GetCurrentObjectName());
263  m_LastSelectedObject = m_SelectedObject;
264  m_PresetItemsTextListbox.SelectRow(-1);
265  m_SelectedObjectIsPreset = 0;
266  }
267 
268  if (m_PresetsTextListbox.GetNumItems() >= 0)
269  {
270  m_PresetsTextListbox.SelectRow(PRESETS_SELECTED_ROW);
271  m_PresetsTextListbox.EnsureVisible(PRESETS_SELECTED_ROW);
272  if (m_SelectedObjectIsPreset == 1)
273  SelectPreset();
274  else
275  RenderPresetItems();
276  }
277 
278  if (m_ObjectsScope == 1)
279  m_ShowProtected.SetChecked(true);
280  else
281  m_ShowProtected.SetChecked(false);
282 
283 
284  m_CategoryMergeType.SetChecked(m_ConfigDebugProfile.GetMergeType());
285 
286  HideItemButtons();
287  ShowItemTransferButtons();
288  }
289 
290  static void DrawItems(string type, float distance = 0)
291  {
292  if (!distance)
293  {
294  distance = DRAW_DISTANCE;
295  }
296  array<Object> objects = new array<Object>;
297  array<CargoBase> proxies = new array<CargoBase>;
298 
299  GetGame().GetObjectsAtPosition(GetGame().GetPlayer().GetPosition(), distance, objects, proxies);
300  int i = 0;
301  foreach (Object o: objects)
302  {
303  if (o.IsKindOf(type))
304  {
305  i++;
306  ScriptConsole.m_MarkedEntities.Insert(new MapMarker(o.GetPosition(),"",COLOR_RED,eMapMarkerTypes.MARKERTYPE_MAP_BORDER_CROSS));
307  Shape shape = Shape.CreateSphere(COLOR_RED, ShapeFlags.TRANSP|ShapeFlags.NOOUTLINE|ShapeFlags.NOZBUFFER, o.GetPosition() + "0 30 0", 1);
308  vector lines[2];
309  lines[0] = o.GetPosition();
310  lines[1] = o.GetPosition() + "0 30 0";
311  Shape line = Shape.CreateLines(COLOR_RED, ShapeFlags.TRANSP|ShapeFlags.NOOUTLINE|ShapeFlags.NOZBUFFER, lines, 2);
312  m_DebugShapes.Insert(shape);
313  m_DebugShapes.Insert(line);
314  }
315  }
316 
318  //GetGame().GetCallQueue(CALL_CATEGORY_GAMEPLAY).CallLaterByName(this, "DrawItemsClear", 5000);
319  Debug.Log(string.Format("found %1 instances of type %1", i, type));
320  }
321 
322 
323  static void DrawItemsClear()
324  {
325  ScriptConsole.m_MarkedEntities.Clear();
326  foreach (Shape s: m_DebugShapes)
327  {
328  s.Destroy();
329  }
330  m_DebugShapes.Clear();
331  }
332 
334  static string GetLastSelectedObject()
335  {
336  return m_LastSelectedObject;
337  }
338 
339  override bool OnKeyDown(Widget w, int x, int y, int key)
340  {
341  if (key == KeyCode.KC_D && m_SelectedObject != "")
342  {
343  DrawItems(m_SelectedObject);
344  return true;
345  }
346  else
347  return super.OnKeyDown(w, x, y, key);
348  }
349 
350  void SelectObject(bool hide_presets = true)
351  {
352  if (hide_presets)
353  m_PresetItemsTextListbox.SelectRow(-1);
354  HideItemButtons();
355  ShowItemTransferButtons();
356  m_SelectedObjectText.SetText(GetCurrentObjectName());
357  SetObject(GetCurrentObjectName());
358 
359  m_LastSelectedObject = m_SelectedObject;
360  m_SelectedObjectIsPreset = 0;
361  }
362 
363 
364  void SelectPreset()
365  {
366  m_ObjectsTextListbox.SelectRow(-1);
367  RenderPresetItems();
368  ShowPresetButtons();
369  ShowItemTransferButtons();
370  m_SelectedObject = GetCurrentPresetName();
371  m_SelectedObjectText.SetText("Preset : " + m_SelectedObject);
372  m_SelectedObjectIsPreset = 1;
373 
374  TStringArray command_array = new TStringArray;
375 
376  m_ConfigDebugProfileFixed.GetPresetItems(m_SelectedObject, command_array, "cmd");
377 
378  bool clear = !IsPresetFixed(m_SelectedObject);
379  if (command_array.IsValidIndex(0))
380  {
381  string first_line = command_array.Get(0);
382  first_line.ToLower();
383  clear = (first_line == "clear_inv");
384  }
385 
386  m_ClearInventory.SetChecked(clear);
387  }
388 
389  int GetCurrentPresetIndex()
390  {
391  return m_PresetsTextListbox.GetSelectedRow();
392  }
393 
394  int GetCurrentItemIndex()
395  {
396  return m_PresetItemsTextListbox.GetSelectedRow();
397  }
398 
399  bool IsCurrentPresetFixed()
400  {
401  int index = GetCurrentPresetIndex();
402  if (index > -1 && index < m_PresetsTextListbox.GetNumItems())
403  {
404  PresetParams item_params_array;
405  m_PresetsTextListbox.GetItemData(index, 0, item_params_array);
406  return item_params_array.param2;
407  }
408  return false;
409  }
410 
411  bool IsPresetFixed(string preset_name)
412  {
413  int preset_index = GetPresetIndexByName(preset_name);
414  PresetParams item_params_array;
415  if (preset_index > -1 && preset_index < m_PresetsTextListbox.GetNumItems())
416  {
417  m_PresetsTextListbox.GetItemData(preset_index, 0, item_params_array);
418  return item_params_array.param2;
419  }
420  return false;
421  }
422 
423  int GetPresetIndexByName(string preset_name)
424  {
425  int i;
426  for (i = 0; i < m_PresetsTextListbox.GetNumItems(); i++)
427  {
428  PresetParams item_params_array;
429  m_PresetsTextListbox.GetItemData(i, 0, item_params_array);
430 
431  if (item_params_array.param1 == preset_name)
432  {
433  return i;
434  }
435  }
436  return -1;
437  }
438 
439  void ShowItemButtons()
440  {
441  if (!IsCurrentPresetFixed())
442  {
443  ShowItemTransferButtons();
444 
445  string preset_name = GetCurrentPresetName();
446  int item_index = GetCurrentItemIndex();
447 
448  m_ItemMoveUpButton.Show(true);
449  m_ItemMoveDownButton.Show(true);
450 
451  m_ItemDamageLabel.Show(true);
452  m_ItemQuantityLabel.Show(true);
453 
454  if (preset_name != "" && item_index > -1)
455  {
456  m_DamageEditBox.Show(true);
457  m_QuantityEditBox.Show(true);
458  m_WithPhysicsCheckbox.Show(true);
459 
460  float item_health= m_ConfigDebugProfile.GetItemHealth(GetCurrentPresetName(), GetCurrentItemIndex());
461  int item_quantity = m_ConfigDebugProfile.GetItemQuantity(GetCurrentPresetName(), GetCurrentItemIndex());
462  bool item_with_physics = m_ConfigDebugProfile.GetItemWithPhysics(GetCurrentPresetName(), GetCurrentItemIndex());
463 
464  // damage
465  m_DamageEditBox.SetText(item_health.ToString());
466 
467  // quantity
468  m_QuantityEditBox.SetText(item_quantity.ToString());
469 
470  // with physics
471  m_WithPhysicsCheckbox.SetChecked(item_with_physics);
472  }
473  else
474  {
475  m_DamageEditBox.Show(false);
476  m_QuantityEditBox.Show(false);
477  m_WithPhysicsCheckbox.Show(false);
478 
479  }
480  }
481  }
482 
483  void HideItemButtons()
484  {
485  m_ItemMoveUpButton.Show(false);
486  m_ItemMoveDownButton.Show(false);
487  }
488 
489  void ShowItemTransferButtons()
490  {
491  int object_row = m_ObjectsTextListbox.GetSelectedRow();
492  if (object_row >-1 && GetCurrentPresetIndex() >-1 && !IsCurrentPresetFixed())
493  {
494  m_PresetAddItemtButton.Show(true);
495  }
496  else
497  {
498  m_PresetAddItemtButton.Show(false);
499  }
500 
501  if (GetCurrentItemIndex() >-1 && GetCurrentPresetIndex() >-1 && !IsCurrentPresetFixed())
502  {
503  m_PresetRemoveItemButton.Show(true);
504  }
505  else
506  {
507  m_PresetRemoveItemButton.Show(false);
508  }
509 
510  if (object_row > -1)
511  {
512  m_ItemNameCopy.Show(true);
513  }
514  else
515  {
516  m_ItemNameCopy.Show(false);
517  }
518 
519  }
520 
521  void ItemMoveUp()
522  {
523  int new_index = GetCurrentItemIndex() - 1;
524  if (GetCurrentItemIndex() != -1 && GetCurrentPresetIndex() != -1 && new_index > -1)
525  {
526  m_ConfigDebugProfile.SwapItem(GetCurrentPresetName(), GetCurrentItemIndex(), new_index);
527  RenderPresetItems();
528  m_PresetItemsTextListbox.SelectRow (new_index);
529  }
530  }
531 
532  void ItemMoveDown()
533  {
534  int new_index = GetCurrentItemIndex() + 1;
535  if (GetCurrentItemIndex() != -1 && GetCurrentPresetIndex() != -1 && new_index < m_PresetItemsTextListbox.GetNumItems())
536  {
537  m_ConfigDebugProfile.SwapItem(GetCurrentPresetName(), GetCurrentItemIndex(), new_index);
538  RenderPresetItems();
539  m_PresetItemsTextListbox.SelectRow (new_index);
540  }
541  }
542 
543 
544  void SaveProfileSpawnDistance()
545  {
546  if (m_ConfigDebugProfile && m_SpawnDistanceEditBox)
547  {
548  m_ConfigDebugProfile.SetSpawnDistance(m_SpawnDistanceEditBox.GetText().ToFloat());
549  }
550  }
551 
552  void RenamePreset(string new_preset_name)
553  {
554  if (new_preset_name && GetCurrentPresetIndex() != -1)
555  {
556  bool result = m_ConfigDebugProfile.PresetRename(GetCurrentPresetName(), new_preset_name);
557  RefreshLists();
558  }
559  }
560 
561 
562  void SpawnPreset(EntityAI target, bool clear_inventory, string preset_name, InventoryLocationType location = InventoryLocationType.ATTACHMENT, float distance = 0)
563  {
564  // spawn preset items into inventory
565  PlayerBase player = PlayerBase.Cast(GetGame().GetPlayer());
566  if (GetCurrentPresetIndex() != -1)
567  {
568  bool is_preset_fixed = IsCurrentPresetFixed();
569  TStringArray preset_array = new TStringArray;
570 
571  if (is_preset_fixed)
572  {
573  m_ConfigDebugProfileFixed.GetPresetItems(preset_name, preset_array);
574 
575  }
576  else
577  {
578  m_ConfigDebugProfile.GetPresetItems(preset_name, preset_array);
579  }
580 
581  if (clear_inventory)
582  {
583  m_Developer.ClearInventory(target);
584  }
585 
586  for (int i = 0; i < preset_array.Count(); i++)
587  {
588  float health = -1;
589  int quantity = 1;
590  bool with_physics = false;
591  if (is_preset_fixed)
592  {
593  health = m_ConfigDebugProfileFixed.GetItemHealth(preset_name, i);
594  quantity = m_ConfigDebugProfileFixed.GetItemQuantity(preset_name, i);
595  with_physics = m_ConfigDebugProfileFixed.GetItemWithPhysics(preset_name, i);
596  }
597  else
598  {
599  health = m_ConfigDebugProfile.GetItemHealth(preset_name, i);
600  quantity = m_ConfigDebugProfile.GetItemQuantity(preset_name, i);
601  with_physics = m_ConfigDebugProfile.GetItemWithPhysics(preset_name, i);
602  }
603  if (location == InventoryLocationType.ATTACHMENT)
604  EntityAI ent = m_Developer.SpawnEntityInInventory(target, preset_array.Get(i), -1, quantity, false, preset_name);
605  //m_Developer.SpawnEntityAsAttachment(player, target, preset_array.Get(i), -1, quantity, false, preset_name);
606  else if (location == InventoryLocationType.GROUND)
607  {
608  m_Developer.SpawnEntityOnCursorDir(player, preset_array.Get(i), quantity, distance, health, false, preset_name, with_physics);
609  }
610  }
611  if (GetGame().IsMultiplayer())
612  {
613  ScriptRPC rpc = new ScriptRPC();
614  rpc.Write(preset_name);
615  rpc.Write(target);
616  rpc.Send(player, ERPCs.DEV_RPC_SPAWN_PRESET, true, player.GetIdentity());
617  }
618  else
619  {
620  PluginDeveloper plugin = PluginDeveloper.Cast(GetPlugin(PluginDeveloper));
621  plugin.HandlePresetSpawn(player,preset_name,target);
622  }
623  }
624  }
625 
626  void SetDefaultPreset(int preset_index)
627  {
628  // remove previous default parameter
629  string default_preset = m_ConfigDebugProfile.GetDefaultPreset();
630  if (default_preset != "")
631  {
632  int index = GetPresetIndexByName(default_preset);
633  // if is fixed
634  if (IsPresetFixed(default_preset))
635  {
636  default_preset = "[" + default_preset + "]";
637  }
638  PresetParams prev_preset_params_array;
639  if (index > -1 && index < m_PresetsTextListbox.GetNumItems())
640  {
641  m_PresetsTextListbox.GetItemData(index, 0, prev_preset_params_array);
642  prev_preset_params_array.param3 = false; // remove DEFAULT
643  m_PresetsTextListbox.SetItem(index, default_preset, prev_preset_params_array, 0);
644  }
645  }
646 
647  // set preset on preset_index to default
648  // if is fixed
649  string preset_name = GetCurrentPresetName();
650  if (IsPresetFixed(preset_name))
651  {
652  preset_name = "[" + preset_name + "]";
653  }
654  // set new default preset
655  PresetParams preset_params_array;
656  index = GetCurrentPresetIndex();
657  if (index > -1 && index < m_PresetsTextListbox.GetNumItems())
658  {
659  m_PresetsTextListbox.GetItemData(index, 0, preset_params_array);
660  preset_params_array.param3 = true; // DEFAULT
661  m_PresetsTextListbox.SetItem(index, preset_name + CONST_DEFAULT_PRESET_PREFIX, preset_params_array, 0);
662  }
663  // store preset
664  m_ConfigDebugProfile.SetDefaultPreset(GetCurrentPresetName());
665  }
666 
667  void SetObject(string object)
668  {
669  m_SelectedObject = object;
670 
671  if (m_ConfigDebugProfile && m_ConfigDebugProfile.GetShowItemPreview())
672  {
673  SetPreviewObject(object);
674  }
675 
676  }
677 
678  void SetPreviewObject(string object)
679  {
680  #ifdef DEVELOPER
681  if (m_PreviewEntity)
682  {
683  m_PreviewEntity.Delete();
684  }
685 
686  if (!GetGame().IsKindOf(object, "DZ_LightAI") && !GetGame().IsKindOf(object, "Man"))
687  {
688  DayZGame.m_IsPreviewSpawn = true;
690  m_PreviewEntity = EntityAI.Cast(GetGame().CreateObjectEx(object, "0 0 0", ECE_LOCAL | ECE_CREATEPHYSICS | ECE_TRACE));
691  DayZGame.m_IsPreviewSpawn = false;
692  if (m_PreviewEntity)
693  {
694  dBodyDestroy(m_PreviewEntity);//prevents cars from acting up when spawned this way(we only want the preview pic, no physics required)
695  m_PreviewEntity.DisableSimulation(true);
696  m_ItemPreviewWidget.SetItem(m_PreviewEntity);
697  m_PreviewEntity.SetAllowDamage(false);
698  }
699  }
700  #endif
701  }
702 
703  void AddItemToPreset()
704  {
705  int selected_row_index = m_ObjectsTextListbox.GetSelectedRow();
706  if (selected_row_index != -1 && GetCurrentPresetIndex() != -1)
707  {
708  string item_name;
709  m_ObjectsTextListbox.GetItemText(selected_row_index, 0, item_name);
710  m_ConfigDebugProfile.ItemAddToPreset(GetCurrentPresetName(), item_name);
711  RenderPresetItems();
712  }
713  }
714 
715  void ShowPresetButtons()
716  {
717  bool show = true;
718  if (IsCurrentPresetFixed())
719  {
720  show = false;
721  }
722  m_PresetDeleteButton.Show(show);
723  m_PresetRenameButton.Show(show);
724 
725  HideItemButtons();
726 
727  }
728 /*
729  void AddItemToClipboard(TextListboxWidget text_listbox_widget)
730  {
731  int selected_row_index = text_listbox_widget.GetSelectedRow();
732  if (selected_row_index != -1)
733  {
734  string item_name;
735  text_listbox_widget.GetItemText(selected_row_index, 0, item_name);
736  GetGame().CopyToClipboard(item_name);
737  }
738  }*/
739 
740  void RemoveItemFromPreset()
741  {
742  if (GetCurrentItemIndex() != -1 && GetCurrentPresetIndex() != -1)
743  {
744  m_ConfigDebugProfile.ItemRemoveFromPreset(GetCurrentPresetName(), GetCurrentItemIndex());
745  RenderPresetItems();
746  }
747  }
748 
749  string GetCurrentPresetName()
750  {
751  int index = GetCurrentPresetIndex();
752  // load preset items list
753  if (index > -1 && index < m_PresetsTextListbox.GetNumItems())
754  {
755  PresetParams item_params_array;
756  m_PresetsTextListbox.GetItemData(index, 0, item_params_array);
757  return item_params_array.param1;
758  }
759  return "";
760  }
761 
762  string GetCurrentItemName()
763  {
764  if (GetCurrentItemIndex() != -1)
765  {
766  string item_name;
767  m_PresetItemsTextListbox.GetItemText(GetCurrentItemIndex(), 0, item_name);
768  return item_name;
769  }
770  return "";
771  }
772 
773  string GetCurrentObjectName()
774  {
775  int selected_row_index = m_ObjectsTextListbox.GetSelectedRow();
776  if (selected_row_index != -1)
777  {
778  string item_name;
779  m_ObjectsTextListbox.GetItemText(selected_row_index, 0, item_name);
780  return item_name;
781  }
782  return "";
783  }
784 
785  void RefreshLists()
786  {
787  RenderPresets();
788  RenderPresetItems();
789  }
790 
791  // Render specific Preset Items
792  void RenderPresets()
793  {
794  m_PresetsTextListbox.ClearItems();
795 
796  int i;
797  TBoolArray preset_params;
798 
799  // load custom presets list
800  TStringArray custom_presets_array = m_ConfigDebugProfile.GetPresets();
801  for (i = custom_presets_array.Count() - 1; i >= 0; i--)
802  {
803  m_PresetsTextListbox.AddItem(custom_presets_array.Get(i), new PresetParams (custom_presets_array.Get(i),false, false), 0);
804  }
805 
806  // load fixed presets list
807  TStringArray presets_array = m_ConfigDebugProfileFixed.GetPresets();
808  for (i = 0; i < presets_array.Count(); i++)
809  {
810  m_PresetsTextListbox.AddItem("["+presets_array.Get(i)+"]", new PresetParams (presets_array.Get(i), true, false), 0);
811  }
812  string default_preset = m_ConfigDebugProfile.GetDefaultPreset();
813  if (default_preset != "")
814  {
815  // if is fixed
816  int index = GetPresetIndexByName(default_preset);
817  if (IsPresetFixed(default_preset))
818  {
819  default_preset = "[" + default_preset + "]";
820  }
821  PresetParams preset_params_array;
822  if (index > -1 && index < m_PresetsTextListbox.GetNumItems())
823  {
824  m_PresetsTextListbox.GetItemData(index, 0, preset_params_array);
825  m_PresetsTextListbox.SetItem(index, default_preset + CONST_DEFAULT_PRESET_PREFIX, preset_params_array, 0);
826  }
827  }
828  }
829 
830  // Render specific Preset Items
831  void RenderPresetItems()
832  {
833  // load preset items list
834  int i;
835  m_PresetItemsTextListbox.ClearItems();
836  if (GetCurrentPresetIndex() != -1)
837  {
838  bool isFixed = IsCurrentPresetFixed();
839  TStringArray preset_array = new TStringArray;
840 
841  if (isFixed)
842  {
843  m_ConfigDebugProfileFixed.GetPresetItems(GetCurrentPresetName(), preset_array);
844  }
845  else
846  {
847  m_ConfigDebugProfile.GetPresetItems(GetCurrentPresetName(), preset_array);
848  }
849 
850  if (preset_array)
851  {
852  for (i = 0; i < preset_array.Count(); i++)
853  {
854  m_PresetItemsTextListbox.AddItem(preset_array.Get(i), NULL, 0);
855  }
856  }
857  }
858  }
859 
860  void NewPreset(string preset_name)
861  {
862  m_ConfigDebugProfile.PresetAdd(preset_name);
863  RefreshLists();
864  }
865 
866  void DeletePreset()
867  {
868  if (GetCurrentPresetIndex() != -1)
869  {
870  bool result = m_ConfigDebugProfile.PresetRemove(GetCurrentPresetName());
871  RefreshLists();
872  }
873  }
874 
875  int GetFilterColor(string color)
876  {
877  switch (color)
878  {
879  case "r":
880  return ARGB(255,255,0,0);
881  case "g":
882  return ARGB(255,0,255,0);
883  case "b":
884  return ARGB(255,130,130,255);
885  case "y":
886  return ARGB(255,255,255,0);
887  case "o":
888  return ARGB(255,255,169,0);
889  }
890  return -1;//white
891  }
892 
893  void PrepareFilters(string filter, out TStringArray filters, out TIntArray colors)
894  {
895  filter.Trim();
896  filter.ToLower();
897 
898  filters = new TStringArray;
899  TStringArray rawFilters = new TStringArray;
900  filter.Split(" ", rawFilters);
901 
902  colors = new TIntArray;
903 
904 
905  foreach (int i, string f:rawFilters)
906  {
907  int color = -1;
908  if (f.IndexOf(":") == 1)//detect color prefix
909  {
910  string clr = f.Substring(0, 1);
911  f = f.Substring(2, f.Length() - 2);//crop off color prefix
912  color = GetFilterColor(clr);
913  }
914  else//autocolor
915  {
916  if (i%2 == 1)
917  {
918  color = ARGB(200,255,255,255);
919  }
920  }
921  filters.Insert(f);
922  colors.Insert(color);
923  }
924  }
925 
926 
927  void ChangeFilter(TStringArray classes, TextListboxWidget widget, MultilineEditBoxWidget filterWidget, int categoryMask = -1, bool ignoreScope = false)
928  {
929  widget.ClearItems();
930 
931  TStringArray filters;
932  TIntArray filterColors;
933 
934  string widgetText;
935  filterWidget.GetText(widgetText);
936  PrepareFilters(widgetText, filters, filterColors);
937 
938  map<string,int> itemsAndColors = new map<string,int>();
940 
941  TStringArray itemsArray = TStringArray();
942 
943  for (int i = 0; i < classes.Count(); i++)
944  {
945  string config_path = classes.Get(i);
946 
947  int objects_count = GetGame().ConfigGetChildrenCount(config_path);
948  for (int j = 0; j < objects_count; j++)
949  {
950  string child_name;
951 
952  GetGame().ConfigGetChildName(config_path, j, child_name);
953 
954  int scope = GetGame().ConfigGetInt(config_path + " " + child_name + " scope");
955 
956  if (scope >= m_ObjectsScope || ignoreScope)
957  {
958  int category_bit = GetGame().ConfigGetInt(config_path + " " + child_name + " debug_ItemCategory") - 1;
959  category_bit = (1 << category_bit);
960 
961  bool display = false;
962  int color = 0;
963  if (category_bit & categoryMask)
964  {
965  display = true;
966  }
967  else if ((!m_ConfigDebugProfile.GetMergeType() || categoryMask == 0) && filters.Count() > 0)
968  {
969  string child_name_lower = child_name;
970  child_name_lower.ToLower();
971 
972  foreach (int indx, string filter:filters)
973  {
974  if (child_name_lower.Contains(filter))
975  {
976  display = false;
977  color = filterColors.Get(indx);
978  TStringArray arr = itemsByFilters.Get(filter);
979  if (!arr)
980  {
981  arr = new TStringArray();
982  itemsByFilters.Set(filter, arr);
983  }
984  arr.Insert(child_name);
985  itemsAndColors.Insert(child_name,color);
986  break;
987  }
988  }
989  }
990  else if (categoryMask == 0)
991  {
992  display = true;
993  }
994 
995  if (display)
996  {
997  itemsArray.Insert(child_name);
998 
999  }
1000  }
1001  }
1002  }
1003 
1004  if (itemsArray)
1005  {
1006  itemsArray.Sort();
1007  foreach (string it:itemsArray)
1008  {
1009  widget.AddItem(it, NULL, 0);
1010  }
1011  }
1012 
1013  if (filters)
1014  {
1015  if (m_FilterOrderReversed)
1016  filters.Invert();
1017 
1018  foreach (string f:filters)
1019  {
1020  TStringArray arr2 = itemsByFilters.Get(f);
1021  if (arr2)
1022  {
1023  arr2.Sort();
1024  foreach (string itm: arr2)
1025  {
1026  int row = widget.AddItem(itm, NULL, 0);
1027  int clr = itemsAndColors.Get(itm);
1028  if (clr)
1029  {
1030  widget.SetItemColor(row, 0, clr);
1031  }
1032  }
1033  }
1034  }
1035  }
1036 
1037 
1038  }
1039 
1040 
1041  void SetFilterOrder(bool reversed)
1042  {
1043  m_FilterOrderReversed = reversed;
1044  if (reversed)
1045  m_FilterOrderImage.SetRotation(0,0,180,true);
1046  else
1047  m_FilterOrderImage.SetRotation(0,0,0,true);
1048  ChangeFilterItems(true);
1050  {
1051  m_ConfigDebugProfile.SetFilterOrderReversed(reversed);
1052  }
1053  }
1054 
1055  override bool OnChange(Widget w, int x, int y, bool finished)
1056  {
1057  super.OnChange(w, x, y, finished);
1058  if (w == m_ShowProtected)
1059  {
1060  if (m_ShowProtected.IsChecked())
1061  {
1062  m_ObjectsScope = 1;
1063  }
1064  else
1065  {
1066  m_ObjectsScope = 2;
1067  }
1068  ChangeFilterItems(true);
1069  return true;
1070  }
1071  else if (w == m_ClearInventory)
1072  {
1073  CLEAR_IVN = m_ClearInventory.IsChecked();
1074  return true;
1075  }
1076  else if (m_CategoryButtonsWidgets.Find(w) >= 0)
1077  {
1078 
1079  int pos = m_CategoryButtonsWidgets.Find(w);
1080  int bit = Math.Pow(2,pos);
1081  CheckBoxWidget cbw = CheckBoxWidget.Cast(w);
1082  if (cbw.IsChecked())
1083  {
1084  m_CategoryMask = m_CategoryMask | bit;
1085  cbw.SetTextColor(ARGB(255, 255, 0, 0));
1086  }
1087  else
1088  {
1089  m_CategoryMask = (m_CategoryMask & ~bit);
1090  cbw.SetTextColor(ARGB(255, 255, 255,255));
1091  }
1092 
1093  ChangeFilterItems(true);
1094  return true;
1095  }
1096 
1097  /*
1098  if (w == m_ObjectFilter)
1099  {
1100  m_RefreshFilterTimer.Run(0.85, this, "ChangeFilterItems", null, false);
1101  return true;
1102  }*/
1103  if (w == m_QuantityEditBox && (GetCurrentItemIndex() >= 0 || GetCurrentPresetName() != ""))
1104  {
1105  m_ConfigDebugProfile.SetItemQuantity(GetCurrentPresetName(), GetCurrentItemIndex(), m_QuantityEditBox.GetText().ToFloat());
1106  return true;
1107  }
1108  else if (w == m_DrawDistanceWidget)
1109  {
1110  DRAW_DISTANCE = m_DrawDistanceWidget.GetText().ToFloat();
1111  return true;
1112  }
1113  else if (w == m_DamageEditBox && (GetCurrentItemIndex() >= 0 || GetCurrentPresetName() != ""))
1114  {
1115  m_ConfigDebugProfile.SetItemHealth(GetCurrentPresetName(), GetCurrentItemIndex(), m_DamageEditBox.GetText().ToFloat());
1116  return true;
1117  }
1118  else if (w == m_WithPhysicsCheckbox && (GetCurrentItemIndex() >= 0 || GetCurrentPresetName() != ""))
1119  {
1120  m_ConfigDebugProfile.SetItemWithPhysics(GetCurrentPresetName(), GetCurrentItemIndex(), m_WithPhysicsCheckbox.IsChecked());
1121  return true;
1122  }
1123  else if (w == m_BatchSpawnQuantity)
1124  {
1125  m_ConfigDebugProfile.SetBatchSpawnQuantity(m_BatchSpawnQuantity.GetText().ToInt());
1126  return true;
1127  }
1128  else if ((w == m_RectSpawnRow || w == m_RectSpawnColumn || w == m_RectSpawnRowStep || w == m_RectSpawnColumnStep))
1129  {
1130  if (w == m_RectSpawnRow || w == m_RectSpawnColumn)
1131  {
1132  int rowQ = m_RectSpawnRow.GetText().ToInt();
1133  int columnQ = m_RectSpawnColumn.GetText().ToInt();
1134  int result = columnQ * rowQ;
1135  m_BatchSpawnQuantity.SetText(result.ToString());
1136  m_ConfigDebugProfile.SetBatchSpawnQuantity(m_BatchSpawnQuantity.GetText().ToInt());
1137  }
1138 
1140  {
1141  m_ConfigDebugProfile.SetBatchSpawnRectangle(m_RectSpawnRow.GetText().ToInt(),m_RectSpawnColumn.GetText().ToInt(), m_RectSpawnRowStep.GetText().ToFloat(),m_RectSpawnColumnStep.GetText().ToFloat());
1142  }
1143  return true;
1144  }
1145  return false;
1146  }
1147 
1148  override bool OnItemSelected(Widget w, int x, int y, int row, int column, int oldRow, int oldColumn)
1149  {
1150  super.OnItemSelected(w, x, y, row, column, oldRow, oldColumn);
1151  if (w == m_PresetsTextListbox && (m_SelectedObjectIsPreset == 1 || m_SelectedObjectIsPreset == -1))
1152  {
1153  if (m_PresetsTextListbox.GetSelectedRow() != -1)
1154  {
1155  SelectPreset();
1156  return true;
1157  }
1158  }
1159  else if (w == m_PresetItemsTextListbox)
1160  {
1161  if (m_PresetItemsTextListbox.GetSelectedRow() != -1)
1162  {
1163  ShowItemButtons();
1164  ShowItemTransferButtons();
1165  m_SelectedObjectText.SetText(GetCurrentItemName());
1166  SetObject(GetCurrentItemName());
1167  m_SelectedObjectIsPreset = 0;
1168  }
1169  return true;
1170  }
1171  else if (w == m_ObjectsTextListbox)
1172  {
1173  SelectObject(false);
1174  return true;
1175  }
1176  return false;
1177  }
1178 
1179 
1180  override bool OnClick(Widget w, int x, int y, int button)
1181  {
1182  super.OnClick(w,x,y,button);
1183  PlayerBase player = PlayerBase.Cast(GetGame().GetPlayer());
1184  int objects_row_index;
1185  if (w == m_CategoryMergeType)
1186  {
1188  {
1189  m_ConfigDebugProfile.SetMergeType(m_CategoryMergeType.IsChecked());
1190  }
1191  ChangeFilterItems(true);
1192  // Refresh UI by new settings
1193  m_MissionGameplay.GetHudDebug().RefreshByLocalProfile();
1194  return true;
1195  }
1196  else if (w == m_ObjectFilter)
1197  {
1198  ChangeFilterItems(true);
1199  return true;
1200  }
1201  else if (w == m_ItemPreviewCheckbox)
1202  {
1204  {
1205  m_ConfigDebugProfile.SetShowItemPreview(m_ItemPreviewCheckbox.IsChecked());
1206  if (!m_ItemPreviewCheckbox.IsChecked())
1207  {
1208  m_ItemPreviewWidget.SetItem(null);
1209  }
1210  }
1211  }
1212  else if (w == m_SpawnInInvButton || w == m_SpawnGroundButton || w == m_SpawnOnTarget || w == m_SpawnOnCursor || w == m_SpawnInHands)
1213  {
1214  SaveProfileSpawnDistance();
1215 
1216  objects_row_index = m_ObjectsTextListbox.GetSelectedRow();
1217 
1218  vector rayStart = GetGame().GetCurrentCameraPosition();
1219  vector rayEnd = rayStart + GetGame().GetCurrentCameraDirection() * 50;
1220  vector hitPos;
1221  vector hitNormal;
1222  int hitComponentIndex;
1223  set<Object> hitObjects = new set<Object>;
1224  //DayZPhysics.RaycastRV(rayStart, rayEnd, hitPos, hitNormal, hitComponentIndex, hitObjects, NULL, player,);
1225  DayZPhysics.RaycastRV(rayStart, rayEnd, hitPos, hitNormal, hitComponentIndex, hitObjects, NULL, player, false, false, ObjIntersectView, 0.3);
1226 
1227  EntityAI target;
1228  if (hitObjects.Count())
1229  target = EntityAI.Cast(hitObjects.Get(0));
1230 
1231  if (m_SelectedObject != "")
1232  {
1233  // @NOTE: duplicate code in PluginDeveloper.c
1234  float distance = m_SpawnDistanceEditBox.GetText().ToFloat();
1235 
1236 
1237  if (m_SelectedObjectIsPreset == 1)
1238  {
1239  //------------ PRESETS -------------
1240  switch (w)
1241  {
1242  case m_SpawnOnTarget:
1243  {
1244  if (target && target.IsInherited(EntityAI))
1245  {
1246  EntityAI att_parent = EntityAI.Cast(target) ;
1247  SpawnPreset(att_parent, CLEAR_IVN, m_SelectedObject);
1248  }
1249  break;
1250  }
1251  case m_SpawnGroundButton:
1252  {
1253  SpawnPreset(player, false, m_SelectedObject, InventoryLocationType.GROUND, distance);
1254  break;
1255  }
1256  default:
1257  {
1258  SpawnPreset(player, CLEAR_IVN, m_SelectedObject);
1259  break;
1260  }
1261  }
1262  }
1263  else
1264  {
1265  //------------SINGLE ITEMS ------------
1266 
1267 
1268  float health = m_DamageEditBox.GetText().ToFloat() * MiscGameplayFunctions.GetTypeMaxGlobalHealth(m_SelectedObject);
1269  float quantity = m_QuantityEditBox.GetText().ToFloat();
1270  bool withPhysics = m_WithPhysicsCheckbox.IsChecked();
1271 
1272  bool spawnOnCrossHair = DeveloperFreeCamera.IsFreeCameraEnabled() || w == m_SpawnOnCursor;
1273 
1274 
1275  switch (w)
1276  {
1277  case m_SpawnGroundPatternGrid:
1278  {
1279  m_Developer.SpawnEntityOnCursorDir(player, m_SelectedObject, quantity, distance, health, m_IsShiftDown, "", withPhysics);
1280  break;
1281  }
1282 
1283  case m_SpawnOnTarget:
1284  {
1285  if (target && target.IsInherited(EntityAI))
1286  m_Developer.SpawnEntityInInventory(target, m_SelectedObject, health, quantity, m_IsShiftDown);
1287  break;
1288  }
1289 
1290  case m_SpawnInInvButton:
1291  {
1292  m_Developer.SpawnEntityInPlayerInventory(player, m_SelectedObject, -1, quantity, m_IsShiftDown);
1293  break;
1294  }
1295  case m_SpawnInHands:
1296  {
1297  m_Developer.SpawnEntityInPlayerInventory(player, m_SelectedObject, -1, quantity, m_IsShiftDown,"", FindInventoryLocationType.HANDS);
1298  break;
1299  }
1300  case m_SpawnOnCursor:
1301  case m_SpawnGroundButton:
1302  {
1303  if (spawnOnCrossHair)
1304  {
1305  m_Developer.SpawnItemOnCrosshair(player, m_SelectedObject, health, quantity, 40, true, m_IsShiftDown, withPhysics );
1306  }
1307  else
1308  {
1309  m_Developer.SpawnEntityOnCursorDir(player, m_SelectedObject, quantity, distance, health, m_IsShiftDown, "", withPhysics);
1310  }
1311  break;
1312  }
1313  }
1314  }
1315  }
1316  return true;
1317  }
1318  else if (w == m_FilterOrderButton)
1319  {
1320  SetFilterOrder(!m_FilterOrderReversed);
1321  return true;
1322  }
1323  else if (w == m_PresetsTextListbox)
1324  {
1325  SelectPreset();
1326  return true;
1327  }
1328  else if (w == m_PresetItemsTextListbox)
1329  {
1330  m_ObjectsTextListbox.SelectRow(-1);
1331  ShowItemButtons();
1332  ShowItemTransferButtons();
1333  m_SelectedObjectText.SetText("Object : " + GetCurrentItemName());
1334  SetObject(GetCurrentItemName());
1335  m_SelectedObjectIsPreset = 0;
1336 
1337  return true;
1338  }
1339  else if (w == m_PresetSetDefaultButton)
1340  {
1341  if (GetCurrentPresetName()!= "")
1342  {
1343  SetDefaultPreset(GetCurrentPresetIndex());
1344  }
1345  return true;
1346  }
1347  else if (w == m_PresetNewButton)
1348  {
1349  g_Game.GetUIManager().EnterScriptedMenu(MENU_SCRIPTCONSOLE_DIALOG_PRESET_NAME, m_ScriptConsole);
1350  return true;
1351  }
1352  else if (w == m_PresetDeleteButton)
1353  {
1354  if (GetCurrentPresetName()!= "")
1355  {
1356  DeletePreset();
1357  }
1358  return true;
1359  }
1360  else if (w == m_PresetRenameButton)
1361  {
1362  if (GetCurrentPresetName()!= "")
1363  {
1364  g_Game.GetUIManager().EnterScriptedMenu(MENU_SCRIPTCONSOLE_DIALOG_PRESET_RENAME, m_ScriptConsole);
1365  }
1366  return true;
1367  }
1368  else if (w == m_PresetAddItemtButton)
1369  {
1370  AddItemToPreset();
1371  return true;
1372  }
1373  else if (w == m_ItemNameCopy)
1374  {
1375  AddItemToClipboard(m_ObjectsTextListbox);
1376  return true;
1377  }
1378  else if (w == m_PresetRemoveItemButton)
1379  {
1380  RemoveItemFromPreset();
1381  return true;
1382  }
1383  else if (w == m_ItemMoveUpButton)
1384  {
1385  ItemMoveUp();
1386  return true;
1387  }
1388  else if (w == m_ItemMoveDownButton)
1389  {
1390  ItemMoveDown();
1391  return true;
1392  }
1393  else if (w == m_SpawnBatchButton)
1394  {
1395  int count = m_BatchSpawnQuantity.GetText().ToInt();
1396  int rows = m_RectSpawnRow.GetText().ToInt();
1397  int columns = m_RectSpawnColumn.GetText().ToInt();
1398  float rowStep = m_RectSpawnRowStep.GetText().ToFloat();
1399  float columnStep = m_RectSpawnColumnStep.GetText().ToFloat();
1400  m_Developer.SpawnEntityOnGroundPatternGrid(player, m_SelectedObject,count, m_DamageEditBox.GetText().ToFloat(), 1, rows, columns, rowStep, columnStep, m_IsShiftDown, m_WithPhysicsCheckbox.IsChecked());
1401  return true;
1402  }
1403  else if (w == m_ListActions)
1404  {
1405  if (!m_PreviewEntity)
1406  return false;
1407 
1408  return ListItemRelatedActions();
1409  }
1410  else if (w == m_ObjectsTextListbox)
1411  {
1412  SelectObject();
1413  return true;
1414  }
1415  else if (w == m_DrawInWorld)
1416  {
1417  DrawItems(m_SelectedObject);
1418  return true;
1419 
1420  }
1421  else if (w == m_DrawInWorldClear)
1422  {
1423  DrawItemsClear();
1424  return true;
1425  }
1426 
1427  return false;
1428  }
1429 
1430  override bool OnDoubleClick(Widget w, int x, int y, int button)
1431  {
1432  super.OnDoubleClick(w, x, y, button);
1433 
1434  int i;
1435  int objects_row_index;
1436  PlayerBase player = PlayerBase.Cast(GetGame().GetPlayer());
1437 
1438  if (w == m_ObjectsTextListbox)
1439  {
1440  //select item
1441  m_PresetItemsTextListbox.SelectRow(-1);
1442  HideItemButtons();
1443  ShowItemTransferButtons();
1444  m_SelectedObjectText.SetText("Object : " + GetCurrentObjectName());
1445 
1446  m_SelectedObject = GetCurrentObjectName();
1447  m_LastSelectedObject = m_SelectedObject;
1448  m_SelectedObjectIsPreset = 0;
1449 
1450  //spawn item
1451  SaveProfileSpawnDistance();
1452 
1453  objects_row_index = m_ObjectsTextListbox.GetSelectedRow();
1454 
1455  vector rayStart = GetGame().GetCurrentCameraPosition();
1456  vector rayEnd = rayStart + GetGame().GetCurrentCameraDirection() * 1.5;
1457  vector hitPos;
1458  vector hitNormal;
1459  int hitComponentIndex;
1460  set<Object> hitObjects = new set<Object>;
1461  DayZPhysics.RaycastRV(rayStart, rayEnd, hitPos, hitNormal, hitComponentIndex, hitObjects, NULL, player);
1462 
1463  Object target = NULL;
1464  if (hitObjects.Count())
1465  target = hitObjects.Get(0);
1466 
1467  if (m_SelectedObject != "")
1468  {
1469  float distance = m_SpawnDistanceEditBox.GetText().ToFloat();
1470 
1471  if (button == 0) //LMB
1472  {
1473  m_Developer.SpawnEntityOnCursorDir(player, m_SelectedObject, 1, distance);
1474  return true;
1475  }
1476  else if (button == 1) //RMB
1477  {
1478  if (GetGame().IsMultiplayer())
1479  {
1480  m_Developer.SpawnEntityInPlayerInventory(player, m_SelectedObject, -1, -1);
1481  }
1482  else
1483  {
1484  EntityAI spawned_entity = m_Developer.SpawnEntityOnCursorDir(player, m_SelectedObject, -1, distance);
1485  player.LocalTakeEntityToHands(spawned_entity);
1486  }
1487  return true;
1488  }
1489  else if (button == 2) //MMB
1490  {
1491  m_Developer.SpawnEntityOnCursorDir(player, m_SelectedObject, 1, distance,-1, true);
1492  return true;
1493  }
1494  }
1495 
1496  }
1497  else if (w == m_QuantityEditBox)
1498  {
1499  m_QuantityEditBox.SetText("1.0");
1500  return true;
1501  }
1502  return false;
1503  }
1504 
1505  override void Update(float timeslice)
1506  {
1507  m_IsShiftDown = KeyState(KeyCode.KC_LSHIFT) || KeyState(KeyCode.KC_RSHIFT);
1508 
1509  UpdateButtonNames();
1510 
1511  super.Update(timeslice);
1512  }
1513 
1514  void SetTextSpawnButton(ButtonWidget w, bool special, string suffix = " Special")
1515  {
1516  string text = m_SpawnButtonsOriginalText.Get(w);
1517  if (special)
1518  text += suffix;
1519  w.SetText(text);
1520  }
1521 
1522  void UpdateButtonNames()
1523  {
1524  SetTextSpawnButton(m_SpawnGroundButton, m_IsShiftDown);
1525  SetTextSpawnButton(m_SpawnInInvButton, m_IsShiftDown);
1526  SetTextSpawnButton(m_SpawnOnTarget, m_IsShiftDown);
1527  SetTextSpawnButton(m_SpawnOnCursor, m_IsShiftDown);
1528  SetTextSpawnButton(m_SpawnBatchButton, m_IsShiftDown);
1529  SetTextSpawnButton(m_SpawnInHands, m_IsShiftDown);
1530  }
1531 
1532  TStringArray GetItemsClasses()
1533  {
1535  }
1536 
1537  protected string PreprocessFilterText(MultilineEditBoxWidget w)
1538  {
1539  string widgetText;
1540  w.GetText(widgetText);
1541 
1542  if (widgetText.Contains(","))
1543  {
1544  widgetText.Replace(","," ");
1545  w.SetLine(0,widgetText);
1546  }
1547  return widgetText;
1548  }
1549 
1550  void ChangeFilterItems(bool forced = false)
1551  {
1552  string widgetText = PreprocessFilterText(m_ObjectFilter);
1553  if (widgetText == m_FilterTextPrev && !forced)
1554  return;
1555 
1556  m_FilterTextPrev = widgetText;
1557  string txt = m_ConfigDebugProfile.GetItemSearch();
1558 
1559  m_ConfigDebugProfile.SetItemSearch(widgetText);
1560  ChangeFilter(GetItemsClasses(), m_ObjectsTextListbox,m_ObjectFilter, m_CategoryMask);
1561  }
1562 
1563  private bool ListItemRelatedActions()
1564  {
1565  string message = "";
1566 
1567  array<ActionBase_Basic> interactActions = new array<ActionBase_Basic>();
1568  m_PreviewEntity.GetActions(InteractActionInput, interactActions);
1569  if (interactActions)
1570  {
1571  message += "\n== Interact (F)\n\n";
1572  foreach (ActionBase_Basic iaction : interactActions)
1573  {
1574  if (iaction.Type() == ActionWorldCraft)
1575  continue;
1576 
1577  ActionBase ia = ActionBase.Cast(iaction);
1578  message += string.Format("%1 <%2>\n", Widget.TranslateString(ia.GetText()), ia.ClassName());
1579  }
1580  }
1581 
1582  array<ActionBase_Basic> continuousInteractActions = new array<ActionBase_Basic>();
1583  m_PreviewEntity.GetActions(ContinuousInteractActionInput, continuousInteractActions);
1584  if (continuousInteractActions)
1585  {
1586  message += "\n== Continuous Interact (F hold)\n\n";
1587  foreach (ActionBase_Basic ciaction : continuousInteractActions)
1588  {
1589  if (ciaction.Type() == ActionWorldCraft)
1590  continue;
1591 
1592  ActionBase cia = ActionBase.Cast(ciaction);
1593  message += string.Format("%1 <%2>\n", Widget.TranslateString(cia.GetText()), cia.ClassName());
1594  }
1595  }
1596 
1597  array<ActionBase_Basic> singleActions = new array<ActionBase_Basic>();
1598  m_PreviewEntity.GetActions(DefaultActionInput, singleActions);
1599  if (singleActions)
1600  {
1601  message += "\n== Single (LMB)\n\n";
1602  foreach (ActionBase_Basic saction : singleActions)
1603  {
1604  if (saction.Type() == ActionWorldCraft)
1605  continue;
1606 
1607  ActionBase sa = ActionBase.Cast(saction);
1608  message += string.Format("%1 <%2>\n", Widget.TranslateString(sa.GetText()), sa.ClassName());
1609  }
1610  }
1611 
1612  array<ActionBase_Basic> continuousActions = new array<ActionBase_Basic>();
1613  m_PreviewEntity.GetActions(ContinuousDefaultActionInput, continuousActions);
1614  if (continuousActions)
1615  {
1616  ActionBase_Basic craftingAction;
1617  message += "\n== Continuous (LMB hold)\n\n";
1618  foreach (ActionBase_Basic caction : continuousActions)
1619  {
1620  if (caction.Type() != ActionWorldCraft)
1621  {
1622  ActionBase ca = ActionBase.Cast(caction);
1623  message += string.Format("%1 <%2>\n", Widget.TranslateString(ca.GetText()), ca.ClassName());
1624  }
1625  else
1626  {
1627  craftingAction = caction;
1628  }
1629  }
1630  message += "\n== Crafting recipes \n\n";
1631  if (craftingAction)
1632  {
1633  PluginRecipesManager pluginRecipesManager = PluginRecipesManager.Cast(GetPlugin(PluginRecipesManager));
1634  array<RecipeBase> recipes = pluginRecipesManager.GetRecipesForItem(m_PreviewEntity.GetType());
1635  foreach (RecipeBase recipe : recipes)
1636  {
1637  if (recipe.IsItemInRecipe("Inventory_Base"))
1638  continue;
1639 
1640  message += string.Format("%1 <%2>\n", Widget.TranslateString(recipe.GetName()), recipe.Type());
1641  }
1642  }
1643  }
1644 
1645  ScriptConsoleUniversalInfoDialog infoDialog = ScriptConsoleUniversalInfoDialog.Cast(g_Game.GetUIManager().EnterScriptedMenu(MENU_SCRIPTCONSOLE_UNIVERSAL_INFO_DIALOG, m_ScriptConsole));
1646  infoDialog.SetLabel(string.Format("%1 related actions", m_PreviewEntity.GetType()));
1647  infoDialog.SetContent(message);
1648 
1649  return true;
1650  }
1651 }
GetGame
proto native CGame GetGame()
MENU_SCRIPTCONSOLE_DIALOG_PRESET_RENAME
const int MENU_SCRIPTCONSOLE_DIALOG_PRESET_RENAME
Definition: constants.c:178
DeveloperFreeCamera
Definition: developerfreecamera.c:1
ContinuousInteractActionInput
Definition: actioninput.c:521
TStringArray
array< string > TStringArray
Definition: enscript.c:685
KeyCode
KeyCode
Definition: ensystem.c:156
EditBoxWidget
Definition: enwidgets.c:353
m_ItemPreviewWidget
ItemPreviewWidget m_ItemPreviewWidget
Definition: pluginitemdiagnostic.c:70
PresetParams
Param3< string, bool, bool > PresetParams
Definition: scriptconsoleitemstab.c:1
MENU_SCRIPTCONSOLE_UNIVERSAL_INFO_DIALOG
const int MENU_SCRIPTCONSOLE_UNIVERSAL_INFO_DIALOG
Definition: constants.c:203
y
Icon y
dBodyDestroy
proto native void dBodyDestroy(notnull IEntity ent)
Destroys attached physics body.
DefaultActionInput
Definition: actioninput.c:630
RecipeBase
Definition: recipebase.c:4
Param3
Definition: entityai.c:95
ActionWorldCraft
Definition: actionworldcraft.c:32
GetPlugin
PluginBase GetPlugin(typename plugin_type)
Definition: pluginmanager.c:316
TIntArray
array< int > TIntArray
Definition: enscript.c:687
ScriptConsoleItemsTab
Definition: scriptconsoleitemstab.c:3
GetPosition
class JsonUndergroundAreaTriggerData GetPosition
Definition: undergroundarealoader.c:9
PlayerBase
Definition: playerbaseclient.c:1
map
map
Definition: controlsxboxnew.c:3
vector
Definition: enconvert.c:105
TextWidget
Definition: enwidgets.c:219
InteractActionInput
Definition: actioninput.c:534
CFG_VEHICLESPATH
const string CFG_VEHICLESPATH
Definition: constants.c:209
KeyState
proto native int KeyState(KeyCode key)
InventoryLocationType
InventoryLocationType
types of Inventory Location
Definition: inventorylocation.c:3
ShapeFlags
ShapeFlags
Definition: endebug.c:125
ScriptRPC
Definition: gameplay.c:104
g_Game
DayZGame g_Game
Definition: dayzgame.c:3727
Object
Definition: objecttyped.c:1
MENU_SCRIPTCONSOLE_DIALOG_PRESET_NAME
const int MENU_SCRIPTCONSOLE_DIALOG_PRESET_NAME
Definition: constants.c:177
CFG_MAGAZINESPATH
const string CFG_MAGAZINESPATH
Definition: constants.c:211
ECE_TRACE
const int ECE_TRACE
Definition: centraleconomy.c:10
CFG_WEAPONSPATH
const string CFG_WEAPONSPATH
Definition: constants.c:210
FindInventoryLocationType
FindInventoryLocationType
flags for searching locations in inventory
Definition: inventorylocation.c:15
COLOR_RED
const int COLOR_RED
Definition: constants.c:64
array< Shape >
name
PlayerSpawnPresetDiscreteItemSetSlotData name
one set for cargo
ActionBase
void ActionBase()
Definition: actionbase.c:73
x
Icon x
MapMarker
Definition: inventoryitem.c:1154
GetPlayer
protected void GetPlayer()
Definition: crosshairselector.c:127
Debug
Definition: debug.c:13
ItemPreviewWidget
Definition: gameplay.c:275
ActionBase_Basic
Definition: actionbase_basic.c:1
m_ConfigDebugProfile
PluginConfigDebugProfile m_ConfigDebugProfile
Definition: pluginitemdiagnostic.c:58
DayZPhysics
Definition: dayzphysics.c:123
ERPCs
ERPCs
Definition: erpcs.c:1
Timer
Definition: dayzplayerimplement.c:62
ECE_CREATEPHYSICS
const int ECE_CREATEPHYSICS
Definition: centraleconomy.c:16
ECE_LOCAL
const int ECE_LOCAL
Definition: centraleconomy.c:24
Widget
Definition: enwidgets.c:189
ScriptConsoleTabBase
Definition: scriptconsoletabbase.c:1
Math
Definition: enmath.c:6
CFG_AMMO
const string CFG_AMMO
Definition: constants.c:212
m_SelectedObject
protected Widget m_SelectedObject
Definition: radialmenu.c:16
EntityAI
Definition: building.c:5
ARGB
int ARGB(int a, int r, int g, int b)
Definition: proto.c:322
Shape
class DiagMenu Shape
don't call destructor directly. Use Destroy() instead
ContinuousDefaultActionInput
void ContinuousDefaultActionInput(PlayerBase player)
Definition: actioninput.c:606