123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- import { _decorator, Component, instantiate, Node, Prefab } from 'cc';
- import { main } from '../main';
- import { scene_item_data, task_data } from '../../data/data';
- import { scene_select_list_item } from './scene_select_list_item';
- import { ClientEvent } from '../clientEvent';
- import { config } from '../config';
- import { tools } from '../tools';
- import { Attributes } from './Attributes';
- import { show_copy_scene } from './show_copy_scene';
- const { ccclass, property } = _decorator;
- @ccclass('scene_select_list')
- export class scene_select_list extends Component {
- @property(Prefab) scene_select_list_item_prefab:Prefab = null;
- @property(Node) content:Node = null;
- private cur_select_index = 0;
- private m_main:main = null;
- public initView(_main:main){
- this.m_main = _main;
- this.content.removeAllChildren()
- this.onUpdateSceneList()
- ClientEvent.off(config.Event.UpdateSceneList,this.onUpdateSceneList,this)
- ClientEvent.on(config.Event.UpdateSceneList,this.onUpdateSceneList,this)
- }
- onUpdateSceneList(is_move:boolean = false){
- let list = this.m_main.control_view.get_bag_data().content;
- if(is_move==false) {
- this.cur_select_index = list.length>0?list.length-1:0;
- }
- this.content.removeAllChildren()
- for (let index = 0; index < list.length; index++) {
- const element:scene_item_data = list[index];
- let item = instantiate(this.scene_select_list_item_prefab)
- item.parent = this.content;
- let scene_select_list_item_component = item.getComponent(scene_select_list_item)
- scene_select_list_item_component.initView(list.length,element,this.onItemSelect.bind(this),index)
- scene_select_list_item_component.moveCallback(this.onItemMoveClick.bind(this))
- scene_select_list_item_component.copyCallback(this.onItemCopyClick.bind(this))
-
- }
- this.updaetSelectStatus()
- }
- onItemSelect(item:scene_select_list_item){
- if(item.getSelect()){
- }else{
- this.cur_select_index = item.getIndex()
- this.updaetSelectStatus()
- }
- }
- onItemMoveClick(item:scene_select_list_item, is_up:boolean) {
- let list = this.m_main.control_view.get_bag_data().content;
- let c_index = item.getIndex()
- let c_data = list[c_index]
- let move_index=-1;
- if(is_up) {
- move_index = c_index - 1
- if(item.getSelect()) {
- this.cur_select_index -=1
- } else {
- this.cur_select_index +=1
- }
- } else {
- move_index = c_index + 1
- if(item.getSelect()) {
- this.cur_select_index +=1
- } else {
- this.cur_select_index -=1
- }
- }
- if(move_index == -1) {return}
- let move_data = list[move_index]
- list[c_index] = move_data
- list[move_index] = c_data
- this.onUpdateSceneList(true)
- }
- onItemCopyClick(item:scene_select_list_item) {
- let c_index = item.getIndex()
- let list = this.m_main.control_view.get_bag_data().content;
- let c_data = list[c_index]
- // console.log('c_data=',c_data)
- tools.show_copy_scene(c_data.scene_diy_name, (scene_name:string, view:show_copy_scene)=> {
- let copy_data = JSON.parse(JSON.stringify(c_data)) //深拷贝
- copy_data.scene_diy_name = scene_name
- for(let i=0; i<copy_data.page_list.length; i++) {
- let i_page_item = copy_data.page_list[i]
- i_page_item.att.id = config.getNewId()
- for(let j=0; j<i_page_item.page_list.length; j++) {
- let j_page_item = i_page_item.page_list[j]
- j_page_item.att.id = i_page_item.att.id
- }
- for(let j=0; j<i_page_item.page_widget_list.length; j++) {
- let j_page_widget_item = i_page_item.page_widget_list[j]
- j_page_widget_item.att.id = config.getNewId()
- }
- }
- if(view.getIsCopyOnlyWidget()) {
- copy_data._task_data = null
- }
- // console.log('copy_data=',copy_data)
- this.m_main.control_view.push_scene_data(copy_data)
- this.onUpdateSceneList()
- view.close()
- })
- }
- updaetSelectStatus(){
- for (let index = 0; index < this.content.children.length; index++) {
- const element = this.content.children[index];
- element.getComponent(scene_select_list_item).setIsSelect(element.getComponent(scene_select_list_item).getIndex()==this.cur_select_index)
- element.getComponent(scene_select_list_item).updatSelectStatus()
- }
- ClientEvent.dispatchEvent(config.Event.UpdateEditScene)
- }
- public getCurSelectScene(){
- if(this.content.children.length<=0){
- return null;
- }
- return this.content.children[this.cur_select_index].getComponent(scene_select_list_item).getData()
- }
- public getCurSelectSceneIndex(){
- return this.cur_select_index;
- }
- }
|