FDialogPet.ts 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. import FF from "../FF";
  2. import { GroupType } from "../object/FObject";
  3. import FSprite, { SpriteActionType } from "../object/FSprite";
  4. import WOneByone from "./map1/WOneByone";
  5. /**
  6. * 伙伴间的对话
  7. */
  8. const {ccclass, property} = cc._decorator;
  9. @ccclass
  10. export default class FDialogPet extends cc.Component {
  11. @property(cc.Prefab)
  12. mMapDialog: cc.Prefab = null;
  13. @property([cc.String])
  14. text: Array<string> = [];
  15. @property({
  16. displayName: '移除伙伴id',
  17. type:[cc.Integer]
  18. })
  19. mRemoveId: Array<number> = [];//对话结束移出的伙伴id
  20. private ff:FF
  21. private isOver = false;
  22. onBeginContact(contact: cc.PhysicsContact, selfCollider: cc.PhysicsCollider, otherCollider: cc.PhysicsCollider){
  23. if(this.isOver){
  24. return
  25. }
  26. if(otherCollider.node.group == 'A'){//主角踩到机关
  27. let obj = otherCollider.node.getComponent(FSprite);
  28. this.ff = obj.ff;
  29. if(obj == this.ff.mainSprite){
  30. this.node.removeComponent(cc.PhysicsBoxCollider);
  31. this.ff = obj.ff;
  32. this.isOver = true;
  33. this.startFight();
  34. }
  35. }
  36. }
  37. /**
  38. * 开始
  39. */
  40. private startFight(){
  41. this.ff.pauseSprite(true);
  42. this.dialog(0);
  43. }
  44. //移除伙伴
  45. private removePet(){
  46. for (let i = 0; i < this.mRemoveId.length; i++) {
  47. const id = this.mRemoveId[i];
  48. this.ff.removePet(id);
  49. }
  50. }
  51. private dialog(index:number){
  52. if(index >= this.text.length){
  53. this.ff.mBlockInputEvents.active = false;
  54. this.ff.pauseSprite(false);
  55. this.node.destroy();
  56. this.removePet();
  57. return;
  58. }
  59. let mysprites = this.ff.getGroupBy(GroupType.A);
  60. let texts = this.text[index].split('|')
  61. let action = texts.shift();
  62. let mid = parseInt(action);
  63. let my = mysprites[mid].node;
  64. this.showDialog(my,texts,()=>{
  65. index ++;
  66. this.dialog(index);
  67. });
  68. }
  69. private showDialog(my:cc.Node,dialogs,fCallback:()=>void){
  70. let d1 = dialogs[0] as string;
  71. if(d1.indexOf('#') == 0){//第一个字符为#表示表情
  72. let sprite = my.getComponent(FSprite)
  73. let spine = sprite.spine;
  74. if(spine){
  75. spine.setCompleteListener(()=>{
  76. spine.setAnimation(0, SpriteActionType.stand, true);
  77. fCallback();
  78. })
  79. let action = d1.replace('#','');
  80. spine.setAnimation(0,action, false);
  81. }else{
  82. fCallback();
  83. }
  84. }else{
  85. this.ff.mBlockInputEvents.active = true;
  86. let node = cc.instantiate(this.mMapDialog);
  87. node.group = 'map'
  88. node.zIndex = 9999;
  89. node.x = my.x;
  90. node.y = my.y + my.height;
  91. node.parent = this.ff.mMap.mSprites;
  92. let obo = node.getComponent(WOneByone);
  93. obo.dialogs = dialogs;
  94. obo.setCallback(()=>{
  95. node.destroy();
  96. this.ff.setBlockInputCallback(null);
  97. fCallback();
  98. });
  99. this.ff.setBlockInputCallback(()=>{
  100. obo.jump();
  101. });
  102. obo._start();
  103. }
  104. }
  105. }