tools.ts 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. import { _decorator, assetManager, Component, ImageAsset, instantiate, Node, Prefab, resources, Sprite, SpriteFrame, Texture2D } from 'cc';
  2. import { main } from './main';
  3. import { toast } from './toast';
  4. import { add_scene } from './edit/add_scene';
  5. import { dialog_view } from './dialog_view';
  6. import { scene_select_list } from './edit/scene_select_list';
  7. import { sceme_type_select_item } from './sceme_type_select_item';
  8. import { slide_dir_select } from './edit/slide_dir_select';
  9. import { click_type_select } from './click_type_select';
  10. import { add_event } from './edit/event/add_event';
  11. import { add_task } from './edit/task/add_task';
  12. import { add_animation } from './edit/animation/add_animation';
  13. import { att_ani_data, event_item, widget_item_data } from '../data/data';
  14. import { select_widget_list } from './edit/event/select_widget_list';
  15. import { select_animation } from './edit/animation/select_animation';
  16. import { show_widget_list } from './edit/show_widget_list';
  17. import { select_ui_top_type } from './edit/uiWidget/select_ui_top_type';
  18. import { show_select_child_scene } from './edit/uiWidget/show_select_child_scene';
  19. import { show_select_evele_list } from './edit/show_select_evele_list';
  20. import { select_collect_event } from './edit/event/select_collect_event';
  21. import { select_res_list } from './select_res_list';
  22. import { select_task_zhao_xi_jie } from './edit/task/select_task_zhao_xi_jie';
  23. import { show_select_z_index } from './edit/attributes/show_select_z_index';
  24. import { game_run } from './run/game_run';
  25. import { config } from './config';
  26. import { edit_event } from './edit/event/edit_event';
  27. import { select_sound_list } from './edit/select_sound_list';
  28. import { select_task_da_guai } from './edit/task/select_task_da_guai';
  29. export class tools {
  30. public static show_dialog(title="是否确定?",sure_callback,cancel_callback=null){
  31. resources.load("prefab/dialog_view",Prefab,(err, prefab)=>{
  32. let node = instantiate(prefab);
  33. node.parent = main.g_canvas.node;
  34. node.getComponent(dialog_view).show(title,sure_callback,cancel_callback)
  35. })
  36. }
  37. public static show_loading(call=null){
  38. resources.load("prefab/loading",Prefab,(err, prefab)=>{
  39. if(!main.loading_view){
  40. let node = instantiate(prefab);
  41. node.name = "loading"
  42. node.parent = main.g_canvas.node;
  43. main.loading_view = node;
  44. if(call!=null){
  45. call()
  46. }
  47. }
  48. })
  49. }
  50. public static hide_loading(){
  51. if(main.loading_view!=null){
  52. main.loading_view.removeFromParent()
  53. main.loading_view =null;
  54. }
  55. }
  56. public static showToast(text:string){
  57. resources.load("prefab/toast",Prefab,(err, prefab)=>{
  58. let node = instantiate(prefab);
  59. node.name = "toast"
  60. node.parent = main.g_canvas.node;
  61. node.getComponent(toast).show(text)
  62. })
  63. }
  64. public static show_add_scene(call){
  65. resources.load("prefab/add_scene",Prefab,(err, prefab)=>{
  66. let node = instantiate(prefab);
  67. node.parent = main.g_canvas.node;
  68. node.getComponent(add_scene).initView(call)
  69. })
  70. }
  71. public static add_scene_page(call){
  72. resources.load("prefab/sceme_type_select_item",Prefab,(err, prefab)=>{
  73. let node = instantiate(prefab);
  74. node.parent = main.g_canvas.node;
  75. node.getComponent(sceme_type_select_item).initView(call)
  76. })
  77. }
  78. public static show_slide_dir_select(call){
  79. resources.load("prefab/slide_dir_select",Prefab,(err, prefab)=>{
  80. let node = instantiate(prefab);
  81. node.parent = main.g_canvas.node;
  82. node.getComponent(slide_dir_select).show(call)
  83. })
  84. }
  85. public static show_click_type_select(call){
  86. resources.load("prefab/click_type_select",Prefab,(err, prefab)=>{
  87. let node = instantiate(prefab);
  88. node.parent = main.g_canvas.node;
  89. node.getComponent(click_type_select).show(call)
  90. })
  91. }
  92. public static show_add_event(call){
  93. resources.load("prefab/add_event",Prefab,(err, prefab)=>{
  94. let node = instantiate(prefab);
  95. node.parent = main.g_canvas.node;
  96. node.getComponent(add_event).show(call)
  97. })
  98. }
  99. public static show_add_task(call){
  100. resources.load("prefab/add_task",Prefab,(err, prefab)=>{
  101. let node = instantiate(prefab);
  102. node.parent = main.g_canvas.node;
  103. node.getComponent(add_task).show(call)
  104. })
  105. }
  106. public static show_add_animation(list,call){
  107. resources.load("prefab/add_animation",Prefab,(err, prefab)=>{
  108. let node = instantiate(prefab);
  109. node.parent = main.g_canvas.node;
  110. node.getComponent(add_animation).show(list,call)
  111. })
  112. }
  113. public static show_select_widget_list(list:widget_item_data[],call,id:number=-1){
  114. resources.load("prefab/select_widget_list",Prefab,(err, prefab)=>{
  115. let node = instantiate(prefab);
  116. node.parent = main.g_canvas.node;
  117. node.getComponent(select_widget_list).show(list,call,id)
  118. })
  119. }
  120. public static show_widget_list(list){
  121. resources.load("prefab/show_widget_list",Prefab,(err, prefab)=>{
  122. let node = instantiate(prefab);
  123. node.parent = main.g_canvas.node;
  124. node.getComponent(show_widget_list).show(list)
  125. })
  126. }
  127. public static show_select_animation_list(list:att_ani_data[],call,id:number=-1){
  128. resources.load("prefab/select_animation",Prefab,(err, prefab)=>{
  129. let node = instantiate(prefab);
  130. node.parent = main.g_canvas.node;
  131. node.getComponent(select_animation).show(list,call,id)
  132. })
  133. }
  134. public static show_select_ui_top_type(call){
  135. resources.load("prefab/ui/select_ui_top_type",Prefab,(err, prefab)=>{
  136. let node:Node = instantiate(prefab);
  137. node.parent = main.g_canvas.node;
  138. node.getComponent(select_ui_top_type).show(call)
  139. })
  140. }
  141. public static show_select_child_scene(list,call){
  142. resources.load("prefab/ui/show_select_child_scene",Prefab,(err, prefab)=>{
  143. let node:Node = instantiate(prefab);
  144. node.parent = main.g_canvas.node;
  145. node.getComponent(show_select_child_scene).show(list,call)
  146. })
  147. }
  148. public static show_select_evele_list(list,call){
  149. resources.load("prefab/show_select_evele_list",Prefab,(err, prefab)=>{
  150. let node:Node = instantiate(prefab);
  151. node.parent = main.g_canvas.node;
  152. node.getComponent(show_select_evele_list).show(list,call)
  153. })
  154. }
  155. public static select_collect_event(list,call,event_id,event_list_id){
  156. resources.load("prefab/ui/select_collect_event",Prefab,(err, prefab)=>{
  157. let node:Node = instantiate(prefab);
  158. node.parent = main.g_canvas.node;
  159. node.getComponent(select_collect_event).show(list,call,event_id,event_list_id)
  160. })
  161. }
  162. public static select_res_list(call){
  163. resources.load("prefab/ui/select_res_list",Prefab,(err, prefab)=>{
  164. let node:Node = instantiate(prefab);
  165. node.parent = main.g_canvas.node;
  166. node.getComponent(select_res_list).initView(call)
  167. })
  168. }
  169. public static select_sound_list(call){
  170. resources.load("prefab/ui/select_sound_list",Prefab,(err, prefab)=>{
  171. let node:Node = instantiate(prefab);
  172. node.parent = main.g_canvas.node;
  173. node.getComponent(select_sound_list).initView(call)
  174. })
  175. }
  176. public static select_task_zhao_xi_jie(data){
  177. resources.load("prefab/task/select_task_zhao_xi_jie",Prefab,(err, prefab)=>{
  178. let node:Node = instantiate(prefab);
  179. node.parent = main.g_canvas.node;
  180. node.getComponent(select_task_zhao_xi_jie).show(data)
  181. })
  182. }
  183. public static select_task_da_guai(data){
  184. resources.load("prefab/task/select_task_da_guai",Prefab,(err, prefab)=>{
  185. let node:Node = instantiate(prefab);
  186. node.parent = main.g_canvas.node;
  187. node.getComponent(select_task_da_guai).show(data)
  188. })
  189. }
  190. public static show_select_z_index(call){
  191. resources.load("prefab/show_select_z_index",Prefab,(err, prefab)=>{
  192. let node:Node = instantiate(prefab);
  193. node.parent = main.g_canvas.node;
  194. node.getComponent(show_select_z_index).show(call)
  195. })
  196. }
  197. public static show_select_dir(call){
  198. resources.load("prefab/show_select_z_index",Prefab,(err, prefab)=>{
  199. let node:Node = instantiate(prefab);
  200. node.parent = main.g_canvas.node;
  201. node.getComponent(show_select_z_index).showDir(call)
  202. })
  203. }
  204. public static loadUrl(url:string,spr:Sprite){
  205. if(url.length<=0){
  206. return null;
  207. }
  208. assetManager.loadRemote<ImageAsset>(url, (err, imageAsset2)=>{
  209. if (!err && imageAsset2) {
  210. const texture = new Texture2D();
  211. texture.image = imageAsset2;
  212. let spFrame2 = new SpriteFrame();
  213. spFrame2.texture = texture;
  214. spr.spriteFrame = spFrame2;
  215. }
  216. });
  217. }
  218. public static loadSceneImg(url:string,call){
  219. if(url.length<=0){
  220. return null;
  221. }
  222. assetManager.loadRemote<ImageAsset>(url, (err, imageAsset2)=>{
  223. if (!err && imageAsset2) {
  224. const texture = new Texture2D();
  225. texture.image = imageAsset2;
  226. let spFrame2 = new SpriteFrame();
  227. spFrame2.texture = texture;
  228. spFrame2.addRef()
  229. call({"url":url,"sf":spFrame2})
  230. }
  231. });
  232. }
  233. public static loadSceneMp3(url:string,call){
  234. if(url.length<=0){
  235. return null;
  236. }
  237. assetManager.loadRemote(url, (err: any, clip: any)=> {
  238. clip.addRef()
  239. if (!err && clip) {
  240. call({"url":url,"clip":clip})
  241. }
  242. });
  243. }
  244. public static game_run(){
  245. resources.load("prefab/run/game_run",Prefab,(err, prefab)=>{
  246. let node:Node = instantiate(prefab);
  247. node.parent = main.g_canvas.node;
  248. node.getComponent(game_run).run()
  249. })
  250. }
  251. public static game_run_all(){
  252. resources.load("prefab/run/game_run",Prefab,(err, prefab)=>{
  253. let node:Node = instantiate(prefab);
  254. node.parent = main.g_canvas.node;
  255. node.getComponent(game_run).runAll()
  256. })
  257. }
  258. public static isWidgetType(type:number){
  259. return type!=config.Widget_Type_List.TEXT_SOUND
  260. }
  261. public static show_edit_event(type:number,data:event_item,delete_call){
  262. resources.load("prefab/edit_event",Prefab,(err, prefab)=>{
  263. let node:Node = instantiate(prefab);
  264. node.parent = main.g_canvas.node;
  265. node.getComponent(edit_event).show(type,data,delete_call)
  266. })
  267. }
  268. }