设置页

This commit is contained in:
2025-09-10 21:02:32 +08:00
parent 24b9942110
commit 3bdeb53859
4 changed files with 91 additions and 52 deletions
@@ -37,7 +37,8 @@ export class SettingPanel extends li_BaseView {
@property(Node)
private panelBg: Node = null;
private languageDrawdown;
private languageDrawdown: Node;
private curLanguage: Label;
private languageButtons: LanguageButton[] = [];
private currentSelectedLang: LanguageType = null;
protected start(): void {
@@ -45,25 +46,55 @@ export class SettingPanel extends li_BaseView {
this.initUI();
this.registerListener();
if (this.languageDrawdown) {
this.languageDrawdown.active = false;
this.languageDrawdown.setScale(new Vec3(1, 0, 1));
}
}
onEnable() {
this.currentSelectedLang = LanguageUtils.CurrentLanguage;
this.updateSelection();
if (this.languageDrawdown) {
this.languageDrawdown.active = false;
}
this.playEnterAnimation();
}
private music_on: Node;
private music_off: Node;
private sound_on: Node;
private sound_off: Node;
private initUI() {
this.languageDrawdown = this._nodeTab.languageSelection;
this.curLanguage = this._nodeTab.curLanguage.getComponent(Label);
this.initLanguageButton(
this._nodeTab.Language1,
this._nodeTab.Language1.getComponent(Button),
LanguageType.EN,
"English"
);
this.initLanguageButton(this._nodeTab.Language2, LanguageType.HI, "हिंदी");
this.initLanguageButton(
this._nodeTab.Language2.getComponent(Button),
LanguageType.HI,
"हिंदी"
);
this.languageButtons.forEach((b) => {
if (b.language == LanguageUtils.CurrentLanguage) {
this.curLanguage.string = b.label.string;
}
});
this.music_on = this._nodeTab.MusicBtn.getChildByName("On");
this.music_off = this._nodeTab.MusicBtn.getChildByName("Off");
this.sound_on = this._nodeTab.SoundBtn.getChildByName("On");
this.sound_off = this._nodeTab.SoundBtn.getChildByName("Off");
let currentState = PlayerDataManager.I.IsSoundOn;
this.sound_on.active = currentState;
this.sound_off.active = !currentState;
currentState = PlayerDataManager.I.IsMusicOn;
this.music_on.active = currentState;
this.music_off.active = !currentState;
}
private initLanguageButton(
@@ -121,8 +152,8 @@ export class SettingPanel extends li_BaseView {
this
);
GButton.BandClick(this._nodeTab.Language1, this.switchToEn, this);
GButton.BandClick(this._nodeTab.Language2, this.swithcToHi, this);
// GButton.BandClick(this._nodeTab.Language1, this.switchToEn, this);
// GButton.BandClick(this._nodeTab.Language2, this.swithcToHi, this);
GButton.BandClick(this._nodeTab.closeBtn, this.close, this);
@@ -140,20 +171,33 @@ export class SettingPanel extends li_BaseView {
}
switchSound() {
const currentState = PlayerDataManager.I.IsSoundOn;
this.sound_on.active = currentState;
this.sound_off.active = !currentState;
PlayerDataManager.I.SetSoundOn(!currentState);
AudioManager.I.PlayEffect("click");
}
switchMusic() {
const currentState = PlayerDataManager.I.IsMusicOn;
this.music_on.active = currentState;
this.music_off.active = !currentState;
PlayerDataManager.I.SetMusicOn(!currentState);
AudioManager.I.PlayEffect("click");
}
isShow: boolean = false;
openLanguageSelection() {
if (this.languageDrawdown) {
this.languageDrawdown.active = true;
if (!this.isShow) {
if (this.languageDrawdown) {
this.languageDrawdown.active = true;
tween(this.languageDrawdown)
.to(0.2, { scale: new Vec3(1, 1, 1) })
.start();
}
} else {
tween(this.languageDrawdown)
.to(0.2, { scale: new Vec3(1, 0, 1) })
.start();
}
this.isShow = !this.isShow;
}
switchToEn() {
@@ -172,8 +216,7 @@ export class SettingPanel extends li_BaseView {
if (this.currentSelectedLang === language) {
return;
}
AudioManager.I.PlayEffect("click");
//AudioManager.I.PlayEffect("click");
this.currentSelectedLang = language;
LanguageUtils.setLanguage(language);
@@ -185,12 +228,14 @@ export class SettingPanel extends li_BaseView {
if (selectedBtn && selectedBtn.button) {
this.playSelectAnimation(selectedBtn.button.node);
}
this.curLanguage.string = selectedBtn.label.string;
this.scheduleOnce(() => {
this.playExitAnimation(() => {
this.close();
});
}, 0.5);
if (this.languageDrawdown) {
tween(this.languageDrawdown)
.to(0.2, { scale: new Vec3(1, 0, 1) })
.start();
}
this.isShow = false;
}
private updateSelection() {
@@ -241,14 +286,4 @@ export class SettingPanel extends li_BaseView {
callback();
}
}
onDestroy() {
this.languageButtons.forEach((langBtn) => {
if (langBtn.button) {
langBtn.button.node.targetOff(this);
}
});
super.onDestroy();
}
}