/Mining_Game/src/org/flixel/system/FlxDebugger.as

https://github.com/8Ashkin8/Mining-Game · ActionScript · 231 lines · 150 code · 20 blank · 61 comment · 1 complexity · b702983d6bd55f9b88fd58720bd5773e MD5 · raw file

  1. package org.flixel.system
  2. {
  3. import flash.display.Bitmap;
  4. import flash.display.BitmapData;
  5. import flash.display.Sprite;
  6. import flash.events.MouseEvent;
  7. import flash.geom.Point;
  8. import flash.geom.Rectangle;
  9. import flash.text.TextField;
  10. import flash.text.TextFormat;
  11. import org.flixel.FlxG;
  12. import org.flixel.system.debug.Log;
  13. import org.flixel.system.debug.Perf;
  14. import org.flixel.system.debug.VCR;
  15. import org.flixel.system.debug.Vis;
  16. import org.flixel.system.debug.Watch;
  17. /**
  18. * Container for the new debugger overlay.
  19. * Most of the functionality is in the debug folder widgets,
  20. * but this class instantiates the widgets and handles their basic formatting and arrangement.
  21. */
  22. public class FlxDebugger extends Sprite
  23. {
  24. /**
  25. * Container for the performance monitor widget.
  26. */
  27. public var perf:Perf;
  28. /**
  29. * Container for the trace output widget.
  30. */
  31. public var log:Log;
  32. /**
  33. * Container for the watch window widget.
  34. */
  35. public var watch:Watch;
  36. /**
  37. * Container for the record, stop and play buttons.
  38. */
  39. public var vcr:VCR;
  40. /**
  41. * Container for the visual debug mode toggle.
  42. */
  43. public var vis:Vis;
  44. /**
  45. * Whether the mouse is currently over one of the debugger windows or not.
  46. */
  47. public var hasMouse:Boolean;
  48. /**
  49. * Internal, tracks what debugger window layout user has currently selected.
  50. */
  51. protected var _layout:uint;
  52. /**
  53. * Internal, stores width and height of the Flash Player window.
  54. */
  55. protected var _screen:Point;
  56. /**
  57. * Internal, used to space out windows from the edges.
  58. */
  59. protected var _gutter:uint;
  60. /**
  61. * Instantiates the debugger overlay.
  62. *
  63. * @param Width The width of the screen.
  64. * @param Height The height of the screen.
  65. */
  66. public function FlxDebugger(Width:Number,Height:Number)
  67. {
  68. super();
  69. visible = false;
  70. hasMouse = false;
  71. _screen = new Point(Width,Height);
  72. addChild(new Bitmap(new BitmapData(Width,15,true,0x7f000000)));
  73. var txt:TextField = new TextField();
  74. txt.x = 2;
  75. txt.width = 160;
  76. txt.height = 16;
  77. txt.selectable = false;
  78. txt.multiline = false;
  79. txt.defaultTextFormat = new TextFormat("Courier",12,0xffffff);
  80. var str:String = FlxG.getLibraryName();
  81. if(FlxG.debug)
  82. str += " [debug]";
  83. else
  84. str += " [release]";
  85. txt.text = str;
  86. addChild(txt);
  87. _gutter = 8;
  88. var screenBounds:Rectangle = new Rectangle(_gutter,15+_gutter/2,_screen.x-_gutter*2,_screen.y-_gutter*1.5-15);
  89. log = new Log("log",0,0,true,screenBounds);
  90. addChild(log);
  91. watch = new Watch("watch",0,0,true,screenBounds);
  92. addChild(watch);
  93. perf = new Perf("stats",0,0,false,screenBounds);
  94. addChild(perf);
  95. vcr = new VCR();
  96. vcr.x = (Width - vcr.width/2)/2;
  97. vcr.y = 2;
  98. addChild(vcr);
  99. vis = new Vis();
  100. vis.x = Width-vis.width - 4;
  101. vis.y = 2;
  102. addChild(vis);
  103. setLayout(FlxG.DEBUGGER_STANDARD);
  104. //Should help with fake mouse focus type behavior
  105. addEventListener(MouseEvent.MOUSE_OVER,onMouseOver);
  106. addEventListener(MouseEvent.MOUSE_OUT,onMouseOut);
  107. }
  108. /**
  109. * Clean up memory.
  110. */
  111. public function destroy():void
  112. {
  113. _screen = null;
  114. removeChild(log);
  115. log.destroy();
  116. log = null;
  117. removeChild(watch);
  118. watch.destroy();
  119. watch = null;
  120. removeChild(perf);
  121. perf.destroy();
  122. perf = null;
  123. removeChild(vcr);
  124. vcr.destroy();
  125. vcr = null;
  126. removeChild(vis);
  127. vis.destroy();
  128. vis = null;
  129. removeEventListener(MouseEvent.MOUSE_OVER,onMouseOver);
  130. removeEventListener(MouseEvent.MOUSE_OUT,onMouseOut);
  131. }
  132. /**
  133. * Mouse handler that helps with fake "mouse focus" type behavior.
  134. *
  135. * @param E Flash mouse event.
  136. */
  137. protected function onMouseOver(E:MouseEvent=null):void
  138. {
  139. hasMouse = true;
  140. }
  141. /**
  142. * Mouse handler that helps with fake "mouse focus" type behavior.
  143. *
  144. * @param E Flash mouse event.
  145. */
  146. protected function onMouseOut(E:MouseEvent=null):void { hasMouse = false; }
  147. /**
  148. * Rearrange the debugger windows using one of the constants specified in FlxG.
  149. *
  150. * @param Layout The layout style for the debugger windows, e.g. <code>FlxG.DEBUGGER_MICRO</code>.
  151. */
  152. public function setLayout(Layout:uint):void
  153. {
  154. _layout = Layout;
  155. resetLayout();
  156. }
  157. /**
  158. * Forces the debugger windows to reset to the last specified layout.
  159. * The default layout is <code>FlxG.DEBUGGER_STANDARD</code>.
  160. */
  161. public function resetLayout():void
  162. {
  163. switch(_layout)
  164. {
  165. case FlxG.DEBUGGER_MICRO:
  166. log.resize(_screen.x/4,68);
  167. log.reposition(0,_screen.y);
  168. watch.resize(_screen.x/4,68);
  169. watch.reposition(_screen.x,_screen.y);
  170. perf.reposition(_screen.x,0);
  171. break;
  172. case FlxG.DEBUGGER_BIG:
  173. log.resize((_screen.x-_gutter*3)/2,_screen.y/2);
  174. log.reposition(0,_screen.y);
  175. watch.resize((_screen.x-_gutter*3)/2,_screen.y/2);
  176. watch.reposition(_screen.x,_screen.y);
  177. perf.reposition(_screen.x,0);
  178. break;
  179. case FlxG.DEBUGGER_TOP:
  180. log.resize((_screen.x-_gutter*3)/2,_screen.y/4);
  181. log.reposition(0,0);
  182. watch.resize((_screen.x-_gutter*3)/2,_screen.y/4);
  183. watch.reposition(_screen.x,0);
  184. perf.reposition(_screen.x,_screen.y);
  185. break;
  186. case FlxG.DEBUGGER_LEFT:
  187. log.resize(_screen.x/3,(_screen.y-15-_gutter*2.5)/2);
  188. log.reposition(0,0);
  189. watch.resize(_screen.x/3,(_screen.y-15-_gutter*2.5)/2);
  190. watch.reposition(0,_screen.y);
  191. perf.reposition(_screen.x,0);
  192. break;
  193. case FlxG.DEBUGGER_RIGHT:
  194. log.resize(_screen.x/3,(_screen.y-15-_gutter*2.5)/2);
  195. log.reposition(_screen.x,0);
  196. watch.resize(_screen.x/3,(_screen.y-15-_gutter*2.5)/2);
  197. watch.reposition(_screen.x,_screen.y);
  198. perf.reposition(0,0);
  199. break;
  200. case FlxG.DEBUGGER_STANDARD:
  201. default:
  202. log.resize((_screen.x-_gutter*3)/2,_screen.y/4);
  203. log.reposition(0,_screen.y);
  204. watch.resize((_screen.x-_gutter*3)/2,_screen.y/4);
  205. watch.reposition(_screen.x,_screen.y);
  206. perf.reposition(_screen.x,0);
  207. break;
  208. }
  209. }
  210. }
  211. }