EquipOpreate.ts 4.9 KB

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