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.
474 lines
13 KiB
474 lines
13 KiB
using EnhancedUI;
|
|
using IVDataFormat;
|
|
using IVServerFormat;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using System.Numerics;
|
|
using Vector2 = UnityEngine.Vector2;
|
|
|
|
public class TreasureMgr : MonoBehaviour
|
|
{
|
|
#region Const
|
|
private static TreasureMgr curMgr = null;
|
|
|
|
private const float F_TotalEfcPos0 = -179f;
|
|
private const float F_TotalEfcPos1 = -227f;
|
|
private const float F_SvTop0 = -230f;
|
|
private const float F_SvTop1 = -278f;
|
|
private const float F_LeftGoodsLeft = -170f;
|
|
private const float F_LeftGoodsMid = 0f;
|
|
#endregion Const
|
|
|
|
#region UI
|
|
[SerializeField]
|
|
private TextMeshProUGUI txtMainT;
|
|
[SerializeField]
|
|
Button mainTreasureButton;
|
|
GameObject mainLock;
|
|
[SerializeField]
|
|
private GameObject goMainBadge;
|
|
|
|
// 가방창.
|
|
[SerializeField]
|
|
private Canvas canvasUI;
|
|
private ButtonIV[] btnTabs;
|
|
private Image[] imgTabLineBottoms;
|
|
private Image[] imgTabLineRights;
|
|
private GameObject[] goTabLocks;
|
|
private GameObject[] goTabBadges;
|
|
private GameObject goSvTreasure;
|
|
|
|
[SerializeField]
|
|
EScrController escrTreasure;
|
|
|
|
#endregion UI
|
|
|
|
#region Variables
|
|
private int iLoading = 1;
|
|
private bool bReLocalize = true;
|
|
private bool bReLocalizeGear, bReLocalizeTreasure = false;
|
|
private int iSelectedTab = -1;
|
|
private int iSelectedSubTab = -1;
|
|
private int iSvType = -1;
|
|
private int iSelectedId = -1;
|
|
private int iSelectedCount = 0;
|
|
|
|
private bool bClicking = false;
|
|
private nIdEnhance dataEnhance = null;
|
|
private Coroutine coEnhance = null;
|
|
|
|
private bool bInitNeedTreasure = true;
|
|
|
|
bool isUnlockTreasure = false;
|
|
#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("all_treasure");
|
|
|
|
//IsUnlock();
|
|
|
|
Transform trfcanvas = canvasUI.transform;
|
|
trfcanvas.Find("txtT").GetComponent<TextMeshProUGUI>().text = LocalizationText.GetText("all_treasure");
|
|
btnTabs = trfcanvas.Find("tabWrapTop").GetComponentsInChildren<ButtonIV>(true);
|
|
goTabLocks = new GameObject[btnTabs.Length];
|
|
goTabBadges = new GameObject[btnTabs.Length];
|
|
for (int i = 0; i < btnTabs.Length; i++)
|
|
{
|
|
goTabLocks[i] = btnTabs[i].transform.Find("lock").gameObject;
|
|
goTabBadges[i] = btnTabs[i].transform.Find("badge").gameObject;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
bReLocalize = false;
|
|
Transform trfcanvas = canvasUI.transform;
|
|
|
|
btnTabs[0].transform.Find("txt").GetComponent<TextMeshProUGUI>().text = LocalizationText.GetText("bag_trs_normal");
|
|
btnTabs[1].transform.Find("txt").GetComponent<TextMeshProUGUI>().text = LocalizationText.GetText("bag_trs_rare");
|
|
|
|
imgTabLineBottoms = new Image[btnTabs.Length];
|
|
imgTabLineRights = new Image[btnTabs.Length];
|
|
|
|
for (int i = 0; i < btnTabs.Length; i++)
|
|
{
|
|
imgTabLineBottoms[i] = btnTabs[i].transform.Find("linebottom").GetComponent<Image>();
|
|
imgTabLineRights[i] = btnTabs[i].transform.Find("lineright").GetComponent<Image>();
|
|
}
|
|
|
|
goSvTreasure = trfcanvas.Find("SvTreasure").gameObject;
|
|
|
|
//scrollTopBar = canvasUI.transform.Find("tabWrapTop").GetComponent<ScrollRect>();
|
|
}
|
|
}
|
|
|
|
public static void IsUnlock()
|
|
{
|
|
if (curMgr.isUnlockTreasure)
|
|
{
|
|
return;
|
|
}
|
|
|
|
curMgr.mainLock = curMgr.mainTreasureButton.transform.Find("Image").gameObject;
|
|
|
|
curMgr.mainLock.SetActive(!DataHandler.IsClearStage(DataHandler.Const.gearTreasureOpenStage));
|
|
|
|
ColorBlock colorBlock = curMgr.mainTreasureButton.colors;
|
|
|
|
if (curMgr.mainLock.activeSelf)
|
|
{
|
|
colorBlock.normalColor = new Color(0.5f, 0.5f, 0.5f);
|
|
colorBlock.highlightedColor = new Color(0.5f, 0.5f, 0.5f);
|
|
colorBlock.selectedColor = new Color(0.5f, 0.5f, 0.5f);
|
|
colorBlock.pressedColor = new Color(0.5f, 0.5f, 0.5f);
|
|
|
|
curMgr.mainTreasureButton.colors = colorBlock;
|
|
}
|
|
else
|
|
{
|
|
curMgr.isUnlockTreasure = true;
|
|
|
|
colorBlock.normalColor = new Color(1f, 1f, 1f);
|
|
colorBlock.highlightedColor = new Color(1f, 1f, 1f);
|
|
colorBlock.selectedColor = new Color(1f, 1f, 1f);
|
|
colorBlock.pressedColor = new Color(1f, 1f, 1f);
|
|
|
|
curMgr.mainTreasureButton.colors = colorBlock;
|
|
}
|
|
|
|
}
|
|
|
|
// 설정에서 언어 변경 시 처리.
|
|
public static void SReLocalize()
|
|
{
|
|
curMgr.Localize(true);
|
|
curMgr.bReLocalize = true;
|
|
curMgr.bReLocalizeGear = true;
|
|
curMgr.bReLocalizeTreasure = true;
|
|
}
|
|
|
|
// 백버튼 처리.
|
|
public static bool SCloseMenu()
|
|
{
|
|
return curMgr.CloseMenu();
|
|
}
|
|
|
|
private bool CloseMenu()
|
|
{
|
|
// 게임 시작 후 열린적 없음.
|
|
if (iSelectedTab < 0)
|
|
return false;
|
|
|
|
if (canvasUI.enabled)
|
|
{
|
|
CloseTreasure();
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
private void Awake()
|
|
{
|
|
curMgr = this;
|
|
}
|
|
|
|
void Start()
|
|
{
|
|
iLoading--;
|
|
//SetBadge();
|
|
}
|
|
#endregion Base
|
|
|
|
#region UI
|
|
public static void SopenTreasure()
|
|
{
|
|
curMgr.OpenTreasure();
|
|
}
|
|
|
|
// 보물창 열기.
|
|
public void OpenTreasure()
|
|
{
|
|
if (mainLock.activeSelf)
|
|
{
|
|
GameUIMgr.SOpenToast(FormatString.TextOpenStageClear(DataHandler.Const.gearTreasureOpenStage));
|
|
return;
|
|
}
|
|
|
|
if (iLoading > 0) return;
|
|
iLoading++;
|
|
|
|
if (bReLocalize)
|
|
Localize(false);
|
|
|
|
if (iSelectedTab < 0)
|
|
iSelectedTab = 0;
|
|
|
|
escrTreasure.scroller.RefreshActiveCellViews();
|
|
|
|
canvasUI.enabled = true;
|
|
GameUIMgr.SRightWindowClose();
|
|
GameUIMgr.SSetMainUiGroupRight(false, false, false, false);
|
|
BattleMgr.CloseFailScroll();
|
|
|
|
SoundMgr.PlaySfx(SoundName.BtnPress);
|
|
|
|
TabPress(iSelectedTab);
|
|
|
|
iLoading--;
|
|
}
|
|
|
|
// 보물창 닫기.
|
|
public void CloseTreasure()
|
|
{
|
|
if (!canvasUI.enabled)
|
|
return;
|
|
if (iLoading > 0)
|
|
return;
|
|
iLoading++;
|
|
|
|
canvasUI.enabled = false;
|
|
GameUIMgr.SSetMainUiOn(true);
|
|
GameUIMgr.SSetMainUiGroupRight(true, true, false, true);
|
|
MissionMgr.SRefreshMission();
|
|
|
|
SoundMgr.PlaySfx(SoundName.BtnPress);
|
|
|
|
iLoading--;
|
|
}
|
|
#endregion
|
|
|
|
#region Tab
|
|
public void TabPress(int index)
|
|
{
|
|
// 잠긴 컨텐츠.
|
|
if (goTabLocks[index].activeSelf)
|
|
{
|
|
if (index == 1)
|
|
GameUIMgr.SOpenToast(LocalizationText.GetText("msg_prepare"));
|
|
return;
|
|
}
|
|
|
|
iLoading++;
|
|
|
|
if (iSelectedTab >= 0)
|
|
{
|
|
btnTabs[iSelectedTab].interactable = true;
|
|
}
|
|
iSelectedTab = index;
|
|
|
|
btnTabs[iSelectedTab].interactable = false;
|
|
|
|
if (iSelectedTab == 0)
|
|
{
|
|
TabSubPress2(0);
|
|
}
|
|
else if (iSelectedTab == 1)
|
|
{
|
|
TabSubPress2(1);
|
|
}
|
|
|
|
|
|
iLoading--;
|
|
}
|
|
|
|
public void TabSubPress2(int index)
|
|
{
|
|
// 희귀 유물. 추후 업데이트.
|
|
//if (index > 0)
|
|
//{
|
|
// GameUIMgr.SOpenPopup1Button(LocalizationText.GetText("msg_prepare"));
|
|
// return;
|
|
//}
|
|
iLoading++;
|
|
|
|
iSelectedSubTab = index;
|
|
|
|
//iSvType = cGoods.TBagTreasure;
|
|
//escrTreasure.SetType(iSvType);
|
|
// 초기화.
|
|
|
|
if (bInitNeedTreasure)
|
|
{
|
|
bInitNeedTreasure = false;
|
|
Dictionary<int, dTreasure> datas = DataHandler.GetGearTreasures();
|
|
EnhancedUI.SmallList<int> treasures = new EnhancedUI.SmallList<int>();
|
|
foreach (var item in datas)
|
|
{
|
|
treasures.Add(item.Key);
|
|
}
|
|
escrTreasure.LoadDatas(treasures);
|
|
}
|
|
else
|
|
{
|
|
escrTreasure.scroller.RefreshActiveCellViews();
|
|
}
|
|
|
|
iLoading--;
|
|
}
|
|
#endregion
|
|
|
|
#region Treasure Enhance
|
|
public static void SOnBtnTreasureEnhanceDown(int key)
|
|
{
|
|
curMgr.OnBtnTreasureEnhanceDown(key);
|
|
}
|
|
|
|
// 보물 강화 시작.
|
|
public void OnBtnTreasureEnhanceDown(int key)
|
|
{
|
|
if (iLoading > 0)
|
|
return;
|
|
if (bClicking)
|
|
return;
|
|
iLoading++;
|
|
|
|
bClicking = true;
|
|
coEnhance = StartCoroutine(CTreasureEnhance(key));
|
|
}
|
|
|
|
// 보물 강화 진행.
|
|
private IEnumerator CTreasureEnhance(int key)
|
|
{
|
|
dTreasure treasure = DataHandler.GetGearTreasure(key);
|
|
dataEnhance = new nIdEnhance(key, treasure.level, treasure.count);
|
|
|
|
while (bClicking)
|
|
{
|
|
if (dataEnhance.aftCnt <= 0 || dataEnhance.aftLv >= treasure.maxLv)
|
|
{
|
|
OnBtnTreasureEnhanceUp(key);
|
|
yield break;
|
|
}
|
|
|
|
dataEnhance.tryCount++;
|
|
dataEnhance.useGoods++;
|
|
dataEnhance.aftCnt--;
|
|
// 강화 확률적 성공.
|
|
if (DataHandler.LvUpGearTreasure(key))
|
|
{
|
|
dataEnhance.aftLv++;
|
|
//@ 레벨업 연출?
|
|
}
|
|
escrTreasure.scroller.RefreshActiveCellViews();
|
|
|
|
yield return YieldInstructionCache.WaitForSeconds(0.1f);
|
|
}
|
|
coEnhance = null;
|
|
}
|
|
|
|
public static void SOnBtnTreasureEnhanceUp(int key)
|
|
{
|
|
curMgr.OnBtnTreasureEnhanceUp(key);
|
|
}
|
|
|
|
// 보물 강화 종료.
|
|
public void OnBtnTreasureEnhanceUp(int key)
|
|
{
|
|
if (!bClicking)
|
|
return;
|
|
CoverCamera.Hold();
|
|
if (coEnhance != null)
|
|
{
|
|
StopCoroutine(coEnhance);
|
|
coEnhance = null;
|
|
}
|
|
bClicking = false;
|
|
|
|
SvConnectManager.Instance.RequestSvPost(true, 0, UrlApi.GetUrl(UrlApi.BagTreasureEnhance), typeof(nTreasureEnhanceReturn), ALvUpTreasureSucc, ALvUpTreasureFail, dataEnhance, true);
|
|
}
|
|
|
|
// 보물 강화 통신 실패.
|
|
private void ALvUpTreasureFail(SvError error, object request)
|
|
{
|
|
DataHandler.UpdateGearTreasure(dataEnhance.sid, dataEnhance.befLv, dataEnhance.befCnt);
|
|
dataEnhance = null;
|
|
CoverCamera.Release();
|
|
iLoading--;
|
|
}
|
|
|
|
// 보물 강화 통신 성공.
|
|
private void ALvUpTreasureSucc(object result, object request)
|
|
{
|
|
nTreasureEnhanceReturn data = result as nTreasureEnhanceReturn;
|
|
if (data == null)
|
|
{
|
|
ALvUpTreasureFail(new SvError(eErrorCode.NULL_OR_EMPTY), request);
|
|
return;
|
|
}
|
|
|
|
DataHandler.UpdateGearTreasurePlay(data.playGearTreasure);
|
|
escrTreasure.scroller.RefreshActiveCellViews();
|
|
dataEnhance = null;
|
|
|
|
CoverCamera.Release();
|
|
iLoading--;
|
|
}
|
|
#endregion Treasure Enhance
|
|
|
|
#region Treasure Sell
|
|
public static void SSellTreasure(int key)
|
|
{
|
|
curMgr.SellTreasure(key);
|
|
}
|
|
|
|
// 보물 판매.
|
|
private void SellTreasure(int key)
|
|
{
|
|
if (iLoading > 0)
|
|
return;
|
|
iLoading++;
|
|
CoverCamera.Hold();
|
|
|
|
nIdCnt data = new nIdCnt(key);
|
|
SvConnectManager.Instance.RequestSvPost(true, 0, UrlApi.GetUrl(UrlApi.BagTreasureSell), typeof(nTreasureSellReturn), ASellTreasureSucc, ASellTreasureFail, data, true);
|
|
}
|
|
|
|
// 보물 판매 통신 실패.
|
|
private void ASellTreasureFail(SvError error, object request)
|
|
{
|
|
CoverCamera.Release();
|
|
iLoading--;
|
|
}
|
|
|
|
// 보물 판매 통신 성공.
|
|
private void ASellTreasureSucc(object result, object request)
|
|
{
|
|
nTreasureSellReturn data = result as nTreasureSellReturn;
|
|
if (data == null)
|
|
{
|
|
ASellTreasureFail(new SvError(eErrorCode.NULL_OR_EMPTY), request);
|
|
return;
|
|
}
|
|
|
|
nGoods[] goods = new nGoods[1] { new nGoods(cGoods.TCurrency, cGoods.CDiaF, data.playCurrency.diaFree + data.playCurrency.diaPaid - DataHandler.Goods.Dia) };
|
|
DataHandler.SetGoods(data.playCurrency, true);
|
|
|
|
nIdCnt reqdata = request as nIdCnt;
|
|
DataHandler.UpdateGearTreasurePlay(data.playGearTreasure);
|
|
escrTreasure.scroller.RefreshActiveCellViews();
|
|
|
|
GameUIMgr.SOpenPopupGoods(goods);
|
|
CoverCamera.Release();
|
|
iLoading--;
|
|
}
|
|
#endregion Treasure Sell
|
|
|
|
public void HelpMsg()
|
|
{
|
|
SoundMgr.PlaySfx(SoundName.BtnPress);
|
|
GameUIMgr.SOpenHelp(LocalizationText.GetText("help_treasure"));
|
|
}
|
|
}
|