123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342 |
- import { _decorator, assetManager, AudioClip, Button, Color, Component, ImageAsset, Node, Prefab, Sprite, SpriteFrame, Texture2D } from 'cc';
- import { config } from '../config';
- import { bag_data, scene_item_data } from '../../data/data';
- import { res_list } from './res_list';
- import { edit_scene } from './edit_scene';
- import { main } from '../main';
- import { gameManager } from '../run/gameManager';
- import { widget_list } from './widget_list';
- const { ccclass, property } = _decorator;
- @ccclass('control')
- export class control extends Component {
- @property(Node) btn_res:Node = null;
- @property(Node) btn_control:Node = null;
- @property(Node) btn_select_scene:Node = null;
- @property(Node) btn_task:Node = null;
- private res_and_control_select_index:number = 0;
- private res_and_control_btn_list:Node[] = null;
- @property(Node) btn_item_list:Node = null;
- @property(Node) btn_bg_list:Node = null;
- @property(Node) btn_component_list:Node = null;
- @property(Node) btn_sound_list:Node = null;
- private res_select_index:number = 0;
- private res_btn_list:Node[] = null;
- @property(Node) item_list:Node = null;
- @property(Node) bg_list:Node = null;
- @property(Node) component_list:Node = null;
- @property(Node) sound_list:Node = null;
- private res_view_list:Node[] = null;
- public static Singleton:control = null;
- private m_bag_data:bag_data = null;
- public static res_map:Map<string,SpriteFrame> = new Map()
- public static mp3_cache:Map<string,AudioClip> = new Map()
- @property(Prefab) prefab_img_item:Prefab = null;
- @property(Prefab) prefab_sound_item:Prefab = null;
- private res_data_list:any[] = []
- @property(Node) res_list:Node = null;
- @property(Node) widget_list:Node = null;
-
- @property(Node) task_list:Node = null;
- @property(Node) scene_list:Node = null;
- private m_main:main = null;
- protected start(): void {
- control.Singleton = this;
- }
- public get_bag_data():bag_data{
- return this.m_bag_data;
- }
- public push_scene_data(data:scene_item_data){
- this.m_bag_data.content.push(data)
- }
- public remove_scene_data(data:scene_item_data){
- let i = this.m_bag_data.content.indexOf(data)
- if(i!=-1){
- let temp = []
- for (let index = 0; index < this.m_bag_data.content.length; index++) {
- const element = this.m_bag_data.content[index];
- if(i===index){
- }else{
- temp.push(element)
- }
- }
- this.m_bag_data.content = temp;
- }
-
- }
- public init(_main:main){
- this.m_main = _main
- if(this.res_and_control_btn_list==null){
- this.res_and_control_btn_list = []
- this.btn_res.name = `${config.select_res_and_control_type.RES_TYPE}`
- this.res_and_control_btn_list.push(this.btn_res)
- this.btn_control.name = `${config.select_res_and_control_type.CONTROL_TYPE}`
- this.res_and_control_btn_list.push(this.btn_control)
- this.btn_select_scene.name = `${config.select_res_and_control_type.SCENE_SELECT}`
- this.res_and_control_btn_list.push(this.btn_select_scene)
- this.btn_task.name = `${config.select_res_and_control_type.TASK}`
- this.res_and_control_btn_list.push(this.btn_task)
- }
- this.res_and_control_select_index = config.select_res_and_control_type.RES_TYPE;
- if(this.res_btn_list==null){
- this.res_btn_list = [];
- this.btn_item_list.name = `${config.select_res_btn_type.ITEM_LIST}`
- this.res_btn_list.push(this.btn_item_list)
- this.btn_component_list.name = `${config.select_res_btn_type.COMPONENT_LIST}`
- this.res_btn_list.push(this.btn_component_list)
- this.btn_bg_list.name = `${config.select_res_btn_type.BG_LIST}`
- this.res_btn_list.push(this.btn_bg_list)
-
- this.btn_sound_list.name = `${config.select_res_btn_type.SOUND_LIST}`
- this.res_btn_list.push(this.btn_sound_list)
- this.res_view_list = []
- this.res_view_list.push(this.item_list)
- this.res_view_list.push(this.component_list)
- this.res_view_list.push(this.bg_list)
- this.res_view_list.push(this.sound_list)
- }
- this.res_select_index = config.select_res_btn_type.ITEM_LIST;
- this.initBtnEvent()
- this.initViews();
- }
- initViews(){
- for (let index = 0; index < this.res_view_list.length; index++) {
- const element = this.res_view_list[index];
- if(index===config.select_res_btn_type.SOUND_LIST){
- element.getComponent(res_list).initView(this.prefab_sound_item,index,this.res_data_list[index])
- }else{
- element.getComponent(res_list).initView(this.prefab_img_item,index,this.res_data_list[index])
- }
- element.active = this.res_select_index==index;
- }
- }
- public getResDataByType(type:number){
- for (let index = 0; index < this.res_view_list.length; index++) {
- const element = this.res_view_list[index];
- if(element.getComponent(res_list).getType()==type){
- return element.getComponent(res_list).getData()
- }
- }
- return null;
- }
- public getWidgetData(type:number){
- return this.widget_list.getComponent(widget_list).getWidgetDataByType(type)
- }
- public getWidgetByType(type:number){
- return this.widget_list.getComponent(widget_list).getWidgetByType(type)
- }
-
- update_res_select_views(){
- for (let index = 0; index < this.res_view_list.length; index++) {
- const element = this.res_view_list[index];
- element.active = this.res_select_index==index;
- }
- }
- public loading_all_resources(data,call_back){
- this.m_bag_data = bag_data.initBagData(data.content);
- if(this.m_bag_data.content==undefined||this.m_bag_data.content==null||this.m_bag_data.content.length<=0){
- this.m_bag_data.content = []
- }
- this.res_data_list = []
- let total = this.m_bag_data.item_list.length+this.m_bag_data.component_list.length+this.m_bag_data.bg_list.length+this.m_bag_data.sound_list.length;
- this.res_data_list.push(this.m_bag_data.item_list)
- this.res_data_list.push(this.m_bag_data.component_list)
- this.res_data_list.push(this.m_bag_data.bg_list)
- this.res_data_list.push(this.m_bag_data.sound_list)
- if(total==0) {
- call_back()
- return
- }
- let count = 0;
- let call = ()=>{
- count++;
- if(count>=total){
- call_back()
- }
- }
- for (let index = 0; index < this.m_bag_data.item_list.length; index++) {
- let url = this.m_bag_data.item_list[index].url;
- let name = this.m_bag_data.item_list[index].name;
- 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()
- control.res_map.set(name,spFrame2)
- gameManager.res_map.set(url,spFrame2)
- call()
- }
- });
- }
- for (let index = 0; index < this.m_bag_data.bg_list.length; index++) {
- let url = this.m_bag_data.bg_list[index].url;
- let name = this.m_bag_data.bg_list[index].name;
- 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()
- control.res_map.set(name,spFrame2)
- gameManager.res_map.set(url,spFrame2)
- call()
- }
- });
- }
- for (let index = 0; index < this.m_bag_data.component_list.length; index++) {
- let url = this.m_bag_data.component_list[index].url;
- let name = this.m_bag_data.component_list[index].name;
- 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()
- control.res_map.set(name,spFrame2)
- gameManager.res_map.set(url,spFrame2)
- call()
- }
- });
- }
- for (let index = 0; index < this.m_bag_data.sound_list.length; index++) {
- let url = this.m_bag_data.sound_list[index].url;
- let name = this.m_bag_data.sound_list[index].name;
- assetManager.loadRemote(url, (err: any, clip: any)=> {
- clip.addRef()
- if (!err && clip) {
- control.mp3_cache.set(name,clip)
- gameManager.mp3_cache.set(url,clip)
- call()
- }
- });
- }
- }
- initBtnEvent(){
- for (let index = 0; index < this.res_and_control_btn_list.length; index++) {
- const element = this.res_and_control_btn_list[index];
- this.res_view_list[index].active = false;
- element.off(Node.EventType.TOUCH_END)
- element.on(Node.EventType.TOUCH_END,()=>{
- this.select_res_btn_type_on_click(parseInt(element.name))
- },element)
- }
- this.select_res_btn_type_on_click(this.res_and_control_select_index)
- for (let index = 0; index < this.res_btn_list.length; index++) {
- const element = this.res_btn_list[index];
- element.off(Node.EventType.TOUCH_END)
- element.on(Node.EventType.TOUCH_END,()=>{
- this.select_res_and_control_type_on_click(parseInt(element.name))
- },element)
- }
- this.select_res_and_control_type_on_click(this.res_select_index)
- }
- hide_all(){
- this.task_list.active = false;
- this.widget_list.active = false;
- this.res_list.active = false;
- this.scene_list.active = false;
- this.btn_res.getComponent(Sprite).color = Color.GRAY;
- this.btn_control.getComponent(Sprite).color = Color.GRAY;
- this.btn_select_scene.getComponent(Sprite).color = Color.GRAY;
- this.btn_task.getComponent(Sprite).color = Color.GRAY;
- }
- show_res(){
- this.hide_all();
- this.res_list.active = true;
- this.btn_res.getComponent(Sprite).color = Color.YELLOW;
- }
- show_widget(){
- this.hide_all();
- this.widget_list.active = true;
- this.btn_control.getComponent(Sprite).color = Color.YELLOW;
- }
- show_select_scene(){
- this.hide_all();
- this.scene_list.active = true;
- this.btn_select_scene.getComponent(Sprite).color = Color.YELLOW;
- }
- show_task(){
- this.hide_all();
- this.task_list.active = true;
- this.btn_task.getComponent(Sprite).color = Color.YELLOW;
- }
- select_res_btn_type_on_click(index){
- switch (index) {
- case config.select_res_and_control_type.RES_TYPE:
- this.show_res()
- break;
- case config.select_res_and_control_type.CONTROL_TYPE:
- this.show_widget()
- break;
- case config.select_res_and_control_type.SCENE_SELECT:
- this.show_select_scene()
- break;
- case config.select_res_and_control_type.TASK:
- this.show_task()
- break;
-
- }
- this.res_and_control_select_index = index
- }
- select_res_and_control_type_on_click(index){
- let select_node = this.res_btn_list[index]
- for (let i = 0; i < this.res_btn_list.length; i++) {
- const element = this.res_btn_list[i];
- if(i==index){
- }else{
- element.getComponent(Sprite).color = Color.GRAY;
- }
- }
- select_node.getComponent(Sprite).color = Color.YELLOW;
- this.res_select_index = index
- this.update_res_select_views()
- }
- }
|