using System; using System.Collections; using System.Collections.Generic; using System.Linq; using TMPro; using UnityEngine; using UnityEngine.UI; public class ForgePanel : MonoBehaviour { [SerializeField] private ItemButton itemObj; [SerializeField] private Transform itemParent; [SerializeField] private Transform wapenParent; [SerializeField] private List _itemButtons; [SerializeField] private List _itemWapenButtons; [SerializeField] private List _slotUis; [SerializeField] private CraftingUI getCrafting; [SerializeField] private CraftingUI getNPCCrafting; [SerializeField] private Image npcIcon; [SerializeField] private List _craftingUis; [SerializeField] private Button _craftButton; [SerializeField] private NPCTrigger _npcTrigger; [SerializeField] private Button startButton; [SerializeField] private Button title; [SerializeField] public Button _buyEventButton; [SerializeField] private Button _getGoldButton; [SerializeField] private Text textPro; [SerializeField] private CraftingPanel _craftingPanel; [SerializeField] private SettlementPanel _settlementPanel; [SerializeField] private TextMeshProUGUI _npcCount; [SerializeField] private Text _goldNum; [SerializeField] private Text _diamondNum; [SerializeField] private Text _physicalNum; public Transform seletIcon; // Start is called before the first frame update void Start() { _buyEventButton.onClick.AddListener(() => { _buyEventButton.gameObject.SetActive(false); }); _getGoldButton.onClick.AddListener(() => { _buyEventButton.gameObject.SetActive(false); GameSystem.ins.goldCoin += 100; ResetGold(); }); } private void OnEnable() { _craftButton.onClick.AddListener(CraftEvent); startButton.onClick.AddListener(GameStart); title.onClick.AddListener(CloseTitle); } // Update is called once per frame void Update() { } public void Open() { _npcTrigger.Open(); } public void Close() { _npcTrigger.Close(); startButton.gameObject.SetActive(true); _craftingPanel.gameObject.SetActive(false); } public void OpenStartPanel() { _settlementPanel.gameObject.SetActive(true); _settlementPanel.SettlementEvent(); } public void CloseTitle() { title.gameObject.SetActive(false); } public void SetData(bool bo,NPCBuyData npcBuyData) { title.gameObject.SetActive(true); var data = JsonTab.Instance.tables.ShopNPC.Get(npcBuyData.npcID); textPro.text = bo ? data.Guestyes : data.Guestno; } private void OnDisable() { _craftButton.onClick.RemoveListener(CraftEvent); startButton.onClick.RemoveListener(GameStart); title.onClick.RemoveListener(CloseTitle); } void GameStart() { GameSystem.ins.StartNpcData(); startButton.gameObject.SetActive(false); } void CraftEvent() { _craftingPanel.gameObject.SetActive(true); _craftingPanel.StartOpen(GameSystem.ins.drawingManager.DrawOpen(), (bool bo) => { GameSystem.ins.Crafting(bo); }); } public void ResetCrafting(int id,int npcID) { getCrafting.SaveIcon(id); getNPCCrafting.SaveIcon(id); _npcCount.text = GameSystem.ins._npcBuyDatas.Count.ToString(); var npcData = JsonTab.Instance.tables.ShopNPC.Get(npcID); npcIcon.sprite = AssetBundleManager.ins.Sprite(npcData.Guesticon,AtlasType.NpcIcon); var slotData = JsonTab.Instance.tables.CraftingRecipes.Get(id); if (slotData.Levelprops1!=0) { _craftingUis[0].gameObject.SetActive(true); _craftingUis[0].SaveIcon(slotData.Levelprops1); } else { _craftingUis[0].gameObject.SetActive(false); } if (slotData.Levelprops2!=0) { _craftingUis[1].gameObject.SetActive(true); _craftingUis[1].SaveIcon(slotData.Levelprops2); } else { _craftingUis[1].gameObject.SetActive(false); } if (slotData.Levelprops3!=0) { _craftingUis[2].gameObject.SetActive(true); _craftingUis[2].SaveIcon(slotData.Levelprops3); } else { _craftingUis[2].gameObject.SetActive(false); } if (slotData.Levelprops4!=0) { _craftingUis[3].gameObject.SetActive(true); _craftingUis[3].SaveIcon(slotData.Levelprops4); } else { _craftingUis[3].gameObject.SetActive(false); } // var data = GameSystem.ins.DataAsset.crafting.FirstOrDefault(d => d.id == id); // List itemId = new List(); // 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]); // } } public void ResetSlotItem() { foreach (var slot in _slotUis) { slot.ResetIcon(); } } public void ResetItemData() { foreach (var item in _itemButtons) { item.gameObject.SetActive(false); } var allData=JsonTab.Instance.tables.Item.DataList; int index = 0; for (int i = 0; i < allData.Count; i++) { if (DataManager.GetItem(allData[i].ID)>0&&allData[i].Proptype!=0&&allData[i].Proptype==1) { if (index>=_itemButtons.Count ) { var add = Instantiate(itemObj.gameObject,itemParent); _itemButtons.Add(add.GetComponent()); } _itemButtons[index].gameObject.SetActive(true); _itemButtons[index].SetItemData(allData[i].ID); index++; } } ResetItem(); } private void ResetItem() { foreach (var item in _itemWapenButtons) { item.gameObject.SetActive(false); } var allData=JsonTab.Instance.tables.Item.DataList; int index = 0; for (int i = 0; i < allData.Count; i++) { if (DataManager.GetItem(allData[i].ID)>0&&allData[i].Proptype>1) { if (index>=_itemWapenButtons.Count ) { var add = Instantiate(itemObj.gameObject,wapenParent); _itemWapenButtons.Add(add.GetComponent()); } _itemWapenButtons[index].gameObject.SetActive(true); _itemWapenButtons[index].SetItemData(allData[i].ID); index++; } } } public void ResetGold() { _goldNum.text = DataManager.GetItem(2).ToString(); _diamondNum.text = DataManager.GetItem(3).ToString(); _physicalNum.text=DataManager.GetPhysical().ToString(); } }