UserGuideUI.ts 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /** @format */
  2. import {BaseUI} from './BaseUI'
  3. import {ccUtils} from '../utils/ccUtils'
  4. import {observer} from '../mobx/observer'
  5. import {GUIDE_TYPE, LANGUAGE_TYPE} from '../enums/Enum'
  6. import {IUserGuide} from '../interface/UIInterface'
  7. import {Data, Mgr} from '../GameControl'
  8. import {IMonsterManualConfig, MonsterManualConfig} from '../config/MonsterManualConfig'
  9. const {ccclass, property} = cc._decorator
  10. @ccclass
  11. @observer
  12. export class UserGuideUI extends BaseUI {
  13. callback: Function
  14. curPage: number = 1
  15. allPageNum: number = 2
  16. onShow(args: IUserGuide, fromUI: number) {
  17. let key = GUIDE_TYPE[args.guideType]
  18. ccUtils.setLabel(
  19. args.guideType == GUIDE_TYPE.monster ? LANGUAGE_TYPE.specialEnemy : LANGUAGE_TYPE.explain,
  20. this.node,
  21. 'title/label',
  22. )
  23. this.callback = args.callback
  24. cc.find('all', this.node).children.forEach(value => {
  25. value.active = value.name == key
  26. if (value.active) {
  27. this.allPageNum = value.children.length
  28. if (args.guideType == GUIDE_TYPE.monster) {
  29. let cfg: IMonsterManualConfig = Object.values(MonsterManualConfig).find(
  30. v => v.trigger == Data.game.stageID,
  31. )
  32. if (cfg) {
  33. Mgr.global.initRoleSpineByName(cfg.resources, value, 'spine')
  34. ccUtils.setLabel(cfg.monster, value, 'name')
  35. ccUtils.setLabel(cfg.skill, value, 'des')
  36. let attrs = ccUtils.instantChildren(cc.find('attrs/attr', value), cfg.features.length)
  37. for (let i = 0; i < attrs.length; i++) {
  38. let attr = attrs[i]
  39. let feature = cfg.features[i]
  40. ccUtils.setLabel(feature, attr)
  41. }
  42. }
  43. }
  44. }
  45. })
  46. this.curPage = 1
  47. }
  48. onHide(): any {
  49. this.callback && this.callback()
  50. return super.onHide()
  51. }
  52. //UI或者其他函数=======================================
  53. switchPage(node: cc.Node) {
  54. node.parent.children.forEach(value => (value.active = value.name == `page${this.curPage}`))
  55. }
  56. //网络事件=======================================
  57. //触发事件=======================================
  58. // 点击事件=======================================
  59. onNextClick(e) {
  60. this.curPage += 1
  61. if (this.curPage > this.allPageNum) this.curPage = 1
  62. this.switchPage(e.target.parent)
  63. }
  64. onPreClick(e) {
  65. this.curPage -= 1
  66. if (this.curPage < 1) this.curPage = 1
  67. this.switchPage(e.target.parent)
  68. }
  69. }