You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
90 lines
2.8 KiB
90 lines
2.8 KiB
import { _decorator, Component, ScrollView, instantiate, Node, UITransform } from "cc";
|
|
|
|
|
|
|
|
const { ccclass, property } = _decorator;
|
|
|
|
@ccclass
|
|
export default class DropDownController extends Component{
|
|
|
|
@property(Node)
|
|
m_SelectItem:Node =null;
|
|
@property(ScrollView)
|
|
m_OpenList:ScrollView=null;
|
|
@property(Node)
|
|
m_RendererItem:Node=null;
|
|
m_ItemRendererFuntion:Function;
|
|
m_ItemClick:Function;
|
|
m_SelectItemFuntion:Function;
|
|
_ItemCount:number=0;
|
|
|
|
isautoSetwith:boolean=false;
|
|
isSelectItemclick:boolean=false;
|
|
|
|
m_Starindex:number=0;
|
|
|
|
private ChildItemList:Node[]=[];
|
|
|
|
get m_ItemCount():number{
|
|
return this._ItemCount;
|
|
}
|
|
set m_ItemCount(value:number){
|
|
this._ItemCount = value;
|
|
this.SetOpenListItem();
|
|
}
|
|
protected onLoad(): void {
|
|
if(this.isSelectItemclick){
|
|
CNodeUtils.addBtnComponent(this.m_SelectItem,this.OpenDropList,this);
|
|
}else{
|
|
CNodeUtils.addBtnComponent(this.node,this.OpenDropList,this);
|
|
}
|
|
this.SetSelectItem(0);
|
|
this.m_OpenList.node.active = false;
|
|
if (this.isautoSetwith)
|
|
{
|
|
this.node.getChildByName("bg").active = this.m_OpenList.node.active;
|
|
}
|
|
}
|
|
SetSelectItem(Index:number){
|
|
this.m_SelectItemFuntion && this.m_SelectItemFuntion(Index,this.m_SelectItem);
|
|
}
|
|
OpenDropList(){
|
|
this.m_OpenList.node.active = !this.m_OpenList.node.active;
|
|
|
|
if (this.isautoSetwith)
|
|
{
|
|
this.node.getChildByName("bg").active = this.m_OpenList.node.active;
|
|
}
|
|
|
|
if(this.m_OpenList.node.active){
|
|
this.SetOpenListItem();
|
|
}
|
|
}
|
|
|
|
SetOpenListItem(){
|
|
for(let i=0; i< this._ItemCount; i++){
|
|
if(i >= this.ChildItemList.length){
|
|
let Item =instantiate(this.m_RendererItem);
|
|
this.ChildItemList.push(Item);
|
|
this.m_OpenList.content.addChild(Item);
|
|
this.m_ItemClick && CNodeUtils.addBtnComponent(Item,this.m_ItemClick.bind(this,i,Item))
|
|
}
|
|
this.ChildItemList[i].active = true;
|
|
this.m_ItemRendererFuntion && this.m_ItemRendererFuntion(i,this.ChildItemList[i]);
|
|
}
|
|
|
|
let TempStarIndex = this._ItemCount;
|
|
for(;TempStarIndex < this.ChildItemList.length; TempStarIndex++ ){
|
|
if(this.ChildItemList[TempStarIndex].active){
|
|
this.ChildItemList[TempStarIndex].active=false;
|
|
}else{
|
|
break;
|
|
}
|
|
}
|
|
if(this.isautoSetwith){
|
|
this.m_OpenList.node.getComponent(UITransform).width = this.m_OpenList.content.getComponent(UITransform).width+7;
|
|
this.node.getChildByName("bg").getComponent(UITransform).width = this.m_OpenList.content.getComponent(UITransform).width+94;
|
|
}
|
|
}
|
|
|
|
}
|