Commit adb58335 authored by 范雪寒's avatar 范雪寒

feat: 边界check

parent 1050217c
...@@ -86,7 +86,7 @@ cc.Class({ ...@@ -86,7 +86,7 @@ cc.Class({
async getBundleInfoList() { async getBundleInfoList() {
await this.asyncDelayLog('汪汪汪31'); await this.asyncDelayLog('汪汪汪31');
const jsonStr = this.callNativeFunction({ name: 'loadSceneList', value: '' }); const jsonStr = this.callNativeFunction({ name: 'loadSceneList', value: '' });
await this.asyncDelayLog('汪汪汪32'); await this.asyncDelayLog('汪汪汪32');
...@@ -111,6 +111,16 @@ cc.Class({ ...@@ -111,6 +111,16 @@ cc.Class({
this.currentBundleIndex = index; this.currentBundleIndex = index;
const currentBundleInfo = this.bundleInfoList[this.currentBundleIndex]; const currentBundleInfo = this.bundleInfoList[this.currentBundleIndex];
const btnLeft = this.node.getChildByName('BtnLeft');
const btnRight = this.node.getChildByName('BtnRight');
if (this.currentBundleIndex == 0) {
btnLeft.active = false;
}
if (this.currentBundleIndex == this.bundleInfoList.length - 1) {
btnRight.active = false;
}
this.baseUrl = currentBundleInfo.baseUrl; this.baseUrl = currentBundleInfo.baseUrl;
this.token = currentBundleInfo.token; this.token = currentBundleInfo.token;
this.homework_id = currentBundleInfo.homework_id; this.homework_id = currentBundleInfo.homework_id;
...@@ -198,20 +208,25 @@ cc.Class({ ...@@ -198,20 +208,25 @@ cc.Class({
const btnLeft = this.node.getChildByName('BtnLeft'); const btnLeft = this.node.getChildByName('BtnLeft');
btnLeft.on('click', () => { btnLeft.on('click', () => {
if (this.currentBundleIndex - 1 < 0) { if (this.currentBundleIndex - 1 < 0) {
this.jumpToBundleByIndex(this.bundleInfoList.length - 1); return;
} else {
this.jumpToBundleByIndex(this.currentBundleIndex - 1);
} }
this.jumpToBundleByIndex(this.currentBundleIndex - 1);
}); });
const btnRight = this.node.getChildByName('BtnRight'); const btnRight = this.node.getChildByName('BtnRight');
btnRight.on('click', () => { btnRight.on('click', () => {
if (this.currentBundleIndex + 1 >= this.bundleInfoList.length) { if (this.currentBundleIndex + 1 >= this.bundleInfoList.length) {
this.jumpToBundleByIndex(0); return;
} else {
this.jumpToBundleByIndex(this.currentBundleIndex + 1);
} }
this.jumpToBundleByIndex(this.currentBundleIndex + 1);
}); });
if (this.currentBundleIndex == 0) {
btnLeft.active = false;
}
if (this.currentBundleIndex == this.bundleInfoList.length - 1) {
btnRight.active = false;
}
}, },
callNativeFunction(param) { callNativeFunction(param) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment