75 lines
1.6 KiB
TypeScript
Raw Permalink Normal View History

2022-08-26 16:48:17 +08:00
import { CoroutineV2 } from "../../CatanEngine/CoroutineV2/CoroutineV2";
import UIPanel from "../../Component/UIPanel/UIPanel";
import ScrollItem from "./ScrollItem";
import UISuperLayout from "./UISuperLayout";
const { ccclass, property } = cc._decorator;
/** Scroll基底 */
@ccclass
export default class ScrollBase extends UIPanel {
//#region 外調參數
@property({ displayName: "List", type: UISuperLayout })
public List: UISuperLayout = null;
//#endregion
//#region public
/** ListData */
public get ListData(): any[] { throw new Error("ListData必須被override"); }
//#endregion
//#region protected
/** 列表資料 */
protected _listData: any[] = [];
//#endregion
//#region ScrollView Function
/**
* /
* @param isScrollTo 0
* @param isScrollTo 1
* @param isScrollTo 2
* @param isScrollTo 3 Item
*/
public *CreateList(isScrollTo: number = 0): IterableIterator<any> {
if (!this.node.active) {
return;
}
this.List?.CreateItem(this.ListData.length);
yield CoroutineV2.WaitTime(5 / cc.game.getFrameRate());
switch (isScrollTo) {
case 1: {
this.List?.scrollToHeader(0);
break;
}
case 2: {
this.List?.scrollToFooter(0);
break;
}
case 3: {
this.List?.scrollToCenter();
break;
}
default:
break;
}
}
public OnRefreshEvent(node: cc.Node, index: number): void {
let listData: any[] = this.ListData;
let info: any = listData[index];
node.getComponent(ScrollItem).ImplementSet(info, this, index);
}
//#endregion
}