Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
handsarea.c
Go to the documentation of this file.
2 {
3  protected ScrollWidget m_Scroller;
4  protected ref HandsContainer m_HandsContainer;
5  protected ref SizeToChild m_HandsResizer;
6 
7  protected bool m_ShouldChangeSize = true;
8 
9  void HandsArea( LayoutHolder parent )
10  {
11  m_HandsContainer = new HandsContainer( this );
12  m_Body.Insert(m_HandsContainer);
13 
14  if ( m_ImmedUpdate )
15  m_MainWidget.Update();
16 
17  m_ParentWidget.GetScript( m_HandsResizer );
18  m_Scroller = ScrollWidget.Cast( m_ParentWidget );
19  RecomputeOpenedContainers();
20  }
21 
22  bool IsSwapActive()
23  {
24  Widget swap_cursor = m_MainWidget.FindAnyWidget("SwapCursor");
25 
26  if ( swap_cursor )
27  return swap_cursor.IsVisible();
28  else
29  return false;
30  }
31 
32  bool IsCombineActive()
33  {
34  Widget combine_cursor = m_MainWidget.FindAnyWidget("CombineCursor");
35 
36  if ( combine_cursor )
37  return combine_cursor.IsVisible();
38  else
39  return false;
40  }
41 
42  override ScrollWidget GetScrollWidget()
43  {
44  return m_Scroller;
45  }
46 
47  override void UpdateSelectionIcons()
48  {
49  #ifdef PLATFORM_CONSOLE
50  ScrollToActiveContainer();
51  #endif
52  }
53 
54  override void UpdateInterval()
55  {
56  if (!m_Scroller.IsScrollbarVisible())
57  {
58  m_Scroller.VScrollToPos01(0.0);
59  }
60  else if (m_Scroller.GetVScrollPos01() > 1.0)
61  {
62  m_Scroller.VScrollToPos01(1.0);
63  }
64  m_HandsContainer.UpdateInterval();
65 
66  float x, y;
67  float x2, y2;
68  m_Scroller.GetScreenSize( x, y );
69  m_MainWidget.GetScreenSize( x2, y2 );
70  if ( y2 != y )
71  m_ShouldChangeSize = true;
72 
73  bool changed_size;
74  if ( m_ShouldChangeSize && m_HandsResizer.ResizeParentToChild( changed_size, InventoryMenu.GetHeight() * 0.5 ) )
75  m_Scroller.SetAlpha( 0.3921 );
76  else
77  m_Scroller.SetAlpha( 0 );
78 
79  if ( changed_size )
80  m_ShouldChangeSize = false;
81  }
82 
83  override void SetLayoutName()
84  {
85  m_LayoutName = WidgetLayoutName.HandsArea;
86  }
87 
88  override void SetParentWidget()
89  {
90  m_ParentWidget = m_Parent.GetMainWidget().FindAnyWidget( "HandsPanel" );
91  }
92 
93  override void OnShow()
94  {
95  super.OnShow();
96  m_HandsContainer.OnShow();
97  }
98 
99  override void Refresh()
100  {
101  UpdateSelectionIcons();
102  m_ShouldChangeSize = true;
103  }
104 
105  override void SetSameLevelNextActive()
106  {
107  super.SetSameLevelNextActive();
108 
109  Refresh();
110  }
111  override void SetSameLevelPreviousActive()
112  {
113  super.SetSameLevelPreviousActive();
114 
115  Refresh();
116  }
117 
118  void DraggingOverHandsPanel( Widget w, int x, int y, Widget receiver )
119  {
120  if ( w == NULL )
121  {
122  return;
123  }
124 
125  ItemPreviewWidget ipw = ItemPreviewWidget.Cast( w.FindAnyWidget( "Render" ) );
126 
127  if( !ipw )
128  {
129  string name = w.GetName();
130  name.Replace( "PanelWidget", "Render" );
131  ipw = ItemPreviewWidget.Cast( w.FindAnyWidget( name ) );
132  }
133 
134  if( !ipw )
135  {
136  ipw = ItemPreviewWidget.Cast( w );
137  }
138 
139  if( !ipw || !ipw.IsInherited( ItemPreviewWidget ) )
140  {
141  return;
142  }
143 
144  if( ipw.GetItem() && GetGame().GetPlayer().GetHumanInventory().CanAddEntityIntoHands( ipw.GetItem() ) )
145  {
146  ColorManager.GetInstance().SetColor( w, ColorManager.GREEN_COLOR );
147  ItemManager.GetInstance().HideDropzones();
148  ItemManager.GetInstance().GetCenterDropzone().SetAlpha( 1 );
149  }
150  else
151  {
152  ColorManager.GetInstance().SetColor( w, ColorManager.RED_COLOR );
153  ItemManager.GetInstance().HideDropzones();
154  ItemManager.GetInstance().GetCenterDropzone().SetAlpha( 1 );
155  }
156  }
157 
158  void OnHandsPanelDropReceived( Widget w, int x, int y, Widget receiver )
159  {
160  ItemPreviewWidget ipw = ItemPreviewWidget.Cast( w.FindAnyWidget( "Render" ) );
161  if( !ipw )
162  {
163  string name = w.GetName();
164  name.Replace( "PanelWidget", "Render" );
165  ipw = ItemPreviewWidget.Cast( w.FindAnyWidget( name ) );
166  }
167 
168  if( !ipw )
169  {
170  ipw = ItemPreviewWidget.Cast( w );
171  }
172 
173  if( !ipw || !ipw.GetItem() || !ipw.IsInherited( ItemPreviewWidget ) )
174  {
175  return;
176  }
177 
178  if( !ipw.GetItem().GetInventory().CanRemoveEntity() )
179  return;
180 
181  if( GetGame().GetPlayer().GetHumanInventory().CanAddEntityIntoHands( ipw.GetItem() ) )
182  {
183  ItemBase item_base = ItemBase.Cast( ipw.GetItem() );
184  float stackable = item_base.GetTargetQuantityMax(-1);
185 
186  if( stackable == 0 || item_base.GetQuantity() <= stackable )
187  {
188  GetGame().GetPlayer().PredictiveTakeEntityToHands( item_base );
189  }
190  else if( stackable != 0 && stackable <= item_base.GetQuantity() )
191  {
192  item_base.SplitIntoStackMaxHandsClient( PlayerBase.Cast( GetGame().GetPlayer() ) );
193  }
194  }
195  }
196 }
ItemBase
Definition: inventoryitem.c:730
GetGame
proto native CGame GetGame()
LayoutHolder
Definition: container.c:1
y
Icon y
WidgetLayoutName
Definition: widgetlayoutname.c:1
m_Parent
protected Widget m_Parent
Definition: sizetochild.c:92
PlayerBase
Definition: playerbaseclient.c:1
ColorManager
Definition: colormanager.c:1
Container
Definition: cargocontainer.c:2
ItemManager
Definition: itemmanager.c:1
HandsArea
Definition: handsarea.c:1
name
PlayerSpawnPresetDiscreteItemSetSlotData name
one set for cargo
x
Icon x
GetPlayer
protected void GetPlayer()
Definition: crosshairselector.c:127
ItemPreviewWidget
Definition: gameplay.c:275
InventoryMenu
void InventoryMenu()
Definition: inventorymenu.c:20
m_ParentWidget
protected Widget m_ParentWidget
Definition: uihintpanel.c:24
Widget
Definition: enwidgets.c:189
HandsContainer
Definition: handscontainer.c:1