tools.ts 12 KB

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