EquipChooseItem.ts 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. import { _decorator, instantiate, Label, Node, Prefab, Sprite, SpriteFrame } from 'cc';
  2. import { ResKeeper } from '../../../framework/res/ResKeeper';
  3. import { StringUtil } from '../../../framework/util/StringUtil';
  4. import { EquipManager } from '../../manager/EquipManager';
  5. import { Framework } from '../../../framework/Framework';
  6. import { AttrAddTypeEnum, AttrConf } from '../../common/InterfaceAddEnum';
  7. import { CommonItem } from '../common/CommonItem';
  8. const { ccclass, property } = _decorator;
  9. @ccclass('EquipChooseItem')
  10. export class EquipChooseItem extends ResKeeper {
  11. @property({ type: Node, tooltip: "装备节点" })
  12. itemNode: Node = null;
  13. @property({ type: Label, tooltip: "装备名" })
  14. nameTx: Label = null;
  15. @property({ type: Label, tooltip: "战力标题" })
  16. fightTitie: Label = null;
  17. @property({ type: Label, tooltip: "战力文字" })
  18. fightTx: Label = null;
  19. @property({ type: Sprite, tooltip: "穿戴按钮图" })
  20. wearBtnSp: Sprite = null;
  21. @property({ type: Label, tooltip: "穿戴按钮文字" })
  22. wearBtnTx: Label = null;
  23. private data = {};
  24. private wearEquip = null;
  25. protected onLoad() {
  26. this.fightTitie.string = StringUtil.getLanguageData('战力') + ': ';
  27. }
  28. protected onDestroy() {
  29. //如果该组件有事件自行取消注释
  30. //Framework.event.removeEvent(this);
  31. super.onDestroy();
  32. }
  33. //如果使用了池中的节点,在该函数内归还,该函数会在onDestroy前调用
  34. onClose() {
  35. }
  36. refreshItem(data, wearEquip) {
  37. this.data = data;
  38. this.wearEquip = wearEquip;
  39. if (wearEquip) {
  40. this.wearBtnTx.string = StringUtil.getLanguageData('替换');
  41. this.load('common', `texture/button/blue_btn_1/spriteFrame`, SpriteFrame, (res: SpriteFrame) => {
  42. this.wearBtnSp.spriteFrame = res;
  43. })
  44. } else {
  45. this.wearBtnTx.string = StringUtil.getLanguageData('装备');
  46. this.load('common', `texture/button/yellow_btn_1/spriteFrame`, SpriteFrame, (res: SpriteFrame) => {
  47. this.wearBtnSp.spriteFrame = res;
  48. })
  49. }
  50. this.load('common', `prefab/CommonItem`, Prefab, (pre: Prefab) => {
  51. let item = instantiate(pre);
  52. this.itemNode.addChild(item);
  53. item.getComponent(CommonItem).setClickEnable(false);
  54. item.getComponent(CommonItem).setNumShow(false);
  55. item.getComponent(CommonItem).refreshItem(data);
  56. })
  57. this.nameTx.string = `${StringUtil.getLanguageData('装备名称')}: ${StringUtil.getLanguageData(data.conf['Name'])}`;
  58. let attrStr = 0;
  59. for (let index = 1; index <= 2; index++) {
  60. let Stat = data.conf['Stat' + index];
  61. if (Stat != 0) {
  62. let attr = Stat.split(':');
  63. let attrConf = AttrConf[attr[0]]
  64. let value = attrConf.type == AttrAddTypeEnum.reality ? Number(attr[1]) :
  65. 100 * Number(attr[1])
  66. attrStr = attrStr + value;
  67. }
  68. }
  69. this.fightTx.string = String(attrStr);
  70. }
  71. //UI事件处理
  72. private onTouchButton(event: Event) {
  73. //Framework.audio.playEffect(AudioID.Click);
  74. let target: any = event.target;
  75. if (target.name == 'wear_btn') {
  76. let args = { eid: this.data['id'], slot: this.data['conf']['Slot'], race: this.data['conf']['Race'] };
  77. EquipManager.sendWearMsg(args, () => {
  78. Framework.tips.setTips(StringUtil.getLanguageData('穿戴成功!'));
  79. })
  80. // if (this.wearEquip) {
  81. // }else{
  82. // }
  83. }
  84. }
  85. }