Commit 9c320242 authored by liujiangnan's avatar liujiangnan

feat: 确定框

parent 791aa3e3
import { initAir } from "./air"; import { initAir } from "./air";
import { middleLayerBase } from "./middleLayerBase"; import { middleLayerBase } from "./middleLayerBase";
import { buttonOnceClick } from "./util";
const { ccclass, property } = cc._decorator; const { ccclass, property } = cc._decorator;
...@@ -41,6 +42,26 @@ export default class NewClass extends middleLayerBase { ...@@ -41,6 +42,26 @@ export default class NewClass extends middleLayerBase {
}) })
.start(); .start();
} }
showConfirm(str: string, yesFun: Function = null, noFun: Function = null) {
const tipsLayer = cc.find('middleLayer/confirmLayer');
const label = cc.find('middleLayer/confirmLayer/confirm_bg/label');
label.getComponent(cc.Label).string = ` ${str} `;
const tips = cc.find('middleLayer/confirmLayer/confirm_bg');
tips.width = label.width + 50;
tipsLayer.active = true;
const yesBtn = cc.find('middleLayer/confirmLayer/confirm_bg/btn_yes');
buttonOnceClick(yesBtn, (evt)=>{
yesFun&&yesFun(evt);
tipsLayer.active = false;
});
const noBtn = cc.find('middleLayer/confirmLayer/confirm_bg/btn_no');
buttonOnceClick(noBtn, (evt)=>{
noFun&&noFun(evt);
tipsLayer.active = false;
});
}
showMask() { showMask() {
} }
...@@ -109,6 +130,12 @@ export default class NewClass extends middleLayerBase { ...@@ -109,6 +130,12 @@ export default class NewClass extends middleLayerBase {
} else { } else {
this.loadOnlineBundle('NJ_login'); this.loadOnlineBundle('NJ_login');
} }
this.showConfirm("Hello World", ()=>{
console.log("=====点击了确定=====")
}, ()=>{
console.log("=====点击了取消=====")
});
} }
role = 'student'; role = 'student';
......
...@@ -421,4 +421,38 @@ export function onHomeworkFinish() { ...@@ -421,4 +421,38 @@ export function onHomeworkFinish() {
} else { } else {
console.log('onHomeworkFinish'); console.log('onHomeworkFinish');
} }
}
export function buttonOnceClick(button: cc.Node, callback: Function, scale = 1.1) {
button.once('click', () => {
if (button['cantClick']) {
return;
}
button['cantClick'] = true;
cc.tween(button)
.to(0.1, { scale: scale })
.to(0.1, { scale: 1.0 })
.call(() => {
button['cantClick'] = false;
callback && callback();
})
.start();
});
}
export function buttonOnClick(button: cc.Node, callback: Function, scale = 1.1) {
button.on('click', () => {
if (button['cantClick']) {
return;
}
button['cantClick'] = true;
cc.tween(button)
.to(0.1, { scale: scale })
.to(0.1, { scale: 1.0 })
.call(() => {
button['cantClick'] = false;
callback && callback();
})
.start();
});
} }
\ No newline at end of file
{
"ver": "2.3.5",
"uuid": "95ed3142-901d-4e0f-bc31-702e47c20fb3",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 158,
"height": 60,
"platformSettings": {},
"subMetas": {
"btn_bg": {
"ver": "1.0.4",
"uuid": "e9dabba7-7ff4-45b1-9ab9-e6f5b31aead7",
"rawTextureUuid": "95ed3142-901d-4e0f-bc31-702e47c20fb3",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 158,
"height": 60,
"rawWidth": 158,
"rawHeight": 60,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"subMetas": {}
}
}
}
\ No newline at end of file
{
"ver": "2.3.5",
"uuid": "322171a8-bd31-4fed-8525-563adfac4324",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 684,
"height": 244,
"platformSettings": {},
"subMetas": {
"confirm_bg": {
"ver": "1.0.4",
"uuid": "204b7485-dcbc-46f6-a45e-4efa44034005",
"rawTextureUuid": "322171a8-bd31-4fed-8525-563adfac4324",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 684,
"height": 244,
"rawWidth": 684,
"rawHeight": 244,
"borderTop": 60,
"borderBottom": 60,
"borderLeft": 60,
"borderRight": 60,
"subMetas": {}
}
}
}
\ No newline at end of file
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