FPlantTrre.ts 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. import BaseEvent from "../base/BaseEvent";
  2. /**
  3. * 种树
  4. */
  5. const {ccclass, property} = cc._decorator;
  6. @ccclass
  7. export default class FPlantTrre extends BaseEvent {
  8. @property({
  9. displayName: '魔树动画',
  10. type: sp.Skeleton
  11. })
  12. mSpine: sp.Skeleton = null;
  13. @property([cc.String])
  14. text: Array<string> = [];
  15. @property({
  16. displayName: '提示图标',
  17. type: cc.SpriteFrame
  18. })
  19. mTipsIcon: cc.SpriteFrame = null;
  20. @property({
  21. displayName: '出现的机关',
  22. type: cc.Node
  23. })
  24. mGearNode: cc.Node = null;
  25. @property({
  26. displayName: '钥匙',
  27. type: cc.Node
  28. })
  29. mKeyNode: cc.Node = null;
  30. onLoad() {
  31. super.onLoad()
  32. if(this.mSpine){
  33. this.mSpine.node.active = false
  34. }
  35. if(this.mGearNode){
  36. this.mGearNode.active = false
  37. }
  38. if(this.mKeyNode){
  39. this.mKeyNode.active = false
  40. }
  41. }
  42. onBegin(tag:number){
  43. if (tag == 1) {
  44. this.showOpt(this.mTipsIcon, () => {
  45. let head = this.ff.mFFheader;
  46. let count = head.getTmpCount(2007);
  47. if(count > 0){ //有魔豆的时候
  48. head.removeTmpGood(2007,1)
  49. this.showKey()
  50. }else{//没有魔豆
  51. this.pause()
  52. this.dialog(0)
  53. }
  54. })
  55. }
  56. }
  57. onEnd(tag:number){
  58. if (tag == 1) {
  59. this.closeOpt()
  60. }
  61. }
  62. private dialog(index:number){
  63. if(index >= this.text.length){
  64. this.resume()
  65. return;
  66. }
  67. let texts = this.text[index].split('|')
  68. let mid = parseInt(texts.shift());
  69. if(mid == -1){//主角
  70. let my = this.ff.mainSprite.node;
  71. this.showDialog(my,texts,()=>{
  72. index ++;
  73. this.dialog(index);
  74. });
  75. }
  76. }
  77. private showKey(){
  78. this.pause()
  79. this.mSpine.node.active = true
  80. this.mSpine.setCompleteListener(()=>{
  81. this.mSpine.setCompleteListener(null)
  82. let pos = this.mGearNode.getPosition()
  83. this.moveCamera(pos,1,()=>{
  84. this.showKey1()
  85. })
  86. })
  87. this.mSpine.setAnimation(0,'grow',false)
  88. }
  89. private showKey1(){
  90. this.mGearNode.active = true
  91. this.mKeyNode.active = true
  92. this.mGearNode.y += 200;
  93. this.mKeyNode.y += 200;
  94. cc.tween(this.mGearNode).sequence(
  95. cc.moveBy(1,cc.v2(0,-200)),
  96. cc.callFunc(()=>{
  97. this.resume()
  98. })
  99. ).start()
  100. cc.tween(this.mKeyNode).sequence(
  101. cc.moveBy(1,cc.v2(0,-200)),
  102. cc.callFunc(()=>{
  103. })
  104. ).start()
  105. }
  106. }