tools.ts 14 KB

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