126 lines
2.9 KiB
C#
126 lines
2.9 KiB
C#
using System.Collections.Generic;
|
|
using Obvious.Soap;
|
|
using TMPro;
|
|
using UFS3;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class UI_ShopDetailsPanel : MonoBehaviour
|
|
{
|
|
public PlayerProfile PlayerProfile;
|
|
|
|
public ScriptableEventNoParam OnNotRequiredMoneyHave;
|
|
|
|
public ScriptableEventNoParam OnPurshare;
|
|
|
|
[SerializeField]
|
|
private IntVariable _Shop_CurrentItemIDSelected;
|
|
|
|
[SerializeField]
|
|
private TextMeshProUGUI _Name;
|
|
|
|
[SerializeField]
|
|
private Image _Image;
|
|
|
|
[SerializeField]
|
|
private TextMeshProUGUI _Parameters;
|
|
|
|
[SerializeField]
|
|
private TextMeshProUGUI _Description;
|
|
|
|
[SerializeField]
|
|
private Image _PurchaseButtonBackground;
|
|
|
|
[SerializeField]
|
|
private ItemButtonParameters _ItemButtonParameters;
|
|
|
|
private void Start()
|
|
{
|
|
Refresh();
|
|
}
|
|
|
|
private void OnEnable()
|
|
{
|
|
_Shop_CurrentItemIDSelected.OnValueChanged += _Shop_CurrentItemIDSelected_OnValueChanged;
|
|
OnPurshare.OnRaised += Refresh;
|
|
Refresh();
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
_Shop_CurrentItemIDSelected.OnValueChanged -= _Shop_CurrentItemIDSelected_OnValueChanged;
|
|
OnPurshare.OnRaised -= Refresh;
|
|
Refresh();
|
|
}
|
|
|
|
private void _Shop_CurrentItemIDSelected_OnValueChanged(int id)
|
|
{
|
|
Refresh();
|
|
}
|
|
|
|
private void Refresh()
|
|
{
|
|
if (_Shop_CurrentItemIDSelected.Value >= 0)
|
|
{
|
|
BaseItemData itemById = PlayerProfile.ItemDatabase.GetItemById(_Shop_CurrentItemIDSelected);
|
|
_Name.text = itemById.name.Replace("(Clone)", "").TrimEnd();
|
|
_Image.sprite = itemById.Icon;
|
|
_Parameters.text = GetParametersString(itemById);
|
|
_Description.text = string.Empty;
|
|
_PurchaseButtonBackground.color = ((PlayerProfile.Money < itemById.Price) ? _ItemButtonParameters.itemBlockedColor : _ItemButtonParameters.itemAvailableColor);
|
|
}
|
|
}
|
|
|
|
private string GetParametersString(BaseItemData item)
|
|
{
|
|
return "" + item.StatisticText;
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
public void AddItem()
|
|
{
|
|
BaseItemData itemById = PlayerProfile.ItemDatabase.GetItemById(_Shop_CurrentItemIDSelected);
|
|
if (PlayerProfile.Money < itemById.Price)
|
|
{
|
|
OnNotRequiredMoneyHave.Raise();
|
|
return;
|
|
}
|
|
PlayerProfile.AddItem(Object.Instantiate(itemById));
|
|
PlayerProfile.Money -= itemById.Price;
|
|
OnPurshare.Raise();
|
|
}
|
|
}
|