WXGame/Blacksmith/Assets/Script/UI/ForgePanel.cs
2024-11-13 16:56:37 +08:00

125 lines
3.2 KiB
C#

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 List<ItemButton> _itemButtons;
[SerializeField] private List<SlotUI> _slotUis;
[SerializeField] private CraftingUI getCrafting;
[SerializeField] private CraftingUI getNPCCrafting;
[SerializeField] private List<CraftingUI> _craftingUis;
[SerializeField] private Button _craftButton;
[SerializeField] private NPCTrigger _npcTrigger;
[SerializeField] private Button startButton;
[SerializeField] private Button title;
[SerializeField] private TextMeshProUGUI textPro;
[SerializeField] private CraftingPanel _craftingPanel;
public Transform seletIcon;
// Start is called before the first frame update
void Start()
{
}
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 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);
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.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);
}
for (int i = 0; i < DataManager.ItemDatas.Count; i++)
{
_itemButtons[i].gameObject.SetActive(true);
_itemButtons[i].SetItemData(DataManager.ItemDatas[i].item.id);
}
}
}