Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
closableheader.c
Go to the documentation of this file.
2 {
3  protected float m_SquareSize;
4  protected int m_DefaultSort;
5 
6  protected Widget m_MovePanel;
7  protected Widget m_PanelWidget;
8  protected Widget m_DragRender;
9  protected ButtonWidget m_MoveUp;
10  protected ButtonWidget m_MoveDown;
11 
12  protected bool m_IsInLocalEquipment;
13 
14  void ClosableHeader( LayoutHolder parent, string function_name )
15  {
16  m_MovePanel = GetMainWidget().FindAnyWidget( "MovePanel" );
17  m_PanelWidget = GetMainWidget().FindAnyWidget( "PanelWidget" );
18  m_DragRender = GetMainWidget().FindAnyWidget( "Drag_Render" );
19  m_MoveUp = ButtonWidget.Cast( GetMainWidget().FindAnyWidget( "MoveUp" ) );
20  m_MoveDown = ButtonWidget.Cast( GetMainWidget().FindAnyWidget( "MoveDown" ) );
21 
22  WidgetEventHandler.GetInstance().RegisterOnClick( m_MoveUp, m_Parent, "MoveContainerUp" );
23  WidgetEventHandler.GetInstance().RegisterOnClick( m_MoveDown, m_Parent, "MoveContainerDown" );
24  WidgetEventHandler.GetInstance().RegisterOnMouseLeave( m_MoveUp, this, "MouseLeave" );
25  WidgetEventHandler.GetInstance().RegisterOnMouseLeave( m_MoveDown, this, "MouseLeave" );
26 
27  WidgetEventHandler.GetInstance().RegisterOnDrag( GetMainWidget() , this, "OnDragHeader" );
28  WidgetEventHandler.GetInstance().RegisterOnDrop( GetMainWidget() , this, "OnDropHeader" );
29 
30  WidgetEventHandler.GetInstance().RegisterOnMouseEnter( GetMainWidget(), this, "MouseEnter" );
31  WidgetEventHandler.GetInstance().RegisterOnMouseLeave( GetMainWidget(), this, "MouseLeave" );
32 
33  float temp;
34  GetMainWidget().GetScreenSize( temp, m_SquareSize );
35 
36  m_DefaultColor = m_PanelWidget.GetColor();
37  m_DefaultFontSize = 20;
38 
40  m_IsInLocalEquipment = GetParent().GetParent().GetParent().IsInherited( RightArea );
41  }
42 
43  void ~ClosableHeader()
44  {
45  if( InventoryItem.Cast( m_Entity ) )
46  InventoryItem.Cast( m_Entity ).GetOnItemFlipped().Remove( UpdateFlip );
47  }
48 
49  override void SetLayoutName()
50  {
51  m_LayoutName = WidgetLayoutName.ClosableHeader;
52  }
53 
54  override void SetName( string name )
55  {
56  name.ToUpper();
57 
58  m_HeaderText.SetText( name );
59  m_HeaderText.Update();
60 
61  float x, y;
62  m_HeaderText.GetScreenSize( x, y );
63  m_PanelWidget.SetSize( 1, y + InventoryMenu.GetHeightMultiplied( 10 ) );
64  }
65 
66  void OnDragHeader( Widget w, int x, int y )
67  {
69  if( parent && GetMainWidget() && m_Entity )
70  {
71  ItemPreviewWidget item_preview_drag = ItemPreviewWidget.Cast( m_DragRender );
72  item_preview_drag.SetFlags(WidgetFlags.EXACTPOS );
73  m_DefaultSort = GetRootWidget().GetSort();
74  item_preview_drag.GetParent().GetParent().GetParent().GetParent().GetParent().GetParent().GetParent().GetParent().AddChild( GetRootWidget() );
75  if( item_preview_drag && m_Entity )
76  {
77  item_preview_drag.SetItem( m_Entity );
78  item_preview_drag.SetView( m_Entity.GetViewIndex() );
79  }
80 
81  ItemManager.GetInstance().SetIsDragging( true );
82 
83  parent.HideContent( true );
84 
85  m_PanelWidget.Show( false );
86  if( item_preview_drag )
87  item_preview_drag.Show( true );
88 
89  int ww, hh;
90  GetGame().GetInventoryItemSize( InventoryItem.Cast( m_Entity ), ww, hh );
91  if( item_preview_drag )
92  {
93  m_Entity.GetOnItemFlipped().Insert( UpdateFlip );
94  if( m_Entity.GetInventory().GetFlipCargo() )
95  {
96  item_preview_drag.SetSize( hh * m_SquareSize, ww * m_SquareSize );
97  }
98  else
99  {
100  item_preview_drag.SetSize( ww * m_SquareSize, hh * m_SquareSize );
101  }
102  }
103  }
104  }
105 
106  void UpdateFlip( bool flipped )
107  {
108  ItemPreviewWidget item_preview_drag = ItemPreviewWidget.Cast( m_DragRender );
109  if( InventoryItem.Cast( m_Entity ) && item_preview_drag )
110  {
111  int ww, hh;
112  GetGame().GetInventoryItemSize( InventoryItem.Cast( m_Entity ), ww, hh );
113  if( flipped )
114  {
115  item_preview_drag.SetSize( hh * m_SquareSize, ww * m_SquareSize );
116  }
117  else
118  {
119  item_preview_drag.SetSize( ww * m_SquareSize, hh * m_SquareSize );
120  }
121  }
122  }
123 
124  void OnDropHeader( Widget w )
125  {
127  parent.GetMainWidget().AddChild( GetRootWidget() );
128  GetRootWidget().SetSort( 0 );
129  if( parent )
130  {
131  //
132  ItemPreviewWidget item_preview_drag = ItemPreviewWidget.Cast( m_DragRender );
133  if( item_preview_drag )
134  {
135  item_preview_drag.SetItem( null );//TODO: is this safe?
136  }
137  //
138 
139  m_PanelWidget.Show( true );
140  m_DragRender.Show( false );
141 
142  parent.ShowContent( true );
143 
144  ItemManager.GetInstance().HideDropzones();
145  ItemManager.GetInstance().SetIsDragging( false );
146  }
147  if( InventoryItem.Cast( m_Entity ) )
148  InventoryItem.Cast( m_Entity ).GetOnItemFlipped().Remove( UpdateFlip );
149  }
150 
151  bool MouseEnter(Widget w, int x, int y)
152  {
153  if( m_IsInLocalEquipment && !GetDragWidget() )
154  {
155  #ifdef PLATFORM_CONSOLE
156  m_MovePanel.Show( GetGame().GetInput().IsEnabledMouseAndKeyboardEvenOnServer() );
157  #else
158  m_MovePanel.Show( true );
159  #endif
160  }
161  PrepareOwnedTooltip( m_Entity, x, y );
162  return true;
163  }
164 
165  bool MouseLeave( Widget w, Widget enter_w, int x, int y )
166  {
167  if( enter_w != m_MoveUp && enter_w != m_MoveDown && enter_w != m_CollapseButton )
168  {
169  if( m_IsInLocalEquipment )
170  {
171  m_MovePanel.Show( false );
172  }
173  }
174  HideOwnedTooltip();
175  return true;
176  }
177 
178  override void SetActive( bool active )
179  {
180  super.SetActive( active );
181  if( active )
182  {
183  m_PanelWidget.SetColor( ARGBF( 1, 1, 0, 0 ) );
184  }
185  else
186  {
187  m_PanelWidget.SetColor( m_DefaultColor );
188  }
189  }
190 }
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
InventoryItem
Definition: itembase.c:13
FindAnyWidget
proto native Widget FindAnyWidget(string pathname)
RightArea
Definition: rightarea.c:1
Header
Definition: header.c:1
GetDragWidget
proto native Widget GetDragWidget()
ItemManager
Definition: itemmanager.c:1
ARGBF
int ARGBF(float fa, float fr, float fg, float fb)
Converts <0.0, 1.0> ARGB into color.
Definition: proto.c:332
ClosableHeader
Definition: closableheader.c:1
name
PlayerSpawnPresetDiscreteItemSetSlotData name
one set for cargo
x
Icon x
ItemPreviewWidget
Definition: gameplay.c:275
WidgetFlags
WidgetFlags
Definition: enwidgets.c:57
InventoryMenu
void InventoryMenu()
Definition: inventorymenu.c:20
GetParent
proto native Widget GetParent()
Get parent of the Effect.
Definition: effect.c:405
Widget
Definition: enwidgets.c:189
GetInput
ActionInput GetInput()
Definition: actionbase.c:1066
ClosableContainer
Definition: containerwithcargo.c:1
m_Entity
EntityAI m_Entity
Definition: actiondebug.c:11
WidgetEventHandler
Definition: widgeteventhandler.c:1