GradeReward.ts 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. import { UITween } from "../../component/tween/UITween";
  2. import { GradeRewardItem } from "./GradeRewardItem";
  3. const { ccclass, property } = cc._decorator;
  4. @ccclass
  5. export class GradeReward extends cc.Component{
  6. @property({displayName:"进度条", type: cc.Sprite})
  7. private sp_slider: cc.Sprite = null;
  8. @property({displayName:"内容节点", type: cc.Node})
  9. private node_content: cc.Node = null;
  10. @property(cc.Prefab)
  11. private node_child: cc.Prefab = null;
  12. @property({displayName: '进度文本', type: cc.Label})
  13. private lbl_progress: cc.Label[] = [];
  14. private gradeExp: number[] = [100, 200, 400, 700, 900];
  15. private curExp: number = 0;
  16. private gradeOffset: number[] = [0.11, 0.33, 0.56, 0.78, 1];
  17. onLoad(){
  18. }
  19. start(){
  20. for(let i = 5; i != 0; --i)
  21. {
  22. let child = cc.instantiate(this.node_child);
  23. let item = child.getComponent(GradeRewardItem);
  24. item.id = i;
  25. item.lbl_value.string = "0.3元";
  26. item.lbl_grade.string = "LV:12";
  27. this.node_content.addChild(child);
  28. }
  29. this.calulateExpAndShowUI();
  30. }
  31. private calulateExpAndShowUI()
  32. {
  33. let curIndex = -1;
  34. for(let i = 0; i != this.gradeExp.length; ++i)
  35. {
  36. if(this.curExp < this.gradeExp[i])
  37. {
  38. if(curIndex == -1)
  39. {
  40. curIndex = i;
  41. }else
  42. {
  43. this.lbl_progress[i].string = "0%";
  44. }
  45. }else
  46. {
  47. this.lbl_progress[i].string = "100%";
  48. }
  49. }
  50. if(curIndex != -1)
  51. {
  52. let remainExp = this.curExp;
  53. for(let i = 0; i != curIndex; ++i)
  54. {
  55. remainExp = this.curExp - this.gradeExp[i];
  56. }
  57. let per = Math.floor(remainExp/this.gradeExp[curIndex] * 100);
  58. this.lbl_progress[curIndex].string = per + "%";
  59. let lastIndex = -1
  60. let lastPro = 0;
  61. if(curIndex > 0)
  62. {
  63. lastIndex = curIndex-1;
  64. }
  65. let offset = this.gradeOffset[curIndex];
  66. if(lastIndex != -1)
  67. {
  68. offset = offset - this.gradeOffset[lastIndex];
  69. lastPro = this.gradeOffset[lastIndex];
  70. }
  71. let pro = offset * per / 100;
  72. this.sp_slider.fillRange = lastPro + pro;
  73. }else{
  74. this.sp_slider.fillRange = 1;
  75. }
  76. }
  77. private clickVideoBtn(){
  78. mk.audio.playEffect("button");
  79. this.curExp += 30;
  80. this.calulateExpAndShowUI();
  81. }
  82. private clickCloseBtn(){
  83. mk.audio.playEffect("closeButton");
  84. }
  85. }