endMode.js 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. function EndMode () {
  2. let zodiac_animal_list = ["Rat", "Ox", "Tiger", "Rabbit", "Dragon", "Snake", "Horse", "Goat", "Monkey", "Rooster", "Dog", "Pig"];
  3. let that = {};
  4. let id_ = 0;
  5. let score_ = 0;
  6. var isCompleted = false;
  7. let btn_size = 152;
  8. let play_timer = 0;
  9. let timerBgImg ;
  10. //responsive stuffs;
  11. let canvas;
  12. let ctx;
  13. let scale;
  14. let baseWidth = 3840 * 0.5;
  15. let baseHeight = 2160 * 0.5;
  16. let baseRatio = baseWidth/baseHeight;
  17. let outDoYourSelfTextSize = 60 * 0.5;
  18. let timerTextSize = 135 * 0.5;
  19. let resultTextSize = 135 * 0.5;
  20. let imageDescriptionTextSize = 55 * 0.5;
  21. let btnSize = 297 * 0.5;
  22. let btnSocialSize = 96;
  23. let resultImageSpacialScale = 2.3 * 0.5;
  24. let posL = 0.3;
  25. let posR = 0.7;
  26. that.resizeWindow = function() {
  27. canvas.width = window.innerWidth*devicescreenratio;
  28. canvas.height = window.innerHeight*devicescreenratio;
  29. canvas.style.width = window.innerWidth + "px";
  30. canvas.style.height = window.innerHeight + "px";
  31. ctx.setTransform(devicescreenratio, 0, 0, devicescreenratio, 0, 0);
  32. width = window.innerWidth;
  33. height = window.innerHeight;
  34. c = {x: width / 2.0, y: height / 2.0 };
  35. degree = -90;
  36. scale = width / height > baseRatio ? height / baseHeight : width / baseWidth;
  37. }
  38. that.setup = function () {
  39. score_ = 0;
  40. canvas = document.getElementById('canvas');
  41. ctx = canvas.getContext('2d');
  42. that.setOnJqueryClickListener();
  43. summaryImg = new Image();
  44. summaryImg.onload = function(){}
  45. summaryImg.src = "content/ui/summary.png";
  46. playagainImg = new Image();
  47. playagainImg.onload = function(){}
  48. playagainImg.src = "content/ui/play_again.png";
  49. // that.setResults(11,12,121);
  50. }
  51. that.update = function() {
  52. that.resizeWindow();
  53. }
  54. that.setResults = function(id, score, gamePlayTimer,isNoZodiac) {
  55. if (!isCompleted && $('#bgm').is('.bgmplay')) {
  56. action_music.pause()
  57. action_music.src = './audio/fail.mp3'
  58. action_music.loop=false
  59. action_music.play()
  60. }
  61. if(score >= 12) {
  62. score = 12;
  63. isCompleted = true;
  64. } else {
  65. isCompleted = true;
  66. }
  67. // play_timer = ("0"+Math.floor(gamePlayTimer/60)).slice(-2) +":" + ("0"+Math.floor(gamePlayTimer)%60).slice(-2);
  68. score_ = score;
  69. id_ = id;
  70. resultImage = new Image();
  71. resultImage.onload = function() {}
  72. if (isNoZodiac) {
  73. if ($('#end_tips').css('display') == 'none') {
  74. }
  75. $('#end_tips').html($.i18n('end_tips')).show()
  76. $('#btn_save').hide()
  77. }else{
  78. resultImage.src = "content/shareImages/"+ lang +"/img_"+id+"_"+0+".png";
  79. $('#success_end').html($.i18n('success_end', score)).show()
  80. }
  81. loadList(id,score,(data)=>{
  82. console.log(data);
  83. let {key,active} = data
  84. if (active=='normal') {
  85. return
  86. }
  87. id_ = key;
  88. resultImage = new Image();
  89. resultImage.onload = function() {}
  90. // resultImage.src = "content/shareImages/"+ lang +"/img_"+id_+"_"+score+".png";
  91. resultImage.src = "content/shareImages/"+ lang +"/img_"+id_+"_"+0+".png";
  92. })
  93. }
  94. that.draw = function() {
  95. that.drawBg();
  96. that.drawResultImage();
  97. that.drawResultDetails();
  98. }
  99. that.drawBg = function() {
  100. ctx.save();
  101. ctx.drawImage(bg_img, 0, 0, width, height);
  102. ctx.restore();
  103. }
  104. that.drawResultImage = function() {
  105. ctx.save();
  106. let imgW = resultImage.width * scale * resultImageSpacialScale ;
  107. let imgH = resultImage.height * scale * resultImageSpacialScale ;
  108. ctx.drawImage(resultImage, c.x - imgW * 0.5, c.y - imgH * 0.6 , imgW, imgH);
  109. ctx.restore();
  110. }
  111. that.drawResultDetails = function(){
  112. let btnScaledSize = btnSize * scale ;
  113. $('#btn_play_end').show();
  114. $('#play_again_btn').hide();
  115. // that.drawTextUncompleted();
  116. $('#btn_play_end').width(btnScaledSize);
  117. $('#btn_play_end').height(btnScaledSize);
  118. $('#btn_play_end').css({top: height*0.82 - btnScaledSize, left: width *0.952 - btnScaledSize });
  119. $('#bgm').css({bottom: '19vh'});
  120. let btnSocialScaledSize = (btnSocialSize * scale) * 0.85;
  121. // if(lang == 'zh-cn'){
  122. // $('#btn_save').width(btnSocialScaledSize);
  123. // $('#btn_save').height(btnSocialScaledSize);
  124. // $('#btn_save').css({top: height*0.80 - btnScaledSize, left: width * 0.935 - btnSocialScaledSize });
  125. // }else {
  126. // $('#btn_twitter').width(btnSocialScaledSize);
  127. // $('#btn_twitter').height(btnSocialScaledSize);
  128. // $('#btn_twitter').css({top: height*0.80 - btnScaledSize, left: width * 0.935 - btnSocialScaledSize });
  129. // $('#btn_fb').width(btnSocialScaledSize);
  130. // $('#btn_fb').height(btnSocialScaledSize);
  131. // $('#btn_fb').css({top: height*0.70 - btnScaledSize, left: width * 0.935 - btnSocialScaledSize });
  132. $('#btn_save').width(btnSocialScaledSize);
  133. $('#btn_save').height(btnSocialScaledSize);
  134. $('#btn_save').css({top: height*0.60 - btnScaledSize, left: width * 0.935 - btnSocialScaledSize });
  135. // }
  136. }
  137. that.drawTextUncompleted = function() {
  138. ctx.save();
  139. ctx.translate( c.x, c.y * 0.35);
  140. let h = resultTextSize * scale;
  141. ctx.fillStyle ='rgb(172, 102, 82)';
  142. ctx.font = h+"px " + $.i18n('fonts_primary');
  143. ctx.textAlign = "center";
  144. ctx.fillText($.i18n('unlock_animal', score_), 0 , h*-1)
  145. ctx.restore();
  146. }
  147. that.drawTextCompleted = function() {
  148. let text_01 = "You've completed";
  149. let text_02 = "the zodiac cycle in";
  150. ctx.save();
  151. ctx.translate( c.x , c.y * 0.35);
  152. let h = resultTextSize * scale;
  153. ctx.fillStyle ='rgb(172, 102, 82)';
  154. ctx.font = h+"px " + $.i18n('fonts_primary');
  155. ctx.textAlign = "center";
  156. ctx.fillText($.i18n('completing_all_12_animals', play_timer), 0 , h*-1);
  157. ctx.restore();
  158. }
  159. that.checkCompleted = function() {
  160. return isCompleted
  161. }
  162. that.hideUI = function() {
  163. $('#play_again_btn').hide();
  164. $('#btn_play_end').hide();
  165. }
  166. that.save_img = function (on_click_ref) {
  167. let download_url = getFullPathURL() + "content/shareImages/" +lang;
  168. $(on_click_ref).attr('href', download_url + '/img_'+id_+'_'+0+'.png');
  169. $(on_click_ref).attr('download', 'capital museum.china.png');
  170. }
  171. // that.share_to_facebook = function(on_click_ref) {
  172. // let fb_end_point_url = 'https://www.facebook.com/sharer/sharer.php?u=';
  173. // let html_share_url = getFullPathURL() + "content/htmlSocialSharing/" +lang;
  174. // $(on_click_ref).attr('href', fb_end_point_url + html_share_url + '/img_'+id_+'_'+score_+'.html');
  175. // $(on_click_ref).attr('target', '_blank');
  176. // }
  177. // that.share_to_twitter = function(on_click_ref) {
  178. // let twitter_end_point_url = "https://twitter.com/intent/tweet?url=";
  179. // let html_share_url = getFullPathURL() + "content/htmlSocialSharing/" +lang;
  180. // $(on_click_ref).attr('href', twitter_end_point_url + html_share_url + '/img_'+id_+'_'+score_+'.html');
  181. // $(on_click_ref).attr('target', '_blank');
  182. // }
  183. that.get_proverb = function(animal_index, score) {
  184. var intro = [$.i18n('unlock_animal', score)];
  185. var out = intro.concat(proverbs[animal_index].split("|"));
  186. return out;
  187. }
  188. that.setOnJqueryClickListener = function() {
  189. $('#play_again_btn').click('on', function(){
  190. location.reload();
  191. });
  192. $("#btn_play_end").on('click', function(){
  193. location.reload();
  194. });
  195. $('#btn_save').on('click', function(){
  196. that.save_img(this);
  197. });
  198. $('#btn_fb').on('click touchstart', function(){
  199. that.share_to_facebook(this);
  200. });
  201. $('#btn_twitter').on('click touchstart', function(){
  202. that.share_to_twitter(this);
  203. });
  204. }
  205. return that;
  206. }