You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
545 lines
15 KiB
545 lines
15 KiB
using IVDataFormat;
|
|
using IVServerFormat;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
|
|
public class MailMgr : MonoBehaviour
|
|
{
|
|
#region Const
|
|
private static MailMgr curMgr = null;
|
|
#endregion Const
|
|
|
|
#region UI
|
|
[Header("UI")]
|
|
[SerializeField]
|
|
private TextMeshProUGUI txtMainT;
|
|
private GameObject goMainBadge;
|
|
[SerializeField]
|
|
private GameObject goUpBadge;
|
|
|
|
[SerializeField]
|
|
private Canvas canvasUI;
|
|
private ButtonIV[] btnTabs;
|
|
|
|
[SerializeField]
|
|
private EScrController escrMail;
|
|
private ButtonIV btnGetAll;
|
|
private TextMeshProUGUI txtMailEmpty, txtMailDesc;
|
|
|
|
[SerializeField]
|
|
private Sprite sprLetterClose, sprLetterOpen;
|
|
#endregion UI
|
|
|
|
#region Variables
|
|
private int iLoading = 1;
|
|
private bool bReLocalize = true;
|
|
private bool bReLocalizeMail = false;
|
|
private int iSelectedTab = -1;
|
|
private int iSvType = -1;
|
|
|
|
private int iMailLoading = 0;
|
|
private bool bUpdateMail = true;
|
|
private EnhancedUI.SmallList<int> mails;
|
|
private EnhancedUI.SmallList<int> reads;
|
|
#endregion Variables
|
|
|
|
#region Base
|
|
public static void SLocalize(bool bmain)
|
|
{
|
|
if (curMgr != null)
|
|
curMgr.Localize(bmain);
|
|
}
|
|
|
|
// 번역.
|
|
private void Localize(bool bmain)
|
|
{
|
|
if (bmain)
|
|
{
|
|
txtMainT.text = LocalizationText.GetText("mail_title");
|
|
goMainBadge = txtMainT.transform.parent.Find("badge").gameObject;
|
|
btnGetAll = canvasUI.transform.Find("btnGetAll").GetComponent<ButtonIV>();
|
|
}
|
|
else
|
|
{
|
|
bReLocalize = false;
|
|
Transform trfcanvas = canvasUI.transform;
|
|
trfcanvas.Find("txtT").GetComponent<TextMeshProUGUI>().text = LocalizationText.GetText("mail_title");
|
|
|
|
btnTabs = new ButtonIV[2];
|
|
btnTabs[0] = trfcanvas.Find("tabMail").GetComponent<ButtonIV>();
|
|
btnTabs[1] = trfcanvas.Find("tabRead").GetComponent<ButtonIV>();
|
|
btnTabs[0].transform.Find("txt").GetComponent<TextMeshProUGUI>().text = LocalizationText.GetText("mail_unread");
|
|
btnTabs[1].transform.Find("txt").GetComponent<TextMeshProUGUI>().text = LocalizationText.GetText("mail_read");
|
|
|
|
btnGetAll.transform.Find("txt").GetComponent<TextMeshProUGUI>().text = LocalizationText.GetText("all_getall");
|
|
txtMailEmpty = trfcanvas.Find("txtEmpty").GetComponent<TextMeshProUGUI>();
|
|
trfcanvas.Find("txtDesc1").GetComponent<TextMeshProUGUI>().text = LocalizationText.GetText("mail_msgcnt");
|
|
txtMailDesc = trfcanvas.Find("txtDesc2").GetComponent<TextMeshProUGUI>();
|
|
|
|
// 읽지 않은 우편.
|
|
if (iSelectedTab == 0)
|
|
{
|
|
txtMailEmpty.text = LocalizationText.GetText("mail_unreadempty");
|
|
txtMailDesc.text = LocalizationText.GetText("mail_msgunread");
|
|
}
|
|
// 읽은 우편.
|
|
else
|
|
{
|
|
txtMailEmpty.text = LocalizationText.GetText("mail_readempty");
|
|
txtMailDesc.text = LocalizationText.GetText("mail_msgread");
|
|
}
|
|
}
|
|
}
|
|
|
|
// 설정에서 언어 변경 시 처리.
|
|
public static void SReLocalize()
|
|
{
|
|
curMgr.Localize(true);
|
|
curMgr.bReLocalize = true;
|
|
curMgr.bReLocalizeMail = true;
|
|
}
|
|
|
|
// 백버튼 처리.
|
|
public static bool SCloseMenu()
|
|
{
|
|
return curMgr.CloseMenu();
|
|
}
|
|
|
|
private bool CloseMenu()
|
|
{
|
|
// 게임 시작 후 열린적 없음.
|
|
if (iSelectedTab < 0)
|
|
return false;
|
|
|
|
if (canvasUI.enabled)
|
|
{
|
|
CloseMail();
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
private void Awake()
|
|
{
|
|
curMgr = this;
|
|
}
|
|
|
|
void Start()
|
|
{
|
|
iLoading--;
|
|
}
|
|
#endregion Base
|
|
|
|
#region UI
|
|
// 우편함 열기.
|
|
public void OpenMail()
|
|
{
|
|
GameUIMgr.SAllOffDownMenu();
|
|
|
|
if (iLoading > 0)
|
|
return;
|
|
iLoading++;
|
|
|
|
if (bReLocalize)
|
|
Localize(false);
|
|
if (iSelectedTab < 0)
|
|
{
|
|
mails = new EnhancedUI.SmallList<int>();
|
|
reads = new EnhancedUI.SmallList<int>();
|
|
escrMail.LoadDatas(mails);
|
|
|
|
TabPress(0);
|
|
}
|
|
else if (iSelectedTab == 0)
|
|
{
|
|
// 우편 목록 갱신.
|
|
if (!RefreshMailList())
|
|
{
|
|
RemoveLimitOverMail();
|
|
UpdateMailList(false);
|
|
}
|
|
}
|
|
|
|
if (bReLocalizeMail)
|
|
{
|
|
bReLocalizeMail = false;
|
|
escrMail.Localize();
|
|
escrMail.scroller.RefreshActiveCellViews();
|
|
}
|
|
canvasUI.enabled = true;
|
|
|
|
SoundMgr.Instance.PlaySfx(SoundName.BtnPress);
|
|
|
|
iLoading--;
|
|
}
|
|
|
|
// 우편함 닫기.
|
|
public void CloseMail()
|
|
{
|
|
if (!canvasUI.enabled)
|
|
return;
|
|
if (iLoading > 0)
|
|
return;
|
|
iLoading++;
|
|
|
|
canvasUI.enabled = false;
|
|
|
|
SoundMgr.Instance.PlaySfx(SoundName.BtnPress);
|
|
|
|
iLoading--;
|
|
}
|
|
|
|
// 닫힌 우편 아이콘.
|
|
public static Sprite SGetIconClose()
|
|
{
|
|
return curMgr.sprLetterClose;
|
|
}
|
|
|
|
// 열린 우편 아이콘.
|
|
public static Sprite SGetIconOpen()
|
|
{
|
|
return curMgr.sprLetterOpen;
|
|
}
|
|
#endregion UI
|
|
|
|
#region Tab
|
|
public void TabPress(int index)
|
|
{
|
|
if (iSelectedTab == index)
|
|
return;
|
|
iLoading++;
|
|
|
|
if (iSelectedTab >= 0)
|
|
{
|
|
btnTabs[iSelectedTab].interactable = true;
|
|
}
|
|
iSelectedTab = index;
|
|
btnTabs[iSelectedTab].interactable = false;
|
|
|
|
// 읽지 않은 우편.
|
|
if (iSelectedTab == 0)
|
|
{
|
|
iSvType = 0;
|
|
escrMail.SetType(iSvType);
|
|
txtMailEmpty.text = LocalizationText.GetText("mail_unreadempty");
|
|
txtMailDesc.text = LocalizationText.GetText("mail_msgunread");
|
|
btnGetAll.gameObject.SetActive(true);
|
|
escrMail.LoadDatas(mails);
|
|
|
|
if (!RefreshMailList())
|
|
{
|
|
RemoveLimitOverMail();
|
|
UpdateMailList(false);
|
|
}
|
|
}
|
|
// 읽은 우편.
|
|
else
|
|
{
|
|
iSvType = 1;
|
|
escrMail.SetType(iSvType);
|
|
txtMailEmpty.text = LocalizationText.GetText("mail_readempty");
|
|
txtMailDesc.text = LocalizationText.GetText("mail_msgread");
|
|
btnGetAll.gameObject.SetActive(false);
|
|
|
|
if (!RefreshReadList())
|
|
{
|
|
UpdateReadList();
|
|
}
|
|
}
|
|
|
|
SoundMgr.Instance.PlaySfx(SoundName.BtnPress);
|
|
|
|
iLoading--;
|
|
}
|
|
#endregion Tab
|
|
|
|
#region Read List
|
|
// 우편 내역 표시 갱신.
|
|
private void UpdateReadList()
|
|
{
|
|
int ilen = DataHandler.GetMailReads().Length;
|
|
txtMailEmpty.gameObject.SetActive(ilen == 0);
|
|
|
|
while (ilen < reads.Count)
|
|
{
|
|
reads.RemoveEnd();
|
|
}
|
|
while (ilen > reads.Count)
|
|
{
|
|
reads.Add(reads.Count);
|
|
}
|
|
escrMail.LoadDatas(reads);
|
|
}
|
|
|
|
// 우편 내역 갱신.
|
|
private bool RefreshReadList()
|
|
{
|
|
if (DataHandler.MailReadRefreshTime > TimeUtils.Now())
|
|
return false;
|
|
iMailLoading++;
|
|
CoverCamera.Hold();
|
|
SvConnectManager.Instance.RequestSvGet(true, 0, UrlApi.GetUrl(UrlApi.MailReadList), typeof(nMailRefreshReturn), AReadRefreshSucc, AReadRefreshFail, false);
|
|
return true;
|
|
}
|
|
|
|
// 통신 성공 - 우편 내역 갱신.
|
|
private void AReadRefreshSucc(object result)
|
|
{
|
|
nMailRefreshReturn data = result as nMailRefreshReturn;
|
|
if (data == null || data.playMail == null)
|
|
{
|
|
AReadRefreshFail(new SvError(eErrorCode.NULL_OR_EMPTY));
|
|
return;
|
|
}
|
|
DataHandler.LoadMailRead(data.playMail, true);
|
|
|
|
bUpdateMail = true;
|
|
UpdateReadList();
|
|
|
|
CoverCamera.Release();
|
|
iMailLoading--;
|
|
}
|
|
|
|
// 통신 실패 - 우편 내역 갱신.
|
|
private void AReadRefreshFail(SvError error)
|
|
{
|
|
CoverCamera.Release();
|
|
iMailLoading--;
|
|
}
|
|
#endregion Read List
|
|
|
|
#region Mail List
|
|
// 우편 목록 표시 갱신.
|
|
private void UpdateMailList(bool bstaypos)
|
|
{
|
|
int ilen = DataHandler.GetMails().Length;
|
|
txtMailEmpty.gameObject.SetActive(ilen == 0);
|
|
if (!bUpdateMail)
|
|
{
|
|
escrMail.scroller.RefreshActiveCellViews();
|
|
return;
|
|
}
|
|
bUpdateMail = false;
|
|
|
|
while (ilen < mails.Count)
|
|
{
|
|
mails.RemoveEnd();
|
|
}
|
|
while (ilen > mails.Count)
|
|
{
|
|
mails.Add(mails.Count);
|
|
}
|
|
|
|
if (bstaypos && escrMail.scroller.ScrollSize != 0)
|
|
escrMail.scroller.ReloadData(escrMail.scroller.ScrollPosition / escrMail.scroller.ScrollSize);
|
|
else
|
|
escrMail.scroller.ReloadData();
|
|
}
|
|
|
|
// 우편 수 갱신.
|
|
public static void SSetBadgeAndRecieveAllButton()
|
|
{
|
|
curMgr.goMainBadge.SetActive(DataHandler.MailCount > 0);
|
|
curMgr.goUpBadge.SetActive(curMgr.goMainBadge.activeSelf);
|
|
curMgr.btnGetAll.interactable = curMgr.goMainBadge.activeSelf;
|
|
}
|
|
|
|
// 우편 수 임의 갱신. 상점 아이템 구매 후 등 수령할 우편이 생기면 호출.
|
|
public static void SAddMailCount()
|
|
{
|
|
DataHandler.SetMailCount(DataHandler.MailCount + 1);
|
|
curMgr.goMainBadge.SetActive(true);
|
|
curMgr.goUpBadge.SetActive(curMgr.goMainBadge.activeSelf);
|
|
curMgr.btnGetAll.interactable = true;
|
|
}
|
|
#endregion Mail List
|
|
|
|
#region Mail Limit Remove & List Reload
|
|
// 만료 우편 수동 제거.
|
|
private void RemoveLimitOverMail()
|
|
{
|
|
int iover = 0;
|
|
dMail[] curmails = DataHandler.GetMails();
|
|
for (int i = 0; i < curmails.Length; i++)
|
|
{
|
|
if (curmails[i].endAt <= TimeUtils.Now())
|
|
{
|
|
iover++;
|
|
}
|
|
}
|
|
if (iover == 0)
|
|
return;
|
|
|
|
bUpdateMail = true;
|
|
int curindex = 0;
|
|
dMail[] mails = new dMail[curmails.Length - iover];
|
|
for (int i = 0; i < curmails.Length; i++)
|
|
{
|
|
if (curindex >= mails.Length)
|
|
break;
|
|
if (curmails[i].endAt <= TimeUtils.Now())
|
|
continue;
|
|
mails[curindex] = curmails[i];
|
|
curindex++;
|
|
}
|
|
DataHandler.LoadMail(mails, true, false);
|
|
}
|
|
|
|
// 우편 목록 갱신.
|
|
private bool RefreshMailList()
|
|
{
|
|
if (DataHandler.MailRefreshTime > TimeUtils.Now())
|
|
return false;
|
|
iMailLoading++;
|
|
CoverCamera.Hold();
|
|
SvConnectManager.Instance.RequestSvGet(true, 0, UrlApi.GetUrl(UrlApi.MailList), typeof(nMailRefreshReturn), AMailRefreshSucc, AMailRefreshFail, false);
|
|
return true;
|
|
}
|
|
|
|
// 통신 성공 - 우편 목록 갱신.
|
|
private void AMailRefreshSucc(object result)
|
|
{
|
|
nMailRefreshReturn data = result as nMailRefreshReturn;
|
|
if (data == null || data.playMail == null)
|
|
{
|
|
AMailRefreshFail(new SvError(eErrorCode.NULL_OR_EMPTY));
|
|
return;
|
|
}
|
|
DataHandler.LoadMail(data.playMail, true, true);
|
|
|
|
bUpdateMail = true;
|
|
UpdateMailList(false);
|
|
DataHandler.SetMailCount(data.playMail.Length);
|
|
SSetBadgeAndRecieveAllButton();
|
|
|
|
CoverCamera.Release();
|
|
iMailLoading--;
|
|
}
|
|
|
|
// 통신 실패 - 우편 목록 갱신.
|
|
private void AMailRefreshFail(SvError error)
|
|
{
|
|
CoverCamera.Release();
|
|
iMailLoading--;
|
|
}
|
|
#endregion Mail Limit Remove & List Reload
|
|
|
|
#region Get
|
|
public static void SGetMailItem(int index)
|
|
{
|
|
if (curMgr != null)
|
|
curMgr.GetMailItem(index);
|
|
}
|
|
|
|
// 우편 아이템 획득.
|
|
private void GetMailItem(int index)
|
|
{
|
|
if (iMailLoading > 0)
|
|
return;
|
|
dMail mail = DataHandler.GetMailByIndex(index);
|
|
if (mail == null || mail.endAt <= TimeUtils.Now())
|
|
{
|
|
RemoveLimitOverMail();
|
|
UpdateMailList(true);
|
|
return;
|
|
}
|
|
|
|
iMailLoading++;
|
|
CoverCamera.Hold();
|
|
SvConnectManager.Instance.RequestSvPost(true, 0, UrlApi.GetUrl(UrlApi.MailReadOne), typeof(nMailGetReturn), AMailGetSucc, AMailGetFail, new nIdStr(mail.id), false);
|
|
}
|
|
|
|
// 통신 실패 - 우편 아이템 획득.
|
|
private void AMailGetFail(SvError error, object request)
|
|
{
|
|
CoverCamera.Release();
|
|
iMailLoading--;
|
|
}
|
|
|
|
// 통신 성공 - 우편 아이템 획득.
|
|
private void AMailGetSucc(object result, object request)
|
|
{
|
|
nMailGetReturn data = result as nMailGetReturn;
|
|
if (data == null || data.playCurrency == null || data.playMail == null)
|
|
{
|
|
AMailGetFail(new SvError(eErrorCode.NULL_OR_EMPTY), request);
|
|
return;
|
|
}
|
|
|
|
DataHandler.AddGoods(data.result, data.playCurrency, true);
|
|
DataHandler.SaveData();
|
|
DataHandler.LoadMail(data.playMail, true, true);
|
|
|
|
GameUIMgr.SOpenPopupGoods(data.result, null, LocalizationText.GetText("mail_get"));
|
|
bUpdateMail = true;
|
|
UpdateMailList(true);
|
|
DataHandler.UpdateMailReadTime();
|
|
DataHandler.SetMailCount(data.playMail.Length);
|
|
SSetBadgeAndRecieveAllButton();
|
|
|
|
CoverCamera.Release();
|
|
iMailLoading--;
|
|
}
|
|
|
|
public void BtnGetAll()
|
|
{
|
|
if (iMailLoading > 0)
|
|
return;
|
|
iMailLoading++;
|
|
CoverCamera.Hold();
|
|
|
|
dMail[] curmails = DataHandler.GetMails();
|
|
int icnt = 0;
|
|
for (int i = 0; i < curmails.Length; i++)
|
|
{
|
|
if (curmails[i] == null || curmails[i].endAt <= TimeUtils.Now())
|
|
continue;
|
|
icnt++;
|
|
}
|
|
|
|
if (icnt == 0)
|
|
{
|
|
GameUIMgr.SOpenPopup1Button(LocalizationText.GetText("msg_nomail"));
|
|
CoverCamera.Release();
|
|
iMailLoading--;
|
|
return;
|
|
}
|
|
SoundMgr.Instance.PlaySfx(SoundName.BtnPress);
|
|
|
|
SvConnectManager.Instance.RequestSvPost(true, 0, UrlApi.GetUrl(UrlApi.MailReadAll), typeof(nMailGetReturn), AMailGetAllSucc, AMailGetAllFail, new nIdCnt(), false);
|
|
}
|
|
|
|
// 통신 실패 - 전체 아이템 획득.
|
|
private void AMailGetAllFail(SvError error, object request)
|
|
{
|
|
CoverCamera.Release();
|
|
iMailLoading--;
|
|
}
|
|
|
|
// 통신 성공 - 전체 아이템 획득.
|
|
private void AMailGetAllSucc(object result, object request)
|
|
{
|
|
nMailGetReturn data = result as nMailGetReturn;
|
|
nIdlLv requestdata = request as nIdlLv;
|
|
if (data == null || data.playCurrency == null || data.playMail == null)
|
|
{
|
|
AMailGetAllFail(new SvError(eErrorCode.NULL_OR_EMPTY), request);
|
|
return;
|
|
}
|
|
|
|
DataHandler.AddGoods(data.result, data.playCurrency, true);
|
|
DataHandler.SaveData();
|
|
DataHandler.LoadMail(data.playMail, true, true);
|
|
|
|
GameUIMgr.SOpenPopupGoods(data.result, null, LocalizationText.GetText("mail_get"));
|
|
bUpdateMail = true;
|
|
UpdateMailList(true);
|
|
DataHandler.UpdateMailReadTime();
|
|
DataHandler.SetMailCount(data.playMail.Length);
|
|
SSetBadgeAndRecieveAllButton();
|
|
|
|
CoverCamera.Release();
|
|
iMailLoading--;
|
|
}
|
|
#endregion Get
|
|
}
|