EquipAttrUI.ts 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /** @format */
  2. import {UI} from '../enums/UI'
  3. import {BaseUI} from './BaseUI'
  4. import {Data, Mgr} from '../GameControl'
  5. import {ccUtils} from '../utils/ccUtils'
  6. import {observer, render, node, label, editBox, list} from '../mobx/observer'
  7. import {msgCmd} from '../proto/msg_cmd'
  8. import List from '../uiutils/List'
  9. import {ATTR_NAME, LANGUAGE_TYPE} from '../enums/Enum'
  10. import {IBaseAttr, IRole} from '../interface/GlobalInterface'
  11. import {ArmorConfig} from '../config/ArmorConfig'
  12. const {ccclass, property} = cc._decorator
  13. @ccclass
  14. @observer
  15. export class EquipAttrUI extends BaseUI {
  16. @list('attrList')
  17. attrList: List
  18. @list('entryList')
  19. entryList: List
  20. entryData: number[] = []
  21. attrKeys: ATTR_NAME[] = [
  22. ATTR_NAME.HP,
  23. ATTR_NAME.defense,
  24. ATTR_NAME.attack,
  25. ATTR_NAME.spellAttack,
  26. ATTR_NAME.spellDefense,
  27. ATTR_NAME.attackCrit,
  28. ATTR_NAME.critNum,
  29. ATTR_NAME.dodge,
  30. ATTR_NAME.hit,
  31. ]
  32. allAttr: IBaseAttr
  33. onShow(args: IRole, fromUI: number) {
  34. this.entryData.length = 0
  35. let allAttr = Mgr.global.buildIBaseAttr(null, true)
  36. for (let equip of args.equips) {
  37. if (equip) {
  38. let baseID = equip.cfg.ID - (equip.cfg.ID % 100) + 1
  39. for (let i = baseID; i <= equip.cfg.ID; i++) {
  40. if (ArmorConfig[i].entry) this.entryData.push(ArmorConfig[i].entry)
  41. }
  42. Mgr.global.changeBaseAttr(allAttr, equip, true)
  43. }
  44. }
  45. this.allAttr = allAttr
  46. this.entryList.numItems = this.entryData.length
  47. this.attrList.numItems = this.attrKeys.length
  48. }
  49. initEntryItem(node, index) {
  50. let richTextNode = cc.find('richText', node)
  51. ccUtils.setRichLabel(Mgr.i18n.getEntryLabel(this.entryData[index]), richTextNode)
  52. this.scheduleOnce(() => {
  53. if (node.activeInHierarchy) {
  54. let layout = node.getComponent(cc.Layout)
  55. layout.resizeMode =
  56. richTextNode.height < 60 ? cc.Layout.ResizeMode.NONE : cc.Layout.ResizeMode.CONTAINER
  57. layout.updateLayout()
  58. if (richTextNode.height < 60) {
  59. node.height = 60
  60. }
  61. }
  62. })
  63. }
  64. initAttrItem(node, index) {
  65. let attrName = this.attrKeys[index]
  66. let rateKey = [ATTR_NAME.attackCrit, ATTR_NAME.critNum, ATTR_NAME.dodge, ATTR_NAME.hit]
  67. let num: string = rateKey.includes(attrName)
  68. ? Math.floor(this.allAttr[attrName] / Data.game.rateNum) + '%'
  69. : this.allAttr[attrName]
  70. ccUtils.setLabel(num, node, 'attrNum')
  71. ccUtils.setLabel(LANGUAGE_TYPE[attrName], node, 'attrName')
  72. this.loadTexImg(`Public/allAttr/${attrName}`, node, 'icon')
  73. }
  74. }