EquipChoose.ts 4.4 KB

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