2024-11-13 16:56:37 +08:00
|
|
|
using System;
|
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
2024-12-23 14:40:13 +08:00
|
|
|
using Spine;
|
|
|
|
using Spine.Unity;
|
2024-11-13 16:56:37 +08:00
|
|
|
using TMPro;
|
|
|
|
using UnityEngine;
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
|
|
|
public class ForgePanel : MonoBehaviour
|
|
|
|
{
|
2024-12-04 17:26:27 +08:00
|
|
|
[SerializeField] private ItemButton itemObj;
|
|
|
|
[SerializeField] private Transform itemParent;
|
2024-12-21 19:57:23 +08:00
|
|
|
[SerializeField] private Transform wapenParent;
|
2024-11-13 16:56:37 +08:00
|
|
|
[SerializeField] private List<ItemButton> _itemButtons;
|
2024-12-21 19:57:23 +08:00
|
|
|
[SerializeField] private List<ItemButton> _itemWapenButtons;
|
2024-11-13 16:56:37 +08:00
|
|
|
[SerializeField] private List<SlotUI> _slotUis;
|
|
|
|
[SerializeField] private CraftingUI getCrafting;
|
|
|
|
[SerializeField] private CraftingUI getNPCCrafting;
|
2024-12-16 17:25:10 +08:00
|
|
|
[SerializeField] private Image npcIcon;
|
2024-11-13 16:56:37 +08:00
|
|
|
[SerializeField] private List<CraftingUI> _craftingUis;
|
|
|
|
[SerializeField] private Button _craftButton;
|
|
|
|
[SerializeField] private NPCTrigger _npcTrigger;
|
2024-12-23 14:40:13 +08:00
|
|
|
[SerializeField] private SkeletonGraphic startAni;
|
|
|
|
|
|
|
|
[SerializeField] private GameObject openParent;
|
2024-11-13 16:56:37 +08:00
|
|
|
[SerializeField] private Button startButton;
|
|
|
|
[SerializeField] private Button title;
|
2024-11-21 10:26:47 +08:00
|
|
|
[SerializeField] public Button _buyEventButton;
|
|
|
|
[SerializeField] private Button _getGoldButton;
|
2024-12-23 20:48:28 +08:00
|
|
|
[SerializeField] private Button closeStoreButton;
|
2024-12-22 21:47:36 +08:00
|
|
|
[SerializeField] private Text textPro;
|
2024-11-13 16:56:37 +08:00
|
|
|
[SerializeField] private CraftingPanel _craftingPanel;
|
2024-11-21 10:26:47 +08:00
|
|
|
[SerializeField] private SettlementPanel _settlementPanel;
|
|
|
|
[SerializeField] private TextMeshProUGUI _npcCount;
|
2024-12-22 20:35:00 +08:00
|
|
|
[SerializeField] private Text _goldNum;
|
|
|
|
[SerializeField] private Text _diamondNum;
|
|
|
|
[SerializeField] private Text _physicalNum;
|
2024-11-13 16:56:37 +08:00
|
|
|
public Transform seletIcon;
|
|
|
|
// Start is called before the first frame update
|
|
|
|
void Start()
|
|
|
|
{
|
2024-11-21 10:26:47 +08:00
|
|
|
_buyEventButton.onClick.AddListener(() =>
|
|
|
|
{
|
|
|
|
_buyEventButton.gameObject.SetActive(false);
|
|
|
|
});
|
|
|
|
_getGoldButton.onClick.AddListener(() =>
|
|
|
|
{
|
|
|
|
_buyEventButton.gameObject.SetActive(false);
|
|
|
|
GameSystem.ins.goldCoin += 100;
|
|
|
|
ResetGold();
|
|
|
|
});
|
2024-11-13 16:56:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private void OnEnable()
|
|
|
|
{
|
|
|
|
_craftButton.onClick.AddListener(CraftEvent);
|
|
|
|
startButton.onClick.AddListener(GameStart);
|
|
|
|
title.onClick.AddListener(CloseTitle);
|
2024-12-23 20:48:28 +08:00
|
|
|
closeStoreButton.onClick.AddListener(CloseStore);
|
2024-11-13 16:56:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Update is called once per frame
|
|
|
|
void Update()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Open()
|
|
|
|
{
|
|
|
|
_npcTrigger.Open();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Close()
|
|
|
|
{
|
|
|
|
_npcTrigger.Close();
|
2024-12-23 14:40:13 +08:00
|
|
|
openParent.SetActive(true);
|
2024-12-26 11:39:49 +08:00
|
|
|
startAni.AnimationState.SetAnimation(0, "idle_1", true);
|
2024-11-13 16:56:37 +08:00
|
|
|
_craftingPanel.gameObject.SetActive(false);
|
2024-12-23 17:12:52 +08:00
|
|
|
ResetItemData();
|
2024-11-13 16:56:37 +08:00
|
|
|
}
|
|
|
|
|
2024-11-21 10:26:47 +08:00
|
|
|
public void OpenStartPanel()
|
|
|
|
{
|
2024-12-23 14:40:13 +08:00
|
|
|
openParent.SetActive(true);
|
|
|
|
startAni.AnimationState.SetAnimation(0, "EnterAnim_1", false);
|
|
|
|
startAni.AnimationState.Complete += StarIdle;
|
2024-12-23 17:12:52 +08:00
|
|
|
_settlementPanel.gameObject.SetActive(true);
|
2024-12-26 11:39:49 +08:00
|
|
|
SoundSystem.ins.CloseAudio();
|
2024-11-21 10:26:47 +08:00
|
|
|
_settlementPanel.SettlementEvent();
|
|
|
|
}
|
2024-12-23 14:40:13 +08:00
|
|
|
|
|
|
|
public void StarIdle(TrackEntry trackentry)
|
|
|
|
{
|
|
|
|
startAni.AnimationState.Complete -= StarIdle;
|
|
|
|
startAni.AnimationState.SetAnimation(0, "idle_1", true);
|
|
|
|
}
|
2024-11-13 16:56:37 +08:00
|
|
|
public void CloseTitle()
|
|
|
|
{
|
|
|
|
title.gameObject.SetActive(false);
|
|
|
|
}
|
2024-12-16 17:25:10 +08:00
|
|
|
public void SetData(bool bo,NPCBuyData npcBuyData)
|
2024-11-13 16:56:37 +08:00
|
|
|
{
|
|
|
|
title.gameObject.SetActive(true);
|
2024-12-16 17:25:10 +08:00
|
|
|
var data = JsonTab.Instance.tables.ShopNPC.Get(npcBuyData.npcID);
|
|
|
|
textPro.text = bo ? data.Guestyes : data.Guestno;
|
2024-11-13 16:56:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private void OnDisable()
|
|
|
|
{
|
|
|
|
_craftButton.onClick.RemoveListener(CraftEvent);
|
|
|
|
startButton.onClick.RemoveListener(GameStart);
|
|
|
|
title.onClick.RemoveListener(CloseTitle);
|
2024-12-23 20:48:28 +08:00
|
|
|
closeStoreButton.onClick.RemoveListener(CloseStore);
|
2024-11-13 16:56:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void GameStart()
|
|
|
|
{
|
2024-12-25 16:35:48 +08:00
|
|
|
|
2024-12-24 17:05:51 +08:00
|
|
|
if (DataManager.GetPhysical()>=5)
|
2024-12-20 15:56:02 +08:00
|
|
|
{
|
2024-12-26 11:39:49 +08:00
|
|
|
SoundSystem.ins.EventAudioSource();
|
2024-12-24 17:05:51 +08:00
|
|
|
DataManager.RemovePhysical();
|
|
|
|
ResetGold();
|
|
|
|
startAni.AnimationState.SetAnimation(0, "EnterAnim_2", false);
|
|
|
|
startAni.AnimationState.Complete += StartEvent;
|
2024-12-25 16:35:48 +08:00
|
|
|
if (DataManager.GetPrefab("openDoor")==0)
|
|
|
|
{
|
|
|
|
DotData.ins.SendEvent("a11103","");
|
|
|
|
}
|
|
|
|
if (DataManager.GetPrefab("openDoor")==1)
|
|
|
|
{
|
|
|
|
DotData.ins.SendEvent("a11104","");
|
|
|
|
}
|
|
|
|
if (DataManager.GetPrefab("openDoor")==3)
|
|
|
|
{
|
|
|
|
DotData.ins.SendEvent("a11105","");
|
|
|
|
}
|
|
|
|
DataManager.SetPrefab("openDoor",DataManager.GetPrefab("openDoor")+1);
|
|
|
|
startAni.AnimationState.SetAnimation(0, "EnterAnim_2", false);
|
|
|
|
startAni.AnimationState.Complete += StartEvent;
|
2024-12-20 15:56:02 +08:00
|
|
|
}
|
2024-12-24 17:05:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void GuideV1()
|
|
|
|
{
|
|
|
|
DataManager.RemovePhysical();
|
|
|
|
ResetGold();
|
2024-12-23 14:40:13 +08:00
|
|
|
startAni.AnimationState.SetAnimation(0, "EnterAnim_2", false);
|
2024-12-24 17:05:51 +08:00
|
|
|
startAni.AnimationState.Complete += GuideV1b;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void GuideV1b(TrackEntry trackentry)
|
|
|
|
{
|
|
|
|
startAni.AnimationState.Complete -= GuideV1b;
|
|
|
|
GameSystem.ins.StartNpcData();
|
|
|
|
openParent.SetActive(false);
|
2024-11-13 16:56:37 +08:00
|
|
|
}
|
|
|
|
|
2024-12-23 20:48:28 +08:00
|
|
|
void CloseStore()
|
|
|
|
{
|
|
|
|
GameSystem.ins.CloseStore();
|
2024-11-13 16:56:37 +08:00
|
|
|
}
|
|
|
|
|
2024-12-23 14:40:13 +08:00
|
|
|
private void StartEvent(TrackEntry trackentry)
|
|
|
|
{
|
|
|
|
startAni.AnimationState.Complete -= StartEvent;
|
|
|
|
GameSystem.ins.StartNpcData();
|
|
|
|
openParent.SetActive(false);
|
|
|
|
}
|
|
|
|
|
2024-11-13 16:56:37 +08:00
|
|
|
void CraftEvent()
|
|
|
|
{
|
|
|
|
_craftingPanel.gameObject.SetActive(true);
|
|
|
|
_craftingPanel.StartOpen(GameSystem.ins.drawingManager.DrawOpen(), (bool bo) =>
|
|
|
|
{
|
|
|
|
GameSystem.ins.Crafting(bo);
|
|
|
|
});
|
|
|
|
}
|
2024-12-24 17:05:51 +08:00
|
|
|
|
|
|
|
public void CraftGuideEvent(Action action)
|
|
|
|
{
|
|
|
|
_craftingPanel.gameObject.SetActive(true);
|
|
|
|
_craftingPanel.StartOpen(true, (bool bo) =>
|
|
|
|
{
|
|
|
|
GameSystem.ins.Crafting(bo);
|
|
|
|
action?.Invoke();
|
|
|
|
});
|
|
|
|
}
|
2024-12-16 17:25:10 +08:00
|
|
|
public void ResetCrafting(int id,int npcID)
|
2024-11-13 16:56:37 +08:00
|
|
|
{
|
|
|
|
getCrafting.SaveIcon(id);
|
|
|
|
getNPCCrafting.SaveIcon(id);
|
2024-11-21 10:26:47 +08:00
|
|
|
_npcCount.text = GameSystem.ins._npcBuyDatas.Count.ToString();
|
2024-12-16 17:25:10 +08:00
|
|
|
var npcData = JsonTab.Instance.tables.ShopNPC.Get(npcID);
|
|
|
|
npcIcon.sprite = AssetBundleManager.ins.Sprite(npcData.Guesticon,AtlasType.NpcIcon);
|
2024-12-04 17:26:27 +08:00
|
|
|
var slotData = JsonTab.Instance.tables.CraftingRecipes.Get(id);
|
2024-12-07 22:30:19 +08:00
|
|
|
if (slotData.Levelprops1!=0)
|
|
|
|
{
|
2024-12-11 13:58:55 +08:00
|
|
|
_craftingUis[0].gameObject.SetActive(true);
|
2024-12-07 22:30:19 +08:00
|
|
|
_craftingUis[0].SaveIcon(slotData.Levelprops1);
|
|
|
|
}
|
2024-12-11 13:58:55 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
_craftingUis[0].gameObject.SetActive(false);
|
|
|
|
}
|
2024-12-07 22:30:19 +08:00
|
|
|
if (slotData.Levelprops2!=0)
|
|
|
|
{
|
2024-12-11 13:58:55 +08:00
|
|
|
_craftingUis[1].gameObject.SetActive(true);
|
2024-12-07 22:30:19 +08:00
|
|
|
_craftingUis[1].SaveIcon(slotData.Levelprops2);
|
|
|
|
}
|
2024-12-11 13:58:55 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
_craftingUis[1].gameObject.SetActive(false);
|
|
|
|
}
|
2024-12-07 22:30:19 +08:00
|
|
|
if (slotData.Levelprops3!=0)
|
|
|
|
{
|
2024-12-11 13:58:55 +08:00
|
|
|
_craftingUis[2].gameObject.SetActive(true);
|
2024-12-07 22:30:19 +08:00
|
|
|
_craftingUis[2].SaveIcon(slotData.Levelprops3);
|
|
|
|
}
|
2024-12-11 13:58:55 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
_craftingUis[2].gameObject.SetActive(false);
|
|
|
|
}
|
2024-12-07 22:30:19 +08:00
|
|
|
if (slotData.Levelprops4!=0)
|
|
|
|
{
|
2024-12-11 13:58:55 +08:00
|
|
|
_craftingUis[3].gameObject.SetActive(true);
|
2024-12-07 22:30:19 +08:00
|
|
|
_craftingUis[3].SaveIcon(slotData.Levelprops4);
|
|
|
|
}
|
2024-12-11 13:58:55 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
_craftingUis[3].gameObject.SetActive(false);
|
|
|
|
}
|
2024-12-04 17:26:27 +08:00
|
|
|
// var data = GameSystem.ins.DataAsset.crafting.FirstOrDefault(d => d.id == id);
|
|
|
|
// List<int> itemId = new List<int>();
|
|
|
|
// foreach (var item in data.craftID)
|
|
|
|
// {
|
|
|
|
// for (int i = 0; i < item.num; i++)
|
|
|
|
// {
|
|
|
|
// itemId.Add(item.id);
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// for (int i = 0; i < itemId.Count; i++)
|
|
|
|
// {
|
|
|
|
// _craftingUis[i].SaveIcon(itemId[i]);
|
|
|
|
// }
|
|
|
|
|
2024-11-13 16:56:37 +08:00
|
|
|
}
|
|
|
|
public void ResetSlotItem()
|
|
|
|
{
|
|
|
|
foreach (var slot in _slotUis)
|
|
|
|
{
|
|
|
|
slot.ResetIcon();
|
|
|
|
}
|
|
|
|
}
|
2024-12-16 17:25:10 +08:00
|
|
|
|
2024-11-13 16:56:37 +08:00
|
|
|
public void ResetItemData()
|
|
|
|
{
|
|
|
|
foreach (var item in _itemButtons)
|
|
|
|
{
|
|
|
|
item.gameObject.SetActive(false);
|
|
|
|
}
|
|
|
|
|
2024-12-04 17:26:27 +08:00
|
|
|
var allData=JsonTab.Instance.tables.Item.DataList;
|
|
|
|
int index = 0;
|
|
|
|
for (int i = 0; i < allData.Count; i++)
|
2024-11-13 16:56:37 +08:00
|
|
|
{
|
2024-12-23 17:12:52 +08:00
|
|
|
if (DataManager.GetItem(allData[i].ID)>=0&&DataManager.GetItemUnLock(allData[i].ID)&&allData[i].Proptype!=0&&allData[i].Proptype==1)
|
2024-12-04 17:26:27 +08:00
|
|
|
{
|
|
|
|
if (index>=_itemButtons.Count )
|
|
|
|
{
|
|
|
|
var add = Instantiate(itemObj.gameObject,itemParent);
|
|
|
|
_itemButtons.Add(add.GetComponent<ItemButton>());
|
|
|
|
}
|
|
|
|
_itemButtons[index].gameObject.SetActive(true);
|
|
|
|
_itemButtons[index].SetItemData(allData[i].ID);
|
|
|
|
index++;
|
|
|
|
}
|
2024-11-13 16:56:37 +08:00
|
|
|
}
|
2024-12-21 19:57:23 +08:00
|
|
|
|
|
|
|
ResetItem();
|
2024-12-13 20:38:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private void ResetItem()
|
|
|
|
{
|
2024-12-21 19:57:23 +08:00
|
|
|
foreach (var item in _itemWapenButtons)
|
2024-12-13 20:38:15 +08:00
|
|
|
{
|
|
|
|
item.gameObject.SetActive(false);
|
|
|
|
}
|
|
|
|
var allData=JsonTab.Instance.tables.Item.DataList;
|
|
|
|
int index = 0;
|
|
|
|
for (int i = 0; i < allData.Count; i++)
|
|
|
|
{
|
2024-12-23 17:12:52 +08:00
|
|
|
if (DataManager.GetItem(allData[i].ID)>=0&&DataManager.GetItemUnLock(allData[i].ID)&&allData[i].Proptype>1)
|
2024-12-13 20:38:15 +08:00
|
|
|
{
|
2024-12-21 19:57:23 +08:00
|
|
|
if (index>=_itemWapenButtons.Count )
|
2024-12-13 20:38:15 +08:00
|
|
|
{
|
2024-12-21 19:57:23 +08:00
|
|
|
var add = Instantiate(itemObj.gameObject,wapenParent);
|
|
|
|
_itemWapenButtons.Add(add.GetComponent<ItemButton>());
|
2024-12-13 20:38:15 +08:00
|
|
|
}
|
2024-12-21 19:57:23 +08:00
|
|
|
_itemWapenButtons[index].gameObject.SetActive(true);
|
|
|
|
_itemWapenButtons[index].SetItemData(allData[i].ID);
|
2024-12-13 20:38:15 +08:00
|
|
|
index++;
|
|
|
|
}
|
|
|
|
}
|
2024-11-13 16:56:37 +08:00
|
|
|
}
|
2024-11-21 10:26:47 +08:00
|
|
|
|
|
|
|
public void ResetGold()
|
|
|
|
{
|
2024-12-04 17:26:27 +08:00
|
|
|
_goldNum.text = DataManager.GetItem(2).ToString();
|
2024-12-21 14:05:40 +08:00
|
|
|
_diamondNum.text = DataManager.GetItem(3).ToString();
|
2024-12-22 20:35:00 +08:00
|
|
|
_physicalNum.text=DataManager.GetPhysical().ToString();
|
2024-11-21 10:26:47 +08:00
|
|
|
}
|
2024-11-13 16:56:37 +08:00
|
|
|
}
|