window_console.tscript 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 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. // Start the timer when initializing the console
  23. $Con::useTimestamp = "1";
  24. // but hide the timestamp until requested
  25. $Con::useTimestamp = "0";
  26. function windowConsoleDlg::onWake(%this)
  27. {
  28. windowConsoleDlgErrorFilterBtn.setStateOn(windowConsoleMessageLogView.getErrorFilter());
  29. windowConsoleDlgWarnFilterBtn.setStateOn(windowConsoleMessageLogView.getWarnFilter());
  30. windowConsoleDlgNormalFilterBtn.setStateOn(windowConsoleMessageLogView.getNormalFilter());
  31. windowConsoleMessageLogView.setProfile(ToolsGuiConsoleProfile);
  32. $Con::font = 12;
  33. windowConsoleMessageLogView.refresh();
  34. // Make the window fit next to the side panel
  35. // We do a simple resize so that we don't have to redo the whole GUI layout
  36. %newWidth = getWord($pref::Video::mode, 0) - 360;
  37. %vertPos = getWord($pref::Video::mode, 1) - 360 - 35;
  38. windowConsoleControl.resize("0", %vertPos, %newWidth, "360");
  39. windowConsoleControl.dockPanel();
  40. }
  41. //-----------------------------------------------------------------------------
  42. function windowConsoleEntry::eval()
  43. {
  44. %text = trim(windowConsoleEntry.getValue());
  45. if(%text $= "")
  46. return;
  47. $Con::lastCommand = %text;
  48. // If it's missing a trailing () and it's not a variable,
  49. // append the parentheses.
  50. if(strpos(%text, "(") == -1 && !isDefined(%text)) {
  51. if(strpos(%text, "=") == -1 && strpos(%text, " ") == -1) {
  52. if(strpos(%text, "{") == -1 && strpos(%text, "}") == -1) {
  53. %text = %text @ "()";
  54. }
  55. }
  56. }
  57. // Append a semicolon if need be.
  58. %pos = strlen(%text) - 1;
  59. if(strpos(%text, ";", %pos) == -1 && strpos(%text, "}") == -1) {
  60. %text = %text @ ";";
  61. }
  62. // Turn off warnings for assigning from void
  63. // and evaluate the snippet.
  64. if(!isDefined("$Con::warnVoidAssignment"))
  65. %oldWarnVoidAssignment = true;
  66. else
  67. %oldWarnVoidAssignment = $Con::warnVoidAssignment;
  68. $Con::warnVoidAssignment = false;
  69. echo("==>" @ %text);
  70. eval(%text);
  71. $Con::warnVoidAssignment = %oldWarnVoidAssignment;
  72. windowConsoleEntry.setValue("");
  73. }
  74. function windowConsoleEntry::repeatLast(%this)
  75. {
  76. if($Con::lastCommand !$="")
  77. windowConsoleEntry.setText($Con::lastCommand);
  78. }
  79. //-----------------------------------------------------------------------------
  80. function windowConsoleDlg::hideWindow(%this)
  81. {
  82. $WindowConsole::Open = false;
  83. Canvas.popDialog(%this);
  84. %this-->Scroll.setVisible(false);
  85. }
  86. function windowConsoleDlg::showWindow(%this)
  87. {
  88. if($WindowConsole::Open)
  89. {
  90. // close the window when it's already opened
  91. windowConsoleDlg.hideWindow();
  92. }
  93. else
  94. {
  95. // open the console window
  96. $WindowConsole::Open = true;
  97. Canvas.pushDialog(%this);
  98. %this-->Scroll.setVisible(true);
  99. // update all the windows (position and size)
  100. EditorGui.updateSideBar();
  101. }
  102. }
  103. //-----------------------------------------------------------------------------
  104. function windowConsoleControl::setTab(%this, %tab, %text, %command)
  105. {
  106. if(isObject(%tab))
  107. {
  108. %tab.setActive(true);
  109. %tab.setHidden(false);
  110. %tab.setText(%text);
  111. %tab.command = %command;
  112. }
  113. }
  114. function windowConsoleControl::putToFront(%this)
  115. {
  116. // Close the object
  117. windowConsoleDlg.hideWindow();
  118. // Create the object again so it will render on top
  119. windowConsoleDlg.showWindow();
  120. // Put the focus on this window
  121. %this.selectWindow();
  122. }
  123. //-----------------------------------------------------------------------------
  124. function windowConsoleDlgErrorFilterBtn::onClick(%this)
  125. {
  126. windowConsoleMessageLogView.toggleErrorFilter();
  127. }
  128. function windowConsoleDlgWarnFilterBtn::onClick(%this)
  129. {
  130. windowConsoleMessageLogView.toggleWarnFilter();
  131. }
  132. function windowConsoleDlgNormalFilterBtn::onClick(%this)
  133. {
  134. windowConsoleMessageLogView.toggleNormalFilter();
  135. }
  136. function windowConsoleMessageLogView::onNewMessage(%this, %errorCount, %warnCount, %normalCount)
  137. {
  138. windowConsoleDlgErrorFilterBtn.setText(" Errors ( " @ %errorCount @ " )");
  139. windowConsoleDlgWarnFilterBtn.setText(" Warnings ( " @ %warnCount @ " )");
  140. windowConsoleDlgNormalFilterBtn.setText(" Messages ( " @ %normalCount @ " )");
  141. }
  142. //-----------------------------------------------------------------------------
  143. function windowConsoleDlg::timeStamp(%this)
  144. {
  145. %state = windowConsoleTimestampBtn.getValue();
  146. if(%state)
  147. {
  148. %label = "Time: On";
  149. %profile = "ToolsGuiButtonActiveProfile";
  150. %toolTip = "Hide the time stamp to console messages";
  151. $Con::useTimestamp = "1";
  152. }
  153. else
  154. {
  155. %label = "Time: Off";
  156. %profile = "ToolsGuiButtonProfile";
  157. %toolTip = "Show the time stamp to console messages";
  158. $Con::useTimestamp = "0";
  159. }
  160. windowConsoleTimestampBtn.setText(%label);
  161. windowConsoleTimestampBtn.setProfile(%profile);
  162. windowConsoleTimestampBtn.ToolTip = %toolTip;
  163. }
  164. function windowConsoleDlg::timeStampReset(%this)
  165. {
  166. resetTimeStamp();
  167. echo(">>>> Resetting timestamp");
  168. }
  169. function windowConsoleDlg::profilerDump(%this)
  170. {
  171. %state = windowConsoleDumpBtn.getValue();
  172. if(%state)
  173. {
  174. echo(">>>> Start profiler ---------------------------------------------");
  175. profilerEnable(true);
  176. %label = "Profiler: On";
  177. %toolTip = "Turn the profiler off and show the results";
  178. %profile = "ToolsGuiButtonGreenProfile";
  179. }
  180. else
  181. {
  182. profilerDump();
  183. %label = "Profiler: Off";
  184. %toolTip = "Turn the profiler on";
  185. %profile = "ToolsGuiButtonProfile";
  186. %this.schedule(1000, stopProfiler);
  187. }
  188. windowConsoleDumpBtn.setProfile(%profile);
  189. windowConsoleDumpBtn.setText(%label);
  190. windowConsoleDumpBtn.ToolTip = %toolTip;
  191. }
  192. function windowConsoleDlg::stopProfiler(%this)
  193. {
  194. profilerEnable(false);
  195. echo(">>>> Stop profiler ----------------------------------------------");
  196. }
  197. function windowConsoleDlg::infoDump(%this)
  198. {
  199. echo(">>>> ------------------------------------------------------------");
  200. %EngineName = getEngineName();
  201. %VersionString = getVersionString();
  202. %AppVersionString = getAppVersionString();
  203. %BuildString = getBuildString();
  204. %CompileTimeString = getCompileTimeString();
  205. echo(" o Engine :" SPC %EngineName);
  206. echo(" o Engine version :" SPC %VersionString);
  207. echo(" o App version :" SPC %AppVersionString);
  208. echo(" o Build :" SPC %BuildString);
  209. echo(" o Compile time :" SPC %CompileTimeString);
  210. echo(">>>> ------------------------------------------------------------");
  211. }
  212. function windowConsoleDlg::incFont()
  213. {
  214. switch ($Con::font)
  215. {
  216. case 16:
  217. windowConsoleMessageLogView.setProfile(ToolsGuiConsoleXLProfile);
  218. $Con::font = 18;
  219. windowConsoleMessageLogView.refresh();
  220. case 14:
  221. windowConsoleMessageLogView.setProfile(ToolsGuiConsoleLargeProfile);
  222. $Con::font = 16;
  223. windowConsoleMessageLogView.refresh();
  224. case 12:
  225. windowConsoleMessageLogView.setProfile(ToolsGuiConsoleMediumProfile);
  226. $Con::font = 14;
  227. windowConsoleMessageLogView.refresh();
  228. }
  229. }
  230. function windowConsoleDlg::decFont()
  231. {
  232. switch ($Con::font)
  233. {
  234. case 14:
  235. windowConsoleMessageLogView.setProfile(ToolsGuiConsoleProfile);
  236. $Con::font = 12;
  237. windowConsoleMessageLogView.refresh();
  238. case 16:
  239. windowConsoleMessageLogView.setProfile(ToolsGuiConsoleMediumProfile);
  240. $Con::font = 14;
  241. windowConsoleMessageLogView.refresh();
  242. case 18:
  243. windowConsoleMessageLogView.setProfile(ToolsGuiConsoleLargeProfile);
  244. $Con::font = 16;
  245. windowConsoleMessageLogView.refresh();
  246. }
  247. }
  248. //-----------------------------------------------------------------------------
  249. function windowConsoleControl::dockPanel(%this)
  250. {
  251. if(%this.docked == true)
  252. return;
  253. %this.resizing = true;
  254. %this.docked = true;
  255. %this.canCollapse = "0";
  256. %this.canMove = "0";
  257. %this.resizeWidth = "0";
  258. windowConsole_UnDockBtn.Visible = "1";
  259. windowConsole_DockBtn.Visible = "0";
  260. EditorGui.updateSideBar();
  261. }
  262. function windowConsoleControl::releasePanel(%this)
  263. {
  264. if(%this.docked == false)
  265. return;
  266. %this.canCollapse = "1";
  267. %this.canMove = "1";
  268. %this.resizeWidth = "1";
  269. windowConsole_UnDockBtn.Visible = "0";
  270. windowConsole_DockBtn.Visible = "1";
  271. // Let's do a small resize so it's visually clear we're "undocking"
  272. %position = %this.position.x + 6 SPC %this.position.y - 6;
  273. %extent = %this.extent.x SPC %this.extent.y;
  274. %this.resize(%position.x, %position.y, %extent.x, %extent.y);
  275. %this.docked = false;
  276. %this.resizing = false;
  277. EditorGui.updateSideBar();
  278. }
  279. //-----------------------------------------------------------------------------
  280. function windowConsoleDlg::addToolbarButton(%this)
  281. {
  282. %button = new GuiBitmapButtonCtrl() {
  283. canSaveDynamicFields = "0";
  284. internalName = windowConsoleBtn;
  285. Enabled = "1";
  286. isContainer = "0";
  287. Profile = "ToolsGuiButtonProfile";
  288. HorizSizing = "right";
  289. VertSizing = "bottom";
  290. position = "180 0";
  291. Extent = "25 19";
  292. MinExtent = "8 2";
  293. canSave = "1";
  294. Visible = "1";
  295. Command = "windowConsoleDlg.showWindow();";
  296. tooltipprofile = "ToolsGuiToolTipProfile";
  297. ToolTip = "Console (Windowed)";
  298. hovertime = "750";
  299. bitmapAsset = "ToolsModule:console_n_image";
  300. bitmapMode = "Stretched";
  301. buttonType = "PushButton";
  302. groupNum = "0";
  303. useMouseEvents = "0";
  304. };
  305. ToolsToolbarArray.add(%button);
  306. EWToolsToolbar.setExtent((29 + 4) * (ToolsToolbarArray.getCount()) + 4 SPC "32");
  307. }
  308. // windowConsoleDlg.addToolbarButton();