FMqs.ts 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import FObject from "../object/FObject";
  2. import FF from "../FF";
  3. import DialogButton from "../box/DialogButton";
  4. import i18n from "../../../i18n/i18n";
  5. /**
  6. * 泉水
  7. */
  8. const {ccclass, property} = cc._decorator;
  9. @ccclass
  10. export default class FMqs extends cc.Component {
  11. @property({
  12. type:cc.Prefab,
  13. displayName: '事件按钮'
  14. })
  15. mDialog: cc.Prefab = null;
  16. @property({
  17. type:cc.Prefab,
  18. displayName: '对话框'
  19. })
  20. mDialog1: cc.Prefab = null;
  21. public temp:cc.Node = null;
  22. public ff:FF = null;
  23. public count:number = 0;
  24. onBeginContact(contact: cc.PhysicsContact, selfCollider: cc.PhysicsCollider, otherCollider: cc.PhysicsCollider){
  25. if(otherCollider.node.group == 'A'){
  26. let sobject = otherCollider.node.getComponent(FObject);
  27. if(sobject){
  28. let ff = sobject.ff;
  29. this.ff = ff;
  30. this.count ++;
  31. this.showButton(ff);
  32. }
  33. }
  34. }
  35. onEndContact(contact: cc.PhysicsContact, selfCollider: cc.PhysicsCollider, otherCollider: cc.PhysicsCollider){
  36. if(otherCollider.node.group == 'A'){
  37. let sobject = otherCollider.node.getComponent(FObject);
  38. if(sobject){
  39. let ff = sobject.ff;
  40. this.count --;
  41. if(this.count <= 0){
  42. this.closeButton();
  43. }
  44. }
  45. }
  46. }
  47. public showButton(ff:FF){
  48. if(this.temp){
  49. return;
  50. }
  51. let node = cc.instantiate(this.mDialog);
  52. ff.main.viewManage.popView(node);
  53. this.temp = node;
  54. let fbutton = node.getComponent(DialogButton);
  55. fbutton.label.string = i18n.t('饮用')
  56. fbutton.setCallback(()=>{
  57. this.closeButton();
  58. this.openDialog();
  59. });
  60. }
  61. public closeButton(){
  62. this.count = 0;
  63. if(this.temp){
  64. this.temp.destroy();
  65. this.temp = null;
  66. }
  67. }
  68. public openDialog(){
  69. let node = cc.instantiate(this.mDialog1);
  70. this.ff.main.viewManage.popView(node);
  71. }
  72. }