scriptconsoleoutputtab.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. class ScriptConsoleOutputTab : ScriptConsoleTabBase
  2. {
  3. protected TextListboxWidget m_ClientLogListbox;
  4. protected ButtonWidget m_ClientLogClearButton;
  5. protected CheckBoxWidget m_ClientLogScrollCheckbox;
  6. void ScriptConsoleOutputTab(Widget root, ScriptConsole console, Widget button, ScriptConsoleTabBase parent = null)
  7. {
  8. m_ClientLogListbox = TextListboxWidget.Cast(root.FindAnyWidget("TextListbox"));
  9. m_ClientLogClearButton = ButtonWidget.Cast(root.FindAnyWidget("ButtonClear"));
  10. m_ClientLogScrollCheckbox = CheckBoxWidget.Cast(root.FindAnyWidget("CheckBoxAutoScroll"));
  11. ReloadOutput();
  12. }
  13. void ~ScriptConsoleOutputTab()
  14. {
  15. }
  16. override bool OnClick(Widget w, int x, int y, int button)
  17. {
  18. super.OnClick(w,x,y,button);
  19. if (w == m_ClientLogClearButton)
  20. {
  21. Clear(true);
  22. return true;
  23. }
  24. return false;
  25. }
  26. override bool OnChange(Widget w, int x, int y, bool finished)
  27. {
  28. super.OnChange(w, x, y, finished);
  29. return false;
  30. }
  31. protected void Clear(bool clearFile = false)
  32. {
  33. if(clearFile)
  34. Debug.ClearLogs();
  35. m_ClientLogListbox.ClearItems();
  36. }
  37. protected void Add(string message, bool isReload = false)
  38. {
  39. if (m_ClientLogListbox)
  40. {
  41. m_ClientLogListbox.AddItem(String(message), NULL, 0);
  42. if (m_ClientLogScrollCheckbox.IsChecked())
  43. {
  44. m_ClientLogListbox.EnsureVisible(m_ClientLogListbox.GetNumItems());
  45. }
  46. }
  47. }
  48. protected void ReloadOutput()
  49. {
  50. Clear();
  51. FileHandle file_index = OpenFile(Debug.GetFileName(), FileMode.READ);
  52. if ( file_index )
  53. {
  54. string line_content;
  55. while ( FGets( file_index, line_content ) != -1 )
  56. {
  57. Add(line_content, true);
  58. }
  59. CloseFile(file_index);
  60. }
  61. }
  62. }