Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
scriptconsoleconfigtab.c
Go to the documentation of this file.
1 typedef Param5<bool, string, int, string, int> ConfigParams; // param1 - isCollapsed, param2 - string name, param3 - num of childs, param4 - path, param5 - deep
2 typedef Param6<bool, string, int, string, int, string> ConfigParamsEx; // param1 - isCollapsed, param2 - string name, param3 - num of childs, param4 - path, param5 - deep
3 
5 {
6 
7  protected static string m_ConfigTextField;
8  protected static string m_VariableTextField;
9  protected static ref ConfigParamsEx m_ConfigData;
10  protected ref TStringArray m_BaseConfigClasses = new TStringArray;
11  protected ref TStringArray m_BaseConfigClassesToggled = new TStringArray;
12  protected ref map<CheckBoxWidget, int> m_ClassCheckboxes = new map<CheckBoxWidget, int>;
13 
14  protected EditBoxWidget m_ObjectConfigFilter;
15  protected EditBoxWidget m_VariableConfigFilter;
16  protected TextListboxWidget m_ConfigHierarchyTextListbox;
17  protected TextListboxWidget m_ConfigVariablesTextListbox;
18  protected ButtonWidget m_SelectedRowCopy;
19  protected ButtonWidget m_DumpParamButton;
20  protected TextWidget m_ClassPath;
21 
22 
23  protected Widget m_WgtClassesConfig;
24  protected PluginConfigViewer m_ModuleConfigViewer;
25  protected int m_Row;
26 
27  void ScriptConsoleConfigTab(Widget root, ScriptConsole console, Widget button, ScriptConsoleTabBase parent = null)
28  {
29  m_WgtClassesConfig = root.FindAnyWidget("ClassesPanel");
30  m_DumpParamButton = ButtonWidget.Cast(root.FindAnyWidget("DumpParamButton"));
31  m_ObjectConfigFilter = EditBoxWidget.Cast(root.FindAnyWidget("ObjectConfigFilter"));
32  m_VariableConfigFilter = EditBoxWidget.Cast(root.FindAnyWidget("VariableConfigFilter"));
33  m_ConfigHierarchyTextListbox = TextListboxWidget.Cast(root.FindAnyWidget("ConfigHierarchy"));
34  m_ConfigVariablesTextListbox = TextListboxWidget.Cast(root.FindAnyWidget("ConfigVariables"));
35  m_SelectedRowCopy = ButtonWidget.Cast(root.FindAnyWidget("SelectedRowCopy"));
36  m_ClassPath = TextWidget.Cast(root.FindAnyWidget("ClassPath"));
37 
38  if (m_ConfigTextField)
39  m_ObjectConfigFilter.SetText(m_ConfigTextField);
40  if (m_VariableTextField)
41  m_VariableConfigFilter.SetText(m_VariableTextField);
42  Init();
43  }
44 
46  {
47  m_VariableTextField = m_VariableConfigFilter.GetText();
48 
49  foreach (int i:m_ClassCheckboxes)
50  {
51  Widget w = m_ClassCheckboxes.GetKeyByValue(i);
52  w.GetParent().Unlink();
53  }
54  }
55 
56  override bool OnChange(Widget w, int x, int y, bool finished)
57  {
58  super.OnChange(w, x, y, finished);
59  if (w == m_ObjectConfigFilter)
60  {
61  ChangeConfigFilter();
62  return true;
63  }
64  else if (w == m_VariableConfigFilter)
65  {
66  RenderVariables(m_Row);
67  return true;
68  }
69 
70  return false;
71  }
72 
73  override bool OnItemSelected(Widget w, int x, int y, int row, int column, int oldRow, int oldColumn)
74  {
75  super.OnItemSelected(w, x, y, row, column, oldRow, oldColumn);
76 
77  if (w == m_ConfigHierarchyTextListbox)
78  {
79  TextListboxWidget wgt = TextListboxWidget.Cast(w);
80  wgt.GetItemData(row, 0,m_ConfigData);
81  RenderClassPath();
82 
83  return true;
84  }
85  return false;
86  }
87 
88  void RenderClassPath()
89  {
90  m_ClassPath.SetText(m_ModuleConfigViewer.GetBaseClasses(m_ConfigData.param4, m_ConfigData.param2));
91  }
92 
93 
94  override bool OnClick(Widget w, int x, int y, int button)
95  {
96  super.OnClick(w,x,y,button);
97 
98  CheckBoxWidget cbw = CheckBoxWidget.Cast(w);
99 
100  if (w == m_DumpParamButton)
101  {
102  int selectedRowIndex = m_ConfigVariablesTextListbox.GetSelectedRow();
103  string paramFinal;
104  if (selectedRowIndex > -1)
105  {
106  string param;
107  m_ConfigVariablesTextListbox.GetItemText(selectedRowIndex,0,param);
108  int index = param.IndexOf("=");
109  if (index > 0)
110  paramFinal = param.Substring(0, index).Trim();
111  }
112 
113  int objects_row_index;
114  objects_row_index = m_ConfigHierarchyTextListbox.GetSelectedRow();
115  if (objects_row_index > -1 && objects_row_index < m_ConfigHierarchyTextListbox.GetNumItems())
116  {
117  ConfigParamsEx params;
118  m_ConfigHierarchyTextListbox.GetItemData(objects_row_index, 0, params);
119  string path = params.param4;
120  TStringArray pathArr = new TStringArray();
121  path.Split(" ", pathArr);
122  string relativePath;
123 
124  foreach (int indx, string s:pathArr)
125  {
126  if (indx > 2)
127  {
128  relativePath+= s+" ";
129  }
130  }
131 
132  if (relativePath)
133  relativePath = relativePath.Trim();
134 
135  Print(relativePath);
136  Print(path);
137  }
138 
139  if (paramFinal)
140  DumpParam(paramFinal,relativePath);
141 
142  return true;
143  }
144  else if (w == m_ConfigHierarchyTextListbox)
145  {
146  objects_row_index = m_ConfigHierarchyTextListbox.GetSelectedRow();
147  //Print(objects_row_index);
148 
149  if (objects_row_index > -1 && objects_row_index < m_ConfigHierarchyTextListbox.GetNumItems())
150  {
151  ConfigParamsEx config_params;
152  m_ConfigHierarchyTextListbox.GetItemData(objects_row_index, 0, config_params);
153 
154  if (config_params.param1 == false)
155  {
156  ExpandHierarchy(objects_row_index);
157  }
158  else
159  {
160  CollapseHierarchy(objects_row_index);
161  }
162 
163  RenderVariables(objects_row_index);
164  m_Row = objects_row_index;
165  }
166  return true;
167  }
168  else if (cbw && m_ClassCheckboxes.Contains(cbw))
169  {
170  int checkbox_index = m_ClassCheckboxes.Get(cbw);
171  string base_class_name = m_BaseConfigClasses.Get(checkbox_index);
172 
173  int index_toggled = m_BaseConfigClassesToggled.Find(base_class_name);
174 
175  int flag, new_flag;
176 
178  {
179  flag = m_ConfigDebugProfile.GetConfigClassesFlag();
180  }
181 
182  if (cbw.IsChecked())
183  {
184  if (index_toggled == -1)//not found
185  {
186  m_BaseConfigClassesToggled.Insert(base_class_name);
187 
189  {
190  new_flag = (flag | (int)Math.Pow(2, checkbox_index));
191  }
192  }
193  }
194  else if (index_toggled != -1)
195  {
196  m_BaseConfigClassesToggled.Remove(index_toggled);
197 
199  {
200  new_flag = (flag ^ (int)Math.Pow(2, checkbox_index));
201  }
202  }
203  m_ConfigDebugProfile.SetConfigClassesFlag(new_flag);
204  /*
205  Print("-----------------------------------------");
206  Print("flag = " + new_flag);
207  foreach (string text:m_BaseConfigClassesToggled)
208  {
209  Print(text);
210  }
211  Print("-----------------------------------------");
212  */
213  ClearHierarchy();
214  }
215  else if (w == m_SelectedRowCopy)
216  {
217  AddItemToClipboard(m_ConfigVariablesTextListbox);
218  return true;
219  }
220  return false;
221  }
222 
223  override void Update(float timeslice)
224  {
225  super.Update(timeslice);
226 
227  }
228 
229  protected void Init()
230  {
231  Debug.GetBaseConfigClasses(m_BaseConfigClasses);
232  m_ModuleConfigViewer = PluginConfigViewer.Cast(GetPlugin(PluginConfigViewer));
233  int flag1;
234 
236  {
237  flag1 = m_ConfigDebugProfile.GetConfigClassesFlag();
238  }
239  //Print("------------------------------------------------");
240  foreach (string s:m_BaseConfigClasses)
241  {
242  Widget w = GetGame().GetWorkspace().CreateWidgets("gui/layouts/script_console/config_class_item.layout", m_WgtClassesConfig);
243  CheckBoxWidget cbw = CheckBoxWidget.Cast(w.FindAnyWidget("Item"));
244  //cbw.SetColor(Colors.RED);
245  cbw.SetText(s);
246  int indx = m_ClassCheckboxes.Count();
247  m_ClassCheckboxes.Insert(cbw,indx);
248  //Print("adding "+cbw +" at index:" + indx);
249 
250  if (flag1 & (int)Math.Pow(2, indx))
251  {
252  string base_class_name = m_BaseConfigClasses.Get(indx);
253  m_BaseConfigClassesToggled.Insert(base_class_name);
254  cbw.SetChecked(true);
255  }
256  }
257 
258  ClearHierarchy();
259  ChangeConfigFilter();
260  }
261 
262  protected void DumpParam(string param, string relativePath)
263  {
264  if (relativePath)
265  {
266  relativePath = " " + relativePath;
267  }
268  for ( int i = 0; i < m_BaseConfigClassesToggled.Count(); i++ )
269  {
270  string config_path = m_BaseConfigClassesToggled.Get(i);
271 
272  int objects_count = GetGame().ConfigGetChildrenCount( config_path );
273 
274  for ( int j = 0; j < objects_count; j++ )
275  {
276  string child_name;
277  GetGame().ConfigGetChildName( config_path, j, child_name );
278 
279 
280  //string dispName;
281  //GetGame().ConfigGetText( config_path + " " + child_name + " displayName",dispName );
282  string value;
283  string path = config_path + " " + child_name + relativePath + " " + param;
284  if (GetGame().ConfigIsExisting(path))
285  {
286  GetGame().ConfigGetText( path , value);
287  if (value)
288  Print(child_name + "," + param + "," + value);
289  }
290 
291 
292  /*
293  int scope = GetGame().ConfigGetInt( config_path + " " + child_name + " scope" );
294  {
295  if ( scope == 2)
296  {
297 
298  }
299  }*/
300  }
301  }
302  }
303 
304  protected void ChangeConfigFilter()
305  {
306  m_ConfigTextField = m_ObjectConfigFilter.GetText();
307 
308  if (m_ConfigTextField == "")
309  {
310  ClearHierarchy();
311  }
312  else
313  {
314  FindInHierarchy(m_ConfigTextField);
315  }
316  }
317 
318  protected void ClearHierarchy()
319  {
320  m_ConfigHierarchyTextListbox.ClearItems();
321  m_ConfigVariablesTextListbox.ClearItems();
322 
323  string config_path = "configfile";
324  TStringArray variables = m_ModuleConfigViewer.GetConfigHierarchy(config_path);
325  for (int i = 0; i < variables.Count(); i++)
326  {
327  string variable = variables.Get(i);
328 
329  for (int j = 0; j < m_BaseConfigClassesToggled.Count(); j++)
330  {
331  if (variable == m_BaseConfigClassesToggled.Get(j))
332  {
333  string new_config_path = (config_path + " " + variable).Trim();
334  m_ConfigHierarchyTextListbox.AddItem("+ " + variable, new ConfigParamsEx(false, variable, 0, new_config_path, 0,variable), 0);
335  }
336  }
337  }
338  }
339 
340  protected void FindInHierarchy(string class_name)
341  {
342  m_ConfigHierarchyTextListbox.ClearItems();
343  m_ConfigVariablesTextListbox.ClearItems();
344 
345  class_name.ToLower();
346  string config_base_path = "configfile";
347 
348  string filter_lower = class_name;
349  filter_lower.ToLower();
350 
351  TStringArray filters = new TStringArray;
352  filter_lower.Split(" ", filters);
353 
354  for (int i = 0; i < m_BaseConfigClassesToggled.Count(); i++)
355  {
356  string config_root = m_BaseConfigClassesToggled.Get(i);
357  string config_path = config_base_path + " " + config_root;
358  TStringArray variables = m_ModuleConfigViewer.GetConfigHierarchy(config_path);
359 
360  for (int j = 0; j < variables.Count(); j++)
361  {
362  string variable = variables.Get(j);
363  string variable_lower = variable;
364  variable_lower.ToLower();
365 
366  for (int k = 0; k < filters.Count(); k++)
367  {
368  if (variable_lower.Contains(filters.Get(k)))
369  {
370  string new_config_path = (config_path + " " + variable).Trim();
371  m_ConfigHierarchyTextListbox.AddItem("+ " + variable, new ConfigParamsEx(false, variable, 0, new_config_path, 0, config_root), 0);
372  break;
373  }
374  }
375  }
376  }
377  }
378 
379  protected void ExpandHierarchy(int row)
380  {
381  if (row <= -1 && row >= m_ConfigHierarchyTextListbox.GetNumItems())
382  {
383  return;
384  }
385 
386  TStringArray variables;
387 
388  // get current row data
389  ConfigParamsEx config_params;
390  m_ConfigHierarchyTextListbox.GetItemData(row, 0, config_params);
391 
392  string config_path = config_params.param4;
393  int deep = config_params.param5;
394 
395 
396  string offset = "";
397  for (int i = 0; i < deep; i++)
398  {
399  offset = offset + " ";
400  }
401 
402  // change selected node
403  variables = m_ModuleConfigViewer.GetConfigHierarchy(config_path);
404  int childrens_count = variables.Count();
405  m_ConfigHierarchyTextListbox.SetItem(row, offset + "- " + config_params.param2, new ConfigParamsEx(true, config_params.param2, childrens_count, config_path, deep,config_params.param6), 0);
406 
407  offset = offset + " ";
408 
409  // render children
410  deep = deep + 1;
411  childrens_count = 0;
412  for (i = variables.Count() - 1; i >= 0; i--)
413  {
414  string new_config_path = (config_path + " " + variables.Get(i)).Trim();
415  m_ConfigHierarchyTextListbox.AddItem(offset + "+ " + variables.Get(i), new ConfigParamsEx(false, variables.Get(i), childrens_count, new_config_path, deep,config_params.param2), 0, (row + 1));
416  }
417  }
418 
419  // 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
420  protected void CollapseHierarchy(int row)
421  {
422  if (row <= -1 && row >= m_ConfigHierarchyTextListbox.GetNumItems())
423  {
424  return;
425  }
426 
427  ConfigParamsEx config_params;
428  ConfigParamsEx config_params_next;
429  m_ConfigHierarchyTextListbox.GetItemData(row, 0, config_params);
430  m_ConfigHierarchyTextListbox.GetItemData(row + 1, 0, config_params_next);
431 
432  if (!config_params || !config_params_next)
433  return;
434  int deep = config_params.param5;
435  int deep_next = config_params_next.param5;
436  int max_count = m_ConfigHierarchyTextListbox.GetNumItems();
437  int remove_lines_count = 0;
438  // Print(max_count);
439  for (int i = row + 1; i < max_count; i++)
440  {
441  if (deep < deep_next && i <= max_count)
442  {
443  remove_lines_count = remove_lines_count + 1;
444  m_ConfigHierarchyTextListbox.GetItemData(i, 0, config_params_next);
445  deep_next = config_params_next.param5;
446  }
447  }
448 
449  // remove remove_lines_count lines from row
450  // remove_lines_count = remove_lines_count - 1;
451  for (i = 1; i < remove_lines_count; i++)
452  {
453  int x = row + 1;
454  if (x < max_count)
455  {
456  m_ConfigHierarchyTextListbox.RemoveRow(x);
457  }
458  }
459 
460  string offset = "";
461  for (i = 0; i < deep; i++)
462  {
463  offset = offset + " ";
464  }
465  m_ConfigHierarchyTextListbox.SetItem(row, offset + "+ " + config_params.param2, new ConfigParamsEx(false, config_params.param2, 0, config_params.param4, deep,""), 0);
466  /* //not sure why this is here, but it's causing issues when collapsing items in config viewer, disabling for now
467  if (deep == 0)
468  {
469  ClearHierarchy();
470  }
471  */
472  }
473 
474  protected void RenderVariables(int row)
475  {
476  if (row > -1 && row < m_ConfigHierarchyTextListbox.GetNumItems())
477  {
478  string filter_lower = m_VariableConfigFilter.GetText();
479  filter_lower.ToLower();
480 
481  TStringArray filters = new TStringArray();
482  filter_lower.Split(" ", filters);
483 
484  ConfigParamsEx config_params;
485 
486  m_ConfigHierarchyTextListbox.GetItemData(row, 0, config_params);
487  m_ConfigVariablesTextListbox.ClearItems();
488  TStringArray variables;
489  string path = config_params.param4;
490  variables = m_ModuleConfigViewer.GetConfigVariables(path);
491 
492  for (int i = 0; i < variables.Count(); i++)
493  {
494  string var = variables.Get(i);
495 
496  if (filters.Count() == 0)
497  {
498  m_ConfigVariablesTextListbox.AddItem(var, NULL, 0);
499  }
500  else
501  {
502  foreach (string f: filters)
503  {
504  var.ToLower();
505  if (var.Contains(f))
506  m_ConfigVariablesTextListbox.AddItem(var, NULL, 0);
507  }
508  }
509  }
510  }
511  }
512 
513 }
GetGame
proto native CGame GetGame()
TStringArray
array< string > TStringArray
Definition: enscript.c:685
EditBoxWidget
Definition: enwidgets.c:353
y
Icon y
Print
proto void Print(void var)
Prints content of variable to console/log.
GetPlugin
PluginBase GetPlugin(typename plugin_type)
Definition: pluginmanager.c:316
ConfigParamsEx
Param6< bool, string, int, string, int, string > ConfigParamsEx
Definition: scriptconsoleconfigtab.c:2
map
map
Definition: controlsxboxnew.c:3
TextWidget
Definition: enwidgets.c:219
class_name
class OptionSelectorMultistate extends OptionSelector class_name
ConfigParams
Param5< bool, string, int, string, int > ConfigParams
Definition: scriptconsoleconfigtab.c:1
array< string >
x
Icon x
int
Param3 int
Debug
Definition: debug.c:13
m_ConfigDebugProfile
PluginConfigDebugProfile m_ConfigDebugProfile
Definition: pluginitemdiagnostic.c:58
Widget
Definition: enwidgets.c:189
ScriptConsoleTabBase
Definition: scriptconsoletabbase.c:1
Math
Definition: enmath.c:6
path
string path
Definition: optionselectormultistate.c:135
ScriptConsoleConfigTab
Definition: scriptconsoleconfigtab.c:4