PlotHome.ts 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. import WOneByone from "../game/fight/evnet/map1/WOneByone";
  2. import Home from "../game/home/Home";
  3. import FqLogin from "../login/FqLogin";
  4. const { ccclass, property } = cc._decorator;
  5. /**
  6. * 第一次进入游戏主页时候的引导
  7. */
  8. @ccclass
  9. export default class PlotHome extends cc.Component {
  10. @property({
  11. displayName: '对话对象',
  12. type: [cc.Node]
  13. })
  14. mNode: Array<cc.Node> = [];
  15. @property(cc.Prefab)
  16. mMapDialog: cc.Prefab = null;
  17. @property([cc.String])
  18. text: Array<string> = [];
  19. @property(cc.Node)
  20. private mBlockInputEvents: cc.Node = null;
  21. /**
  22. * 冒险按钮
  23. */
  24. @property(cc.Node)
  25. mBtMx: cc.Node = null;
  26. @property(sp.Skeleton)
  27. mBtSpine: sp.Skeleton = null;//冒险菜单动画
  28. /**
  29. * 点击任意位置的回调
  30. */
  31. private blockInputCallback: () => void;
  32. private home: Home;
  33. onLoad() {
  34. this.home = this.node.getComponent(Home)
  35. }
  36. /**
  37. * 执行对话
  38. */
  39. public exDialog() {
  40. this.dialog(0)
  41. this.mBtSpine.node.parent.active = false;
  42. }
  43. public openMenu() {
  44. this.mNode[1].children[0].active = false;
  45. cc.tween(this).sequence(
  46. cc.delayTime(0.1),
  47. cc.callFunc(() => {
  48. this.mBtSpine.setAnimation(0, 'idle', true);
  49. })
  50. ).start()
  51. }
  52. private dialog(index: number) {
  53. if (index >= this.text.length) {
  54. this.setBlockInputCallback(null);
  55. this.moveToMx(() => {
  56. this.mBlockInputEvents.active = false;
  57. this.guideMX()
  58. })
  59. return;
  60. }
  61. let texts = this.text[index].split('|')
  62. let mid = parseInt(texts.shift());
  63. let curNode = this.mNode[mid]
  64. this.mBlockInputEvents.active = true
  65. this.showDialog(texts, curNode, null, () => {
  66. index++;
  67. this.dialog(index);
  68. });
  69. }
  70. /**
  71. * 对象头顶显示对话
  72. */
  73. private showDialog(dialogs: Array<string>,//对话内容
  74. curNode: cc.Node,//显示在地图中的位置
  75. spine: sp.Skeleton,//当前动画精灵
  76. callback: () => void)//对话结束后的回调
  77. {
  78. let node = cc.instantiate(this.mMapDialog);
  79. node.zIndex = 9999;
  80. node.y += curNode.height
  81. node.parent = curNode;
  82. let obo = node.getComponent(WOneByone);
  83. obo.dialogs = dialogs;
  84. obo.spine = spine;
  85. obo.setCallback(() => {
  86. node.destroy();
  87. callback();
  88. });
  89. this.setBlockInputCallback(() => {
  90. obo.jump();
  91. });
  92. obo._start();
  93. }
  94. public setBlockInputCallback(blockInputCallback: () => void) {
  95. this.blockInputCallback = blockInputCallback
  96. }
  97. public onclickBlockInput() {
  98. if (this.blockInputCallback) {
  99. this.blockInputCallback()
  100. }
  101. }
  102. /**
  103. * 幽灵移动到冒险按钮
  104. */
  105. private moveToMx(callback: () => void) {
  106. //1.幽灵变身
  107. let spine = this.mNode[1].children[0].getComponent(sp.Skeleton)
  108. spine.setAnimation(0, 'escape', false);
  109. spine.setCompleteListener(() => {
  110. spine.setCompleteListener(null)
  111. spine.setAnimation(0, 'fly', true);
  112. let pos = this.mBtMx.convertToWorldSpaceAR(cc.v2(0, 0));
  113. let winSize = cc.winSize;
  114. pos.x -= winSize.width / 2;
  115. pos.y -= winSize.height / 2;
  116. cc.tween(this.mNode[1]).sequence(
  117. cc.moveTo(1, pos),
  118. cc.callFunc(() => {
  119. this.openMenu1()
  120. callback()
  121. })
  122. ).start()
  123. })
  124. }
  125. private openMenu1() {
  126. this.mBtSpine.node.parent.active = true;
  127. this.mBtSpine.setCompleteListener(()=>{
  128. this.mBtSpine.setAnimation(0, 'idle', false);
  129. })
  130. this.mBtSpine.setAnimation(0, 'open', false);
  131. }
  132. /**
  133. * 强制引导到冒险
  134. */
  135. private guideMX() {
  136. let main = this.home.main
  137. let guideMask = main.mGuideMask
  138. guideMask.setTargetNode(this.mBtMx)
  139. guideMask.show()
  140. this.home.setMxCallback(() => {
  141. guideMask.close()
  142. this.home.setMxCallback(null)
  143. FqLogin.commitEvent('jinruguanqia','','')
  144. })
  145. }
  146. }