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().text = LocalizationText.GetText("all_treasure"); btnTabs = trfcanvas.Find("tabWrapTop").GetComponentsInChildren(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().text = LocalizationText.GetText("bag_trs_normal"); btnTabs[1].transform.Find("txt").GetComponent().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(); imgTabLineRights[i] = btnTabs[i].transform.Find("lineright").GetComponent(); } goSvTreasure = trfcanvas.Find("SvTreasure").gameObject; //scrollTopBar = canvasUI.transform.Find("tabWrapTop").GetComponent(); } } 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 datas = DataHandler.GetGearTreasures(); EnhancedUI.SmallList treasures = new EnhancedUI.SmallList(); 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")); } }