EditorConsole.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. function EditorConsole::create(%this)
  23. {
  24. %this.guiPage = EditorCore.RegisterEditor("Console", %this);
  25. %this.consoleEntry = new GuiConsoleEditCtrl()
  26. {
  27. HorizSizing="width";
  28. VertSizing="top";
  29. Position="0 738";
  30. Extent="924 30";
  31. minExtent="120 20";
  32. AltCommand="EditorConsole.eval();";
  33. MaxLength="255";
  34. active = "1";
  35. HistorySize="40";
  36. password="0";
  37. TabComplete="0";
  38. SinkAllKeyEvents="1";
  39. UseSiblingScroller="1";
  40. };
  41. ThemeManager.setProfile(%this.consoleEntry, "textEditProfile");
  42. %this.guiPage.add(%this.consoleEntry);
  43. %this.hideLogButton = new GuiButtonCtrl()
  44. {
  45. Text="Close";
  46. command="EditorCore.close();";
  47. HorizSizing="left";
  48. VertSizing="top";
  49. Position="924 738";
  50. Extent="100 30";
  51. MinExtent="80 20";
  52. };
  53. ThemeManager.setProfile(%this.hideLogButton, "buttonProfile");
  54. %this.guiPage.add(%this.hideLogButton);
  55. %this.scroller = new GuiScrollCtrl()
  56. {
  57. HorizSizing="width";
  58. VertSizing="height";
  59. Position="0 0";
  60. Extent="1024 738";
  61. MinExtent="220 200";
  62. hScrollBar="alwaysOn";
  63. vScrollBar="alwaysOn";
  64. constantThumbHeight="0";
  65. showArrowButtons="1";
  66. };
  67. ThemeManager.setProfile(%this.scroller, "scrollProfile");
  68. ThemeManager.setProfile(%this.scroller, "thumbProfile", ThumbProfile);
  69. ThemeManager.setProfile(%this.scroller, "trackProfile", TrackProfile);
  70. ThemeManager.setProfile(%this.scroller, "scrollArrowProfile", ArrowProfile);
  71. %this.guiPage.add(%this.scroller);
  72. %this.consoleLog = new GuiConsole()
  73. {
  74. Position="0 0";
  75. Extent="1024 738";
  76. HorizSizing="width";
  77. VertSizing="height";
  78. Visible="1";
  79. };
  80. ThemeManager.setProfile(%this.consoleLog, "consoleProfile");
  81. %this.scroller.add(%this.consoleLog);
  82. EditorCore.FinishRegistration(%this.guiPage);
  83. }
  84. function EditorConsole::destroy(%this)
  85. {
  86. }
  87. function EditorConsole::open(%this)
  88. {
  89. %this.scroller.scrollToBottom();
  90. %this.consoleEntry.setFirstResponder();
  91. }
  92. function EditorConsole::close(%this)
  93. {
  94. }
  95. function EditorConsole::eval(%this)
  96. {
  97. %text = trim(%this.consoleEntry.getValue());
  98. if(strpos(%text, "(") == -1)
  99. {
  100. if(strpos(%text, "=") == -1 && strpos(%text, " ") == -1)
  101. {
  102. if(strpos(%text, "{") == -1 && strpos(%text, "}") == -1)
  103. {
  104. %text = %text @ "()";
  105. }
  106. }
  107. }
  108. %pos = strlen(%text) - 1;
  109. if(strpos(%text, ";", %pos) == -1 && strpos(%text, "}") == -1)
  110. %text = %text @ ";";
  111. echo("==>" @ %text);
  112. eval(%text);
  113. %this.consoleEntry.setValue("");
  114. }