WXGame/Blacksmith/Assets/Script/UI/ForgePanel.cs

241 lines
7.5 KiB
C#
Raw Normal View History

2024-11-13 16:56:37 +08:00
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
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-11-13 16:56:37 +08:00
[SerializeField] private List<ItemButton> _itemButtons;
[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;
[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-13 20:38:15 +08:00
[SerializeField] private Button _switchIButton;
[SerializeField] private Button _switchWButton;
2024-11-13 16:56:37 +08:00
[SerializeField] private TextMeshProUGUI textPro;
[SerializeField] private CraftingPanel _craftingPanel;
2024-11-21 10:26:47 +08:00
[SerializeField] private SettlementPanel _settlementPanel;
[SerializeField] private TextMeshProUGUI _npcCount;
[SerializeField] private TextMeshProUGUI _goldNum;
2024-12-21 14:05:40 +08:00
[SerializeField] private TextMeshProUGUI _diamondNum;
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-13 20:38:15 +08:00
_switchIButton.onClick.AddListener(ResetItemData);
_switchWButton.onClick.AddListener(ResetItem);
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();
startButton.gameObject.SetActive(true);
_craftingPanel.gameObject.SetActive(false);
}
2024-11-21 10:26:47 +08:00
public void OpenStartPanel()
{
_settlementPanel.gameObject.SetActive(true);
_settlementPanel.SettlementEvent();
}
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-13 20:38:15 +08:00
_switchIButton.onClick.RemoveListener(ResetItemData);
_switchWButton.onClick.RemoveListener(ResetItem);
2024-11-13 16:56:37 +08:00
}
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);
});
}
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);
if (slotData.Levelprops1!=0)
{
2024-12-11 13:58:55 +08:00
_craftingUis[0].gameObject.SetActive(true);
_craftingUis[0].SaveIcon(slotData.Levelprops1);
}
2024-12-11 13:58:55 +08:00
else
{
_craftingUis[0].gameObject.SetActive(false);
}
if (slotData.Levelprops2!=0)
{
2024-12-11 13:58:55 +08:00
_craftingUis[1].gameObject.SetActive(true);
_craftingUis[1].SaveIcon(slotData.Levelprops2);
}
2024-12-11 13:58:55 +08:00
else
{
_craftingUis[1].gameObject.SetActive(false);
}
if (slotData.Levelprops3!=0)
{
2024-12-11 13:58:55 +08:00
_craftingUis[2].gameObject.SetActive(true);
_craftingUis[2].SaveIcon(slotData.Levelprops3);
}
2024-12-11 13:58:55 +08:00
else
{
_craftingUis[2].gameObject.SetActive(false);
}
if (slotData.Levelprops4!=0)
{
2024-12-11 13:58:55 +08:00
_craftingUis[3].gameObject.SetActive(true);
_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-13 20:38:15 +08:00
if (DataManager.GetItem(allData[i].ID)>0&&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-13 20:38:15 +08:00
_switchIButton.gameObject.SetActive(false);
_switchWButton.gameObject.SetActive(true);
}
private void ResetItem()
{
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>1)
{
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++;
}
}
_switchIButton.gameObject.SetActive(true);
_switchWButton.gameObject.SetActive(false);
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-11-21 10:26:47 +08:00
}
2024-11-13 16:56:37 +08:00
}