Files
18xchat/assets/Scripts/chat18x/ui/components/SimpleToggle.ts
T

43 lines
1.0 KiB
TypeScript
Raw Normal View History

2025-08-25 20:15:42 +08:00
import { _decorator, Button, Component, Node, NodeEventType, Sprite } from "cc";
2025-09-20 12:22:00 +08:00
import { GButton } from "../../../Main/Common/GButton";
2025-08-25 20:15:42 +08:00
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 {
2025-09-20 12:22:00 +08:00
GButton.BandClick(this.node,this.onClickThis,this);
2025-08-25 20:15:42 +08:00
this.btn = this.getComponent(Button);
}
refresh(isSelected: boolean) {
2025-09-09 14:31:47 +08:00
this.selectedSprite.node.active = isSelected;
this.unSelectedSprite.node.active = !isSelected;
2025-08-25 20:15:42 +08:00
}
onClickThis() {
if (this.callback) {
this.callback();
}
if (this.toggleGroupCallBack) {
this.toggleGroupCallBack(this.node);
}
this.btn.interactable = false;
}
protected onDestroy(): void {
2025-09-20 12:22:00 +08:00
//this.node.off(NodeEventType.TOUCH_START, this.onClickThis, this);
2025-08-25 20:15:42 +08:00
this.callback = null;
}
}