Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
closablecontainer.c
Go to the documentation of this file.
1 class ClosableContainer extends Container
2 {
3  protected ref ClosableHeader m_ClosableHeader;
4  protected bool m_LockCargo;
5 
6  void ClosableContainer( LayoutHolder parent, int sort = -1 )
7  {
8  m_Body = new array<ref LayoutHolder>;
9  m_ClosableHeader = new ClosableHeader( this, "CloseButtonOnMouseButtonDown" );
10 
11  if( sort > -1 )
12  m_RootWidget.SetSort( sort + 2 );
13 
14  m_MainWidget = m_MainWidget.FindWidget( "body" );
15  }
16 
17  override bool IsDisplayable()
18  {
19  for(int i = 0; i < m_Body.Count(); i++)
20  {
21  LayoutHolder c = m_Body[i];
22  if( c && c.IsDisplayable())
23  return true;
24  }
25  return false;
26  }
27 
28  override void UpdateRadialIcon()
29  {
30  if ( m_SlotIcon )
31  {
32  bool show_radial_icon;
33  show_radial_icon = IsOpened();
34  show_radial_icon = show_radial_icon && ( ( m_Entity.GetInventory().GetCargo() && m_Entity.CanDisplayCargo()) || m_Entity.GetSlotsCountCorrect() > 0 );
35  show_radial_icon = show_radial_icon && !m_Entity.GetInventory().IsInventoryLockedForLockType( HIDE_INV_FROM_SCRIPT );
36  if ( IsDisplayable() )
37  {
38  m_SlotIcon.GetRadialIconPanel().Show( true );
39  SetOpenForSlotIcon(show_radial_icon);
40  }
41  else
42  {
43  m_SlotIcon.GetRadialIconPanel().Show( false );
44  }
45  }
46  }
47 
48  void SetOpenState( bool state )
49  {
50  ItemManager.GetInstance().SetDefaultOpenState( m_Entity.GetType(), state );
51  m_Closed = !state;
52  if( !m_Closed )
53  {
54  OnShow();
55  }
56  else
57  {
58  OnHide();
59  }
60  }
61 
62  override Header GetHeader()
63  {
64  return m_ClosableHeader;
65  }
66 
67  override void Open()
68  {
69  if( IsDisplayable() )
70  {
71  super.Open();
72  ItemManager.GetInstance().SetDefaultOpenState( m_Entity.GetType(), true );
73  SetOpenForSlotIcon(true);
74  OnShow();
75  m_Parent.m_Parent.Refresh();
76  }
77  }
78 
79  override void Close()
80  {
81  ItemManager.GetInstance().SetDefaultOpenState( m_Entity.GetType(), false );
82  super.Close();
83  SetOpenForSlotIcon(false);
84  OnHide();
85  m_Parent.m_Parent.Refresh(); //TODO: ???
86  }
87 
88  override void SetLayoutName()
89  {
90  m_LayoutName = WidgetLayoutName.ClosableContainer;
91  }
92 
93  override void OnShow()
94  {
95  if( IsOpened() )
96  {
97  super.OnShow();
98  }
99  }
100 
101  override LayoutHolder Get( int x )
102  {
103  if( m_Body && x < m_Body.Count() && x >= 0 )
104  return m_Body.Get( x );
105  return null;
106  }
107 
108  override void Refresh()
109  {
110  if( !m_Closed )
111  {
112  super.Refresh();
113  }
114  }
115 
116  void CloseButtonOnMouseButtonDown()
117  {
118  Close();
119  }
120 
121  override float GetFocusedContainerHeight( bool contents = false )
122  {
123  float x, y;
124  if( contents && GetFocusedContainer() )
125  y = GetFocusedContainer().GetFocusedContainerHeight( contents );
126  else if( GetRootWidget() )
127  GetRootWidget().GetScreenSize( x, y );
128  return y;
129  }
130 
131  override float GetFocusedContainerYPos( bool contents = false )
132  {
133  float x, y;
134  if( contents && GetFocusedContainer() )
135  y = GetFocusedContainer().GetFocusedContainerYPos( contents );
136  else if( GetRootWidget() )
137  GetRootWidget().GetPos( x, y );
138  return y;
139  }
140 
141  override float GetFocusedContainerYScreenPos( bool contents = false )
142  {
143  float x, y;
144  if( contents && GetFocusedContainer() )
145  y = GetFocusedContainer().GetFocusedContainerYScreenPos( contents );
146  else if( GetRootWidget() )
147  GetRootWidget().GetScreenPos( x, y );
148  return y;
149  }
150 
151  void MoveContainerUp( Widget cont )
152  {
153  if( m_Entity )
154  {
156  m_Entity.GetInventory().GetCurrentInventoryLocation( loc );
157  if( loc.IsValid() )
158  {
159  int slot = loc.GetSlot();
160  Inventory.MoveAttachmentUp( slot );
161  UpdateSelectionIcons();
162  }
163  }
164  }
165 
166  void MoveContainerDown( Widget cont )
167  {
168  if( m_Entity )
169  {
171  m_Entity.GetInventory().GetCurrentInventoryLocation( loc );
172  if( loc.IsValid() )
173  {
174  int slot = loc.GetSlot();
175  Inventory.MoveAttachmentDown( slot );
176  UpdateSelectionIcons();
177  }
178  }
179  }
180 
181  override void CheckHeaderDragability()
182  {
183  super.CheckHeaderDragability();
184 
185  if (m_ClosableHeader && m_Entity) //TODO: do the entity check here?
186  {
187  int flag = m_ClosableHeader.GetMainWidget().GetFlags();
188  bool old = flag & WidgetFlags.DRAGGABLE;
189  bool current = ItemBase.Cast(m_Entity) && m_Entity.IsTakeable();
190  //bool changed = false;
191  if (old && !current)
192  {
193  m_ClosableHeader.GetMainWidget().ClearFlags( WidgetFlags.DRAGGABLE );
194  Widget drag = GetDragWidget();
195  if (drag && drag == m_ClosableHeader.GetMainWidget())
196  {
198  m_ClosableHeader.OnDropHeader(null);
199  }
200 
201  //changed = true;
202  }
203  else if (!old && current)
204  {
205  m_ClosableHeader.GetMainWidget().SetFlags( WidgetFlags.DRAGGABLE );
206  //changed = true;
207  }
208  /*if (old != current)
209  {
210  flag &= ~WidgetFlags.DRAGGABLE;
211  m_ClosableHeader.GetMainWidget().SetFlags( flag );
212  }*/
213  }
214  }
215 }
ItemBase
Definition: inventoryitem.c:730
LayoutHolder
Definition: container.c:1
m_RootWidget
ref Widget m_RootWidget[MAX_SIMULTANIOUS_PLAYERS]
Definition: pluginremoteplayerdebugclient.c:14
OnHide
override void OnHide()
Definition: inventorymenu.c:141
y
Icon y
InventoryLocation
InventoryLocation.
Definition: inventorylocation.c:27
WidgetLayoutName
Definition: widgetlayoutname.c:1
m_Parent
protected Widget m_Parent
Definition: sizetochild.c:92
Refresh
void Refresh()
Definition: sizetochild.c:108
CancelWidgetDragging
proto native Widget CancelWidgetDragging()
Header
Definition: header.c:1
SetLayoutName
override void SetLayoutName()
Definition: inventory.c:1078
GetHeader
string GetHeader()
Definition: errorproperties.c:76
Container
Definition: cargocontainer.c:2
GetDragWidget
proto native Widget GetDragWidget()
ItemManager
Definition: itemmanager.c:1
Get
array< ref PlayerStatBase > Get()
Definition: playerstatspco.c:103
array< ref LayoutHolder >
ClosableHeader
Definition: closableheader.c:1
x
Icon x
WidgetFlags
WidgetFlags
Definition: enwidgets.c:57
Inventory
void Inventory(LayoutHolder parent)
Definition: inventory.c:76
OnShow
override void OnShow()
Definition: controlsxbox.c:349
Widget
Definition: enwidgets.c:189
ClosableContainer
Definition: containerwithcargo.c:1
m_Entity
EntityAI m_Entity
Definition: actiondebug.c:11