美素佳儿 litter wizard小游戏
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

4745 lines
181KB

  1. var __reflect = (this && this.__reflect) || function (p, c, t) {
  2. p.__class__ = c, t ? t.push(c) : t = [c], p.__types__ = p.__types__ ? t.concat(p.__types__) : t;
  3. };
  4. var __extends = (this && this.__extends) || function (d, b) {
  5. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  6. function __() { this.constructor = d; }
  7. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  8. };
  9. //////////////////////////////////////////////////////////////////////////////////////
  10. //
  11. // Copyright (c) 2014-present, Egret Technology.
  12. // All rights reserved.
  13. // Redistribution and use in source and binary forms, with or without
  14. // modification, are permitted provided that the following conditions are met:
  15. //
  16. // * Redistributions of source code must retain the above copyright
  17. // notice, this list of conditions and the following disclaimer.
  18. // * Redistributions in binary form must reproduce the above copyright
  19. // notice, this list of conditions and the following disclaimer in the
  20. // documentation and/or other materials provided with the distribution.
  21. // * Neither the name of the Egret nor the
  22. // names of its contributors may be used to endorse or promote products
  23. // derived from this software without specific prior written permission.
  24. //
  25. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  26. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  27. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  28. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  29. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  30. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  31. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  32. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  33. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  34. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  35. //
  36. //////////////////////////////////////////////////////////////////////////////////////
  37. var egret;
  38. (function (egret) {
  39. /**
  40. * @version Egret 2.4
  41. * @platform Web,Native
  42. * @private
  43. */
  44. var FrameLabel = (function (_super) {
  45. __extends(FrameLabel, _super);
  46. /**
  47. * @version Egret 2.4
  48. * @platform Web,Native
  49. */
  50. function FrameLabel(name, frame /*int*/, end /*int*/) {
  51. var _this = _super.call(this) || this;
  52. _this._name = name;
  53. _this._frame = frame | 0;
  54. if (end)
  55. _this._end = end | 0;
  56. return _this;
  57. }
  58. Object.defineProperty(FrameLabel.prototype, "name", {
  59. /**
  60. * @language en_US
  61. * Frame number
  62. * @version Egret 2.4
  63. * @platform Web,Native
  64. */
  65. /**
  66. * @language zh_CN
  67. * 标签名
  68. * @version Egret 2.4
  69. * @platform Web,Native
  70. */
  71. get: function () {
  72. return this._name;
  73. },
  74. enumerable: true,
  75. configurable: true
  76. });
  77. Object.defineProperty(FrameLabel.prototype, "frame", {
  78. /**
  79. * @language en_US
  80. * Frame serial number of the label
  81. * @version Egret 2.4
  82. * @platform Web,Native
  83. */
  84. /**
  85. * @language zh_CN
  86. * 标签所在帧序号
  87. * @version Egret 2.4
  88. * @platform Web,Native
  89. */
  90. get: function () {
  91. return this._frame;
  92. },
  93. enumerable: true,
  94. configurable: true
  95. });
  96. Object.defineProperty(FrameLabel.prototype, "end", {
  97. /**
  98. * @language en_US
  99. * Frame serial number, the end of the label
  100. * @version Egret 2.4
  101. * @platform Web,Native
  102. */
  103. /**
  104. * @language zh_CN
  105. * 标签对应的结束帧序号
  106. * @version Egret 2.4
  107. * @platform Web,Native
  108. */
  109. get: function () {
  110. return this._end;
  111. },
  112. enumerable: true,
  113. configurable: true
  114. });
  115. /**
  116. * @language en_US
  117. * Duplicate the current frame label object
  118. * @version Egret 2.4
  119. * @platform Web,Native
  120. */
  121. /**
  122. * @language zh_CN
  123. * 复制当前帧标签对象
  124. * @version Egret 2.4
  125. * @platform Web,Native
  126. */
  127. FrameLabel.prototype.clone = function () {
  128. return new FrameLabel(this._name, this._frame, this._end);
  129. };
  130. return FrameLabel;
  131. }(egret.EventDispatcher));
  132. egret.FrameLabel = FrameLabel;
  133. __reflect(FrameLabel.prototype, "egret.FrameLabel");
  134. })(egret || (egret = {}));
  135. //////////////////////////////////////////////////////////////////////////////////////
  136. //
  137. // Copyright (c) 2014-present, Egret Technology.
  138. // All rights reserved.
  139. // Redistribution and use in source and binary forms, with or without
  140. // modification, are permitted provided that the following conditions are met:
  141. //
  142. // * Redistributions of source code must retain the above copyright
  143. // notice, this list of conditions and the following disclaimer.
  144. // * Redistributions in binary form must reproduce the above copyright
  145. // notice, this list of conditions and the following disclaimer in the
  146. // documentation and/or other materials provided with the distribution.
  147. // * Neither the name of the Egret nor the
  148. // names of its contributors may be used to endorse or promote products
  149. // derived from this software without specific prior written permission.
  150. //
  151. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  152. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  153. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  154. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  155. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  156. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  157. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  158. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  159. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  160. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  161. //
  162. //////////////////////////////////////////////////////////////////////////////////////
  163. var egret;
  164. (function (egret) {
  165. /**
  166. * @language en_US
  167. * @version Egret 2.4
  168. * @platform Web,Native
  169. * @includeExample extension/game/display/MovieClip.ts
  170. */
  171. /**
  172. * @language zh_CN
  173. * 影片剪辑,可以通过影片剪辑播放序列帧动画。MovieClip 类从以下类继承而来:DisplayObject 和 EventDispatcher。不同于 DisplayObject 对象,MovieClip 对象拥有一个时间轴。
  174. * @extends egret.DisplayObject
  175. * @event egret.Event.COMPLETE 动画播放完成。
  176. * @event egret.Event.LOOP_COMPLETE 动画循环播放完成。
  177. * @see http://edn.egret.com/cn/docs/page/596 MovieClip序列帧动画
  178. * @version Egret 2.4
  179. * @platform Web,Native
  180. * @includeExample extension/game/display/MovieClip.ts
  181. */
  182. var MovieClip = (function (_super) {
  183. __extends(MovieClip, _super);
  184. //Construct Function
  185. /**
  186. * 创建新的 MovieClip 实例。创建 MovieClip 之后,调用舞台上的显示对象容器的addElement方法。
  187. * @param movieClipData {movieClipData} 被引用的 movieClipData 对象
  188. * @version Egret 2.4
  189. * @platform Web,Native
  190. */
  191. function MovieClip(movieClipData) {
  192. var _this = _super.call(this) || this;
  193. //Render Property
  194. _this.$bitmapData = null;
  195. //Render Property
  196. _this.offsetPoint = egret.Point.create(0, 0);
  197. //Data Property
  198. _this.$movieClipData = null;
  199. /**
  200. * @private
  201. */
  202. _this.frames = null;
  203. /**
  204. * @private
  205. */
  206. _this.$totalFrames = 0;
  207. /**
  208. * @version Egret 2.4
  209. * @platform Web,Native
  210. * @private
  211. */
  212. _this.frameLabels = null;
  213. /**
  214. * @private
  215. */
  216. _this.$frameLabelStart = 0;
  217. /**
  218. * @private
  219. */
  220. _this.$frameLabelEnd = 0;
  221. /**
  222. * @version Egret 2.4
  223. * @platform Web,Native
  224. * @private
  225. */
  226. _this.frameEvents = null;
  227. /**
  228. * @private
  229. */
  230. _this.frameIntervalTime = 0;
  231. /**
  232. * @private
  233. */
  234. _this.$eventPool = null;
  235. //Animation Property
  236. _this.$isPlaying = false;
  237. /**
  238. * @private
  239. */
  240. _this.isStopped = true;
  241. /**
  242. * @private
  243. */
  244. _this.playTimes = 0;
  245. /**
  246. * @private
  247. */
  248. _this.$currentFrameNum = 0;
  249. /**
  250. * @private
  251. */
  252. _this.$nextFrameNum = 1;
  253. /**
  254. * @private
  255. */
  256. _this.displayedKeyFrameNum = 0;
  257. /**
  258. * @private
  259. */
  260. _this.passedTime = 0;
  261. /**
  262. * @private
  263. */
  264. _this.$frameRate = NaN;
  265. /**
  266. * @private
  267. */
  268. _this.lastTime = 0;
  269. _this.$smoothing = egret.Bitmap.defaultSmoothing;
  270. _this.$renderNode = new egret.sys.BitmapNode();
  271. _this.setMovieClipData(movieClipData);
  272. return _this;
  273. }
  274. Object.defineProperty(MovieClip.prototype, "smoothing", {
  275. /**
  276. * @language en_US
  277. * Whether or not is smoothed when scaled.
  278. * @version Egret 3.0
  279. * @platform Web
  280. */
  281. /**
  282. * @language zh_CN
  283. * 控制在缩放时是否进行平滑处理。
  284. * @version Egret 3.0
  285. * @platform Web
  286. */
  287. get: function () {
  288. return this.$smoothing;
  289. },
  290. set: function (value) {
  291. value = !!value;
  292. if (value == this.$smoothing) {
  293. return;
  294. }
  295. this.$smoothing = value;
  296. this.$invalidate();
  297. },
  298. enumerable: true,
  299. configurable: true
  300. });
  301. /**
  302. * @private
  303. *
  304. */
  305. MovieClip.prototype.$init = function () {
  306. this.$reset();
  307. var movieClipData = this.$movieClipData;
  308. if (movieClipData && movieClipData.$isDataValid()) {
  309. this.frames = movieClipData.frames;
  310. this.$totalFrames = movieClipData.numFrames;
  311. this.frameLabels = movieClipData.labels;
  312. this.frameEvents = movieClipData.events;
  313. this.$frameRate = movieClipData.frameRate;
  314. this.frameIntervalTime = 1000 / this.$frameRate;
  315. this._initFrame();
  316. }
  317. };
  318. /**
  319. * @private
  320. *
  321. */
  322. MovieClip.prototype.$reset = function () {
  323. this.frames = null;
  324. this.playTimes = 0;
  325. this.$isPlaying = false;
  326. this.setIsStopped(true);
  327. this.$currentFrameNum = 0;
  328. this.$nextFrameNum = 1;
  329. this.displayedKeyFrameNum = 0;
  330. this.passedTime = 0;
  331. this.$eventPool = [];
  332. };
  333. /**
  334. * @private
  335. *
  336. */
  337. MovieClip.prototype._initFrame = function () {
  338. if (this.$movieClipData.$isTextureValid()) {
  339. this.advanceFrame();
  340. this.constructFrame();
  341. }
  342. };
  343. /**
  344. * @private
  345. */
  346. MovieClip.prototype.$render = function () {
  347. var texture = this.$bitmapData;
  348. if (texture) {
  349. var offsetX = Math.round(this.offsetPoint.x);
  350. var offsetY = Math.round(this.offsetPoint.y);
  351. var bitmapWidth = texture._bitmapWidth;
  352. var bitmapHeight = texture._bitmapHeight;
  353. var textureWidth = texture.$getTextureWidth();
  354. var textureHeight = texture.$getTextureHeight();
  355. var destW = Math.round(texture.$getScaleBitmapWidth());
  356. var destH = Math.round(texture.$getScaleBitmapHeight());
  357. var sourceWidth = texture._sourceWidth;
  358. var sourceHeight = texture._sourceHeight;
  359. egret.sys.BitmapNode.$updateTextureData(this.$renderNode, texture._bitmapData, texture._bitmapX, texture._bitmapY, bitmapWidth, bitmapHeight, offsetX, offsetY, textureWidth, textureHeight, destW, destH, sourceWidth, sourceHeight, null, egret.BitmapFillMode.SCALE, this.$smoothing);
  360. }
  361. };
  362. /**
  363. * @private
  364. */
  365. MovieClip.prototype.$measureContentBounds = function (bounds) {
  366. var texture = this.$bitmapData;
  367. if (texture) {
  368. var x = this.offsetPoint.x;
  369. var y = this.offsetPoint.y;
  370. var w = texture.$getTextureWidth();
  371. var h = texture.$getTextureHeight();
  372. bounds.setTo(x, y, w, h);
  373. }
  374. else {
  375. bounds.setEmpty();
  376. }
  377. };
  378. /**
  379. * @private
  380. *
  381. * @param stage
  382. * @param nestLevel
  383. */
  384. MovieClip.prototype.$onAddToStage = function (stage, nestLevel) {
  385. _super.prototype.$onAddToStage.call(this, stage, nestLevel);
  386. if (this.$isPlaying && this.$totalFrames > 1) {
  387. this.setIsStopped(false);
  388. }
  389. };
  390. /**
  391. * @private
  392. *
  393. */
  394. MovieClip.prototype.$onRemoveFromStage = function () {
  395. _super.prototype.$onRemoveFromStage.call(this);
  396. this.setIsStopped(true);
  397. };
  398. //Data Function
  399. /**
  400. * @private
  401. * 返回帧标签为指定字符串的FrameLabel对象
  402. * @param labelName {string} 帧标签名
  403. * @param ignoreCase {boolean} 是否忽略大小写,可选参数,默认false
  404. * @returns {egret.FrameLabel} FrameLabel对象
  405. */
  406. MovieClip.prototype.getFrameLabelByName = function (labelName, ignoreCase) {
  407. if (ignoreCase === void 0) { ignoreCase = false; }
  408. if (ignoreCase) {
  409. labelName = labelName.toLowerCase();
  410. }
  411. var frameLabels = this.frameLabels;
  412. if (frameLabels) {
  413. var outputFramelabel = null;
  414. for (var i = 0; i < frameLabels.length; i++) {
  415. outputFramelabel = frameLabels[i];
  416. if (ignoreCase ? outputFramelabel.name.toLowerCase() == labelName : outputFramelabel.name == labelName) {
  417. return outputFramelabel;
  418. }
  419. }
  420. }
  421. return null;
  422. };
  423. /**
  424. * @private
  425. * 根据帧标签,设置开始和结束的帧数
  426. * @param labelName {string} 帧标签名
  427. */
  428. MovieClip.prototype.getFrameStartEnd = function (labelName) {
  429. var frameLabels = this.frameLabels;
  430. if (frameLabels) {
  431. var outputFramelabel = null;
  432. for (var i = 0; i < frameLabels.length; i++) {
  433. outputFramelabel = frameLabels[i];
  434. if (labelName == outputFramelabel.name) {
  435. this.$frameLabelStart = outputFramelabel.frame;
  436. this.$frameLabelEnd = outputFramelabel.end;
  437. break;
  438. }
  439. }
  440. }
  441. };
  442. /**
  443. * @private
  444. * 返回指定序号的帧的FrameLabel对象
  445. * @param frame {number} 帧序号
  446. * @returns {egret.FrameLabel} FrameLabel对象
  447. */
  448. MovieClip.prototype.getFrameLabelByFrame = function (frame) {
  449. var frameLabels = this.frameLabels;
  450. if (frameLabels) {
  451. var outputFramelabel = null;
  452. for (var i = 0; i < frameLabels.length; i++) {
  453. outputFramelabel = frameLabels[i];
  454. if (outputFramelabel.frame == frame) {
  455. return outputFramelabel;
  456. }
  457. }
  458. }
  459. return null;
  460. };
  461. /**
  462. * @private
  463. * 返回指定序号的帧对应的FrameLabel对象,如果当前帧没有标签,则返回前面最近的有标签的帧的FrameLabel对象
  464. * @method egret.MovieClip#getFrameLabelForFrame
  465. * @param frame {number} 帧序号
  466. * @returns {egret.FrameLabel} FrameLabel对象
  467. */
  468. MovieClip.prototype.getFrameLabelForFrame = function (frame) {
  469. var outputFrameLabel = null;
  470. var tempFrameLabel = null;
  471. var frameLabels = this.frameLabels;
  472. if (frameLabels) {
  473. for (var i = 0; i < frameLabels.length; i++) {
  474. tempFrameLabel = frameLabels[i];
  475. if (tempFrameLabel.frame > frame) {
  476. return outputFrameLabel;
  477. }
  478. outputFrameLabel = tempFrameLabel;
  479. }
  480. }
  481. return outputFrameLabel;
  482. };
  483. //Animation Function
  484. /**
  485. * 继续播放当前动画
  486. * @param playTimes {number} 播放次数。 参数为整数,可选参数,>=1:设定播放次数,<0:循环播放,默认值 0:不改变播放次数(MovieClip初始播放次数设置为1),
  487. * @version Egret 2.4
  488. * @platform Web,Native
  489. */
  490. MovieClip.prototype.play = function (playTimes) {
  491. if (playTimes === void 0) { playTimes = 0; }
  492. this.$isPlaying = true;
  493. this.setPlayTimes(playTimes);
  494. if (this.$totalFrames > 1 && this.$stage) {
  495. this.setIsStopped(false);
  496. }
  497. };
  498. /**
  499. * 暂停播放动画
  500. * @version Egret 2.4
  501. * @platform Web,Native
  502. */
  503. MovieClip.prototype.stop = function () {
  504. this.$isPlaying = false;
  505. this.setIsStopped(true);
  506. };
  507. /**
  508. * 将播放头移到前一帧并停止
  509. * @version Egret 2.4
  510. * @platform Web,Native
  511. */
  512. MovieClip.prototype.prevFrame = function () {
  513. this.gotoAndStop(this.$currentFrameNum - 1);
  514. };
  515. /**
  516. * 跳到后一帧并停止
  517. * @version Egret 2.4
  518. * @platform Web,Native
  519. */
  520. MovieClip.prototype.nextFrame = function () {
  521. this.gotoAndStop(this.$currentFrameNum + 1);
  522. };
  523. /**
  524. * 将播放头移到指定帧并播放
  525. * @param frame {any} 指定帧的帧号或帧标签
  526. * @param playTimes {number} 播放次数。 参数为整数,可选参数,>=1:设定播放次数,<0:循环播放,默认值 0:不改变播放次数,
  527. * @version Egret 2.4
  528. * @platform Web,Native
  529. */
  530. MovieClip.prototype.gotoAndPlay = function (frame, playTimes) {
  531. if (playTimes === void 0) { playTimes = 0; }
  532. if (arguments.length == 0 || arguments.length > 2) {
  533. egret.$error(1022, "MovieClip.gotoAndPlay()");
  534. }
  535. if (typeof frame === "string") {
  536. this.getFrameStartEnd(frame);
  537. }
  538. else {
  539. this.$frameLabelStart = 0;
  540. this.$frameLabelEnd = 0;
  541. }
  542. this.play(playTimes);
  543. this.gotoFrame(frame);
  544. };
  545. /**
  546. * 将播放头移到指定帧并停止
  547. * @param frame {any} 指定帧的帧号或帧标签
  548. * @version Egret 2.4
  549. * @platform Web,Native
  550. */
  551. MovieClip.prototype.gotoAndStop = function (frame) {
  552. if (arguments.length != 1) {
  553. egret.$error(1022, "MovieClip.gotoAndStop()");
  554. }
  555. this.stop();
  556. this.gotoFrame(frame);
  557. };
  558. /**
  559. * @private
  560. *
  561. * @param frame
  562. */
  563. MovieClip.prototype.gotoFrame = function (frame) {
  564. var frameNum;
  565. if (typeof frame === "string") {
  566. frameNum = this.getFrameLabelByName(frame).frame;
  567. }
  568. else {
  569. frameNum = parseInt(frame + '', 10);
  570. if (frameNum != frame) {
  571. egret.$error(1022, "Frame Label Not Found");
  572. }
  573. }
  574. if (frameNum < 1) {
  575. frameNum = 1;
  576. }
  577. else if (frameNum > this.$totalFrames) {
  578. frameNum = this.$totalFrames;
  579. }
  580. if (frameNum == this.$nextFrameNum) {
  581. return;
  582. }
  583. this.$nextFrameNum = frameNum;
  584. this.advanceFrame();
  585. this.constructFrame();
  586. this.handlePendingEvent();
  587. };
  588. /**
  589. * @private
  590. *
  591. * @param advancedTime
  592. * @returns
  593. */
  594. MovieClip.prototype.advanceTime = function (timeStamp) {
  595. var self = this;
  596. var advancedTime = timeStamp - self.lastTime;
  597. self.lastTime = timeStamp;
  598. var frameIntervalTime = self.frameIntervalTime;
  599. var currentTime = self.passedTime + advancedTime;
  600. self.passedTime = currentTime % frameIntervalTime;
  601. var num = currentTime / frameIntervalTime;
  602. if (num < 1) {
  603. return false;
  604. }
  605. while (num >= 1) {
  606. num--;
  607. self.$nextFrameNum++;
  608. if (self.$nextFrameNum > self.$totalFrames || (self.$frameLabelStart > 0 && self.$nextFrameNum > self.$frameLabelEnd)) {
  609. if (self.playTimes == -1) {
  610. self.$eventPool.push(egret.Event.LOOP_COMPLETE);
  611. self.$nextFrameNum = 1;
  612. }
  613. else {
  614. self.playTimes--;
  615. if (self.playTimes > 0) {
  616. self.$eventPool.push(egret.Event.LOOP_COMPLETE);
  617. self.$nextFrameNum = 1;
  618. }
  619. else {
  620. self.$nextFrameNum = self.$totalFrames;
  621. self.$eventPool.push(egret.Event.COMPLETE);
  622. self.stop();
  623. break;
  624. }
  625. }
  626. }
  627. if (self.$currentFrameNum == self.$frameLabelEnd) {
  628. self.$nextFrameNum = self.$frameLabelStart;
  629. }
  630. self.advanceFrame();
  631. }
  632. self.constructFrame();
  633. self.handlePendingEvent();
  634. return false;
  635. };
  636. /**
  637. * @private
  638. *
  639. */
  640. MovieClip.prototype.advanceFrame = function () {
  641. this.$currentFrameNum = this.$nextFrameNum;
  642. var event = this.frameEvents[this.$nextFrameNum];
  643. if (event && event != "") {
  644. egret.MovieClipEvent.dispatchMovieClipEvent(this, egret.MovieClipEvent.FRAME_LABEL, event);
  645. }
  646. };
  647. /**
  648. * @private
  649. *
  650. */
  651. MovieClip.prototype.constructFrame = function () {
  652. var currentFrameNum = this.$currentFrameNum;
  653. if (this.displayedKeyFrameNum == currentFrameNum) {
  654. return;
  655. }
  656. this.$bitmapData = this.$movieClipData.getTextureByFrame(currentFrameNum);
  657. this.$movieClipData.$getOffsetByFrame(currentFrameNum, this.offsetPoint);
  658. this.$invalidateContentBounds();
  659. this.displayedKeyFrameNum = currentFrameNum;
  660. };
  661. /**
  662. * @private
  663. *
  664. */
  665. MovieClip.prototype.$renderFrame = function () {
  666. this.$bitmapData = this.$movieClipData.getTextureByFrame(this.$currentFrameNum);
  667. this.$invalidateContentBounds();
  668. };
  669. /**
  670. * @private
  671. *
  672. */
  673. MovieClip.prototype.handlePendingEvent = function () {
  674. if (this.$eventPool.length != 0) {
  675. this.$eventPool.reverse();
  676. var eventPool = this.$eventPool;
  677. var length_1 = eventPool.length;
  678. var isComplete = false;
  679. var isLoopComplete = false;
  680. for (var i = 0; i < length_1; i++) {
  681. var event_1 = eventPool.pop();
  682. if (event_1 == egret.Event.LOOP_COMPLETE) {
  683. isLoopComplete = true;
  684. }
  685. else if (event_1 == egret.Event.COMPLETE) {
  686. isComplete = true;
  687. }
  688. else {
  689. this.dispatchEventWith(event_1);
  690. }
  691. }
  692. if (isLoopComplete) {
  693. this.dispatchEventWith(egret.Event.LOOP_COMPLETE);
  694. }
  695. if (isComplete) {
  696. this.dispatchEventWith(egret.Event.COMPLETE);
  697. }
  698. }
  699. };
  700. Object.defineProperty(MovieClip.prototype, "totalFrames", {
  701. //Properties
  702. /**
  703. * MovieClip 实例中帧的总数
  704. * @version Egret 2.4
  705. * @platform Web,Native
  706. */
  707. get: function () {
  708. return this.$totalFrames;
  709. },
  710. enumerable: true,
  711. configurable: true
  712. });
  713. Object.defineProperty(MovieClip.prototype, "currentFrame", {
  714. /**
  715. * MovieClip 实例当前播放的帧的序号
  716. * @version Egret 2.4
  717. * @platform Web,Native
  718. */
  719. get: function () {
  720. return this.$currentFrameNum;
  721. },
  722. enumerable: true,
  723. configurable: true
  724. });
  725. Object.defineProperty(MovieClip.prototype, "currentFrameLabel", {
  726. /**
  727. * MovieClip 实例当前播放的帧的标签。如果当前帧没有标签,则 currentFrameLabel返回null。
  728. * @version Egret 2.4
  729. * @platform Web,Native
  730. */
  731. get: function () {
  732. var label = this.getFrameLabelByFrame(this.$currentFrameNum);
  733. return label && label.name;
  734. },
  735. enumerable: true,
  736. configurable: true
  737. });
  738. Object.defineProperty(MovieClip.prototype, "currentLabel", {
  739. /**
  740. * 当前播放的帧对应的标签,如果当前帧没有标签,则currentLabel返回包含标签的先前帧的标签。如果当前帧和先前帧都不包含标签,currentLabel返回null。
  741. * @version Egret 2.4
  742. * @platform Web,Native
  743. */
  744. get: function () {
  745. var label = this.getFrameLabelForFrame(this.$currentFrameNum);
  746. return label ? label.name : null;
  747. },
  748. enumerable: true,
  749. configurable: true
  750. });
  751. Object.defineProperty(MovieClip.prototype, "frameRate", {
  752. /**
  753. * MovieClip 实例的帧频
  754. * @version Egret 2.4
  755. * @platform Web,Native
  756. */
  757. get: function () {
  758. return this.$frameRate;
  759. },
  760. set: function (value) {
  761. if (value == this.$frameRate) {
  762. return;
  763. }
  764. this.$frameRate = value;
  765. this.frameIntervalTime = 1000 / this.$frameRate;
  766. },
  767. enumerable: true,
  768. configurable: true
  769. });
  770. Object.defineProperty(MovieClip.prototype, "isPlaying", {
  771. /**
  772. * MovieClip 实例当前是否正在播放
  773. * @version Egret 2.4
  774. * @platform Web,Native
  775. */
  776. get: function () {
  777. return this.$isPlaying;
  778. },
  779. enumerable: true,
  780. configurable: true
  781. });
  782. Object.defineProperty(MovieClip.prototype, "movieClipData", {
  783. /**
  784. * @version Egret 2.4
  785. * @platform Web,Native
  786. */
  787. get: function () {
  788. return this.$movieClipData;
  789. },
  790. /**
  791. * MovieClip数据源
  792. */
  793. set: function (value) {
  794. this.setMovieClipData(value);
  795. },
  796. enumerable: true,
  797. configurable: true
  798. });
  799. /**
  800. * @private
  801. *
  802. * @param value
  803. */
  804. MovieClip.prototype.setMovieClipData = function (value) {
  805. if (this.$movieClipData == value) {
  806. return;
  807. }
  808. this.$movieClipData = value;
  809. this.$init();
  810. };
  811. /**
  812. * @private
  813. *
  814. * @param value
  815. */
  816. MovieClip.prototype.setPlayTimes = function (value) {
  817. if (value < 0 || value >= 1) {
  818. this.playTimes = value < 0 ? -1 : Math.floor(value);
  819. }
  820. };
  821. /**
  822. * @private
  823. *
  824. * @param value
  825. */
  826. MovieClip.prototype.setIsStopped = function (value) {
  827. if (this.isStopped == value) {
  828. return;
  829. }
  830. this.isStopped = value;
  831. if (value) {
  832. egret.sys.$ticker.$stopTick(this.advanceTime, this);
  833. }
  834. else {
  835. this.playTimes = this.playTimes == 0 ? 1 : this.playTimes;
  836. this.lastTime = egret.getTimer();
  837. egret.sys.$ticker.$startTick(this.advanceTime, this);
  838. }
  839. };
  840. return MovieClip;
  841. }(egret.DisplayObject));
  842. egret.MovieClip = MovieClip;
  843. __reflect(MovieClip.prototype, "egret.MovieClip");
  844. })(egret || (egret = {}));
  845. //////////////////////////////////////////////////////////////////////////////////////
  846. //
  847. // Copyright (c) 2014-present, Egret Technology.
  848. // All rights reserved.
  849. // Redistribution and use in source and binary forms, with or without
  850. // modification, are permitted provided that the following conditions are met:
  851. //
  852. // * Redistributions of source code must retain the above copyright
  853. // notice, this list of conditions and the following disclaimer.
  854. // * Redistributions in binary form must reproduce the above copyright
  855. // notice, this list of conditions and the following disclaimer in the
  856. // documentation and/or other materials provided with the distribution.
  857. // * Neither the name of the Egret nor the
  858. // names of its contributors may be used to endorse or promote products
  859. // derived from this software without specific prior written permission.
  860. //
  861. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  862. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  863. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  864. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  865. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  866. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  867. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  868. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  869. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  870. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  871. //
  872. //////////////////////////////////////////////////////////////////////////////////////
  873. var egret;
  874. (function (egret) {
  875. /**
  876. * @classdesc 使用 MovieClipData 类,您可以创建 MovieClip 对象和处理 MovieClip 对象的数据。MovieClipData 一般由MovieClipDataFactory生成
  877. * @see http://edn.egret.com/cn/docs/page/596 MovieClip序列帧动画
  878. * @version Egret 2.4
  879. * @platform Web,Native
  880. */
  881. var MovieClipData = (function (_super) {
  882. __extends(MovieClipData, _super);
  883. /**
  884. * 创建一个 egret.MovieClipData 对象
  885. * @version Egret 2.4
  886. * @platform Web,Native
  887. */
  888. function MovieClipData() {
  889. var _this = _super.call(this) || this;
  890. /**
  891. * @private
  892. * MovieClip数据
  893. */
  894. _this.$mcData = null;
  895. /**
  896. * 总帧数
  897. * @version Egret 2.4
  898. * @platform Web,Native
  899. */
  900. _this.numFrames = 1;
  901. /**
  902. * 帧数据列表
  903. * @version Egret 2.4
  904. * @platform Web,Native
  905. */
  906. _this.frames = [];
  907. /**
  908. * 帧标签列表
  909. * @version Egret 2.4
  910. * @platform Web,Native
  911. */
  912. _this.labels = null;
  913. /**
  914. * 帧事件列表
  915. * @version Egret 2.4
  916. * @platform Web,Native
  917. */
  918. _this.events = [];
  919. /**
  920. * 帧率
  921. * @version Egret 2.4
  922. * @platform Web,Native
  923. */
  924. _this.frameRate = 0;
  925. /**
  926. * 纹理数据
  927. * @version Egret 2.4
  928. * @platform Web,Native
  929. */
  930. _this.textureData = null;
  931. /**
  932. * 纹理集
  933. * @version Egret 2.4
  934. * @platform Web,Native
  935. */
  936. _this.spriteSheet = null;
  937. return _this;
  938. }
  939. /**
  940. * @private
  941. *
  942. * @param mcData
  943. * @param textureData
  944. * @param spriteSheet
  945. */
  946. MovieClipData.prototype.$init = function (mcData, textureData, spriteSheet) {
  947. this.textureData = textureData;
  948. this.spriteSheet = spriteSheet;
  949. this.setMCData(mcData);
  950. };
  951. /**
  952. * 根据指定帧序号获取该帧对应的关键帧数据
  953. * @param frame {number} 帧序号
  954. * @returns {any} 帧数据对象
  955. * @version Egret 2.4
  956. * @platform Web,Native
  957. */
  958. MovieClipData.prototype.getKeyFrameData = function (frame) {
  959. var outputFrameData = this.frames[frame - 1];
  960. if (outputFrameData.frame) {
  961. outputFrameData = this.frames[outputFrameData.frame - 1];
  962. }
  963. return outputFrameData;
  964. };
  965. /**
  966. * 根据指定帧序号获取该帧对应的Texture对象
  967. * @param frame {number} 帧序号
  968. * @returns {egret.Texture} Texture对象
  969. * @version Egret 2.4
  970. * @platform Web,Native
  971. */
  972. MovieClipData.prototype.getTextureByFrame = function (frame) {
  973. var frameData = this.getKeyFrameData(frame);
  974. if (frameData.res) {
  975. var outputTexture = this.getTextureByResName(frameData.res);
  976. return outputTexture;
  977. }
  978. return null;
  979. };
  980. MovieClipData.prototype.$getOffsetByFrame = function (frame, point) {
  981. var frameData = this.getKeyFrameData(frame);
  982. if (frameData.res) {
  983. point.setTo(frameData.x | 0, frameData.y | 0);
  984. }
  985. };
  986. /**
  987. * @private
  988. *
  989. * @param resName
  990. * @returns
  991. */
  992. MovieClipData.prototype.getTextureByResName = function (resName) {
  993. if (this.spriteSheet == null) {
  994. return null;
  995. }
  996. var texture = this.spriteSheet.getTexture(resName);
  997. if (!texture) {
  998. var textureData = this.textureData[resName];
  999. texture = this.spriteSheet.createTexture(resName, textureData.x, textureData.y, textureData.w, textureData.h);
  1000. }
  1001. return texture;
  1002. };
  1003. /**
  1004. * @private
  1005. *
  1006. * @returns
  1007. */
  1008. MovieClipData.prototype.$isDataValid = function () {
  1009. return this.frames.length > 0;
  1010. };
  1011. /**
  1012. * @private
  1013. *
  1014. * @returns
  1015. */
  1016. MovieClipData.prototype.$isTextureValid = function () {
  1017. return this.textureData != null && this.spriteSheet != null;
  1018. };
  1019. /**
  1020. * @private
  1021. *
  1022. * @param mcData
  1023. */
  1024. MovieClipData.prototype.$fillMCData = function (mcData) {
  1025. this.frameRate = mcData["frameRate"] || 24;
  1026. this.fillFramesData(mcData.frames);
  1027. this.fillFrameLabelsData(mcData.labels);
  1028. this.fillFrameEventsData(mcData.events);
  1029. };
  1030. /**
  1031. * @private
  1032. *
  1033. * @param framesData
  1034. */
  1035. MovieClipData.prototype.fillFramesData = function (framesData) {
  1036. var frames = this.frames;
  1037. var length = framesData ? framesData.length : 0;
  1038. var keyFramePosition;
  1039. for (var i = 0; i < length; i++) {
  1040. var frameData = framesData[i];
  1041. frames.push(frameData);
  1042. if (frameData.duration) {
  1043. var duration = parseInt(frameData.duration);
  1044. if (duration > 1) {
  1045. keyFramePosition = frames.length;
  1046. for (var j = 1; j < duration; j++) {
  1047. frames.push({ "frame": keyFramePosition });
  1048. }
  1049. }
  1050. }
  1051. }
  1052. this.numFrames = frames.length;
  1053. };
  1054. /**
  1055. * @private
  1056. *
  1057. * @param frameLabelsData
  1058. */
  1059. MovieClipData.prototype.fillFrameLabelsData = function (frameLabelsData) {
  1060. if (frameLabelsData) {
  1061. var length_2 = frameLabelsData.length;
  1062. if (length_2 > 0) {
  1063. this.labels = [];
  1064. for (var i = 0; i < length_2; i++) {
  1065. var label = frameLabelsData[i];
  1066. this.labels.push(new egret.FrameLabel(label.name, label.frame, label.end));
  1067. }
  1068. }
  1069. }
  1070. };
  1071. /**
  1072. * @private
  1073. *
  1074. * @param frameEventsData
  1075. */
  1076. MovieClipData.prototype.fillFrameEventsData = function (frameEventsData) {
  1077. if (frameEventsData) {
  1078. var length_3 = frameEventsData.length;
  1079. if (length_3 > 0) {
  1080. this.events = [];
  1081. for (var i = 0; i < length_3; i++) {
  1082. var events = frameEventsData[i];
  1083. this.events[events.frame] = events.name;
  1084. }
  1085. }
  1086. }
  1087. };
  1088. Object.defineProperty(MovieClipData.prototype, "mcData", {
  1089. /**
  1090. * @version Egret 2.4
  1091. * @platform Web,Native
  1092. */
  1093. get: function () {
  1094. return this.$mcData;
  1095. },
  1096. /**
  1097. * MovieClip数据源
  1098. */
  1099. set: function (value) {
  1100. this.setMCData(value);
  1101. },
  1102. enumerable: true,
  1103. configurable: true
  1104. });
  1105. /**
  1106. * @private
  1107. *
  1108. * @param value
  1109. */
  1110. MovieClipData.prototype.setMCData = function (value) {
  1111. if (this.$mcData == value) {
  1112. return;
  1113. }
  1114. this.$mcData = value;
  1115. if (value) {
  1116. this.$fillMCData(value);
  1117. }
  1118. };
  1119. return MovieClipData;
  1120. }(egret.HashObject));
  1121. egret.MovieClipData = MovieClipData;
  1122. __reflect(MovieClipData.prototype, "egret.MovieClipData");
  1123. })(egret || (egret = {}));
  1124. //////////////////////////////////////////////////////////////////////////////////////
  1125. //
  1126. // Copyright (c) 2014-present, Egret Technology.
  1127. // All rights reserved.
  1128. // Redistribution and use in source and binary forms, with or without
  1129. // modification, are permitted provided that the following conditions are met:
  1130. //
  1131. // * Redistributions of source code must retain the above copyright
  1132. // notice, this list of conditions and the following disclaimer.
  1133. // * Redistributions in binary form must reproduce the above copyright
  1134. // notice, this list of conditions and the following disclaimer in the
  1135. // documentation and/or other materials provided with the distribution.
  1136. // * Neither the name of the Egret nor the
  1137. // names of its contributors may be used to endorse or promote products
  1138. // derived from this software without specific prior written permission.
  1139. //
  1140. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  1141. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  1142. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  1143. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  1144. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  1145. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  1146. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  1147. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  1148. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  1149. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  1150. //
  1151. //////////////////////////////////////////////////////////////////////////////////////
  1152. var egret;
  1153. (function (egret) {
  1154. /**
  1155. * @classdesc 使用 MovieClipDataFactory 类,可以生成 MovieClipData 对象用于创建MovieClip
  1156. * @see http://edn.egret.com/cn/docs/page/596 MovieClip序列帧动画
  1157. * @version Egret 2.4
  1158. * @platform Web,Native
  1159. */
  1160. var MovieClipDataFactory = (function (_super) {
  1161. __extends(MovieClipDataFactory, _super);
  1162. /**
  1163. * 创建一个 egret.MovieClipDataFactory 对象
  1164. * @param movieClipDataSet {any} MovieClip数据集,该数据集必须由Egret官方工具生成
  1165. * @param texture {Texture} 纹理
  1166. * @version Egret 2.4
  1167. * @platform Web,Native
  1168. */
  1169. function MovieClipDataFactory(movieClipDataSet, texture) {
  1170. var _this = _super.call(this) || this;
  1171. /**
  1172. * 是否开启缓存
  1173. * @version Egret 2.4
  1174. * @platform Web,Native
  1175. */
  1176. _this.enableCache = true;
  1177. /**
  1178. * @private
  1179. */
  1180. _this.$mcDataCache = {};
  1181. _this.$mcDataSet = movieClipDataSet;
  1182. _this.setTexture(texture);
  1183. return _this;
  1184. }
  1185. /**
  1186. * 清空缓存
  1187. * @version Egret 2.4
  1188. * @platform Web,Native
  1189. */
  1190. MovieClipDataFactory.prototype.clearCache = function () {
  1191. this.$mcDataCache = {};
  1192. };
  1193. /**
  1194. * 根据名字生成一个MovieClipData实例。可以用于创建MovieClip。
  1195. * @param movieClipName {string} MovieClip名字. 可选参数,默认为"", 相当于取第一个MovieClip数据
  1196. * @returns {MovieClipData} 生成的MovieClipData对象
  1197. * @version Egret 2.4
  1198. * @platform Web,Native
  1199. */
  1200. MovieClipDataFactory.prototype.generateMovieClipData = function (movieClipName) {
  1201. if (movieClipName === void 0) { movieClipName = ""; }
  1202. if (movieClipName == "") {
  1203. if (this.$mcDataSet) {
  1204. for (movieClipName in this.$mcDataSet.mc) {
  1205. break;
  1206. }
  1207. }
  1208. }
  1209. if (movieClipName == "") {
  1210. return null;
  1211. }
  1212. var output = this.findFromCache(movieClipName, this.$mcDataCache);
  1213. if (!output) {
  1214. output = new egret.MovieClipData();
  1215. this.fillData(movieClipName, output, this.$mcDataCache);
  1216. }
  1217. return output;
  1218. };
  1219. /**
  1220. * @private
  1221. *
  1222. * @param movieClipName
  1223. * @param cache
  1224. * @returns
  1225. */
  1226. MovieClipDataFactory.prototype.findFromCache = function (movieClipName, cache) {
  1227. if (this.enableCache && cache[movieClipName]) {
  1228. return cache[movieClipName];
  1229. }
  1230. return null;
  1231. };
  1232. /**
  1233. * @private
  1234. *
  1235. * @param movieClipName
  1236. * @param movieClip
  1237. * @param cache
  1238. */
  1239. MovieClipDataFactory.prototype.fillData = function (movieClipName, movieClip, cache) {
  1240. if (this.$mcDataSet) {
  1241. var mcData = this.$mcDataSet.mc[movieClipName];
  1242. if (mcData) {
  1243. movieClip.$init(mcData, this.$mcDataSet.res, this.$spriteSheet);
  1244. if (this.enableCache) {
  1245. cache[movieClipName] = movieClip;
  1246. }
  1247. }
  1248. }
  1249. };
  1250. Object.defineProperty(MovieClipDataFactory.prototype, "mcDataSet", {
  1251. /**
  1252. * MovieClip数据集
  1253. * @version Egret 2.4
  1254. * @platform Web,Native
  1255. */
  1256. get: function () {
  1257. return this.$mcDataSet;
  1258. },
  1259. set: function (value) {
  1260. this.$mcDataSet = value;
  1261. },
  1262. enumerable: true,
  1263. configurable: true
  1264. });
  1265. Object.defineProperty(MovieClipDataFactory.prototype, "texture", {
  1266. /**
  1267. * MovieClip需要使用的纹理图
  1268. */
  1269. set: function (value) {
  1270. this.setTexture(value);
  1271. },
  1272. enumerable: true,
  1273. configurable: true
  1274. });
  1275. Object.defineProperty(MovieClipDataFactory.prototype, "spriteSheet", {
  1276. /**
  1277. * 由纹理图生成的精灵表
  1278. * @version Egret 2.4
  1279. * @platform Web,Native
  1280. */
  1281. get: function () {
  1282. return this.$spriteSheet;
  1283. },
  1284. enumerable: true,
  1285. configurable: true
  1286. });
  1287. /**
  1288. * @private
  1289. *
  1290. * @param value
  1291. */
  1292. MovieClipDataFactory.prototype.setTexture = function (value) {
  1293. this.$spriteSheet = value ? new egret.SpriteSheet(value) : null;
  1294. };
  1295. return MovieClipDataFactory;
  1296. }(egret.EventDispatcher));
  1297. egret.MovieClipDataFactory = MovieClipDataFactory;
  1298. __reflect(MovieClipDataFactory.prototype, "egret.MovieClipDataFactory");
  1299. })(egret || (egret = {}));
  1300. //////////////////////////////////////////////////////////////////////////////////////
  1301. //
  1302. // Copyright (c) 2014-present, Egret Technology.
  1303. // All rights reserved.
  1304. // Redistribution and use in source and binary forms, with or without
  1305. // modification, are permitted provided that the following conditions are met:
  1306. //
  1307. // * Redistributions of source code must retain the above copyright
  1308. // notice, this list of conditions and the following disclaimer.
  1309. // * Redistributions in binary form must reproduce the above copyright
  1310. // notice, this list of conditions and the following disclaimer in the
  1311. // documentation and/or other materials provided with the distribution.
  1312. // * Neither the name of the Egret nor the
  1313. // names of its contributors may be used to endorse or promote products
  1314. // derived from this software without specific prior written permission.
  1315. //
  1316. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  1317. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  1318. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  1319. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  1320. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  1321. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  1322. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  1323. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  1324. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  1325. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  1326. //
  1327. //////////////////////////////////////////////////////////////////////////////////////
  1328. var egret;
  1329. (function (egret) {
  1330. /**
  1331. * @language en_US
  1332. * When the movieClip's current frame have a frameLabel, dispatches MovieClipEvent object. FrameLabel Event type: MovieClipEvent.FRAME_LABEL
  1333. * @version Egret 2.4
  1334. * @platform Web,Native
  1335. */
  1336. /**
  1337. * @language zh_CN
  1338. * 当动画的当前帧有事件,将调度 MovieClipEvent 对象。帧事件类型 MovieClipEvent.FRAME_LABEL.
  1339. * @version Egret 2.4
  1340. * @platform Web,Native
  1341. */
  1342. var MovieClipEvent = (function (_super) {
  1343. __extends(MovieClipEvent, _super);
  1344. /**
  1345. * @language en_US
  1346. * TextEvent create an object that contains information about movieClip events.
  1347. * @param type Type of event, you can access the MovieClipEvent.type.
  1348. * @param bubbles Determines whether the Event object participates in the bubbling stage of the event flow. The default value is false.
  1349. * @param cancelable Determine whether the Event object can be canceled. The default value is false.
  1350. * @param frameLabel When the current frame have a frameLabel, the event listeners can access this information through the frameLabel property.
  1351. * @version Egret 2.4
  1352. * @platform Web,Native
  1353. */
  1354. /**
  1355. * @language zh_CN
  1356. * 创建一个 MovieClipEvent 对象,其中包含有关帧事件的信息。
  1357. * @param type 事件的类型,可以作为 MovieClipEvent.type 访问。
  1358. * @param bubbles 确定 Event 对象是否参与事件流的冒泡阶段。默认值为 false。
  1359. * @param cancelable 确定是否可以取消 Event 对象。默认值为 false。
  1360. * @param frameLabel 动画上的帧事件。事件侦听器可以通过 frameLabel 属性访问此信息。
  1361. * @version Egret 2.4
  1362. * @platform Web,Native
  1363. */
  1364. function MovieClipEvent(type, bubbles, cancelable, frameLabel) {
  1365. if (bubbles === void 0) { bubbles = false; }
  1366. if (cancelable === void 0) { cancelable = false; }
  1367. if (frameLabel === void 0) { frameLabel = null; }
  1368. var _this = _super.call(this, type, bubbles, cancelable) || this;
  1369. /**
  1370. * @language en_US
  1371. * In MovieClipEvent.FRAME_LABEL event, event corresponding string.
  1372. * @version Egret 2.4
  1373. * @platform Web,Native
  1374. */
  1375. /**
  1376. * @language zh_CN
  1377. * 在 MovieClipEvent.FRAME_LABEL 事件中,event对应的字符串。
  1378. * @version Egret 2.4
  1379. * @platform Web,Native
  1380. */
  1381. _this.frameLabel = null;
  1382. _this.frameLabel = frameLabel;
  1383. return _this;
  1384. }
  1385. /**
  1386. * @language en_US
  1387. * EventDispatcher object using the specified event object thrown MovieClipEvent. The objects will be thrown in the object cache pool for the next round robin.
  1388. * @param type The type of the event, accessible as Event.type.
  1389. * @param bubbles Determines whether the Event object participates in the bubbling stage of the event flow. The default value is false.
  1390. * @param frameLabel MovieClipEvent object frameLabel
  1391. * @version Egret 2.4
  1392. * @platform Web,Native
  1393. */
  1394. /**
  1395. * @language zh_CN
  1396. * 使用指定的EventDispatcher对象来抛出 MovieClipEvent 事件对象。抛出的对象将会缓存在对象池上,供下次循环复用。
  1397. * @param target 派发事件目标
  1398. * @param type 事件类型
  1399. * @param frameLabel MovieClipEvent 对象的 frameLabel 赋值
  1400. * @version Egret 2.4
  1401. * @platform Web,Native
  1402. */
  1403. MovieClipEvent.dispatchMovieClipEvent = function (target, type, frameLabel) {
  1404. if (frameLabel === void 0) { frameLabel = null; }
  1405. var event = egret.Event.create(MovieClipEvent, type);
  1406. event.frameLabel = frameLabel;
  1407. var result = target.dispatchEvent(event);
  1408. egret.Event.release(event);
  1409. return result;
  1410. };
  1411. return MovieClipEvent;
  1412. }(egret.Event));
  1413. /**
  1414. * @language en_US
  1415. * Dispatched whenever the current frame have a frameLabel.
  1416. * @version Egret 2.4
  1417. * @platform Web,Native
  1418. */
  1419. /**
  1420. * @language zh_CN
  1421. * 动画的当前帧上有事件时调度
  1422. * @version Egret 2.4
  1423. * @platform Web,Native
  1424. */
  1425. MovieClipEvent.FRAME_LABEL = "frame_label";
  1426. egret.MovieClipEvent = MovieClipEvent;
  1427. __reflect(MovieClipEvent.prototype, "egret.MovieClipEvent");
  1428. })(egret || (egret = {}));
  1429. //////////////////////////////////////////////////////////////////////////////////////
  1430. //
  1431. // Copyright (c) 2014-present, Egret Technology.
  1432. // All rights reserved.
  1433. // Redistribution and use in source and binary forms, with or without
  1434. // modification, are permitted provided that the following conditions are met:
  1435. //
  1436. // * Redistributions of source code must retain the above copyright
  1437. // notice, this list of conditions and the following disclaimer.
  1438. // * Redistributions in binary form must reproduce the above copyright
  1439. // notice, this list of conditions and the following disclaimer in the
  1440. // documentation and/or other materials provided with the distribution.
  1441. // * Neither the name of the Egret nor the
  1442. // names of its contributors may be used to endorse or promote products
  1443. // derived from this software without specific prior written permission.
  1444. //
  1445. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  1446. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  1447. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  1448. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  1449. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  1450. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  1451. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  1452. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  1453. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  1454. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  1455. //
  1456. //////////////////////////////////////////////////////////////////////////////////////
  1457. var egret;
  1458. (function (egret) {
  1459. /**
  1460. * @private
  1461. */
  1462. var ScrollEase = (function () {
  1463. /**
  1464. * @version Egret 2.4
  1465. * @platform Web,Native
  1466. */
  1467. function ScrollEase() {
  1468. egret.$error(1014);
  1469. }
  1470. /**
  1471. *
  1472. * @param amount
  1473. * @returns
  1474. * @version Egret 2.4
  1475. * @platform Web,Native
  1476. */
  1477. ScrollEase.get = function (amount) {
  1478. if (amount < -1) {
  1479. amount = -1;
  1480. }
  1481. if (amount > 1) {
  1482. amount = 1;
  1483. }
  1484. return function (t) {
  1485. if (amount == 0) {
  1486. return t;
  1487. }
  1488. if (amount < 0) {
  1489. return t * (t * -amount + 1 + amount);
  1490. }
  1491. return t * ((2 - t) * amount + (1 - amount));
  1492. };
  1493. };
  1494. /**
  1495. *
  1496. * @param pow
  1497. * @returns
  1498. * @version Egret 2.4
  1499. * @platform Web,Native
  1500. */
  1501. ScrollEase.getPowOut = function (pow) {
  1502. return function (t) {
  1503. return 1 - Math.pow(1 - t, pow);
  1504. };
  1505. };
  1506. return ScrollEase;
  1507. }());
  1508. /**
  1509. * @version Egret 2.4
  1510. * @platform Web,Native
  1511. */
  1512. ScrollEase.quintOut = ScrollEase.getPowOut(5);
  1513. /**
  1514. * @version Egret 2.4
  1515. * @platform Web,Native
  1516. */
  1517. ScrollEase.quartOut = ScrollEase.getPowOut(4);
  1518. egret.ScrollEase = ScrollEase;
  1519. __reflect(ScrollEase.prototype, "egret.ScrollEase");
  1520. /**
  1521. * @private
  1522. */
  1523. var ScrollTween = (function (_super) {
  1524. __extends(ScrollTween, _super);
  1525. /**
  1526. * 创建一个 egret.ScrollTween 对象
  1527. * @private
  1528. * @version Egret 2.4
  1529. * @platform Web,Native
  1530. */
  1531. function ScrollTween(target, props, pluginData) {
  1532. var _this = _super.call(this) || this;
  1533. /**
  1534. * @private
  1535. */
  1536. _this._target = null;
  1537. /**
  1538. * @private
  1539. */
  1540. _this._useTicks = false;
  1541. /**
  1542. * @private
  1543. */
  1544. _this.ignoreGlobalPause = false;
  1545. /**
  1546. * @private
  1547. */
  1548. _this.loop = false;
  1549. /**
  1550. * @private
  1551. */
  1552. _this.pluginData = null;
  1553. /**
  1554. * @private
  1555. */
  1556. _this._steps = null;
  1557. /**
  1558. * @private
  1559. */
  1560. _this._actions = null;
  1561. /**
  1562. * @private
  1563. */
  1564. _this.paused = false;
  1565. /**
  1566. * @private
  1567. */
  1568. _this.duration = 0;
  1569. /**
  1570. * @private
  1571. */
  1572. _this._prevPos = -1;
  1573. /**
  1574. * @private
  1575. */
  1576. _this.position = null;
  1577. /**
  1578. * @private
  1579. */
  1580. _this._prevPosition = 0;
  1581. /**
  1582. * @private
  1583. */
  1584. _this._stepPosition = 0;
  1585. /**
  1586. * @private
  1587. */
  1588. _this.passive = false;
  1589. _this.initialize(target, props, pluginData);
  1590. return _this;
  1591. }
  1592. /**
  1593. * @language en_US
  1594. * Activate an object and add a ScrollTween animation to the object
  1595. * @param target {any} The object to be activated
  1596. * @param props {any} Parameters, support loop onChange onChangeObj
  1597. * @param pluginData {any} Write realized
  1598. * @param override {boolean} Whether to remove the object before adding a tween, the default value false
  1599. * @version Egret 2.4
  1600. * @platform Web,Native
  1601. */
  1602. /**
  1603. * @language zh_CN
  1604. * 激活一个对象,对其添加 ScrollTween 动画
  1605. * @param target {any} 要激活 ScrollTween 的对象
  1606. * @param props {any} 参数,支持loop(循环播放) onChange(变化函数) onChangeObj(变化函数作用域)
  1607. * @param pluginData {any} 暂未实现
  1608. * @param override {boolean} 是否移除对象之前添加的tween,默认值false
  1609. * @version Egret 2.4
  1610. * @platform Web,Native
  1611. */
  1612. ScrollTween.get = function (target, props, pluginData, override) {
  1613. if (props === void 0) { props = null; }
  1614. if (pluginData === void 0) { pluginData = null; }
  1615. if (override === void 0) { override = false; }
  1616. if (override) {
  1617. ScrollTween.removeTweens(target);
  1618. }
  1619. return new ScrollTween(target, props, pluginData);
  1620. };
  1621. /**
  1622. * @language en_US
  1623. * Delete all ScrollTween animations from an object
  1624. * @param target The object whose ScrollTween to be deleted
  1625. * @version Egret 2.4
  1626. * @platform Web,Native
  1627. */
  1628. /**
  1629. * @language zh_CN
  1630. * 删除一个对象上的全部 ScrollTween 动画
  1631. * @param target 需要移除 ScrollTween 的对象
  1632. * @version Egret 2.4
  1633. * @platform Web,Native
  1634. */
  1635. ScrollTween.removeTweens = function (target) {
  1636. if (!target.tween_count) {
  1637. return;
  1638. }
  1639. var tweens = ScrollTween._tweens;
  1640. for (var i = tweens.length - 1; i >= 0; i--) {
  1641. if (tweens[i]._target == target) {
  1642. tweens[i].paused = true;
  1643. tweens.splice(i, 1);
  1644. }
  1645. }
  1646. target.tween_count = 0;
  1647. };
  1648. /**
  1649. * @private
  1650. *
  1651. * @param delta
  1652. * @param paused
  1653. */
  1654. ScrollTween.tick = function (timeStamp, paused) {
  1655. if (paused === void 0) { paused = false; }
  1656. var delta = timeStamp - ScrollTween._lastTime;
  1657. ScrollTween._lastTime = timeStamp;
  1658. var tweens = ScrollTween._tweens.concat();
  1659. for (var i = tweens.length - 1; i >= 0; i--) {
  1660. var tween = tweens[i];
  1661. if ((paused && !tween.ignoreGlobalPause) || tween.paused) {
  1662. continue;
  1663. }
  1664. tween.tick(tween._useTicks ? 1 : delta);
  1665. }
  1666. return false;
  1667. };
  1668. /**
  1669. * @private
  1670. *
  1671. * @param tween
  1672. * @param value
  1673. */
  1674. ScrollTween._register = function (tween, value) {
  1675. var target = tween._target;
  1676. var tweens = ScrollTween._tweens;
  1677. if (value) {
  1678. if (target) {
  1679. target.tween_count = target.tween_count > 0 ? target.tween_count + 1 : 1;
  1680. }
  1681. tweens.push(tween);
  1682. if (!ScrollTween._inited) {
  1683. ScrollTween._lastTime = egret.getTimer();
  1684. egret.sys.$ticker.$startTick(ScrollTween.tick, null);
  1685. ScrollTween._inited = true;
  1686. }
  1687. }
  1688. else {
  1689. if (target) {
  1690. target.tween_count--;
  1691. }
  1692. var i = tweens.length;
  1693. while (i--) {
  1694. if (tweens[i] == tween) {
  1695. tweens.splice(i, 1);
  1696. return;
  1697. }
  1698. }
  1699. }
  1700. };
  1701. /**
  1702. * @private
  1703. *
  1704. * @param target
  1705. * @param props
  1706. * @param pluginData
  1707. */
  1708. ScrollTween.prototype.initialize = function (target, props, pluginData) {
  1709. this._target = target;
  1710. if (props) {
  1711. this._useTicks = props.useTicks;
  1712. this.ignoreGlobalPause = props.ignoreGlobalPause;
  1713. this.loop = props.loop;
  1714. props.onChange && this.addEventListener("change", props.onChange, props.onChangeObj);
  1715. if (props.override) {
  1716. ScrollTween.removeTweens(target);
  1717. }
  1718. }
  1719. this.pluginData = pluginData || {};
  1720. this._curQueueProps = {};
  1721. this._initQueueProps = {};
  1722. this._steps = [];
  1723. this._actions = [];
  1724. if (props && props.paused) {
  1725. this.paused = true;
  1726. }
  1727. else {
  1728. ScrollTween._register(this, true);
  1729. }
  1730. if (props && props.position != null) {
  1731. this.setPosition(props.position);
  1732. }
  1733. };
  1734. /**
  1735. * @private
  1736. *
  1737. * @param value
  1738. * @param actionsMode
  1739. * @returns
  1740. */
  1741. ScrollTween.prototype.setPosition = function (value, actionsMode) {
  1742. if (actionsMode === void 0) { actionsMode = 1; }
  1743. if (value < 0) {
  1744. value = 0;
  1745. }
  1746. //正常化位置
  1747. var t = value;
  1748. var end = false;
  1749. if (t >= this.duration) {
  1750. if (this.loop) {
  1751. t = t % this.duration;
  1752. }
  1753. else {
  1754. t = this.duration;
  1755. end = true;
  1756. }
  1757. }
  1758. if (t == this._prevPos) {
  1759. return end;
  1760. }
  1761. var prevPos = this._prevPos;
  1762. this.position = this._prevPos = t;
  1763. this._prevPosition = value;
  1764. if (this._target) {
  1765. if (end) {
  1766. //结束
  1767. this._updateTargetProps(null, 1);
  1768. }
  1769. else if (this._steps.length > 0) {
  1770. // 找到新的tween
  1771. var i = void 0;
  1772. var l = this._steps.length;
  1773. for (i = 0; i < l; i++) {
  1774. if (this._steps[i].t > t) {
  1775. break;
  1776. }
  1777. }
  1778. var step = this._steps[i - 1];
  1779. this._updateTargetProps(step, (this._stepPosition = t - step.t) / step.d);
  1780. }
  1781. }
  1782. if (end) {
  1783. this.setPaused(true);
  1784. }
  1785. //执行actions
  1786. if (actionsMode != 0 && this._actions.length > 0) {
  1787. if (this._useTicks) {
  1788. this._runActions(t, t);
  1789. }
  1790. else if (actionsMode == 1 && t < prevPos) {
  1791. if (prevPos != this.duration) {
  1792. this._runActions(prevPos, this.duration);
  1793. }
  1794. this._runActions(0, t, true);
  1795. }
  1796. else {
  1797. this._runActions(prevPos, t);
  1798. }
  1799. }
  1800. this.dispatchEventWith("change");
  1801. return end;
  1802. };
  1803. /**
  1804. * @private
  1805. *
  1806. * @param startPos
  1807. * @param endPos
  1808. * @param includeStart
  1809. */
  1810. ScrollTween.prototype._runActions = function (startPos, endPos, includeStart) {
  1811. if (includeStart === void 0) { includeStart = false; }
  1812. var sPos = startPos;
  1813. var ePos = endPos;
  1814. var i = -1;
  1815. var j = this._actions.length;
  1816. var k = 1;
  1817. if (startPos > endPos) {
  1818. //把所有的倒置
  1819. sPos = endPos;
  1820. ePos = startPos;
  1821. i = j;
  1822. j = k = -1;
  1823. }
  1824. while ((i += k) != j) {
  1825. var action = this._actions[i];
  1826. var pos = action.t;
  1827. if (pos == ePos || (pos > sPos && pos < ePos) || (includeStart && pos == startPos)) {
  1828. action.f.apply(action.o, action.p);
  1829. }
  1830. }
  1831. };
  1832. /**
  1833. * @private
  1834. *
  1835. * @param step
  1836. * @param ratio
  1837. */
  1838. ScrollTween.prototype._updateTargetProps = function (step, ratio) {
  1839. var p0, p1, v, v0, v1, arr;
  1840. if (!step && ratio == 1) {
  1841. this.passive = false;
  1842. p0 = p1 = this._curQueueProps;
  1843. }
  1844. else {
  1845. this.passive = !!step.v;
  1846. //不更新props.
  1847. if (this.passive) {
  1848. return;
  1849. }
  1850. //使用ease
  1851. if (step.e) {
  1852. ratio = step.e(ratio, 0, 1, 1);
  1853. }
  1854. p0 = step.p0;
  1855. p1 = step.p1;
  1856. }
  1857. for (var n in this._initQueueProps) {
  1858. if ((v0 = p0[n]) == null) {
  1859. p0[n] = v0 = this._initQueueProps[n];
  1860. }
  1861. if ((v1 = p1[n]) == null) {
  1862. p1[n] = v1 = v0;
  1863. }
  1864. if (v0 == v1 || ratio == 0 || ratio == 1 || (typeof (v0) != "number")) {
  1865. v = ratio == 1 ? v1 : v0;
  1866. }
  1867. else {
  1868. v = v0 + (v1 - v0) * ratio;
  1869. }
  1870. var ignore = false;
  1871. if (arr = ScrollTween._plugins[n]) {
  1872. for (var i = 0, l = arr.length; i < l; i++) {
  1873. var v2 = arr[i].tween(this, n, v, p0, p1, ratio, !!step && p0 == p1, !step);
  1874. if (v2 == ScrollTween.IGNORE) {
  1875. ignore = true;
  1876. }
  1877. else {
  1878. v = v2;
  1879. }
  1880. }
  1881. }
  1882. if (!ignore) {
  1883. this._target[n] = v;
  1884. }
  1885. }
  1886. };
  1887. /**
  1888. * @language en_US
  1889. * Whether setting is paused
  1890. * @param value {boolean} Whether to pause
  1891. * @returns ScrollTween object itself
  1892. * @version Egret 2.4
  1893. * @platform Web,Native
  1894. */
  1895. /**
  1896. * @language zh_CN
  1897. * 设置是否暂停
  1898. * @param value {boolean} 是否暂停
  1899. * @returns Tween对象本身
  1900. * @version Egret 2.4
  1901. * @platform Web,Native
  1902. */
  1903. ScrollTween.prototype.setPaused = function (value) {
  1904. this.paused = value;
  1905. ScrollTween._register(this, !value);
  1906. return this;
  1907. };
  1908. /**
  1909. * @private
  1910. *
  1911. * @param props
  1912. * @returns
  1913. */
  1914. ScrollTween.prototype._cloneProps = function (props) {
  1915. var o = {};
  1916. for (var n in props) {
  1917. o[n] = props[n];
  1918. }
  1919. return o;
  1920. };
  1921. /**
  1922. * @private
  1923. *
  1924. * @param o
  1925. * @returns
  1926. */
  1927. ScrollTween.prototype._addStep = function (o) {
  1928. if (o.d > 0) {
  1929. this._steps.push(o);
  1930. o.t = this.duration;
  1931. this.duration += o.d;
  1932. }
  1933. return this;
  1934. };
  1935. /**
  1936. * @private
  1937. *
  1938. * @param o
  1939. * @returns
  1940. */
  1941. ScrollTween.prototype._appendQueueProps = function (o) {
  1942. var arr, oldValue, i, l, injectProps;
  1943. for (var n in o) {
  1944. if (this._initQueueProps[n] === undefined) {
  1945. oldValue = this._target[n];
  1946. //设置plugins
  1947. if (arr = ScrollTween._plugins[n]) {
  1948. for (i = 0, l = arr.length; i < l; i++) {
  1949. oldValue = arr[i].init(this, n, oldValue);
  1950. }
  1951. }
  1952. this._initQueueProps[n] = this._curQueueProps[n] = (oldValue === undefined) ? null : oldValue;
  1953. }
  1954. else {
  1955. oldValue = this._curQueueProps[n];
  1956. }
  1957. }
  1958. for (var n in o) {
  1959. oldValue = this._curQueueProps[n];
  1960. if (arr = ScrollTween._plugins[n]) {
  1961. injectProps = injectProps || {};
  1962. for (i = 0, l = arr.length; i < l; i++) {
  1963. if (arr[i].step) {
  1964. arr[i].step(this, n, oldValue, o[n], injectProps);
  1965. }
  1966. }
  1967. }
  1968. this._curQueueProps[n] = o[n];
  1969. }
  1970. if (injectProps) {
  1971. this._appendQueueProps(injectProps);
  1972. }
  1973. return this._curQueueProps;
  1974. };
  1975. /**
  1976. * @private
  1977. *
  1978. * @param o
  1979. * @returns
  1980. */
  1981. ScrollTween.prototype._addAction = function (o) {
  1982. o.t = this.duration;
  1983. this._actions.push(o);
  1984. return this;
  1985. };
  1986. /**
  1987. * @language en_US
  1988. * Modify the property of the specified display object to a specified value
  1989. * @param props {Object} Property set of an object
  1990. * @param duration {number} Duration
  1991. * @param ease {egret.ScrollEase} Easing algorithm
  1992. * @returns {egret.ScrollTween} ScrollTween object itself
  1993. * @version Egret 2.4
  1994. * @platform Web,Native
  1995. */
  1996. /**
  1997. * @language zh_CN
  1998. * 将指定显示对象的属性修改为指定值
  1999. * @param props {Object} 对象的属性集合
  2000. * @param duration {number} 持续时间
  2001. * @param ease {egret.ScrollEase} 缓动算法
  2002. * @returns {egret.ScrollTween} Tween对象本身
  2003. * @version Egret 2.4
  2004. * @platform Web,Native
  2005. */
  2006. ScrollTween.prototype.to = function (props, duration, ease) {
  2007. if (ease === void 0) { ease = undefined; }
  2008. if (isNaN(duration) || duration < 0) {
  2009. duration = 0;
  2010. }
  2011. return this._addStep({ d: duration || 0, p0: this._cloneProps(this._curQueueProps), e: ease, p1: this._cloneProps(this._appendQueueProps(props)) });
  2012. };
  2013. /**
  2014. * @language en_US
  2015. * Execute callback function
  2016. * @param callback {Function} Callback method
  2017. * @param thisObj {any} this action scope of the callback method
  2018. * @param params {any[]} Parameter of the callback method
  2019. * @returns {egret.ScrollTween} ScrollTween object itself
  2020. * @version Egret 2.4
  2021. * @platform Web,Native
  2022. */
  2023. /**
  2024. * @language zh_CN
  2025. * 执行回调函数
  2026. * @param callback {Function} 回调方法
  2027. * @param thisObj {any} 回调方法this作用域
  2028. * @param params {any[]} 回调方法参数
  2029. * @returns {egret.ScrollTween} Tween对象本身
  2030. * @version Egret 2.4
  2031. * @platform Web,Native
  2032. */
  2033. ScrollTween.prototype.call = function (callback, thisObj, params) {
  2034. if (thisObj === void 0) { thisObj = undefined; }
  2035. if (params === void 0) { params = undefined; }
  2036. return this._addAction({ f: callback, p: params ? params : [], o: thisObj ? thisObj : this._target });
  2037. };
  2038. /**
  2039. * @method egret.ScrollTween#tick
  2040. * @param delta {number}
  2041. * @private
  2042. * @version Egret 2.4
  2043. * @platform Web,Native
  2044. */
  2045. ScrollTween.prototype.tick = function (delta) {
  2046. if (this.paused) {
  2047. return;
  2048. }
  2049. this.setPosition(this._prevPosition + delta);
  2050. };
  2051. return ScrollTween;
  2052. }(egret.EventDispatcher));
  2053. /**
  2054. * @private
  2055. */
  2056. ScrollTween._tweens = [];
  2057. /**
  2058. * @private
  2059. */
  2060. ScrollTween.IGNORE = {};
  2061. /**
  2062. * @private
  2063. */
  2064. ScrollTween._plugins = {};
  2065. /**
  2066. * @private
  2067. */
  2068. ScrollTween._inited = false;
  2069. ScrollTween._lastTime = 0;
  2070. egret.ScrollTween = ScrollTween;
  2071. __reflect(ScrollTween.prototype, "egret.ScrollTween");
  2072. })(egret || (egret = {}));
  2073. //////////////////////////////////////////////////////////////////////////////////////
  2074. //
  2075. // Copyright (c) 2014-present, Egret Technology.
  2076. // All rights reserved.
  2077. // Redistribution and use in source and binary forms, with or without
  2078. // modification, are permitted provided that the following conditions are met:
  2079. //
  2080. // * Redistributions of source code must retain the above copyright
  2081. // notice, this list of conditions and the following disclaimer.
  2082. // * Redistributions in binary form must reproduce the above copyright
  2083. // notice, this list of conditions and the following disclaimer in the
  2084. // documentation and/or other materials provided with the distribution.
  2085. // * Neither the name of the Egret nor the
  2086. // names of its contributors may be used to endorse or promote products
  2087. // derived from this software without specific prior written permission.
  2088. //
  2089. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  2090. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  2091. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  2092. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  2093. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  2094. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  2095. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  2096. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  2097. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  2098. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  2099. //
  2100. //////////////////////////////////////////////////////////////////////////////////////
  2101. var egret;
  2102. (function (egret) {
  2103. /**
  2104. * @language en_US
  2105. * ScrollView auxiliary classes for slides, you will pass a display object constructor. It can display more than the range display object within the specified size range. And can easily drag in this range.
  2106. * @version Egret 2.4
  2107. * @platform Web,Native
  2108. * @includeExample extension/game/display/ScrollView.ts
  2109. */
  2110. /**
  2111. * @language zh_CN
  2112. * ScrollView 是用于滑动的辅助类,将一个显示对象传入构造函数即可。可以在指定的尺寸范围内显示超过该范围的显示对象。并可以在此范围内随意拖动。
  2113. * @version Egret 2.4
  2114. * @platform Web,Native
  2115. * @includeExample extension/game/display/ScrollView.ts
  2116. */
  2117. var ScrollView = (function (_super) {
  2118. __extends(ScrollView, _super);
  2119. /**
  2120. * @language en_US
  2121. * Create a egret.ScrollView objects
  2122. * @param content {egret.DisplayObject} You need to scroll object
  2123. * @version Egret 2.4
  2124. * @platform Web,Native
  2125. */
  2126. /**
  2127. * @language zh_CN
  2128. * 创建一个 egret.ScrollView 对象
  2129. * @param content {egret.DisplayObject} 需要滚动的对象
  2130. * @version Egret 2.4
  2131. * @platform Web,Native
  2132. */
  2133. function ScrollView(content) {
  2134. if (content === void 0) { content = null; }
  2135. var _this = _super.call(this) || this;
  2136. /**
  2137. * @language en_US
  2138. * Start rolling threshold when the touch point from the initial touch point at a distance exceeding this value will trigger roll
  2139. * @version Egret 2.4
  2140. * @platform Web,Native
  2141. */
  2142. /**
  2143. * @language zh_CN
  2144. * 开始滚动的阈值,当触摸点偏离初始触摸点的距离超过这个值时才会触发滚动
  2145. * @version Egret 2.4
  2146. * @platform Web,Native
  2147. */
  2148. _this.scrollBeginThreshold = 10;
  2149. /**
  2150. * @language en_US
  2151. * Scrolling speed, the speed is required and the default speed ratio.
  2152. * The range of scrollSpeed> 0 assigned to 2:00, the speed is 2 times the default speed
  2153. * @version Egret 2.4
  2154. * @platform Web,Native
  2155. */
  2156. /**
  2157. * @language zh_CN
  2158. * 滚动速度,这个值为需要的速度与默认速度的比值。
  2159. * 取值范围为 scrollSpeed > 0 赋值为 2 时,速度是默认速度的 2 倍
  2160. * @version Egret 2.4
  2161. * @platform Web,Native
  2162. */
  2163. _this.scrollSpeed = 1;
  2164. /**
  2165. * @private
  2166. */
  2167. _this._content = null;
  2168. /**
  2169. * @private
  2170. */
  2171. _this.delayTouchBeginEvent = null;
  2172. /**
  2173. * @private
  2174. */
  2175. _this.touchBeginTimer = null;
  2176. _this.touchEnabled = true;
  2177. _this._ScrV_Props_ = new egret.ScrollViewProperties();
  2178. if (content) {
  2179. _this.setContent(content);
  2180. }
  2181. return _this;
  2182. }
  2183. Object.defineProperty(ScrollView.prototype, "bounces", {
  2184. /**
  2185. * @language en_US
  2186. * Whether to enable rebound, rebound When enabled, ScrollView contents allowed to continue to drag the border after arriving at the end user drag operation, and then bounce back boundary position
  2187. * @default true
  2188. * @version Egret 2.4
  2189. */
  2190. /**
  2191. * @language zh_CN
  2192. * 是否启用回弹,当启用回弹后,ScrollView中内容在到达边界后允许继续拖动,在用户拖动操作结束后,再反弹回边界位置
  2193. * @default true
  2194. * @version Egret 2.4
  2195. */
  2196. get: function () {
  2197. return this._ScrV_Props_._bounces;
  2198. },
  2199. set: function (value) {
  2200. this._ScrV_Props_._bounces = !!value;
  2201. },
  2202. enumerable: true,
  2203. configurable: true
  2204. });
  2205. /**
  2206. * @language en_US
  2207. * Set to scroll object
  2208. * @param content {egret.DisplayObject} You need to scroll object
  2209. * @version Egret 2.4
  2210. * @platform Web,Native
  2211. */
  2212. /**
  2213. * @language zh_CN
  2214. * 设置需要滚动的对象
  2215. * @param content {egret.DisplayObject} 需要滚动的对象
  2216. * @version Egret 2.4
  2217. * @platform Web,Native
  2218. */
  2219. ScrollView.prototype.setContent = function (content) {
  2220. if (this._content === content)
  2221. return;
  2222. this.removeContent();
  2223. if (content) {
  2224. this._content = content;
  2225. _super.prototype.addChild.call(this, content);
  2226. this._addEvents();
  2227. }
  2228. };
  2229. /**
  2230. * @language en_US
  2231. * Remove rolling objects
  2232. * @version Egret 2.4
  2233. * @platform Web,Native
  2234. */
  2235. /**
  2236. * @language zh_CN
  2237. * 移除滚动的对象
  2238. * @version Egret 2.4
  2239. * @platform Web,Native
  2240. */
  2241. ScrollView.prototype.removeContent = function () {
  2242. if (this._content) {
  2243. this._removeEvents();
  2244. _super.prototype.removeChildAt.call(this, 0);
  2245. }
  2246. this._content = null;
  2247. };
  2248. Object.defineProperty(ScrollView.prototype, "verticalScrollPolicy", {
  2249. /**
  2250. * @language en_US
  2251. * Vertical scroll bar display policy, on / off / auto.
  2252. * @version Egret 2.4
  2253. * @platform Web,Native
  2254. */
  2255. /**
  2256. * @language zh_CN
  2257. * 垂直滚动条显示策略,on/off/auto。
  2258. * @version Egret 2.4
  2259. * @platform Web,Native
  2260. */
  2261. get: function () {
  2262. return this._ScrV_Props_._verticalScrollPolicy;
  2263. },
  2264. set: function (value) {
  2265. if (value == this._ScrV_Props_._verticalScrollPolicy)
  2266. return;
  2267. this._ScrV_Props_._verticalScrollPolicy = value;
  2268. },
  2269. enumerable: true,
  2270. configurable: true
  2271. });
  2272. Object.defineProperty(ScrollView.prototype, "horizontalScrollPolicy", {
  2273. /**
  2274. * @language en_US
  2275. * The horizontal scroll bar display policy, on / off / auto.
  2276. * @version Egret 2.4
  2277. * @platform Web,Native
  2278. */
  2279. /**
  2280. * @language zh_CN
  2281. * 水平滚动条显示策略,on/off/auto。
  2282. * @version Egret 2.4
  2283. * @platform Web,Native
  2284. */
  2285. get: function () {
  2286. return this._ScrV_Props_._horizontalScrollPolicy;
  2287. },
  2288. set: function (value) {
  2289. if (value == this._ScrV_Props_._horizontalScrollPolicy)
  2290. return;
  2291. this._ScrV_Props_._horizontalScrollPolicy = value;
  2292. },
  2293. enumerable: true,
  2294. configurable: true
  2295. });
  2296. Object.defineProperty(ScrollView.prototype, "scrollLeft", {
  2297. /**
  2298. * @language en_US
  2299. * Gets or sets the horizontal scroll position
  2300. * @returns {number}
  2301. * @version Egret 2.4
  2302. * @platform Web,Native
  2303. */
  2304. /**
  2305. * @language zh_CN
  2306. * 获取或设置水平滚动位置,
  2307. * @returns {number}
  2308. * @version Egret 2.4
  2309. * @platform Web,Native
  2310. */
  2311. get: function () {
  2312. return this._ScrV_Props_._scrollLeft;
  2313. },
  2314. set: function (value) {
  2315. if (value == this._ScrV_Props_._scrollLeft)
  2316. return;
  2317. this._ScrV_Props_._scrollLeft = value;
  2318. this._validatePosition(false, true);
  2319. this._updateContentPosition();
  2320. },
  2321. enumerable: true,
  2322. configurable: true
  2323. });
  2324. Object.defineProperty(ScrollView.prototype, "scrollTop", {
  2325. /**
  2326. * @language en_US
  2327. * Gets or sets the vertical scroll position
  2328. * @returns {number}
  2329. * @version Egret 2.4
  2330. * @platform Web,Native
  2331. */
  2332. /**
  2333. * @language zh_CN
  2334. * 获取或设置垂直滚动位置,
  2335. * @returns {number}
  2336. * @version Egret 2.4
  2337. * @platform Web,Native
  2338. */
  2339. get: function () {
  2340. return this._ScrV_Props_._scrollTop;
  2341. },
  2342. set: function (value) {
  2343. if (value == this._ScrV_Props_._scrollTop)
  2344. return;
  2345. this._ScrV_Props_._scrollTop = value;
  2346. this._validatePosition(true, false);
  2347. this._updateContentPosition();
  2348. },
  2349. enumerable: true,
  2350. configurable: true
  2351. });
  2352. /**
  2353. * @language en_US
  2354. * Set scroll position
  2355. * @param top {number} The vertical scroll position
  2356. * @param left {number} The horizontal scroll position
  2357. * @param isOffset {boolean} Optional parameter, the default is false, whether it is the amount of scrolling increase as top = 1 on behalf of one pixel scroll up
  2358. * @version Egret 2.4
  2359. * @platform Web,Native
  2360. */
  2361. /**
  2362. * @language zh_CN
  2363. * 设置滚动位置
  2364. * @param top {number} 垂直滚动位置
  2365. * @param left {number} 水平滚动位置
  2366. * @param isOffset {boolean} 可选参数,默认是false,是否是滚动增加量,如 top=1 代表往上滚动1像素
  2367. * @version Egret 2.4
  2368. * @platform Web,Native
  2369. */
  2370. ScrollView.prototype.setScrollPosition = function (top, left, isOffset) {
  2371. if (isOffset === void 0) { isOffset = false; }
  2372. if (isOffset && top == 0 && left == 0)
  2373. return;
  2374. if (!isOffset && this._ScrV_Props_._scrollTop == top
  2375. && this._ScrV_Props_._scrollLeft == left)
  2376. return;
  2377. var oldTop = this._ScrV_Props_._scrollTop, oldLeft = this._ScrV_Props_._scrollLeft;
  2378. if (isOffset) {
  2379. var maxLeft = this.getMaxScrollLeft();
  2380. var maxTop = this.getMaxScrollTop();
  2381. if (oldTop <= 0 || oldTop >= maxTop) {
  2382. top = top / 2;
  2383. }
  2384. if (oldLeft <= 0 || oldLeft >= maxLeft) {
  2385. left = left / 2;
  2386. }
  2387. var newTop = oldTop + top;
  2388. var newLeft = oldLeft + left;
  2389. //判断是否回弹
  2390. var bounces = this._ScrV_Props_._bounces;
  2391. if (!bounces) {
  2392. if (newTop <= 0 || newTop >= maxTop)
  2393. newTop = Math.max(0, Math.min(newTop, maxTop));
  2394. if (newLeft <= 0 || newLeft >= maxLeft)
  2395. newLeft = Math.max(0, Math.min(newLeft, maxLeft));
  2396. }
  2397. this._ScrV_Props_._scrollTop = newTop;
  2398. this._ScrV_Props_._scrollLeft = newLeft;
  2399. }
  2400. else {
  2401. this._ScrV_Props_._scrollTop = top;
  2402. this._ScrV_Props_._scrollLeft = left;
  2403. }
  2404. this._validatePosition(true, true);
  2405. this._updateContentPosition();
  2406. };
  2407. /**
  2408. * @private
  2409. *
  2410. * @param top
  2411. * @param left
  2412. */
  2413. ScrollView.prototype._validatePosition = function (top, left) {
  2414. if (top === void 0) { top = false; }
  2415. if (left === void 0) { left = false; }
  2416. if (top) {
  2417. var height = this.height;
  2418. var contentHeight = this._getContentHeight();
  2419. this._ScrV_Props_._scrollTop = Math.max(this._ScrV_Props_._scrollTop, (0 - height) / 2);
  2420. this._ScrV_Props_._scrollTop = Math.min(this._ScrV_Props_._scrollTop, contentHeight > height ? (contentHeight - height / 2) : height / 2);
  2421. }
  2422. if (left) {
  2423. var width = this.width;
  2424. var contentWidth = this._getContentWidth();
  2425. this._ScrV_Props_._scrollLeft = Math.max(this._ScrV_Props_._scrollLeft, (0 - width) / 2);
  2426. this._ScrV_Props_._scrollLeft = Math.min(this._ScrV_Props_._scrollLeft, contentWidth > width ? (contentWidth - width / 2) : width / 2);
  2427. }
  2428. };
  2429. /**
  2430. * @private
  2431. * @inheritDoc
  2432. */
  2433. ScrollView.prototype.$setWidth = function (value) {
  2434. if (this.$getExplicitWidth() == value) {
  2435. return false;
  2436. }
  2437. var result = _super.prototype.$setWidth.call(this, value);
  2438. this._updateContentPosition();
  2439. return result;
  2440. };
  2441. /**
  2442. * @private
  2443. * @inheritDoc
  2444. */
  2445. ScrollView.prototype.$setHeight = function (value) {
  2446. if (this.$getExplicitHeight() == value)
  2447. return false;
  2448. var result = _super.prototype.$setHeight.call(this, value);
  2449. this._updateContentPosition();
  2450. return true;
  2451. };
  2452. /**
  2453. * @private
  2454. *
  2455. */
  2456. ScrollView.prototype._updateContentPosition = function () {
  2457. var height = this.height;
  2458. var width = this.width;
  2459. //这里将坐标取整,避免有些浏览器精度低产生“黑线”问题
  2460. this.scrollRect = new egret.Rectangle(Math.round(this._ScrV_Props_._scrollLeft), Math.round(this._ScrV_Props_._scrollTop), width, height);
  2461. this.dispatchEvent(new egret.Event(egret.Event.CHANGE));
  2462. };
  2463. /**
  2464. * @private
  2465. *
  2466. * @returns
  2467. */
  2468. ScrollView.prototype._checkScrollPolicy = function () {
  2469. var hpolicy = this._ScrV_Props_._horizontalScrollPolicy;
  2470. var hCanScroll = this.__checkScrollPolicy(hpolicy, this._getContentWidth(), this.width);
  2471. this._ScrV_Props_._hCanScroll = hCanScroll;
  2472. var vpolicy = this._ScrV_Props_._verticalScrollPolicy;
  2473. var vCanScroll = this.__checkScrollPolicy(vpolicy, this._getContentHeight(), this.height);
  2474. this._ScrV_Props_._vCanScroll = vCanScroll;
  2475. return hCanScroll || vCanScroll;
  2476. };
  2477. /**
  2478. * @private
  2479. *
  2480. * @param policy
  2481. * @param contentLength
  2482. * @param viewLength
  2483. * @returns
  2484. */
  2485. ScrollView.prototype.__checkScrollPolicy = function (policy, contentLength, viewLength) {
  2486. if (policy == "on")
  2487. return true;
  2488. if (policy == "off")
  2489. return false;
  2490. return contentLength > viewLength;
  2491. };
  2492. /**
  2493. * @private
  2494. *
  2495. * @returns
  2496. */
  2497. ScrollView.prototype._addEvents = function () {
  2498. this.addEventListener(egret.TouchEvent.TOUCH_BEGIN, this._onTouchBegin, this);
  2499. this.addEventListener(egret.TouchEvent.TOUCH_BEGIN, this._onTouchBeginCapture, this, true);
  2500. this.addEventListener(egret.TouchEvent.TOUCH_END, this._onTouchEndCapture, this, true);
  2501. };
  2502. /**
  2503. * @private
  2504. *
  2505. * @returns
  2506. */
  2507. ScrollView.prototype._removeEvents = function () {
  2508. this.removeEventListener(egret.TouchEvent.TOUCH_BEGIN, this._onTouchBegin, this);
  2509. this.removeEventListener(egret.TouchEvent.TOUCH_BEGIN, this._onTouchBeginCapture, this, true);
  2510. this.removeEventListener(egret.TouchEvent.TOUCH_END, this._onTouchEndCapture, this, true);
  2511. };
  2512. /**
  2513. * @private
  2514. *
  2515. * @param e
  2516. */
  2517. ScrollView.prototype._onTouchBegin = function (e) {
  2518. if (e.$isDefaultPrevented) {
  2519. return;
  2520. }
  2521. var canScroll = this._checkScrollPolicy();
  2522. if (!canScroll) {
  2523. return;
  2524. }
  2525. this._ScrV_Props_._touchStartPosition.x = e.stageX;
  2526. this._ScrV_Props_._touchStartPosition.y = e.stageY;
  2527. if (this._ScrV_Props_._isHTweenPlaying || this._ScrV_Props_._isVTweenPlaying) {
  2528. this._onScrollFinished();
  2529. }
  2530. this._tempStage = this.stage;
  2531. this._tempStage.addEventListener(egret.TouchEvent.TOUCH_MOVE, this._onTouchMove, this);
  2532. this._tempStage.addEventListener(egret.TouchEvent.TOUCH_END, this._onTouchEnd, this);
  2533. this._tempStage.addEventListener(egret.TouchEvent.LEAVE_STAGE, this._onTouchEnd, this);
  2534. this.addEventListener(egret.Event.ENTER_FRAME, this._onEnterFrame, this);
  2535. this._logTouchEvent(e);
  2536. e.preventDefault();
  2537. };
  2538. /**
  2539. * @private
  2540. *
  2541. * @param event
  2542. */
  2543. ScrollView.prototype._onTouchBeginCapture = function (event) {
  2544. var canScroll = this._checkScrollPolicy();
  2545. if (!canScroll) {
  2546. return;
  2547. }
  2548. var target = event.target;
  2549. while (target != this) {
  2550. if ("_checkScrollPolicy" in target) {
  2551. canScroll = target._checkScrollPolicy();
  2552. if (canScroll) {
  2553. return;
  2554. }
  2555. }
  2556. target = target.parent;
  2557. }
  2558. event.stopPropagation();
  2559. var evt = this.cloneTouchEvent(event);
  2560. this.delayTouchBeginEvent = evt;
  2561. if (!this.touchBeginTimer) {
  2562. this.touchBeginTimer = new egret.Timer(100, 1);
  2563. this.touchBeginTimer.addEventListener(egret.TimerEvent.TIMER_COMPLETE, this._onTouchBeginTimer, this);
  2564. }
  2565. this.touchBeginTimer.start();
  2566. this._onTouchBegin(event);
  2567. };
  2568. /**
  2569. * @private
  2570. *
  2571. * @param event
  2572. * @returns
  2573. */
  2574. ScrollView.prototype._onTouchEndCapture = function (event) {
  2575. var _this = this;
  2576. if (!this.delayTouchBeginEvent) {
  2577. return;
  2578. }
  2579. this._onTouchBeginTimer();
  2580. event.stopPropagation();
  2581. var evt = this.cloneTouchEvent(event);
  2582. egret.callLater(function () {
  2583. if (_this.stage) {
  2584. _this.dispatchPropagationEvent(evt);
  2585. }
  2586. }, this);
  2587. };
  2588. /**
  2589. * @private
  2590. *
  2591. */
  2592. ScrollView.prototype._onTouchBeginTimer = function () {
  2593. this.touchBeginTimer.stop();
  2594. var event = this.delayTouchBeginEvent;
  2595. this.delayTouchBeginEvent = null;
  2596. //Dispatch event only if the scroll view is still on the stage
  2597. if (this.stage)
  2598. this.dispatchPropagationEvent(event);
  2599. };
  2600. /**
  2601. * @private
  2602. *
  2603. * @param event
  2604. * @returns
  2605. */
  2606. ScrollView.prototype.dispatchPropagationEvent = function (event) {
  2607. var target = event.$target;
  2608. var list = this.$getPropagationList(target);
  2609. var length = list.length;
  2610. var targetIndex = list.length * 0.5;
  2611. var startIndex = -1;
  2612. for (var i = 0; i < length; i++) {
  2613. if (list[i] === this._content) {
  2614. startIndex = i;
  2615. break;
  2616. }
  2617. }
  2618. list.splice(0, startIndex + 1);
  2619. targetIndex -= startIndex + 1;
  2620. this.$dispatchPropagationEvent(event, list, targetIndex);
  2621. egret.Event.release(event);
  2622. };
  2623. /**
  2624. * @private
  2625. *
  2626. * @param event
  2627. * @returns
  2628. */
  2629. ScrollView.prototype._onTouchMove = function (event) {
  2630. if (this._ScrV_Props_._lastTouchPosition.x == event.stageX && this._ScrV_Props_._lastTouchPosition.y == event.stageY)
  2631. return;
  2632. if (!this._ScrV_Props_._scrollStarted) {
  2633. var x = event.stageX - this._ScrV_Props_._touchStartPosition.x, y = event.stageY - this._ScrV_Props_._touchStartPosition.y;
  2634. var distance = Math.sqrt(x * x + y * y);
  2635. if (distance < this.scrollBeginThreshold) {
  2636. this._logTouchEvent(event);
  2637. return;
  2638. }
  2639. }
  2640. this._ScrV_Props_._scrollStarted = true;
  2641. if (this.delayTouchBeginEvent) {
  2642. this.delayTouchBeginEvent = null;
  2643. this.touchBeginTimer.stop();
  2644. }
  2645. this.touchChildren = false;
  2646. var offset = this._getPointChange(event);
  2647. this.setScrollPosition(offset.y, offset.x, true);
  2648. this._calcVelocitys(event);
  2649. this._logTouchEvent(event);
  2650. };
  2651. /**
  2652. * @private
  2653. *
  2654. * @param event
  2655. * @returns
  2656. */
  2657. ScrollView.prototype._onTouchEnd = function (event) {
  2658. this.touchChildren = true;
  2659. this._ScrV_Props_._scrollStarted = false;
  2660. this._tempStage.removeEventListener(egret.TouchEvent.TOUCH_MOVE, this._onTouchMove, this);
  2661. this._tempStage.removeEventListener(egret.TouchEvent.TOUCH_END, this._onTouchEnd, this);
  2662. this._tempStage.removeEventListener(egret.TouchEvent.LEAVE_STAGE, this._onTouchEnd, this);
  2663. this.removeEventListener(egret.Event.ENTER_FRAME, this._onEnterFrame, this);
  2664. this._moveAfterTouchEnd();
  2665. };
  2666. /**
  2667. * @private
  2668. *
  2669. * @param event
  2670. * @returns
  2671. */
  2672. ScrollView.prototype._onEnterFrame = function (event) {
  2673. var time = egret.getTimer();
  2674. if (time - this._ScrV_Props_._lastTouchTime > 100 && time - this._ScrV_Props_._lastTouchTime < 300) {
  2675. this._calcVelocitys(this._ScrV_Props_._lastTouchEvent);
  2676. }
  2677. };
  2678. /**
  2679. * @private
  2680. *
  2681. * @param e
  2682. * @returns
  2683. */
  2684. ScrollView.prototype._logTouchEvent = function (e) {
  2685. this._ScrV_Props_._lastTouchPosition.x = e.stageX;
  2686. this._ScrV_Props_._lastTouchPosition.y = e.stageY;
  2687. this._ScrV_Props_._lastTouchEvent = this.cloneTouchEvent(e);
  2688. this._ScrV_Props_._lastTouchTime = egret.getTimer();
  2689. };
  2690. /**
  2691. * @private
  2692. *
  2693. * @param e
  2694. * @returns
  2695. */
  2696. ScrollView.prototype._getPointChange = function (e) {
  2697. return {
  2698. x: this._ScrV_Props_._hCanScroll === false ? 0 : (this._ScrV_Props_._lastTouchPosition.x - e.stageX),
  2699. y: this._ScrV_Props_._vCanScroll === false ? 0 : (this._ScrV_Props_._lastTouchPosition.y - e.stageY)
  2700. };
  2701. };
  2702. /**
  2703. * @private
  2704. *
  2705. * @param e
  2706. * @returns
  2707. */
  2708. ScrollView.prototype._calcVelocitys = function (e) {
  2709. var time = egret.getTimer();
  2710. if (this._ScrV_Props_._lastTouchTime == 0) {
  2711. this._ScrV_Props_._lastTouchTime = time;
  2712. return;
  2713. }
  2714. var change = this._getPointChange(e);
  2715. var timeoffset = time - this._ScrV_Props_._lastTouchTime;
  2716. change.x /= timeoffset;
  2717. change.y /= timeoffset;
  2718. this._ScrV_Props_._velocitys.push(change);
  2719. if (this._ScrV_Props_._velocitys.length > 5)
  2720. this._ScrV_Props_._velocitys.shift();
  2721. this._ScrV_Props_._lastTouchPosition.x = e.stageX;
  2722. this._ScrV_Props_._lastTouchPosition.y = e.stageY;
  2723. };
  2724. /**
  2725. * @private
  2726. *
  2727. * @returns
  2728. */
  2729. ScrollView.prototype._getContentWidth = function () {
  2730. return this._content.$getExplicitWidth() || this._content.width;
  2731. };
  2732. /**
  2733. * @private
  2734. *
  2735. * @returns
  2736. */
  2737. ScrollView.prototype._getContentHeight = function () {
  2738. return this._content.$getExplicitHeight() || this._content.height;
  2739. };
  2740. /**
  2741. * @language en_US
  2742. * The left side of the maximum distance
  2743. * @returns The left side of the maximum distance
  2744. * @version Egret 2.4
  2745. * @platform Web,Native
  2746. */
  2747. /**
  2748. * @language zh_CN
  2749. * 距离左侧的最大值
  2750. * @returns 距离左侧最大值
  2751. * @version Egret 2.4
  2752. * @platform Web,Native
  2753. */
  2754. ScrollView.prototype.getMaxScrollLeft = function () {
  2755. var max = this._getContentWidth() - this.width;
  2756. return Math.max(0, max);
  2757. };
  2758. /**
  2759. * @language en_US
  2760. * Above the maximum distance
  2761. * @returns Above the maximum distance
  2762. * @version Egret 2.4
  2763. * @platform Web,Native
  2764. */
  2765. /**
  2766. * @language zh_CN
  2767. * 距离上方最大值
  2768. * @returns 距离上方最大值
  2769. * @version Egret 2.4
  2770. * @platform Web,Native
  2771. */
  2772. ScrollView.prototype.getMaxScrollTop = function () {
  2773. var max = this._getContentHeight() - this.height;
  2774. return Math.max(0, max);
  2775. };
  2776. /**
  2777. * @private
  2778. *
  2779. */
  2780. ScrollView.prototype._moveAfterTouchEnd = function () {
  2781. if (this._ScrV_Props_._velocitys.length == 0)
  2782. return;
  2783. var sum = { x: 0, y: 0 }, totalW = 0;
  2784. for (var i = 0; i < this._ScrV_Props_._velocitys.length; i++) {
  2785. var v = this._ScrV_Props_._velocitys[i];
  2786. var w = ScrollView.weight[i];
  2787. sum.x += v.x * w;
  2788. sum.y += v.y * w;
  2789. totalW += w;
  2790. }
  2791. this._ScrV_Props_._velocitys.length = 0;
  2792. if (this.scrollSpeed <= 0)
  2793. this.scrollSpeed = 1;
  2794. var x = sum.x / totalW * this.scrollSpeed, y = sum.y / totalW * this.scrollSpeed;
  2795. var pixelsPerMSX = Math.abs(x), pixelsPerMSY = Math.abs(y);
  2796. var maxLeft = this.getMaxScrollLeft();
  2797. var maxTop = this.getMaxScrollTop();
  2798. var datax = pixelsPerMSX > 0.02 ? this.getAnimationDatas(x, this._ScrV_Props_._scrollLeft, maxLeft) : {
  2799. position: this._ScrV_Props_._scrollLeft,
  2800. duration: 1
  2801. };
  2802. var datay = pixelsPerMSY > 0.02 ? this.getAnimationDatas(y, this._ScrV_Props_._scrollTop, maxTop) : {
  2803. position: this._ScrV_Props_._scrollTop,
  2804. duration: 1
  2805. };
  2806. this.setScrollLeft(datax.position, datax.duration);
  2807. this.setScrollTop(datay.position, datay.duration);
  2808. };
  2809. /**
  2810. * @private
  2811. *
  2812. * @param tw
  2813. */
  2814. ScrollView.prototype.onTweenFinished = function (tw) {
  2815. if (tw == this._ScrV_Props_._vScrollTween)
  2816. this._ScrV_Props_._isVTweenPlaying = false;
  2817. if (tw == this._ScrV_Props_._hScrollTween)
  2818. this._ScrV_Props_._isHTweenPlaying = false;
  2819. if (this._ScrV_Props_._isHTweenPlaying == false && this._ScrV_Props_._isVTweenPlaying == false) {
  2820. this._onScrollFinished();
  2821. }
  2822. };
  2823. /**
  2824. * @private
  2825. *
  2826. * @returns
  2827. */
  2828. ScrollView.prototype._onScrollStarted = function () {
  2829. };
  2830. /**
  2831. * @private
  2832. *
  2833. * @returns
  2834. */
  2835. ScrollView.prototype._onScrollFinished = function () {
  2836. egret.ScrollTween.removeTweens(this);
  2837. this._ScrV_Props_._hScrollTween = null;
  2838. this._ScrV_Props_._vScrollTween = null;
  2839. this._ScrV_Props_._isHTweenPlaying = false;
  2840. this._ScrV_Props_._isVTweenPlaying = false;
  2841. this.dispatchEvent(new egret.Event(egret.Event.COMPLETE));
  2842. };
  2843. /**
  2844. * @language en_US
  2845. * Set the scroll position above the distance
  2846. * @param scrollTop Position above distance
  2847. * @param duration Easing of time, in milliseconds
  2848. * @returns Get tween vertical scrolling
  2849. * @version Egret 2.4
  2850. * @platform Web,Native
  2851. */
  2852. /**
  2853. * @language zh_CN
  2854. * 设置滚动距离上方的位置
  2855. * @param scrollTop 距离上方的位置
  2856. * @param duration 缓动时间,毫秒单位
  2857. * @returns 获取垂直滚动的tween
  2858. * @version Egret 2.4
  2859. * @platform Web,Native
  2860. */
  2861. ScrollView.prototype.setScrollTop = function (scrollTop, duration) {
  2862. if (duration === void 0) { duration = 0; }
  2863. var finalPosition = Math.min(this.getMaxScrollTop(), Math.max(scrollTop, 0));
  2864. if (duration == 0) {
  2865. this.scrollTop = finalPosition;
  2866. return;
  2867. }
  2868. if (this._ScrV_Props_._bounces == false)
  2869. scrollTop = finalPosition;
  2870. var vtween = egret.ScrollTween.get(this).to({ scrollTop: scrollTop }, duration, egret.ScrollEase.quartOut);
  2871. if (finalPosition != scrollTop) {
  2872. vtween.to({ scrollTop: finalPosition }, 300, egret.ScrollEase.quintOut);
  2873. }
  2874. this._ScrV_Props_._isVTweenPlaying = true;
  2875. this._ScrV_Props_._vScrollTween = vtween;
  2876. vtween.call(this.onTweenFinished, this, [vtween]);
  2877. if (!this._ScrV_Props_._isHTweenPlaying)
  2878. this._onScrollStarted();
  2879. };
  2880. /**
  2881. * @language en_US
  2882. * Set the scroll position from the left side
  2883. * @param scrollLeft From the position on the left side
  2884. * @param duration Get tween vertical scrolling
  2885. * @returns Gets the horizontal scroll tween
  2886. * @version Egret 2.4
  2887. * @platform Web,Native
  2888. */
  2889. /**
  2890. * @language zh_CN
  2891. * 设置滚动距离左侧的位置
  2892. * @param scrollLeft 距离左侧的位置
  2893. * @param duration 缓动时间,毫秒单位
  2894. * @returns 获取水平滚动的tween
  2895. * @version Egret 2.4
  2896. * @platform Web,Native
  2897. */
  2898. ScrollView.prototype.setScrollLeft = function (scrollLeft, duration) {
  2899. if (duration === void 0) { duration = 0; }
  2900. var finalPosition = Math.min(this.getMaxScrollLeft(), Math.max(scrollLeft, 0));
  2901. if (duration == 0) {
  2902. this.scrollLeft = finalPosition;
  2903. return;
  2904. }
  2905. if (this._ScrV_Props_._bounces == false)
  2906. scrollLeft = finalPosition;
  2907. var htween = egret.ScrollTween.get(this).to({ scrollLeft: scrollLeft }, duration, egret.ScrollEase.quartOut);
  2908. if (finalPosition != scrollLeft) {
  2909. htween.to({ scrollLeft: finalPosition }, 300, egret.ScrollEase.quintOut);
  2910. }
  2911. this._ScrV_Props_._isHTweenPlaying = true;
  2912. this._ScrV_Props_._hScrollTween = htween;
  2913. htween.call(this.onTweenFinished, this, [htween]);
  2914. if (!this._ScrV_Props_._isVTweenPlaying)
  2915. this._onScrollStarted();
  2916. };
  2917. /**
  2918. * @private
  2919. *
  2920. * @param pixelsPerMS
  2921. * @param curPos
  2922. * @param maxPos
  2923. * @returns
  2924. */
  2925. ScrollView.prototype.getAnimationDatas = function (pixelsPerMS, curPos, maxPos) {
  2926. var absPixelsPerMS = Math.abs(pixelsPerMS);
  2927. var extraFricition = 0.95;
  2928. var duration = 0;
  2929. var friction = 0.998;
  2930. var minVelocity = 0.02;
  2931. var posTo = curPos + pixelsPerMS * 500;
  2932. if (posTo < 0 || posTo > maxPos) {
  2933. posTo = curPos;
  2934. while (Math.abs(pixelsPerMS) != Infinity && Math.abs(pixelsPerMS) > minVelocity) {
  2935. posTo += pixelsPerMS;
  2936. if (posTo < 0 || posTo > maxPos) {
  2937. pixelsPerMS *= friction * extraFricition;
  2938. }
  2939. else {
  2940. pixelsPerMS *= friction;
  2941. }
  2942. duration++;
  2943. }
  2944. }
  2945. else {
  2946. duration = -Math.log(minVelocity / absPixelsPerMS) * 500;
  2947. }
  2948. var result = {
  2949. position: Math.min(maxPos + 50, Math.max(posTo, -50)),
  2950. duration: duration
  2951. };
  2952. return result;
  2953. };
  2954. /**
  2955. * @private
  2956. *
  2957. * @param event
  2958. * @returns
  2959. */
  2960. ScrollView.prototype.cloneTouchEvent = function (event) {
  2961. var evt = new egret.TouchEvent(event.type, event.bubbles, event.cancelable);
  2962. evt.touchPointID = event.touchPointID;
  2963. evt.$stageX = event.stageX;
  2964. evt.$stageY = event.stageY;
  2965. //evt.ctrlKey = event.ctrlKey;
  2966. //evt.altKey = event.altKey;
  2967. //evt.shiftKey = event.shiftKey;
  2968. evt.touchDown = event.touchDown;
  2969. evt.$isDefaultPrevented = false;
  2970. evt.$target = event.target;
  2971. return evt;
  2972. };
  2973. /**
  2974. * @private
  2975. *
  2976. * @returns
  2977. */
  2978. ScrollView.prototype.throwNotSupportedError = function () {
  2979. egret.$error(1023);
  2980. };
  2981. /**
  2982. * @deprecated
  2983. * @inheritDoc
  2984. * @inheritDoc
  2985. * @version Egret 2.4
  2986. * @platform Web,Native
  2987. */
  2988. ScrollView.prototype.addChild = function (child) {
  2989. this.throwNotSupportedError();
  2990. return null;
  2991. };
  2992. /**
  2993. * @deprecated
  2994. * @inheritDoc
  2995. * @version Egret 2.4
  2996. * @platform Web,Native
  2997. */
  2998. ScrollView.prototype.addChildAt = function (child, index) {
  2999. this.throwNotSupportedError();
  3000. return null;
  3001. };
  3002. /**
  3003. * @deprecated
  3004. * @inheritDoc
  3005. * @version Egret 2.4
  3006. * @platform Web,Native
  3007. */
  3008. ScrollView.prototype.removeChild = function (child) {
  3009. this.throwNotSupportedError();
  3010. return null;
  3011. };
  3012. /**
  3013. * @deprecated
  3014. * @inheritDoc
  3015. * @version Egret 2.4
  3016. * @platform Web,Native
  3017. */
  3018. ScrollView.prototype.removeChildAt = function (index) {
  3019. this.throwNotSupportedError();
  3020. return null;
  3021. };
  3022. /**
  3023. * @deprecated
  3024. * @inheritDoc
  3025. * @version Egret 2.4
  3026. * @platform Web,Native
  3027. */
  3028. ScrollView.prototype.setChildIndex = function (child, index) {
  3029. this.throwNotSupportedError();
  3030. };
  3031. /**
  3032. * @deprecated
  3033. * @inheritDoc
  3034. * @version Egret 2.4
  3035. * @platform Web,Native
  3036. */
  3037. ScrollView.prototype.swapChildren = function (child1, child2) {
  3038. this.throwNotSupportedError();
  3039. };
  3040. /**
  3041. * @deprecated
  3042. * @inheritDoc
  3043. * @version Egret 2.4
  3044. * @platform Web,Native
  3045. */
  3046. ScrollView.prototype.swapChildrenAt = function (index1, index2) {
  3047. this.throwNotSupportedError();
  3048. };
  3049. return ScrollView;
  3050. }(egret.DisplayObjectContainer));
  3051. /**
  3052. * @private
  3053. */
  3054. ScrollView.weight = [1, 1.33, 1.66, 2, 2.33];
  3055. egret.ScrollView = ScrollView;
  3056. __reflect(ScrollView.prototype, "egret.ScrollView");
  3057. })(egret || (egret = {}));
  3058. //////////////////////////////////////////////////////////////////////////////////////
  3059. //
  3060. // Copyright (c) 2014-present, Egret Technology.
  3061. // All rights reserved.
  3062. // Redistribution and use in source and binary forms, with or without
  3063. // modification, are permitted provided that the following conditions are met:
  3064. //
  3065. // * Redistributions of source code must retain the above copyright
  3066. // notice, this list of conditions and the following disclaimer.
  3067. // * Redistributions in binary form must reproduce the above copyright
  3068. // notice, this list of conditions and the following disclaimer in the
  3069. // documentation and/or other materials provided with the distribution.
  3070. // * Neither the name of the Egret nor the
  3071. // names of its contributors may be used to endorse or promote products
  3072. // derived from this software without specific prior written permission.
  3073. //
  3074. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  3075. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  3076. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  3077. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  3078. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  3079. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  3080. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  3081. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  3082. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  3083. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  3084. //
  3085. //////////////////////////////////////////////////////////////////////////////////////
  3086. var egret;
  3087. (function (egret) {
  3088. /**
  3089. * @private
  3090. * @version Egret 2.4
  3091. * @platform Web,Native
  3092. */
  3093. var ScrollViewProperties = (function () {
  3094. function ScrollViewProperties() {
  3095. /**
  3096. * @private
  3097. */
  3098. this._verticalScrollPolicy = "auto";
  3099. /**
  3100. * @private
  3101. */
  3102. this._horizontalScrollPolicy = "auto";
  3103. /**
  3104. * @private
  3105. */
  3106. this._scrollLeft = 0;
  3107. /**
  3108. * @private
  3109. */
  3110. this._scrollTop = 0;
  3111. /**
  3112. * @private
  3113. */
  3114. this._hCanScroll = false;
  3115. /**
  3116. * @private
  3117. */
  3118. this._vCanScroll = false;
  3119. /**
  3120. * @private
  3121. */
  3122. this._lastTouchPosition = new egret.Point(0, 0);
  3123. /**
  3124. * @private
  3125. */
  3126. this._touchStartPosition = new egret.Point(0, 0);
  3127. /**
  3128. * @private
  3129. */
  3130. this._scrollStarted = false;
  3131. /**
  3132. * @private
  3133. */
  3134. this._lastTouchTime = 0;
  3135. /**
  3136. * @private
  3137. */
  3138. this._lastTouchEvent = null;
  3139. /**
  3140. * @private
  3141. */
  3142. this._velocitys = [];
  3143. /**
  3144. * @private
  3145. */
  3146. this._isHTweenPlaying = false;
  3147. /**
  3148. * @private
  3149. */
  3150. this._isVTweenPlaying = false;
  3151. /**
  3152. * @private
  3153. */
  3154. this._hScrollTween = null;
  3155. /**
  3156. * @private
  3157. */
  3158. this._vScrollTween = null;
  3159. /**
  3160. * @private
  3161. */
  3162. this._bounces = true;
  3163. }
  3164. return ScrollViewProperties;
  3165. }());
  3166. egret.ScrollViewProperties = ScrollViewProperties;
  3167. __reflect(ScrollViewProperties.prototype, "egret.ScrollViewProperties");
  3168. })(egret || (egret = {}));
  3169. //////////////////////////////////////////////////////////////////////////////////////
  3170. //
  3171. // Copyright (c) 2014-present, Egret Technology.
  3172. // All rights reserved.
  3173. // Redistribution and use in source and binary forms, with or without
  3174. // modification, are permitted provided that the following conditions are met:
  3175. //
  3176. // * Redistributions of source code must retain the above copyright
  3177. // notice, this list of conditions and the following disclaimer.
  3178. // * Redistributions in binary form must reproduce the above copyright
  3179. // notice, this list of conditions and the following disclaimer in the
  3180. // documentation and/or other materials provided with the distribution.
  3181. // * Neither the name of the Egret nor the
  3182. // names of its contributors may be used to endorse or promote products
  3183. // derived from this software without specific prior written permission.
  3184. //
  3185. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  3186. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  3187. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  3188. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  3189. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  3190. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  3191. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  3192. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  3193. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  3194. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  3195. //
  3196. //////////////////////////////////////////////////////////////////////////////////////
  3197. var egret;
  3198. (function (egret) {
  3199. /**
  3200. * @private
  3201. *
  3202. * @param request
  3203. * @returns
  3204. */
  3205. function $getUrl(request) {
  3206. var url = request.url;
  3207. //get请求没有设置参数,而是设置URLVariables的情况
  3208. if (url.indexOf("?") == -1 && request.method == egret.URLRequestMethod.GET && request.data && request.data instanceof egret.URLVariables) {
  3209. url = url + "?" + request.data.toString();
  3210. }
  3211. return url;
  3212. }
  3213. egret.$getUrl = $getUrl;
  3214. })(egret || (egret = {}));
  3215. //////////////////////////////////////////////////////////////////////////////////////
  3216. //
  3217. // Copyright (c) 2014-present, Egret Technology.
  3218. // All rights reserved.
  3219. // Redistribution and use in source and binary forms, with or without
  3220. // modification, are permitted provided that the following conditions are met:
  3221. //
  3222. // * Redistributions of source code must retain the above copyright
  3223. // notice, this list of conditions and the following disclaimer.
  3224. // * Redistributions in binary form must reproduce the above copyright
  3225. // notice, this list of conditions and the following disclaimer in the
  3226. // documentation and/or other materials provided with the distribution.
  3227. // * Neither the name of the Egret nor the
  3228. // names of its contributors may be used to endorse or promote products
  3229. // derived from this software without specific prior written permission.
  3230. //
  3231. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  3232. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  3233. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  3234. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  3235. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  3236. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  3237. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  3238. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  3239. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  3240. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  3241. //
  3242. //////////////////////////////////////////////////////////////////////////////////////
  3243. var egret;
  3244. (function (egret) {
  3245. var setTimeoutCache = {};
  3246. var setTimeoutIndex = 0;
  3247. var setTimeoutCount = 0;
  3248. var lastTime = 0;
  3249. /**
  3250. * @language en_US
  3251. * Run the designated function in specified delay (in milliseconds).
  3252. * @param listener {Function} Listener function
  3253. * @param thisObject {any} this object
  3254. * @param delay {number} Delay time, in milliseconds
  3255. * @param ...args {any} Parameter list
  3256. * @returns {number} Return index which can be used for clearTimeout
  3257. * @version Egret 2.4
  3258. * @platform Web,Native
  3259. * @includeExample extension/game/utils/setTimeout.ts
  3260. */
  3261. /**
  3262. * @language zh_CN
  3263. * 在指定的延迟(以毫秒为单位)后运行指定的函数。
  3264. * @param listener {Function} 侦听函数
  3265. * @param thisObject {any} this对象
  3266. * @param delay {number} 延迟时间,以毫秒为单位
  3267. * @param ...args {any} 参数列表
  3268. * @returns {number} 返回索引,可以用于 clearTimeout
  3269. * @version Egret 2.4
  3270. * @platform Web,Native
  3271. * @includeExample extension/game/utils/setTimeout.ts
  3272. */
  3273. function setTimeout(listener, thisObject, delay) {
  3274. var args = [];
  3275. for (var _i = 3; _i < arguments.length; _i++) {
  3276. args[_i - 3] = arguments[_i];
  3277. }
  3278. var data = { listener: listener, thisObject: thisObject, delay: delay, params: args };
  3279. setTimeoutCount++;
  3280. if (setTimeoutCount == 1 && egret.sys.$ticker) {
  3281. lastTime = egret.getTimer();
  3282. egret.sys.$ticker.$startTick(timeoutUpdate, null);
  3283. }
  3284. setTimeoutIndex++;
  3285. setTimeoutCache[setTimeoutIndex] = data;
  3286. return setTimeoutIndex;
  3287. }
  3288. egret.setTimeout = setTimeout;
  3289. /**
  3290. * @language en_US
  3291. * Function run after the specified delay is cleared.
  3292. * @param key {number} Index that egret.setTimeout returns
  3293. * @version Egret 2.4
  3294. * @platform Web,Native
  3295. */
  3296. /**
  3297. * @language zh_CN
  3298. * 清除指定延迟后运行的函数。
  3299. * @param key {number} egret.setTimeout所返回的索引
  3300. * @version Egret 2.4
  3301. * @platform Web,Native
  3302. */
  3303. function clearTimeout(key) {
  3304. if (setTimeoutCache[key]) {
  3305. setTimeoutCount--;
  3306. delete setTimeoutCache[key];
  3307. if (setTimeoutCount == 0 && egret.sys.$ticker) {
  3308. egret.sys.$ticker.$stopTick(timeoutUpdate, null);
  3309. }
  3310. }
  3311. }
  3312. egret.clearTimeout = clearTimeout;
  3313. /**
  3314. * @private
  3315. *
  3316. * @param dt
  3317. */
  3318. function timeoutUpdate(timeStamp) {
  3319. var dt = timeStamp - lastTime;
  3320. lastTime = timeStamp;
  3321. for (var key in setTimeoutCache) {
  3322. var key2 = key;
  3323. var data = setTimeoutCache[key2];
  3324. data.delay -= dt;
  3325. if (data.delay <= 0) {
  3326. data.listener.apply(data.thisObject, data.params);
  3327. clearTimeout(key2);
  3328. }
  3329. }
  3330. return false;
  3331. }
  3332. })(egret || (egret = {}));
  3333. //////////////////////////////////////////////////////////////////////////////////////
  3334. //
  3335. // Copyright (c) 2014-present, Egret Technology.
  3336. // All rights reserved.
  3337. // Redistribution and use in source and binary forms, with or without
  3338. // modification, are permitted provided that the following conditions are met:
  3339. //
  3340. // * Redistributions of source code must retain the above copyright
  3341. // notice, this list of conditions and the following disclaimer.
  3342. // * Redistributions in binary form must reproduce the above copyright
  3343. // notice, this list of conditions and the following disclaimer in the
  3344. // documentation and/or other materials provided with the distribution.
  3345. // * Neither the name of the Egret nor the
  3346. // names of its contributors may be used to endorse or promote products
  3347. // derived from this software without specific prior written permission.
  3348. //
  3349. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  3350. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  3351. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  3352. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  3353. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  3354. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  3355. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  3356. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  3357. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  3358. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  3359. //
  3360. //////////////////////////////////////////////////////////////////////////////////////
  3361. var egret;
  3362. (function (egret) {
  3363. /**
  3364. * @language en_US
  3365. * The URLLoaderDataFormat class provides values that specify how downloaded data is received.
  3366. * @see http://edn.egret.com/cn/docs/page/600 Read different data format
  3367. * @version Egret 2.4
  3368. * @platform Web,Native
  3369. * @includeExample extension/game/net/URLLoaderDataFormat.ts
  3370. */
  3371. /**
  3372. * @language zh_CN
  3373. * URLLoaderDataFormat 类提供了一些用于指定如何接收已下载数据的值。
  3374. * @see http://edn.egret.com/cn/docs/page/600 读取不同数据格式
  3375. * @version Egret 2.4
  3376. * @platform Web,Native
  3377. * @includeExample extension/game/net/URLLoaderDataFormat.ts
  3378. */
  3379. var URLLoaderDataFormat = (function () {
  3380. function URLLoaderDataFormat() {
  3381. }
  3382. return URLLoaderDataFormat;
  3383. }());
  3384. /**
  3385. * @language en_US
  3386. * Specify that downloaded data is received as raw binary data.
  3387. * @version Egret 2.4
  3388. * @platform Web
  3389. */
  3390. /**
  3391. * @language zh_CN
  3392. * 指定以原始二进制数据形式接收下载的数据。
  3393. * @version Egret 2.4
  3394. * @platform Web
  3395. */
  3396. URLLoaderDataFormat.BINARY = "binary";
  3397. /**
  3398. * @language en_US
  3399. * Specify that downloaded data is received as text.
  3400. * @version Egret 2.4
  3401. * @platform Web,Native
  3402. */
  3403. /**
  3404. * @language zh_CN
  3405. * 指定以文本形式接收已下载的数据。
  3406. * @version Egret 2.4
  3407. * @platform Web,Native
  3408. */
  3409. URLLoaderDataFormat.TEXT = "text";
  3410. /**
  3411. * @language en_US
  3412. * Specify that downloaded data is received as URL-encoded variables.
  3413. * @version Egret 2.4
  3414. * @platform Web,Native
  3415. */
  3416. /**
  3417. * @language zh_CN
  3418. * 指定以 URL 编码变量形式接收下载的数据。
  3419. * @version Egret 2.4
  3420. * @platform Web,Native
  3421. */
  3422. URLLoaderDataFormat.VARIABLES = "variables";
  3423. /**
  3424. * @language en_US
  3425. * Specify that downloaded data is received as bitmap texture.
  3426. * @version Egret 2.4
  3427. * @platform Web,Native
  3428. */
  3429. /**
  3430. * @language zh_CN
  3431. * 指定以位图纹理形式接收已下载的数据。
  3432. * @version Egret 2.4
  3433. * @platform Web,Native
  3434. */
  3435. URLLoaderDataFormat.TEXTURE = "texture";
  3436. /**
  3437. * @language en_US
  3438. * Specify that downloaded data is received as sound.
  3439. * @version Egret 2.4
  3440. * @platform Web,Native
  3441. */
  3442. /**
  3443. * @language zh_CN
  3444. * 指定以声音形式接收已下载的数据。
  3445. * @version Egret 2.4
  3446. * @platform Web,Native
  3447. */
  3448. URLLoaderDataFormat.SOUND = "sound";
  3449. egret.URLLoaderDataFormat = URLLoaderDataFormat;
  3450. __reflect(URLLoaderDataFormat.prototype, "egret.URLLoaderDataFormat");
  3451. })(egret || (egret = {}));
  3452. //////////////////////////////////////////////////////////////////////////////////////
  3453. //
  3454. // Copyright (c) 2014-present, Egret Technology.
  3455. // All rights reserved.
  3456. // Redistribution and use in source and binary forms, with or without
  3457. // modification, are permitted provided that the following conditions are met:
  3458. //
  3459. // * Redistributions of source code must retain the above copyright
  3460. // notice, this list of conditions and the following disclaimer.
  3461. // * Redistributions in binary form must reproduce the above copyright
  3462. // notice, this list of conditions and the following disclaimer in the
  3463. // documentation and/or other materials provided with the distribution.
  3464. // * Neither the name of the Egret nor the
  3465. // names of its contributors may be used to endorse or promote products
  3466. // derived from this software without specific prior written permission.
  3467. //
  3468. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  3469. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  3470. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  3471. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  3472. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  3473. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  3474. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  3475. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  3476. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  3477. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  3478. //
  3479. //////////////////////////////////////////////////////////////////////////////////////
  3480. var egret;
  3481. (function (egret) {
  3482. /**
  3483. * @language en_US
  3484. * The URLRequest class captures all of the information in a single HTTP request.
  3485. * @see http://edn.egret.com/cn/index.php/article/index/id/601 Build communication request
  3486. * @version Egret 2.4
  3487. * @platform Web,Native
  3488. * @includeExample extension/game/net/URLRequest.ts
  3489. */
  3490. /**
  3491. * @language zh_CN
  3492. * URLRequest 类可捕获单个 HTTP 请求中的所有信息。
  3493. * @see http://edn.egret.com/cn/index.php/article/index/id/601 构建通信请求
  3494. * @version Egret 2.4
  3495. * @platform Web,Native
  3496. * @includeExample extension/game/net/URLRequest.ts
  3497. */
  3498. var URLRequest = (function (_super) {
  3499. __extends(URLRequest, _super);
  3500. /**
  3501. * @language en_US
  3502. * Create an egret.URLRequest object
  3503. * @param url {string} Addresses for URL requests
  3504. * @version Egret 2.4
  3505. * @platform Web,Native
  3506. */
  3507. /**
  3508. * @language zh_CN
  3509. * 创建一个 egret.URLRequest 对象
  3510. * @param url {string} 进行网络请求的地址
  3511. * @version Egret 2.4
  3512. * @platform Web,Native
  3513. */
  3514. function URLRequest(url) {
  3515. if (url === void 0) { url = null; }
  3516. var _this = _super.call(this) || this;
  3517. /**
  3518. * @language en_US
  3519. * An object contains data to be transmitted with the URL request.
  3520. * This property is used in conjunction with the method property. When the value of method is GET, the value of data is appended to the value of URLRequest.url, using HTTP query-string syntax.
  3521. * When the method value is POST (or any value other than GET), the value of data is transmitted in the body of the HTTP request.
  3522. * The URLRequest API offers binary POST support and support for URL-encoded variables, as well as support for strings. The data object can be a ArrayBuffer, URLVariables, or String object.
  3523. * The way in which the data is used depends on the type of object used:
  3524. * If the object is a ArrayBuffer object, the binary data of the ArrayBuffer object is used as POST data. For GET, data of ArrayBuffer type is not supported.
  3525. * If the object is a URLVariables object and the method is POST, then the variables are encoded using x-www-form-urlencoded format and the resulting string is used as POST data.
  3526. * If the object is a URLVariables object and the method is GET, the URLVariables object will define variables to be sent with the URLRequest object.
  3527. * Otherwise, the object is converted into a string, and the string is used as the POST or GET data.
  3528. * @version Egret 2.4
  3529. * @platform Web,Native
  3530. */
  3531. /**
  3532. * @language zh_CN
  3533. * 一个对象,它包含将随 URL 请求一起传输的数据。
  3534. * 该属性与 method 属性配合使用。当 method 值为 GET 时,将使用 HTTP 查询字符串语法将 data 值追加到 URLRequest.url 值。
  3535. * 当 method 值为 POST(或 GET 之外的任何值)时,将在 HTTP 请求体中传输 data 值。
  3536. * URLRequest API 支持二进制 POST,并支持 URL 编码变量和字符串。该数据对象可以是 ArrayBuffer、URLVariables 或 String 对象。
  3537. * 该数据的使用方式取决于所用对象的类型:
  3538. * 如果该对象为 ArrayBuffer 对象,则 ArrayBuffer 对象的二进制数据用作 POST 数据。对于 GET,不支持 ArrayBuffer 类型的数据。
  3539. * 如果该对象是 URLVariables 对象,并且该方法是 POST,则使用 x-www-form-urlencoded 格式对变量进行编码,并且生成的字符串会用作 POST 数据。
  3540. * 如果该对象是 URLVariables 对象,并且该方法是 GET,则 URLVariables 对象将定义要随 URLRequest 对象一起发送的变量。
  3541. * 否则,该对象会转换为字符串,并且该字符串会用作 POST 或 GET 数据。
  3542. * @version Egret 2.4
  3543. * @platform Web,Native
  3544. */
  3545. _this.data = null;
  3546. /**
  3547. * @language en_US
  3548. * Request method, valid values are URLRequestMethod.GET or URLRequestMethod.POST.
  3549. * @version Egret 2.4
  3550. * @platform Web,Native
  3551. */
  3552. /**
  3553. * @language zh_CN
  3554. * 请求方式,有效值为URLRequestMethod.GET 或 URLRequestMethod.POST。
  3555. * @version Egret 2.4
  3556. * @platform Web,Native
  3557. */
  3558. _this.method = egret.URLRequestMethod.GET;
  3559. /**
  3560. * @language en_US
  3561. * The requested URL.
  3562. * @version Egret 2.4
  3563. * @platform Web,Native
  3564. */
  3565. /**
  3566. * @language zh_CN
  3567. * 所请求的 URL。
  3568. * @version Egret 2.4
  3569. * @platform Web,Native
  3570. */
  3571. _this.url = "";
  3572. /**
  3573. * @language en_US
  3574. * The array of HTTP request headers to be appended to the HTTP request. The array is composed of URLRequestHeader objects.
  3575. * Each object in the array must be a URLRequestHeader object that contains a name string and a value string.
  3576. * Because of browser compatibility, this property has not been achieved in html5
  3577. * @version Egret 2.4
  3578. * @platform Web,Native
  3579. */
  3580. /**
  3581. * @language zh_CN
  3582. * 要追加到 HTTP 请求的 HTTP 请求标头的数组。该数组由 URLRequestHeader 对象组成。
  3583. * 数组中的每一对象必须是包含一个名称字符串和一个值字符串的 URLRequestHeader 对象。
  3584. * 由于浏览器兼容性原因,该属性在 html5 中并未实现
  3585. * @version Egret 2.4
  3586. * @platform Web,Native
  3587. */
  3588. _this.requestHeaders = [];
  3589. _this.url = url;
  3590. return _this;
  3591. }
  3592. return URLRequest;
  3593. }(egret.HashObject));
  3594. egret.URLRequest = URLRequest;
  3595. __reflect(URLRequest.prototype, "egret.URLRequest");
  3596. })(egret || (egret = {}));
  3597. //////////////////////////////////////////////////////////////////////////////////////
  3598. //
  3599. // Copyright (c) 2014-present, Egret Technology.
  3600. // All rights reserved.
  3601. // Redistribution and use in source and binary forms, with or without
  3602. // modification, are permitted provided that the following conditions are met:
  3603. //
  3604. // * Redistributions of source code must retain the above copyright
  3605. // notice, this list of conditions and the following disclaimer.
  3606. // * Redistributions in binary form must reproduce the above copyright
  3607. // notice, this list of conditions and the following disclaimer in the
  3608. // documentation and/or other materials provided with the distribution.
  3609. // * Neither the name of the Egret nor the
  3610. // names of its contributors may be used to endorse or promote products
  3611. // derived from this software without specific prior written permission.
  3612. //
  3613. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  3614. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  3615. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  3616. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  3617. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  3618. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  3619. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  3620. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  3621. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  3622. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  3623. //
  3624. //////////////////////////////////////////////////////////////////////////////////////
  3625. var egret;
  3626. (function (egret) {
  3627. /**
  3628. * @language en_US
  3629. * A URLRequestHeader object encapsulates a single HTTP request header and consists of a name/value pair. URLRequestHeader objects are used in the requestHeaders property of the URLRequest class.
  3630. * Note: Because of browser compatibility, this property has not been achieved in html5
  3631. * @version Egret 2.4
  3632. * @platform Web,Native
  3633. * @includeExample extension/game/net/URLRequestHeader.ts
  3634. */
  3635. /**
  3636. * @language zh_CN
  3637. * URLRequestHeader 对象封装了一个 HTTP 请求标头并由一个名称/值对组成。URLRequestHeader 对象在 URLRequest 类的 requestHeaders 属性中使用。
  3638. * 注意:由于浏览器兼容性原因,在 html5 中并未实现
  3639. * @version Egret 2.4
  3640. * @platform Web,Native
  3641. * @includeExample extension/game/net/URLRequestHeader.ts
  3642. */
  3643. var URLRequestHeader = (function () {
  3644. /**
  3645. * @language en_US
  3646. * Create an egret.URLRequestHeader object
  3647. * @version Egret 2.4
  3648. * @platform Web,Native
  3649. */
  3650. /**
  3651. * @language zh_CN
  3652. * 创建一个 egret.URLRequestHeader 对象
  3653. * @version Egret 2.4
  3654. * @platform Web,Native
  3655. */
  3656. function URLRequestHeader(name, value) {
  3657. /**
  3658. * @language en_US
  3659. * HTTP request header name, such as Content-Type
  3660. * @version Egret 2.4
  3661. * @platform Web,Native
  3662. */
  3663. /**
  3664. * @language zh_CN
  3665. * HTTP 请求标头名称,如 Content-Type
  3666. * @version Egret 2.4
  3667. * @platform Web,Native
  3668. */
  3669. this.name = "";
  3670. /**
  3671. * @language en_US
  3672. * The values associated with the name property (such as text/plain).
  3673. * @version Egret 2.4
  3674. * @platform Web,Native
  3675. */
  3676. /**
  3677. * @language zh_CN
  3678. * 与 name 属性相关联的值,如 text/plain
  3679. * @version Egret 2.4
  3680. * @platform Web,Native
  3681. */
  3682. this.value = "";
  3683. this.name = name;
  3684. this.value = value;
  3685. }
  3686. return URLRequestHeader;
  3687. }());
  3688. egret.URLRequestHeader = URLRequestHeader;
  3689. __reflect(URLRequestHeader.prototype, "egret.URLRequestHeader");
  3690. })(egret || (egret = {}));
  3691. //////////////////////////////////////////////////////////////////////////////////////
  3692. //
  3693. // Copyright (c) 2014-present, Egret Technology.
  3694. // All rights reserved.
  3695. // Redistribution and use in source and binary forms, with or without
  3696. // modification, are permitted provided that the following conditions are met:
  3697. //
  3698. // * Redistributions of source code must retain the above copyright
  3699. // notice, this list of conditions and the following disclaimer.
  3700. // * Redistributions in binary form must reproduce the above copyright
  3701. // notice, this list of conditions and the following disclaimer in the
  3702. // documentation and/or other materials provided with the distribution.
  3703. // * Neither the name of the Egret nor the
  3704. // names of its contributors may be used to endorse or promote products
  3705. // derived from this software without specific prior written permission.
  3706. //
  3707. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  3708. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  3709. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  3710. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  3711. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  3712. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  3713. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  3714. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  3715. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  3716. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  3717. //
  3718. //////////////////////////////////////////////////////////////////////////////////////
  3719. var egret;
  3720. (function (egret) {
  3721. /**
  3722. * @language en_US
  3723. * The URLRequestMethod class provides values that specify whether the
  3724. * URLRequest object should use the POST method or the GET method when sending data to a server.
  3725. * @see http://edn.egret.com/cn/docs/page/599 POST与GET
  3726. * @version Egret 2.4
  3727. * @platform Web,Native
  3728. * @includeExample extension/game/net/URLRequestMethod.ts
  3729. */
  3730. /**
  3731. * @language zh_CN
  3732. * URLRequestMethod 类提供了一些值,这些值可指定在将数据发送到服务器时,
  3733. * URLRequest 对象应使用 POST 方法还是 GET 方法。
  3734. * @see http://edn.egret.com/cn/docs/page/599 POST与GET
  3735. * @version Egret 2.4
  3736. * @platform Web,Native
  3737. * @includeExample extension/game/net/URLRequestMethod.ts
  3738. */
  3739. var URLRequestMethod = (function () {
  3740. function URLRequestMethod() {
  3741. }
  3742. return URLRequestMethod;
  3743. }());
  3744. /**
  3745. * @language en_US
  3746. * Specify that the URLRequest object is a GET.
  3747. * @version Egret 2.4
  3748. * @platform Web,Native
  3749. */
  3750. /**
  3751. * @language zh_CN
  3752. * 表示 URLRequest 对象是一个 GET。
  3753. * @version Egret 2.4
  3754. * @platform Web,Native
  3755. */
  3756. URLRequestMethod.GET = "get";
  3757. /**
  3758. * @language en_US
  3759. * Specify that the URLRequest object is a POST.
  3760. * @version Egret 2.4
  3761. * @platform Web,Native
  3762. */
  3763. /**
  3764. * @language zh_CN
  3765. * 表示 URLRequest 对象是一个 POST。
  3766. * @version Egret 2.4
  3767. * @platform Web,Native
  3768. */
  3769. URLRequestMethod.POST = "post";
  3770. egret.URLRequestMethod = URLRequestMethod;
  3771. __reflect(URLRequestMethod.prototype, "egret.URLRequestMethod");
  3772. })(egret || (egret = {}));
  3773. //////////////////////////////////////////////////////////////////////////////////////
  3774. //
  3775. // Copyright (c) 2014-present, Egret Technology.
  3776. // All rights reserved.
  3777. // Redistribution and use in source and binary forms, with or without
  3778. // modification, are permitted provided that the following conditions are met:
  3779. //
  3780. // * Redistributions of source code must retain the above copyright
  3781. // notice, this list of conditions and the following disclaimer.
  3782. // * Redistributions in binary form must reproduce the above copyright
  3783. // notice, this list of conditions and the following disclaimer in the
  3784. // documentation and/or other materials provided with the distribution.
  3785. // * Neither the name of the Egret nor the
  3786. // names of its contributors may be used to endorse or promote products
  3787. // derived from this software without specific prior written permission.
  3788. //
  3789. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  3790. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  3791. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  3792. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  3793. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  3794. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  3795. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  3796. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  3797. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  3798. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  3799. //
  3800. //////////////////////////////////////////////////////////////////////////////////////
  3801. var egret;
  3802. (function (egret) {
  3803. /**
  3804. * @language en_US
  3805. * The URLVariables class allows you to transfer variables between an application and a server.
  3806. * Use URLVariables objects with methods of the URLLoader class and the data property of the URLRequest class.
  3807. * @see http://edn.egret.com/cn/docs/page/598 Send the request with parameters
  3808. * @version Egret 2.4
  3809. * @platform Web,Native
  3810. * @includeExample extension/game/net/URLVariables.ts
  3811. */
  3812. /**
  3813. * @language zh_CN
  3814. * 使用 URLVariables 类可以在应用程序和服务器之间传输变量。
  3815. * 将 URLVariables 对象与 URLLoader 类的方法、URLRequest 类的 data 属性一起使用。
  3816. * @see http://edn.egret.com/cn/docs/page/598 发送带参数的请求
  3817. * @version Egret 2.4
  3818. * @platform Web,Native
  3819. * @includeExample extension/game/net/URLVariables.ts
  3820. */
  3821. var URLVariables = (function (_super) {
  3822. __extends(URLVariables, _super);
  3823. /**
  3824. * @language en_US
  3825. * Create an egret.URLVariable object
  3826. * @param source {String} A URL-encoded string containing name/value pairs.
  3827. * @version Egret 2.4
  3828. * @platform Web,Native
  3829. */
  3830. /**
  3831. * @language zh_CN
  3832. * 创建一个 egret.URLVariables 对象
  3833. * @param source {String} 包含名称/值对的 URL 编码的字符串。
  3834. * @version Egret 2.4
  3835. * @platform Web,Native
  3836. */
  3837. function URLVariables(source) {
  3838. if (source === void 0) { source = null; }
  3839. var _this = _super.call(this) || this;
  3840. /**
  3841. * @language en_US
  3842. * Key-value pair data object saved in this URLVariables object
  3843. * @version Egret 2.4
  3844. * @platform Web,Native
  3845. */
  3846. /**
  3847. * @language zh_CN
  3848. * 此 URLVariables 储存的键值对数据对象。
  3849. * @version Egret 2.4
  3850. * @platform Web,Native
  3851. */
  3852. _this.variables = null;
  3853. if (source !== null) {
  3854. _this.decode(source);
  3855. }
  3856. return _this;
  3857. }
  3858. /**
  3859. * @language en_US
  3860. * Convert the variable string into the property of this URLVariables.variables object.
  3861. * @param source {string}
  3862. * @version Egret 2.4
  3863. * @platform Web,Native
  3864. */
  3865. /**
  3866. * @language zh_CN
  3867. * 将变量字符串转换为此 URLVariables.variables 对象的属性。
  3868. * @param source {string}
  3869. * @version Egret 2.4
  3870. * @platform Web,Native
  3871. */
  3872. URLVariables.prototype.decode = function (source) {
  3873. if (!this.variables) {
  3874. this.variables = {};
  3875. }
  3876. source = source.split("+").join(" ");
  3877. var tokens, re = /[?&]?([^=]+)=([^&]*)/g;
  3878. while (tokens = re.exec(source)) {
  3879. var key = decodeURIComponent(tokens[1]), val = decodeURIComponent(tokens[2]);
  3880. //没有重复键值,直接赋值
  3881. if ((key in this.variables) == false) {
  3882. this.variables[key] = val;
  3883. continue;
  3884. }
  3885. //有重复键值,如果已经存在数组,直接push到数组,否则创建一个新数组
  3886. var value = this.variables[key];
  3887. if (value instanceof Array) {
  3888. value.push(val);
  3889. }
  3890. else {
  3891. this.variables[key] = [value, val];
  3892. }
  3893. }
  3894. };
  3895. /**
  3896. * @language en_US
  3897. * Return a string containing all enumerable variables using the MIME content encoding format : application/x-www-form-urlencoded.
  3898. * @version Egret 2.4
  3899. * @platform Web,Native
  3900. */
  3901. /**
  3902. * @language zh_CN
  3903. * 以 MIME 内容编码格式 application/x-www-form-urlencoded 返回包含所有可枚举变量的字符串。
  3904. * @version Egret 2.4
  3905. * @platform Web,Native
  3906. */
  3907. URLVariables.prototype.toString = function () {
  3908. if (!this.variables) {
  3909. return "";
  3910. }
  3911. var variables = this.variables;
  3912. var stringArray = [];
  3913. for (var key in variables) {
  3914. stringArray.push(this.encodeValue(key, variables[key]));
  3915. }
  3916. return stringArray.join("&");
  3917. };
  3918. /**
  3919. * @private
  3920. *
  3921. * @param key
  3922. * @param value
  3923. */
  3924. URLVariables.prototype.encodeValue = function (key, value) {
  3925. if (value instanceof Array) {
  3926. return this.encodeArray(key, value);
  3927. }
  3928. else {
  3929. return encodeURIComponent(key) + "=" + encodeURIComponent(value);
  3930. }
  3931. };
  3932. /**
  3933. * @private
  3934. *
  3935. * @param key
  3936. * @param value
  3937. */
  3938. URLVariables.prototype.encodeArray = function (key, value) {
  3939. if (!key)
  3940. return "";
  3941. if (value.length == 0) {
  3942. return encodeURIComponent(key) + "=";
  3943. }
  3944. return value.map(function (v) { return encodeURIComponent(key) + "=" + encodeURIComponent(v); }).join("&");
  3945. };
  3946. return URLVariables;
  3947. }(egret.HashObject));
  3948. egret.URLVariables = URLVariables;
  3949. __reflect(URLVariables.prototype, "egret.URLVariables");
  3950. })(egret || (egret = {}));
  3951. //////////////////////////////////////////////////////////////////////////////////////
  3952. //
  3953. // Copyright (c) 2014-present, Egret Technology.
  3954. // All rights reserved.
  3955. // Redistribution and use in source and binary forms, with or without
  3956. // modification, are permitted provided that the following conditions are met:
  3957. //
  3958. // * Redistributions of source code must retain the above copyright
  3959. // notice, this list of conditions and the following disclaimer.
  3960. // * Redistributions in binary form must reproduce the above copyright
  3961. // notice, this list of conditions and the following disclaimer in the
  3962. // documentation and/or other materials provided with the distribution.
  3963. // * Neither the name of the Egret nor the
  3964. // names of its contributors may be used to endorse or promote products
  3965. // derived from this software without specific prior written permission.
  3966. //
  3967. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  3968. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  3969. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  3970. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  3971. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  3972. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  3973. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  3974. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  3975. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  3976. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  3977. //
  3978. //////////////////////////////////////////////////////////////////////////////////////
  3979. var egret;
  3980. (function (egret) {
  3981. /**
  3982. * @language en_US
  3983. * @version Egret 2.4
  3984. * @platform Web,Native
  3985. * @includeExample extension/game/player/Ticker.ts
  3986. */
  3987. /**
  3988. * @language zh_CN
  3989. * @version Egret 2.4
  3990. * @platform Web,Native
  3991. * @includeExample extension/game/player/Ticker.ts
  3992. */
  3993. var Ticker = (function (_super) {
  3994. __extends(Ticker, _super);
  3995. /**
  3996. * @deprecated
  3997. * @version Egret 2.4
  3998. * @platform Web,Native
  3999. */
  4000. function Ticker() {
  4001. var _this = _super.call(this) || this;
  4002. _this._timeScale = 1;
  4003. _this._paused = false;
  4004. _this._callIndex = -1;
  4005. _this._lastTime = 0;
  4006. _this.callBackList = [];
  4007. if (Ticker.instance != null) {
  4008. if (true) {
  4009. egret.$error(1033);
  4010. }
  4011. }
  4012. egret.sys.$ticker.$startTick(_this.update, _this);
  4013. _this._lastTime = egret.getTimer();
  4014. return _this;
  4015. }
  4016. Ticker.prototype.update = function (timeStamp) {
  4017. var advancedTime = timeStamp - this._lastTime;
  4018. this._lastTime = timeStamp;
  4019. if (this._paused) {
  4020. return false;
  4021. }
  4022. var frameTime = advancedTime * this._timeScale;
  4023. this._callList = this.callBackList.concat();
  4024. this._callIndex = 0;
  4025. for (; this._callIndex < this._callList.length; this._callIndex++) {
  4026. var eventBin = this._callList[this._callIndex];
  4027. eventBin.listener.call(eventBin.thisObject, frameTime);
  4028. }
  4029. this._callIndex = -1;
  4030. this._callList = null;
  4031. return false;
  4032. };
  4033. /**
  4034. * 注册帧回调事件,同一函数的重复监听会被忽略。推荐使用 egret.startTick 替代此方法。
  4035. * @method egret.Ticker#register
  4036. * @param listener {Function} 帧回调函数,参数返回上一帧和这帧的间隔时间。示例:onEnterFrame(frameTime:number):void
  4037. * @param thisObject {any} 帧回调函数的this对象
  4038. * @param priority {number} 事件优先级,开发者请勿传递 Number.NEGATIVE_INFINITY 和 Number.POSITIVE_INFINITY
  4039. * @version Egret 2.4
  4040. * @platform Web,Native
  4041. * @deprecated
  4042. */
  4043. Ticker.prototype.register = function (listener, thisObject, priority) {
  4044. if (priority === void 0) { priority = 0; }
  4045. this.$insertEventBin(this.callBackList, "", listener, thisObject, false, priority, false);
  4046. };
  4047. /**
  4048. * 取消侦听enterFrame事件。推荐使用 egret.stopTick 替代此方法。
  4049. * @method egret.Ticker#unregister
  4050. * @param listener {Function} 事件侦听函数
  4051. * @param thisObject {any} 侦听函数的this对象
  4052. * @version Egret 2.4
  4053. * @platform Web,Native
  4054. * @deprecated
  4055. */
  4056. Ticker.prototype.unregister = function (listener, thisObject) {
  4057. this.$removeEventBin(this.callBackList, listener, thisObject);
  4058. };
  4059. /**
  4060. * @deprecated
  4061. * @param timeScale {number}
  4062. * @private
  4063. */
  4064. Ticker.prototype.setTimeScale = function (timeScale) {
  4065. this._timeScale = timeScale;
  4066. };
  4067. /**
  4068. * @deprecated
  4069. * @method egret.Ticker#getTimeScale
  4070. * @private
  4071. */
  4072. Ticker.prototype.getTimeScale = function () {
  4073. return this._timeScale;
  4074. };
  4075. /**
  4076. * 暂停
  4077. * @deprecated
  4078. * @method egret.Ticker#pause
  4079. */
  4080. Ticker.prototype.pause = function () {
  4081. this._paused = true;
  4082. };
  4083. /**
  4084. * 继续
  4085. * @deprecated
  4086. * @method egret.Ticker#resume
  4087. */
  4088. Ticker.prototype.resume = function () {
  4089. this._paused = false;
  4090. };
  4091. /**
  4092. * @method egret.Ticker.getInstance
  4093. * @returns {Ticker}
  4094. * @version Egret 2.4
  4095. * @platform Web,Native
  4096. * @deprecated
  4097. */
  4098. Ticker.getInstance = function () {
  4099. if (Ticker.instance == null) {
  4100. Ticker.instance = new Ticker();
  4101. }
  4102. return Ticker.instance;
  4103. };
  4104. return Ticker;
  4105. }(egret.EventDispatcher));
  4106. egret.Ticker = Ticker;
  4107. __reflect(Ticker.prototype, "egret.Ticker");
  4108. })(egret || (egret = {}));
  4109. //////////////////////////////////////////////////////////////////////////////////////
  4110. //
  4111. // Copyright (c) 2014-present, Egret Technology.
  4112. // All rights reserved.
  4113. // Redistribution and use in source and binary forms, with or without
  4114. // modification, are permitted provided that the following conditions are met:
  4115. //
  4116. // * Redistributions of source code must retain the above copyright
  4117. // notice, this list of conditions and the following disclaimer.
  4118. // * Redistributions in binary form must reproduce the above copyright
  4119. // notice, this list of conditions and the following disclaimer in the
  4120. // documentation and/or other materials provided with the distribution.
  4121. // * Neither the name of the Egret nor the
  4122. // names of its contributors may be used to endorse or promote products
  4123. // derived from this software without specific prior written permission.
  4124. //
  4125. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  4126. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  4127. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  4128. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  4129. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  4130. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  4131. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  4132. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  4133. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  4134. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  4135. //
  4136. //////////////////////////////////////////////////////////////////////////////////////
  4137. var egret;
  4138. (function (egret) {
  4139. /**
  4140. * @class egret.MainContext
  4141. * @classdesc
  4142. * MainContext是游戏的核心跨平台接口,组合了多个功能Context,并是游戏启动的主入口
  4143. * @extends egret.EventDispatcher
  4144. * @private
  4145. * @version Egret 2.4
  4146. * @platform Web,Native
  4147. */
  4148. var MainContext = (function (_super) {
  4149. __extends(MainContext, _super);
  4150. /**
  4151. * @version Egret 2.4
  4152. * @platform Web,Native
  4153. */
  4154. function MainContext() {
  4155. return _super.call(this) || this;
  4156. }
  4157. Object.defineProperty(MainContext.prototype, "stage", {
  4158. /**
  4159. * 渲染Context
  4160. * @member egret.MainContext#rendererContext
  4161. * @version Egret 2.4
  4162. * @platform Web,Native
  4163. */
  4164. //public rendererContext:RendererContext = null;
  4165. /**
  4166. * 触摸Context
  4167. * @member egret.MainContext#touchContext
  4168. * @version Egret 2.4
  4169. * @platform Web,Native
  4170. */
  4171. //public touchContext:TouchContext = null;
  4172. /**
  4173. * 网络Context
  4174. * @member egret.MainContext#netContext
  4175. * @version Egret 2.4
  4176. * @platform Web,Native
  4177. */
  4178. //public netContext:NetContext = null;
  4179. /**
  4180. * 设备divice
  4181. * @member egret.MainContext#deviceContext
  4182. * @version Egret 2.4
  4183. * @platform Web,Native
  4184. */
  4185. //public deviceContext:DeviceContext = null;
  4186. /**
  4187. * 舞台
  4188. * @member egret.MainContext#stage
  4189. * @version Egret 2.4
  4190. * @platform Web,Native
  4191. */
  4192. get: function () {
  4193. return egret.sys.$TempStage;
  4194. },
  4195. enumerable: true,
  4196. configurable: true
  4197. });
  4198. Object.defineProperty(MainContext, "runtimeType", {
  4199. /**
  4200. * @version Egret 2.4
  4201. * @platform Web,Native
  4202. */
  4203. get: function () {
  4204. egret.$warn(1041, "egret.MainContext.runtimeType", "egret.Capabilities.runtimeType");
  4205. return MainContext._runtimeType;
  4206. },
  4207. enumerable: true,
  4208. configurable: true
  4209. });
  4210. /**
  4211. * 游戏启动,开启主循环,参考Flash的滑动跑道模型
  4212. * @method egret.MainContext#run
  4213. * @version Egret 2.4
  4214. * @platform Web,Native
  4215. */
  4216. MainContext.prototype.run = function () {
  4217. };
  4218. Object.defineProperty(MainContext, "instance", {
  4219. /**
  4220. * @method egret.Ticker.getInstance
  4221. * @returns {Ticker}
  4222. * @version Egret 2.4
  4223. * @platform Web,Native
  4224. */
  4225. get: function () {
  4226. if (MainContext._instance == null) {
  4227. MainContext._instance = new MainContext();
  4228. }
  4229. return MainContext._instance;
  4230. },
  4231. enumerable: true,
  4232. configurable: true
  4233. });
  4234. return MainContext;
  4235. }(egret.EventDispatcher));
  4236. /**
  4237. * @version Egret 2.4
  4238. * @platform Web,Native
  4239. */
  4240. MainContext.deviceType = null;
  4241. /**
  4242. * @version Egret 2.4
  4243. * @platform Web,Native
  4244. */
  4245. MainContext.DEVICE_PC = "web";
  4246. /**
  4247. * @version Egret 2.4
  4248. * @platform Web,Native
  4249. */
  4250. MainContext.DEVICE_MOBILE = "native";
  4251. /**
  4252. * @version Egret 2.4
  4253. * @platform Web,Native
  4254. */
  4255. MainContext.RUNTIME_HTML5 = "runtimeHtml5";
  4256. /**
  4257. * @version Egret 2.4
  4258. * @platform Web,Native
  4259. */
  4260. MainContext.RUNTIME_NATIVE = "runtimeNative";
  4261. egret.MainContext = MainContext;
  4262. __reflect(MainContext.prototype, "egret.MainContext");
  4263. })(egret || (egret = {}));
  4264. /**
  4265. * @private
  4266. */
  4267. var testDeviceType1 = function () {
  4268. if (!this["navigator"]) {
  4269. return true;
  4270. }
  4271. var ua = navigator.userAgent.toLowerCase();
  4272. return (ua.indexOf('mobile') != -1 || ua.indexOf('android') != -1);
  4273. };
  4274. /**
  4275. * @private
  4276. */
  4277. var testRuntimeType1 = function () {
  4278. if (this["navigator"]) {
  4279. return true;
  4280. }
  4281. return false;
  4282. };
  4283. egret.MainContext.deviceType = testDeviceType1() ? egret.MainContext.DEVICE_MOBILE : egret.MainContext.DEVICE_PC;
  4284. egret.MainContext._runtimeType = testRuntimeType1() ? egret.MainContext.RUNTIME_HTML5 : egret.MainContext.RUNTIME_NATIVE;
  4285. delete testDeviceType1;
  4286. delete testRuntimeType1;
  4287. //////////////////////////////////////////////////////////////////////////////////////
  4288. //
  4289. // Copyright (c) 2014-present, Egret Technology.
  4290. // All rights reserved.
  4291. // Redistribution and use in source and binary forms, with or without
  4292. // modification, are permitted provided that the following conditions are met:
  4293. //
  4294. // * Redistributions of source code must retain the above copyright
  4295. // notice, this list of conditions and the following disclaimer.
  4296. // * Redistributions in binary form must reproduce the above copyright
  4297. // notice, this list of conditions and the following disclaimer in the
  4298. // documentation and/or other materials provided with the distribution.
  4299. // * Neither the name of the Egret nor the
  4300. // names of its contributors may be used to endorse or promote products
  4301. // derived from this software without specific prior written permission.
  4302. //
  4303. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  4304. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  4305. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  4306. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  4307. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  4308. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  4309. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  4310. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  4311. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  4312. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  4313. //
  4314. //////////////////////////////////////////////////////////////////////////////////////
  4315. var egret;
  4316. (function (egret) {
  4317. /**
  4318. * @language en_US
  4319. * Tool class for object cache repeat use, which can be used to construct an object pool. Objects are automatically recycled after a certain duration.
  4320. * @version Egret 2.4
  4321. * @platform Web,Native
  4322. * @includeExample extension/game/utils/Recycler.ts
  4323. * @private
  4324. */
  4325. /**
  4326. * @language zh_CN
  4327. * 对象缓存复用工具类,可用于构建对象池,一段时间后会自动回收对象。
  4328. * @version Egret 2.4
  4329. * @platform Web,Native
  4330. * @includeExample extension/game/utils/Recycler.ts
  4331. * @private
  4332. */
  4333. var Recycler = (function (_super) {
  4334. __extends(Recycler, _super);
  4335. /**
  4336. * @language en_US
  4337. * Create an egret.Recycler object
  4338. * @param autoDisposeTime {number} Number of frames when objects are destroyed automatically. Default value: 300
  4339. * @version Egret 2.4
  4340. * @platform Web,Native
  4341. */
  4342. /**
  4343. * @language zh_CN
  4344. * 创建一个 egret.Recycler 对象
  4345. * @param autoDisposeTime {number} 多少帧后自动销毁对象,默认值300
  4346. * @version Egret 2.4
  4347. * @platform Web,Native
  4348. */
  4349. function Recycler(autoDisposeTime) {
  4350. if (autoDisposeTime === void 0) { autoDisposeTime = 300; }
  4351. var _this = _super.call(this) || this;
  4352. /**
  4353. * @private
  4354. */
  4355. _this.objectPool = [];
  4356. /**
  4357. * @private
  4358. */
  4359. _this._length = 0;
  4360. if (autoDisposeTime < 1)
  4361. autoDisposeTime = 1;
  4362. _this.autoDisposeTime = autoDisposeTime;
  4363. _this.frameCount = 0;
  4364. return _this;
  4365. }
  4366. Recycler.$init = function () {
  4367. egret.sys.$ticker.$startTick(Recycler.onUpdate, Recycler);
  4368. };
  4369. Recycler.onUpdate = function (timeStamp) {
  4370. var list = Recycler._callBackList;
  4371. for (var i = list.length - 1; i >= 0; i--) {
  4372. list[i].$checkFrame();
  4373. }
  4374. return false;
  4375. };
  4376. /**
  4377. * @private
  4378. *
  4379. */
  4380. Recycler.prototype.$checkFrame = function () {
  4381. this.frameCount--;
  4382. if (this.frameCount <= 0) {
  4383. this.dispose();
  4384. }
  4385. };
  4386. Object.defineProperty(Recycler.prototype, "length", {
  4387. /**
  4388. * @language en_US
  4389. * Number of cached objects"
  4390. * @version Egret 2.4
  4391. * @platform Web,Native
  4392. */
  4393. /**
  4394. * @language zh_CN
  4395. * 缓存的对象数量
  4396. * @version Egret 2.4
  4397. * @platform Web,Native
  4398. */
  4399. get: function () {
  4400. return this._length;
  4401. },
  4402. enumerable: true,
  4403. configurable: true
  4404. });
  4405. /**
  4406. * @language en_US
  4407. * Cache an object for repeat use
  4408. * @param object {any} The object to be cached
  4409. * @version Egret 2.4
  4410. * @platform Web,Native
  4411. */
  4412. /**
  4413. * @language zh_CN
  4414. * 缓存一个对象以复用
  4415. * @param object {any} 需要缓存的对象
  4416. * @version Egret 2.4
  4417. * @platform Web,Native
  4418. */
  4419. Recycler.prototype.push = function (object) {
  4420. var pool = this.objectPool;
  4421. if (pool.indexOf(object) == -1) {
  4422. pool.push(object);
  4423. if (object.__recycle) {
  4424. object.__recycle();
  4425. }
  4426. this._length++;
  4427. if (this.frameCount == 0) {
  4428. this.frameCount = this.autoDisposeTime;
  4429. Recycler._callBackList.push(this);
  4430. }
  4431. }
  4432. };
  4433. /**
  4434. * @language en_US
  4435. * Obtain a cached object
  4436. * @returns {any} The obtained cached object
  4437. * @version Egret 2.4
  4438. * @platform Web,Native
  4439. */
  4440. /**
  4441. * @language zh_CN
  4442. * 获取一个缓存的对象
  4443. * @returns {any} 获得的缓存对象
  4444. * @version Egret 2.4
  4445. * @platform Web,Native
  4446. */
  4447. Recycler.prototype.pop = function () {
  4448. if (this._length == 0)
  4449. return null;
  4450. this._length--;
  4451. return this.objectPool.pop();
  4452. };
  4453. /**
  4454. * @language en_US
  4455. * Immediately clear all cached objects.
  4456. * @version Egret 2.4
  4457. * @platform Web,Native
  4458. */
  4459. /**
  4460. * @language zh_CN
  4461. * 立即清空所有缓存的对象。
  4462. * @version Egret 2.4
  4463. * @platform Web,Native
  4464. */
  4465. Recycler.prototype.dispose = function () {
  4466. if (this._length > 0) {
  4467. this.objectPool = [];
  4468. this._length = 0;
  4469. }
  4470. this.frameCount = 0;
  4471. var list = Recycler._callBackList;
  4472. var index = list.indexOf(this);
  4473. if (index != -1) {
  4474. list.splice(index, 1);
  4475. }
  4476. };
  4477. return Recycler;
  4478. }(egret.HashObject));
  4479. /**
  4480. * @private
  4481. */
  4482. Recycler._callBackList = [];
  4483. egret.Recycler = Recycler;
  4484. __reflect(Recycler.prototype, "egret.Recycler");
  4485. Recycler.$init();
  4486. })(egret || (egret = {}));
  4487. var egret;
  4488. (function (egret) {
  4489. var setIntervalCache = {};
  4490. var setIntervalIndex = 0;
  4491. var setIntervalCount = 0;
  4492. var lastTime = 0;
  4493. /**
  4494. * @language en_US
  4495. * To specify a delay (in milliseconds) calls the function specified interval loop.
  4496. * @param listener {Function} Listener function
  4497. * @param thisObject {any} this object
  4498. * @param delay {number} Delay time, in milliseconds
  4499. * @param ...args {any} Parameter list
  4500. * @returns {number} Return index which can be used for clearInterval
  4501. * @version Egret 2.4
  4502. * @platform Web,Native
  4503. * @includeExample extension/game/utils/setInterval.ts
  4504. */
  4505. /**
  4506. * @language zh_CN
  4507. * 以指定的延迟(以毫秒为单位)间隔循环调用指定的函数。
  4508. * @param listener {Function} 侦听函数
  4509. * @param thisObject {any} this对象
  4510. * @param delay {number} 延迟时间,以毫秒为单位
  4511. * @param ...args {any} 参数列表
  4512. * @returns {number} 返回索引,可以用于 clearInterval
  4513. * @version Egret 2.4
  4514. * @platform Web,Native
  4515. * @includeExample extension/game/utils/setInterval.ts
  4516. */
  4517. function setInterval(listener, thisObject, delay) {
  4518. var args = [];
  4519. for (var _i = 3; _i < arguments.length; _i++) {
  4520. args[_i - 3] = arguments[_i];
  4521. }
  4522. var data = { listener: listener, thisObject: thisObject, delay: delay, originDelay: delay, params: args };
  4523. setIntervalCount++;
  4524. if (setIntervalCount == 1) {
  4525. lastTime = egret.getTimer();
  4526. egret.sys.$ticker.$startTick(intervalUpdate, null);
  4527. }
  4528. setIntervalIndex++;
  4529. setIntervalCache[setIntervalIndex] = data;
  4530. return setIntervalIndex;
  4531. }
  4532. egret.setInterval = setInterval;
  4533. /**
  4534. * @language en_US
  4535. * Clear function to run after a specified delay.
  4536. * @param key {number} Index that egret.setInterval returns
  4537. * @version Egret 2.4
  4538. * @platform Web,Native
  4539. * @includeExample egret/utils/setInterval.ts
  4540. */
  4541. /**
  4542. * @language zh_CN
  4543. * 清除指定延迟后运行的函数。
  4544. * @param key {number} egret.setInterval所返回的索引
  4545. * @version Egret 2.4
  4546. * @platform Web,Native
  4547. * @includeExample egret/utils/setInterval.ts
  4548. */
  4549. function clearInterval(key) {
  4550. if (setIntervalCache[key]) {
  4551. setIntervalCount--;
  4552. delete setIntervalCache[key];
  4553. if (setIntervalCount == 0) {
  4554. egret.sys.$ticker.$stopTick(intervalUpdate, null);
  4555. }
  4556. }
  4557. }
  4558. egret.clearInterval = clearInterval;
  4559. /**
  4560. * @private
  4561. *
  4562. * @param dt
  4563. */
  4564. function intervalUpdate(timeStamp) {
  4565. var dt = timeStamp - lastTime;
  4566. lastTime = timeStamp;
  4567. for (var key in setIntervalCache) {
  4568. var data = setIntervalCache[key];
  4569. data.delay -= dt;
  4570. if (data.delay <= 0) {
  4571. data.delay = data.originDelay;
  4572. data.listener.apply(data.thisObject, data.params);
  4573. }
  4574. }
  4575. return false;
  4576. }
  4577. })(egret || (egret = {}));
  4578. //////////////////////////////////////////////////////////////////////////////////////
  4579. //
  4580. // Copyright (c) 2014-present, Egret Technology.
  4581. // All rights reserved.
  4582. // Redistribution and use in source and binary forms, with or without
  4583. // modification, are permitted provided that the following conditions are met:
  4584. //
  4585. // * Redistributions of source code must retain the above copyright
  4586. // notice, this list of conditions and the following disclaimer.
  4587. // * Redistributions in binary form must reproduce the above copyright
  4588. // notice, this list of conditions and the following disclaimer in the
  4589. // documentation and/or other materials provided with the distribution.
  4590. // * Neither the name of the Egret nor the
  4591. // names of its contributors may be used to endorse or promote products
  4592. // derived from this software without specific prior written permission.
  4593. //
  4594. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  4595. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  4596. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  4597. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  4598. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  4599. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  4600. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  4601. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  4602. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  4603. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  4604. //
  4605. //////////////////////////////////////////////////////////////////////////////////////
  4606. var egret;
  4607. (function (egret) {
  4608. /**
  4609. * @language en_US
  4610. * UThe URLLoader class downloads data from a URL as text, binary data, or URL-encoded variables. It is useful for downloading text files, XML, or other information to be used in a dynamic, data-driven application.
  4611. * A URLLoader object downloads all of the data from a URL before making it available to code in the applications. It sends out notifications about the progress of the download,
  4612. * which you can monitor through bytesLoaded and bytesTotal properties, as well as through dispatched events.
  4613. * @see http://edn.egret.com/cn/docs/page/601 Build communication request
  4614. * @event egret.Event.COMPLETE Dispatched when the net request is complete.
  4615. * @event egret.IOErrorEvent.IO_ERROR io error.
  4616. * @version Egret 2.4
  4617. * @platform Web,Native
  4618. * @includeExample extension/game/net/URLLoader.ts
  4619. */
  4620. /**
  4621. * @language zh_CN
  4622. * URLLoader 类以文本、二进制数据或 URL 编码变量的形式从 URL 下载数据。在下载文本文件、XML 或其他用于动态数据驱动应用程序的信息时,它很有用。
  4623. * URLLoader 对象会先从 URL 中下载所有数据,然后才将数据用于应用程序中的代码。它会发出有关下载进度的通知,
  4624. * 通过 bytesLoaded 和 bytesTotal 属性以及已调度的事件,可以监视下载进度。
  4625. * @see http://edn.egret.com/cn/docs/page/601 构建通信请求
  4626. * @event egret.Event.COMPLETE 加载完成后调度。
  4627. * @event egret.IOErrorEvent.IO_ERROR 加载错误后调度。
  4628. * @version Egret 2.4
  4629. * @platform Web,Native
  4630. * @includeExample extension/game/net/URLLoader.ts
  4631. */
  4632. var URLLoader = (function (_super) {
  4633. __extends(URLLoader, _super);
  4634. /**
  4635. * @language en_US
  4636. * Create an egret.URLLoader object
  4637. * @param request {URLRequest} A URLRequest object specifies the URL to be downloaded.
  4638. * If this parameter is omitted, no load operation begins. If a parameter is specified, the load operation begins immediately
  4639. * @version Egret 2.4
  4640. * @platform Web,Native
  4641. */
  4642. /**
  4643. * @language zh_CN
  4644. * 创建 egret.URLLoader 对象
  4645. * @param request {URLRequest} 一个 URLRequest 对象,指定要下载的 URL。
  4646. * 如果省略该参数,则不开始加载操作。如果已指定参数,则立即开始加载操作
  4647. * @version Egret 2.4
  4648. * @platform Web,Native
  4649. */
  4650. function URLLoader(request) {
  4651. if (request === void 0) { request = null; }
  4652. var _this = _super.call(this) || this;
  4653. /**
  4654. * @language en_US
  4655. * Control whether the downloaded data is received as text (URLLoaderDataFormat.TEXT), raw binary data (URLLoaderDataFormat.BINARY), or URL-encoded variables (URLLoaderDataFormat.VARIABLES).
  4656. * If the value of the dataFormat property is URLLoaderDataFormat.TEXT, the received data is a string containing the text of the loaded file.
  4657. * If the value of the dataFormat property is URLLoaderDataFormat.BINARY, the received data is a ByteArray object containing the raw binary data.
  4658. * If the value of the dataFormat property is URLLoaderDataFormat.TEXTURE, the received data is a Texture object containing the bitmap data.
  4659. * If the value of the dataFormat property is URLLoaderDataFormat.VARIABLES, the received data is a URLVariables object containing the URL-encoded variables.
  4660. * The default value is URLLoaderDataFormat.TEXT.
  4661. * @default egret.URLLoaderDataFormat.TEXT
  4662. * @version Egret 2.4
  4663. * @platform Web,Native
  4664. */
  4665. /**
  4666. * @language zh_CN
  4667. * 控制是以文本 (URLLoaderDataFormat.TEXT)、原始二进制数据 (URLLoaderDataFormat.BINARY) 还是 URL 编码变量 (URLLoaderDataFormat.VARIABLES) 接收下载的数据。
  4668. * 如果 dataFormat 属性的值是 URLLoaderDataFormat.TEXT,则所接收的数据是一个包含已加载文件文本的字符串。
  4669. * 如果 dataFormat 属性的值是 URLLoaderDataFormat.BINARY,则所接收的数据是一个包含原始二进制数据的 ByteArray 对象。
  4670. * 如果 dataFormat 属性的值是 URLLoaderDataFormat.TEXTURE,则所接收的数据是一个包含位图数据的Texture对象。
  4671. * 如果 dataFormat 属性的值是 URLLoaderDataFormat.VARIABLES,则所接收的数据是一个包含 URL 编码变量的 URLVariables 对象。
  4672. * @default egret.URLLoaderDataFormat.TEXT
  4673. * @version Egret 2.4
  4674. * @platform Web,Native
  4675. */
  4676. _this.dataFormat = egret.URLLoaderDataFormat.TEXT;
  4677. /**
  4678. * @language en_US
  4679. * The data received from the load operation. This property is populated only when the load operation is complete. The format of the data depends on the setting of the dataFormat property:
  4680. * If the dataFormat property is URLLoaderDataFormat.TEXT, the received data is a string containing the text of the loaded file.
  4681. * If the dataFormat property is URLLoaderDataFormat.BINARY, the received data is a ByteArray object containing the raw binary data.
  4682. * If the dataFormat property is URLLoaderDataFormat.TEXTURE, the received data is a Texture object containing the bitmap data.
  4683. * If the dataFormat property is URLLoaderDataFormat.VARIABLES, the received data is a URLVariables object containing the URL-encoded variables.
  4684. * @version Egret 2.4
  4685. * @platform Web,Native
  4686. */
  4687. /**
  4688. * @language zh_CN
  4689. * 从加载操作接收的数据。只有完成加载操作时,才会填充该属性。该数据的格式取决于 dataFormat 属性的设置:
  4690. * 如果 dataFormat 属性是 URLLoaderDataFormat.TEXT,则所接收的数据是一个包含已加载文件文本的字符串。
  4691. * 如果 dataFormat 属性是 URLLoaderDataFormat.BINARY,则所接收的数据是一个包含原始二进制数据的 ByteArray 对象。
  4692. * 如果 dataFormat 属性是 URLLoaderDataFormat.TEXTURE,则所接收的数据是一个包含位图数据的Texture对象。
  4693. * 如果 dataFormat 属性是 URLLoaderDataFormat.VARIABLES,则所接收的数据是一个包含 URL 编码变量的 URLVariables 对象。
  4694. * @version Egret 2.4
  4695. * @platform Web,Native
  4696. */
  4697. _this.data = null;
  4698. /**
  4699. * @private
  4700. */
  4701. _this._request = null;
  4702. /**
  4703. * @private
  4704. */
  4705. _this._status = -1;
  4706. if (request) {
  4707. _this.load(request);
  4708. }
  4709. return _this;
  4710. }
  4711. /**
  4712. * @language en_US
  4713. * Send and load data from the specified URL. The data can be received as text, raw binary data, or URL-encoded variables, depending on the value you set for the dataFormat property.
  4714. * Note that the default value of the dataFormat property is text. If you want to send data to the specified URL, you can set the data property in the URLRequest object.
  4715. * @param request {URLRequest} A URLRequest object specifies the URL to be downloaded.
  4716. * @version Egret 2.4
  4717. * @platform Web,Native
  4718. */
  4719. /**
  4720. * @language zh_CN
  4721. * 从指定的 URL 发送和加载数据。可以以文本、原始二进制数据或 URL 编码变量格式接收数据,这取决于为 dataFormat 属性所设置的值。
  4722. * 请注意 dataFormat 属性的默认值为文本。如果想将数据发送至指定的 URL,则可以在 URLRequest 对象中设置 data 属性。
  4723. * @param request {URLRequest} 一个 URLRequest 对象,指定要下载的 URL。
  4724. * @version Egret 2.4
  4725. * @platform Web,Native
  4726. */
  4727. URLLoader.prototype.load = function (request) {
  4728. this._request = request;
  4729. this.data = null;
  4730. egret.NetContext.getNetContext().proceed(this);
  4731. };
  4732. /**
  4733. * @private
  4734. *
  4735. */
  4736. URLLoader.prototype.__recycle = function () {
  4737. this._request = null;
  4738. this.data = null;
  4739. };
  4740. return URLLoader;
  4741. }(egret.EventDispatcher));
  4742. egret.URLLoader = URLLoader;
  4743. __reflect(URLLoader.prototype, "egret.URLLoader");
  4744. })(egret || (egret = {}));