GradeReward.ts 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. import JsbSystem from "../../../mk/system/JsbSystem";
  2. import { UITween } from "../../component/tween/UITween";
  3. import { DataEventId, ExpAddType, VideoAdType } from "../../data/GameData";
  4. import { GradeRewardItem } from "./GradeRewardItem";
  5. const { ccclass, property } = cc._decorator;
  6. @ccclass
  7. export class GradeReward extends cc.Component {
  8. @property({ displayName: "进度条", type: cc.Sprite })
  9. private sp_slider: cc.Sprite = null;
  10. @property({ displayName: "内容节点", type: cc.Node })
  11. private node_content: cc.Node = null;
  12. @property(cc.Prefab)
  13. private node_child: cc.Prefab = null;
  14. @property({ displayName: '进度文本', type: cc.Label })
  15. private lbl_progress: cc.Label[] = [];
  16. private gradeExp: number[] = [];
  17. private curExp: number = 0;
  18. private gradeOffset: number[] = [0.11, 0.33, 0.56, 0.78, 1];
  19. private gradeItemArr: GradeRewardItem[] = [];
  20. onLoad(){
  21. }
  22. start(){
  23. if(gData.gameData.playerProp.farmGradeData)
  24. {
  25. let len = gData.gameData.playerProp.farmGradeData.farmGradeRewardList.length;
  26. for(let i = len; i != 0; --i)
  27. {
  28. let data = gData.gameData.playerProp.farmGradeData.farmGradeRewardList[i-1];
  29. let child = cc.instantiate(this.node_child);
  30. let item = child.getComponent(GradeRewardItem);
  31. item.setData(data);
  32. this.node_content.addChild(child);
  33. this.gradeItemArr.push(item);
  34. }
  35. }
  36. // for(let i = 5; i != 0; --i)
  37. // {
  38. // let child = cc.instantiate(this.node_child);
  39. // let item = child.getComponent(GradeRewardItem);
  40. // item.id = i;
  41. // item.lbl_value.string = "0.3元";
  42. // item.lbl_grade.string = "LV:12";
  43. // this.node_content.addChild(child);
  44. // }
  45. this.calulateExpAndShowUI2();
  46. }
  47. update(dt)
  48. {
  49. if(gData.farmGradeData.changeExp)
  50. {
  51. this.calulateExpAndShowUI2();
  52. this.freshFramGradeData();
  53. gData.farmGradeData.changeExp = false;
  54. }
  55. }
  56. private freshFramGradeData()
  57. {
  58. let len = this.gradeItemArr.length;
  59. for(let i = 0 ; i != len; ++i)
  60. {
  61. let data = gData.gameData.playerProp.farmGradeData.farmGradeRewardList[len-1-i];
  62. this.gradeItemArr[i].setData(data);
  63. this.gradeItemArr[i].changeBtnState();
  64. }
  65. }
  66. private calulateExpAndShowUI()
  67. {
  68. this.curExp = gData.gameData.playerProp.farmExpValue;
  69. let curIndex = -1;
  70. for (let i = 0; i != this.gradeExp.length; ++i) {
  71. if (this.curExp < this.gradeExp[i]) {
  72. if (curIndex == -1) {
  73. curIndex = i;
  74. } else {
  75. this.lbl_progress[i].string = "0%";
  76. }
  77. } else {
  78. this.lbl_progress[i].string = "100%";
  79. }
  80. }
  81. if (curIndex != -1) {
  82. let remainExp = this.curExp;
  83. for (let i = 0; i != curIndex; ++i) {
  84. remainExp = this.curExp - this.gradeExp[i];
  85. }
  86. let per = Math.floor(remainExp / this.gradeExp[curIndex] * 100);
  87. this.lbl_progress[curIndex].string = per + "%";
  88. let lastIndex = -1
  89. let lastPro = 0;
  90. if (curIndex > 0) {
  91. lastIndex = curIndex - 1;
  92. }
  93. let offset = this.gradeOffset[curIndex];
  94. if (lastIndex != -1) {
  95. offset = offset - this.gradeOffset[lastIndex];
  96. lastPro = this.gradeOffset[lastIndex];
  97. }
  98. let pro = offset * per / 100;
  99. this.sp_slider.fillRange = lastPro + pro;
  100. } else {
  101. this.sp_slider.fillRange = 1;
  102. }
  103. }
  104. private calulateExpAndShowUI2()
  105. {
  106. let curIndex = -1;
  107. let curPer = 0;
  108. let len = gData.gameData.playerProp.farmGradeData.farmGradeRewardList.length;
  109. for(let i = 0; i != len; ++i)
  110. {
  111. let per = gData.gameData.playerProp.farmGradeData.farmGradeRewardList[i].progressRate;
  112. this.lbl_progress[i].string = Math.round(per * 100) + '%';
  113. if(curIndex == -1)
  114. {
  115. if(per < 1)
  116. {
  117. curIndex = i;
  118. curPer = per;
  119. }
  120. }
  121. }
  122. if(curIndex != -1)
  123. {
  124. let lastIndex = -1
  125. let lastPro = 0;
  126. if(curIndex > 0)
  127. {
  128. lastIndex = curIndex-1;
  129. }
  130. let offset = this.gradeOffset[curIndex];
  131. if(lastIndex != -1)
  132. {
  133. offset = offset - this.gradeOffset[lastIndex];
  134. lastPro = this.gradeOffset[lastIndex];
  135. }
  136. let pro = offset * curPer;
  137. this.sp_slider.fillRange = lastPro + pro;
  138. }else
  139. {
  140. this.sp_slider.fillRange = 1;
  141. }
  142. }
  143. private clickVideoBtn() {
  144. mk.audio.playEffect("button");
  145. if (cc.sys.isNative && !gData.loginData.isAuth) {
  146. // JsbSystem.WxAuth();
  147. gData.gameData.authUIType = 0;
  148. mk.ui.openPanel('module/authUI/authUI');
  149. return;
  150. }
  151. mk.ad.videoAdType = VideoAdType.video_init_1;
  152. mk.ad.watchAd((success: boolean) => {
  153. mk.console.log("watchAD:" + success);
  154. if (success) {
  155. gData.adData.watchVideo(null);
  156. gData.farmGradeData.addGradeExp(ExpAddType.EAT_video);
  157. }
  158. });
  159. }
  160. private clickCloseBtn() {
  161. mk.audio.playEffect("button");
  162. }
  163. onDisable() {
  164. let pop = gData.adData.checkShowFullInter(4);
  165. if(pop){
  166. gData.moreGame.openType = 3;
  167. mk.data.sendDataEvent(DataEventId.htRedBag_scene, "关闭农场等级奖励界面");
  168. }
  169. }
  170. }