result.js 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. var ResultLayer = cc.Layer.extend({
  2. sprite: null,
  3. ctor: function (score) {
  4. var self = this;
  5. self._super();
  6. self.y = winSize.height;
  7. var isPassed = score >= scoreNeeded;
  8. var isClear = isPassed && curLevel + 1 > Levels.length;
  9. if (isPassed) {
  10. totalScore += score;
  11. }
  12. var title = ccui.Text.create();
  13. title.attr({
  14. anchorY: 1,
  15. color: cc.color(0, 0, 0),
  16. fontSize: 44,
  17. x: winSize.width / 2,
  18. y: -20,
  19. textAlign: cc.TEXT_ALIGNMENT_CENTER,
  20. verticalAlign: cc.VERTICAL_TEXT_ALIGNMENT_TOP,
  21. string: Localize[lang]['level'] + ' ' + curLevel
  22. });
  23. self.addChild(title);
  24. var result = ccui.Text.create();
  25. result.attr({
  26. anchorY: 1,
  27. color: isPassed ? cc.color(110, 168, 232) : cc.color(100, 100, 100),
  28. fontSize: 88,
  29. x: winSize.width / 2,
  30. y: -100,
  31. textAlign: cc.TEXT_ALIGNMENT_CENTER,
  32. verticalAlign: cc.VERTICAL_TEXT_ALIGNMENT_TOP,
  33. string: isClear ? Localize[lang]['clear'] : (isPassed ? Localize[lang]['passed'] : Localize[lang]['failed'])
  34. });
  35. self.addChild(result);
  36. var pointLabel = ccui.Text.create();
  37. pointLabel.attr({
  38. anchorY: 1,
  39. color: cc.color(0, 0, 0),
  40. fontSize: 44,
  41. x: winSize.width / 2,
  42. y: -260,
  43. textAlign: cc.TEXT_ALIGNMENT_CENTER,
  44. verticalAlign: cc.VERTICAL_TEXT_ALIGNMENT_TOP,
  45. string: Localize[lang]['yourScore']
  46. });
  47. self.addChild(pointLabel);
  48. var point = ccui.Text.create();
  49. point.attr({
  50. anchorY: 1,
  51. color: isPassed ? cc.color(252, 68, 69) : cc.color(100, 100, 100),
  52. fontSize: 106,
  53. x: winSize.width / 2,
  54. y: -324,
  55. textAlign: cc.TEXT_ALIGNMENT_CENTER,
  56. verticalAlign: cc.VERTICAL_TEXT_ALIGNMENT_TOP,
  57. string: score
  58. });
  59. self.addChild(point);
  60. var targetLabel = ccui.Text.create();
  61. targetLabel.attr({
  62. anchorY: 0,
  63. color: cc.color(0, 0, 0),
  64. fontSize: 28,
  65. x: winSize.width / 2,
  66. y: -496,
  67. textAlign: cc.TEXT_ALIGNMENT_CENTER,
  68. verticalAlign: cc.VERTICAL_TEXT_ALIGNMENT_BOTTOM,
  69. string: Localize[lang]['scoreNeeded']
  70. });
  71. targetLabel.setTextAreaSize(cc.size(560, winSize.height));
  72. self.addChild(targetLabel);
  73. var target = ccui.Text.create();
  74. target.attr({
  75. anchorY: 1,
  76. color: cc.color(252, 68, 69),
  77. fontSize: 60,
  78. x: winSize.width / 2,
  79. y: -496,
  80. textAlign: cc.TEXT_ALIGNMENT_CENTER,
  81. verticalAlign: cc.VERTICAL_TEXT_ALIGNMENT_TOP,
  82. string: scoreNeeded
  83. });
  84. self.addChild(target);
  85. if (!isPassed) {
  86. SG_Hooks['gameOver'](curLevel, score);
  87. var retryBtn = ccui.Button.create();
  88. retryBtn.setScale9Enabled(true);
  89. retryBtn.setCapInsets(cc.rect(1, 1, 1, 1));
  90. retryBtn.loadTextures(res.btn2, res.btn2, null, texType);
  91. retryBtn.setContentSize(cc.size(360, 90));
  92. retryBtn.setTitleText(Localize[lang]['playAgain']);
  93. retryBtn.setTitleFontSize(44);
  94. retryBtn.setPressedActionEnabled(true);
  95. retryBtn.attr({
  96. x: winSize.width / 2,
  97. y: -603
  98. });
  99. retryBtn.addTouchEventListener(function (sender, type) {
  100. if (type == ccui.Widget.TOUCH_ENDED) {
  101. director.runScene(new GameScene());
  102. }
  103. }, self);
  104. self.addChild(retryBtn);
  105. } else if (!isClear) {
  106. SG_Hooks['levelUp'](curLevel, score);
  107. curLevel++;
  108. var nextBtn = ccui.Button.create();
  109. nextBtn.setScale9Enabled(true);
  110. nextBtn.setCapInsets(cc.rect(1, 1, 1, 1));
  111. nextBtn.loadTextures(res.btn1, res.btn1, null, texType);
  112. nextBtn.setContentSize(cc.size(360, 90));
  113. nextBtn.setTitleText(Localize[lang]['next']);
  114. nextBtn.setTitleFontSize(44);
  115. nextBtn.setPressedActionEnabled(true);
  116. nextBtn.attr({
  117. x: winSize.width / 2,
  118. y: -603
  119. });
  120. nextBtn.addTouchEventListener(function (sender, type) {
  121. if (type == ccui.Widget.TOUCH_ENDED) {
  122. director.runScene(new LevelScene());
  123. }
  124. }, self);
  125. self.addChild(nextBtn);
  126. }
  127. var shopBtn = ccui.Button.create();
  128. shopBtn.setScale9Enabled(true);
  129. shopBtn.setCapInsets(cc.rect(1, 1, 1, 1));
  130. shopBtn.loadTextures(res.btn4, res.btn4, null, texType);
  131. shopBtn.setContentSize(cc.size(288, 70));
  132. shopBtn.setTitleText(Localize[lang]['shop']);
  133. shopBtn.setTitleFontSize(44);
  134. shopBtn.setPressedActionEnabled(true);
  135. shopBtn.attr({
  136. x: winSize.width / 2,
  137. y: -693
  138. });
  139. shopBtn.addTouchEventListener(function (sender, type) {
  140. if (type == ccui.Widget.TOUCH_ENDED) {
  141. director.runScene(new ShopScene());
  142. }
  143. }, self);
  144. self.addChild(shopBtn);
  145. var ua = navigator.userAgent.toLowerCase();
  146. var isWeixin = false;
  147. if (ua.match(/MicroMessenger/i) == "micromessenger") {
  148. isWeixin = true;
  149. }
  150. if (isWeixin) {
  151. var shareBtn = ccui.Button.create();
  152. shareBtn.setScale9Enabled(true);
  153. shareBtn.setCapInsets(cc.rect(1, 1, 1, 1));
  154. shareBtn.loadTextures(res.btn3, res.btn3, null, texType);
  155. shareBtn.setContentSize(cc.size(288, 70));
  156. shareBtn.setTitleText(Localize[lang]['share']);
  157. shareBtn.setTitleFontSize(44);
  158. shareBtn.setPressedActionEnabled(true);
  159. shareBtn.attr({
  160. x: winSize.width / 2,
  161. y: -773
  162. });
  163. shareBtn.addTouchEventListener(function (sender, type) {
  164. if (type == ccui.Widget.TOUCH_ENDED) {
  165. var shareLayer = ccui.Layout.create();
  166. shareLayer.setBackGroundColorType(ccui.Layout.BG_COLOR_SOLID);
  167. shareLayer.setBackGroundColor(cc.color(0, 0, 0));
  168. shareLayer.setBackGroundColorOpacity(128);
  169. shareLayer.setSize(winSize);
  170. shareLayer.attr({
  171. y: -winSize.height,
  172. zIndex: 100,
  173. touchEnabled: true
  174. });
  175. shareLayer.addTouchEventListener(function (sender, type) {
  176. if (type == ccui.Widget.TOUCH_ENDED) {
  177. sender.removeFromParent();
  178. }
  179. }, self);
  180. self.addChild(shareLayer);
  181. var textImage = ccui.ImageView.create();
  182. textImage.loadTexture(res.share, texType);
  183. textImage.attr({
  184. anchorX: 1,
  185. anchorY: 1,
  186. x: winSize.width - 5,
  187. y: winSize.height - 5
  188. });
  189. shareLayer.addChild(textImage);
  190. }
  191. }, self);
  192. self.addChild(shareBtn);
  193. }
  194. return true;
  195. }
  196. });
  197. var ResultScene = cc.Scene.extend({
  198. ctor: function (score) {
  199. this._super();
  200. var layer = new ResultLayer(score);
  201. this.addChild(layer);
  202. }
  203. });