EquipChooseItem.ts 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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, AttrEnum } 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).refreshItem(data);
  54. })
  55. this.nameTx.string = `${StringUtil.getLanguageData('装备名称')}: ${StringUtil.getLanguageData(data.conf['Name'])}`;
  56. let attrStr = 0;
  57. for (let index = 1; index <= 2; index++) {
  58. let Stat = data.conf['Stat' + index];
  59. if (Stat != 0) {
  60. let attr = Stat.split(':');
  61. let attrConf = AttrEnum[attr[0]]
  62. let value = attrConf.type == AttrAddTypeEnum.reality ? Number(attr[1]) :
  63. 100 * Number(attr[1])
  64. attrStr = attrStr + value;
  65. }
  66. }
  67. this.fightTx.string = String(attrStr);
  68. }
  69. //UI事件处理
  70. private onTouchButton(event: Event) {
  71. //Framework.audio.playEffect(AudioID.Click);
  72. let target: any = event.target;
  73. if (target.name == 'wear_btn') {
  74. let args = { eid: this.data['id'], slot: this.data['conf']['Slot'], race: this.data['conf']['Race'] };
  75. EquipManager.sendWearMsg(args, () => {
  76. Framework.tips.setTips(StringUtil.getLanguageData('穿戴成功!'));
  77. })
  78. // if (this.wearEquip) {
  79. // }else{
  80. // }
  81. }
  82. }
  83. }