window_console.tscript 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  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. $WindowConsole::Open = true;
  89. Canvas.pushDialog(%this);
  90. %this-->Scroll.setVisible(true);
  91. // Add a tab to the asset browser
  92. if($AssetBrowser::Open)
  93. {
  94. %text = "Asset Browser";
  95. %command = "AssetBrowser.putToFront();";
  96. AssetBrowserWindow.text = "";
  97. windowConsoleControl.text = "";
  98. windowConsoleControl.setTab(windowConsole_Tab1, "Console Log", "");
  99. windowConsole_Tab1.setHidden(false);
  100. windowConsole_Tab1.setActive(false);
  101. if(windowConsole_Tab2.text $= %text || windowConsole_Tab3.text $= %text || windowConsole_Tab4.text $= %text)
  102. {
  103. // we have a tab, don't do anything
  104. }
  105. else if(windowConsole_Tab2.hidden == true)
  106. {
  107. windowConsoleControl.setTab(windowConsole_Tab2, %text, %command);
  108. }
  109. else if(windowConsole_Tab3.hidden == true)
  110. {
  111. windowConsoleControl.setTab(windowConsole_Tab3, %text, %command);
  112. }
  113. else if(windowConsole_Tab4.hidden == true)
  114. {
  115. windowConsoleControl.setTab(windowConsole_Tab4, %text, %command);
  116. }
  117. else
  118. {
  119. warn("Ran out of tabs for AssetBrowserWindow - windowConsoleDlg::showWindow()");
  120. }
  121. }
  122. }
  123. //-----------------------------------------------------------------------------
  124. function windowConsoleControl::setTab(%this, %tab, %text, %command)
  125. {
  126. if(isObject(%tab))
  127. {
  128. %tab.setActive(true);
  129. %tab.setHidden(false);
  130. %tab.setText(%text);
  131. %tab.command = %command;
  132. }
  133. }
  134. function windowConsoleControl::putToFront(%this)
  135. {
  136. // Close the object
  137. windowConsoleDlg.hideWindow();
  138. // Create the object again so it will render on top
  139. windowConsoleDlg.showWindow();
  140. // Put the focus on this window
  141. %this.selectWindow();
  142. }
  143. //-----------------------------------------------------------------------------
  144. function windowConsoleDlgErrorFilterBtn::onClick(%this)
  145. {
  146. windowConsoleMessageLogView.toggleErrorFilter();
  147. }
  148. function windowConsoleDlgWarnFilterBtn::onClick(%this)
  149. {
  150. windowConsoleMessageLogView.toggleWarnFilter();
  151. }
  152. function windowConsoleDlgNormalFilterBtn::onClick(%this)
  153. {
  154. windowConsoleMessageLogView.toggleNormalFilter();
  155. }
  156. function windowConsoleMessageLogView::onNewMessage(%this, %errorCount, %warnCount, %normalCount)
  157. {
  158. windowConsoleDlgErrorFilterBtn.setText(" Errors ( " @ %errorCount @ " )");
  159. windowConsoleDlgWarnFilterBtn.setText(" Warnings ( " @ %warnCount @ " )");
  160. windowConsoleDlgNormalFilterBtn.setText(" Messages ( " @ %normalCount @ " )");
  161. }
  162. //-----------------------------------------------------------------------------
  163. function windowConsoleDlg::timeStamp(%this)
  164. {
  165. %state = windowConsoleTimestampBtn.getValue();
  166. if(%state)
  167. {
  168. %label = "Time: On";
  169. %profile = "ToolsGuiButtonActiveProfile";
  170. %toolTip = "Hide the time stamp to console messages";
  171. $Con::useTimestamp = "1";
  172. }
  173. else
  174. {
  175. %label = "Time: Off";
  176. %profile = "ToolsGuiButtonProfile";
  177. %toolTip = "Show the time stamp to console messages";
  178. $Con::useTimestamp = "0";
  179. }
  180. windowConsoleTimestampBtn.setText(%label);
  181. windowConsoleTimestampBtn.setProfile(%profile);
  182. windowConsoleTimestampBtn.ToolTip = %toolTip;
  183. }
  184. function windowConsoleDlg::timeStampReset(%this)
  185. {
  186. resetTimeStamp();
  187. echo(">>>> Resetting timestamp");
  188. }
  189. function windowConsoleDlg::profilerDump(%this)
  190. {
  191. %state = windowConsoleDumpBtn.getValue();
  192. if(%state)
  193. {
  194. echo(">>>> Start profiler ---------------------------------------------");
  195. profilerEnable(true);
  196. %label = "Profiler: On";
  197. %toolTip = "Turn the profiler off and show the results";
  198. %profile = "ToolsGuiButtonGreenProfile";
  199. }
  200. else
  201. {
  202. profilerDump();
  203. %label = "Profiler: Off";
  204. %toolTip = "Turn the profiler on";
  205. %profile = "ToolsGuiButtonProfile";
  206. %this.schedule(1000, stopProfiler);
  207. }
  208. windowConsoleDumpBtn.setProfile(%profile);
  209. windowConsoleDumpBtn.setText(%label);
  210. windowConsoleDumpBtn.ToolTip = %toolTip;
  211. }
  212. function windowConsoleDlg::stopProfiler(%this)
  213. {
  214. profilerEnable(false);
  215. echo(">>>> Stop profiler ----------------------------------------------");
  216. }
  217. function windowConsoleDlg::infoDump(%this)
  218. {
  219. echo(">>>> ------------------------------------------------------------");
  220. %EngineName = getEngineName();
  221. %VersionString = getVersionString();
  222. %AppVersionString = getAppVersionString();
  223. %BuildString = getBuildString();
  224. %CompileTimeString = getCompileTimeString();
  225. echo(" o Engine :" SPC %EngineName);
  226. echo(" o Engine version :" SPC %VersionString);
  227. echo(" o App version :" SPC %AppVersionString);
  228. echo(" o Build :" SPC %BuildString);
  229. echo(" o Compile time :" SPC %CompileTimeString);
  230. echo(">>>> ------------------------------------------------------------");
  231. }
  232. function windowConsoleDlg::incFont()
  233. {
  234. switch ($Con::font)
  235. {
  236. case 14:
  237. windowConsoleMessageLogView.setProfile(ToolsGuiConsoleLargeProfile);
  238. $Con::font = 16;
  239. windowConsoleMessageLogView.refresh();
  240. case 12:
  241. windowConsoleMessageLogView.setProfile(ToolsGuiConsoleMediumProfile);
  242. $Con::font = 14;
  243. windowConsoleMessageLogView.refresh();
  244. }
  245. }
  246. function windowConsoleDlg::decFont()
  247. {
  248. switch ($Con::font)
  249. {
  250. case 14:
  251. windowConsoleMessageLogView.setProfile(ToolsGuiConsoleProfile);
  252. $Con::font = 12;
  253. windowConsoleMessageLogView.refresh();
  254. case 16:
  255. windowConsoleMessageLogView.setProfile(ToolsGuiConsoleMediumProfile);
  256. $Con::font = 14;
  257. windowConsoleMessageLogView.refresh();
  258. }
  259. }
  260. //-----------------------------------------------------------------------------
  261. function windowConsoleControl::dockPanel(%this)
  262. {
  263. if(%this.docked == true)
  264. return;
  265. %this.resizing = true;
  266. %this.docked = true;
  267. %this.canCollapse = "0";
  268. %this.canMove = "0";
  269. %this.resizeWidth = "0";
  270. windowConsole_UnDockBtn.Visible = "1";
  271. windowConsole_DockBtn.Visible = "0";
  272. EditorGui.updateSideBar();
  273. }
  274. function windowConsoleControl::releasePanel(%this)
  275. {
  276. if(%this.docked == false)
  277. return;
  278. %this.canCollapse = "1";
  279. %this.canMove = "1";
  280. %this.resizeWidth = "1";
  281. windowConsole_UnDockBtn.Visible = "0";
  282. windowConsole_DockBtn.Visible = "1";
  283. // Let's do a small resize so it's visually clear we're "undocking"
  284. %position = %this.position.x + 6 SPC %this.position.y - 6;
  285. %extent = %this.extent.x SPC %this.extent.y;
  286. %this.resize(%position.x, %position.y, %extent.x, %extent.y);
  287. %this.docked = false;
  288. %this.resizing = false;
  289. EditorGui.updateSideBar();
  290. }
  291. //-----------------------------------------------------------------------------
  292. function windowConsoleDlg::addToolbarButton(%this)
  293. {
  294. %button = new GuiBitmapButtonCtrl() {
  295. canSaveDynamicFields = "0";
  296. internalName = windowConsoleBtn;
  297. Enabled = "1";
  298. isContainer = "0";
  299. Profile = "ToolsGuiButtonProfile";
  300. HorizSizing = "right";
  301. VertSizing = "bottom";
  302. position = "180 0";
  303. Extent = "25 19";
  304. MinExtent = "8 2";
  305. canSave = "1";
  306. Visible = "1";
  307. Command = "windowConsoleDlg.showWindow();";
  308. tooltipprofile = "ToolsGuiToolTipProfile";
  309. ToolTip = "Console (Windowed)";
  310. hovertime = "750";
  311. bitmapAsset = "ToolsModule:console_n_image";
  312. bitmapMode = "Stretched";
  313. buttonType = "PushButton";
  314. groupNum = "0";
  315. useMouseEvents = "0";
  316. };
  317. ToolsToolbarArray.add(%button);
  318. EWToolsToolbar.setExtent((29 + 4) * (ToolsToolbarArray.getCount()) + 4 SPC "32");
  319. }
  320. // windowConsoleDlg.addToolbarButton();