123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- /** @format */
- import {BaseUI} from '../BaseUI'
- import {Data, Mgr} from '../../GameControl'
- import {ccUtils} from '../../utils/ccUtils'
- import {observer, render, node, label, editBox, list} from '../../mobx/observer'
- import {ATTR_NAME, LANGUAGE_TYPE, PREFAB_TYPE} from '../../enums/Enum'
- import {RoleConfig} from '../../config/RoleConfig'
- import {GoodsConfig} from '../../config/GoodsConfig'
- import {CardConsumeConfig} from '../../config/CardConsumeConfig'
- import {CardSkillConfig} from '../../config/CardSkillConfig'
- import {ArmorConfig, IArmorConfig} from '../../config/ArmorConfig'
- import {IGoodShowInfo} from '../../interface/GlobalInterface'
- const {ccclass, property} = cc._decorator
- @ccclass
- @observer
- export class ItemDetailsUI extends BaseUI {
- @node('equipItem')
- equipItemNode: cc.Node
- @node('goodItem')
- goodItemNode: cc.Node
- curID: number
- curGoodType: string
- onShow(args: IGoodShowInfo, fromUI: number) {
- this.curID = args.id
- this.curGoodType = args.goodType
- this.equipItemNode.active = this.curGoodType == PREFAB_TYPE.equip
- this.goodItemNode.active = this.curGoodType != PREFAB_TYPE.equip
- if (this.curGoodType == PREFAB_TYPE.equip) {
- this.initGoodsDetails(this.equipItemNode)
- this.initEquipDetails()
- } else {
- this.initGoodsDetails(this.goodItemNode)
- let describe: string = null //描述文本
- let name: string = null //物品名字
- this.initRoleDetails()
- if (this.curGoodType == PREFAB_TYPE.role) {
- name = RoleConfig[this.curID].name
- describe = Mgr.i18n.getLabel(RoleConfig[this.curID].describe)
- } else if (this.curGoodType == PREFAB_TYPE.cardDebris) {
- name = CardConsumeConfig[this.curID].name
- describe = Mgr.i18n.getLabel(CardConsumeConfig[this.curID].description)
- } else if (this.curGoodType == PREFAB_TYPE.goods) {
- name = GoodsConfig[this.curID].name
- describe = Mgr.i18n.getLabel(GoodsConfig[this.curID].tips)
- } else if (this.curGoodType == PREFAB_TYPE.card) {
- name = CardSkillConfig[this.curID].name
- describe = Mgr.i18n.getLabel(CardSkillConfig[this.curID].tip, CardSkillConfig[this.curID].attrNum)
- }
- ccUtils.setRichLabel(describe, this.goodItemNode, 'describe')
- ccUtils.setLabel(name, this.goodItemNode, 'name')
- }
- }
- onHide(): any {
- Mgr.event.removeAll(this)
- }
- //UI或者其他函数=======================================
- initRoleDetails() {
- let cfg = RoleConfig[this.curID]
- let good_parent = cc.find('good_parent', this.goodItemNode)
- cc.find('role_type', good_parent).active = !!cfg
- if (cfg) {
- this.loadTexImg(`Public/role/role_type_${cfg.profession}`, good_parent, 'role_type')
- }
- }
- initEquipDetails() {
- let armorConfig = ArmorConfig[this.curID]
- let node = this.equipItemNode
- let equipNode = cc.find('good_parent', node)
- let atk = cc.find('atk', node)
- let atkNum = cc.find('atknum', node)
- //属性值
- let attrNum =
- armorConfig.HP > 0
- ? armorConfig.HP
- : armorConfig.spellAttack > armorConfig.attack
- ? armorConfig.spellAttack
- : armorConfig.attack
- let attrName =
- armorConfig.HP > 0
- ? ATTR_NAME.HP
- : armorConfig.spellAttack > armorConfig.attack
- ? ATTR_NAME.spellAttack
- : ATTR_NAME.attack
- ccUtils.setLabel(armorConfig.name, node, 'name')
- ccUtils.setLabel(LANGUAGE_TYPE[attrName], atk)
- ccUtils.labelForceUpdateRenderData(atk)
- ccUtils.setLabel(attrNum.toString(), atkNum)
- atkNum.x = atk.x + atk.width
- //职业限定
- let professionNodes = ccUtils.instantChildren(cc.find('occupation/type', node), armorConfig.profession.length)
- for (let i = 0; i < professionNodes.length; i++) {
- this.loadTexImg(`Public/role/role_type_${armorConfig.profession[i]}`, professionNodes[i])
- }
- //词条
- let attrItemOrigin = cc.find('attrList/view/content/item', node)
- let tips: {entry: number; cfg: IArmorConfig}[] = []
- for (let i = 1; i <= Data.main.maxEquipQuality; i++) {
- let ID = Math.floor(armorConfig.ID / 100) * 100 + i
- if (ArmorConfig[ID.toString()].entry)
- tips.push({
- entry: ArmorConfig[ID.toString()].entry,
- cfg: ArmorConfig[ID.toString()],
- })
- }
- let attrItems = ccUtils.instantChildren(attrItemOrigin, tips.length)
- for (let i = 0; i < tips.length; i++) {
- let attrItem = attrItems[i]
- let tip = tips[i]
- cc.find('icon/lock_1', attrItem).active = tip.cfg.quality > armorConfig.quality
- this.loadTexImg(`Public/goodsQuality/item_frame${tip.cfg.qualityType}`, attrItem, 'icon/item_frame')
- let richTextNode = cc.find('richText', attrItem)
- ccUtils.setRichLabel(Mgr.i18n.getEntryLabel(tip.entry), richTextNode)
- if (tip.cfg.quality > armorConfig.quality) ccUtils.setRichLabelGray(richTextNode)
- this.scheduleOnce(() => {
- if (attrItem.activeInHierarchy) {
- let layout = attrItem.getComponent(cc.Layout)
- layout.resizeMode =
- richTextNode.height < 65 ? cc.Layout.ResizeMode.NONE : cc.Layout.ResizeMode.CONTAINER
- layout.updateLayout()
- if (richTextNode.height < 65) {
- attrItem.height = 65
- }
- }
- })
- }
- }
- initGoodsDetails(node: cc.Node) {
- Mgr.goods.initOneGoods({id: this.curID, num: 0}, cc.find('good_parent/good', node), this, {showDetails: false})
- }
- //网络事件=======================================
- // onXXXRsp() {}
- //触发事件=======================================
- // @render
- // showRender() {}
- // 点击事件=======================================
- // onClick() {}
- }
|