tools.ts 15 KB

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