tools.ts 13 KB

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