EditorConsole.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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="1024 30";
  31. minExtent="120 20";
  32. ReturnCommand="EditorConsole.eval();";
  33. MaxLength="255";
  34. active = "1";
  35. };
  36. ThemeManager.setProfile(%this.consoleEntry, "textEditProfile");
  37. %this.guiPage.add(%this.consoleEntry);
  38. %this.scroller = new GuiScrollCtrl()
  39. {
  40. HorizSizing="width";
  41. VertSizing="height";
  42. Position="0 0";
  43. Extent="1024 738";
  44. MinExtent="220 200";
  45. hScrollBar="alwaysOn";
  46. vScrollBar="alwaysOn";
  47. constantThumbHeight="0";
  48. showArrowButtons="1";
  49. };
  50. ThemeManager.setProfile(%this.scroller, "scrollProfile");
  51. ThemeManager.setProfile(%this.scroller, "thumbProfile", ThumbProfile);
  52. ThemeManager.setProfile(%this.scroller, "trackProfile", TrackProfile);
  53. ThemeManager.setProfile(%this.scroller, "scrollArrowProfile", ArrowProfile);
  54. %this.guiPage.add(%this.scroller);
  55. %this.consoleLog = new GuiConsole()
  56. {
  57. Position="0 0";
  58. Extent="1024 738";
  59. HorizSizing="width";
  60. VertSizing="height";
  61. Visible="1";
  62. };
  63. ThemeManager.setProfile(%this.consoleLog, "consoleProfile");
  64. %this.scroller.add(%this.consoleLog);
  65. EditorCore.FinishRegistration(%this.guiPage);
  66. }
  67. function EditorConsole::destroy(%this)
  68. {
  69. }
  70. function EditorConsole::open(%this)
  71. {
  72. %this.scroller.scrollToBottom();
  73. %this.consoleEntry.setFirstResponder();
  74. }
  75. function EditorConsole::close(%this)
  76. {
  77. }
  78. function EditorConsole::eval(%this)
  79. {
  80. %text = trim(%this.consoleEntry.getValue());
  81. if(%text $= "")
  82. {
  83. return;
  84. }
  85. if(strpos(%text, "(") == -1 && strpos(%text, "=") == -1 && strpos(%text, " ") == -1 && strpos(%text, "{") == -1 && strpos(%text, "}") == -1)
  86. {
  87. %text = %text @ "()";
  88. }
  89. %pos = strlen(%text) - 1;
  90. if(strpos(%text, ";", %pos) == -1 && strpos(%text, "}") == -1)
  91. %text = %text @ ";";
  92. echo("==>" @ %text);
  93. eval(%text);
  94. %this.consoleEntry.setValue("");
  95. }