ItemDetailsUI.ts 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /** @format */
  2. import {BaseUI} from '../BaseUI'
  3. import {Data, Mgr} from '../../GameControl'
  4. import {ccUtils} from '../../utils/ccUtils'
  5. import {observer, render, node, label, editBox, list} from '../../mobx/observer'
  6. import {ATTR_NAME, LANGUAGE_TYPE, PREFAB_TYPE} from '../../enums/Enum'
  7. import {RoleConfig} from '../../config/RoleConfig'
  8. import {GoodsConfig} from '../../config/GoodsConfig'
  9. import {CardConsumeConfig} from '../../config/CardConsumeConfig'
  10. import {CardSkillConfig} from '../../config/CardSkillConfig'
  11. import {ArmorConfig, IArmorConfig} from '../../config/ArmorConfig'
  12. import {IGoodShowInfo} from '../../interface/GlobalInterface'
  13. const {ccclass, property} = cc._decorator
  14. @ccclass
  15. @observer
  16. export class ItemDetailsUI extends BaseUI {
  17. @node('equipItem')
  18. equipItemNode: cc.Node
  19. @node('goodItem')
  20. goodItemNode: cc.Node
  21. curID: number
  22. curGoodType: string
  23. onShow(args: IGoodShowInfo, fromUI: number) {
  24. this.curID = args.id
  25. this.curGoodType = args.goodType
  26. this.equipItemNode.active = this.curGoodType == PREFAB_TYPE.equip
  27. this.goodItemNode.active = this.curGoodType != PREFAB_TYPE.equip
  28. if (this.curGoodType == PREFAB_TYPE.equip) {
  29. this.initGoodsDetails(this.equipItemNode)
  30. this.initEquipDetails()
  31. } else {
  32. this.initGoodsDetails(this.goodItemNode)
  33. let describe: string = null //描述文本
  34. let name: string = null //物品名字
  35. this.initRoleDetails()
  36. if (this.curGoodType == PREFAB_TYPE.role) {
  37. name = RoleConfig[this.curID].name
  38. describe = Mgr.i18n.getLabel(RoleConfig[this.curID].describe)
  39. } else if (this.curGoodType == PREFAB_TYPE.cardDebris) {
  40. name = CardConsumeConfig[this.curID].name
  41. describe = Mgr.i18n.getLabel(CardConsumeConfig[this.curID].description)
  42. } else if (this.curGoodType == PREFAB_TYPE.goods) {
  43. name = GoodsConfig[this.curID].name
  44. describe = Mgr.i18n.getLabel(GoodsConfig[this.curID].tips)
  45. } else if (this.curGoodType == PREFAB_TYPE.card) {
  46. name = CardSkillConfig[this.curID].name
  47. describe = Mgr.i18n.getLabel(CardSkillConfig[this.curID].tip, CardSkillConfig[this.curID].attrNum)
  48. }
  49. ccUtils.setRichLabel(describe, this.goodItemNode, 'describe')
  50. ccUtils.setLabel(name, this.goodItemNode, 'name')
  51. }
  52. }
  53. onHide(): any {
  54. Mgr.event.removeAll(this)
  55. }
  56. //UI或者其他函数=======================================
  57. initRoleDetails() {
  58. let cfg = RoleConfig[this.curID]
  59. let good_parent = cc.find('good_parent', this.goodItemNode)
  60. cc.find('role_type', good_parent).active = !!cfg
  61. if (cfg) {
  62. this.loadTexImg(`Public/role/role_type_${cfg.profession}`, good_parent, 'role_type')
  63. }
  64. }
  65. initEquipDetails() {
  66. let armorConfig = ArmorConfig[this.curID]
  67. let node = this.equipItemNode
  68. let equipNode = cc.find('good_parent', node)
  69. let atk = cc.find('atk', node)
  70. let atkNum = cc.find('atknum', node)
  71. //属性值
  72. let attrNum =
  73. armorConfig.HP > 0
  74. ? armorConfig.HP
  75. : armorConfig.spellAttack > armorConfig.attack
  76. ? armorConfig.spellAttack
  77. : armorConfig.attack
  78. let attrName =
  79. armorConfig.HP > 0
  80. ? ATTR_NAME.HP
  81. : armorConfig.spellAttack > armorConfig.attack
  82. ? ATTR_NAME.spellAttack
  83. : ATTR_NAME.attack
  84. ccUtils.setLabel(armorConfig.name, node, 'name')
  85. ccUtils.setLabel(LANGUAGE_TYPE[attrName], atk)
  86. ccUtils.labelForceUpdateRenderData(atk)
  87. ccUtils.setLabel(attrNum.toString(), atkNum)
  88. atkNum.x = atk.x + atk.width
  89. //职业限定
  90. let professionNodes = ccUtils.instantChildren(cc.find('occupation/type', node), armorConfig.profession.length)
  91. for (let i = 0; i < professionNodes.length; i++) {
  92. this.loadTexImg(`Public/role/role_type_${armorConfig.profession[i]}`, professionNodes[i])
  93. }
  94. //词条
  95. let attrItemOrigin = cc.find('attrList/view/content/item', node)
  96. let tips: {entry: number; cfg: IArmorConfig}[] = []
  97. for (let i = 1; i <= Data.main.maxEquipQuality; i++) {
  98. let ID = Math.floor(armorConfig.ID / 100) * 100 + i
  99. if (ArmorConfig[ID.toString()].entry)
  100. tips.push({
  101. entry: ArmorConfig[ID.toString()].entry,
  102. cfg: ArmorConfig[ID.toString()],
  103. })
  104. }
  105. let attrItems = ccUtils.instantChildren(attrItemOrigin, tips.length)
  106. for (let i = 0; i < tips.length; i++) {
  107. let attrItem = attrItems[i]
  108. let tip = tips[i]
  109. cc.find('icon/lock_1', attrItem).active = tip.cfg.quality > armorConfig.quality
  110. this.loadTexImg(`Public/goodsQuality/item_frame${tip.cfg.qualityType}`, attrItem, 'icon/item_frame')
  111. let richTextNode = cc.find('richText', attrItem)
  112. ccUtils.setRichLabel(Mgr.i18n.getEntryLabel(tip.entry), richTextNode)
  113. if (tip.cfg.quality > armorConfig.quality) ccUtils.setRichLabelGray(richTextNode)
  114. this.scheduleOnce(() => {
  115. if (attrItem.activeInHierarchy) {
  116. let layout = attrItem.getComponent(cc.Layout)
  117. layout.resizeMode =
  118. richTextNode.height < 65 ? cc.Layout.ResizeMode.NONE : cc.Layout.ResizeMode.CONTAINER
  119. layout.updateLayout()
  120. if (richTextNode.height < 65) {
  121. attrItem.height = 65
  122. }
  123. }
  124. })
  125. }
  126. }
  127. initGoodsDetails(node: cc.Node) {
  128. Mgr.goods.initOneGoods({id: this.curID, num: 0}, cc.find('good_parent/good', node), this, {showDetails: false})
  129. }
  130. //网络事件=======================================
  131. // onXXXRsp() {}
  132. //触发事件=======================================
  133. // @render
  134. // showRender() {}
  135. // 点击事件=======================================
  136. // onClick() {}
  137. }