Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
uipopupscriptconfigs.c
Go to the documentation of this file.
1 class UIPopupScriptConfigs extends UIPopupScript
2 {
3  private ButtonWidget m_BtnOk;
4  private ButtonWidget m_BtnCancel;
5  private ButtonWidget m_BtnCopyToClipboard;
6 
7  private TextListboxWidget m_ConfigHierarchyTextListbox;
8  private TextListboxWidget m_ConfigVariablesTextListbox;
9 
10  private PluginConfigViewer m_ModuleConfigViewer;
11 
12  private EditBoxWidget m_ObjectConfigFilter;
13 
14  void UIPopupScriptConfigs( Widget wgt )
15  {
16  m_BtnOk = ButtonWidget.Cast( wgt.FindAnyWidget("btn_ppp_pc_ok") );
17  m_ConfigHierarchyTextListbox = TextListboxWidget.Cast( wgt.FindAnyWidget("ConfigHierarchy") );
18  m_ConfigVariablesTextListbox = TextListboxWidget.Cast( wgt.FindAnyWidget("ConfigVariables") );
19  m_BtnCopyToClipboard = ButtonWidget.Cast( wgt.FindAnyWidget("btn_ppp_pc_copy") );
20  m_ObjectConfigFilter = EditBoxWidget.Cast( wgt.FindAnyWidget("ObjectConfigFilter") );
21  }
22 
23  void ChangeConfigFilter()
24  {
25  if ( m_ObjectConfigFilter.GetText() == "" )
26  {
27  ClearHierarchy();
28  }
29  else
30  {
31  FindInHierarchy( m_ObjectConfigFilter.GetText() );
32  }
33  }
34 
35  override void OnOpen(Param param)
36  {
37  m_ModuleConfigViewer = PluginConfigViewer.Cast( GetPlugin( PluginConfigViewer ) );
38  ClearHierarchy();
39  }
40 
41  void AddItemToClipboard( TextListboxWidget text_listbox_widget )
42  {
43  int selected_row_index = text_listbox_widget.GetSelectedRow();
44  if ( selected_row_index != -1 )
45  {
46  string item_name;
47  text_listbox_widget.GetItemText( selected_row_index, 0, item_name );
48  GetGame().CopyToClipboard( item_name );
49  }
50  }
51 
52  void RenderVariables( int row )
53  {
54  ConfigParams config_params;
55  if( row > -1 && row < m_ConfigHierarchyTextListbox.GetNumItems() )
56  {
57  m_ConfigHierarchyTextListbox.GetItemData( row, 0, config_params );
58  m_ConfigVariablesTextListbox.ClearItems();
59  ref TStringArray variables;
60  string path = config_params.param4;
61  variables = m_ModuleConfigViewer.GetConfigVariables( path );
62  for ( int i = 0; i < variables.Count(); i++ )
63  {
64  m_ConfigVariablesTextListbox.AddItem( variables.Get(i), NULL, 0);
65  }
66  }
67  }
68 
69  void ExpandHierarchy( int row )
70  {
71  if( row <= -1 && row >= m_ConfigHierarchyTextListbox.GetNumItems() )
72  {
73  return;
74  }
75 
76  ref TStringArray variables;
77 
78  // get current row data
79  ConfigParams config_params;
80  m_ConfigHierarchyTextListbox.GetItemData( row, 0, config_params );
81 
82  string config_path = config_params.param4;
83  int deep = config_params.param5;
84 
85  string offset = "";
86  for ( int i = 0; i < deep; i++)
87  {
88  offset = offset + " ";
89  }
90 
91  // change selected node
92  variables = m_ModuleConfigViewer.GetConfigHierarchy( config_path );
93  int childrens_count = variables.Count();
94  m_ConfigHierarchyTextListbox.SetItem( row, offset + "- " + config_params.param2, new ConfigParams( true, config_params.param2, childrens_count, config_path, deep ), 0 );
95 
96  offset = offset + " ";
97 
98  // render childrens
99  deep = deep + 1;
100  childrens_count = 0;
101  for ( i = variables.Count() - 1; i >= 0; i-- )
102  {
103  string new_config_path = ( config_path + " " + variables.Get(i) ).Trim();
104  m_ConfigHierarchyTextListbox.AddItem( offset + "+ " + variables.Get(i), new ConfigParams( false, variables.Get(i), childrens_count, new_config_path, deep ), 0, (row + 1) );
105  }
106  }
107 
108  // niekde je bug, ked su len 2 polozky a expand/collapse na prvu tak zmaze aj druhu. ak collapse a expand na druhu tak crash lebo sa snazi zmazat riadok co neexistuje
109  void CollapseHierarchy( int row )
110  {
111  if( row <= -1 && row >= m_ConfigHierarchyTextListbox.GetNumItems() )
112  {
113  return;
114  }
115 
116  ConfigParams config_params;
117  ConfigParams config_params_next;
118  m_ConfigHierarchyTextListbox.GetItemData( row, 0, config_params );
119  m_ConfigHierarchyTextListbox.GetItemData( row + 1, 0, config_params_next );
120 
121  int deep = config_params.param5;
122  int deep_next = config_params_next.param5;
123  int max_count = m_ConfigHierarchyTextListbox.GetNumItems();
124  int remove_lines_count = 0;
125  // Print(max_count);
126  for ( int i = row + 1; i < max_count; i++)
127  {
128  if ( deep < deep_next && i <= max_count )
129  {
130  remove_lines_count = remove_lines_count + 1;
131  m_ConfigHierarchyTextListbox.GetItemData( i, 0, config_params_next );
132  deep_next = config_params_next.param5;
133  }
134  }
135 
136  // remove remove_lines_count lines from row
137  // remove_lines_count = remove_lines_count - 1;
138  for ( i = 1; i < remove_lines_count; i++ )
139  {
140  int x = row + 1;
141  if ( x < max_count )
142  {
143  m_ConfigHierarchyTextListbox.RemoveRow( x );
144  }
145  }
146 
147  string offset = "";
148  for ( i = 0; i < deep; i++)
149  {
150  offset = offset + " ";
151  }
152  m_ConfigHierarchyTextListbox.SetItem( row, offset + "+ " + config_params.param2, new ConfigParams( false, config_params.param2, 0, config_params.param4, deep ), 0 );
153  }
154 
155  void ClearHierarchy()
156  {
157  // config hierarchy
158  // string config_path = "configfile CfgVehicles APC";
159  // string config_path = "";
160 
161  m_ConfigHierarchyTextListbox.ClearItems();
162  m_ConfigVariablesTextListbox.ClearItems();
163 
164  ref TStringArray base_classes = new TStringArray;
165  Debug.GetBaseConfigClasses( base_classes );
166 
167  string config_path = "configfile";
168  ref TStringArray variables = m_ModuleConfigViewer.GetConfigHierarchy( config_path );
169  for ( int i = 0; i < variables.Count(); i++ )
170  {
171  string variable = variables.Get(i);
172 
173  for ( int j = 0; j < base_classes.Count(); j++ )
174  {
175  if ( variable == base_classes.Get(j) )
176  {
177  string new_config_path = ( config_path + " " + variable ).Trim();
178  m_ConfigHierarchyTextListbox.AddItem( "+ " + variable, new ConfigParams( false, variable, 0, new_config_path, 0 ), 0);
179  }
180  }
181  }
182  }
183 
184  void FindInHierarchy( string class_name )
185  {
186  m_ConfigHierarchyTextListbox.ClearItems();
187  m_ConfigVariablesTextListbox.ClearItems();
188 
189  class_name.ToLower( );
190  string config_base_path = "configfile";
191 
192  ref TStringArray base_classes = new TStringArray;
193  Debug.GetBaseConfigClasses( base_classes );
194 
195  string filter_lower = class_name;
196  filter_lower.ToLower( );
197 
198  ref TStringArray filters = new TStringArray;
199  filter_lower.Split( " ", filters );
200 
201  for ( int i = 0; i < base_classes.Count(); i++ )
202  {
203  string config_path = config_base_path + " " + base_classes.Get(i);
204  ref TStringArray variables = m_ModuleConfigViewer.GetConfigHierarchy( config_path );
205 
206  for ( int j = 0; j < variables.Count(); j++ )
207  {
208  string variable = variables.Get(j);
209  string variable_lower = variable;
210  variable_lower.ToLower( );
211 
212  for ( int k = 0; k < filters.Count(); k++ )
213  {
214  if ( variable_lower.Contains(filters.Get(k)))
215  {
216  string new_config_path = ( config_path + " " + variable ).Trim();
217  m_ConfigHierarchyTextListbox.AddItem( "+ " + variable, new ConfigParams( false, variable, 0, new_config_path, 0 ), 0);
218  break;
219  }
220  }
221  }
222  }
223  }
224 
225  override bool OnChange( Widget w, int x, int y, bool finished )
226  {
227  super.OnChange( w, x, y, finished );
228 
229  if ( w == m_ObjectConfigFilter )
230  {
231  ChangeConfigFilter();
232  }
233 
234  return false;
235  }
236 
237  override bool OnClick( Widget w, int x, int y, int button )
238  {
239  super.OnClick( w, x, y, button );
240 
241  if ( w == m_BtnOk )
242  {
243  PopupBack();
244  return true;
245  }
246  else if ( w == m_BtnCancel )
247  {
248  PopupBack();
249  return true;
250  }
251  else if ( w == m_BtnCopyToClipboard )
252  {
253  AddItemToClipboard( m_ConfigVariablesTextListbox );
254  return true;
255  }
256  else if ( w == m_ConfigHierarchyTextListbox )
257  {
258  int objects_row_index = m_ConfigHierarchyTextListbox.GetSelectedRow();
259 
260  if ( objects_row_index > -1 && objects_row_index < m_ConfigHierarchyTextListbox.GetNumItems() )
261  {
262  ConfigParams config_params;
263  m_ConfigHierarchyTextListbox.GetItemData( objects_row_index, 0, config_params );
264 
265  if ( config_params.param1 == false )
266  {
267  ExpandHierarchy( objects_row_index );
268  }
269  else
270  {
271  CollapseHierarchy( objects_row_index );
272  }
273  RenderVariables( objects_row_index );
274  }
275 
276  return true;
277  }
278 
279  return false;
280  }
281 }
GetGame
proto native CGame GetGame()
Param
Base Param Class with no parameters. Used as general purpose parameter overloaded with Param1 to Para...
Definition: param.c:11
TStringArray
array< string > TStringArray
Definition: enscript.c:685
EditBoxWidget
Definition: enwidgets.c:353
y
Icon y
GetPlugin
PluginBase GetPlugin(typename plugin_type)
Definition: pluginmanager.c:316
class_name
class OptionSelectorMultistate extends OptionSelector class_name
UIPopupScript
Definition: uipopupscriptconfigs.c:1
ConfigParams
Param5< bool, string, int, string, int > ConfigParams
Definition: scriptconsoleconfigtab.c:1
array< string >
x
Icon x
Debug
Definition: debug.c:13
OnChange
bool OnChange(Widget w, int x, int y, bool finished)
Definition: huddebug.c:336
Widget
Definition: enwidgets.c:189
OnClick
override bool OnClick(Widget w, int x, int y, int button)
buttons clicks
Definition: dayzgame.c:146
path
string path
Definition: optionselectormultistate.c:135