FExitBox.ts 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. import i18n from "../../../i18n/i18n";
  2. import ViewObject from "../../../main/ViewObject";
  3. import { __StageData } from "../../data/sdata/SManage";
  4. import FF from "../FF";
  5. /**
  6. * 退出box
  7. */
  8. const {ccclass, property} = cc._decorator;
  9. @ccclass
  10. export default class FExitBox extends ViewObject {
  11. @property(cc.Label)
  12. mAbout: cc.Label = null;
  13. @property(cc.Sprite)
  14. mGoodIcon1: cc.Sprite = null;
  15. @property(cc.Label)
  16. mGood1: cc.Label = null;
  17. @property(cc.Sprite)
  18. mGoodIcon2: cc.Sprite = null;
  19. @property(cc.Label)
  20. mGood2: cc.Label = null;
  21. @property(cc.Node)
  22. mStar: cc.Node = null;//星星节点
  23. @property([cc.SpriteFrame])
  24. mStarx: Array<cc.SpriteFrame> = [];
  25. public endType = 0;//0,通关后退出,1是半路退出
  26. public ff:FF
  27. public stageData:__StageData
  28. public callbackOK:()=>void;
  29. public callbackClose:()=>void;
  30. public setOKCallback(callbackOK:()=>void){
  31. this.callbackOK = callbackOK;
  32. }
  33. public setCloseCallback(callbackClose:()=>void){
  34. this.callbackClose = callbackClose;
  35. }
  36. public onclickOK(){
  37. this.__distroyAll();
  38. this.callbackOK();
  39. cc.director.getPhysicsManager().enabled = true;
  40. }
  41. public onclickCancel(){
  42. this.__distroyAll();
  43. if(this.callbackClose){
  44. this.callbackClose()
  45. }
  46. }
  47. public init(__stageData:__StageData){
  48. this.stageData = __stageData
  49. let sManage = this.main.sManage;
  50. let good1 = sManage.getGoodById1(this.stageData.goodId1);
  51. cc.resources.load('icon/good/'+good1.icon, cc.SpriteFrame, (err, spriteFrame:cc.SpriteFrame) =>{
  52. if(err){
  53. cc.error(err);
  54. }else{
  55. this.mGoodIcon1.spriteFrame = spriteFrame;
  56. }
  57. } );
  58. let good2 = sManage.getGoodById1(this.stageData.goodId2);
  59. cc.resources.load('icon/good/'+good2.icon, cc.SpriteFrame, (err, spriteFrame:cc.SpriteFrame) =>{
  60. if(err){
  61. cc.error(err);
  62. }else{
  63. this.mGoodIcon2.spriteFrame = spriteFrame;
  64. }
  65. } );
  66. this.flush();
  67. let starCount = this.getStarCount()
  68. let nodes = this.mStar.children;
  69. for (let i = 0; i < nodes.length; i++) {
  70. let node = nodes[i];
  71. let sprite = node.getComponent(cc.Sprite);
  72. if(i < starCount){
  73. sprite.spriteFrame = this.mStarx[1];
  74. }else{
  75. sprite.spriteFrame = this.mStarx[0];
  76. }
  77. }
  78. let starCount1 = 0
  79. let main = this.main;
  80. let stageData = main.player.stage;
  81. let stageAttr = stageData.data[this.stageData.id];
  82. if(stageAttr != null){
  83. let count1 = this.getCount(this.stageData.goodId1);
  84. if(count1 >= this.stageData.goodCount1){
  85. starCount1 ++
  86. }
  87. let count2 = this.getCount(this.stageData.goodId2);
  88. if(count2 >= this.stageData.goodCount2){
  89. starCount1 ++
  90. }
  91. }
  92. if(starCount1 >= 2){
  93. this.mAbout.string = i18n.t('关卡内任务已完成')
  94. }else{
  95. this.mAbout.string = i18n.t('关卡内还有未完成的任务,是否确定退出?')
  96. }
  97. }
  98. /**
  99. * 获取当前星星数量
  100. */
  101. private getStarCount(){
  102. let main = this.main;
  103. let stageData = main.player.stage;
  104. let stageAttr = stageData.data[this.stageData.id];
  105. let starCount = 0;//星星的数量
  106. if(this.endType == 0){//通关后退出
  107. starCount ++
  108. }else{//半路退出
  109. if(stageData.stageIndex > this.stageData.id){
  110. starCount ++
  111. }
  112. }
  113. if(stageAttr != null){
  114. let count1 = this.getCount(this.stageData.goodId1);
  115. if(count1 >= this.stageData.goodCount1){
  116. starCount ++
  117. }
  118. let count2 = this.getCount(this.stageData.goodId2);
  119. if(count2 >= this.stageData.goodCount2){
  120. starCount ++
  121. }
  122. }
  123. return starCount
  124. }
  125. public flush(){
  126. let count1 = this.getCount(this.stageData.goodId1);
  127. this.mGood1.string = count1+'/'+this.stageData.goodCount1;
  128. let count2 = this.getCount(this.stageData.goodId2);
  129. this.mGood2.string = count2+'/'+this.stageData.goodCount2;
  130. }
  131. public getCount(goodId){
  132. let player = this.main.player;
  133. let stage = player.stage;
  134. let curr = stage.data[this.stageData.id];
  135. if(curr && curr.good){
  136. let count = curr.good[''+goodId];
  137. if(count == undefined){
  138. return 0 ;
  139. }
  140. return count;
  141. }else{
  142. return 0;
  143. }
  144. }
  145. }