4 protected bool m_IsDragging;
6 protected bool m_SlotInfoShown;
8 protected Icon m_DraggedIcon;
9 protected ref
Widget m_TooltipWidget;
10 protected ref
Widget m_TooltipSlotWidget;
11 protected ref
Widget m_TooltipCategoryWidget;
13 protected Widget m_RootWidget;
16 protected int m_HandsDefaultOpenState;
17 protected ref
Timer m_ToolTipTimer;
18 protected ref
Timer m_TooltipSlotTimer;
22 protected Widget m_SelectedWidget;
28 protected bool m_ItemMicromanagmentMode;
30 protected Widget m_LeftDropzone;
31 protected Widget m_CenterDropzone;
32 protected Widget m_RightDropzone;
34 protected int m_TooltipPosX;
35 protected int m_TooltipPosY;
36 protected Widget m_TooltipSourceWidget;
38 #ifndef PLATFORM_CONSOLE
39 protected const float TOOLTIP_DELAY = 0.25;
41 protected const float TOOLTIP_DELAY = 1.5;
50 m_SlotInfoShown =
false;
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 );
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 );
59 m_TooltipWidget.Show(
false );
60 m_TooltipSlotWidget.Show(
false );
63 void SetItemMicromanagmentMode(
bool item_micromanagment_mode )
65 m_ItemMicromanagmentMode = item_micromanagment_mode;
66 Inventory.GetInstance().UpdateConsoleToolbar();
69 bool IsMicromanagmentMode()
71 return m_ItemMicromanagmentMode;
76 return m_HandsPreview;
81 m_HandsPreview = hansd_preview;
86 return m_SelectedItem;
91 return m_SelectedContainer;
96 return m_SelectedWidget;
101 return m_SelectedIcon;
106 m_SelectedItem = selected_item;
107 m_SelectedContainer = selected_container;
108 m_SelectedWidget = selected_widget;
109 m_SelectedIcon = selected_icon;
117 m_SelectedItem = selected_item;
118 m_SelectedContainer = selected_container;
120 if (m_SelectedBaseIcon)
122 sIcon =
SlotsIcon.Cast(m_SelectedBaseIcon);
123 icon =
Icon.Cast(m_SelectedBaseIcon);
126 sIcon.GetMicromanagedPanel().Show(
false);
130 icon.GetMicromanagedPanel().Show(
false);
137 icon =
Icon.Cast(selected_icon);
141 m_SelectedWidget = sIcon.GetCursorWidget();
142 sIcon.GetMicromanagedPanel().Show(
true);
146 m_SelectedWidget = icon.GetCursorWidget();
147 icon.GetMicromanagedPanel().Show(
true);
152 m_SelectedWidget =
null;
154 m_SelectedBaseIcon = selected_icon;
157 void ClearDefaultOpenStates()
159 m_DefautOpenStates.Clear();
162 void ClearDefaultHeaderOpenStates()
164 m_DefautHeaderOpenStates.Clear();
167 void SetDefaultOpenState(
string type,
bool is_opened )
169 m_DefautOpenStates.Set( type, is_opened );
172 void SetDefaultHeaderOpenState(
string type,
bool is_opened )
174 m_DefautHeaderOpenStates.Set( type, is_opened );
177 void SetDefaultOpenStateHands(
bool is_opened )
179 m_HandsDefaultOpenState = is_opened;
180 int hands_default_open_state = m_HandsDefaultOpenState;
181 GetGame().SetProfileString(
"defaultOpenStateHands", hands_default_open_state.ToString() );
185 bool GetDefaultOpenStateHands( )
188 GetGame().GetProfileString(
"defaultOpenStateHands", value );
189 m_HandsDefaultOpenState = value.ToInt();
190 return m_HandsDefaultOpenState;
193 void SerializeDefaultHeaderOpenStates()
197 for (
int i = 0; i < m_DefautHeaderOpenStates.Count(); i++ )
199 int is_opened = m_DefautHeaderOpenStates.GetElement( i );
200 serialized_types.Insert( m_DefautHeaderOpenStates.GetKey( i ) +
"," + is_opened );
203 if( serialized_types.Count() > 0 )
205 GetGame().SetProfileStringList(
"defaultHeaderOpenStates", serialized_types );
210 void DeserializeDefaultHeaderOpenStates()
212 ClearDefaultHeaderOpenStates();
215 GetGame().GetProfileStringList(
"defaultHeaderOpenStates", serialized_types );
217 for(
int i = 0; i < serialized_types.Count(); i++ )
220 serialized_types.Get( i ).Split(
",", strs );
221 bool is_opened = strs.Get( 1 ).ToInt();
222 SetDefaultHeaderOpenState( strs.Get( 0 ), is_opened );
226 void SerializeDefaultOpenStates()
230 for (
int i = 0; i < m_DefautOpenStates.Count(); i++ )
232 int is_opened = m_DefautOpenStates.GetElement( i );
233 serialized_types.Insert( m_DefautOpenStates.GetKey( i ) +
"," + is_opened );
236 if( serialized_types.Count() > 0 )
238 GetGame().SetProfileStringList(
"defaultOpenStates", serialized_types );
243 void DeserializeDefaultOpenStates()
245 ClearDefaultOpenStates();
248 GetGame().GetProfileStringList(
"defaultOpenStates", serialized_types );
250 for(
int i = 0; i < serialized_types.Count(); i++ )
253 serialized_types.Get( i ).Split(
",", strs );
254 bool is_opened = strs.Get( 1 ).ToInt();
255 SetDefaultOpenState( strs.Get( 0 ), is_opened );
259 bool GetDefaultOpenState(
string type )
261 if( m_DefautOpenStates.Contains( type ) )
263 return m_DefautOpenStates.Get( type );
271 bool GetDefaultHeaderOpenState(
string type )
273 if( m_DefautHeaderOpenStates.Contains( type ) )
275 return m_DefautHeaderOpenStates.Get( type );
290 GetRightDropzone().SetAlpha( 0 );
291 GetLeftDropzone().SetAlpha( 0 );
292 GetCenterDropzone().SetAlpha( 0 );
295 void ShowSourceDropzone(
EntityAI item )
297 EntityAI owner = item.GetHierarchyParent();
302 GetRightDropzone().SetAlpha(1);
304 else if (owner && owner != player)
306 ShowSourceDropzone(owner);
311 item.GetInventory().GetCurrentInventoryLocation(inv_loc_src);
312 int loc_type = inv_loc_src.GetType();
316 GetLeftDropzone().SetAlpha(1);
320 GetCenterDropzone().SetAlpha(1);
324 GetRightDropzone().SetAlpha(1);
332 m_LeftDropzone =
m_RootWidget.FindAnyWidget(
"LeftPanel").FindAnyWidget(
"DropzoneX");
334 return m_LeftDropzone;
339 if( !m_RightDropzone )
340 m_RightDropzone =
m_RootWidget.FindAnyWidget(
"RightPanel").FindAnyWidget(
"DropzoneX");
341 return m_RightDropzone;
344 Widget GetCenterDropzone()
346 if( !m_CenterDropzone )
347 m_CenterDropzone =
m_RootWidget.FindAnyWidget(
"HandsPanel").FindAnyWidget(
"DropzoneX");
348 return m_CenterDropzone;
353 return m_HoveredItem;
356 void SetDraggedItem(
EntityAI dragged_item )
358 m_DraggedItem = dragged_item;
363 return m_DraggedItem;
366 void SetDraggedIcon(
Icon dragged_icon )
368 m_DraggedIcon = dragged_icon;
371 Icon GetDraggedIcon()
373 return m_DraggedIcon;
376 void SetIsDragging(
bool is_dragging )
381 SetDraggedItem(
null );
382 SetDraggedIcon(
null );
393 m_TooltipWidget.Show(
false );
394 m_HoveredItem =
null;
395 delete m_ToolTipTimer;
400 void HideTooltipSlot()
402 if ( m_SlotInfoShown )
404 m_TooltipSlotWidget.Show(
false );
405 m_SlotInfoShown =
false;
406 delete m_TooltipSlotTimer;
410 static int GetItemHealthColor(
int pHealthLevel)
412 switch (pHealthLevel)
417 return Colors.COLOR_PRISTINE;
421 return Colors.COLOR_DAMAGED;
423 return Colors.COLOR_BADLY_DAMAGED;
425 return Colors.COLOR_RUINED;
431 static int GetItemHealthColor(
EntityAI item,
string zone =
"")
435 switch (item.GetHealthLevel(zone))
440 return Colors.COLOR_PRISTINE;
444 return Colors.COLOR_DAMAGED;
446 return Colors.COLOR_BADLY_DAMAGED;
448 return Colors.COLOR_RUINED;
455 static int ColorFromFloat(
float fraction )
457 if( fraction > 1 || fraction < 0 )
459 else if( fraction > 0.80 )
460 return Colors.COLOR_PRISTINE;
461 else if( fraction > 0.6 )
463 else if( fraction > 0.4 )
464 return Colors.COLOR_DAMAGED;
465 else if( fraction > 0.2 )
466 return Colors.COLOR_BADLY_DAMAGED;
468 return Colors.COLOR_RUINED;
477 if ( item && item.IsInherited(
ItemBase ) )
482 string name = item_w.GetName();
483 name.Replace(
"Render",
"Temperature");
484 Widget temperature_widget = item_w.GetParent().FindAnyWidget(
name );
487 temperature_widget.Show(
true );
488 temperature_widget.SetColor( color );
492 temperature_widget.Show(
false );
495 temperature_widget.SetAlpha( 0.3 );
506 if ( item && item.IsInherited(
ItemBase ) )
512 Widget color_widget = item_w.FindAnyWidget(
"Color" );
515 color_widget.SetColor( color );
526 void PrepareTooltip(
EntityAI item,
int x = 0,
int y = 0)
528 if( IsDragging() || !item )
537 m_HoveredItem = item;
538 InspectMenuNew.UpdateItemInfo( m_TooltipWidget, item );
540 int screen_w, screen_h;
543 m_TooltipWidget.GetScreenSize(w,h);
547 x = screen_w/2 - w/2;
549 m_RootWidget.FindAnyWidget(
"InventoryFrameWidget").GetScreenPos(x1,y1);
552 else if (
x == 0 &&
y == 0 &&
GetGame().
GetInput().IsEnabledMouseAndKeyboardEvenOnServer())
561 int rightEdge =
x + w;
562 if (rightEdge > screen_w)
567 int bottomEdge =
y + h;
568 if (bottomEdge > screen_h)
573 m_TooltipWidget.SetPos(
x,
y);
575 m_ToolTipTimer =
new Timer();
576 m_ToolTipTimer.Run( TOOLTIP_DELAY,
this,
"ShowTooltip" );
578 Widget preview_frame = m_TooltipWidget.FindAnyWidget(
"ItemFrameWidget");
589 void PrepareSlotsTooltip(
string name,
string desc,
int x = 0,
int y = 0)
591 InspectMenuNew.UpdateSlotInfo( m_TooltipSlotWidget,
name, desc );
597 m_SlotInfoShown =
true;
599 m_TooltipSlotTimer =
new Timer();
600 m_TooltipSlotTimer.Run( TOOLTIP_DELAY,
this,
"ShowTooltipSlot" );
604 void CalculateTooltipSlotPosition(
int x = 0,
int y = 0)
606 int screen_w, screen_h;
610 m_TooltipSlotWidget.GetSize(w,h);
611 int slot_normal_w =
SlotsIcon.GetNormalWidth();
612 int slot_normal_h =
SlotsIcon.GetNormalHeight();
617 #ifndef PLATFORM_CONSOLE
619 y += slot_normal_h + 5;
624 Widget scrollerWidget = m_TooltipSourceWidget.GetParent();
625 while (scrollerWidget)
627 if (ScrollWidget.Cast(scrollerWidget))
633 scrollerWidget = scrollerWidget.GetParent();
637 int rightEdge =
x + w;
638 if (rightEdge > screen_w)
643 int bottomEdge =
y + h;
646 float scrollerX, scrollerY, scrollerSizeX, scrollerSizeY;
647 scrollerWidget.GetScreenPos(scrollerX,scrollerY);
648 scrollerWidget.GetScreenSize(scrollerSizeX,scrollerSizeY);
650 int scroller_bottom = scrollerY + scrollerSizeY;
651 if (bottomEdge > scroller_bottom)
653 y = scroller_bottom - slot_normal_h;
662 if (bottomEdge > screen_h)
671 void UpdateTooltipSlotPosition()
674 m_TooltipSourceWidget.GetScreenPos(
x,
y);
675 CalculateTooltipSlotPosition(
x,
y);
678 void SetTooltipWidget(
Widget w)
680 m_TooltipSourceWidget = w;
683 bool EvaluateContainerDragabilityDefault(
EntityAI entity)
690 draggable = !player.GetInventory().HasInventoryReservation( entity,
null ) && !player.IsItemsToDelete();
692 draggable = draggable && entity.GetInventory().CanRemoveEntity();
697 void SetWidgetDraggable(
Widget w,
bool draggable )
712 m_TooltipWidget.Show(
true );
716 void ShowTooltipSlot()
718 UpdateTooltipSlotPosition();
719 m_TooltipSlotWidget.SetPos(m_TooltipPosX, m_TooltipPosY);
720 m_TooltipSlotWidget.Show(
true );
727 if (!selectedEntity || !targetEntity)
738 if (amc.CanPerformActionFromInventory(targetItem, selectedItem))
744 if (amc.CanSetActionFromInventory(targetItem, selectedItem))
750 if (targetEntity.CanBeCombined(selectedEntity))
758 if (targetEntity.GetInventory().CanAddAttachment(selectedEntity))
766 if (!targetEntity.GetInventory().HasEntityInInventory(selectedEntity) && targetEntity.GetInventory().CanAddEntityInCargo( selectedEntity, selectedEntity.GetInventory().GetFlipCargo() ))
774 Magazine mag = Magazine.Cast(targetEntity);
778 if (player.GetWeaponManager().CanSwapMagazine(wpn, Magazine.Cast(selectedEntity)))
787 if (
GameInventory.CanSwapEntitiesEx(selectedEntity, targetEntity))
795 if (
GameInventory.CanForceSwapEntitiesEx(selectedEntity,
null, targetEntity, dst))
809 if (!entity1 || !entity2)
818 if (entity1.GetInventory().CanAddAttachment( entity2 ))
820 if (!entity1.IsInherited(
ZombieBase ) && !entity1.IsInherited( Car ) && !entity2.IsInherited(
ZombieBase ) && !entity2.IsInherited( Car ))
825 if (!entity1.GetInventory().HasEntityInInventory(entity2) && entity1.GetInventory().CanAddEntityInCargo( entity2, entity2.GetInventory().GetFlipCargo() )) flags = flags |
InventoryCombinationFlags.ADD_AS_CARGO;
827 if (entity1 ==
m_player.GetHumanInventory().GetEntityInHands() || entity2 ==
m_player.GetHumanInventory().GetEntityInHands())
831 if (entity1 ==
m_player.GetHumanInventory().GetEntityInHands())
833 if (amc.CanPerformActionFromInventory(
ItemBase.Cast(entity1),
ItemBase.Cast(entity2) ))
837 else if (amc.CanSetActionFromInventory(
ItemBase.Cast(entity1),
ItemBase.Cast(entity2) ))
844 if (amc.CanPerformActionFromInventory(
ItemBase.Cast(entity2),
ItemBase.Cast(entity1) ))
848 else if (amc.CanSetActionFromInventory(
ItemBase.Cast(entity2),
ItemBase.Cast(entity1) ))
857 static int GetRecipeCount(
bool recipe_anywhere,
EntityAI entity1,
EntityAI entity2)
859 PluginRecipesManager plugin_recipes_manager = PluginRecipesManager.Cast(
GetPlugin( PluginRecipesManager ));