add_event.ts 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import { _decorator, Component, EditBox, instantiate, Node, Prefab } from 'cc';
  2. import { config } from '../../config';
  3. import { add_event_item } from './add_event_item';
  4. import { tools } from '../../tools';
  5. const { ccclass, property } = _decorator;
  6. @ccclass('add_event')
  7. export class add_event extends Component {
  8. @property(Node) content:Node = null;
  9. @property(Node) btn_close:Node = null;
  10. @property(Prefab) item_prefab:Prefab = null;
  11. @property(Node) btn_add:Node = null;
  12. @property(Node) btn_cancel:Node = null;
  13. @property(EditBox) edit:EditBox = null;
  14. @property(Node) input_event_name:Node = null;
  15. private call_back = null;
  16. private select_type:number = 0;
  17. public show(call){
  18. this.call_back = call;
  19. this.input_event_name.active = false;
  20. config.event_type_map.forEach((v,k)=>{
  21. let item = instantiate(this.item_prefab)
  22. item.parent = this.content;
  23. item.getComponent(add_event_item).initView(k,this.onItemClick.bind(this))
  24. })
  25. this.btn_close.on(Node.EventType.TOUCH_END,()=>{
  26. this.close()
  27. })
  28. this.btn_add.on(Node.EventType.TOUCH_END,()=>{
  29. if(this.edit.string.length>0){
  30. if(this.call_back!=null){
  31. this.call_back(this.select_type,this.edit.string)
  32. }
  33. this.close()
  34. }else{
  35. tools.showToast("请输入事件名字")
  36. }
  37. })
  38. this.btn_cancel.on(Node.EventType.TOUCH_END,()=>{
  39. this.input_event_name.active = false;
  40. })
  41. }
  42. onItemClick(type:number){
  43. this.select_type = type;
  44. this.input_event_name.active = true;
  45. }
  46. close(){
  47. this.node.destroy()
  48. }
  49. }