Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
dropdownprefab.c
Go to the documentation of this file.
1 class DropdownPrefab extends ScriptedWidgetEventHandler
2 {
3  protected Widget m_Root;
4  protected Widget m_Parent;
5  protected ScrollWidget m_Scroller;
6  protected Widget m_ContentContainer;
7  protected ref array<Widget> m_Content = new array<Widget>;
8 
9  protected Widget m_Button;
10  protected Widget m_Holder;
11  protected TextWidget m_Text;
12  protected ImageWidget m_ImageExpand;
13  protected ImageWidget m_ImageCollapse;
14 
15  protected bool m_IsExpanded;
16  ref ScriptInvoker m_OnSelectItem = new ScriptInvoker();
17 
18  void DropdownPrefab( Widget root, string text = "" )
19  {
20  m_Parent = root;
21  m_Root = GetGame().GetWorkspace().CreateWidgets( "gui/layouts/new_ui/dropdown_prefab/dropdown_prefab.layout", root );
22 
23  m_Scroller = ScrollWidget.Cast( m_Root.FindAnyWidget( "dropdown_container" ) );
24  m_ContentContainer = m_Root.FindAnyWidget( "dropdown_content" );
25  m_Text = TextWidget.Cast( m_Root.FindAnyWidget( "dropdown_text" ) );
26  m_Holder = m_Root.FindAnyWidget( "holder" );
27  SetText( text );
28 
29  m_Button = m_Root.FindAnyWidget( "dropdown_selector_button" );
30  m_ImageExpand = ImageWidget.Cast( m_Root.FindAnyWidget( "expand_image" ) );
31  m_ImageCollapse = ImageWidget.Cast( m_Root.FindAnyWidget( "collapse_image" ) );
32 
33  m_Root.SetHandler( this );
34 
35  RefreshContent();
36  }
37 
38  void RefreshContent()
39  {
40  Widget child = m_ContentContainer.GetChildren();
41  while( child )
42  {
43  if( m_Content.Find( child ) > -1 )
44  {
45  m_Content.Insert( child );
46  }
47  }
48 
49  m_ContentContainer.Update();
50  m_Root.Update();
51 
52  float x, y;
53  m_ContentContainer.GetScreenSize( x, y );
54  if( y > m_Scroller.GetContentHeight() )
55  {
56  m_Scroller.SetAlpha( 1 );
57  }
58  else
59  {
60  m_Scroller.SetAlpha( 0 );
61  }
62  }
63 
64  int AddElement( string text, Widget content = null )
65  {
66  ButtonWidget element = ButtonWidget.Cast( GetGame().GetWorkspace().CreateWidgets( "gui/layouts/new_ui/dropdown_prefab/dropdown_element.layout", m_ContentContainer ) );
67  RichTextWidget textWidget = RichTextWidget.Cast(element.FindAnyWidget("dropdown_element_text"));
68  textWidget.SetText( text );
69 
70  if( content )
71  {
72  element.AddChild( content, false );
73  }
74  m_ContentContainer.Update();
75  textWidget.Update();
76  m_Root.Update();
77  element.Update();
78 
79  m_Content.Insert( element );
80  return m_Content.Count() - 1;
81  }
82 
83  void RemoveElement( int index )
84  {
85  if( 0 < index && index < m_Content.Count() )
86  {
87  delete m_Content.Get( index );
88  m_ContentContainer.Update();
89  m_Root.Update();
90  m_Parent.Update();
91  }
92  }
93 
94  void Close()
95  {
96  if( m_IsExpanded )
97  {
99  m_Scroller.Show( m_IsExpanded );
100  m_ImageExpand.Show( !m_IsExpanded );
101  m_ImageCollapse.Show( m_IsExpanded );
102 
103  m_Root.Update();
104  m_Parent.Update();
105  }
106  }
107 
108  void SetText( string text )
109  {
110  m_Text.SetText( text );
111  }
112 
113  override bool OnClick( Widget w, int x, int y, int button )
114  {
115  int index = m_Content.Find( w );
116  if ( index > -1 )
117  {
118  m_OnSelectItem.Invoke( index );
119  m_IsExpanded = false;
120  m_Scroller.Show( m_IsExpanded );
121  m_ImageExpand.Show( !m_IsExpanded );
122  m_ImageCollapse.Show( m_IsExpanded );
123  return true;
124  }
125  return false;
126  }
127 
128  override bool OnMouseButtonDown( Widget w, int x, int y, int button )
129  {
130  if ( (w == m_Button || w == m_Text || w == m_Holder) && button == MouseState.LEFT )
131  {
133  m_Scroller.Show( m_IsExpanded );
134  m_ImageExpand.Show( !m_IsExpanded );
135  m_ImageCollapse.Show( m_IsExpanded );
136 
137  m_Root.Update();
138  m_Parent.Update();
139  m_ContentContainer.Update();
140 
141  return true;
142  }
143  return false;
144  }
145 }
GetGame
proto native CGame GetGame()
Close
void Close()
y
Icon y
m_Parent
protected Widget m_Parent
Definition: sizetochild.c:92
RichTextWidget
Definition: gameplay.c:315
TextWidget
Definition: enwidgets.c:219
m_IsExpanded
bool m_IsExpanded
Definition: bioslobbyservice.c:60
MouseState
MouseState
Definition: ensystem.c:310
array< Widget >
x
Icon x
OnMouseButtonDown
bool OnMouseButtonDown(Widget w, int x, int y, int button)
Definition: pluginitemdiagnostic.c:117
m_Text
protected string m_Text
Definition: actionbase.c:49
Widget
Definition: enwidgets.c:189
OnClick
override bool OnClick(Widget w, int x, int y, int button)
buttons clicks
Definition: dayzgame.c:146
m_Root
protected Widget m_Root
Definition: sizetochild.c:91
ScriptedWidgetEventHandler
map: item x vector(index, width, height)
Definition: enwidgets.c:650
ScriptInvoker
ScriptInvoker Class provide list of callbacks usage:
Definition: tools.c:115