FarmLevelPanel.ts 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /** 农场等级界面 */
  2. const { ccclass, property } = cc._decorator;
  3. @ccclass
  4. export default class FarmLevelPanel extends cc.Component {
  5. @property({ type: cc.Sprite, displayName: '仓库' })
  6. scrollStore: cc.Sprite = null;
  7. @property({ type: cc.Sprite, displayName: '等级解锁' })
  8. scrollUnlock: cc.Sprite = null;
  9. @property({ type: cc.Label, displayName: '经验进度文本' })
  10. lblPro: cc.Label = null;
  11. @property({ type: cc.ProgressBar, displayName: '经验进度' })
  12. proExp: cc.ProgressBar = null;
  13. @property({ type: cc.Label, displayName: '等级' })
  14. lblLv: cc.Label = null;
  15. @property({ type: cc.Label, displayName: '名称' })
  16. lblName: cc.Label = null;
  17. @property({ type: cc.Sprite, displayName: '头像' })
  18. head: cc.Sprite = null;
  19. //解锁数组
  20. dataArr = [];
  21. curChooseId: number = 1;
  22. storeHasInit = false;
  23. async start() {
  24. this.scrollUnlock.node.active = true;
  25. this.scrollStore.node.active = false;
  26. let buildName = '';
  27. let buildUrl = '';
  28. let state = 0;
  29. let p = null;
  30. for (var i = 30001; i < 30010; i++) {
  31. let data: any = {};
  32. if (i == 30001) {
  33. buildName = '养鸡场';
  34. buildUrl = 'game/coregame/texture/main/main/enclosure_0';
  35. p = gData.gameData.getPastureDataMap(i);
  36. state = p.state;
  37. } else if (i == 30002) {
  38. buildName = '养牛场';
  39. buildUrl = 'game/coregame/texture/main/main/enclosure_1';
  40. p = gData.gameData.getPastureDataMap(i);
  41. state = p.state;
  42. } else if (i == 30003) {
  43. buildName = '养猪场';
  44. buildUrl = 'game/coregame/texture/main/main/enclosure_2';
  45. p = gData.gameData.getPastureDataMap(i);
  46. state = p.state;
  47. } else if (i == 30004) {
  48. buildName = gData.gameData.getTabByConfigID(i);
  49. buildUrl = 'game/coregame/texture/main/main/mapIcon_0';
  50. p = gData.gameData.getFactoryDataMap(i);
  51. state = p.state;
  52. } else if (i == 30005) {
  53. buildName = gData.gameData.getTabByConfigID(i);
  54. buildUrl = 'game/coregame/texture/main/main/mapIcon_1';
  55. p = gData.gameData.getFactoryDataMap(i);
  56. state = p.state;
  57. } else if (i == 30006) {
  58. buildName = gData.gameData.getTabByConfigID(i);
  59. buildUrl = 'game/coregame/texture/main/main/mapIcon_7';
  60. p = gData.gameData.getFactoryDataMap(i);
  61. state = p.state;
  62. } else if (i == 30007) {
  63. buildName = gData.gameData.getTabByConfigID(i);
  64. buildUrl = 'game/coregame/texture/main/main/mapIcon_4';
  65. p = gData.gameData.getFactoryDataMap(i);
  66. state = p.state;
  67. } else if (i == 30008) {
  68. buildName = gData.gameData.getTabByConfigID(i);
  69. buildUrl = 'game/coregame/texture/main/main/mapIcon_2';
  70. p = gData.gameData.getFactoryDataMap(i);
  71. state = p.state;
  72. } else if (i == 30009) {
  73. buildName = gData.gameData.getTabByConfigID(i);
  74. buildUrl = 'game/coregame/texture/main/main/mapIcon_3';
  75. p = gData.gameData.getFactoryDataMap(i);
  76. state = p.state;
  77. }
  78. data.buildName = buildName;
  79. data.buildUrl = buildUrl;
  80. data.state = state;
  81. this.dataArr.push(data);
  82. }
  83. this.scrollUnlock.node.emit('srollview-init', this.dataArr);
  84. if (gData.wechatData.nickName != '' && gData.wechatData.nickName != '点我授权提现') {
  85. this.lblName.string = `${gData.wechatData.nickName}的小农场`
  86. }
  87. else {
  88. this.lblName.string = `你的小农场`
  89. }
  90. let curLevel = gData.gameData.playerProp.gradeLevel;
  91. let needExp = gData.gameData.configs.UpgradeReward[curLevel].exp - gData.gameData.configs.UpgradeReward[curLevel - 1].exp;
  92. let curExp = gData.gameData.playerProp.farmExpValue - gData.gameData.configs.UpgradeReward[curLevel - 1].exp;
  93. this.lblLv.string = `等级:${curLevel}`;
  94. this.proExp.progress = curExp / needExp;
  95. this.lblPro.string = `${(Math.floor(curExp / needExp) * 100)}%`;
  96. if (gData.wechatData.avatar != '') {
  97. let result = await mk.loader.loadRemote(gData.wechatData.avatar + "?aaa=aa.jpg", null);
  98. if (result) {
  99. this.head.spriteFrame = new cc.SpriteFrame(result);
  100. }
  101. }
  102. }
  103. private clickToggleBtn(event, customEvenData) {
  104. mk.audio.playEffect('button');
  105. let id = parseInt(customEvenData);
  106. if (id == this.curChooseId)
  107. return;
  108. this.curChooseId = id;
  109. switch (id) {
  110. case 1:
  111. this.scrollUnlock.node.active = true;
  112. this.scrollStore.node.active = false;
  113. break;
  114. case 2:
  115. this.scrollUnlock.node.active = false;
  116. this.scrollStore.node.active = true;
  117. if (!this.storeHasInit) {
  118. this.scrollStore.node.emit('srollview-init', gData.gameData.configs.Product);
  119. this.storeHasInit = true;
  120. }
  121. break;
  122. }
  123. }
  124. }