设置页
This commit is contained in:
+23
-4894
File diff suppressed because it is too large
Load Diff
@@ -1,17 +1,117 @@
|
|||||||
import { _decorator, Component, Node } from "cc";
|
import {
|
||||||
|
_decorator,
|
||||||
|
Component,
|
||||||
|
Node,
|
||||||
|
Button,
|
||||||
|
Label,
|
||||||
|
Color,
|
||||||
|
Sprite,
|
||||||
|
tween,
|
||||||
|
Vec3,
|
||||||
|
} from "cc";
|
||||||
import Utils from "../../../Main/Common/Utils";
|
import Utils from "../../../Main/Common/Utils";
|
||||||
import li_BaseView from "../../../Main/Common/li_BaseView";
|
import li_BaseView from "../../../Main/Common/li_BaseView";
|
||||||
import { GButton } from "../../../Main/Common/GButton";
|
import { GButton } from "../../../Main/Common/GButton";
|
||||||
|
import LanguageUtils, {
|
||||||
|
LanguageType,
|
||||||
|
} from "../../../Main/Common/LanguageUtils";
|
||||||
|
import AudioManager from "../../../Main/Manager/AudioManager";
|
||||||
|
import PlayerDataManager from "../../../Main/Manager/PlayerDataManager";
|
||||||
const { ccclass, property } = _decorator;
|
const { ccclass, property } = _decorator;
|
||||||
|
|
||||||
|
interface LanguageButton {
|
||||||
|
button: Button;
|
||||||
|
label: Label;
|
||||||
|
checkMark: Node;
|
||||||
|
bg: Sprite;
|
||||||
|
language: LanguageType;
|
||||||
|
}
|
||||||
|
|
||||||
@ccclass("SettingPanel")
|
@ccclass("SettingPanel")
|
||||||
export class SettingPanel extends li_BaseView {
|
export class SettingPanel extends li_BaseView {
|
||||||
private _nodeTab: any = {};
|
private _nodeTab: any = {};
|
||||||
|
|
||||||
|
@property(Label)
|
||||||
|
private titleLabel: Label = null;
|
||||||
|
|
||||||
|
@property(Node)
|
||||||
|
private panelBg: Node = null;
|
||||||
|
|
||||||
|
private languageDrawdown;
|
||||||
|
private languageButtons: LanguageButton[] = [];
|
||||||
|
private currentSelectedLang: LanguageType = null;
|
||||||
protected start(): void {
|
protected start(): void {
|
||||||
Utils.parseNode(this.node, this._nodeTab);
|
Utils.parseNode(this.node, this._nodeTab);
|
||||||
|
|
||||||
|
this.initUI();
|
||||||
this.registerListener();
|
this.registerListener();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onEnable() {
|
||||||
|
this.currentSelectedLang = LanguageUtils.CurrentLanguage;
|
||||||
|
this.updateSelection();
|
||||||
|
if (this.languageDrawdown) {
|
||||||
|
this.languageDrawdown.active = false;
|
||||||
|
}
|
||||||
|
this.playEnterAnimation();
|
||||||
|
}
|
||||||
|
|
||||||
|
private initUI() {
|
||||||
|
this.languageDrawdown = this._nodeTab.languageSelection;
|
||||||
|
this.initLanguageButton(
|
||||||
|
this._nodeTab.Language1,
|
||||||
|
LanguageType.EN,
|
||||||
|
"English"
|
||||||
|
);
|
||||||
|
this.initLanguageButton(this._nodeTab.Language2, LanguageType.HI, "हिंदी");
|
||||||
|
}
|
||||||
|
|
||||||
|
private initLanguageButton(
|
||||||
|
button: Button,
|
||||||
|
language: LanguageType,
|
||||||
|
displayName: string
|
||||||
|
) {
|
||||||
|
if (!button) return;
|
||||||
|
|
||||||
|
const node = button.node;
|
||||||
|
|
||||||
|
let labelNode = node.getChildByName("Label");
|
||||||
|
if (!labelNode) {
|
||||||
|
labelNode = node.getChildByName("label");
|
||||||
|
}
|
||||||
|
|
||||||
|
let label: Label = null;
|
||||||
|
if (labelNode) {
|
||||||
|
label = labelNode.getComponent(Label);
|
||||||
|
if (label) {
|
||||||
|
label.string = displayName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let checkMark = node.getChildByName("CheckMark");
|
||||||
|
if (!checkMark) {
|
||||||
|
checkMark = node.getChildByName("checkmark");
|
||||||
|
}
|
||||||
|
if (checkMark) {
|
||||||
|
checkMark.active = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
let bg = node.getComponent(Sprite);
|
||||||
|
if (!bg) {
|
||||||
|
const bgNode = node.getChildByName("Bg");
|
||||||
|
if (bgNode) {
|
||||||
|
bg = bgNode.getComponent(Sprite);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.languageButtons.push({
|
||||||
|
button,
|
||||||
|
label,
|
||||||
|
checkMark,
|
||||||
|
bg,
|
||||||
|
language,
|
||||||
|
});
|
||||||
|
}
|
||||||
registerListener() {
|
registerListener() {
|
||||||
GButton.BandClick(this._nodeTab.MusicBtn, this.switchMusic, this);
|
GButton.BandClick(this._nodeTab.MusicBtn, this.switchMusic, this);
|
||||||
GButton.BandClick(this._nodeTab.SoundBtn, this.switchSound, this);
|
GButton.BandClick(this._nodeTab.SoundBtn, this.switchSound, this);
|
||||||
@@ -25,16 +125,130 @@ export class SettingPanel extends li_BaseView {
|
|||||||
GButton.BandClick(this._nodeTab.Language2, this.swithcToHi, this);
|
GButton.BandClick(this._nodeTab.Language2, this.swithcToHi, this);
|
||||||
|
|
||||||
GButton.BandClick(this._nodeTab.closeBtn, this.close, this);
|
GButton.BandClick(this._nodeTab.closeBtn, this.close, this);
|
||||||
|
|
||||||
|
this.languageButtons.forEach((langBtn) => {
|
||||||
|
if (langBtn.button) {
|
||||||
|
langBtn.button.node.on(
|
||||||
|
Button.EventType.CLICK,
|
||||||
|
() => {
|
||||||
|
this.onLanguageSelect(langBtn.language);
|
||||||
|
},
|
||||||
|
this
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
switchSound() {
|
switchSound() {
|
||||||
throw new Error("Method not implemented.");
|
const currentState = PlayerDataManager.I.IsSoundOn;
|
||||||
|
PlayerDataManager.I.SetSoundOn(!currentState);
|
||||||
|
AudioManager.I.PlayEffect("click");
|
||||||
}
|
}
|
||||||
|
|
||||||
switchMusic() {
|
switchMusic() {
|
||||||
throw new Error("Method not implemented.");
|
const currentState = PlayerDataManager.I.IsMusicOn;
|
||||||
|
PlayerDataManager.I.SetMusicOn(!currentState);
|
||||||
|
AudioManager.I.PlayEffect("click");
|
||||||
}
|
}
|
||||||
|
|
||||||
openLanguageSelection() {}
|
openLanguageSelection() {
|
||||||
|
if (this.languageDrawdown) {
|
||||||
|
this.languageDrawdown.active = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
switchToEn() {}
|
switchToEn() {
|
||||||
swithcToHi() {}
|
this.onLanguageSelect(LanguageType.EN);
|
||||||
|
}
|
||||||
|
|
||||||
|
switchToCn() {
|
||||||
|
this.onLanguageSelect(LanguageType.CN);
|
||||||
|
}
|
||||||
|
|
||||||
|
swithcToHi() {
|
||||||
|
this.onLanguageSelect(LanguageType.HI);
|
||||||
|
}
|
||||||
|
|
||||||
|
private onLanguageSelect(language: LanguageType) {
|
||||||
|
if (this.currentSelectedLang === language) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
AudioManager.I.PlayEffect("click");
|
||||||
|
|
||||||
|
this.currentSelectedLang = language;
|
||||||
|
LanguageUtils.setLanguage(language);
|
||||||
|
this.updateSelection();
|
||||||
|
|
||||||
|
const selectedBtn = this.languageButtons.find(
|
||||||
|
(btn) => btn.language === language
|
||||||
|
);
|
||||||
|
if (selectedBtn && selectedBtn.button) {
|
||||||
|
this.playSelectAnimation(selectedBtn.button.node);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.scheduleOnce(() => {
|
||||||
|
this.playExitAnimation(() => {
|
||||||
|
this.close();
|
||||||
|
});
|
||||||
|
}, 0.5);
|
||||||
|
}
|
||||||
|
|
||||||
|
private updateSelection() {
|
||||||
|
this.languageButtons.forEach((langBtn) => {
|
||||||
|
const isSelected = langBtn.language === this.currentSelectedLang;
|
||||||
|
|
||||||
|
if (langBtn.checkMark) {
|
||||||
|
langBtn.checkMark.active = isSelected;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (langBtn.bg) {
|
||||||
|
if (isSelected) {
|
||||||
|
langBtn.bg.color = new Color(150, 255, 150, 255);
|
||||||
|
} else {
|
||||||
|
langBtn.bg.color = new Color(255, 255, 255, 255);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (langBtn.button) {
|
||||||
|
langBtn.button.interactable = !isSelected;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private playSelectAnimation(node: Node) {
|
||||||
|
tween(node)
|
||||||
|
.to(0.1, { scale: new Vec3(1.1, 1.1, 1) })
|
||||||
|
.to(0.1, { scale: new Vec3(1, 1, 1) })
|
||||||
|
.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
private playEnterAnimation() {
|
||||||
|
if (this.panelBg) {
|
||||||
|
this.panelBg.scale = new Vec3(0.8, 0.8, 1);
|
||||||
|
tween(this.panelBg)
|
||||||
|
.to(0.3, { scale: new Vec3(1, 1, 1) }, { easing: "backOut" })
|
||||||
|
.start();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private playExitAnimation(callback: () => void) {
|
||||||
|
if (this.panelBg) {
|
||||||
|
tween(this.panelBg)
|
||||||
|
.to(0.2, { scale: new Vec3(0.8, 0.8, 1) }, { easing: "backIn" })
|
||||||
|
.call(callback)
|
||||||
|
.start();
|
||||||
|
} else {
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onDestroy() {
|
||||||
|
this.languageButtons.forEach((langBtn) => {
|
||||||
|
if (langBtn.button) {
|
||||||
|
langBtn.button.node.targetOff(this);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
super.onDestroy();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,250 +0,0 @@
|
|||||||
import {
|
|
||||||
_decorator,
|
|
||||||
Component,
|
|
||||||
Node,
|
|
||||||
Button,
|
|
||||||
Label,
|
|
||||||
Color,
|
|
||||||
Sprite,
|
|
||||||
tween,
|
|
||||||
Vec3,
|
|
||||||
} from "cc";
|
|
||||||
import li_BaseView from "../../../Main/Common/li_BaseView";
|
|
||||||
import LanguageUtils, { LanguageType } from "../../../Main/Common/LanguageUtils";
|
|
||||||
import AudioManager from "../../../Main/Manager/AudioManager";
|
|
||||||
import { ConfigManager } from "../../manager/ConfigManager";
|
|
||||||
|
|
||||||
const { ccclass, property } = _decorator;
|
|
||||||
|
|
||||||
interface LanguageButton {
|
|
||||||
button: Button;
|
|
||||||
label: Label;
|
|
||||||
checkMark: Node;
|
|
||||||
bg: Sprite;
|
|
||||||
language: LanguageType;
|
|
||||||
}
|
|
||||||
|
|
||||||
@ccclass("SimpleLanguagePanel")
|
|
||||||
export class SimpleLanguagePanel extends li_BaseView {
|
|
||||||
@property(Button)
|
|
||||||
private closeBtn: Button = null;
|
|
||||||
|
|
||||||
@property(Node)
|
|
||||||
private languageDrawdown: Node = null;
|
|
||||||
|
|
||||||
@property(Label)
|
|
||||||
private titleLabel: Label = null;
|
|
||||||
|
|
||||||
@property(Button)
|
|
||||||
private btnEnglish: Button = null;
|
|
||||||
|
|
||||||
@property(Button)
|
|
||||||
private btnChinese: Button = null;
|
|
||||||
|
|
||||||
@property(Button)
|
|
||||||
private btnHindi: Button = null;
|
|
||||||
|
|
||||||
|
|
||||||
@property(Node)
|
|
||||||
private panelBg: Node = null;
|
|
||||||
|
|
||||||
private languageButtons: LanguageButton[] = [];
|
|
||||||
private currentSelectedLang: LanguageType = null;
|
|
||||||
|
|
||||||
onLoadCT() {
|
|
||||||
super.onLoadCT();
|
|
||||||
this.initUI();
|
|
||||||
this.bindEvents();
|
|
||||||
this.playEnterAnimation();
|
|
||||||
}
|
|
||||||
|
|
||||||
onEnable() {
|
|
||||||
this.currentSelectedLang = LanguageUtils.CurrentLanguage;
|
|
||||||
this.updateSelection();
|
|
||||||
this.languageDrawdown.active = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public onClickLanguageSelect() {
|
|
||||||
this.languageDrawdown.active = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private initUI() {
|
|
||||||
// 初始化语言按钮数组
|
|
||||||
this.initLanguageButton(this.btnEnglish, LanguageType.EN, "English");
|
|
||||||
this.initLanguageButton(this.btnChinese, LanguageType.CN, "中文");
|
|
||||||
this.initLanguageButton(this.btnHindi, LanguageType.HI, "हिंदी");
|
|
||||||
}
|
|
||||||
|
|
||||||
private initLanguageButton(
|
|
||||||
button: Button,
|
|
||||||
language: LanguageType,
|
|
||||||
displayName: string
|
|
||||||
) {
|
|
||||||
if (!button) return;
|
|
||||||
|
|
||||||
const node = button.node;
|
|
||||||
|
|
||||||
// 查找或创建标签
|
|
||||||
let labelNode = node.getChildByName("Label");
|
|
||||||
if (!labelNode) {
|
|
||||||
labelNode = node.getChildByName("label");
|
|
||||||
}
|
|
||||||
|
|
||||||
let label: Label = null;
|
|
||||||
if (labelNode) {
|
|
||||||
label = labelNode.getComponent(Label);
|
|
||||||
if (label) {
|
|
||||||
label.string = displayName;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 查找或创建选中标记
|
|
||||||
let checkMark = node.getChildByName("CheckMark");
|
|
||||||
if (!checkMark) {
|
|
||||||
checkMark = node.getChildByName("checkmark");
|
|
||||||
}
|
|
||||||
if (checkMark) {
|
|
||||||
checkMark.active = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 获取背景
|
|
||||||
let bg = node.getComponent(Sprite);
|
|
||||||
if (!bg) {
|
|
||||||
const bgNode = node.getChildByName("Bg");
|
|
||||||
if (bgNode) {
|
|
||||||
bg = bgNode.getComponent(Sprite);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.languageButtons.push({
|
|
||||||
button,
|
|
||||||
label,
|
|
||||||
checkMark,
|
|
||||||
bg,
|
|
||||||
language,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private bindEvents() {
|
|
||||||
if (this.closeBtn) {
|
|
||||||
this.closeBtn.node.on(Button.EventType.CLICK, this.onCloseBtnClick, this);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 绑定语言按钮事件
|
|
||||||
this.languageButtons.forEach((langBtn) => {
|
|
||||||
if (langBtn.button) {
|
|
||||||
langBtn.button.node.on(
|
|
||||||
Button.EventType.CLICK,
|
|
||||||
() => {
|
|
||||||
this.onLanguageSelect(langBtn.language);
|
|
||||||
},
|
|
||||||
this
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private onLanguageSelect(language: LanguageType) {
|
|
||||||
if (this.currentSelectedLang === language) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//AudioManager.I.playSfx("click");
|
|
||||||
|
|
||||||
this.currentSelectedLang = language;
|
|
||||||
LanguageUtils.setLanguage(language);
|
|
||||||
this.updateSelection();
|
|
||||||
|
|
||||||
// 播放选中动画
|
|
||||||
const selectedBtn = this.languageButtons.find(
|
|
||||||
(btn) => btn.language === language
|
|
||||||
);
|
|
||||||
if (selectedBtn && selectedBtn.button) {
|
|
||||||
this.playSelectAnimation(selectedBtn.button.node);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 延迟关闭面板
|
|
||||||
this.scheduleOnce(() => {
|
|
||||||
this.playExitAnimation(() => {
|
|
||||||
this.close();
|
|
||||||
});
|
|
||||||
}, 0.5);
|
|
||||||
}
|
|
||||||
|
|
||||||
private updateSelection() {
|
|
||||||
this.languageButtons.forEach((langBtn) => {
|
|
||||||
const isSelected = langBtn.language === this.currentSelectedLang;
|
|
||||||
|
|
||||||
// 更新选中标记
|
|
||||||
if (langBtn.checkMark) {
|
|
||||||
langBtn.checkMark.active = isSelected;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 更新背景色
|
|
||||||
if (langBtn.bg) {
|
|
||||||
if (isSelected) {
|
|
||||||
langBtn.bg.color = new Color(150, 255, 150, 255);
|
|
||||||
} else {
|
|
||||||
langBtn.bg.color = new Color(255, 255, 255, 255);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 更新按钮交互性
|
|
||||||
if (langBtn.button) {
|
|
||||||
langBtn.button.interactable = !isSelected;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private playSelectAnimation(node: Node) {
|
|
||||||
tween(node)
|
|
||||||
.to(0.1, { scale: new Vec3(1.1, 1.1, 1) })
|
|
||||||
.to(0.1, { scale: new Vec3(1, 1, 1) })
|
|
||||||
.start();
|
|
||||||
}
|
|
||||||
|
|
||||||
private playEnterAnimation() {
|
|
||||||
if (this.panelBg) {
|
|
||||||
this.panelBg.scale = new Vec3(0.8, 0.8, 1);
|
|
||||||
tween(this.panelBg)
|
|
||||||
.to(0.3, { scale: new Vec3(1, 1, 1) }, { easing: "backOut" })
|
|
||||||
.start();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private playExitAnimation(callback: () => void) {
|
|
||||||
if (this.panelBg) {
|
|
||||||
tween(this.panelBg)
|
|
||||||
.to(0.2, { scale: new Vec3(0.8, 0.8, 1) }, { easing: "backIn" })
|
|
||||||
.call(callback)
|
|
||||||
.start();
|
|
||||||
} else {
|
|
||||||
callback();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private onCloseBtnClick() {
|
|
||||||
//AudioManager.I.playSfx("click");
|
|
||||||
this.playExitAnimation(() => {
|
|
||||||
this.close();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
onDestroy() {
|
|
||||||
// if (this.closeBtn) {
|
|
||||||
// this.closeBtn.node.off(
|
|
||||||
// Button.EventType.CLICK,
|
|
||||||
// this.onCloseBtnClick,
|
|
||||||
// this
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
|
|
||||||
// this.languageButtons.forEach((langBtn) => {
|
|
||||||
// if (langBtn.button) {
|
|
||||||
// langBtn.button.node.targetOff(this);
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
|
|
||||||
super.onDestroy();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
{
|
|
||||||
"ver": "4.0.24",
|
|
||||||
"importer": "typescript",
|
|
||||||
"imported": true,
|
|
||||||
"uuid": "775ab74f-0a20-4218-9c6e-9e30bfc91635",
|
|
||||||
"files": [],
|
|
||||||
"subMetas": {},
|
|
||||||
"userData": {}
|
|
||||||
}
|
|
||||||
@@ -175,7 +175,7 @@ export class ThemePanel extends li_BaseView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
openSetting() {
|
openSetting() {
|
||||||
ViewManager.I.openBundlesView("LanguagePanel");
|
ViewManager.I.openBundlesView("SettingPanel");
|
||||||
}
|
}
|
||||||
|
|
||||||
openMsgBox() {
|
openMsgBox() {
|
||||||
|
|||||||
+4370
-2035
File diff suppressed because it is too large
Load Diff
+2
-2
@@ -2,12 +2,12 @@
|
|||||||
"ver": "1.1.50",
|
"ver": "1.1.50",
|
||||||
"importer": "prefab",
|
"importer": "prefab",
|
||||||
"imported": true,
|
"imported": true,
|
||||||
"uuid": "e1582f17-936e-4c4d-af55-0edf062e5181",
|
"uuid": "841a0c1d-ee34-45b6-837c-6b8854a38834",
|
||||||
"files": [
|
"files": [
|
||||||
".json"
|
".json"
|
||||||
],
|
],
|
||||||
"subMetas": {},
|
"subMetas": {},
|
||||||
"userData": {
|
"userData": {
|
||||||
"syncNodeName": "LanguagePanel"
|
"syncNodeName": "SettingPanel"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user