menu.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448
  1. var MenuLayer = cc.Layer.extend({
  2. sprite: null,
  3. ctor: function () {
  4. var self = this;
  5. self._super();
  6. self.y = winSize.height;
  7. var logo = ccui.ImageView.create();
  8. logo.loadTexture(res.logo, texType);
  9. logo.attr({
  10. x: winSize.width / 2,
  11. y: -128
  12. });
  13. self.addChild(logo);
  14. var line = ccui.Layout.create();
  15. line.setBackGroundColorType(ccui.Layout.BG_COLOR_SOLID);
  16. line.setBackGroundColor(cc.color(208, 208, 208));
  17. line.setContentSize(cc.size(496, 2));
  18. line.attr({
  19. x: 72,
  20. y: -221
  21. });
  22. self.addChild(line);
  23. var text = ccui.Text.create();
  24. text.attr({
  25. anchorY: 0,
  26. color: cc.color(40, 127, 91),
  27. fontSize: 40,
  28. x: winSize.width / 2,
  29. y: -596,
  30. textAlign: cc.TEXT_ALIGNMENT_CENTER,
  31. verticalAlign: cc.VERTICAL_TEXT_ALIGNMENT_BOTTOM,
  32. string: Localize[lang]['goal']
  33. });
  34. text.setTextAreaSize(cc.size(408, winSize.height));
  35. self.addChild(text);
  36. var enterBtn = ccui.Button.create();
  37. enterBtn.setScale9Enabled(true);
  38. enterBtn.setCapInsets(cc.rect(1, 1, 1, 1));
  39. enterBtn.loadTextures(res.btn1, res.btn1, null, texType);
  40. enterBtn.setContentSize(cc.size(360, 110));
  41. enterBtn.setTitleText(Localize[lang]['start']);
  42. enterBtn.setTitleFontSize(44);
  43. enterBtn.setPressedActionEnabled(true);
  44. enterBtn.attr({
  45. x: winSize.width / 2,
  46. y: -670
  47. });
  48. enterBtn.addTouchEventListener(function (sender, type) {
  49. if (type == ccui.Widget.TOUCH_ENDED) {
  50. director.runScene(new LevelScene());
  51. }
  52. }, self);
  53. self.addChild(enterBtn);
  54. var shopBtn = ccui.Button.create();
  55. shopBtn.setScale9Enabled(true);
  56. shopBtn.setCapInsets(cc.rect(1, 1, 1, 1));
  57. shopBtn.loadTextures(res.btn4, res.btn4, null, texType);
  58. shopBtn.setContentSize(cc.size(288, 70));
  59. shopBtn.setTitleText(Localize[lang]['shop']);
  60. shopBtn.setTitleFontSize(40);
  61. shopBtn.setPressedActionEnabled(true);
  62. shopBtn.attr({
  63. x: winSize.width / 2,
  64. y: -773
  65. });
  66. shopBtn.addTouchEventListener(function (sender, type) {
  67. if (type == ccui.Widget.TOUCH_ENDED) {
  68. director.runScene(new ShopScene());
  69. }
  70. }, self);
  71. self.addChild(shopBtn);
  72. var tutorialPV = ccui.PageView.create();
  73. tutorialPV.addEventListenerPageView(function (sender, type) {
  74. if (type == ccui.PageView.EVENT_TURNING) {
  75. for (var i = 0; i < dots.length; i++) {
  76. var dot = dots[i];
  77. if (dot.name == 'dot' + sender.getCurPageIndex()) {
  78. dots[i].loadTexture(res.dot_current, texType);
  79. } else {
  80. dots[i].loadTexture(res.dot, texType);
  81. }
  82. }
  83. }
  84. }, self);
  85. tutorialPV.y = -winSize.height;
  86. tutorialPV.setSize(winSize);
  87. var page1 = ccui.Layout.create();
  88. page1.setBackGroundColorType(ccui.Layout.BG_COLOR_SOLID);
  89. page1.setBackGroundColor(cc.color(246, 246, 246));
  90. tutorialPV.addPage(page1);
  91. var p1Bar = ccui.Layout.create();
  92. p1Bar.setBackGroundColorType(ccui.Layout.BG_COLOR_SOLID);
  93. p1Bar.setBackGroundColor(cc.color(111, 168, 233));
  94. p1Bar.setSize(cc.size(winSize.width, 100));
  95. p1Bar.y = winSize.height - 137;
  96. page1.addChild(p1Bar);
  97. var p1Title = ccui.Text.create();
  98. p1Title.attr({
  99. color: cc.color(255, 255, 255),
  100. fontSize: 40,
  101. x: winSize.width / 2,
  102. y: 50,
  103. textAlign: cc.TEXT_ALIGNMENT_CENTER,
  104. verticalAlign: cc.VERTICAL_TEXT_ALIGNMENT_CENTER,
  105. string: Localize[lang]['htp']
  106. });
  107. p1Bar.addChild(p1Title);
  108. var p1Logo = ccui.ImageView.create();
  109. p1Logo.loadTexture(res.logo, texType);
  110. p1Logo.attr({
  111. x: winSize.width / 2,
  112. y: 468
  113. });
  114. page1.addChild(p1Logo);
  115. var sgLogo = ccui.ImageView.create();
  116. sgLogo.loadTexture(res.logo_ingame);
  117. sgLogo.attr({
  118. x: winSize.width / 2,
  119. y: 55,
  120. touchEnabled: true
  121. });
  122. sgLogo.addTouchEventListener(function (sender, type) {
  123. if (type == ccui.Widget.TOUCH_ENDED) {
  124. window.location.href = 'http://m.softgames.de';
  125. }
  126. }, page1);
  127. page1.addChild(sgLogo);
  128. var page2 = ccui.Layout.create();
  129. page2.setBackGroundColorType(ccui.Layout.BG_COLOR_SOLID);
  130. page2.setBackGroundColor(cc.color(246, 246, 246));
  131. tutorialPV.addPage(page2);
  132. var p2Bar = ccui.Layout.create();
  133. p2Bar.setBackGroundColorType(ccui.Layout.BG_COLOR_SOLID);
  134. p2Bar.setBackGroundColor(cc.color(111, 168, 233));
  135. p2Bar.setSize(cc.size(winSize.width, 100));
  136. p2Bar.y = winSize.height - 137;
  137. page2.addChild(p2Bar);
  138. var p2Title = ccui.Text.create();
  139. p2Title.attr({
  140. color: cc.color(255, 255, 255),
  141. fontSize: 40,
  142. x: winSize.width / 2,
  143. y: 50,
  144. textAlign: cc.TEXT_ALIGNMENT_CENTER,
  145. verticalAlign: cc.VERTICAL_TEXT_ALIGNMENT_CENTER,
  146. string: Localize[lang]['htp2']
  147. });
  148. p2Title.setTextAreaSize(cc.size(600, winSize.height));
  149. p2Bar.addChild(p2Title);
  150. var p2Pic = ccui.ImageView.create();
  151. p2Pic.loadTexture(res.htp2, texType);
  152. p2Pic.attr({
  153. x: winSize.width / 2,
  154. y: 390
  155. });
  156. page2.addChild(p2Pic);
  157. var page3 = ccui.Layout.create();
  158. page3.setBackGroundColorType(ccui.Layout.BG_COLOR_SOLID);
  159. page3.setBackGroundColor(cc.color(246, 246, 246));
  160. tutorialPV.addPage(page3);
  161. var p3Bar = ccui.Layout.create();
  162. p3Bar.setBackGroundColorType(ccui.Layout.BG_COLOR_SOLID);
  163. p3Bar.setBackGroundColor(cc.color(111, 168, 233));
  164. p3Bar.setSize(cc.size(winSize.width, 100));
  165. p3Bar.y = winSize.height - 137;
  166. page3.addChild(p3Bar);
  167. var p3Title = ccui.Text.create();
  168. p3Title.attr({
  169. color: cc.color(255, 255, 255),
  170. fontSize: 40,
  171. x: winSize.width / 2,
  172. y: 50,
  173. textAlign: cc.TEXT_ALIGNMENT_CENTER,
  174. verticalAlign: cc.VERTICAL_TEXT_ALIGNMENT_CENTER,
  175. string: Localize[lang]['htp31']
  176. });
  177. p3Bar.addChild(p3Title);
  178. var p3Bar1 = ccui.Layout.create();
  179. p3Bar1.setBackGroundColorType(ccui.Layout.BG_COLOR_SOLID);
  180. p3Bar1.setBackGroundColor(cc.color(39, 205, 137));
  181. p3Bar1.setSize(cc.size(winSize.width, 60));
  182. p3Bar1.y = winSize.height - 197;
  183. page3.addChild(p3Bar1);
  184. var p3Title1 = ccui.Text.create();
  185. p3Title1.attr({
  186. color: cc.color(255, 255, 255),
  187. fontSize: 28,
  188. x: winSize.width / 2,
  189. y: 30,
  190. textAlign: cc.TEXT_ALIGNMENT_CENTER,
  191. verticalAlign: cc.VERTICAL_TEXT_ALIGNMENT_CENTER,
  192. string: Localize[lang]['htp32']
  193. });
  194. p3Bar1.addChild(p3Title1);
  195. var p3Pic = ccui.ImageView.create();
  196. p3Pic.loadTexture(res.htp3, texType);
  197. p3Pic.attr({
  198. x: winSize.width / 2,
  199. y: 390
  200. });
  201. page3.addChild(p3Pic);
  202. var page4 = ccui.Layout.create();
  203. page4.setBackGroundColorType(ccui.Layout.BG_COLOR_SOLID);
  204. page4.setBackGroundColor(cc.color(246, 246, 246));
  205. tutorialPV.addPage(page4);
  206. var p4Bar = ccui.Layout.create();
  207. p4Bar.setBackGroundColorType(ccui.Layout.BG_COLOR_SOLID);
  208. p4Bar.setBackGroundColor(cc.color(111, 168, 233));
  209. p4Bar.setSize(cc.size(winSize.width, 100));
  210. p4Bar.y = winSize.height - 137;
  211. page4.addChild(p4Bar);
  212. var p4Title = ccui.Text.create();
  213. p4Title.attr({
  214. color: cc.color(255, 255, 255),
  215. fontSize: 40,
  216. x: winSize.width / 2,
  217. y: 50,
  218. textAlign: cc.TEXT_ALIGNMENT_CENTER,
  219. verticalAlign: cc.VERTICAL_TEXT_ALIGNMENT_CENTER,
  220. string: Localize[lang]['tools']
  221. });
  222. p4Title.setTextAreaSize(cc.size(600, winSize.height));
  223. p4Bar.addChild(p4Title);
  224. var stopIcon = ccui.ImageView.create();
  225. stopIcon.loadTexture(res.stop, texType);
  226. stopIcon.attr({
  227. x: 107,
  228. y: 592
  229. });
  230. page4.addChild(stopIcon);
  231. var stopText = ccui.Text.create();
  232. stopText.attr({
  233. anchorX: 0,
  234. color: cc.color(150, 150, 150),
  235. fontSize: 22,
  236. x: 172,
  237. y: 590,
  238. textAlign: cc.TEXT_ALIGNMENT_LEFT,
  239. verticalAlign: cc.VERTICAL_TEXT_ALIGNMENT_CENTER,
  240. string: Localize[lang]['stop']
  241. });
  242. stopText.setTextAreaSize(cc.size(400, 70));
  243. page4.addChild(stopText);
  244. var singleIcon = ccui.ImageView.create();
  245. singleIcon.loadTexture(res.single, texType);
  246. singleIcon.attr({
  247. x: 107,
  248. y: 452
  249. });
  250. page4.addChild(singleIcon);
  251. var singleText = ccui.Text.create();
  252. singleText.attr({
  253. anchorX: 0,
  254. color: cc.color(150, 150, 150),
  255. fontSize: 22,
  256. x: 172,
  257. y: 448,
  258. textAlign: cc.TEXT_ALIGNMENT_LEFT,
  259. verticalAlign: cc.VERTICAL_TEXT_ALIGNMENT_CENTER,
  260. string: Localize[lang]['single1']
  261. });
  262. singleText.setTextAreaSize(cc.size(400, 70));
  263. page4.addChild(singleText);
  264. var sameIcon = ccui.ImageView.create();
  265. sameIcon.loadTexture(res.same, texType);
  266. sameIcon.attr({
  267. x: 107,
  268. y: 312
  269. });
  270. page4.addChild(sameIcon);
  271. var sameText = ccui.Text.create();
  272. sameText.attr({
  273. anchorX: 0,
  274. color: cc.color(150, 150, 150),
  275. fontSize: 22,
  276. x: 172,
  277. y: 306,
  278. textAlign: cc.TEXT_ALIGNMENT_LEFT,
  279. verticalAlign: cc.VERTICAL_TEXT_ALIGNMENT_CENTER,
  280. string: Localize[lang]['same']
  281. });
  282. sameText.setTextAreaSize(cc.size(400, 70));
  283. page4.addChild(sameText);
  284. var beginBtn = ccui.Button.create();
  285. beginBtn.setScale9Enabled(true);
  286. beginBtn.setCapInsets(cc.rect(1, 1, 1, 1));
  287. beginBtn.loadTextures(res.btn3, res.btn3, null, texType);
  288. beginBtn.setContentSize(cc.size(216, 66));
  289. beginBtn.setTitleText(Localize[lang]['begin']);
  290. beginBtn.setTitleFontSize(40);
  291. beginBtn.setPressedActionEnabled(true);
  292. beginBtn.attr({
  293. x: winSize.width / 2,
  294. y: 74
  295. });
  296. beginBtn.addTouchEventListener(function (sender, type) {
  297. if (type == ccui.Widget.TOUCH_ENDED) {
  298. for (var i = 0; i < dots.length; i++) {
  299. dots[i].removeFromParent();
  300. }
  301. tutorialPV.removeFromParent();
  302. pageBtn.removeFromParent();
  303. }
  304. }, self);
  305. page4.addChild(beginBtn);
  306. self.addChild(tutorialPV);
  307. //add prevBtn nextBtn
  308. function IsPC() {
  309. var userAgentInfo = navigator.userAgent;
  310. var Agents = new Array("Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod");
  311. var flag = true;
  312. for (var v = 0; v < Agents.length; v++) {
  313. if (userAgentInfo.indexOf(Agents[v]) > 0) {
  314. flag = false;
  315. break;
  316. }
  317. }
  318. return flag;
  319. }
  320. var isPC = IsPC();
  321. var pageBtn = ccui.Layout.create();
  322. pageBtn.setSize(cc.size(winSize.width, 60));
  323. pageBtn.attr({
  324. y: -winSize.height / 2,
  325. zIndex: 100,
  326. touchEnabled: true
  327. });
  328. var nextBtn = ccui.ImageView.create();
  329. nextBtn.loadTexture(res.right);
  330. nextBtn.attr({
  331. x: winSize.width - 40,
  332. y: 30,
  333. touchEnabled: true
  334. });
  335. var prevBtn = ccui.ImageView.create();
  336. prevBtn.loadTexture(res.left);
  337. prevBtn.attr({
  338. x: 40,
  339. y: 30,
  340. touchEnabled: true
  341. });
  342. if (isPC) {
  343. pageBtn.addChild(nextBtn);
  344. pageBtn.addChild(prevBtn);
  345. prevBtn.visible = false;
  346. nextBtn.addTouchEventListener(function (sender, type) {
  347. if (type == ccui.Widget.TOUCH_ENDED) {
  348. tutorialPV.scrollToPage(tutorialPV.getCurPageIndex() + 1);
  349. if (tutorialPV.getCurPageIndex() == 1) {
  350. prevBtn.visible = true;
  351. } else if (tutorialPV.getCurPageIndex() == 3) {
  352. nextBtn.visible = false;
  353. }
  354. }
  355. }, pageBtn);
  356. prevBtn.addTouchEventListener(function (sender, type) {
  357. if (type == ccui.Widget.TOUCH_ENDED) {
  358. tutorialPV.scrollToPage(tutorialPV.getCurPageIndex() - 1);
  359. if (tutorialPV.getCurPageIndex() == 2) {
  360. nextBtn.visible = true;
  361. } else if (tutorialPV.getCurPageIndex() == 0) {
  362. prevBtn.visible = false;
  363. }
  364. }
  365. }, pageBtn);
  366. self.addChild(pageBtn);
  367. }
  368. //add ending
  369. var pageLen = tutorialPV.getPages().length, dots = [];
  370. var dotWidth = 48 * pageLen + (pageLen - 1) * 24;
  371. for (var i = 0; i < pageLen; i++) {
  372. var dot = ccui.ImageView.create();
  373. dot.loadTexture(i == 0 ? res.dot_current : res.dot, texType);
  374. dot.attr({
  375. name: 'dot' + i,
  376. x: winSize.width / 2 - dotWidth / 2 + 24 + i * 72,
  377. y: -winSize.height + 144
  378. });
  379. self.addChild(dot);
  380. dots.push(dot);
  381. }
  382. return true;
  383. }
  384. });
  385. var MenuScene = cc.Scene.extend({
  386. onEnter: function () {
  387. this._super();
  388. var layer = new MenuLayer();
  389. this.addChild(layer);
  390. }
  391. });