RandomGFGoStop/Assets/Scripts/UI/HuntingSlot.cs

222 lines
7.4 KiB
C#
Raw Normal View History

2025-08-28 21:16:55 +00:00
using UnityEngine;
2025-08-27 21:08:17 +00:00
using UnityEngine.UI;
using CodeJay.Classes;
using UnityEngine.ResourceManagement.AsyncOperations;
using BansheeGz.BGDatabase;
using UnityEngine.EventSystems;
2025-08-28 21:16:55 +00:00
using TMPro;
2025-08-27 21:08:17 +00:00
2025-08-29 00:59:06 +00:00
public class HuntingSlot : CardBase
2025-08-27 21:08:17 +00:00
{
[SerializeField] private TMPro.TextMeshProUGUI NameTMP;
[Space(20)]
[SerializeField] private Image AI_Left;
[SerializeField] private Image AI_Right;
2025-08-28 21:16:55 +00:00
[SerializeField] private GameObject Block_Left;
[SerializeField] private GameObject Block_Right;
public GameObject[] gos_openbutton;
public TextMeshProUGUI[] texts_price;
2025-08-27 21:08:17 +00:00
[SerializeField] private GameObject[] Right_GOs;
[SerializeField] private ScrollRect sr;
private bool _fullview_Left = false;
private bool _fullview_Right = false;
private HuntingData _data_left;
private HuntingData _data_right;
private DB_HuntingData _huntigdata_left;
private DB_HuntingData _huntigdata_right;
private BGId _huntingListID;
2025-08-29 00:59:06 +00:00
public override void Set<T>(T _base, int iLoop = -1, int idata = -1)
{
base.Set(_base, iLoop, idata);
SetData(iLoop, idata);
}
2025-08-27 21:08:17 +00:00
public void SetData(int index, int unlockTargetIndex)
{
DB_HuntingListData huntingListData = DB_HuntingListData.GetEntity(Mathf.FloorToInt((float)((float)index / 2.0f)));
_huntingListID = huntingListData.Id;
_data_left = GameManager.DB.GetHuntingData(index);
_data_right = GameManager.DB.GetHuntingData(index + 1);
2025-08-28 21:16:55 +00:00
gos_openbutton[0].SetActive(false);
gos_openbutton[1].SetActive(false);
if (_data_left != null && _data_left.Index == unlockTargetIndex)
gos_openbutton[0].SetActive(true);
if (_data_right != null && _data_right.Index == unlockTargetIndex)
gos_openbutton[1].SetActive(true);
2025-08-29 00:59:06 +00:00
texts_price[0].text = _data_left.BuyPrice.ToString();
texts_price[1].text = _data_right.BuyPrice.ToString();
2025-08-28 21:16:55 +00:00
2025-08-27 21:08:17 +00:00
_huntigdata_left = DB_HuntingData.GetEntity(new BansheeGz.BGDatabase.BGId(_data_left.HuntingDataID));
if (GameManager.BGDatabase.LoadUnlockHuntingImageHandle[_huntigdata_left.GetDBF_UnlockImageAddressablesAddress()].Status == AsyncOperationStatus.Succeeded)
{
AI_Left.sprite = GameManager.BGDatabase.LoadUnlockHuntingImageHandle[_huntigdata_left.GetDBF_UnlockImageAddressablesAddress()].Result as Sprite;
}
NameTMP.text = huntingListData.DBF_Title;
//NameTMP.text = $"{huntingListData.DBF_Title}\n<color=yellow>{_data_left.Name}</color>";
//AI_Left.sprite = GameManager.Resource.GetAISpriteFromResources(_data_left.TextureIndex);
if (_data_right == null)
{
for (int i = 0; i < Right_GOs.Length; i++)
Right_GOs[i].SetActive(false);
}
else
{
for (int i = 0; i < Right_GOs.Length; i++)
Right_GOs[i].SetActive(true);
_huntigdata_right = DB_HuntingData.GetEntity(new BansheeGz.BGDatabase.BGId(_data_right.HuntingDataID));
if (GameManager.BGDatabase.LoadUnlockHuntingImageHandle[_huntigdata_right.GetDBF_UnlockImageAddressablesAddress()].Status == AsyncOperationStatus.Succeeded)
{
AI_Right.sprite = GameManager.BGDatabase.LoadUnlockHuntingImageHandle[_huntigdata_right.GetDBF_UnlockImageAddressablesAddress()].Result as Sprite;
}
//AI_Right.sprite = GameManager.Resource.GetAISpriteFromResources(_data_right.TextureIndex);
}
// 도달 못함
if (GameManager.DB.IsAllUnlocked())
{
_fullview_Left = true;
_fullview_Right = true;
2025-08-28 21:16:55 +00:00
Block_Left.SetActive(false);
Block_Right.SetActive(false);
2025-08-27 21:08:17 +00:00
}
else if (_data_left.Index > unlockTargetIndex)
{
_fullview_Left = false;
_fullview_Right = false;
2025-08-28 21:16:55 +00:00
// 왼쪽 클리어 못함
Block_Left.SetActive(true);
2025-08-27 21:08:17 +00:00
if (_data_right != null)
{
2025-08-28 21:16:55 +00:00
// 당연히 오른쪽 클리어 못함
Block_Right.SetActive(true);
2025-08-27 21:08:17 +00:00
}
}
else if (_data_left.Index == unlockTargetIndex)
{
// 1단계 클리어 해야함
_fullview_Left = false;
_fullview_Right = false;
2025-08-28 21:16:55 +00:00
// 왼쪽 클리어 못 함
Block_Left.SetActive(true);
2025-08-27 21:08:17 +00:00
if (_data_right != null)
{
2025-08-28 21:16:55 +00:00
// 왼쪽 클리어 못 했으니 열 수 없음
Block_Right.SetActive(true);
2025-08-27 21:08:17 +00:00
}
}
else if (_data_right != null)
{
// 2단계 클리어 해야함
// 두 if문 조건 교체 (복구)
if (_data_right.Index == unlockTargetIndex)
{
_fullview_Left = true;
_fullview_Right = false;
2025-08-28 21:16:55 +00:00
// 왼쪽 클리어 함
Block_Left.SetActive(false);
2025-08-27 21:08:17 +00:00
2025-08-28 21:16:55 +00:00
// 오른쪽 클리어 못 함
Block_Right.SetActive(true);
2025-08-27 21:08:17 +00:00
}
else if (_data_right.Index < unlockTargetIndex)
{
_fullview_Left = true;
_fullview_Right = true;
2025-08-28 21:16:55 +00:00
Block_Left.SetActive(false);
Block_Right.SetActive(false);
2025-08-27 21:08:17 +00:00
}
}
// 왼쪽 데이터만 있고(총 데이터가 홀수일 경우) 클리어함
else
{
_fullview_Left = true;
_fullview_Right = false;
2025-08-28 21:16:55 +00:00
// 왼쪽 클리어 함
Block_Left.SetActive(false);
2025-08-27 21:08:17 +00:00
}
}
public void ClickAIImage(bool isLeft)
{
GameManager.Sound.PlaySFX(ESFXType.Button_Hit);
if (isLeft)
{
if (_fullview_Left)
GameManager.Event.InvokeEvent(EEventType.OnClickFullView, new BGId(_data_left.HuntingDataID), _huntingListID);
}
else
{
if (_data_right != null && _fullview_Right)
GameManager.Event.InvokeEvent(EEventType.OnClickFullView, new BGId(_data_right.HuntingDataID), _huntingListID);
}
}
public void OnBeginDrag(PointerEventData eventData)
{
sr.OnBeginDrag(eventData);
}
public void OnDrag(PointerEventData eventData)
{
sr.OnDrag(eventData);
}
public void OnEndDrag(PointerEventData eventData)
{
sr.OnEndDrag(eventData);
}
public void OnClick_Buy(bool left)
{
GameManager.Sound.PlaySFX(ESFXType.Button_Hit);
if (GameManager.DB.IsAllUnlocked() == false)
{
2025-08-29 00:59:06 +00:00
var needKey = left ? _data_left.BuyPrice : _data_right.BuyPrice;
if (GameManager.DB.Key >= needKey)
{
GameManager.DB.SubKey(needKey, this.name);
GameManager.DB.UnlockLastAIImage();
GameManager.DB.SaveDatas();
GameManager.Event.InvokeEvent(EEventType.OnSynchronizeAIChllengeModeAIData);
BGId huntingDataID = GameManager.BGDatabase.GetLastUnolockHuntingDataID();
BGId huntingListDataID = GameManager.BGDatabase.GetLastUnolockHuntingListDataID();
if (huntingDataID != BGId.Empty && huntingListDataID != BGId.Empty)
{
GameManager.Event.InvokeEvent(EEventType.OnClickFullView, huntingDataID, huntingListDataID);
}
}
else
{
GameManager.UI.ShowNStackPopup(EPopupType.KeyChargePopup);
}
}
}
2025-08-27 21:08:17 +00:00
}