using IVDataFormat; using IVServerFormat; using TMPro; using UnityEngine; public class NoticeMgr : MonoBehaviour { #region Const private static NoticeMgr curMgr = null; #endregion Const #region Notice UI [Header("Notice UI")] [SerializeField] private GameObject goBtnNotice; //private GameObject goBadgeNotice; [SerializeField] private Canvas canvasNoticeUI; private TextMeshProUGUI txtNoticeTitle; private GameObject goList, goDetail; private GameObject goBtnClose, goBtnBack; private TextMeshProUGUI txtDesc, txtNoNotice, txtBigTitle; [SerializeField] private EScrController escrNotice; #endregion UI #region Variables private int iLoading = 1; private bool bReLocalize = true; private bool bInitNeedNotice = true; private bool bRefreshNotice = false; EnhancedUI.SmallList notices; #endregion Variables #region Base public static void SLocalize(bool bmain) { if (curMgr != null) curMgr.Localize(bmain); } // 번역. private void Localize(bool bmain) { if (bmain) { goBtnNotice.transform.Find("txt").GetComponent().text = LocalizationText.GetText("notice_title"); //goBadgeNotice = goBtnNotice.transform.Find("badge").gameObject; } else { bReLocalize = false; Transform trfcanvas = canvasNoticeUI.transform; txtNoticeTitle = trfcanvas.Find("txtT").GetComponent(); goList = trfcanvas.Find("SvNotice").gameObject; goDetail = trfcanvas.Find("SvDetail").gameObject; goBtnClose = trfcanvas.Find("btnClose").gameObject; goBtnBack = trfcanvas.Find("btnBack").gameObject; txtDesc = goDetail.transform.Find("txtDesc").GetComponent(); txtNoNotice = trfcanvas.Find("txtNoNotice").GetComponent(); txtBigTitle = trfcanvas.Find("SvDetailTitle").GetComponent(); txtNoNotice.text = LocalizationText.GetText("no_notice"); } } // 설정에서 언어 변경 시 처리. public static void SReLocalize() { curMgr.Localize(true); curMgr.bReLocalize = true; curMgr.bRefreshNotice = true; } // 백버튼 처리. public static bool SCloseMenu() { return curMgr.CloseMenu(); } private bool CloseMenu() { // 공지. if (canvasNoticeUI.enabled) { CloseNotice(); return true; } return false; } private void Awake() { curMgr = this; } void Start() { iLoading--; } #endregion Base #region Notice UI public static void SOpenNotice() { if (curMgr != null) curMgr.OpenNotice(); } // 공지사항 열기. public void OpenNotice() { if (iLoading > 0) return; iLoading++; if (bReLocalize) Localize(false); if (bInitNeedNotice) { bInitNeedNotice = false; CloseDetail(); dNotice[] datas = DataHandler.GetNotices(); notices = new EnhancedUI.SmallList(); for (int i = 0; i < datas.Length; i++) { notices.Add(i); } escrNotice.LoadDatas(notices); } if (bRefreshNotice) { bRefreshNotice = false; RefreshNotice(); } canvasNoticeUI.enabled = true; if (DataHandler.GetNotices().Length == 0) { txtNoNotice.gameObject.SetActive(true); } else { txtNoNotice.gameObject.SetActive(false); } SoundMgr.Instance.PlaySfx(SoundName.BtnPress); iLoading--; } // 공지사항 닫기. public void CloseNotice() { if (!canvasNoticeUI.enabled) return; if (iLoading > 0) return; iLoading++; canvasNoticeUI.enabled = false; CloseDetail(); SoundMgr.Instance.PlaySfx(SoundName.BtnPress); iLoading--; } public static void SOpenDetail(int index) { curMgr.OpenDetail(index); } private void OpenDetail(int index) { if (!DataHandler.TryGetNotice(index, out dNotice targetNotice)) return; txtBigTitle.gameObject.SetActive(true); txtBigTitle.text = targetNotice.GetTitle(); txtDesc.text = targetNotice.GetMsg(); goList.SetActive(false); goDetail.SetActive(true); goBtnClose.SetActive(false); goBtnBack.SetActive(true); } public void CloseDetail() { goList.SetActive(true); goDetail.SetActive(false); goBtnClose.SetActive(true); goBtnBack.SetActive(false); txtBigTitle.gameObject.SetActive(false); txtNoticeTitle.text = LocalizationText.GetText("notice_title"); } #endregion Notice UI #region Notice Refresh public static void SRefreshNotice() { if (curMgr != null) curMgr.RefreshNotice(); } // 공지사항 갱신. public void RefreshNotice() { iLoading++; SvConnectManager.Instance.RequestSvGet(true, 0, UrlApi.GetUrl(UrlApi.Notice), typeof(dNoticeDatas), ANoticeSucc, ANoticeFail, false); } // 공지사항 통신 실패. private void ANoticeFail(SvError error) { iLoading--; } // 공지사항 통신 성공. private void ANoticeSucc(object result) { dNoticeDatas data = (dNoticeDatas)result; if (data.sysNotice == null) { ANoticeFail(new SvError(eErrorCode.NULL_OR_EMPTY)); return; } DataHandler.SetNewNotices(data.sysNotice); if (!bInitNeedNotice) { if (notices.Count != data.sysNotice.Length) { while (notices.Count > data.sysNotice.Length) { notices.RemoveEnd(); } while (notices.Count < data.sysNotice.Length) { notices.Add(notices.Count); } escrNotice.scroller.ReloadData(); } else { escrNotice.scroller.RefreshActiveCellViews(); } } iLoading--; } #endregion Notice Refresh }