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 List _itemButtons; [SerializeField] private List _slotUis; [SerializeField] private CraftingUI getCrafting; [SerializeField] private CraftingUI getNPCCrafting; [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 TextMeshProUGUI textPro; [SerializeField] private CraftingPanel _craftingPanel; [SerializeField] private SettlementPanel _settlementPanel; [SerializeField] private TextMeshProUGUI _npcCount; [SerializeField] private TextMeshProUGUI _goldNum; 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) { title.gameObject.SetActive(true); textPro.text = bo ? "售卖正确" : "售卖错误"; } 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) { getCrafting.SaveIcon(id); getNPCCrafting.SaveIcon(id); _npcCount.text = GameSystem.ins._npcBuyDatas.Count.ToString(); var slotData = JsonTab.Instance.tables.CraftingRecipes.Get(id); _craftingUis[0].SaveIcon(slotData.Levelprops1); _craftingUis[1].SaveIcon(slotData.Levelprops2); _craftingUis[2].SaveIcon(slotData.Levelprops3); _craftingUis[3].SaveIcon(slotData.Levelprops4); // 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) { 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++; } } } public void ResetGold() { _goldNum.text = DataManager.GetItem(2).ToString(); } }