Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
handspreview.c
Go to the documentation of this file.
2 {
3  protected ref Icon m_Icon;
4  protected EntityAI m_AttachmentsInitialized;
5 
6  protected float m_IconSize;
7 
8  protected ItemBase m_Item
9 
10  void HandsPreview( LayoutHolder parent )
11  {
12  GetGame().GetPlayer().GetOnItemAddedToHands().Insert( CreateNewIcon );
13  GetGame().GetPlayer().GetOnItemRemovedFromHands().Insert( DeleteIcon );
14  }
15 
16  void ~HandsPreview()
17  {
18  GetGame().GetPlayer().GetOnItemAddedToHands().Remove( CreateNewIcon );
19  GetGame().GetPlayer().GetOnItemRemovedFromHands().Remove( DeleteIcon );
20  }
21 
22  void RefreshQuantity( EntityAI m_Item_to_refresh )
23  {
24  if ( m_Icon )
25  {
26  m_Icon.SetQuantity();
27  }
28  }
29 
30  override EntityAI GetFocusedItem()
31  {
32  return m_Item;
33  }
34 
35  Icon GetIcon()
36  {
37  return m_Icon;
38  }
39 
40  override void SetDefaultFocus(bool while_micromanagment_mode = false)
41  {
42  super.SetDefaultFocus(while_micromanagment_mode);
43  if ( m_Icon )
44  m_Icon.SetActive(true);
45  }
46 
47  override void SetLastFocus()
48  {
49  super.SetLastFocus();
50  if ( m_Icon )
51  m_Icon.SetActive(true);
52  }
53 
54  override void Unfocus()
55  {
56  super.Unfocus();
57  if ( m_Icon )
58  m_Icon.SetActive(false);
59  }
60 
61  float GetIconSize()
62  {
63  return m_IconSize;
64  }
65 
66  override void SetLayoutName()
67  {
68  m_LayoutName = WidgetLayoutName.HandsPreview;
69  }
70 
71  void RemoveItem()
72  {
73  delete m_Icon;
74  m_Item = null;
75  }
76 
77  override void UpdateInterval()
78  {
79  bool show_combine_swap = ItemManager.GetInstance().IsDragging();
80 
81  #ifdef PLATFORM_CONSOLE
82  if ( m_Icon && !m_Icon.IsDragged() && GetGame().GetInput().IsEnabledMouseAndKeyboardEvenOnServer() )
83  #else
84  if ( m_Icon && !m_Icon.IsDragged() )
85  #endif
86  {
87  m_Icon.GetMainWidget().FindAnyWidget( "Combine" ).Show( show_combine_swap );
88  m_Icon.GetMainWidget().FindAnyWidget( "Swap" ).Show( show_combine_swap );
89  }
90 
91  if ( m_Icon )
92  {
93  m_Icon.UpdateInterval();
94  }
95  }
96 
97  void CreateNewIcon( ItemBase item )
98  {
99  float y;
100  GetRootWidget().GetParent().GetParent().GetParent().GetParent().GetScreenSize( m_IconSize, y );
101  m_IconSize = m_IconSize / 10;
102 
103  m_Icon = new Icon( this, true );
104  m_Icon.Refresh();
105  if ( m_Icon )
106  {
107  m_Item = item;
108  m_Icon.Init( m_Item );
109  m_Icon.FullScreen();
110  ( HandsContainer.Cast( m_Parent ) ).ShowAtt( m_Item );
111  m_Icon.Refresh();
112  }
113 
114  m_RootWidget.SetColor( ARGB( 180, 0, 0, 0 ) );
115  m_Parent.GetParent().Refresh();
116  Inventory.GetInstance().UpdateConsoleToolbar();
117 
118  HandsContainer parent = HandsContainer.Cast( m_Parent );
119  HandsHeader header = HandsHeader.Cast( parent.GetHeader() );
120 
121  if( m_Item && !m_Item.GetInventory().GetCargo() )
122  {
123  string display_name = m_Item.GetDisplayName();
124  display_name.ToUpper();
125  header.SetName( display_name );
126  }
127  }
128 
129  void DeleteIcon()
130  {
131  RemoveItem();
132  ( HandsContainer.Cast( m_Parent ) ).DestroyAtt();
133  ( HandsContainer.Cast( m_Parent ) ).DestroyCargo();
134  ( HandsContainer.Cast( m_Parent ) ).RemoveItem();
135  m_AttachmentsInitialized = null;
136  m_RootWidget.SetColor( ARGB( 166, 80, 80, 80 ) );
137  m_Parent.GetParent().Refresh();
138  Inventory.GetInstance().UpdateConsoleToolbar();
139  }
140 
141  override bool SelectItem()
142  {
143  if( m_Item )
144  {
145  ItemManager.GetInstance().SetSelectedItemEx(m_Item, null, null);
146  return true;
147  }
148  return false;
149  }
150 
151  override bool Select()
152  {
153  Man player = GetGame().GetPlayer();
154  EntityAI item_in_hands = m_Item;
155  if( ItemManager.GetInstance().IsMicromanagmentMode() )
156  {
157  EntityAI selected_item = ItemManager.GetInstance().GetSelectedItem();
158  if( selected_item && selected_item.GetInventory().CanRemoveEntity() )
159  {
160  if(item_in_hands && item_in_hands.GetInventory().CanRemoveEntity())
161  {
162  if( GameInventory.CanSwapEntitiesEx( item_in_hands, selected_item ) )
163  {
164  player.PredictiveSwapEntities( item_in_hands, selected_item );
165  return true;
166  }
167  }
168  else
169  {
170  if ( player.GetHumanInventory().CanAddEntityInHands( selected_item ) && selected_item.GetInventory().CanRemoveEntity())
171  {
172  ItemBase item_base = ItemBase.Cast( selected_item );
173  float stackable = item_base.GetTargetQuantityMax();
174  if (stackable == 0 || item_base.GetQuantity() <= stackable)
175  {
176  GetGame().GetPlayer().PredictiveTakeEntityToHands( item_base );
177  return true;
178  }
179  else if( stackable != 0 && stackable <= item_base.GetQuantity() )
180  {
181  item_base.SplitIntoStackMaxHandsClient(PlayerBase.Cast( GetGame().GetPlayer() ));
182  return true;
183  }
184  }
185  }
186  }
187  }
188  return false;
189  }
190 }
ItemBase
Definition: inventoryitem.c:730
GetGame
proto native CGame GetGame()
LayoutHolder
Definition: container.c:1
HandsHeader
Definition: handsheader.c:1
m_RootWidget
ref Widget m_RootWidget[MAX_SIMULTANIOUS_PLAYERS]
Definition: pluginremoteplayerdebugclient.c:14
y
Icon y
WidgetLayoutName
Definition: widgetlayoutname.c:1
m_Item
protected EntityAI m_Item
Definition: radialquickbarmenu.c:14
HandsPreview
Definition: handspreview.c:1
m_Parent
protected Widget m_Parent
Definition: sizetochild.c:92
PlayerBase
Definition: playerbaseclient.c:1
Container
Definition: cargocontainer.c:2
ItemManager
Definition: itemmanager.c:1
GetPlayer
protected void GetPlayer()
Definition: crosshairselector.c:127
Icon
Definition: icon.c:1
Inventory
void Inventory(LayoutHolder parent)
Definition: inventory.c:76
GetInput
ActionInput GetInput()
Definition: actionbase.c:1066
EntityAI
Definition: building.c:5
ARGB
int ARGB(int a, int r, int g, int b)
Definition: proto.c:322
HandsContainer
Definition: handscontainer.c:1
GameInventory
script counterpart to engine's class Inventory
Definition: inventory.c:78