scriptconsoleconfigtab.c 14 KB

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