工具类:封装List

语言:LayaBox - AS3
代码

package UIEngine.UICell
{
    import laya.events.Event;
    import laya.ui.List;
    import laya.utils.Handler;

    //用于List,UICell组控制
    public class UICellGroup
    {
        //分散的组
        // public var m_length:int = 0;         //数量       
        public var m_cells:Array = [];          //cell
        public var m_celldatas:Array = [];          //celldata      
        public var m_selectIndex:int = -1;          //当前选中索引        
        //list
        // public static var m_list:List = null;        //名称
        //menu
        public var m_preIndex:int = 0;          //上次选中              
        public var m_menu:List;     //菜单
        public var m_menuData:Array;        //当前数据        
        public var m_parentData:Array;      //一级菜单
        public var m_childData:Array;       //二级菜单
        public var m_bExtand:Boolean = false;       //是否展开        

        public function UICellGroup()
        {

        }
        public function clearData():void
        {           
            // m_cells = [];
            m_celldatas = [];
            m_selectIndex = -1;
        }       
        public function addCell(cell:UICell):void
        {           
            m_cells.push(cell);
        }
        public function getCell(index:int):UICell
        {           
            return  m_cells[index];
        }        
        public function addCellData(celldata:UICellData):void
        {           
            m_celldatas.push(celldata);
        }   
        public function getCellData(index:int):UICellData
        {           
            return  m_celldatas[index];
        } 

        public function Select(index:int):void
        {           
            
        }
        public function onSelect(index:int):void
        {           
            if(m_selectIndex == index){
                return;
            }
            var preIndex:int = m_selectIndex;
            var precell:UICell = m_cells[preIndex];
            var preData:* = m_celldatas[preIndex];
            if(precell && preData){
                preData.select = false;
                precell.dataSource = preData;
            }

            var cell:UICell = m_cells[index];           
            var selectData:* = m_celldatas[index];
            if(cell && selectData){
                selectData.select = true;
                cell.dataSource = selectData;   

                m_selectIndex = index;              
            }       
        }       
        public function refresh():void
        {           
            for(var i:int=0;i0){      
                m_preIndex = firstChildIndex;       
                AutoSelectMenu(firstChildIndex,true);
                //父节点置顶
                m_menu.scrollTo(firstChildIndex-1);
            }


        }            
        public function AutoSelectMenu(index:int,notRefreshMenu:Boolean=false):void
        {     
            var event:Event =  new Event();
            event.type = "click";
            m_menu.mouseHandler.runWith([event,index,notRefreshMenu]);            
        }               

        
        ////////////////////////////////////////
        public function getMenuDataIndex(data:*):int
        {
            for(var i:int=0;i

使用示例

UICellGroup.initList(m_list,TacticalCell,true,null,Handler.create(this, onListSelect,null,false));
m_list.dataSource=m_arrSkillCellData;  
UICellGroup.AutoSelectList(m_list,_selectListIndex);
private function onListSelect(e:Event,index:int):void{
       if(e.type==Event.CLICK){               
        //修改列表项选中状态(cell中可以通过select变量判断是否被选中)    
          UICellGroup.onListSelect(m_list,m_arrSkillCellData,index);
       }
}

配套cellData,列表项继承该类

package UIEngine.UICell
{
    //通用CellData结构,可满足大部分UICell应用
    //如果参数不足,可以继续添加arg1,arg2;
    public class UICellData
    {
        public var index:int = 0;           //索引
        public var key:Number = 0;          //uid       
        public var name:String = "";        //名称
        public var icon:int = 0;            //图标            
        public var type:int = 0;            //类型                
        public var style:int = 0;       //样式
        //选中功能
        public var select:Boolean = false;  //是否选中
        public var selectType:int = 0;  //选中类型,1normal和pushed图片切换,2附加选中图片,3附加选中特效
        public var normalRes:String = "";  //选中图片url,注意不是normalImage和pushedImage
        public var selectRes:String = "";  //选中图片url,注意不是normalImage和pushedImage        
        public var offsetX:int = 0;         //选中图片偏移,默认居中       
        public var offsetY:int = 0;         //选中图片偏移,默认居中       
        public var zOrder:int = 0;          //选中图片偏移cengji  
        //          
        public var arg:* = null;            //自定义参数     
        public var arg1:* = null;           //自定义参数     
        // public var flag:int=0; //标志 0:无    1:可合成
        public var redType:int=0;//追踪红点类型   
        public var redID:int=0;//红点ID 
        public var redGroupid:int=-1;       
        public var redKey:int=-1;   
        
        public function UICellData(index:int=0)
        {
            this.index = index;
        }
        public function clear():void
        {
            index = 0;
            key = 0;
            name = "";      
            type = 0;   
            style = 0;
            select = false;
            arg = null;
        }       
        //redType:0点 1上级 2组
        public function setRedType(type:int,id:int,groupid:int=1,key:int=-1):void
        {       
            this.redType = type;
            this.redID = id;
            this.redGroupid = groupid;
            this.redKey = key;          
        }   
        public function setSelectType(type:int,selectRes:String = "",offsetX:Number=0,offsetY:Number=0,zOrder:int=0):void
        {           
            this.selectType = type;
            // this.normalRes = normalRes;
            this.selectRes = selectRes;
            this.offsetX = offsetX;
            this.offsetY = offsetY;
            this.zOrder = zOrder;
        }       
    }
}

你可能感兴趣的:(工具类:封装List)