备份CatanBuilding瘦身独立工程
This commit is contained in:
94
Assets/Scripts/UI/Setting/SelectlanguagePopupPanel.cs
Normal file
94
Assets/Scripts/UI/Setting/SelectlanguagePopupPanel.cs
Normal file
@@ -0,0 +1,94 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using asap.core;
|
||||
using cfg;
|
||||
using game;
|
||||
using GameCore;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class SelectlanguagePopupPanel : MonoBehaviour
|
||||
{
|
||||
public Button btn_close;
|
||||
public Button btn_mask;
|
||||
|
||||
public GameObject item;
|
||||
public Transform content;
|
||||
public Button btn_sure;
|
||||
int language;
|
||||
List<Toggle> toggles = new List<Toggle>();
|
||||
private void Awake()
|
||||
{
|
||||
btn_close = transform.Find("btn_close").GetComponent<Button>();
|
||||
btn_mask = transform.Find("mask").GetComponent<Button>();
|
||||
content = transform.Find("root/panel_list/ScrollView/Viewport/Content").GetComponent<Transform>();
|
||||
btn_sure = transform.Find("root/btn_sure/btn_green").GetComponent<Button>();
|
||||
|
||||
}
|
||||
private void Start()
|
||||
{
|
||||
item.SetActive(false);
|
||||
btn_close.onClick.AddListener(() => { UIManager.Instance.DestroyUI(UITypes.SelectlanguagePopupPanel); });
|
||||
btn_mask.onClick.AddListener(() => { UIManager.Instance.DestroyUI(UITypes.SelectlanguagePopupPanel); });
|
||||
IUIService uiService = GContext.container.Resolve<IUIService>();
|
||||
List<LanguageConfig> _dataList = GContext.container.Resolve<cfg.Tables>().TbLanguageConfig.DataList;
|
||||
for (int i = 0; i < _dataList.Count; i++)
|
||||
{
|
||||
GameObject go = Instantiate(item, content);
|
||||
go.SetActive(true);
|
||||
Image image = go.transform.Find("img_languagelist").GetComponent<Image>();
|
||||
uiService.SetImageSprite(image, _dataList[i].LanImg);
|
||||
var i1 = i;
|
||||
Toggle toggle = go.GetComponent<Toggle>();
|
||||
toggle.onValueChanged.AddListener((isOn) =>
|
||||
{
|
||||
if (isOn)
|
||||
{
|
||||
language = i1;
|
||||
}
|
||||
});
|
||||
toggles.Add(toggle);
|
||||
}
|
||||
|
||||
language = LocalizationMgr.LanguageIndex;
|
||||
for (int i = 0; i < toggles.Count; i++)
|
||||
{
|
||||
toggles[i].isOn = language == i;
|
||||
}
|
||||
btn_sure.onClick.AddListener(OnBtnLanguage);
|
||||
}
|
||||
|
||||
private async void OnBtnLanguage()
|
||||
{
|
||||
if (LocalizationMgr.LanguageIndex != language)
|
||||
{
|
||||
string languagePack = LocalizationMgr.languagePackList[language];
|
||||
ILoadResourceService loadResourceService = GContext.container.Resolve<ILoadResourceService>();
|
||||
bool isInit = await loadResourceService.Load(languagePack);
|
||||
if (!isInit)
|
||||
{
|
||||
Debug.Log($"Load language pack {languagePack} failed. download");
|
||||
var panel = await UIManager.Instance.ShowUINotLoading(UITypes.DownLoadPopupPanel);
|
||||
panel.GetComponent<DownLoadPopupPanel>().SetBtn(() =>
|
||||
{
|
||||
SetLanguage();
|
||||
}, () =>
|
||||
{
|
||||
UIManager.Instance.DestroyUI(UITypes.SelectlanguagePopupPanel);
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
SetLanguage();
|
||||
}
|
||||
//下载多语言包
|
||||
}
|
||||
|
||||
}
|
||||
void SetLanguage()
|
||||
{
|
||||
LocalizationMgr.SetLanguageAsync(language);
|
||||
UIManager.Instance.DestroyUI(UITypes.SelectlanguagePopupPanel);
|
||||
ToastPanel.Show(LocalizationMgr.GetText("UI_ToastPanel_108"));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user