edit_scene.ts 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. import { _decorator, Component, Node, Prefab } from 'cc';
  2. import { tools } from '../tools';
  3. import { config } from '../config';
  4. import { control } from './control';
  5. import { main } from '../main';
  6. import { scene_item_data } from '../../data/data';
  7. import { scene_select_list } from './scene_select_list';
  8. import { ClientEvent } from '../clientEvent';
  9. import { cur_edit_scene } from './cur_edit_scene';
  10. import { scene_task } from './task/scene_task';
  11. import { http } from '../http';
  12. import { Attributes } from './Attributes';
  13. import { gameManager } from '../run/gameManager';
  14. const { ccclass, property } = _decorator;
  15. @ccclass('edit_scene')
  16. export class edit_scene extends Component {
  17. @property(Node) btn_add_scene:Node = null;
  18. @property(Node) btn_run:Node = null;
  19. @property(Node) btn_run_all:Node = null;
  20. @property(Node) btn_save:Node = null;
  21. @property(Node) btn_delete:Node = null;
  22. @property(Node) scene_select_list:Node = null;
  23. @property(Node) scene_task:Node = null;
  24. @property(Prefab) scene_prefab:Prefab = null;
  25. @property(Node) cur_edit_scene_node:Node = null;
  26. @property(Node) btn_widget_list:Node = null;
  27. private m_main:main = null;
  28. public getMain(){
  29. return this.m_main;
  30. }
  31. public init(_main:main){
  32. this.m_main = _main
  33. this.initSceneList()
  34. this.cur_edit_scene_node.getComponent(cur_edit_scene).initView(this)
  35. this.scene_select_list.getComponent(scene_select_list).initView(this.m_main)
  36. this.scene_task.getComponent(scene_task).initView(this)
  37. }
  38. public getTaskData(){
  39. return this.scene_task.getComponent(scene_task).getTaskData()
  40. }
  41. public getCurSelectSceneIndex(){
  42. return this.scene_select_list.getComponent(scene_select_list).getCurSelectSceneIndex();
  43. }
  44. public getCurSelectScene(){
  45. return this.scene_select_list.getComponent(scene_select_list).getCurSelectScene()
  46. }
  47. public getCurEditBaseView(){
  48. return this.cur_edit_scene_node.getComponent(cur_edit_scene).getCurEditBaseView()
  49. }
  50. public getPrefabByType():Prefab{
  51. return this.scene_prefab;
  52. }
  53. initSceneList(){
  54. }
  55. onAddScene(data:scene_item_data){
  56. this.m_main.control_view.push_scene_data(data)
  57. ClientEvent.dispatchEvent(config.Event.UpdateSceneList)
  58. }
  59. protected start(): void {
  60. this.btn_add_scene.on(Node.EventType.TOUCH_END,()=>{
  61. tools.show_add_scene(this.onAddScene.bind(this))
  62. })
  63. this.btn_run.on(Node.EventType.TOUCH_END,()=>{
  64. let curScene = this.getCurSelectScene()
  65. if(curScene.is_child_scene){
  66. return tools.showToast("子场景不可以运行")
  67. }
  68. tools.game_run()
  69. })
  70. this.btn_run_all.on(Node.EventType.TOUCH_END,()=>{
  71. tools.game_run_all()
  72. })
  73. this.btn_save.on(Node.EventType.TOUCH_END,()=>{
  74. gameManager.requestSaveEditScene()
  75. })
  76. this.btn_delete.on(Node.EventType.TOUCH_END,()=>{
  77. if(this.m_main.control_view.get_bag_data().content.length<=0){
  78. tools.showToast("暂无场景可以删除!")
  79. }else{
  80. tools.show_dialog("是否删除当前选中的场景?",()=>{
  81. this.m_main.control_view.remove_scene_data(this.scene_select_list.getComponent(scene_select_list).getCurSelectScene())
  82. ClientEvent.dispatchEvent(config.Event.UpdateSceneList)
  83. })
  84. }
  85. })
  86. this.btn_widget_list.on(Node.EventType.TOUCH_END,()=>{
  87. Attributes.Singleton.hideAllAtt()
  88. ClientEvent.dispatchEvent(config.Event.ShowWidgetList)
  89. })
  90. }
  91. }