Guide.ts 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. import { GuideVO } from "../../data/module/GuideData";
  2. /**
  3. * @description 新手引导
  4. * @author 邹勇
  5. */
  6. const { ccclass, property } = cc._decorator;
  7. @ccclass
  8. export default class Guide extends cc.Component {
  9. @property({ type: cc.Node, displayName: "显示区域" })
  10. node_display: cc.Node = null;
  11. @property({ type: cc.Node, displayName: "点击区域" })
  12. node_click: cc.Node = null;
  13. @property({ type: cc.Node, displayName: "背景" })
  14. node_bg: cc.Node = null;
  15. @property({ type: cc.Sprite, displayName: "手指" })
  16. node_finger: cc.Sprite = null;
  17. @property({ type: cc.Sprite, displayName: "头像" })
  18. node_head: cc.Sprite = null;
  19. @property({ type: cc.Sprite, displayName: "形象" })
  20. node_person: cc.Sprite = null;
  21. @property({ type: cc.RichText, displayName: "对话内容" })
  22. rich_dialog: cc.RichText = null;
  23. private guides: GuideVO[];
  24. private crtStep: number;
  25. private crtGuide: GuideVO;
  26. private targetNode: cc.Node;
  27. private event_name: string;
  28. onLoad() {
  29. }
  30. start() {
  31. if (gData.guideData.crtID == null) {
  32. this.node.destroy();
  33. return;
  34. }
  35. this.guides = gData.guideData.getGuidesByID(gData.guideData.crtID);
  36. this.crtStep = -1;
  37. this.nextStep();
  38. }
  39. private nextStep() {
  40. this.crtStep++;
  41. this.crtGuide = this.guides[this.crtStep];
  42. this.updateGuide();
  43. }
  44. private updateGuide() {
  45. if (this.crtGuide == null) {
  46. this.close();
  47. }
  48. else {
  49. this.targetNode = null;
  50. this.event_name = null;
  51. //点击全屏下一步,显示区域不显示,点击区域全屏
  52. if (this.crtGuide.click_rect == "all") {
  53. this.node_display.width = 0;
  54. this.node_display.height = 0;
  55. this.node_click.x = 0;
  56. this.node_click.y = 0;
  57. this.node_click.width = this.node.width;
  58. this.node_click.height = this.node.height;
  59. }
  60. else if (this.crtGuide.click_rect.indexOf("event") != -1) {//点击区域下一步,并发送事件,显示区域读配置,点击区域=显示区域
  61. this.event_name = "event_guide_" + this.crtGuide.id + "_" + this.crtStep;
  62. let arr = this.crtGuide.display_rect.split(":");
  63. this.node_display.x = this.node_click.x = parseInt(arr[0]);
  64. this.node_display.y = this.node_click.y = parseInt(arr[1]);
  65. this.node_display.width = this.node_click.width = parseInt(arr[2]);
  66. this.node_display.height = this.node_click.height = parseInt(arr[3]);
  67. }
  68. else {//点击按钮下一步,显示区域为配置的node,点击区域=显示区域
  69. this.targetNode = cc.find("Canvas/" + this.crtGuide.click_rect);
  70. this.node_display.width = this.targetNode.width;
  71. this.node_display.height = this.targetNode.height;
  72. let pos = mk.game.getWorldPos(this.targetNode);
  73. this.node_display.setPosition(pos);
  74. }
  75. if (this.crtGuide.finger == "") {
  76. this.node_finger.node.active = false;
  77. }
  78. else {
  79. this.node_finger.node.active = true;
  80. let arr = this.crtGuide.finger.split(":");
  81. this.node_finger.node.x = this.node_display.x + parseInt(arr[0]);
  82. this.node_finger.node.y = this.node_display.y + parseInt(arr[1]);
  83. }
  84. if (this.crtGuide.tr_form == 1) {
  85. this.node_head.node.active = true;
  86. this.node_person.node.active = false;
  87. }
  88. else {
  89. this.node_head.node.active = false;
  90. this.node_person.node.active = true;
  91. }
  92. this.node_bg.x = -this.node_display.x;
  93. this.node_bg.y = -this.node_display.y;
  94. this.rich_dialog.string = `<color=#000000>${this.crtGuide.dialog}</color>`;
  95. }
  96. }
  97. async clickNodeClick() {
  98. console.log("clickNodeClick");
  99. if (this.targetNode) {
  100. this.targetNode.getComponent(cc.Button).clickEvents[0].emit([]);
  101. }
  102. if (this.event_name) {
  103. mk.event.emit(this.event_name);
  104. }
  105. if (this.crtGuide.lag_next > 0) {
  106. await mk.time.WaitForSeconds(this.crtGuide.lag_next);
  107. }
  108. this.nextStep();
  109. }
  110. private close() {
  111. mk.guide.close();
  112. this.node.destroy();
  113. }
  114. }