EquipOpreate.ts 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. import { _decorator, instantiate, Label, Node, Prefab, SpotLight, Sprite, tween, UIOpacity } from 'cc';
  2. import { BaseView } from '../../../framework/layer/BaseView';
  3. import { StringUtil } from '../../../framework/util/StringUtil';
  4. import { Equip } from '../../data/EquipData';
  5. import { EquipConf } from '../../config/EquipConf';
  6. import { CommonItem } from '../common/CommonItem';
  7. import { AttrAddTypeEnum, AttrConf } from '../../common/InterfaceAddEnum';
  8. import { Framework } from '../../../framework/Framework';
  9. import { ViewID } from '../../../framework/config/LayerConf';
  10. import { GameEvent } from '../../data/GameEvent';
  11. const { ccclass, property } = _decorator;
  12. @ccclass('EquipOpreate')
  13. export class EquipOpreate 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. itemNode: Node = null;
  20. @property({ type: Label, tooltip: "名字" })
  21. nameTx: Label = null;
  22. @property({ type: Label, tooltip: "阵营" })
  23. posTx: Label = null;
  24. @property({ type: Label, tooltip: "部位" })
  25. slotTx: Label = null;
  26. @property({ type: Label, tooltip: "描述" })
  27. descTx: Label = null;
  28. @property({ type: Label, tooltip: "属性标题" })
  29. attrTitieTx: Label = null;
  30. @property({ type: Label, tooltip: "属性" })
  31. attrTx: Label = null;
  32. @property({ type: Sprite, tooltip: "替换/卸下按钮图" })
  33. wearBtnSp: Sprite = null;
  34. @property({ type: Label, tooltip: "替换/卸下按钮文字" })
  35. wearBtnTx: Label = null;
  36. @property({ type: Label, tooltip: "升级按钮文字" })
  37. updateBtnTx: Label = null;
  38. @property({ type: Node, tooltip: "强化按钮" })
  39. strongBtn: Node = null;
  40. @property({ type: Label, tooltip: "强化按钮文字" })
  41. strongBtnTx: Label = null;
  42. private _curRace: number = 0;
  43. private _curSlot: number = 0;
  44. private _curEquip: Equip = null;
  45. protected onLoad() {
  46. super.onLoad();
  47. this.closeTips.string = StringUtil.getLanguageData('点击空白关闭');
  48. this.titieTx.string = StringUtil.getLanguageData('装备详情');
  49. this.attrTitieTx.string = StringUtil.getLanguageData('属性加成');
  50. this.wearBtnTx.string = StringUtil.getLanguageData('替换');
  51. this.updateBtnTx.string = StringUtil.getLanguageData('升级');
  52. this.strongBtnTx.string = StringUtil.getLanguageData('突破');
  53. this.closeTips.node.getComponent(UIOpacity).opacity = 0;
  54. Framework.event.addEvent(GameEvent.EquipWearChange, () => {
  55. Framework.layer.close(this);
  56. }, this);
  57. }
  58. protected onDestroy() {
  59. }
  60. //UI开打时会调用,如果有初始化代码应该放到此函数
  61. onOpen(data) {
  62. tween(this.closeTips.node.getComponent(UIOpacity))
  63. .to(1, { opacity: 255 })
  64. .to(1.2, { opacity: 10 })
  65. .union()
  66. .repeatForever()
  67. .start()
  68. this._curRace = data.race;
  69. this._curSlot = data.slot;
  70. this._curEquip = data.equip;
  71. if (this._curEquip.conf['Quality'] < 5) {
  72. this.strongBtn.active = false;
  73. }
  74. this.updateUI();
  75. }
  76. //UI关闭时会调用,该函数在onDestroy前调用
  77. onClose() {
  78. }
  79. //框架管理UI层级时会调用,可根据UI情况修改
  80. onShow() {
  81. super.onShow();
  82. }
  83. //框架管理UI层级时会调用,可根据UI情况修改
  84. onHide() {
  85. super.onHide();
  86. }
  87. //UI事件处理
  88. private onTouchButton(event: Event) {
  89. //Framework.audio.playEffect(AudioID.Click);
  90. let target: any = event.target;
  91. if (target.name == 'mask') {
  92. Framework.layer.close(this);
  93. } else if (target.name == 'wear_btn') {
  94. let args = { race: this._curRace, slot: this._curSlot, equip: this._curEquip }
  95. Framework.layer.open(ViewID.EquipChoose, null, args);
  96. } else if (target.name == 'update_btn') {
  97. let args = { race: this._curRace, slot: this._curSlot, equip: this._curEquip }
  98. Framework.layer.open(ViewID.EquipUpdate, null, args);
  99. } else if (target.name == 'strong_btn') {
  100. // let args = { race: this._curRace, slot: this._curSlot, equip: this._curEquip }
  101. // Framework.layer.open(ViewID.EquipStrong, null, args);
  102. }
  103. }
  104. updateUI() {
  105. this.load('common', `prefab/CommonItem`, Prefab, (pre: Prefab) => {
  106. let item = instantiate(pre);
  107. this.itemNode.addChild(item);
  108. item.getComponent(CommonItem).setClickEnable(false);
  109. item.getComponent(CommonItem).setNumShow(false);
  110. item.getComponent(CommonItem).refreshItem(this._curEquip);
  111. })
  112. this.nameTx.string = `${StringUtil.getLanguageData('装备名称')}: ${StringUtil.getLanguageData(this._curEquip.conf['Name'])}`;
  113. this.posTx.string = `${StringUtil.getLanguageData('阵营类型')}: ${StringUtil.getLanguageData('阵营' + this._curEquip.conf['Race'])}`;
  114. this.slotTx.string = `${StringUtil.getLanguageData('装备位置')}: ${StringUtil.getLanguageData('部位' + this._curEquip.conf['Slot'])}`;
  115. this.descTx.string = StringUtil.getLanguageData(this._curEquip.conf['Desc']);
  116. let attrStr = "";
  117. for (let index = 1; index <= 2; index++) {
  118. let Stat = this._curEquip.conf['Stat' + index];
  119. if (Stat != 0) {
  120. let attr = Stat.split(':');
  121. let attrConf = AttrConf[attr[0]]
  122. let value = attrConf.type == AttrAddTypeEnum.reality ? ("+" + attr[1]) :
  123. ("+" + (100 * Number(attr[1])) + "%")
  124. attrStr = attrStr + StringUtil.getLanguageData(attrConf.name) + ' ' + value + "\n";
  125. }
  126. }
  127. this.attrTx.string = attrStr;
  128. }
  129. }