EquipOpreate.ts 5.2 KB

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