uipopupscriptconfigs.c 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. class UIPopupScriptConfigs extends UIPopupScript
  2. {
  3. private ButtonWidget m_BtnOk;
  4. private ButtonWidget m_BtnCancel;
  5. private ButtonWidget m_BtnCopyToClipboard;
  6. private TextListboxWidget m_ConfigHierarchyTextListbox;
  7. private TextListboxWidget m_ConfigVariablesTextListbox;
  8. private PluginConfigViewer m_ModuleConfigViewer;
  9. private EditBoxWidget m_ObjectConfigFilter;
  10. void UIPopupScriptConfigs( Widget wgt )
  11. {
  12. m_BtnOk = ButtonWidget.Cast( wgt.FindAnyWidget("btn_ppp_pc_ok") );
  13. m_ConfigHierarchyTextListbox = TextListboxWidget.Cast( wgt.FindAnyWidget("ConfigHierarchy") );
  14. m_ConfigVariablesTextListbox = TextListboxWidget.Cast( wgt.FindAnyWidget("ConfigVariables") );
  15. m_BtnCopyToClipboard = ButtonWidget.Cast( wgt.FindAnyWidget("btn_ppp_pc_copy") );
  16. m_ObjectConfigFilter = EditBoxWidget.Cast( wgt.FindAnyWidget("ObjectConfigFilter") );
  17. }
  18. void ChangeConfigFilter()
  19. {
  20. if ( m_ObjectConfigFilter.GetText() == "" )
  21. {
  22. ClearHierarchy();
  23. }
  24. else
  25. {
  26. FindInHierarchy( m_ObjectConfigFilter.GetText() );
  27. }
  28. }
  29. override void OnOpen(Param param)
  30. {
  31. m_ModuleConfigViewer = PluginConfigViewer.Cast( GetPlugin( PluginConfigViewer ) );
  32. ClearHierarchy();
  33. }
  34. void AddItemToClipboard( TextListboxWidget text_listbox_widget )
  35. {
  36. int selected_row_index = text_listbox_widget.GetSelectedRow();
  37. if ( selected_row_index != -1 )
  38. {
  39. string item_name;
  40. text_listbox_widget.GetItemText( selected_row_index, 0, item_name );
  41. GetGame().CopyToClipboard( item_name );
  42. }
  43. }
  44. void RenderVariables( int row )
  45. {
  46. ConfigParams config_params;
  47. if( row > -1 && row < m_ConfigHierarchyTextListbox.GetNumItems() )
  48. {
  49. m_ConfigHierarchyTextListbox.GetItemData( row, 0, config_params );
  50. m_ConfigVariablesTextListbox.ClearItems();
  51. ref TStringArray variables;
  52. string path = config_params.param4;
  53. variables = m_ModuleConfigViewer.GetConfigVariables( path );
  54. for ( int i = 0; i < variables.Count(); i++ )
  55. {
  56. m_ConfigVariablesTextListbox.AddItem( variables.Get(i), NULL, 0);
  57. }
  58. }
  59. }
  60. void ExpandHierarchy( int row )
  61. {
  62. if( row <= -1 && row >= m_ConfigHierarchyTextListbox.GetNumItems() )
  63. {
  64. return;
  65. }
  66. ref TStringArray variables;
  67. // get current row data
  68. ConfigParams config_params;
  69. m_ConfigHierarchyTextListbox.GetItemData( row, 0, config_params );
  70. string config_path = config_params.param4;
  71. int deep = config_params.param5;
  72. string offset = "";
  73. for ( int i = 0; i < deep; i++)
  74. {
  75. offset = offset + " ";
  76. }
  77. // change selected node
  78. variables = m_ModuleConfigViewer.GetConfigHierarchy( config_path );
  79. int childrens_count = variables.Count();
  80. m_ConfigHierarchyTextListbox.SetItem( row, offset + "- " + config_params.param2, new ConfigParams( true, config_params.param2, childrens_count, config_path, deep ), 0 );
  81. offset = offset + " ";
  82. // render childrens
  83. deep = deep + 1;
  84. childrens_count = 0;
  85. for ( i = variables.Count() - 1; i >= 0; i-- )
  86. {
  87. string new_config_path = ( config_path + " " + variables.Get(i) ).Trim();
  88. m_ConfigHierarchyTextListbox.AddItem( offset + "+ " + variables.Get(i), new ConfigParams( false, variables.Get(i), childrens_count, new_config_path, deep ), 0, (row + 1) );
  89. }
  90. }
  91. // 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
  92. void CollapseHierarchy( int row )
  93. {
  94. if( row <= -1 && row >= m_ConfigHierarchyTextListbox.GetNumItems() )
  95. {
  96. return;
  97. }
  98. ConfigParams config_params;
  99. ConfigParams config_params_next;
  100. m_ConfigHierarchyTextListbox.GetItemData( row, 0, config_params );
  101. m_ConfigHierarchyTextListbox.GetItemData( row + 1, 0, config_params_next );
  102. int deep = config_params.param5;
  103. int deep_next = config_params_next.param5;
  104. int max_count = m_ConfigHierarchyTextListbox.GetNumItems();
  105. int remove_lines_count = 0;
  106. // Print(max_count);
  107. for ( int i = row + 1; i < max_count; i++)
  108. {
  109. if ( deep < deep_next && i <= max_count )
  110. {
  111. remove_lines_count = remove_lines_count + 1;
  112. m_ConfigHierarchyTextListbox.GetItemData( i, 0, config_params_next );
  113. deep_next = config_params_next.param5;
  114. }
  115. }
  116. // remove remove_lines_count lines from row
  117. // remove_lines_count = remove_lines_count - 1;
  118. for ( i = 1; i < remove_lines_count; i++ )
  119. {
  120. int x = row + 1;
  121. if ( x < max_count )
  122. {
  123. m_ConfigHierarchyTextListbox.RemoveRow( x );
  124. }
  125. }
  126. string offset = "";
  127. for ( i = 0; i < deep; i++)
  128. {
  129. offset = offset + " ";
  130. }
  131. m_ConfigHierarchyTextListbox.SetItem( row, offset + "+ " + config_params.param2, new ConfigParams( false, config_params.param2, 0, config_params.param4, deep ), 0 );
  132. }
  133. void ClearHierarchy()
  134. {
  135. // config hierarchy
  136. // string config_path = "configfile CfgVehicles APC";
  137. // string config_path = "";
  138. m_ConfigHierarchyTextListbox.ClearItems();
  139. m_ConfigVariablesTextListbox.ClearItems();
  140. ref TStringArray base_classes = new TStringArray;
  141. Debug.GetBaseConfigClasses( base_classes );
  142. string config_path = "configfile";
  143. ref TStringArray variables = m_ModuleConfigViewer.GetConfigHierarchy( config_path );
  144. for ( int i = 0; i < variables.Count(); i++ )
  145. {
  146. string variable = variables.Get(i);
  147. for ( int j = 0; j < base_classes.Count(); j++ )
  148. {
  149. if ( variable == base_classes.Get(j) )
  150. {
  151. string new_config_path = ( config_path + " " + variable ).Trim();
  152. m_ConfigHierarchyTextListbox.AddItem( "+ " + variable, new ConfigParams( false, variable, 0, new_config_path, 0 ), 0);
  153. }
  154. }
  155. }
  156. }
  157. void FindInHierarchy( string class_name )
  158. {
  159. m_ConfigHierarchyTextListbox.ClearItems();
  160. m_ConfigVariablesTextListbox.ClearItems();
  161. class_name.ToLower( );
  162. string config_base_path = "configfile";
  163. ref TStringArray base_classes = new TStringArray;
  164. Debug.GetBaseConfigClasses( base_classes );
  165. string filter_lower = class_name;
  166. filter_lower.ToLower( );
  167. ref TStringArray filters = new TStringArray;
  168. filter_lower.Split( " ", filters );
  169. for ( int i = 0; i < base_classes.Count(); i++ )
  170. {
  171. string config_path = config_base_path + " " + base_classes.Get(i);
  172. ref TStringArray variables = m_ModuleConfigViewer.GetConfigHierarchy( config_path );
  173. for ( int j = 0; j < variables.Count(); j++ )
  174. {
  175. string variable = variables.Get(j);
  176. string variable_lower = variable;
  177. variable_lower.ToLower( );
  178. for ( int k = 0; k < filters.Count(); k++ )
  179. {
  180. if ( variable_lower.Contains(filters.Get(k)))
  181. {
  182. string new_config_path = ( config_path + " " + variable ).Trim();
  183. m_ConfigHierarchyTextListbox.AddItem( "+ " + variable, new ConfigParams( false, variable, 0, new_config_path, 0 ), 0);
  184. break;
  185. }
  186. }
  187. }
  188. }
  189. }
  190. override bool OnChange( Widget w, int x, int y, bool finished )
  191. {
  192. super.OnChange( w, x, y, finished );
  193. if ( w == m_ObjectConfigFilter )
  194. {
  195. ChangeConfigFilter();
  196. }
  197. return false;
  198. }
  199. override bool OnClick( Widget w, int x, int y, int button )
  200. {
  201. super.OnClick( w, x, y, button );
  202. if ( w == m_BtnOk )
  203. {
  204. PopupBack();
  205. return true;
  206. }
  207. else if ( w == m_BtnCancel )
  208. {
  209. PopupBack();
  210. return true;
  211. }
  212. else if ( w == m_BtnCopyToClipboard )
  213. {
  214. AddItemToClipboard( m_ConfigVariablesTextListbox );
  215. return true;
  216. }
  217. else if ( w == m_ConfigHierarchyTextListbox )
  218. {
  219. int objects_row_index = m_ConfigHierarchyTextListbox.GetSelectedRow();
  220. if ( objects_row_index > -1 && objects_row_index < m_ConfigHierarchyTextListbox.GetNumItems() )
  221. {
  222. ConfigParams config_params;
  223. m_ConfigHierarchyTextListbox.GetItemData( objects_row_index, 0, config_params );
  224. if ( config_params.param1 == false )
  225. {
  226. ExpandHierarchy( objects_row_index );
  227. }
  228. else
  229. {
  230. CollapseHierarchy( objects_row_index );
  231. }
  232. RenderVariables( objects_row_index );
  233. }
  234. return true;
  235. }
  236. return false;
  237. }
  238. }