123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465 |
- import { _decorator, assetManager, Color, Component, ImageAsset, instantiate, Node, Prefab, resources, Size, Sprite, SpriteFrame, sys, Texture2D, Vec2 } from 'cc';
- import { main } from './main';
- import { toast } from './toast';
- import { add_scene } from './edit/add_scene';
- import { dialog_view } from './dialog_view';
- import { scene_select_list } from './edit/scene_select_list';
- import { sceme_type_select_item } from './sceme_type_select_item';
- import { slide_dir_select } from './edit/slide_dir_select';
- import { click_type_select } from './click_type_select';
- import { add_event } from './edit/event/add_event';
- import { add_task } from './edit/task/add_task';
- import { add_animation } from './edit/animation/add_animation';
- import { att_ani_data, event_item, widget_item_data } from '../data/data';
- import { select_widget_list } from './edit/event/select_widget_list';
- import { select_animation } from './edit/animation/select_animation';
- import { show_widget_list } from './edit/show_widget_list';
- import { select_ui_top_type } from './edit/uiWidget/select_ui_top_type';
- import { show_select_child_scene } from './edit/uiWidget/show_select_child_scene';
- import { show_select_evele_list } from './edit/show_select_evele_list';
- import { select_collect_event } from './edit/event/select_collect_event';
- import { select_res_list } from './select_res_list';
- import { select_task_zhao_xi_jie } from './edit/task/select_task_zhao_xi_jie';
- import { show_select_z_index } from './edit/attributes/show_select_z_index';
- import { game_run } from './run/game_run';
- import { config } from './config';
- import { edit_event } from './edit/event/edit_event';
- import { select_sound_list } from './edit/select_sound_list';
- import { select_task_da_guai } from './edit/task/select_task_da_guai';
- import { edit_event_view } from './edit/event/edit_event_view';
- import { tip_type_select } from './edit/tip_type_select';
- import { show_copy_scene } from './edit/show_copy_scene';
- import { show_select_more_scene_page } from './edit/show_select_more_scene_page';
- import { select_task_dai_dao_ju } from './edit/task/select_task_dai_dao_ju';
- import { set_color } from './edit/set_color';
- import { show_setup_res_anchor } from './edit/show_setup_res_anchor';
- import { dialog_input } from './dialog_input';
- import { control } from './edit/control';
- import { http } from './http';
- export class tools {
- public static show_dialog(title="是否确定?",sure_callback,cancel_callback=null){
- resources.load("prefab/dialog_view",Prefab,(err, prefab)=>{
- let node = instantiate(prefab);
- node.parent = main.g_canvas.node;
- node.getComponent(dialog_view).show(title,sure_callback,cancel_callback)
- })
- }
- public static show_dialog_input(content:string,sure_callback,cancel_callback=null){
- resources.load("prefab/dialog_input",Prefab,(err, prefab)=>{
- let node = instantiate(prefab);
- node.parent = main.g_canvas.node;
- node.getComponent(dialog_input).show(content,sure_callback,cancel_callback)
- })
- }
- public static show_loading(call=null){
- resources.load("prefab/loading",Prefab,(err, prefab)=>{
- if(!main.loading_view){
- let node = instantiate(prefab);
- node.name = "loading"
- node.parent = main.g_canvas.node;
- main.loading_view = node;
- if(call!=null){
- call()
- }
- }
- })
- }
-
- public static hide_loading(){
- if(main.loading_view!=null){
- main.loading_view.removeFromParent()
- main.loading_view =null;
- }
- }
- public static showToast(text:string){
- resources.load("prefab/toast",Prefab,(err, prefab)=>{
- let node = instantiate(prefab);
- node.name = "toast"
- node.parent = main.g_canvas.node;
- node.getComponent(toast).show(text)
- })
- }
- public static show_add_scene(call){
- resources.load("prefab/add_scene",Prefab,(err, prefab)=>{
- let node = instantiate(prefab);
- node.parent = main.g_canvas.node;
- node.getComponent(add_scene).initView(call)
- })
- }
- public static add_scene_page(call){
- resources.load("prefab/sceme_type_select_item",Prefab,(err, prefab)=>{
- let node = instantiate(prefab);
- node.parent = main.g_canvas.node;
- node.getComponent(sceme_type_select_item).initView(call)
- })
- }
- public static show_copy_scene(sceneName:string,call) {
- resources.load("prefab/show_copy_scene", Prefab, (err, prefab)=> {
- let node = instantiate(prefab);
- node.parent = main.g_canvas.node;
- node.getComponent(show_copy_scene).initView(sceneName,call)
- })
- }
- public static show_slide_dir_select(call){
- resources.load("prefab/slide_dir_select",Prefab,(err, prefab)=>{
- let node = instantiate(prefab);
- node.parent = main.g_canvas.node;
- node.getComponent(slide_dir_select).show(call)
- })
- }
- public static show_tip_type_select(call){
- resources.load("prefab/tip_type_select",Prefab,(err, prefab)=>{
- let node = instantiate(prefab);
- node.parent = main.g_canvas.node;
- node.getComponent(tip_type_select).show(call)
- })
- }
- public static show_click_type_select(call){
- resources.load("prefab/click_type_select",Prefab,(err, prefab)=>{
- let node = instantiate(prefab);
- node.parent = main.g_canvas.node;
- node.getComponent(click_type_select).show(call)
- })
- }
- public static show_add_event(call){
- resources.load("prefab/add_event",Prefab,(err, prefab)=>{
- let node = instantiate(prefab);
- node.parent = main.g_canvas.node;
- node.getComponent(add_event).show(call)
- })
- }
- public static show_add_task(call){
- resources.load("prefab/add_task",Prefab,(err, prefab)=>{
- let node = instantiate(prefab);
- node.parent = main.g_canvas.node;
- node.getComponent(add_task).show(call)
- })
- }
- public static show_add_animation(list,call){
- resources.load("prefab/add_animation",Prefab,(err, prefab)=>{
- let node = instantiate(prefab);
- node.parent = main.g_canvas.node;
- node.getComponent(add_animation).show(list,call)
- })
- }
- public static show_select_widget_list(list:widget_item_data[],call,id:number=-1){
- resources.load("prefab/select_widget_list",Prefab,(err, prefab)=>{
- let node = instantiate(prefab);
- node.parent = main.g_canvas.node;
- node.getComponent(select_widget_list).show(list,call,id)
- })
- }
- public static show_widget_list(list){
- resources.load("prefab/show_widget_list",Prefab,(err, prefab)=>{
- let node = instantiate(prefab);
- node.parent = main.g_canvas.node;
- node.getComponent(show_widget_list).show(list)
- })
- }
- public static show_select_animation_list(list:att_ani_data[],call,id:number=-1){
- resources.load("prefab/select_animation",Prefab,(err, prefab)=>{
- let node = instantiate(prefab);
- node.parent = main.g_canvas.node;
- node.getComponent(select_animation).show(list,call,id)
- })
- }
- public static show_select_animation_delete_list(list:att_ani_data[],call,id:number=-1) {
- resources.load("prefab/select_animation",Prefab,(err, prefab)=>{
- let node = instantiate(prefab);
- node.parent = main.g_canvas.node;
- node.getComponent(select_animation).showWithDelete(list,call,id)
- })
- }
- public static show_select_ui_top_type(call){
- resources.load("prefab/ui/select_ui_top_type",Prefab,(err, prefab)=>{
- let node:Node = instantiate(prefab);
- node.parent = main.g_canvas.node;
- node.getComponent(select_ui_top_type).show(call)
- })
- }
- public static show_select_child_scene(list,call){
- resources.load("prefab/ui/show_select_child_scene",Prefab,(err, prefab)=>{
- let node:Node = instantiate(prefab);
- node.parent = main.g_canvas.node;
- node.getComponent(show_select_child_scene).show(list,call)
- })
- }
- public static show_select_evele_list(list,call){
- if(list.length == 0) {
- return tools.showToast('任务事件列表是空的')
- }
- resources.load("prefab/show_select_evele_list",Prefab,(err, prefab)=>{
- let node:Node = instantiate(prefab);
- node.parent = main.g_canvas.node;
- node.getComponent(show_select_evele_list).show(list,call)
- })
- }
- public static show_setup_res_anchor(img_sf:SpriteFrame,img_size:Size,img_anchor:Vec2,callback:Function) {
- resources.load("prefab/show_setup_res_anchor",Prefab,(err, prefab)=>{
- let node:Node = instantiate(prefab);
- node.parent = main.g_canvas.node;
- node.getComponent(show_setup_res_anchor).show(img_sf,img_size,img_anchor,callback)
- })
- }
- public static select_collect_event(list,call,event_id,event_list_id){
- resources.load("prefab/ui/select_collect_event",Prefab,(err, prefab)=>{
- let node:Node = instantiate(prefab);
- node.parent = main.g_canvas.node;
- node.getComponent(select_collect_event).show(list,call,event_id,event_list_id)
- })
- }
- public static select_res_list(call){
- resources.load("prefab/ui/select_res_list",Prefab,(err, prefab)=>{
- let node:Node = instantiate(prefab);
- node.parent = main.g_canvas.node;
- node.getComponent(select_res_list).initView(call)
- })
- }
- public static select_sound_list(call){
- resources.load("prefab/ui/select_sound_list",Prefab,(err, prefab)=>{
- let node:Node = instantiate(prefab);
- node.parent = main.g_canvas.node;
- node.getComponent(select_sound_list).initView(call)
- })
- }
- public static select_task_zhao_xi_jie(data){
- resources.load("prefab/task/select_task_zhao_xi_jie",Prefab,(err, prefab)=>{
- let node:Node = instantiate(prefab);
- node.parent = main.g_canvas.node;
- node.getComponent(select_task_zhao_xi_jie).show(data)
- })
- }
- public static select_task_da_guai(data){
- resources.load("prefab/task/select_task_da_guai",Prefab,(err, prefab)=>{
- let node:Node = instantiate(prefab);
- node.parent = main.g_canvas.node;
- node.getComponent(select_task_da_guai).show(data)
- })
- }
- public static select_task_dai_dao_ju(data){
- resources.load("prefab/task/select_task_dai_dao_ju",Prefab,(err, prefab)=>{
- let node:Node = instantiate(prefab);
- node.parent = main.g_canvas.node;
- node.getComponent(select_task_dai_dao_ju).show(data)
- })
- }
- public static show_select_z_index(call){
- resources.load("prefab/show_select_z_index",Prefab,(err, prefab)=>{
- let node:Node = instantiate(prefab);
- node.parent = main.g_canvas.node;
- node.getComponent(show_select_z_index).show(call)
- })
- }
- public static show_edit_event_view(){
- resources.load("prefab/ui/edit_event_view",Prefab,(err, prefab)=>{
- let node:Node = instantiate(prefab);
- node.parent = main.g_canvas.node;
- node.getComponent(edit_event_view).show()
- })
- }
- public static show_select_dir(call){
- resources.load("prefab/show_select_z_index",Prefab,(err, prefab)=>{
- let node:Node = instantiate(prefab);
- node.parent = main.g_canvas.node;
- node.getComponent(show_select_z_index).showDir(call)
- })
- }
- public static show_select_more_scene_page(data,cur_index,call) {
- resources.load("prefab/show_select_more_scene_page",Prefab,(err, prefab)=>{
- let node:Node = instantiate(prefab);
- node.parent = main.g_canvas.node;
- node.getComponent(show_select_more_scene_page).show(data,cur_index,call)
- })
- }
- public static loadUrl(url:string,spr:Sprite,call=null){
- if(url.length<=0){
- return null;
- }
- assetManager.loadRemote<ImageAsset>(url, (err, imageAsset2)=>{
- if (!err && imageAsset2) {
- const texture = new Texture2D();
- texture.image = imageAsset2;
- let spFrame2 = new SpriteFrame();
- spFrame2.texture = texture;
- if(spr!=null) {
- spr.spriteFrame = spFrame2;
- }
- call && call(spFrame2)
- } else {
- call && call(null)
- }
- });
- }
- public static loadSceneImg(url:string,call){
- if(url.length<=0){
- return null;
- }
- assetManager.loadRemote<ImageAsset>(url, (err, imageAsset2)=>{
- if (!err && imageAsset2) {
- const texture = new Texture2D();
- texture.image = imageAsset2;
- let spFrame2 = new SpriteFrame();
- spFrame2.texture = texture;
- spFrame2.addRef()
- call({"url":url,"sf":spFrame2})
- }
- });
- }
- public static loadSceneMp3(url:string,call){
- if(url.length<=0){
- return null;
- }
- assetManager.loadRemote(url, (err: any, clip: any)=> {
- clip.addRef()
- if (!err && clip) {
- call({"url":url,"clip":clip})
- }
- });
- }
- public static game_run(callback=null){
- resources.load("prefab/run/game_run",Prefab,(err, prefab)=>{
- let node:Node = instantiate(prefab);
- node.parent = main.g_canvas.node;
- node.getComponent(game_run).run(callback)
- })
- }
- public static game_run_all(){
- resources.load("prefab/run/game_run",Prefab,(err, prefab)=>{
- let node:Node = instantiate(prefab);
- node.parent = main.g_canvas.node;
- node.getComponent(game_run).runAll()
- })
- }
- public static isWidgetType(type:number){
- return type!=config.Widget_Type_List.TEXT_SOUND
- }
- public static show_edit_event(type:number,data:event_item,delete_call){
- resources.load("prefab/edit_event",Prefab,(err, prefab)=>{
- let node:Node = instantiate(prefab);
- node.parent = main.g_canvas.node;
- node.getComponent(edit_event).show(type,data,delete_call)
- })
- }
- // 去除左边和右边空格
- public static trimLeftAndRightblank(str: string):string {
- const reg = /^\s+|\s+$/g;
- return str.replace(reg, '')
- }
- public static show_set_color(color:Color,call){
- resources.load("prefab/set_color",Prefab,(err, prefab)=>{
- let node:Node = instantiate(prefab);
- node.parent = main.g_canvas.node;
- node.getComponent(set_color).show(color,call)
- })
- }
- //请求保存编辑场景
- public static requestSaveEditScene() {
- tools.show_loading(()=>{
- // let data = new FormData()
- let content = control.Singleton.get_bag_data().content
- let zujian_id = config.last_id;
- let id = control.Singleton.get_bag_data().id;
- // data.append("content",JSON.stringify(content))
- // data.append("zujian_id",zujian_id+"")
- // data.append("id",id+"")
- console.log("btn_save",content)
- let request_data = {"content":JSON.stringify(content),"zujian_id":zujian_id,"id":id}
- http.post("/tool/mysnote/save", request_data, (err,data)=>{
- if(!err){
- tools.showToast("保存成功!")
- }
- tools.hide_loading()
- })
- })
- }
- //请求获取服务器动画列表
- public static requestGetAnimationList(call) {
- http.get('/tool/mysnote/get_animation',(err,data)=>{
- // console.log('err=',err,'data=',data)
- if(!err) {
- let _data = JSON.parse(data);
- if(_data.code==config.MSG_CODE.SUCCESS) {
- let content_list = JSON.parse(_data.content.content)
- let list:att_ani_data[] = []
- for (let index = 0; index < content_list.length; index++) {
- const element = content_list[index];
- list.push(element)
- }
- call(list)
- } else {
- tools.showToast('获取动画列表失败')
- }
- }
- })
- }
- //添加动画到动画列表
- public static requestAddAnimationToAnimationList(ani_data:att_ani_data) {
- let string = ani_data.ani_name
- tools.show_dialog_input(string, (content)=>{
- tools.requestGetAnimationList((ani_list)=>{
- let copy_ani_data = JSON.parse(JSON.stringify(ani_data)) //深拷贝
- copy_ani_data.ani_name = content
- ani_list.push(copy_ani_data)
- tools.requestSyncAnimationList(ani_list)
- })
- })
- }
- //同步服务器动画列表
- public static requestSyncAnimationList(list:att_ani_data[]) {
- let request_data = {"content": JSON.stringify(list)}
- // console.log('request_data=',request_data)
- http.post('/tool/mysnote/snyc_animation',request_data, (err,data)=>{
- // console.log('同步 err=',err,'data',data)
- if(!err){
- tools.showToast("动画列表同步成功!")
- }
- })
- }
- }
|