163 lines
3.6 KiB
C#
163 lines
3.6 KiB
C#
using System.Collections.Generic;
|
|
using Michsky.UI.Heat;
|
|
using Obvious.Soap;
|
|
using UFS3;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class UI_SlotItemAssignButton : MonoBehaviour
|
|
{
|
|
public ItemType Type;
|
|
|
|
public BaseItemData ItemData;
|
|
|
|
public BoolVariable IsAssigmentModeEnabled;
|
|
|
|
public ItemTypeVariable SelectedItemTypeToAssign;
|
|
|
|
public BoolVariable isPlayerEquiped;
|
|
|
|
public ScriptableEventNoParam onPlayerEquipedNotifyCanAssignItem;
|
|
|
|
public ScriptableEventItemType OnAssignItem;
|
|
|
|
public ScriptableEventItemData OnItemAssignApply;
|
|
|
|
public ScriptableEventItemData OnRemoveItem;
|
|
|
|
public ScriptableEventGameObject OnUIItemPointerEnter;
|
|
|
|
public ScriptableEventGameObject OnUIItemPointerExit;
|
|
|
|
[SerializeField]
|
|
private List<Sprite> _Icons;
|
|
|
|
[SerializeField]
|
|
private ShopButtonManager _ShopButtonManager;
|
|
|
|
[SerializeField]
|
|
private GameObject _AssignButton;
|
|
|
|
[SerializeField]
|
|
private GameObject _RemoveButton;
|
|
|
|
[SerializeField]
|
|
private GameObject _CancelButton;
|
|
|
|
[SerializeField]
|
|
private ProgressBar _DurabilityBar;
|
|
|
|
[SerializeField]
|
|
private ItemButtonParameters _ItemButtonParameters;
|
|
|
|
private static bool _IsAssign;
|
|
|
|
private void Awake()
|
|
{
|
|
_ShopButtonManager = GetComponent<ShopButtonManager>();
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
SetData(ItemData);
|
|
ButtonCheck();
|
|
}
|
|
|
|
private void OnEnable()
|
|
{
|
|
OnItemAssignApply.OnRaised += OnItemAssignApplyOnOnRaised;
|
|
IsAssigmentModeEnabled.OnValueChanged += IsAssigmentModeEnabledOnOnValueChanged;
|
|
}
|
|
|
|
private void IsAssigmentModeEnabledOnOnValueChanged(bool value)
|
|
{
|
|
if (!value)
|
|
{
|
|
_IsAssign = false;
|
|
ButtonCheck();
|
|
}
|
|
}
|
|
|
|
private void ButtonCheck()
|
|
{
|
|
_AssignButton.SetActive(!IsAssigmentModeEnabled.Value && ItemData == null && !_IsAssign);
|
|
_RemoveButton.SetActive(ItemData != null);
|
|
_CancelButton.SetActive(IsAssigmentModeEnabled.Value && ItemData == null);
|
|
}
|
|
|
|
private void DurabilityBarUpdate()
|
|
{
|
|
_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 OnDisable()
|
|
{
|
|
OnItemAssignApply.OnRaised -= OnItemAssignApplyOnOnRaised;
|
|
IsAssigmentModeEnabled.OnValueChanged -= IsAssigmentModeEnabledOnOnValueChanged;
|
|
}
|
|
|
|
private void OnItemAssignApplyOnOnRaised(BaseItemData obj)
|
|
{
|
|
ItemType itemType = ((IItemType)obj).ItemType;
|
|
if (SelectedItemTypeToAssign.Value == Type && itemType == Type)
|
|
{
|
|
SetData(obj);
|
|
}
|
|
ButtonCheck();
|
|
}
|
|
|
|
public void SetData(BaseItemData obj)
|
|
{
|
|
ItemData = obj;
|
|
Sprite sprite = _Icons[(int)Type];
|
|
_ShopButtonManager.SetIcon(((object)obj == null) ? sprite : obj.Icon);
|
|
_ShopButtonManager.SetText(((object)obj == null) ? Type.ToString() : ItemData.name.Replace("(Clone)", "").Trim());
|
|
DurabilityBarUpdate();
|
|
ButtonCheck();
|
|
}
|
|
|
|
public void AssignItem()
|
|
{
|
|
if (isPlayerEquiped.Value)
|
|
{
|
|
onPlayerEquipedNotifyCanAssignItem.Raise();
|
|
return;
|
|
}
|
|
if (_IsAssign)
|
|
{
|
|
IsAssigmentModeEnabled.Value = false;
|
|
_IsAssign = false;
|
|
}
|
|
else if (ItemData == null)
|
|
{
|
|
_IsAssign = true;
|
|
IsAssigmentModeEnabled.Value = true;
|
|
SelectedItemTypeToAssign.Value = Type;
|
|
OnAssignItem.Raise(Type);
|
|
}
|
|
else
|
|
{
|
|
OnRemoveItem.Raise(ItemData);
|
|
SetData(null);
|
|
IsAssigmentModeEnabled.Value = false;
|
|
}
|
|
ButtonCheck();
|
|
}
|
|
|
|
public void PointerEnterHandler()
|
|
{
|
|
OnUIItemPointerEnter.Raise(base.gameObject);
|
|
}
|
|
|
|
public void PointerExitHandler()
|
|
{
|
|
OnUIItemPointerExit.Raise(base.gameObject);
|
|
}
|
|
}
|