1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- import game_constants from "./game_constants";
- const { ccclass, property } = cc._decorator;
- @ccclass
- export default class NewClass extends cc.Component {
- @property(cc.Label)
- level_text: cc.Label = null;
- @property(cc.Label)
- level_grey: cc.Label = null;
- @property(cc.Node)
- lock_node: cc.Node = null;
- @property(cc.Node)
- currentLv_node: cc.Node = null;
- current_level = 0;
- protected onLoad(): void {
- // 在节点加载时,为节点添加触摸结束事件监听器
- this.addTouchEndEventListener();
- }
- // 为节点添加触摸结束事件监听器的函数
- private addTouchEndEventListener(): void {
- this.node.on(cc.Node.EventType.TOUCH_END, this.onLevelClick, this);
- }
- initLevelItem(lv: number, isCurrentLv: boolean, isLock: boolean) {
- // 设置当前等级值
- this.setCurrentLevel(lv);
- // 更新等级文本显示
- this.updateLevelText(lv);
- // 更新灰色等级文本显示
- this.updateLevelGreyText(lv);
- // 根据是否为当前等级,设置当前等级节点的显示状态
- this.setCurrentLvNodeActive(isCurrentLv);
- // 根据是否锁定,设置锁定节点的显示状态
- this.setLockNodeActive(isLock);
- }
- // 设置当前等级值的函数
- private setCurrentLevel(lv: number): void {
- this.current_level = lv;
- }
- // 更新等级文本显示的函数
- private updateLevelText(lv: number): void {
- this.level_text.string = lv + "";
- }
- // 更新灰色等级文本显示的函数
- private updateLevelGreyText(lv: number): void {
- this.level_grey.string = lv + "";
- }
- // 根据是否为当前等级,设置当前等级节点的显示状态的函数
- private setCurrentLvNodeActive(isCurrentLv: boolean): void {
- if (isCurrentLv) {
- this.currentLv_node.active = true;
- }
- }
- // 根据是否锁定,设置锁定节点的显示状态的函数
- private setLockNodeActive(isLock: boolean): void {
- this.lock_node.active = isLock;
- }
- onLevelClick() {
- // 检查是否可点击当前等级,并在可点击时发送选择等级点击事件
- this.checkAndEmitLevelClickEvent();
- }
- // 检查是否可点击当前等级,并在可点击时发送选择等级点击事件的函数
- private checkAndEmitLevelClickEvent(): void {
- if (this.lock_node.active === false && this.current_level > 0) {
- cc.systemEvent.emit(game_constants.select_level_clicked, this.current_level);
- }
- }
- // update (dt) {}
- }
|