Files
Ultimate-Fishing-Simulator-…/Assets/Scripts/Assembly-CSharp/UI_InventoryButton.cs
2026-03-04 09:37:33 +08:00

220 lines
5.8 KiB
C#

using System;
using Michsky.UI.Heat;
using Obvious.Soap;
using TMPro;
using UFS3;
using UnityEngine;
using UnityEngine.UI;
public class UI_InventoryButton : MonoBehaviour
{
public BaseItemData ItemData;
public ScriptableListFishingSetData FishingSetsList;
public BoolVariable IsAssignModeEnabled;
public ItemTypeVariable SelectedItemTypeToAssign;
public ScriptableEventItemData OnAssignItem;
public ScriptableEventItemData OnSellItemFromInventory;
public ScriptableEventItemData OnRemoveItem;
public ScriptableEventNoParam OnSell;
public BoolVariable isPlayerEquiped;
public ScriptableEventNoParam onPlayerEquipedNotifyCanAssignItem;
public ScriptableEventItemData OnItemAssignDirect;
public ScriptableEventGameObject OnUIItemPointerEnter;
public ScriptableEventGameObject OnUIItemPointerExit;
private ShopButtonManager _ShopButtonManager;
[SerializeField]
private ProgressBar _DurabilityBar;
[SerializeField]
private TextMeshProUGUI descriptionLabels;
[SerializeField]
private TextMeshProUGUI descriptionValues;
[SerializeField]
private ItemButtonParameters _ItemButtonParameters;
[SerializeField]
private ButtonManager _EquipDirect;
private void Start()
{
Refresh();
}
private void OnEnable()
{
RefreshState(IsAssignModeEnabled.Value);
IsAssignModeEnabled.OnValueChanged += RefreshState;
UI_FishingSlotsController.OnInventorySlotNumberChange += Refresh;
}
private void OnDisable()
{
IsAssignModeEnabled.OnValueChanged -= RefreshState;
UI_FishingSlotsController.OnInventorySlotNumberChange -= Refresh;
}
public void Initialize(BaseItemData itemData, ItemType itemType)
{
ItemData = itemData;
RefreshState(IsAssignModeEnabled.Value);
Refresh();
}
public void TryAssign()
{
ItemType itemType = ((IItemType)ItemData).ItemType;
int currentInventorySlotNumber = UI_FishingSlotsController.CurrentInventorySlotNumber;
if (IsAssignModeEnabled.Value && SelectedItemTypeToAssign.Value == itemType)
{
switch (itemType)
{
case ItemType.Rod:
FishingSetsList[currentInventorySlotNumber].Rod = (RodData)ItemData;
break;
case ItemType.Reel:
FishingSetsList[currentInventorySlotNumber].Reel = (ReelData)ItemData;
break;
case ItemType.Line:
FishingSetsList[currentInventorySlotNumber].Line = (LineData)ItemData;
break;
case ItemType.Bobber:
FishingSetsList[currentInventorySlotNumber].Bobber = (BobberData)ItemData;
FishingSetsList[currentInventorySlotNumber].SetType = FishingMethodType.Float;
break;
case ItemType.Hook:
FishingSetsList[currentInventorySlotNumber].Hook = (HookData)ItemData;
break;
case ItemType.Lure:
FishingSetsList[currentInventorySlotNumber].Lure = (LureData)ItemData;
FishingSetsList[currentInventorySlotNumber].SetType = FishingMethodType.Spinning;
break;
case ItemType.Bait:
FishingSetsList[currentInventorySlotNumber].Bait = (BaitData)ItemData;
break;
default:
throw new ArgumentOutOfRangeException();
}
OnAssignItem.Raise(ItemData);
IsAssignModeEnabled.Value = false;
}
}
public void TryAssignDirect()
{
if (!IsAssignModeEnabled.Value)
{
if (isPlayerEquiped.Value)
{
onPlayerEquipedNotifyCanAssignItem.Raise();
return;
}
OnItemAssignDirect.Raise(ItemData);
OnAssignItem.Raise(ItemData);
}
}
private void RefreshState(bool value)
{
if (((IItemType)ItemData).ItemType == SelectedItemTypeToAssign.Value)
{
if (_ShopButtonManager == null)
{
_ShopButtonManager = GetComponent<ShopButtonManager>();
}
_ShopButtonManager.SetState(value ? ShopButtonManager.State.Purchased : ShopButtonManager.State.Default);
}
}
private void DurabilityBarRefresh()
{
_DurabilityBar.gameObject.gameObject.SetActive(ItemData != null);
_DurabilityBar.SetValue(Mathf.Clamp(((object)ItemData == null) ? 0f : ItemData.Durabilty, 0.05f, 1f));
if (ItemData != null)
{
_DurabilityBar.barImage.color = _ItemButtonParameters.GetColor(ItemData.Durabilty);
_DurabilityBar.transform.Find("Frame").GetComponent<Image>().color = _ItemButtonParameters.GetColor(ItemData.Durabilty);
}
}
private void EquipDirectRefresh()
{
ItemType itemType = ((IItemType)ItemData).ItemType;
int currentInventorySlotNumber = UI_FishingSlotsController.CurrentInventorySlotNumber;
switch (itemType)
{
case ItemType.Rod:
_EquipDirect.Interactable(value: true);
break;
case ItemType.Reel:
_EquipDirect.Interactable(FishingSetsList[currentInventorySlotNumber].Rod != null);
break;
case ItemType.Line:
_EquipDirect.Interactable(FishingSetsList[currentInventorySlotNumber].Reel != null);
break;
case ItemType.Bobber:
_EquipDirect.Interactable(FishingSetsList[currentInventorySlotNumber].Line != null);
break;
case ItemType.Hook:
_EquipDirect.Interactable(FishingSetsList[currentInventorySlotNumber].Bobber != null);
break;
case ItemType.Lure:
_EquipDirect.Interactable(FishingSetsList[currentInventorySlotNumber].Line != null);
break;
case ItemType.Bait:
_EquipDirect.Interactable(FishingSetsList[currentInventorySlotNumber].Hook != null);
break;
default:
throw new ArgumentOutOfRangeException();
}
}
public void Refresh()
{
if (!(ItemData == null))
{
_ShopButtonManager = GetComponent<ShopButtonManager>();
string text = ItemData.name;
text = text.Replace("(Clone)", "");
_ShopButtonManager.SetText(text);
_ShopButtonManager.SetIcon(ItemData.Icon);
_ShopButtonManager.SetPrice(ItemData.Price.ToString());
DurabilityBarRefresh();
EquipDirectRefresh();
}
}
public void SellItem()
{
OnSellItemFromInventory.Raise(ItemData);
OnRemoveItem.Raise(ItemData);
OnSell.Raise();
_ShopButtonManager.OnPointerEnter(null);
}
public void PointerEnterHandler()
{
OnUIItemPointerEnter.Raise(base.gameObject);
}
public void PointerExitHandler()
{
OnUIItemPointerExit.Raise(base.gameObject);
}
}