FPanelIcon.ts 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. import { GameViewType } from "../../../main/ViewManage";
  2. import ViewObject from "../../../main/ViewObject";
  3. import RedPoint from "../../data/RedPoint";
  4. import Equip from "../../home/equip/Equip";
  5. import SetLeader from "../../home/equip/SetLeader";
  6. import FPanel from "./FPanel";
  7. /**
  8. * 头像
  9. */
  10. const { ccclass, property } = cc._decorator;
  11. @ccclass
  12. export default class FPanelIcon extends FPanel {
  13. @property(cc.Sprite)
  14. mIcon: cc.Sprite = null;
  15. @property(cc.Node)
  16. mIconX: cc.Node = null;
  17. @property(cc.Node)
  18. mLeader: cc.Node = null;//队长标识
  19. public inGuide = false//当前是否处于引导中
  20. public guideStep: number = 0;
  21. /**
  22. * 引导中的点击回调
  23. */
  24. private guideCallback: () => void
  25. onLoad() {
  26. this.mIconX.active = false;
  27. }
  28. public setGuideCallback(guideCallback: () => void) {
  29. this.guideCallback = guideCallback
  30. }
  31. /**
  32. * 更新当前面板
  33. */
  34. public updatePanel() {
  35. if (this.sprite) {
  36. this.mHPBar.progress = this.sprite.hp / this.sprite.attrData.hp;
  37. if (this.mLabel) {
  38. this.mLabel.string = this.sprite.hp + '/' + this.sprite.attrData.hp;
  39. }
  40. if (this.sprite.hp <= 0) {
  41. this.mIconX.active = true;
  42. } else {
  43. this.mIconX.active = false;
  44. }
  45. }
  46. }
  47. public setCancel() {
  48. }
  49. public setClose() {
  50. }
  51. /**
  52. * 设置头像
  53. */
  54. public setIcon() {
  55. let ffAttr = this.sprite.attrData
  56. let headIcon = ffAttr.skin
  57. if (headIcon == '30000') {
  58. headIcon = '' + ffAttr.id
  59. }
  60. cc.resources.load('icon/role_head/' + headIcon, cc.SpriteFrame, (err, spriteFrame: cc.SpriteFrame) => {
  61. if (err) {
  62. cc.error(err);
  63. } else {
  64. this.mIcon.spriteFrame = spriteFrame;
  65. }
  66. });
  67. let main = this.sprite.ff.main
  68. let player = main.player
  69. if (this.sprite.attrData.id == player.role.leader) {
  70. this.mLeader.active = true;
  71. } else {
  72. this.mLeader.active = false;
  73. }
  74. }
  75. public onclick() {
  76. let res = this.sprite.map.ff.fres
  77. let nodes = res.mHudNode.children
  78. for (let i = 0; i < nodes.length; i++) {
  79. const element = nodes[i];
  80. RedPoint.removeRed(element)
  81. }
  82. let main = this.sprite.map.ff.main
  83. this.sprite.ff.pauseSprite(true)
  84. main.viewManage.loadFunc(GameViewType.equip, (viewObject: ViewObject) => {
  85. viewObject.show();
  86. let topNode = this.sprite.ff.main.topNode;
  87. topNode.active = true;
  88. let equip: Equip = viewObject as Equip
  89. equip.inGuide = this.inGuide
  90. equip.guideStep = this.guideStep;
  91. this.inGuide = false
  92. equip.openId = this.sprite.attrData.id
  93. let setLeader = equip.node.getComponent(SetLeader)
  94. setLeader.mSetButton.active = false
  95. equip.setCloseCallback(() => {
  96. if (this.sprite.isValid && this.sprite.ff.isValid) {
  97. this.sprite.ff.pauseSprite(false)
  98. this.sprite.map.ff.updateRole()
  99. }
  100. topNode.active = false;
  101. })
  102. });
  103. if (this.guideCallback) {
  104. this.guideCallback()
  105. }
  106. }
  107. }