diff --git a/flixel/system/FlxBasePreloader.hx b/flixel/system/FlxBasePreloader.hx index 24f2ba8df9..9099fd488a 100644 --- a/flixel/system/FlxBasePreloader.hx +++ b/flixel/system/FlxBasePreloader.hx @@ -22,15 +22,15 @@ import flixel.util.FlxStringUtil; class FlxBasePreloader extends NMEPreloader { /** - * Add this string to allowedURLs array if you want to be able to test game with enabled site-locking on local machine + * Add this string to allowedURLs array if you want to be able to test game with enabled site-locking on local machine */ public static inline var LOCAL:String = #if flash "local" #else "localhost" #end; - + /** * Change this if you want the flixel logo to show for more or less time. Default value is 0 seconds (no delay). */ public var minDisplayTime:Float = 0; - + /** * List of allowed URLs for built-in site-locking. * Set it in FlxPreloader's constructor as: `['http://adamatomic.com/canabalt/', FlxPreloader.LOCAL]`; @@ -47,13 +47,13 @@ class FlxBasePreloader extends NMEPreloader /** * The title text to display on the sitelock failure screen. - * NOTE: This string should be reviewed for accuracy and may need to be localized. + * NOTE: This string should be reviewed for accuracy and may need to be localized. */ public var siteLockTitleText:String = "Sorry."; /** * The body text to display on the sitelock failure screen. - * NOTE: This string should be reviewed for accuracy and may need to be localized. + * NOTE: This string should be reviewed for accuracy and may need to be localized. */ public var siteLockBodyText:String = "It appears the website you are using is hosting an unauthorized copy of this game. " @@ -61,14 +61,14 @@ class FlxBasePreloader extends NMEPreloader + "developer or other copyright holder, is prohibited under copyright law.\n\n" + "Thank you for your interest in this game! Please support the developer by " + "visiting the following website to play the game:"; - + private var _percent:Float = 0; private var _width:Int; private var _height:Int; private var _loaded:Bool = false; private var _urlChecked:Bool = false; private var _startTime:Float; - + /** * FlxBasePreloader Constructor. * @param MinDisplayTime Minimum time (in seconds) the preloader should be shown. (Default = 0) @@ -77,56 +77,56 @@ class FlxBasePreloader extends NMEPreloader public function new(MinDisplayTime:Float = 0, ?AllowedURLs:Array) { super(); - + removeChild(progress); removeChild(outline); - + minDisplayTime = MinDisplayTime; if (AllowedURLs != null) allowedURLs = AllowedURLs; else allowedURLs = []; - + _startTime = Date.now().getTime(); } - + /** * Override this to create your own preloader objects. */ private function create():Void {} - + /** * This function is called externally to initialize the Preloader. */ - override public function onInit() + override public function onInit() { super.onInit(); - + Lib.current.stage.scaleMode = StageScaleMode.NO_SCALE; Lib.current.stage.align = StageAlign.TOP_LEFT; create(); addEventListener(Event.ENTER_FRAME, onEnterFrame); checkSiteLock(); } - + /** - * This function is called each update to check the load status of the project. + * This function is called each update to check the load status of the project. * It is highly recommended that you do NOT override this. */ - override public function onUpdate(bytesLoaded:Int, bytesTotal:Int) + override public function onUpdate(bytesLoaded:Int, bytesTotal:Int) { #if flash if (root.loaderInfo.bytesTotal == 0) bytesTotal = 50000; #end - + #if web _percent = (bytesTotal != 0) ? bytesLoaded / bytesTotal : 0; #else super.onUpdate(bytesLoaded, bytesTotal); #end } - + /** * This function is triggered on each 'frame'. * It is highly reccommended that you do NOT override this. @@ -139,7 +139,7 @@ class FlxBasePreloader extends NMEPreloader if ((min > 0) && (_percent > time / min)) percent = time / min; update(percent); - + if (_loaded && (min <= 0 || time / min >= 1)) { removeEventListener(Event.ENTER_FRAME, onEnterFrame); @@ -147,36 +147,36 @@ class FlxBasePreloader extends NMEPreloader destroy(); } } - + /** * This function is called when the project has finished loading. * Override it to remove all of your objects. */ private function destroy():Void {} - + /** * Override to draw your preloader objects in response to the Percent - * + * * @param Percent How much of the program has loaded. */ private function update(Percent:Float):Void {} - + /** - * This function is called EXTERNALLY once the movie has actually finished being loaded. + * This function is called EXTERNALLY once the movie has actually finished being loaded. * Highly recommended you DO NO override. */ - override public function onLoaded() + override public function onLoaded() { _loaded = true; _percent = 1; } - + /** * This should be used whenever you want to create a Bitmap that uses BitmapData embedded with the * @:bitmap metadata, if you want to support both Flash and HTML5. Because the embedded data is loaded * asynchronously in HTML5, any code that depends on the pixel data or size of the bitmap should be * in the onLoad function; any such code executed before it is called will fail on the HTML5 target. - * + * * @param bitmapDataClass A reference to the BitmapData child class that contains the embedded data which is to be used. * @param onLoad Executed once the bitmap data is finished loading in HTML5, and immediately in Flash. The new Bitmap instance is passed as an argument. * @return The Bitmap instance that was created. @@ -193,14 +193,14 @@ class FlxBasePreloader extends NMEPreloader return bmp; #end } - + /** * This should be used whenever you want to create a BitmapData object from a class containing data embedded with * the @:bitmap metadata. Often, you'll want to use the BitmapData in a Bitmap object; in this case, createBitmap() * can should be used instead. Because the embedded data is loaded asynchronously in HTML5, any code that depends on * the pixel data or size of the bitmap should be in the onLoad function; any such code executed before it is called * will fail on the HTML5 target. - * + * * @param bitmapDataClass A reference to the BitmapData child class that contains the embedded data which is to be used. * @param onLoad Executed once the bitmap data is finished loading in HTML5, and immediately in Flash. The new BitmapData instance is passed as an argument. * @return The BitmapData instance that was created. @@ -215,29 +215,29 @@ class FlxBasePreloader extends NMEPreloader return bmpData; #end } - + /** * Site-locking Functionality */ private function checkSiteLock():Void { - #if web - if (_urlChecked) return; + #if web + if (_urlChecked) return; - if (!isHostUrlAllowed()) + if (!isHostUrlAllowed()) { - removeChildren(); - removeEventListener(Event.ENTER_FRAME, onEnterFrame); + removeChildren(); + removeEventListener(Event.ENTER_FRAME, onEnterFrame); createSiteLockFailureScreen(); - } + } else { - _urlChecked = true; - } - #end + _urlChecked = true; + } + #end } - + #if web /** * When overridden, allows the customized creation of the sitelock failure screen. @@ -249,84 +249,84 @@ class FlxBasePreloader extends NMEPreloader addChild(createSiteLockFailureText(30)); } - private function createSiteLockFailureBackground(innerColor:UInt, outerColor:UInt):Shape + private function createSiteLockFailureBackground(innerColor:UInt, outerColor:UInt):Shape { - var shape = new Shape(); - var graphics = shape.graphics; - graphics.clear(); - - var fillMatrix = new Matrix(); - fillMatrix.createGradientBox(1, 1, 0, -0.5, -0.5); - var scaling = Math.max(stage.stageWidth, stage.stageHeight); - fillMatrix.scale(scaling, scaling); - fillMatrix.translate(0.5 * stage.stageWidth, 0.5 * stage.stageHeight); - - graphics.beginGradientFill(GradientType.RADIAL, [innerColor, outerColor], [1, 1], [0, 255], fillMatrix); - graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight); - graphics.endFill(); - return shape; - } - - private function createSiteLockFailureIcon(color:UInt, scale:Float):Shape + var shape = new Shape(); + var graphics = shape.graphics; + graphics.clear(); + + var fillMatrix = new Matrix(); + fillMatrix.createGradientBox(1, 1, 0, -0.5, -0.5); + var scaling = Math.max(stage.stageWidth, stage.stageHeight); + fillMatrix.scale(scaling, scaling); + fillMatrix.translate(0.5 * stage.stageWidth, 0.5 * stage.stageHeight); + + graphics.beginGradientFill(GradientType.RADIAL, [innerColor, outerColor], [1, 1], [0, 255], fillMatrix); + graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight); + graphics.endFill(); + return shape; + } + + private function createSiteLockFailureIcon(color:UInt, scale:Float):Shape { - var shape = new Shape(); - var graphics = shape.graphics; - graphics.clear(); - - graphics.beginFill(color); - graphics.drawPath( - [ 1, 6, 2, 2, 2, 6, 6, 2, 2, 2, 6, 1, 6, 2, 6, 2, 6, 2, 6, 1, 6, 6, 2, 2, 2, 6, 6 ], - [ 120.0, 0, 164, 0, 200, 35, 200, 79, 200, 130, 160, 130, 160, 79, 160, 57, 142, 40, - 120, 40, 97, 40, 79, 57, 79, 79, 80, 130, 40, 130, 40, 79, 40, 35, 75, 0, 120, 0, - 220, 140, 231, 140, 240, 148, 240, 160, 240, 300, 240, 311, 231, 320, 220, 320, - 20, 320, 8, 320, 0, 311, 0, 300, 0, 160, 0, 148, 8, 140, 20, 140, 120, 190, 108, - 190, 100, 198, 100, 210, 100, 217, 104, 223, 110, 227, 110, 270, 130, 270, 130, - 227, 135, 223, 140, 217, 140, 210, 140, 198, 131, 190, 120, 190 ], - GraphicsPathWinding.NON_ZERO - ); - graphics.endFill(); - - var transformMatrix = new Matrix(); - transformMatrix.translate(-0.5 * shape.width, -0.5 * shape.height); - var scaling = scale * Math.min(stage.stageWidth / shape.width, stage.stageHeight / shape.height); - transformMatrix.scale(scaling, scaling); - transformMatrix.translate(0.5 * stage.stageWidth, 0.5 * stage.stageHeight); - shape.transform.matrix = transformMatrix; - return shape; - } - - private function createSiteLockFailureText(margin:Float):Sprite + var shape = new Shape(); + var graphics = shape.graphics; + graphics.clear(); + + graphics.beginFill(color); + graphics.drawPath( + [ 1, 6, 2, 2, 2, 6, 6, 2, 2, 2, 6, 1, 6, 2, 6, 2, 6, 2, 6, 1, 6, 6, 2, 2, 2, 6, 6 ], + [ 120.0, 0, 164, 0, 200, 35, 200, 79, 200, 130, 160, 130, 160, 79, 160, 57, 142, 40, + 120, 40, 97, 40, 79, 57, 79, 79, 80, 130, 40, 130, 40, 79, 40, 35, 75, 0, 120, 0, + 220, 140, 231, 140, 240, 148, 240, 160, 240, 300, 240, 311, 231, 320, 220, 320, + 20, 320, 8, 320, 0, 311, 0, 300, 0, 160, 0, 148, 8, 140, 20, 140, 120, 190, 108, + 190, 100, 198, 100, 210, 100, 217, 104, 223, 110, 227, 110, 270, 130, 270, 130, + 227, 135, 223, 140, 217, 140, 210, 140, 198, 131, 190, 120, 190 ], + GraphicsPathWinding.NON_ZERO + ); + graphics.endFill(); + + var transformMatrix = new Matrix(); + transformMatrix.translate(-0.5 * shape.width, -0.5 * shape.height); + var scaling = scale * Math.min(stage.stageWidth / shape.width, stage.stageHeight / shape.height); + transformMatrix.scale(scaling, scaling); + transformMatrix.translate(0.5 * stage.stageWidth, 0.5 * stage.stageHeight); + shape.transform.matrix = transformMatrix; + return shape; + } + + private function createSiteLockFailureText(margin:Float):Sprite { - var sprite = new Sprite(); - var bounds = new Rectangle(0, 0, stage.stageWidth, stage.stageHeight); - bounds.inflate(-margin, -margin); - - var titleText = new TextField(); - var titleTextFormat = new TextFormat("_sans", 33, 0x333333, true); - titleTextFormat.align = TextFormatAlign.LEFT; - titleText.defaultTextFormat = titleTextFormat; - titleText.selectable = false; - titleText.width = bounds.width; - titleText.text = siteLockTitleText; - - var bodyText = new TextField(); - var bodyTextFormat = new TextFormat("_sans", 22, 0x333333); - bodyTextFormat.align = TextFormatAlign.JUSTIFY; - bodyText.defaultTextFormat = bodyTextFormat; - bodyText.multiline = true; - bodyText.wordWrap = true; - bodyText.selectable = false; - bodyText.width = bounds.width; - bodyText.text = siteLockBodyText; - - var hyperlinkText = new TextField(); - var hyperlinkTextFormat = new TextFormat("_sans", 22, 0x6e97cc, true, false, true); - hyperlinkTextFormat.align = TextFormatAlign.CENTER; - hyperlinkTextFormat.url = allowedURLs[siteLockURLIndex]; - hyperlinkText.defaultTextFormat = hyperlinkTextFormat; - hyperlinkText.selectable = true; - hyperlinkText.width = bounds.width; - hyperlinkText.text = allowedURLs[siteLockURLIndex]; + var sprite = new Sprite(); + var bounds = new Rectangle(0, 0, stage.stageWidth, stage.stageHeight); + bounds.inflate(-margin, -margin); + + var titleText = new TextField(); + var titleTextFormat = new TextFormat("_sans", 33, 0x333333, true); + titleTextFormat.align = TextFormatAlign.LEFT; + titleText.defaultTextFormat = titleTextFormat; + titleText.selectable = false; + titleText.width = bounds.width; + titleText.text = siteLockTitleText; + + var bodyText = new TextField(); + var bodyTextFormat = new TextFormat("_sans", 22, 0x333333); + bodyTextFormat.align = TextFormatAlign.JUSTIFY; + bodyText.defaultTextFormat = bodyTextFormat; + bodyText.multiline = true; + bodyText.wordWrap = true; + bodyText.selectable = false; + bodyText.width = bounds.width; + bodyText.text = siteLockBodyText; + + var hyperlinkText = new TextField(); + var hyperlinkTextFormat = new TextFormat("_sans", 22, 0x6e97cc, true, false, true); + hyperlinkTextFormat.align = TextFormatAlign.CENTER; + hyperlinkTextFormat.url = allowedURLs[siteLockURLIndex]; + hyperlinkText.defaultTextFormat = hyperlinkTextFormat; + hyperlinkText.selectable = true; + hyperlinkText.width = bounds.width; + hyperlinkText.text = allowedURLs[siteLockURLIndex]; // Do customization before final layout. adjustSiteLockTextFields(titleText, bodyText, hyperlinkText); @@ -335,19 +335,19 @@ class FlxBasePreloader extends NMEPreloader titleText.height = titleText.textHeight + gutterSize; bodyText.height = bodyText.textHeight + gutterSize; hyperlinkText.height = hyperlinkText.textHeight + gutterSize; - titleText.x = bodyText.x = hyperlinkText.x = bounds.left; - titleText.y = bounds.top; - bodyText.y = titleText.y + 2.0 * titleText.height; - hyperlinkText.y = bodyText.y + bodyText.height + hyperlinkText.height; + titleText.x = bodyText.x = hyperlinkText.x = bounds.left; + titleText.y = bounds.top; + bodyText.y = titleText.y + 2.0 * titleText.height; + hyperlinkText.y = bodyText.y + bodyText.height + hyperlinkText.height; - sprite.addChild(titleText); - sprite.addChild(bodyText); - sprite.addChild(hyperlinkText); - return sprite; - } + sprite.addChild(titleText); + sprite.addChild(bodyText); + sprite.addChild(hyperlinkText); + return sprite; + } /** - * When overridden, allows the customization of the text fields in the sitelock failure screen. + * When overridden, allows the customization of the text fields in the sitelock failure screen. */ private function adjustSiteLockTextFields(titleText:TextField, bodyText:TextField, hyperlinkText:TextField):Void {} @@ -360,14 +360,14 @@ class FlxBasePreloader extends NMEPreloader else Lib.getURL(new URLRequest(allowedURLs[siteLockURLIndex])); } - + private function isHostUrlAllowed():Bool { if (allowedURLs.length == 0) { return true; } - + var homeDomain:String = FlxStringUtil.getDomain(#if flash loaderInfo.loaderURL #elseif js js.Browser.location.href #end); for (allowedURL in allowedURLs) {