landingMode.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. function LandingMode (playMode) {
  2. let that = {};
  3. let btn_size = 297 * 0.5;
  4. let text_size = 80 * 0.5;
  5. let dropdown_select_lang_w = 200;
  6. let dropdown_select_lang_h = 45;
  7. let videofenbianlv = 1080/1080;
  8. let canvas;
  9. let ctx;
  10. let badgeImg;
  11. let scale;
  12. let intro_sptire;
  13. let spriteIntroImg;
  14. let introVideo;
  15. let intro_sprite_w = 830;
  16. let circle_mask_intro = intro_sprite_w*0.5 ;
  17. let header_scale = 0.1;
  18. that.resizeWindow = function() {
  19. width = window.innerWidth;
  20. height = window.innerHeight;
  21. canvas.width = width*devicescreenratio;
  22. canvas.height = height*devicescreenratio;
  23. canvas.style.width = width + "px";
  24. canvas.style.height = height + "px";
  25. canvas.getContext("2d").setTransform(devicescreenratio, 0, 0, devicescreenratio, 0, 0);
  26. c = {x: width / 2.0, y: height / 2.0 };
  27. degree = -90;
  28. scale = width / height > 1.77778 ? height / (2160 * 0.5) : width / (3840 * 0.5);
  29. }
  30. that.setup = function () {
  31. canvas = document.getElementById('canvas');
  32. ctx = canvas.getContext('2d');
  33. that.showUI();
  34. headerImg = new Image();
  35. headerImg.onload = function() {};
  36. headerImg.src = $.i18n('header_img');
  37. badgeImg = new Image();
  38. badgeImg.onload = function() {};
  39. badgeImg.src = "content/ui/ai_experiment.svg";
  40. // shadowArtTextImg = new Image();
  41. // shadowArtTextImg.onload = function(){}
  42. // shadowArtTextImg.src = "content/ui/shadow_art.png";
  43. shadowCircleImg = new Image();
  44. shadowCircleImg.onload = function(){}
  45. shadowCircleImg.src = "content/ui/circle_shadow_art.png";
  46. introVideo = $('<video muted src="content/zodiac_sprite/common/zh-cn/rat.mp4" control="false" playsinline="true"></video>')
  47. introVideo[0].addEventListener('canplay', function () {
  48. intro_sptire = new sprite({
  49. context: ctx,
  50. width: this.width,
  51. height: this.height,
  52. drawWidth: intro_sprite_w,
  53. drawHeight: intro_sprite_w,
  54. workVideo: introVideo,
  55. numberOfFrames: this.width / this.height,
  56. ticksPerFrame: 2,
  57. scale: 1.0
  58. })
  59. })
  60. that.setOnJqueryClickListener();
  61. }
  62. that.setResultImage = function(id, score) {
  63. shadowCircleImg = new Image();
  64. shadowCircleImg.onload = function(){}
  65. shadowCircleImg.src = "content/ui/circle_02.png";
  66. }
  67. that.update = function() {
  68. that.resizeWindow();
  69. let btn_scaled_size = btn_size * scale
  70. let btn_play_pos_x = width * 0.96 - btn_scaled_size;
  71. let btn_play_pos_y = height * 0.92 - btn_scaled_size
  72. $('#btn_play').width(btn_scaled_size);
  73. $('#btn_play').height(btn_scaled_size);
  74. $('#btn_play').offset({top: btn_play_pos_y , left: btn_play_pos_x});
  75. let scaled_dropdown_select_lang_w = dropdown_select_lang_w * scale;
  76. let scaled_dropdown_select_lang_h = dropdown_select_lang_h * scale;
  77. $('#dropdown_select_lang').width(scaled_dropdown_select_lang_w);
  78. $('#dropdown_select_lang').height(scaled_dropdown_select_lang_h);
  79. $('#dropdown_select_lang').offset({top: Math.floor(btn_play_pos_y + btn_scaled_size*0.5 - scaled_dropdown_select_lang_h * 0.5), left: Math.floor(btn_play_pos_x - scaled_dropdown_select_lang_w*1.1) });
  80. let privacy_link_w = $('.intro__footer-link--right').width();
  81. $('.intro__footer-link--right').offset({top: btn_play_pos_y + btn_scaled_size * 0.5 + scaled_dropdown_select_lang_h * 0.5, left: btn_play_pos_x - scaled_dropdown_select_lang_w*1.1});
  82. if(intro_sptire) {
  83. intro_sptire.update();
  84. }
  85. // $('#btn_practice').width(btn_scaled_size);
  86. // $('#btn_practice').height(btn_scaled_size);
  87. // $('#btn_practice').offset({top: height*0.96 - btn_scaled_size, left: width- 80* scale - (btn_scaled_size * 0.5)});
  88. }
  89. that.draw = function() {
  90. that.drawBg();
  91. that.drawShadowCircle();
  92. // that.drawBadge();
  93. that.drawDescriptionText();
  94. }
  95. that.drawBg = function() {
  96. ctx.save();
  97. ctx.drawImage(bg_img, 0, 0, width, height);
  98. ctx.restore();
  99. }
  100. that.drawBadge = function() {
  101. ctx.save();
  102. ctx.translate(width*0.04, height*0.925 );
  103. ctx.beginPath();
  104. ctx.fillStyle = "black"
  105. ctx.drawImage(badgeImg, 0, - badgeImg.height * scale , badgeImg.width* scale , badgeImg.height* scale );
  106. ctx.fill();
  107. ctx.closePath();
  108. ctx.restore();
  109. }
  110. that.drawShadowCircle = function() {
  111. if(intro_sptire) {
  112. ctx.save();
  113. ctx.translate(c.x, height * 0.535);
  114. ctx.beginPath();
  115. ctx.fillStyle = "white";
  116. ctx.arc(0, 0, circle_mask_intro * scale, 0 , 2* Math.PI);
  117. ctx.clip();
  118. ctx.fill();
  119. ctx.translate(-intro_sprite_w *0.5 * scale * videofenbianlv, -intro_sprite_w *0.5 * scale);
  120. intro_sptire.render();
  121. intro_sptire.drawWidth = intro_sprite_w *scale ;
  122. intro_sptire.drawHeight = intro_sprite_w * scale ;
  123. ctx.restore();
  124. ctx.closePath();
  125. ctx.restore();
  126. }
  127. }
  128. that.drawDescriptionText = function(){
  129. ctx.save();
  130. let fontSize = text_size * scale;
  131. ctx.save();
  132. ctx.translate(c.x, (height * 0.535 - circle_mask_intro * scale)/2.0);
  133. let headerLocalizationScale = parseFloat($.i18n('header_img_scale'));
  134. let headerScaleW = headerImg.width *scale * headerLocalizationScale;
  135. let headerScaleH = headerImg.height *scale * headerLocalizationScale;
  136. ctx.drawImage(headerImg , -headerScaleW , -headerScaleH , headerScaleW * 2 , headerScaleH * 2) ;
  137. ctx.restore();
  138. }
  139. that.setOnJqueryClickListener = function() {
  140. $("#btn_practice").on('click', function(){
  141. mode = ENUM_MODE.PRACTICE;
  142. that.hideUI();
  143. });
  144. $("#btn_play").on('click', function(){
  145. if(isAndroid && !iOS && isChrome) {
  146. document.body.requestFullscreen();
  147. }
  148. playMode.preLoader();
  149. selectMode.selectShowUI();
  150. that.hideUI();
  151. $('#bgm').addClass('bgmplay')
  152. g_bgm.play()
  153. });
  154. }
  155. that.hideUI = function() {
  156. $("#btn_practice").hide();
  157. $("#btn_play").hide();
  158. $('.intro__footer-link--right ').hide();
  159. $('#dropdown_select_lang').hide();
  160. }
  161. that.showUI = function() {
  162. $("#btn_play").show();
  163. $('.intro__footer-link--right ').show();
  164. $('#dropdown_select_lang').show();
  165. }
  166. return that;
  167. }