82 lines
2.9 KiB
C#
82 lines
2.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.Localization.Components;
|
|
using UnityEngine.UI;
|
|
|
|
namespace DDD
|
|
{
|
|
public class ItemDetailPanel : MonoBehaviour, IEventHandler<ItemSlotSelectedEvent>
|
|
{
|
|
[SerializeField] private TextMeshProUGUI _nameText;
|
|
[SerializeField] private LocalizeStringEvent _nameLocalizer;
|
|
[SerializeField] private TextMeshProUGUI _descriptionText;
|
|
[SerializeField] private LocalizeStringEvent _descriptionLocalizer;
|
|
[SerializeField] private Image _cookwareImage;
|
|
[SerializeField] private Transform _tasteHashTagContent;
|
|
|
|
private RestaurantManagementSo _restaurantManagementSo;
|
|
private List<RectTransform> _tasteHashTags = new();
|
|
|
|
private async void Start()
|
|
{
|
|
_restaurantManagementSo =
|
|
await AssetManager.LoadAsset<RestaurantManagementSo>(DataConstants.RestaurantManagementSo);
|
|
Debug.Assert(_restaurantManagementSo != null, "RestaurantManagementSo is null");
|
|
|
|
_nameText.text = string.Empty;
|
|
_descriptionText.text = string.Empty;
|
|
_cookwareImage.sprite = null;
|
|
}
|
|
|
|
private void OnEnable()
|
|
{
|
|
EventBus.Register<ItemSlotSelectedEvent>(this);
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
EventBus.Unregister<ItemSlotSelectedEvent>(this);
|
|
}
|
|
|
|
public void Invoke(ItemSlotSelectedEvent evt)
|
|
{
|
|
Show(evt.Model);
|
|
}
|
|
|
|
public void Show(ItemViewModel model)
|
|
{
|
|
_nameLocalizer.StringReference = LocalizationManager.Instance.GetLocalizedString(model.NameKey);
|
|
_descriptionLocalizer.StringReference =
|
|
LocalizationManager.Instance.GetLocalizedString(model.DescriptionKey);
|
|
_cookwareImage.sprite = DataManager.Instance.GetSprite(model.Id);
|
|
UpdateTasteHashTags(model);
|
|
}
|
|
|
|
private void UpdateTasteHashTags(ItemViewModel model)
|
|
{
|
|
foreach (Transform content in _tasteHashTagContent)
|
|
{
|
|
Destroy(content.gameObject);
|
|
}
|
|
|
|
_tasteHashTags.Clear();
|
|
List<TasteData> tasteDatas = model.GetTasteDatas;
|
|
|
|
var outlineColor = model.RecipeType switch
|
|
{
|
|
RecipeType.FoodRecipe => _restaurantManagementSo.FoodTasteOutlineColor,
|
|
RecipeType.DrinkRecipe => _restaurantManagementSo.DrinkTasteOutlineColor,
|
|
_ => throw new ArgumentOutOfRangeException()
|
|
};
|
|
|
|
foreach (var tasteData in tasteDatas)
|
|
{
|
|
var newTasteHashTag = Instantiate(_restaurantManagementSo.TasteHashTagSlotUiPrefab);
|
|
newTasteHashTag.Initialize(outlineColor, tasteData);
|
|
_tasteHashTags.Add(newTasteHashTag.RectTransform);
|
|
}
|
|
}
|
|
}
|
|
} |