Files
Monopoly/assets/res-native/setting/SwitchLang.ts
2026-03-30 09:39:59 +08:00

34 lines
1.0 KiB
TypeScript

import { _decorator, Component, Label, Sprite, SpriteFrame } from "cc";
import { app } from "../../app/app";
import { Tools } from "../tools/Tools";
import { LANG_SET } from "./LangSet";
const { ccclass, property } = _decorator;
@ccclass('SwitchLang')
export class SwitchLang extends Component {
@property(String) lab_lang: string = "";
@property(SpriteFrame) spr_lang : SpriteFrame[] = [];
protected onLoad(): void {
this.updateLab();
app.manager.event.on("LangChanged", this.updateLab, this);
}
protected onDestroy(): void {
app?.manager.event?.off("LangChanged", this.updateLab, this);
}
updateLab(){
let lab = this.getComponent(Label)
if (lab != null) {
this.getComponent(Label).string = Tools.GetLocalized(this.lab_lang)
};
let sprite = this.getComponent(Sprite)
if (sprite != null) {
if (this.spr_lang && this.spr_lang[LANG_SET.langIndex])
this.getComponent(Sprite).spriteFrame = this.spr_lang[LANG_SET.langIndex]
};
}
}