EquipChoose.ts 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. import { _decorator, instantiate, Label, Node, Prefab, tween, UIOpacity } from 'cc';
  2. import { BaseView } from '../../../framework/layer/BaseView';
  3. import { EquipChooseItem } from './EquipChooseItem';
  4. import { StringUtil } from '../../../framework/util/StringUtil';
  5. import List from '../../../framework/list/List';
  6. import { EquipManager } from '../../manager/EquipManager';
  7. import { Framework } from '../../../framework/Framework';
  8. import { Equip } from '../../data/EquipData';
  9. import { CommonItem } from '../common/CommonItem';
  10. import { AttrAddTypeEnum, AttrEnum } from '../../common/InterfaceAddEnum';
  11. const { ccclass, property } = _decorator;
  12. @ccclass('EquipChoose')
  13. export class EquipChoose extends BaseView {
  14. @property({ type: Label, tooltip: "关闭提示" })
  15. closeTips: Label = null;
  16. @property({ type: Label, tooltip: "标题" })
  17. titieTx: Label = null;
  18. @property({ type: Node, tooltip: "穿戴装备节点" })
  19. wearNode: Node = null;
  20. @property({ type: Label, tooltip: "列表空提示" })
  21. equipListNoneTx: Label = null;
  22. @property({ type: List, tooltip: "列表" })
  23. equipList: List = null;
  24. @property({ type: Node, tooltip: "装备节点" })
  25. itemNode: Node = null;
  26. @property({ type: Label, tooltip: "装备名" })
  27. nameTx: Label = null;
  28. @property({ type: Label, tooltip: "战力标题" })
  29. fightTitie: Label = null;
  30. @property({ type: Label, tooltip: "战力文字" })
  31. fightTx: Label = null;
  32. @property({ type: Label, tooltip: "穿戴文字" })
  33. wearTx: Label = null;
  34. private _curRace: number = 0;
  35. private _curSlot: number = 0;
  36. private _equipsData: any[] = [];
  37. private _curEquip: Equip = null;
  38. start() {
  39. }
  40. protected onLoad() {
  41. super.onLoad();
  42. this.closeTips.string = StringUtil.getLanguageData('点击空白关闭');
  43. this.titieTx.string = StringUtil.getLanguageData('装备选择');
  44. this.wearTx.string = StringUtil.getLanguageData('当前穿戴');
  45. this.fightTitie.string = StringUtil.getLanguageData('战力') + ': ';
  46. this.equipListNoneTx.string = StringUtil.getLanguageData('暂无可用装备');
  47. this.closeTips.node.getComponent(UIOpacity).opacity = 0;
  48. this.wearNode.active = false;
  49. }
  50. protected onDestroy() {
  51. }
  52. //UI开打时会调用,如果有初始化代码应该放到此函数
  53. onOpen(data) {
  54. tween(this.closeTips.node.getComponent(UIOpacity))
  55. .to(1, { opacity: 255 })
  56. .to(1.2, { opacity: 10 })
  57. .union()
  58. .repeatForever()
  59. .start()
  60. this._curRace = data.race;
  61. this._curSlot = data.slot;
  62. let eData = EquipManager.getEquipRaceSlotGroup(data.race)[data.slot];
  63. if (data.equip) {
  64. this._curEquip = data.equip;
  65. this.wearNode.active = true;
  66. this.updateWear();
  67. this._equipsData = eData.filter((element) => element.id !== data.equip.id);
  68. }else{
  69. this._equipsData = eData;
  70. }
  71. this.equipListNoneTx.node.active = this._equipsData.length == 0;
  72. this.equipList.numItems = this._equipsData.length;
  73. }
  74. //UI关闭时会调用,该函数在onDestroy前调用
  75. onClose() {
  76. }
  77. //框架管理UI层级时会调用,可根据UI情况修改
  78. onShow() {
  79. super.onShow();
  80. }
  81. //框架管理UI层级时会调用,可根据UI情况修改
  82. onHide() {
  83. super.onHide();
  84. }
  85. //UI事件处理
  86. private onTouchButton(event: Event) {
  87. //Framework.audio.playEffect(AudioID.Click);
  88. let target: any = event.target;
  89. if (target.name == 'mask') {
  90. Framework.layer.close(this);
  91. }
  92. }
  93. updateWear() {
  94. this.load('common', `prefab/CommonItem`, Prefab, (pre: Prefab) => {
  95. let item = instantiate(pre);
  96. this.itemNode.addChild(item);
  97. item.getComponent(CommonItem).refreshItem(this._curEquip);
  98. })
  99. this.nameTx.string = `${StringUtil.getLanguageData('装备名称')}: ${StringUtil.getLanguageData(this._curEquip.conf['Name'])}`;
  100. let attrStr = 0;
  101. for (let index = 1; index <= 2; index++) {
  102. let Stat = this._curEquip.conf['Stat' + index];
  103. if (Stat != 0) {
  104. let attr = Stat.split(':');
  105. let attrConf = AttrEnum[attr[0]]
  106. let value = attrConf.type == AttrAddTypeEnum.reality ? Number(attr[1]) :
  107. 100 * Number(attr[1])
  108. attrStr = attrStr + value;
  109. }
  110. }
  111. this.fightTx.string = String(attrStr);
  112. }
  113. onEventList(item, idx) {
  114. item.getComponent(EquipChooseItem).refreshItem(this._equipsData[idx], this._curEquip);
  115. }
  116. }