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.
 
 
 
 
 
 

1228 lines
37 KiB

using DG.Tweening;
using IVDataFormat;
using IVServerFormat;
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.ResourceManagement.AsyncOperations;
using UnityEngine.U2D;
using UnityEngine.UI;
public class ShopMgr : MonoBehaviour
{
#region Const
//private static readonly Vector2 V2_RewPosUp = new Vector2(0f, 16f);
private static ShopMgr curMgr = null;
#endregion Const
#region UI
[Header("UI")]
[SerializeField]
private TextMeshProUGUI txtMainT;
[SerializeField]
private Canvas canvasUI;
private ButtonIV[] btnTabs;
private TextMeshProUGUI txtTime;
private RectTransform rtrfTime;
private GameObject groupItem, groupCos, groupPack;
private GameObject goRefund;
[SerializeField]
private EScrController escrItem, escrCos, escrPack;
#endregion UI
#region Pack Info
[Header("Pack Info")]
[SerializeField]
private Canvas canvasPackInfo;
private Image imgPack;
private TextMeshProUGUI txtPackName, txtPackLimit, txtPackPrice;
private GameObject[] goPackItems;
private GameObject[] goPackEffects;
private RectTransform[] rtrfPackItems;
private GoodsItem[] goodsPacks;
private TextMeshProUGUI[] txtPackNames, txtPackCounts, txtPackEffects;
#endregion Pack Info
#region Variables
private int iLoading = 1;
private bool bReLocalize = true;
private bool bReLocalizeCos = true;
private bool bInitNeed = true;
private int iMoveToTab = -1;
private int iSelectedTab = -1;
private eShopType selectedType = eShopType.None;
private bool bRefreshNeed = false;
private System.DateTime dtEventLimit;
private EnhancedUI.SmallList<int> itemRows, cosRows, packList;
private int iSelectedCount = 1;
private dShop selectedData = null;
private AsyncOperationHandle<SpriteAtlas> handleAtlas;
public static SpriteAtlas shopImgs = null;
private Sequence seqTime = null;
//GameObject dust;
private GameObject popUp;
private TextMeshProUGUI popMsg,popTitle,popYesText;
private int iShineMode = -1;
#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("shop_title");
}
else
{
bReLocalize = false;
Transform trfui = canvasUI.transform;
trfui.Find("txtT").GetComponent<TextMeshProUGUI>().text = LocalizationText.GetText("shop_title");
for (int i = 0; i < btnTabs.Length; i++)
btnTabs[i].transform.Find("txt").GetComponent<TextMeshProUGUI>().text = LocalizationText.GetText(FormatString.CombineAllString("shoptype", i.ToString()));
goRefund.transform.GetComponent<TextMeshProUGUI>().text = LocalizationText.GetText("shop_refund1");
goRefund.transform.GetChild(0).GetChild(0).GetComponent<TextMeshProUGUI>().text = LocalizationText.GetText("all_see");
Transform trfpack = canvasPackInfo.transform;
trfpack.Find("txtT").GetComponent<TextMeshProUGUI>().text = LocalizationText.GetText("shopdetail");
trfpack.Find("txtRewardT").GetComponent<TextMeshProUGUI>().text = LocalizationText.GetText("shopdetailrew");
trfpack.Find("txtBuyTip").GetComponent<TextMeshProUGUI>().text = LocalizationText.GetText("shop_refund1");
//dust = canvasUI.transform.Find("all_dust").gameObject;
popUp = trfui.Find("popup1Button").gameObject;
popMsg = popUp.transform.Find("txtMsg").GetComponent<TextMeshProUGUI>();
popTitle = popUp.transform.Find("txtTitle").GetComponent<TextMeshProUGUI>();
popTitle.text = LocalizationText.GetText("all_confirm");
popYesText = popUp.transform.Find("btnYes").transform.Find("txt").GetComponent<TextMeshProUGUI>();
popYesText.text = LocalizationText.GetText("all_confirm");
}
}
// 설정에서 언어 변경 시 처리.
public static void SReLocalize()
{
curMgr.Localize(true);
curMgr.bReLocalize = true;
curMgr.bReLocalizeCos = true;
}
// 백버튼 처리.
public static bool SCloseMenu()
{
return curMgr.CloseMenu();
}
private bool CloseMenu()
{
// 게임 시작 후 열린적 없음.
if (bInitNeed)
return false;
// 패키지 정보 팝업.
if (canvasPackInfo.enabled)
{
ClosePackInfo();
return true;
}
if (canvasUI.enabled)
{
CloseShop();
return true;
}
return false;
}
private void Awake()
{
curMgr = this;
}
void Start()
{
iLoading--;
}
private void Init()
{
if (DataHandler.GetShopGroup(eShopType.Event).Count > 0)
dtEventLimit = DataHandler.GetShopByIndex(eShopType.Event, 0).endAt;
else
dtEventLimit = System.DateTime.MinValue;
Transform trfui = canvasUI.transform;
btnTabs = trfui.Find("tabWrapLeft").GetComponentsInChildren<ButtonIV>(true);
txtTime = trfui.Find("txtTime").GetComponent<TextMeshProUGUI>();
rtrfTime = txtTime.transform.GetChild(0).GetComponent<RectTransform>();
groupItem = trfui.Find("SvItem").gameObject;
groupCos = trfui.Find("SvCos").gameObject;
groupPack = trfui.Find("SvPack").gameObject;
goRefund = trfui.Find("txtBuyTip").gameObject;
Transform trfpack = canvasPackInfo.transform;
txtPackPrice = trfpack.Find("btnBuy").GetChild(0).GetComponent<TextMeshProUGUI>();
Transform trfpackitem = trfpack.Find("PackItem");
imgPack = trfpackitem.Find("reward").Find("img").GetComponent<Image>();
txtPackName = trfpackitem.Find("txtName").GetComponent<TextMeshProUGUI>();
txtPackLimit = trfpackitem.Find("txtLimit").GetComponent<TextMeshProUGUI>();
Transform trfpackrew = trfpack.Find("SvReward").GetChild(0);
int ilen = trfpackrew.childCount;
goPackItems = new GameObject[ilen];
goPackEffects = new GameObject[ilen];
rtrfPackItems = new RectTransform[ilen];
goodsPacks = new GoodsItem[ilen];
txtPackNames = new TextMeshProUGUI[ilen];
txtPackCounts = new TextMeshProUGUI[ilen];
txtPackEffects = new TextMeshProUGUI[ilen];
for (int i = 0; i < ilen; i++)
{
Transform trfitem = trfpackrew.GetChild(i);
goPackItems[i] = trfitem.gameObject;
goPackEffects[i] = trfitem.Find("effect").gameObject;
rtrfPackItems[i] = trfitem.Find("item").GetComponent<RectTransform>();
goodsPacks[i] = rtrfPackItems[i].GetChild(0).GetComponent<GoodsItem>();
txtPackNames[i] = rtrfPackItems[i].GetChild(1).GetComponent<TextMeshProUGUI>();
txtPackCounts[i] = rtrfPackItems[i].GetChild(2).GetComponent<TextMeshProUGUI>();
txtPackEffects[i] = goPackEffects[i].transform.GetChild(0).GetComponent<TextMeshProUGUI>();
}
}
#endregion Base
#region UI
public static bool SOpenShopEvent()
{
if (curMgr.iLoading > 0)
return false;
curMgr.iMoveToTab = 0;
curMgr.OpenShop();
return true;
}
public static bool SOpenShopSpecial()
{
if (curMgr.iLoading > 0)
return false;
curMgr.iMoveToTab = 1;
curMgr.OpenShop();
return true;
}
public void OpenShop()
{
if (iLoading > 0)
return;
iLoading++;
if (bInitNeed)
{
bInitNeed = false;
Init();
}
if (bReLocalize)
Localize(false);
// 상점 창 열때 아틀라스 불러오기.
CoverCamera.Hold();
Addressables.LoadAssetAsync<SpriteAtlas>("atlasShopIcon").Completed += ALoadAtlasComp;
//dust.SetActive(true);
SoundMgr.Instance.PlaySfx(SoundName.BtnPress);
iLoading--;
}
public void OpenShopComp()
{
// 이벤트 아이템 존재 여부에 따라서 버튼 표시.
btnTabs[0].gameObject.SetActive(dtEventLimit > TimeUtils.Now());
if (iMoveToTab < 0)
iMoveToTab = 0;
if (iMoveToTab == 0 && !btnTabs[0].gameObject.activeSelf)
iMoveToTab = 1;
if (iMoveToTab != iSelectedTab)
{
TabShop(iMoveToTab);
}
else
{
bRefreshNeed = selectedType == eShopType.Event;
SetSeqTime(false, bRefreshNeed);
RefreshList();
}
canvasUI.enabled = true;
GameUIMgr.SRightWindowClose();
GameUIMgr.SOpenUpPanel(isUp: true, dia: true, mileage: true, mail: true);
GameUIMgr.SSetMainUiOn(false);
BattleMgr.SSetBattleUiOn(false);
BattleMgr.SSetClearFailUiOn(false);
BattleMgr.Instance.SetCameraOn(false);
}
public void CloseShop()
{
if (!canvasUI.enabled)
return;
if (iLoading > 0)
return;
iLoading++;
CoverCamera.Hold();
SetSeqTime(bRefreshNeed, false);
bRefreshNeed = false;
canvasUI.enabled = false;
GameUIMgr.SCloseUpPanel();
GameUIMgr.SSetMainUiOn(true);
BattleMgr.SSetBattleUiOn(true);
BattleMgr.SSetClearFailUiOn(true);
BattleMgr.Instance.SetCameraOn(true);
// 상점 창 닫을때 리소스 해제.
escrPack.ReleaseResources();
escrItem.ReleaseResources();
shopImgs = null;
if (handleAtlas.IsValid())
{
Addressables.Release(handleAtlas);
AddressableMgr.SAddUnload();
}
CoverCamera.Release();
//dust.SetActive(false);
SoundMgr.Instance.PlaySfx(SoundName.BtnPress);
iLoading--;
}
// 시계 연출.
private void SetSeqTime(bool bprev, bool bnext)
{
if (bprev == bnext)
return;
if (bprev)
{
if (bRefreshNeed)
seqTime.Kill();
}
else
{
Vector3 v3left = new Vector3(0f, 0f, 5f);
Vector3 v3right = new Vector3(0f, 0f, -5f);
seqTime = DOTween.Sequence()
.SetUpdate(true)
.Append(rtrfTime.DOLocalRotate(v3right, 0.05f))
.Append(rtrfTime.DOLocalRotate(v3left, 0.1f))
.Append(rtrfTime.DOLocalRotate(v3right, 0.1f))
.Append(rtrfTime.DOLocalRotate(v3left, 0.1f))
.Append(rtrfTime.DOLocalRotate(v3right, 0.1f))
.Append(rtrfTime.DOLocalRotate(v3left, 0.1f))
.Append(rtrfTime.DOLocalRotate(v3right, 0.1f))
.Append(rtrfTime.DOLocalRotate(v3left, 0.1f))
.Append(rtrfTime.DOLocalRotate(Vector3.zero, 0.05f))
.AppendInterval(1.5f)
.SetLoops(-1)
.Play();
}
}
// 상점 이미지 가져오기
public static Sprite SGetShopImg(string strpath)
{
if (shopImgs == null)
return null;
return shopImgs.GetSprite(strpath);
}
// 어드레서블 상점 이미지 불러왔을때 처리.
private void ALoadAtlasComp(AsyncOperationHandle<SpriteAtlas> obj)
{
shopImgs = obj.Result;
handleAtlas = obj;
OpenShopComp();
CoverCamera.Release();
}
#endregion UI
#region Tab
// 탭.
public void TabShop(int index)
{
if (iSelectedTab == index)
return;
if (iSelectedTab >= 0)
{
btnTabs[iSelectedTab].interactable = true;
}
iMoveToTab = index;
iSelectedTab = index;
selectedType = (eShopType)iSelectedTab;
btnTabs[iSelectedTab].interactable = false;
ReloadList();
ReloadShineEffect();
// 이벤트 탭일 경우 남은 시간 표시.
SetSeqTime(bRefreshNeed, selectedType == eShopType.Event);
bRefreshNeed = selectedType == eShopType.Event;
if (bRefreshNeed)
{
txtTime.text = FormatString.TextLeftTimeDHMS(dtEventLimit);
txtTime.gameObject.SetActive(true);
}
else
{
txtTime.gameObject.SetActive(false);
}
SoundMgr.Instance.PlaySfx(SoundName.BtnPress);
}
// 탭 전환 시 반짝이는 연출 재생.
private void ReloadShineEffect()
{
switch (selectedType)
{
case eShopType.Event:
case eShopType.SpecialPack:
if (iShineMode == 1)
{
StopCoroutine("CoShineEffect");
escrItem.SetFloat(1f);
}
if (iShineMode != 0)
{
iShineMode = 0;
StartCoroutine("CoShineEffect");
}
break;
case eShopType.Dia:
case eShopType.General:
case eShopType.Mileage:
if (iShineMode == 0)
{
StopCoroutine("CoShineEffect");
escrPack.SetFloat(1f);
}
if (iShineMode != 1)
{
iShineMode = 1;
StartCoroutine("CoShineEffect");
}
break;
default:
if (iShineMode >= 0)
{
StopCoroutine("CoShineEffect");
escrPack.SetFloat(1f);
escrItem.SetFloat(1f);
iShineMode = -1;
}
break;
}
}
// 반짝이는 연출.
private IEnumerator CoShineEffect()
{
float fvalue = 1f;
// 이벤트, 특별 패키지.
if (iShineMode == 0)
{
while (true)
{
escrPack.SetFloat(fvalue);
yield return YieldInstructionCache.WaitForSeconds(0.05f);
fvalue -= 0.08f;
if (fvalue < 0f)
{
fvalue = 1f;
yield return YieldInstructionCache.WaitForSeconds(3f);
}
}
}
// 보석, 일반, 마일리지.
else
{
while (true)
{
escrItem.SetFloat(fvalue);
yield return YieldInstructionCache.WaitForSeconds(0.05f);
fvalue -= 0.08f;
if (fvalue < 0f)
{
fvalue = 1f;
yield return YieldInstructionCache.WaitForSeconds(3f);
}
}
}
}
// 탭 전환 시 목록 개수 체크 및 표시.
private void ReloadList()
{
int ilen = DataHandler.GetShopGroup(selectedType).Count;
switch (selectedType)
{
case eShopType.Event:
case eShopType.SpecialPack:
case eShopType.CostumePack:
groupItem.SetActive(false);
groupCos.SetActive(false);
groupPack.SetActive(true);
goRefund.SetActive(true);
if (packList == null)
{
packList = new EnhancedUI.SmallList<int>();
for (int i = 0; i < ilen; i++)
{
packList.Add(i);
}
escrPack.LoadDatas(packList);
}
else
{
while (packList.Count < ilen)
packList.Add(packList.Count);
while (packList.Count > ilen)
packList.RemoveEnd();
escrPack.scroller.ReloadData();
}
break;
case eShopType.Dia:
case eShopType.General:
case eShopType.Mileage:
groupItem.SetActive(true);
groupCos.SetActive(false);
groupPack.SetActive(false);
goRefund.SetActive(selectedType == eShopType.Dia);
// 아이템이 8개를 초과하면 2행으로 나누어 표시.
if (ilen > 8)
ilen = (ilen + 1) / 2;
// 아이템이 5~8개면 4줄로 고정.
else if (ilen > 4)
ilen = 4;
// 그 외에는 무조건 1번째 줄에 전부 다 표시.
if (itemRows == null)
{
itemRows = new EnhancedUI.SmallList<int>();
for (int i = 0; i < ilen; i++)
{
itemRows.Add(i);
}
escrItem.LoadDatas(itemRows);
}
else
{
while (itemRows.Count < ilen)
itemRows.Add(itemRows.Count);
while (itemRows.Count > ilen)
itemRows.RemoveEnd();
escrItem.scroller.ReloadData();
}
break;
case eShopType.CostumeCloth:
case eShopType.CostumeWeapon:
groupItem.SetActive(false);
groupCos.SetActive(true);
groupPack.SetActive(false);
goRefund.SetActive(false);
// 아이템이 4개를 초과하면 2행으로 나누어 표시.
if (ilen > 4)
ilen = (ilen + 1) / 2;
// 아이템이 3~4개면 2줄로 고정.
else if (ilen > 2)
ilen = 2;
// 그 외에는 무조건 1번째 줄에 전부 다 표시.
if (cosRows == null)
{
cosRows = new EnhancedUI.SmallList<int>();
for (int i = 0; i < ilen; i++)
{
cosRows.Add(i);
}
escrCos.LoadDatas(cosRows);
}
else
{
while (cosRows.Count < ilen)
cosRows.Add(cosRows.Count);
while (cosRows.Count > ilen)
cosRows.RemoveEnd();
escrCos.scroller.ReloadData();
}
if (bReLocalizeCos)
escrCos.Localize();
break;
}
}
// 목록 새로고침.
private void RefreshList()
{
switch (selectedType)
{
case eShopType.Event:
case eShopType.SpecialPack:
case eShopType.CostumePack:
escrPack.scroller.RefreshActiveCellViews();
break;
case eShopType.Dia:
case eShopType.General:
case eShopType.Mileage:
escrItem.scroller.RefreshActiveCellViews();
break;
case eShopType.CostumeCloth:
case eShopType.CostumeWeapon:
escrCos.scroller.RefreshActiveCellViews();
if (bReLocalizeCos)
escrCos.Localize();
break;
}
}
#endregion Tab
#region Get Item
public static int SSGetPackKey(int index)
{
return curMgr.GetPackKey(index);
}
bool isAdBanner = false;
public static int SSGetSpecialGetPackKey()
{
curMgr.selectedType = eShopType.SpecialPack;
curMgr.isAdBanner = true;
return curMgr.GetPackKey(0);
}
// 패키지 키 가져오기.
private int GetPackKey(int index)
{
List<dShop> idlist = DataHandler.GetShopGroup(selectedType);
if (index >= idlist.Count)
return -1;
return idlist[index].id;
}
public static int SSGetItemKey(int icolumn, int irow)
{
return curMgr.GetItemKey(icolumn, irow);
}
// 아이템 키 가져오기.
private int GetItemKey(int icolumn, int irow)
{
List<dShop> idlist = DataHandler.GetShopGroup(selectedType);
int index = irow * itemRows.Count + icolumn;
if (index >= idlist.Count)
return -1;
return idlist[index].id;
}
public static int SSGetCosKey(int icolumn, int irow)
{
return curMgr.GetCosKey(icolumn, irow);
}
// 의상/무기 키 가져오기.
private int GetCosKey(int icolumn, int irow)
{
List<dShop> idlist = DataHandler.GetShopGroup(selectedType);
int index = irow * cosRows.Count + icolumn;
if (index >= idlist.Count)
return -1;
return idlist[index].id;
}
#endregion Get Item
#region Refresh
public static void SUpdateOneSec()
{
if (curMgr != null)
curMgr.UpdateOneSec();
}
// 초당 갱신.
private void UpdateOneSec()
{
// 상점 창이 열려있으며, 이벤트 탭일 경우.
if (bRefreshNeed)
txtTime.text = FormatString.TextLeftTimeDHMS(dtEventLimit);
}
public static void SResetShop()
{
if (curMgr != null)
curMgr.ResetShop();
}
// 상점 갱신.
private void ResetShop()
{
// 상점 창이 열려있지 않은 경우.
if (bInitNeed || !canvasUI.enabled)
{
return;
}
iLoading++;
// 이벤트 아이템 존재 여부에 따라서 버튼 표시.
btnTabs[0].gameObject.SetActive(dtEventLimit > TimeUtils.Now());
if (iSelectedTab == 0 && !btnTabs[0].gameObject.activeSelf)
TabShop(1);
else
RefreshList();
iLoading--;
}
#endregion Refresh
#region Pack Info
public static void SOpenPackInfo(int key)
{
curMgr.OpenPackInfo(key);
}
bool isCostume = false;
// 패키지 정보 팝업 열기.
private void OpenPackInfo(int key)
{
if (iLoading > 0)
return;
iLoading++;
selectedData = DataHandler.GetShop(key);
if (selectedData == null)
{
iLoading--;
return;
}
// 구매 불가 아이템.
if (selectedData.endAt <= TimeUtils.Now())
{
OpenTap1PopUp(LocalizationText.GetText("error_nobuyshop"));
iLoading--;
return;
}
isCostume = false;
// 상품 이미지, 이름, 가격 표시.
imgPack.sprite = SGetShopImg(selectedData.path);
imgPack.SetNativeSize();
txtPackName.text = LocalizationText.GetText(FormatString.CombineAllString("shop", key.ToString()));
txtPackPrice.text = DataHandler.GetShopPrice(key, 1);
// 구매 제한 텍스트 표시.
if (selectedData.refreshType == eRefreshType.None)
{
txtPackLimit.enabled = false;
}
else
{
txtPackLimit.enabled = true;
txtPackLimit.text = FormatString.TextShopLimit(selectedData.refreshType, selectedData.refreshValue, selectedData.limitCnt - selectedData.buyCnt, selectedData.limitCnt);
}
// 구성품 표시.
for (int k = 0; k < goPackItems.Length; k++)
{
if (k >= selectedData.rewards.Length)
{
goPackItems[k].SetActive(false);
continue;
}
nReward reward = selectedData.rewards[k];
goodsPacks[k].SetGoods(reward.rewardType, reward.rewardId, reward.rewardCount);
txtPackNames[k].text = FormatString.GetGoodsName(reward.rewardType, reward.rewardId);
if (reward.rewardType == cGoods.TAdsRemove)
txtPackCounts[k].gameObject.SetActive(false);
else
txtPackCounts[k].gameObject.SetActive(true);
txtPackCounts[k].text = FormatString.TextInt(reward.rewardCount);
if (reward.rewardType == cGoods.TCosCloth)
{
dCostume costume = DataHandler.GetCosCloth(reward.rewardId);
txtPackEffects[k].text = FormatString.CombineAllString(LocalizationText.GetText("own_effect_titlec"),
FormatString.TextEffectTitleValuesComma(costume.abilityType1, costume.abilityValue1, costume.abilityType2, costume.abilityValue2));
goPackEffects[k].SetActive(true);
//rtrfPackItems[k].anchoredPosition = V2_RewPosUp;
goPackItems[k].GetComponent<RectTransform>().sizeDelta = new Vector2(606,110);
isCostume = true;
}
else if (reward.rewardType == cGoods.TCosWeapon)
{
dCostume costume = DataHandler.GetCosWeapon(reward.rewardId);
txtPackEffects[k].text = FormatString.CombineAllString(LocalizationText.GetText("own_effect_titlec"),
FormatString.TextEffectTitleValuesComma(costume.abilityType1, costume.abilityValue1, costume.abilityType2, costume.abilityValue2));
goPackEffects[k].SetActive(true);
//rtrfPackItems[k].anchoredPosition = V2_RewPosUp;
goPackItems[k].GetComponent<RectTransform>().sizeDelta = new Vector2(606, 110);
isCostume = true;
}
else
{
goPackEffects[k].SetActive(false);
//rtrfPackItems[k].anchoredPosition = Vector2.zero;
goPackItems[k].GetComponent<RectTransform>().sizeDelta = new Vector2(606, 82);
}
goPackItems[k].SetActive(true);
}
if (isCostume)
{
imgPack.transform.localScale = new Vector2(0.75f, 0.75f);
}
else
{
imgPack.transform.localScale = new Vector2(1, 1);
}
canvasPackInfo.enabled = true;
SoundMgr.Instance.PlaySfx(SoundName.BtnPress);
iLoading--;
}
// 패키지 정보 팝업 닫기.
public void ClosePackInfo()
{
if (iLoading > 0)
return;
iLoading++;
canvasPackInfo.enabled = false;
imgPack.sprite = null;
selectedData = null;
SoundMgr.Instance.PlaySfx(SoundName.BtnPress);
iLoading--;
}
// 패키지 정보 팝업에서 구매.
public void BuyPackInfo()
{
TryBuy(selectedData.id);
SoundMgr.Instance.PlaySfx(SoundName.BtnPress);
}
#endregion Pack Info
#region Try Buy
public static void STryBuy(int key, Sprite sprBtn = null)
{
curMgr.TryBuy(key, sprBtn);
}
// 목록에서 구매 시도.
private void TryBuy(int key, Sprite sprBtn = null)
{
if (iLoading > 0)
return;
iLoading++;
selectedData = DataHandler.GetShop(key);
if (selectedData == null)
{
iLoading--;
return;
}
// 구매 불가 아이템.
if (selectedData.endAt <= TimeUtils.Now())
{
OpenTap1PopUp(LocalizationText.GetText("error_nobuyshop"));
iLoading--;
return;
}
SoundMgr.Instance.PlaySfx(SoundName.BtnPress);
if (selectedData.buyingType == cGoods.TCash)
{
if (string.IsNullOrEmpty(selectedData.productId))
{
iLoading--;
return;
}
// 인앱 구매 시도.
CoverCamera.Hold();
IapMgr.STryPurchase(key, selectedData.productId);
}
else if (selectedData.buyingType == cGoods.TAds)
{
// 보상형 광고 재생 시도.
CoverCamera.Hold();
//AdsMgr.SPlayRewardAds(AdsMgr.eRewardType.Shop, key);
SampleAdsMgr.ShowRewardedShopAd(AdsMgr.eRewardType.Shop, key);
}
else
{
nGoods goods = new nGoods(selectedData.rewards[0]);
iSelectedCount = 1;
int iunit = (int)selectedData.rewards[0].rewardCount;
if (selectedData.limitCnt == 1)
{
GameUIMgr.SOpenPopupItemBuy(goods, selectedData.buyingType, selectedData.buyingId, selectedData.buyingCnt,
ATryBuyItem, ACancelBuyItem, LocalizationText.GetText("shopbuyt"), LocalizationText.GetText(Global.STR_CANCEL));
}
else
{
GameUIMgr.SOpenPopupItemBuyCount(goods, selectedData.buyingType, selectedData.buyingId, selectedData.buyingCnt,
ABuyItemSub, ABuyItemAdd, ABuyItemMin, ABuyItemMax, ATryBuyItem, ACancelBuyItem, LocalizationText.GetText("shopbuyt"), LocalizationText.GetText(Global.STR_CANCEL), sprBtn: sprBtn);
GameUIMgr.SSetPopupItemBuyCount(iSelectedCount, iunit, selectedData.buyingCnt);
}
iLoading--;
}
}
// 아이템 구매 수 감소.
private void ABuyItemSub()
{
if (iLoading > 0)
return;
iLoading++;
if (iSelectedCount <= 1)
{
iLoading--;
return;
}
iSelectedCount--;
int iunit = (int)selectedData.rewards[0].rewardCount;
GameUIMgr.SSetPopupItemBuyCount(iSelectedCount, iunit, selectedData.buyingCnt);
iLoading--;
}
// 아이템 구매 수 증가.
private void ABuyItemAdd()
{
if (iLoading > 0)
return;
iLoading++;
int iunit = (int)selectedData.rewards[0].rewardCount;
int ilimitcount = selectedData.limitCnt - selectedData.buyCnt;
int imaxcount;
if (selectedData.buyingId == cGoods.CMileage)
imaxcount = DataHandler.Goods.mileage / selectedData.buyingCnt;
else
imaxcount = DataHandler.Goods.Dia / selectedData.buyingCnt;
if (ilimitcount > 0 && ilimitcount < imaxcount)
imaxcount = ilimitcount;
if (iSelectedCount >= imaxcount)
{
iLoading--;
return;
}
iSelectedCount++;
GameUIMgr.SSetPopupItemBuyCount(iSelectedCount, iunit, selectedData.buyingCnt);
iLoading--;
}
// 아이템 구매 최소.
private void ABuyItemMin()
{
if (iLoading > 0)
return;
iLoading++;
if (iSelectedCount <= 1)
{
iLoading--;
return;
}
iSelectedCount = 1;
int iunit = (int)selectedData.rewards[0].rewardCount;
GameUIMgr.SSetPopupItemBuyCount(iSelectedCount, iunit, selectedData.buyingCnt);
iLoading--;
}
// 아이템 구매 수 최대.
private void ABuyItemMax()
{
if (iLoading > 0)
return;
iLoading++;
int iunit = (int)selectedData.rewards[0].rewardCount;
int ilimitcount = selectedData.limitCnt - selectedData.buyCnt;
int imaxcount;
if (selectedData.buyingId == cGoods.CMileage)
imaxcount = DataHandler.Goods.mileage / selectedData.buyingCnt;
else
imaxcount = DataHandler.Goods.Dia / selectedData.buyingCnt;
if (ilimitcount > 0 && ilimitcount < imaxcount)
imaxcount = ilimitcount;
if (iSelectedCount >= imaxcount)
{
iLoading--;
return;
}
iSelectedCount = imaxcount;
GameUIMgr.SSetPopupItemBuyCount(iSelectedCount, iunit, selectedData.buyingCnt);
iLoading--;
}
// 아이템 구매 취소.
private void ACancelBuyItem()
{
selectedData = null;
iSelectedCount = 1;
}
// 아이템 구매.
private void ATryBuyItem()
{
if (iLoading > 0)
return;
iLoading++;
CoverCamera.Hold();
StartBuy();
}
#endregion Try Buy
#region Finish Buy
/// <summary>
/// 인앱 결제, 광고 재생 실패시 구매 실패 처리.
/// </summary>
/// <param name="key">상점 ID.</param>
/// <returns></returns>
public static void SSubProcessFail(int key)
{
if (curMgr != null)
curMgr.SubProcessFail(key);
}
private void SubProcessFail(int key)
{
if (selectedData == null || key != selectedData.id)
return;
// 패스 상품일 경우 패스 구매 실패 처리.
if (selectedData.rewards[0].rewardType == cGoods.TPass)
{
PassMgr.SFailBuyPass();
GameUIMgr.SOpenToast(LocalizationText.GetText("error_buyfail"));
}
// 광고 상품. AdsMgr에서 실패시 메시지 표시를 하므로 여기서는 아무것도 하지 않음.
else if (selectedData.buyingType == cGoods.TAds)
{
}
// 인앱 상품, 인게임 재화로 구매하는 상품. 구매 실패 메시지 표시.
else
{
GameUIMgr.SOpenToast(LocalizationText.GetText("error_buyfail"));
}
selectedData = null;
iSelectedCount = 1;
CoverCamera.Release();
iLoading--;
}
/// <summary>
/// 인앱 결제, 광고 재생 성공시 처리. 구매 통신 시작.
/// </summary>
/// <param name="key">상점 ID.</param>
/// <returns></returns>
public static void SSubProcessSucc(int key)
{
if (curMgr != null)
curMgr.SubProcessSucc(key);
}
private void SubProcessSucc(int key)
{
if (selectedData == null || key != selectedData.id)
{
selectedData = DataHandler.GetShop(key);
if (selectedData == null)
return;
iSelectedCount = 1;
iLoading++;
CoverCamera.Hold();
}
StartBuy();
}
// 구매 통신.
private void StartBuy()
{
if (selectedData == null)
{
selectedData = null;
iSelectedCount = 1;
CoverCamera.Release();
iLoading--;
return;
}
nIdBuyCnt data = new nIdBuyCnt(selectedData.id, iSelectedCount);
SvConnectManager.Instance.RequestSvPost(true, 0, UrlApi.GetUrl(UrlApi.ShopBuy), typeof(nShopBuyReturn), ABuySucc, ABuyFail, data, true);
}
// 구매 통신 실패시 처리.
private void ABuyFail(SvError error, object request)
{
if (selectedData == null)
return;
// 패스 상품일 경우 패스 구매 실패 처리.
if (selectedData.rewards[0].rewardType == cGoods.TPass)
{
PassMgr.SFailBuyPass();
}
GameUIMgr.SOpenToast(LocalizationText.GetText("error_buyfail"));
selectedData = null;
iSelectedCount = 1;
CoverCamera.Release();
iLoading--;
}
// 구매 통신 성공시 처리.
private void ABuySucc(object result, object request)
{
if (selectedData == null)
return;
nShopBuyReturn data = result as nShopBuyReturn;
if (data == null)
{
ABuyFail(new SvError(eErrorCode.NULL_OR_EMPTY), request);
return;
}
// 상점 구매 처리.
DataHandler.BuyShop(data.playShop.sid, data.playShop.buyCnt, data.playShop.totalCnt, data.playShop.refreshAt);
// 패스 상품일 경우 즉시 지급, 패스 구매 완료 처리. rewardType: 패스, rewardId: 패스 시스템 아이디, rewardCnt: 패스 페이지 번호.
if (selectedData.shopType == eShopType.Pass)
{
DataHandler.SetGoods(data.playCurrency, true);
PassMgr.SSuccBuyPass(selectedData.rewards[0].rewardId, (int)selectedData.rewards[0].rewardCount);
selectedData = null;
iSelectedCount = 1;
RefreshList();
CoverCamera.Release();
iLoading--;
return;
}
// 광고 제거 패키지. 즉시 지급, 보상 획득 UI 출력.
else if (selectedData.rewards[0].rewardType == cGoods.TAdsRemove)
{
int ilen = selectedData.rewards.Length;
nGoods[] goods = new nGoods[ilen];
for (int i = 0; i < ilen; i++)
goods[i] = new nGoods(selectedData.rewards[i]);
DataHandler.AddGoods(goods, data.playCurrency, true);
GameUIMgr.SOpenPopupGoods(goods);
AdBuffMgr.SAdBUffNoAd();
}
// 인앱 상품.
else if (selectedData.buyingType == cGoods.TCash)
{
MailMgr.SAddMailCount();
DataHandler.SetGoods(data.playCurrency, true);
OpenTap1PopUp(LocalizationText.GetText("msg_buysuccmail"));
}
// 광고 상품, 인게임 재화로 구매하는 상품. 즉시 지급, 보상 획득 UI 출력.
else
{
int ilen = selectedData.rewards.Length;
nGoods[] goods = new nGoods[ilen];
for (int i = 0; i < ilen; i++)
{
goods[i] = new nGoods(selectedData.rewards[i]);
if (iSelectedCount > 1)
goods[i].propertyCount *= iSelectedCount;
}
DataHandler.AddGoods(goods, data.playCurrency, true);
GameUIMgr.SOpenPopupGoods(goods);
}
selectedData = null;
iSelectedCount = 1;
RefreshList();
CoverCamera.Release();
iLoading--;
if(isAdBanner)
{
isAdBanner = false;
}
else
{
ClosePackInfo();
}
}
#endregion Finish Buy
private void OpenTap1PopUp(string str)
{
popUp.SetActive(true);
popMsg.text = str;
}
public void CloseTap1PopUp()
{
popUp.SetActive(false);
}
}