12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- import { _decorator, Component, instantiate, Node, Prefab } from 'cc';
- import { main } from '../main';
- import { scene_item_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';
- 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))
-
- }
- 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
- // this.cur_select_index -=1
- // } else {
- // move_index = c_index + 1
- // 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)
- }
- 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;
- }
- }
|