164 lines
3.5 KiB
C#
164 lines
3.5 KiB
C#
using System.Collections.Generic;
|
|
using Michsky.UI.Heat;
|
|
using TMPro;
|
|
using UFS3;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class UI_ItemStatisticWindow : MonoBehaviour
|
|
{
|
|
[SerializeField]
|
|
private ModalWindowManager modalWindowManager;
|
|
|
|
[SerializeField]
|
|
private TextMeshProUGUI _Name;
|
|
|
|
[SerializeField]
|
|
private Image _Image;
|
|
|
|
[SerializeField]
|
|
private TextMeshProUGUI _Parameters;
|
|
|
|
[SerializeField]
|
|
private TextMeshProUGUI _Description;
|
|
|
|
[SerializeField]
|
|
private float XpositionOffsetForItemPanel;
|
|
|
|
[SerializeField]
|
|
private float XpositionOffsetForSetPanel;
|
|
|
|
private GameObject currentlyFocusedObject;
|
|
|
|
private BaseItemData itemData;
|
|
|
|
private bool isShowing;
|
|
|
|
private CanvasGroup canvasGroup;
|
|
|
|
private Animator animator;
|
|
|
|
private void Start()
|
|
{
|
|
canvasGroup = GetComponent<CanvasGroup>();
|
|
animator = GetComponent<Animator>();
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (isShowing && currentlyFocusedObject == null)
|
|
{
|
|
PointerExitHandler(currentlyFocusedObject);
|
|
}
|
|
if (isShowing && canvasGroup.alpha == 0f)
|
|
{
|
|
animator.Play("In");
|
|
}
|
|
}
|
|
|
|
public void PointerEnterHandler(GameObject go)
|
|
{
|
|
itemData = TryGetItem(go);
|
|
if (itemData == null)
|
|
{
|
|
itemData = null;
|
|
return;
|
|
}
|
|
currentlyFocusedObject = go;
|
|
isShowing = true;
|
|
modalWindowManager.OpenWindow();
|
|
Refresh();
|
|
}
|
|
|
|
public void PointerExitHandler(GameObject go)
|
|
{
|
|
if (!(go != currentlyFocusedObject))
|
|
{
|
|
currentlyFocusedObject = null;
|
|
itemData = null;
|
|
isShowing = false;
|
|
modalWindowManager.CloseWindow();
|
|
}
|
|
}
|
|
|
|
private void Refresh()
|
|
{
|
|
_Name.text = itemData.name.Replace("(Clone)", "").TrimEnd();
|
|
_Image.sprite = itemData.Icon;
|
|
_Parameters.text = GetParametersString(itemData);
|
|
_Description.text = string.Empty;
|
|
GetComponent<RectTransform>().anchoredPosition = GetAnchoredPosition(currentlyFocusedObject);
|
|
}
|
|
|
|
private BaseItemData TryGetItem(GameObject go)
|
|
{
|
|
BaseItemData result = null;
|
|
UI_SlotItemAssignButton component2;
|
|
if (go.TryGetComponent<UI_InventoryButton>(out var component))
|
|
{
|
|
result = component.ItemData;
|
|
}
|
|
else if (go.TryGetComponent<UI_SlotItemAssignButton>(out component2))
|
|
{
|
|
result = component2.ItemData;
|
|
}
|
|
return result;
|
|
}
|
|
|
|
private Vector2 GetAnchoredPosition(GameObject go)
|
|
{
|
|
Vector2 result = Vector2.zero;
|
|
UI_SlotItemAssignButton component2;
|
|
if (go.TryGetComponent<UI_InventoryButton>(out var _))
|
|
{
|
|
result = new Vector2(XpositionOffsetForItemPanel, 0f);
|
|
}
|
|
else if (go.TryGetComponent<UI_SlotItemAssignButton>(out component2))
|
|
{
|
|
result = new Vector2(XpositionOffsetForSetPanel, 0f);
|
|
}
|
|
return result;
|
|
}
|
|
|
|
private string GetParametersString(BaseItemData item)
|
|
{
|
|
string result = "" + item.StatisticText;
|
|
_ = ((IItemType)item).ItemType;
|
|
return result;
|
|
}
|
|
|
|
private string GetDescriptionString(BaseItemData item)
|
|
{
|
|
string text = item.Description;
|
|
ItemType itemType = ((IItemType)item).ItemType;
|
|
switch (itemType)
|
|
{
|
|
case ItemType.Lure:
|
|
{
|
|
text += "\n<size=32><b>Best for:</b></size>\n";
|
|
LureData obj2 = item as LureData;
|
|
List<string> lureFishNames = new List<string>();
|
|
obj2.attractedFish.ForEach(delegate(FishData fish)
|
|
{
|
|
lureFishNames.Add(fish.FishName);
|
|
});
|
|
text += string.Join(", ", lureFishNames);
|
|
break;
|
|
}
|
|
case ItemType.Bait:
|
|
{
|
|
text += "\n<size=32><b>Best for:</b></size>\n";
|
|
BaitData obj = item as BaitData;
|
|
List<string> baitFishNames = new List<string>();
|
|
obj.attractedFish.ForEach(delegate(FishData fish)
|
|
{
|
|
baitFishNames.Add(fish.FishName);
|
|
});
|
|
text += string.Join(", ", baitFishNames);
|
|
break;
|
|
}
|
|
}
|
|
return text;
|
|
}
|
|
}
|