150 lines
4.1 KiB
C#
150 lines
4.1 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] 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 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);
|
|
}
|
|
|
|
}
|
|
|
|
public void ResetGold()
|
|
{
|
|
_goldNum.text = GameSystem.ins.goldCoin.ToString();
|
|
}
|
|
}
|