美术更新
- detail页面修改 - ui布局修改
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
import { _decorator, Button, Component, Node, NodeEventType, Sprite } from "cc";
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass("SimpleToggle")
|
||||
export class SimpleToggle extends Component {
|
||||
@property(Sprite)
|
||||
selectedSprite: Sprite = null;
|
||||
@property(Sprite)
|
||||
unSelectedSprite: Sprite = null;
|
||||
|
||||
callback: () => {};
|
||||
|
||||
toggleGroupCallBack: Function;
|
||||
|
||||
btn: Button;
|
||||
protected onLoad(): void {
|
||||
this.node.on(NodeEventType.TOUCH_START, this.onClickThis, this);
|
||||
this.btn = this.getComponent(Button);
|
||||
}
|
||||
|
||||
init(isSelected: boolean, callBack: () => {}) {
|
||||
this.selectedSprite.enabled = isSelected;
|
||||
this.unSelectedSprite.enabled = !isSelected;
|
||||
if (this.callback) {
|
||||
this.onDestroy();
|
||||
}
|
||||
this.callback = callBack;
|
||||
|
||||
this.node.on(NodeEventType.TOUCH_START, this.onClickThis, this);
|
||||
}
|
||||
|
||||
refresh(isSelected: boolean) {
|
||||
this.selectedSprite.enabled = isSelected;
|
||||
this.unSelectedSprite.enabled = !isSelected;
|
||||
}
|
||||
|
||||
onClickThis() {
|
||||
if (this.callback) {
|
||||
this.callback();
|
||||
}
|
||||
if (this.toggleGroupCallBack) {
|
||||
this.toggleGroupCallBack(this.node);
|
||||
}
|
||||
this.btn.interactable = false;
|
||||
}
|
||||
|
||||
protected onDestroy(): void {
|
||||
this.node.off(NodeEventType.TOUCH_START, this.onClickThis, this);
|
||||
|
||||
this.callback = null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user