DayZ 1.24
Loading...
Searching...
No Matches
ItemManager.c
Go to the documentation of this file.
2{
3 private ref static ItemManager m_Instance;
4 protected bool m_IsDragging;
6 protected bool m_SlotInfoShown;
8 protected Icon m_DraggedIcon;
19
25
27
29
33
34 protected int m_TooltipPosX;
35 protected int m_TooltipPosY;
36 protected Widget m_TooltipSourceWidget; //stored here for tooltip position updates
37
38#ifndef PLATFORM_CONSOLE
39 protected const float TOOLTIP_DELAY = 0.25; // in seconds
40#else
41 protected const float TOOLTIP_DELAY = 1.5; // in seconds
42#endif
43
45 {
46 m_Instance = this;
50 m_SlotInfoShown = false;
51
52#ifdef PLATFORM_CONSOLE
53 m_TooltipWidget = GetGame().GetWorkspace().CreateWidgets("gui/layouts/inventory_new/day_z_inventory_new_tooltip_xbox.layout", root);
54 m_TooltipSlotWidget = GetGame().GetWorkspace().CreateWidgets("gui/layouts/inventory_new/day_z_inventory_new_tooltip_slot_xbox.layout", root);
55#else
56 m_TooltipWidget = GetGame().GetWorkspace().CreateWidgets("gui/layouts/inventory_new/day_z_inventory_new_tooltip.layout", root);
57 m_TooltipSlotWidget = GetGame().GetWorkspace().CreateWidgets("gui/layouts/inventory_new/day_z_inventory_new_tooltip_slot.layout", root);
58#endif
59 m_TooltipWidget.Show(false);
60 m_TooltipSlotWidget.Show(false);
61 }
62
64 {
66 Inventory.GetInstance().UpdateConsoleToolbar();
67 }
68
73
78
83
85 {
86 return m_SelectedItem;
87 }
88
93
98
100 {
101 return m_SelectedIcon;
102 }
103
111
113 {
115 Icon icon;
116
119
121 {
124 if (sIcon)
125 sIcon.GetMicromanagedPanel().Show(false);
126 else if (icon)
127 icon.GetMicromanagedPanel().Show(false);
128 }
129
130 if (selected_icon)
131 {
133 icon = Icon.Cast(selected_icon);
134
135 if (sIcon)
136 {
137 m_SelectedWidget = sIcon.GetCursorWidget();
138 sIcon.GetMicromanagedPanel().Show(true);
139 }
140 else if (icon)
141 {
142 m_SelectedWidget = icon.GetCursorWidget();
143 icon.GetMicromanagedPanel().Show(true);
144 }
145 }
146 else
149 }
150
152 {
153 m_DefautOpenStates.Clear();
154 }
155
160
161 void SetDefaultOpenState(string type, bool is_opened)
162 {
163 m_DefautOpenStates.Set(type, is_opened);
164 }
165
166 void SetDefaultHeaderOpenState(string type, bool is_opened)
167 {
169 }
170
172 {
174 int hands_default_open_state = m_HandsDefaultOpenState; //from bool to int for easier parsing
175 GetGame().SetProfileString("defaultOpenStateHands", hands_default_open_state.ToString());
176 GetGame().SaveProfile();
177 }
178
180 {
181 string value;
182 GetGame().GetProfileString("defaultOpenStateHands", value);
185 }
186
188 {
190
191 for (int i = 0; i < m_DefautHeaderOpenStates.Count(); i++)
192 {
193 int is_opened = m_DefautHeaderOpenStates.GetElement(i); //from bool to int for easier parsing
195 }
196
197 if (serialized_types.Count() > 0)
198 GetGame().SetProfileStringList("defaultHeaderOpenStates", serialized_types);
199 GetGame().SaveProfile();
200 }
201
203 {
205
207 GetGame().GetProfileStringList("defaultHeaderOpenStates", serialized_types);
208
209 for (int i = 0; i < serialized_types.Count(); i++)
210 {
212 serialized_types.Get(i).Split(",", strs);
213 bool is_opened = strs.Get(1).ToInt();
215 }
216 }
217
219 {
221
222 for (int i = 0; i < m_DefautOpenStates.Count(); i++)
223 {
224 int is_opened = m_DefautOpenStates.GetElement(i); //from bool to int for easier parsing
225 serialized_types.Insert(m_DefautOpenStates.GetKey(i) + "," + is_opened);
226 }
227
228 if (serialized_types.Count() > 0)
229 GetGame().SetProfileStringList("defaultOpenStates", serialized_types);
230 GetGame().SaveProfile();
231 }
232
234 {
236
238 GetGame().GetProfileStringList("defaultOpenStates", serialized_types);
239
240 for (int i = 0; i < serialized_types.Count(); i++)
241 {
243 serialized_types.Get(i).Split(",", strs);
244 bool is_opened = strs.Get(1).ToInt();
246 }
247 }
248
249 bool GetDefaultOpenState(string type)
250 {
251 if (m_DefautOpenStates.Contains(type))
252 return m_DefautOpenStates.Get(type);
253 else
254 return true;
255 }
256
258 {
259 if (m_DefautHeaderOpenStates.Contains(type))
260 return m_DefautHeaderOpenStates.Get(type);
261 else
262 return true;
263 }
264
266 {
267 return m_Instance;
268 }
269
271 {
272 GetRightDropzone().SetAlpha(0);
273 GetLeftDropzone().SetAlpha(0);
274 GetCenterDropzone().SetAlpha(0);
275 }
276
278 {
279 EntityAI owner = item.GetHierarchyParent();
281
282 if (item == player)
283 GetRightDropzone().SetAlpha(1);
284 else if (owner && owner != player)
286 else
287 {
289 item.GetInventory().GetCurrentInventoryLocation(inv_loc_src);
290 int loc_type = inv_loc_src.GetType();
292 if (loc_type == InventoryLocationType.GROUND)
293 GetLeftDropzone().SetAlpha(1);
294 else if (loc_type == InventoryLocationType.HANDS)
295 GetCenterDropzone().SetAlpha(1);
296 else
297 GetRightDropzone().SetAlpha(1);
298 }
299 }
300
302 {
303 if (!m_LeftDropzone)
304 m_LeftDropzone = m_RootWidget.FindAnyWidget("LeftPanel").FindAnyWidget("DropzoneX");
305
306 return m_LeftDropzone;
307 }
308
310 {
311 if (!m_RightDropzone)
312 m_RightDropzone = m_RootWidget.FindAnyWidget("RightPanel").FindAnyWidget("DropzoneX");
313 return m_RightDropzone;
314 }
315
317 {
318 if (!m_CenterDropzone)
319 m_CenterDropzone = m_RootWidget.FindAnyWidget("HandsPanel").FindAnyWidget("DropzoneX");
320 return m_CenterDropzone;
321 }
322
324 {
325 return m_HoveredItem;
326 }
327
332
334 {
335 return m_DraggedItem;
336 }
337
342
344 {
345 return m_DraggedIcon;
346 }
347
349 {
351 if (!is_dragging)
352 {
355 }
356 }
357
359 {
360 return m_IsDragging;
361 }
362
364 {
365 m_TooltipWidget.Show(false);
367 delete m_ToolTipTimer;
368
370 }
371
373 {
374 if (m_SlotInfoShown)
375 {
376 m_TooltipSlotWidget.Show(false);
377 m_SlotInfoShown = false;
378 delete m_TooltipSlotTimer;
379 }
380 }
381
383 {
384 switch (pHealthLevel)
385 {
386 case -1:
387 break;
389 return Colors.COLOR_PRISTINE;
391 return Colors.COLOR_WORN;
393 return Colors.COLOR_DAMAGED;
397 return Colors.COLOR_RUINED;
398 }
399
400 return 0x00FFFFFF;
401 }
402
403 static int GetItemHealthColor(EntityAI item, string zone = "")
404 {
405 if (item)
406 {
407 switch (item.GetHealthLevel(zone))
408 {
409 case -1:
410 break;
412 return Colors.COLOR_PRISTINE;
414 return Colors.COLOR_WORN;
416 return Colors.COLOR_DAMAGED;
420 return Colors.COLOR_RUINED;
421 }
422 }
423
424 return 0x00FFFFFF;
425 }
426
427 static int ColorFromFloat(float fraction)
428 {
429 if (fraction > 1 || fraction < 0)
430 return 0x00FFFFFF;
431 else if (fraction > 0.80)
432 return Colors.COLOR_PRISTINE;
433 else if (fraction > 0.6)
434 return Colors.COLOR_WORN;
435 else if (fraction > 0.4)
436 return Colors.COLOR_DAMAGED;
437 else if (fraction > 0.2)
439 else
440 return Colors.COLOR_RUINED;
441 }
442
444 {
445 if (item_w)
446 {
447 if (true/*show_temperature */)
448 {
449 if (item && item.IsInherited(ItemBase))
450 {
451 int color = ColorManager.GetInstance().GetItemColor(ItemBase.Cast(item)); // !!!!!
452 if (color)
453 {
454 string name = item_w.GetName();
455 name.Replace("Render", "Temperature");
456 Widget temperature_widget = item_w.GetParent().FindAnyWidget(name);
457 if (color != -1)
458 {
459 temperature_widget.Show(true);
460 temperature_widget.SetColor(color);
461 }
462 else
463 temperature_widget.Show(false);
464
465 temperature_widget.SetAlpha(0.3);
466 }
467 }
468 }
469 }
470 }
471
473 {
474 if (item_w)
475 {
476 if (item && item.IsInherited(ItemBase))
477 {
478 int color = ColorManager.GetInstance().GetItemColor(ItemBase.Cast(item));
479
480 if (color)
481 {
482 Widget color_widget = item_w.FindAnyWidget("Color");
483 if (color != -1)
484 color_widget.SetColor(color);
485 else
487 }
488 }
489 }
490 }
491
492 void PrepareTooltip(EntityAI item, int x = 0, int y = 0)
493 {
494 if (IsDragging() || !item)
495 return;
496
497 if (item.IsInherited(InventoryItem))
498 {
499 HideTooltip();
500
502 InspectMenuNew.UpdateItemInfo(m_TooltipWidget, item);
503
504 int screen_w, screen_h;
505 float w, h;
507 m_TooltipWidget.GetScreenSize(w, h);
508
509 if (x == -1)//set by icon focusing
510 {
511 x = screen_w / 2 - w / 2;
512 float x1, y1;
513 m_RootWidget.FindAnyWidget("InventoryFrameWidget").GetScreenPos(x1, y1); //allign to the same height
514 y = y1;
515 }
516 else if (x == 0 && y == 0 && GetGame().GetInput().IsEnabledMouseAndKeyboardEvenOnServer())
517 GetMousePos(x, y);
518
519 //minimal edge distance adjustments..
520 screen_w -= 10;
521 screen_h -= 10;
522
523 int rightEdge = x + w;
524 if (rightEdge > screen_w)
525 x = screen_w - w;
526
527 int bottomEdge = y + h;
528 if (bottomEdge > screen_h)
529 y = screen_h - h;
530
531 m_TooltipWidget.SetPos(x, y);
532
533 m_ToolTipTimer = new Timer();
534 m_ToolTipTimer.Run(TOOLTIP_DELAY, this, "ShowTooltip");
535
536 Widget preview_frame = m_TooltipWidget.FindAnyWidget("ItemFrameWidget");
537 if (preview_frame)
538 {
541 m_ItemPreviewWidget.SetView(item.GetViewIndex());
542 }
543 }
544 }
545
547 void PrepareSlotsTooltip(string name, string desc, int x = 0, int y = 0)
548 {
549 InspectMenuNew.UpdateSlotInfo(m_TooltipSlotWidget, name, desc);
550
551 HideTooltip();
552
553 if (name != "")
554 {
555 m_SlotInfoShown = true;
556 //CalculateTooltipSlotPosition(x,y);
558 m_TooltipSlotTimer.Run(TOOLTIP_DELAY, this, "ShowTooltipSlot");
559 }
560 }
561
562 void CalculateTooltipSlotPosition(int x = 0, int y = 0)
563 {
564 int screen_w, screen_h;
565 float w, h;
567 //m_TooltipSlotWidget.GetScreenSize(w,h);
568 m_TooltipSlotWidget.GetSize(w, h);
571 //minimal edge distance adjustments..
572 screen_w -= 10;
573 screen_h -= 10;
574
575#ifndef PLATFORM_CONSOLE
576 x += 5;
577 y += slot_normal_h + 5;
578#else
579 x += 5;
580 y += 15;
581#endif
583 while (scrollerWidget)
584 {
586 break;
587 else
588 scrollerWidget = scrollerWidget.GetParent();
589 }
590
591 int rightEdge = x + w;
592 if (rightEdge > screen_w)
593 x = screen_w - w;
594
595 int bottomEdge = y + h;
596 if (scrollerWidget)
597 {
599 scrollerWidget.GetScreenPos(scrollerX, scrollerY);
601
604 {
606 bottomEdge = y + h;
607 }
608 }
609 /*else
610 {
611 ErrorEx("No scroller widget! | m_TooltipSourceWidget: " + m_TooltipSourceWidget);
612 }*/
613
614 if (bottomEdge > screen_h) //should mostly never proc now
615 y = screen_h - h;
616
619 }
620
622 {
623 float x, y;
624 m_TooltipSourceWidget.GetScreenPos(x, y);
626 }
627
632
634 {
635 if (!ItemBase.Cast(entity))
636 return false;
637
638 bool draggable;
640 draggable = !player.GetInventory().HasInventoryReservation(entity, null) && !player.IsItemsToDelete();
641 draggable = draggable && entity.CanPutIntoHands(GetGame().GetPlayer());
642 draggable = draggable && entity.GetInventory().CanRemoveEntity();
643
644 return draggable;
645 }
646
648 {
649 if (w)
650 {
651 if (draggable)
652 w.SetFlags(WidgetFlags.DRAGGABLE);
653 else
654 w.ClearFlags(WidgetFlags.DRAGGABLE);
655 }
656 }
657
659 {
661 m_TooltipWidget.Show(true);
662 }
663
670
672 {
674
677
680
681 //EntityAI itemInHands = m_player.GetHumanInventory().GetEntityInHands();
682 ActionManagerClient amc = ActionManagerClient.Cast(player.GetActionManager());
683
685 {
686 if (amc.CanPerformActionFromInventory(targetItem, selectedItem))
688 }
689
691 {
692 if (amc.CanSetActionFromInventory(targetItem, selectedItem))
694 }
695
697 {
698 if (targetEntity.CanBeCombined(selectedEntity))
700 }
701
703 {
704 if (targetEntity.GetInventory().CanAddAttachment(selectedEntity))
706 }
707
709 {
710 if (!targetEntity.GetInventory().HasEntityInInventory(selectedEntity) && targetEntity.GetInventory().CanAddEntityInCargo(selectedEntity, selectedEntity.GetInventory().GetFlipCargo()))
712 }
713
715 {
717 Weapon_Base wpn = Weapon_Base.Cast(targetEntity.GetHierarchyParent());
718 if (wpn && mag)
719 {
720 if (player.GetWeaponManager().CanSwapMagazine(wpn, Magazine.Cast(selectedEntity)))
722 }
723 }
724
726 {
729 }
730
732 {
735 }
736
738 }
739
741 {
742 int flags = 0;
744
745 if (!entity1 || !entity2)
746 return flags;
747
748 if (entity1.IsInherited(ItemBase) && entity2.IsInherited(ItemBase))
749 {
751 if (ent1.CanBeCombined(ItemBase.Cast(entity2))) flags = flags | InventoryCombinationFlags.COMBINE_QUANTITY2;
752 }
753
754 if (entity1.GetInventory().CanAddAttachment(entity2))
755 {
756 if (!entity1.IsInherited(ZombieBase) && !entity1.IsInherited(Car) && !entity2.IsInherited(ZombieBase) && !entity2.IsInherited(Car))
758 }
759 if (!entity1.GetInventory().HasEntityInInventory(entity2) && entity1.GetInventory().CanAddEntityInCargo(entity2, entity2.GetInventory().GetFlipCargo())) flags = flags | InventoryCombinationFlags.ADD_AS_CARGO;
760
761 if (entity1 == m_player.GetHumanInventory().GetEntityInHands() || entity2 == m_player.GetHumanInventory().GetEntityInHands())
762 {
764 Class.CastTo(amc, m_player.GetActionManager());
765 if (entity1 == m_player.GetHumanInventory().GetEntityInHands())
766 {
767 if (amc.CanPerformActionFromInventory(ItemBase.Cast(entity1), ItemBase.Cast(entity2)))
769 else if (amc.CanSetActionFromInventory(ItemBase.Cast(entity1), ItemBase.Cast(entity2)))
771 }
772 else
773 {
774 if (amc.CanPerformActionFromInventory(ItemBase.Cast(entity2), ItemBase.Cast(entity1)))
776 else if (amc.CanSetActionFromInventory(ItemBase.Cast(entity2), ItemBase.Cast(entity1)))
778 }
779 }
780 return flags;
781 }
782
784 {
785 PluginRecipesManager plugin_recipes_manager = PluginRecipesManager.Cast(GetPlugin(PluginRecipesManager));
786 return plugin_recipes_manager.GetValidRecipes(ItemBase.Cast(entity1), ItemBase.Cast(entity2), NULL, PlayerBase.Cast(GetGame().GetPlayer()));
787 }
788}
void Inventory(LayoutHolder parent)
Definition Inventory.c:76
ActionInput GetInput()
Definition ActionBase.c:989
PlayerSpawnPresetDiscreteItemSetSlotData name
one set for cargo
Icon x
Icon y
InventoryLocationType
types of Inventory Location
PlayerBase GetPlayer()
PluginBase GetPlugin(typename plugin_type)
DayZPlayer m_player
Super root of all classes in Enforce script.
Definition EnScript.c:11
static int BASE_COLOR
static ColorManager GetInstance()
Definition Colors.c:4
const int COLOR_DAMAGED
Definition Colors.c:22
const int COLOR_BADLY_DAMAGED
Definition Colors.c:21
const int COLOR_PRISTINE
Definition Colors.c:24
const int COLOR_WORN
Definition Colors.c:23
const int COLOR_RUINED
Definition Colors.c:20
script counterpart to engine's class Inventory
Definition Inventory.c:79
static bool CanSwapEntitiesEx(notnull EntityAI item1, notnull EntityAI item2)
Definition Inventory.c:610
static bool CanForceSwapEntitiesEx(notnull EntityAI item1, InventoryLocation item1_dst, notnull EntityAI item2, out InventoryLocation item2_dst)
Definition Inventory.c:645
Definition Icon.c:2
InventoryLocation.
static ref ItemManager m_Instance
Definition ItemManager.c:3
Widget m_LeftDropzone
Definition ItemManager.c:30
ref map< string, bool > m_DefautHeaderOpenStates
Definition ItemManager.c:15
bool GetDefaultHeaderOpenState(string type)
static int GetItemHealthColor(EntityAI item, string zone="")
void SerializeDefaultHeaderOpenStates()
void CalculateTooltipSlotPosition(int x=0, int y=0)
const float TOOLTIP_DELAY
Definition ItemManager.c:39
void SetTemperature(EntityAI item, Widget item_w)
static int GetCombinationFlags(EntityAI entity1, EntityAI entity2)
void SetItemMicromanagmentMode(bool item_micromanagment_mode)
Definition ItemManager.c:63
int m_HandsDefaultOpenState
Definition ItemManager.c:16
void ClearDefaultOpenStates()
ref map< string, bool > m_DefautOpenStates
Definition ItemManager.c:14
ref Widget m_TooltipSlotWidget
Definition ItemManager.c:10
EntityAI GetDraggedItem()
void SetSelectedItemEx(EntityAI selected_item, Container selected_container, LayoutHolder selected_icon)
static int ColorFromFloat(float fraction)
Widget GetCenterDropzone()
EntityAI GetHoveredItem()
void ClearDefaultHeaderOpenStates()
Icon GetDraggedIcon()
void HideTooltipSlot()
HandsPreview GetHandsPreview()
Definition ItemManager.c:74
void ShowSourceDropzone(EntityAI item)
void DeserializeDefaultHeaderOpenStates()
void SetDefaultHeaderOpenState(string type, bool is_opened)
Container GetSelectedContainer()
Definition ItemManager.c:89
bool m_IsDragging
Definition ItemManager.c:4
EntityAI m_DraggedItem
Definition ItemManager.c:7
Widget m_CenterDropzone
Definition ItemManager.c:31
bool EvaluateContainerDragabilityDefault(EntityAI entity)
Widget m_RightDropzone
Definition ItemManager.c:32
SlotsIcon GetSelectedIcon()
Definition ItemManager.c:99
void ShowTooltipSlot()
HandsPreview m_HandsPreview
Definition ItemManager.c:26
void ShowTooltip()
EntityAI m_SelectedItem
Definition ItemManager.c:20
Icon m_DraggedIcon
Definition ItemManager.c:8
ref Widget m_TooltipWidget
Definition ItemManager.c:9
Widget GetLeftDropzone()
Widget m_TooltipSourceWidget
Definition ItemManager.c:36
void SetIconTemperature(EntityAI item, Widget item_w)
void SetHandsPreview(HandsPreview hansd_preview)
Definition ItemManager.c:79
void SetDraggedItem(EntityAI dragged_item)
bool m_SlotInfoShown
Definition ItemManager.c:6
ref Timer m_TooltipSlotTimer
Definition ItemManager.c:18
void SerializeDefaultOpenStates()
EntityAI m_HoveredItem
Definition ItemManager.c:5
ref Widget m_TooltipCategoryWidget
Definition ItemManager.c:11
ref Timer m_ToolTipTimer
Definition ItemManager.c:17
void HideTooltip()
Widget GetSelectedWidget()
Definition ItemManager.c:94
EntityAI GetSelectedItem()
Definition ItemManager.c:84
Widget GetRightDropzone()
void HideDropzones()
void PrepareTooltip(EntityAI item, int x=0, int y=0)
static int GetItemHealthColor(int pHealthLevel)
bool IsDragging()
Container m_SelectedContainer
Definition ItemManager.c:21
SlotsIcon m_SelectedIcon
Definition ItemManager.c:23
void DeserializeDefaultOpenStates()
bool IsMicromanagmentMode()
Definition ItemManager.c:69
Widget m_SelectedWidget
Definition ItemManager.c:22
void SetWidgetDraggable(Widget w, bool draggable)
Widget m_RootWidget
Definition ItemManager.c:13
ItemPreviewWidget m_ItemPreviewWidget
Definition ItemManager.c:12
static int GetRecipeCount(bool recipe_anywhere, EntityAI entity1, EntityAI entity2)
void SetDraggedIcon(Icon dragged_icon)
int m_TooltipPosX
Definition ItemManager.c:34
void SetIsDragging(bool is_dragging)
void SetDefaultOpenStateHands(bool is_opened)
void PrepareSlotsTooltip(string name, string desc, int x=0, int y=0)
position is currentlycalculated from the owning 'm_TooltipSourceWidget' directly
void SetTooltipWidget(Widget w)
bool m_ItemMicromanagmentMode
Definition ItemManager.c:28
LayoutHolder m_SelectedBaseIcon
Definition ItemManager.c:24
bool GetDefaultOpenStateHands()
void UpdateTooltipSlotPosition()
void ItemManager(Widget root)
Definition ItemManager.c:44
static int GetChosenCombinationFlag(EntityAI selectedEntity, EntityAI targetEntity, int relevantFlags, out InventoryLocation dst=null)
int m_TooltipPosY
Definition ItemManager.c:35
bool GetDefaultOpenState(string type)
static ItemManager GetInstance()
void SetSelectedItem(EntityAI selected_item, Container selected_container, Widget selected_widget, SlotsIcon selected_icon)
void SetDefaultOpenState(string type, bool is_opened)
proto native void SetView(int viewIndex)
proto native void SetItem(EntityAI object)
static int GetNormalWidth()
Definition SlotsIcon.c:750
static int GetNormalHeight()
Definition SlotsIcon.c:755
proto native CGame GetGame()
static proto bool CastTo(out Class to, Class from)
Try to safely down-cast base class to child class.
array< string > TStringArray
Definition EnScript.c:666
const int STATE_RUINED
Definition constants.c:757
const int STATE_WORN
Definition constants.c:760
const int STATE_DAMAGED
Definition constants.c:759
const int STATE_BADLY_DAMAGED
Definition constants.c:758
const int STATE_PRISTINE
Definition constants.c:761
proto void GetScreenSize(out int x, out int y)
proto void GetMousePos(out int x, out int y)
WidgetFlags
Definition EnWidgets.c:58