|
@@ -1,15 +1,26 @@
|
|
|
-import { _decorator, Component, Node ,Button,director} from 'cc';
|
|
|
+import { _decorator, Component, Node ,Button,director, PageView} from 'cc';
|
|
|
const { ccclass, property } = _decorator;
|
|
|
|
|
|
@ccclass('SelectScene')
|
|
|
export class SelectScene extends Component {
|
|
|
+ @property(Node)
|
|
|
+ pageView:Node = null;
|
|
|
+
|
|
|
+ currentPageIndex:number = null;
|
|
|
start() {
|
|
|
+ this.currentPageIndex = this.pageView.getComponent(PageView).getCurrentPageIndex();
|
|
|
+ console.log(this.currentPageIndex);
|
|
|
let BtnHome = this.node.getChildByPath("UIButton/BtnHome");
|
|
|
BtnHome.on(Button.EventType.CLICK,this.onBtnHome,this);
|
|
|
|
|
|
let BtnHelp = this.node.getChildByPath("UIButton/BtnHelp");
|
|
|
BtnHelp.on(Button.EventType.CLICK,this.onBtnHelp,this);
|
|
|
- TouchEvent
|
|
|
+
|
|
|
+ let BtnLeft = this.node.getChildByPath("UIButton/BtnLeft");
|
|
|
+ BtnLeft.on(Button.EventType.CLICK,this.onBtnLeft,this);
|
|
|
+
|
|
|
+ let BtnRight = this.node.getChildByPath("UIButton/BtnRight");
|
|
|
+ BtnRight.on(Button.EventType.CLICK,this.onBtnRight,this);
|
|
|
}
|
|
|
|
|
|
onBtnHome(){
|
|
@@ -23,14 +34,37 @@ export class SelectScene extends Component {
|
|
|
}
|
|
|
|
|
|
onBtnLeft(){
|
|
|
-
|
|
|
+ // if(this.currentPageIndex < 0){
|
|
|
+ // this.currentPageIndex = 0;
|
|
|
+ // }
|
|
|
+ // else{
|
|
|
+ // this.currentPageIndex = this.currentPageIndex - 1;
|
|
|
+ // }
|
|
|
+ this.currentPageIndex = Math.max(0, this.currentPageIndex - 1);
|
|
|
+ this.pageView.getComponent(PageView).scrollToPage(this.currentPageIndex);
|
|
|
+ this.pageView.getComponent(PageView).scrollToPage(this.currentPageIndex);
|
|
|
}
|
|
|
|
|
|
onBtnRight(){
|
|
|
+ // if(this.currentPageIndex == this.pageView.getComponent(PageView).getPages().length + 1){
|
|
|
+ // this.currentPageIndex = this.pageView.getComponent(PageView).getPages().length;
|
|
|
+ // }else{
|
|
|
+ // this.currentPageIndex = this.currentPageIndex + 1;
|
|
|
+ // }
|
|
|
+ //总页数totalPages 最大索引totalPages - 1
|
|
|
+ const totalPages = this.pageView.getComponent(PageView).getPages().length;
|
|
|
+
|
|
|
+ // 确保 currentPageIndex 不会超过 totalPages - 1
|
|
|
+ if (this.currentPageIndex === totalPages - 1) {
|
|
|
+ this.currentPageIndex = totalPages - 1; // 保持在最后一页
|
|
|
+ } else {
|
|
|
+ this.currentPageIndex = Math.min(this.currentPageIndex + 1, totalPages -1);
|
|
|
+ }
|
|
|
+ this.pageView.getComponent(PageView).scrollToPage(this.currentPageIndex);
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
update(deltaTime: number) {
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
|