
using System.Linq;
namespace ScrewsMaster
{
    public class MenuModel : BaseModel
    {
        public bool IsOpenMusic
        {
            get { return AudioManager.Instance.IsOpenBGM; }
            set { AudioManager.Instance.IsOpenBGM = value; }
        }

        public bool IsOpenEffect
        {
            get { return AudioManager.Instance.IsOpenEffect; }
            set { AudioManager.Instance.IsOpenEffect = value; }
        }

        #region 生命周期
        private int currLangId;
        private LangDisplayModel langDisplayModel;
        public int CurrLangId
        {
            get
            {
                string code = "";

                code = AppConst.CurrMultiLangue;

                currLangId = GetIdByLanguageCode(code);
                return currLangId;
            }
            set
            {
                currLangId = value;

                var vo = langDisplayModel.dataList[0];
                foreach (var langDisplay in langDisplayModel.dataList.Where(langDisplay => langDisplay.id == currLangId))
                {
                    vo = langDisplay;
                }
                PlayerPrefsKit.WriteString(LangIdKey, vo.language);
                UIManager.Instance.SetSwitchLanguage(vo.language);
            }
        }
        int GetIdByLanguageCode(string code)
        {
            if (langDisplayModel == null)
            {
                langDisplayModel = ConfigSystem.GetConfig<LangDisplayModel>();
            }

            var vo = langDisplayModel.dataList.Find((tmp) => tmp.language == code);
            if (vo != null)
                return vo.id;
            return GetIdByLanguageCode(AppConst.DefaultLangue);
        }

        public string LangIdKey = "LangIdKey";
        protected override void OnInit()
        {
        }

        protected override void OnDispose()
        {
        }

        // protected override void OnReset()
        // {
        // }

        // #endregion

        // #region 读取数据

        // protected override void OnReadData()
        // {
        // }

        // #endregion

        // #region 本地存储



        // protected override void WriteLocalStorage()
        // {

        // }

        #endregion

        #region 消息

        protected override void AddListener()
        {

        }

        protected override void RemoveListener()
        {

        }

        #endregion
    }
}