EquipChooseItem.ts 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import { _decorator, Label, Node, 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. const { ccclass, property } = _decorator;
  7. @ccclass('EquipChooseItem')
  8. export class EquipChooseItem extends ResKeeper {
  9. @property({ type: Node, tooltip: "装备节点" })
  10. itemNode: Node = null;
  11. @property({ type: Label, tooltip: "装备名" })
  12. nameTx: Label = null;
  13. @property({ type: Label, tooltip: "战力标题" })
  14. fightTitie: Label = null;
  15. @property({ type: Label, tooltip: "战力文字" })
  16. fightTx: Label = null;
  17. @property({ type: Sprite, tooltip: "穿戴按钮图" })
  18. wearBtnSp: Sprite = null;
  19. @property({ type: Label, tooltip: "穿戴按钮文字" })
  20. wearBtnTx: Label = null;
  21. private data = {};
  22. private wearEquip = null;
  23. protected onLoad() {
  24. this.fightTitie.string = StringUtil.getLanguageData('战力') + ': ';
  25. }
  26. protected onDestroy() {
  27. //如果该组件有事件自行取消注释
  28. //Framework.event.removeEvent(this);
  29. super.onDestroy();
  30. }
  31. //如果使用了池中的节点,在该函数内归还,该函数会在onDestroy前调用
  32. onClose() {
  33. }
  34. refreshItem(data, wearEquip) {
  35. this.data = data;
  36. this.wearEquip = wearEquip;
  37. if (wearEquip) {
  38. this.wearBtnTx.string = StringUtil.getLanguageData('替换');
  39. this.load('common', `texture/button/blue_btn_1/spriteFrame`, SpriteFrame, (res: SpriteFrame) => {
  40. this.wearBtnSp.spriteFrame = res;
  41. })
  42. } else {
  43. this.wearBtnTx.string = StringUtil.getLanguageData('装备');
  44. this.load('common', `texture/button/yellow_btn_1/spriteFrame`, SpriteFrame, (res: SpriteFrame) => {
  45. this.wearBtnSp.spriteFrame = res;
  46. })
  47. }
  48. this.nameTx.string = StringUtil.getLanguageData(data.conf.Name);
  49. this.fightTx.string = data.fightForce;
  50. }
  51. //UI事件处理
  52. private onTouchButton(event: Event) {
  53. //Framework.audio.playEffect(AudioID.Click);
  54. let target: any = event.target;
  55. if (target.name == 'wear_btn') {
  56. let args = { eid: this.data['id'], slot: this.data['conf']['Slot'], race: this.data['conf']['Race'] };
  57. EquipManager.sendWearMsg(args, () => {
  58. Framework.tips.setTips(StringUtil.getLanguageData('穿戴成功!'));
  59. })
  60. // if (this.wearEquip) {
  61. // }else{
  62. // }
  63. }
  64. }
  65. }