FFHeader.ts 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. import i18n from "../../i18n/i18n";
  2. import Main from "../../main/Main";
  3. import { __StageData } from "../data/sdata/SManage";
  4. import FF from "./FF";
  5. import FTmpTaskGood from "./FTmpTaskGood";
  6. import FTmpTaskPanel from "./FTmpTaskPanel";
  7. /**
  8. * 战斗中显示收集的物品
  9. */
  10. const {ccclass, property} = cc._decorator;
  11. @ccclass
  12. export default class FFHeader extends cc.Component {
  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.Sprite)
  22. mGoodIcon3: cc.Sprite = null;
  23. @property(cc.Label)
  24. mGood3: cc.Label = null;
  25. @property(cc.Node)
  26. mTmpGoods: cc.Node = null;
  27. @property(cc.Node)
  28. mTmpContent: cc.Node = null;
  29. @property(cc.Prefab)
  30. mTmpGoodItem: cc.Prefab = null;
  31. @property(FTmpTaskPanel)
  32. mTmpPanel: FTmpTaskPanel = null;//点击后显示的物品属性
  33. private tmpGoods:Map<number,number> = new Map();
  34. /**
  35. * 当前打的关卡
  36. */
  37. public stageData:__StageData;
  38. private main:Main;
  39. private ff:FF;
  40. public onLoad(){
  41. this.mTmpPanel.node.active = false
  42. }
  43. public init(ff:FF,stageData:__StageData){
  44. this.ff = ff;
  45. this.main = this.ff.main;
  46. this.stageData = stageData;
  47. let sManage = this.main.sManage;
  48. let good1 = sManage.getGoodById1(this.stageData.goodId1);
  49. cc.resources.load('icon/good/'+good1.icon, cc.SpriteFrame, (err, spriteFrame:cc.SpriteFrame) =>{
  50. if(err){
  51. cc.error(err);
  52. }else{
  53. this.mGoodIcon1.spriteFrame = spriteFrame;
  54. }
  55. } );
  56. let good2 = sManage.getGoodById1(this.stageData.goodId2);
  57. cc.resources.load('icon/good/'+good2.icon, cc.SpriteFrame, (err, spriteFrame:cc.SpriteFrame) =>{
  58. if(err){
  59. cc.error(err);
  60. }else{
  61. this.mGoodIcon2.spriteFrame = spriteFrame;
  62. }
  63. } );
  64. let good3 = sManage.getGoodById1(this.stageData.goodId3);
  65. cc.resources.load('icon/good/'+good3.icon, cc.SpriteFrame, (err, spriteFrame:cc.SpriteFrame) =>{
  66. if(err){
  67. cc.error(err);
  68. }else{
  69. this.mGoodIcon3.spriteFrame = spriteFrame;
  70. }
  71. } );
  72. this.flush();
  73. }
  74. public flush(){
  75. // cc.log('this.stageData : ',this.stageData)
  76. let player = this.main.player;
  77. let stage = player.stage;
  78. // cc.log('stage:',stage)
  79. let count1 = this.getCount(this.stageData.goodId1);
  80. this.mGood1.string = count1+'/'+this.stageData.goodCount1;
  81. let count2 = this.getCount(this.stageData.goodId2);
  82. this.mGood2.string = count2+'/'+this.stageData.goodCount2;
  83. let count3 = this.getCount(this.stageData.goodId3);
  84. this.mGood3.string = count3+'/'+this.stageData.goodCount3;
  85. }
  86. public getCount(goodId){
  87. let player = this.main.player;
  88. let stage = player.stage;
  89. let curr = stage.data[''+this.stageData.id];
  90. if(curr && curr.good){
  91. let count = curr.good[''+goodId];
  92. if(count == undefined){
  93. return 0 ;
  94. }
  95. return count;
  96. }else{
  97. return 0;
  98. }
  99. }
  100. public addTmpGood(id,count){
  101. let xx = this.tmpGoods.get(id);
  102. if(this.tmpGoods.has(id)){
  103. xx += count;
  104. this.tmpGoods.set(id,xx);
  105. }else{
  106. this.tmpGoods.set(id,count);
  107. }
  108. this.flushTmpGood();
  109. let _good = this.main.sManage.getGoodById(id)
  110. //<color=#FFFFFF>获得道具</c><color=#0fffff>服饰卡*1</color>
  111. let str = '<color=#FFFFFF>'+i18n.t('获得道具')+':</c><color=#0fffff>'+i18n.t(_good.name)+'x'+count+'</c>'
  112. this.main.showTips(str)
  113. }
  114. public removeTmpGood(id,count){
  115. if(this.tmpGoods.has(id)){
  116. let xx = this.tmpGoods.get(id);
  117. xx -= count;
  118. if(xx > 0){
  119. this.tmpGoods.set(id,xx);
  120. }else{
  121. this.tmpGoods.delete(id);
  122. }
  123. this.flushTmpGood();
  124. }
  125. }
  126. public getTmpCount(id){
  127. if(this.tmpGoods.has(id)){
  128. return this.tmpGoods.get(id);
  129. }
  130. return 0;
  131. }
  132. private flushTmpGood(){
  133. this.mTmpGoods.active = this.tmpGoods.size > 0
  134. let manage = this.ff.main.sManage;
  135. this.mTmpContent.destroyAllChildren()
  136. this.tmpGoods.forEach((count, id)=> {
  137. let good = manage.getGoodById1(id);
  138. let node:cc.Node = cc.instantiate(this.mTmpGoodItem)
  139. node.parent = this.mTmpContent
  140. let tmpTaskGood = node.getComponent(FTmpTaskGood)
  141. tmpTaskGood.init(good,count)
  142. tmpTaskGood.setCallback((goodItem:FTmpTaskGood,isActive)=>{
  143. if(isActive){
  144. this.mTmpPanel.show(goodItem)
  145. }else{
  146. this.mTmpPanel.node.active = false
  147. }
  148. })
  149. })
  150. }
  151. }