DayZ 1.24
Loading...
Searching...
No Matches
AttachmentCategoriesContainer.c
Go to the documentation of this file.
2{
4 protected int m_SlotsCount;
6
11
13 {
16
17 m_MainWidget = m_RootWidget.FindAnyWidget("body");
18 WidgetEventHandler.GetInstance().RegisterOnChildAdd(m_MainWidget, this, "OnChildAdd");
19 WidgetEventHandler.GetInstance().RegisterOnChildRemove(m_MainWidget, this, "OnChildRemove");
20
22
23 (Container.Cast(m_Parent)).m_Body.Insert(this);
24 m_Parent.Refresh();
26 RecomputeOpenedContainers();
27 }
28
30 {
31 m_CollapsibleHeader.SetName(m_Entity.GetDisplayName());
32 }
33
34 override bool IsDisplayable()
35 {
36 return !IsEmpty() || CanDisplayAnyCategory();
37 }
38
39 override void UpdateInterval()
40 {
41 if (m_Entity)
42 {
43 if (m_Entity.GetInventory().IsInventoryLockedForLockType(HIDE_INV_FROM_SCRIPT) || m_Hidden)
44 {
45 if (m_Body.Count() > 0 && !m_Hidden)
46 m_CollapsibleHeader.OnHide();
47 HideContent();
48 GetMainWidget().Show(false);
49 }
50 else
51 {
52 if (m_Body.Count() > 0 && !m_Hidden)
53 {
54 if (m_Body.Count() > 0 && !m_Hidden)
55 m_CollapsibleHeader.OnShow();
56 int i;
57 for (i = m_SlotsCount; i < m_Body.Count(); i++)
58 {
60 if (row)
61 {
62 if (m_Entity.CanDisplayAttachmentCategory(row.GetCategoryIdentifier()))
63 {
64 if (row.IsDisplayable())
65 {
66 ShowInSlots(row.GetCategoryIdentifier(), true);
67 if (!row.IsVisible())
68 row.OnShow();
69 }
70 else
71 {
72 ShowInSlots(row.GetCategoryIdentifier(), false);
73 if (row.IsVisible())
74 row.OnHide();
75 }
76 }
77 else
78 {
79 ShowInSlots(row.GetCategoryIdentifier(), false);
80 if (row.IsVisible())
81 row.OnHide();
82 }
83 row.UpdateInterval();
84 }
85 else
86 {
87 ContainerWithCargo cargo = ContainerWithCargo.Cast(m_Body[i]);
88 if (cargo)
89 {
90 if (m_Entity.CanDisplayCargo())
91 {
92 m_CargoSlotsIcon.m_MainWidget.Show(true);
93 if (!cargo.IsVisible())
94 cargo.OnShow();
95 }
96 else
97 {
98 m_CargoSlotsIcon.m_MainWidget.Show(false);
99 if (cargo.IsVisible())
100 cargo.OnHide();
101 }
102 cargo.UpdateInterval();
103 }
104 RecomputeOpenedContainers();
105
106 }
107
108 }
109 for (i = 0; i < m_SlotsCount; i++)
110 {
112 {
113 if (slots.IsDisplayable())
114 slots.OnShow();
115 else
116 slots.OnHide();
117 }
118 }
119 }
120 GetMainWidget().Show(true);
121 }
122 }
123 }
124
126 {
127 SlotsIcon icon = items_cont.GetSlotIcon(slot_number);
128 ImageWidget image_widget = icon.GetGhostSlot();
129 image_widget.Show(true);
130 image_widget.LoadImageFile(0, StaticGUIUtils.VerifyIconImageString(StaticGUIUtils.IMAGESETGROUP_INVENTORY, icon_name)); //icon_name must be in format "set:<setname> image:<imagename>"
131 }
132
134 {
135 return GetGame().ConfigGetChildrenCount(config_path);
136 }
137
143
148
149 void ShowInSlots(string category, bool show)
150 {
153
155 if (items_cont)
156 {
157 Widget icon_widget = items_cont.GetSlotIcon(slot_number).GetMainWidget();
158 if (icon_widget)
159 icon_widget.Show(show);
160 icon_widget.GetParent().Update();
161 icon_widget.GetParent().GetParent().Update();
162 icon_widget.GetParent().GetParent().GetParent().Update();
163 }
164 }
165
166 //oof
167 override bool CanDisplayAnyCategory()
168 {
169 int count = m_Body.Count();
171 for (int i = m_SlotsCount; i < count; i++)
172 {
173 if (Class.CastTo(row, m_Body[i]) && m_Entity.CanDisplayAttachmentCategory(row.GetCategoryIdentifier()))
174 return true;
175 }
176 return super.CanDisplayAnyCategory();
177 }
178
179 override void UpdateRadialIcon()
180 {
181 if (m_SlotIcon)
182 {
183 if (m_Entity.CanDisplayCargo() || CanDisplayAnyCategory())
184 {
185 m_SlotIcon.GetRadialIconPanel().Show(true);
186 SetOpenForSlotIcon(!m_Hidden);
187 }
188 else
189 m_SlotIcon.GetRadialIconPanel().Show(false);
190 }
191 }
192
199
201 {
203 string icon_name;
204 GetGame().ConfigGetText(icon_path, icon_name);
205 return icon_name;
206 }
207
209 {
211 return GetGame().ConfigGetInt(preview_path);;
212 }
213
215 {
217 w.GetUserData(icon);
218
219 ClosableContainer c = ClosableContainer.Cast(icon.GetContainer());
220 if (c)
221 c.Toggle();
222 }
223
225 {
226 if (m_OpenedContainers.Count() > m_ActiveIndex)
227 {
228 //c - container where selected icon is part of
229 Container c = Container.Cast(m_OpenedContainers.Get(m_ActiveIndex));
230 //cc - container connected to selected icon (this container will be close/open)
232 //icon - selected icon
233 SlotsIcon icon = c.GetFocusedSlotsIcon();
234
235 if (icon)
236 cc = ClosableContainer.Cast(icon.GetContainer());
237
238 if (cc)
239 {
240
241 cc.Toggle();
242 RecomputeOpenedContainers();
243 }
244 }
245 }
246
248 {
249 return m_CollapsibleHeader.IsActive();
250 }
251
253 {
254 m_SlotsCount = 0;
255
256 string type = m_Entity.GetType();
257 string config_path_attachment_categories = "CfgVehicles " + type + " GUIInventoryAttachmentsProps";
260 if (m_Entity.GetInventory().GetCargo())
264 row_count++;
265 for (int i = 0; i < row_count; i++)
266 {
268 m_Body.Insert(items_cont);
269 m_OpenedContainers.Insert(items_cont);
270
271 //TODO MW find better way
272 if (i == (row_count - 1) && categories_count % ITEMS_IN_ROW != 0)
273 items_cont.GetSlotsContainer().SetColumnCount(categories_count % ITEMS_IN_ROW);
274 else
275 items_cont.GetSlotsContainer().SetColumnCount(ITEMS_IN_ROW);
276 }
278 }
279
281 {
282 string type = m_Entity.GetType();
283 string config_path_attachment_categories = "CfgVehicles " + type + " GUIInventoryAttachmentsProps";
284
286
289 string attachment_category;
290 string icon_name;
291
292 for (int i = 0; i < attachments_categories_count; i++)
293 {
297
298 if (items_cont)
299 {
300 int slot_number = i % ITEMS_IN_ROW;
302 icon = items_cont.GetSlotIcon(slot_number);
303 icon.GetGhostSlot().SetFlags(WidgetFlags.IGNOREPOINTER);
304
306
308 string name;
309
310 GetGame().ConfigGetText(config, name);
311 icon.SetSlotDisplayName(name);
312
314
315 ar = new AttachmentCategoriesRow(this, -1);
317
318 //Insert(ar);
319 ar.SetSlotIcon(icon);
320 //icon.SetContainer(ar);
321
322 icon.GetRadialIconPanel().Show(true);
323 ar.Open();
324 icon.SetContainer(ar);
325 Insert(ar);
326 }
327 }
328
329 if (m_Entity.GetInventory().GetCargo())
330 {
332 if (items_cont)
333 {
335 icon.GetGhostSlot().Show(true);
336 icon.GetGhostSlot().LoadImageFile(0, StaticGUIUtils.VerifyIconImageString(StaticGUIUtils.IMAGESETGROUP_INVENTORY, m_Entity.ConfigGetString("GUIInventoryCargoIcon")));
337 icon.SetSlotDisplayName(m_Entity.ConfigGetString("GUIInventoryCargoName"));
338 icon.GetGhostSlot().SetFlags(WidgetFlags.IGNOREPOINTER);
339
340 icon.GetRadialIconPanel().Show(true);
341 icon.GetMainWidget().Show(true);
342
343 ContainerWithCargo iwc = new ContainerWithCargo(this, -1);
344 iwc.Get(0).GetRootWidget().ClearFlags(WidgetFlags.DRAGGABLE);
345 iwc.SetEntity(m_Entity, 0, false);
346 iwc.SetSlotIcon(icon);
347 iwc.Open();
348
349 icon.SetContainer(iwc);
351 }
352 }
353
354 RecomputeOpenedContainers();
355 }
356
357
359 {
360 ItemPreviewWidget iw = ItemPreviewWidget.Cast(w.FindAnyWidget("Render"));
361 if (!iw)
362 {
363 string name = w.GetName();
364 name.Replace("PanelWidget", "Render");
365 iw = ItemPreviewWidget.Cast(w.FindAnyWidget(name));
366 }
367 if (!iw)
368 iw = ItemPreviewWidget.Cast(w);
369 if (!iw.GetItem())
370 return;
371 if (m_Entity.GetInventory().CanAddAttachment(iw.GetItem()) && iw.GetItem().GetInventory().CanRemoveEntity())
372 GetGame().GetPlayer().PredictiveTakeEntityToTargetAttachment(m_Entity, iw.GetItem());
373 else if (m_Entity.GetInventory().CanAddEntityToInventory(iw.GetItem()) && iw.GetItem().GetInventory().CanRemoveEntity())
374 GetGame().GetPlayer().PredictiveTakeEntityToTargetInventory(m_Entity, FindInventoryLocationType.ANY, iw.GetItem());
375 }
376
377 override void DraggingOverHeader(Widget w, int x, int y, Widget receiver)
378 {
379 if (w == null)
380 return;
381 ItemPreviewWidget iw = ItemPreviewWidget.Cast(w.FindAnyWidget("Render"));
382 if (!iw)
383 {
384 string name = w.GetName();
385 name.Replace("PanelWidget", "Render");
386 iw = ItemPreviewWidget.Cast(w.FindAnyWidget(name));
387 }
388 if (!iw)
389 iw = ItemPreviewWidget.Cast(w);
390 if (!iw || !iw.GetItem())
391 return;
392
393 ItemManager.GetInstance().ShowSourceDropzone(iw.GetItem());
395 }
396
397 /*override void CollapseButtonOnMouseButtonDown(Widget w)
398 {
399 super.CollapseButtonOnMouseButtonDown(w);
400 RecomputeOpenedContainers();
401 }*/
403 {
404 if (!m_Hidden)
405 {
406 for (int i = 1; i < m_Body.Count(); i++)
407 {
408 m_Body.Get(i).OnHide();
409 Container c = Container.Cast(m_Body.Get(i));
410 if (c)
411 c.Close();
412 }
413
414 //m_Hidden = true;
415 OnHide();
416 }
417 else
418 {
419 //m_Hidden = false;
420 OnShow();
421 }
422 m_Closed = m_Hidden;
423
426 m_CollapsibleHeader.SetHeaderVisible(true);
427
429 RecomputeOpenedContainers();
430 }
431
432 override void Open()
433 {
434 if (IsDisplayable())
435 {
436 super.Open();
437 //ItemManager.GetInstance().SetDefaultOpenState( m_Entity.GetType(), true );
438 SetOpenForSlotIcon(true);
439 OnShow();
440 //m_Parent.m_Parent.Refresh();
441 }
442 }
443
444 override void Close()
445 {
446 //ItemManager.GetInstance().SetDefaultOpenState( m_Entity.GetType(), false );
447 super.Close();
448
452 else if (m_SlotIcon && m_SlotIcon.GetObject())
453 icon = m_SlotIcon;
454 /*else
455 {
456 Print("Dbg | no object in icon here!");
457 }
458 */
459
460 SetOpenForSlotIcon(false, icon);
461 OnHide();
462 }
463
464 override void OnHide()
465 {
467 {
468 bool b1 = !m_SlotIcon && !m_CargoSlotsIcon;
469 bool b2 = (!m_SlotIcon || !m_SlotIcon.IsVisible()) && m_CargoSlotsIcon && m_CargoSlotsIcon.IsVisible();
470 m_CollapsibleHeader.SetHeaderVisible(b1 || b2);
471 }
472 super.OnHide();
473 }
474
476 {
477 if (m_OpenedContainers.Count() > m_ActiveIndex)
478 {
480 SlotsIcon icon = GetFocusedSlotsIcon();
481
482 if (icon)
483 c = ClosableContainer.Cast(icon.GetContainer());
484
485 if (c && c.IsDisplayable())
486 return true;
487 }
488
489 return false;
490 }
491
493 {
494 return false;
495 }
496}
const int ITEMS_IN_ROW
Definition Attachments.c:1
EntityAI m_Entity
Definition ActionDebug.c:11
PlayerSpawnPresetDiscreteItemSetSlotData name
one set for cargo
Icon x
Icon y
FindInventoryLocationType
flags for searching locations in inventory
ref Widget m_RootWidget[MAX_SIMULTANIOUS_PLAYERS]
Widget m_Parent
Definition SizeToChild.c:86
int GetViewIndex(string config_path_attachment_categories, string attachment_category)
override void DraggingOverHeader(Widget w, int x, int y, Widget receiver)
override void CollapseButtonOnMouseButtonDown(Widget w)
void ShowInSlots(string category, bool show)
override bool CanOpenCloseContainerEx(EntityAI focusedEntity)
void AttachmentCategoriesContainer(LayoutHolder parent, int sort=-1)
override void OnDropReceivedFromHeader(Widget w, int x, int y, Widget receiver)
void LoadAttachmentCategoriesIcon(SlotsContainer items_cont, string icon_name, int slot_number)
string GetAttachmentCategory(string config_path_attachment_categories, int i)
int GetAttachmentCategoriesCount(string config_path)
override bool CanSplitEx(EntityAI focusedEntity)
string GetIconName(string config_path_attachment_categories, string attachment_category)
SlotsContainer GetSlotsContainer(int icons_row)
Super root of all classes in Enforce script.
Definition EnScript.c:11
ref CollapsibleHeader m_CollapsibleHeader
void SetCollapsibleHeaderArrowState(bool open)
override void Insert(LayoutHolder container, int pos=-1, bool immedUpdate=true)
static int RED_COLOR
static ColorManager GetInstance()
override bool IsEmpty()
static ItemManager GetInstance()
Object GetObject()
Definition SlotsIcon.c:362
override bool IsVisible()
Definition SlotsIcon.c:131
static const int IMAGESETGROUP_INVENTORY
static string VerifyIconImageString(int imageset_group=IMAGESETGROUP_INVENTORY, string icon_name="")
Checks for improperly formated, legacy image names and corrects them to default format.
static WidgetEventHandler GetInstance()
proto native CGame GetGame()
static proto bool CastTo(out Class to, Class from)
Try to safely down-cast base class to child class.
WidgetFlags
Definition EnWidgets.c:58