仕入れItemView処理追加/DetailView追加
This commit is contained in:
parent
42c4b83da6
commit
f30ca21eb8
|
|
@ -2,29 +2,24 @@ using System;
|
|||
using UniRx;
|
||||
using UnityEngine;
|
||||
|
||||
public enum ShopHeaderTab
|
||||
{
|
||||
Material,
|
||||
Recipe
|
||||
}
|
||||
public class ShopHeaderView : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private ShopHeaderTabView materialTab;
|
||||
[SerializeField] private ShopHeaderTabView recipeTab;
|
||||
|
||||
public IReadOnlyReactiveProperty<ShopHeaderTab> Tab => tab;
|
||||
private readonly ReactiveProperty<ShopHeaderTab> tab = new ReactiveProperty<ShopHeaderTab>();
|
||||
public IReadOnlyReactiveProperty<ItemCategory> Tab => tab;
|
||||
private readonly ReactiveProperty<ItemCategory> tab = new ReactiveProperty<ItemCategory>();
|
||||
private void Start()
|
||||
{
|
||||
tab.AddTo(this);
|
||||
tab.Value = ShopHeaderTab.Material;
|
||||
tab.Value = ItemCategory.Material;
|
||||
tab.Subscribe(tabName =>
|
||||
{
|
||||
materialTab.SetToggle(tabName == ShopHeaderTab.Material);
|
||||
recipeTab.SetToggle(tabName == ShopHeaderTab.Recipe);
|
||||
materialTab.SetToggle(tabName == ItemCategory.Material);
|
||||
recipeTab.SetToggle(tabName == ItemCategory.Recipe);
|
||||
}).AddTo(this);
|
||||
materialTab.ClickObservable.Select(_ => ShopHeaderTab.Material)
|
||||
.Merge(recipeTab.ClickObservable.Select(_ => ShopHeaderTab.Recipe))
|
||||
materialTab.ClickObservable.Select(_ => ItemCategory.Material)
|
||||
.Merge(recipeTab.ClickObservable.Select(_ => ItemCategory.Recipe))
|
||||
.Subscribe(tabName =>
|
||||
{
|
||||
tab.Value = tabName;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,38 @@
|
|||
using System;
|
||||
using UniRx;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class ShopItemDetailView : MonoBehaviour
|
||||
{
|
||||
public static readonly string ItemDetailTag = "ItemDetail";
|
||||
private static readonly int OpenTrigger = Animator.StringToHash("OpenTrigger");
|
||||
private static readonly int CloseTrigger = Animator.StringToHash("CloseTrigger");
|
||||
|
||||
[SerializeField] private Animator backgroundAnimator;
|
||||
[SerializeField] private Text name;
|
||||
[SerializeField] private Image icon;
|
||||
[SerializeField] private Text text;
|
||||
[SerializeField] private Button closeButton;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
var data = LocalCacheManager.Load<ShopData>(ItemDetailTag);
|
||||
SetData(data);
|
||||
closeButton.OnClickAsObservable().Subscribe(_ =>
|
||||
{
|
||||
transform.parent.SetLocalScale(0);
|
||||
backgroundAnimator.SetTrigger(CloseTrigger);
|
||||
this.CallWaitForSeconds(.25f, () =>
|
||||
{
|
||||
TransitionManager.Instance.UnloadScene(GameScenes.ShoppingExplanation);
|
||||
});
|
||||
}).AddTo(this);
|
||||
}
|
||||
|
||||
private void SetData(ShopData shopData)
|
||||
{
|
||||
name.text = shopData.name;
|
||||
text.text = shopData.text;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 2014f6a58b674f40ad557f809d8b21f2
|
||||
timeCreated: 1631188062
|
||||
|
|
@ -29,17 +29,17 @@ public class ShopItemPurchaseButton : MonoBehaviour
|
|||
}
|
||||
}
|
||||
|
||||
public void SetItemActive(bool active)
|
||||
public void SetButtonActive(bool active)
|
||||
{
|
||||
switch (itemType)
|
||||
{
|
||||
case ShopItemType.Consumable:
|
||||
onObject.SetActive(active);
|
||||
offObject.SetActive(active);
|
||||
offObject.SetActive(!active);
|
||||
break;
|
||||
case ShopItemType.NonConsumable:
|
||||
onObject.SetActive(active);
|
||||
soldOutObject.SetActive(active);
|
||||
soldOutObject.SetActive(!active);
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
|
|
|
|||
|
|
@ -12,5 +12,27 @@ public class ShopItemView : MonoBehaviour
|
|||
[SerializeField] private Text price;
|
||||
[SerializeField] private Text stockCount;
|
||||
|
||||
public IObservable<Unit> DetailButtonObservable => detailButton.OnClickAsObservable().TakeUntilDestroy(this);
|
||||
public IObservable<Unit> PurchaseButtonObservable => purchaseButton.ClickObservable.TakeUntilDestroy(this);
|
||||
|
||||
public void SetData(ShopData shopData)
|
||||
{
|
||||
itemName.text = shopData.name;
|
||||
price.text = $"{shopData.price}";
|
||||
if (shopData.ConsumeType == ShopItemType.NonConsumable)
|
||||
{
|
||||
stockCount.transform.parent.gameObject.SetActive(false);
|
||||
}
|
||||
purchaseButton.SetItemType(shopData.ConsumeType);
|
||||
}
|
||||
|
||||
public void SetStockCount(int stock)
|
||||
{
|
||||
stockCount.text = $"{stock}";
|
||||
}
|
||||
|
||||
public void SetItemActive(bool active)
|
||||
{
|
||||
purchaseButton.SetButtonActive(active);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ public class ShopListView : MonoBehaviour
|
|||
[SerializeField] private ScrollRect scrollRect;
|
||||
[SerializeField] private ShopItemView itemViewPrefab;
|
||||
[SerializeField] private ShopHeaderView headerView;
|
||||
private List<(ShopHeaderTab, RectTransform)> tabs = new List<(ShopHeaderTab, RectTransform)>();
|
||||
private readonly List<(ItemCategory category, RectTransform content)> tabs = new List<(ItemCategory, RectTransform)>();
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
|
|
@ -17,35 +17,56 @@ public class ShopListView : MonoBehaviour
|
|||
{
|
||||
DestroyImmediate(scrollRect.content.GetChild(0).gameObject);
|
||||
}
|
||||
tabs.Add((ShopHeaderTab.Recipe, scrollRect.content));
|
||||
tabs.Add((ItemCategory.Recipe, scrollRect.content));
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
headerView.Tab.Subscribe(tab =>
|
||||
{
|
||||
// scrollRect.verticalNormalizedPosition = 1;
|
||||
scrollRect.verticalNormalizedPosition = 1;
|
||||
tabs.ForEach(x =>
|
||||
{
|
||||
x.Item2.gameObject.SetActive(x.Item1 == tab);
|
||||
if (x.Item1 == tab)
|
||||
x.content.gameObject.SetActive(x.category == tab);
|
||||
if (x.category == tab)
|
||||
{
|
||||
scrollRect.content = x.Item2;
|
||||
scrollRect.content = x.content;
|
||||
}
|
||||
});
|
||||
}).AddTo(this);
|
||||
}
|
||||
|
||||
public ShopItemView AddItem()
|
||||
public ShopItemView AddItemView(ShopData shopData)
|
||||
{
|
||||
var youTab = ShopHeaderTab.Material;
|
||||
var index = tabs.FindIndex(x => x.Item1 == youTab);
|
||||
var tabCategory = GetTabCategory(shopData.Category);
|
||||
var index = tabs.FindIndex(x => x.category == tabCategory);
|
||||
if (index == -1)
|
||||
{
|
||||
index = tabs.Count;
|
||||
tabs.Add((youTab, Instantiate(scrollRect.content, scrollRect.content.parent)));
|
||||
tabs.Add((tabCategory, Instantiate(scrollRect.content, scrollRect.content.parent)));
|
||||
}
|
||||
var itemView = Instantiate(itemViewPrefab, tabs[index].Item2);
|
||||
var itemView = Instantiate(itemViewPrefab, tabs[index].content);
|
||||
itemView.SetData(shopData);
|
||||
// show detail view
|
||||
itemView.DetailButtonObservable.Subscribe(_ =>
|
||||
{
|
||||
LocalCacheManager.Save(ShopItemDetailView.ItemDetailTag, shopData);
|
||||
TransitionManager.Instance.LoadSceneAdditive(GameScenes.ShoppingExplanation);
|
||||
}).AddTo(itemView);
|
||||
return itemView;
|
||||
}
|
||||
|
||||
private ItemCategory GetTabCategory(ItemCategory category)
|
||||
{
|
||||
switch (category)
|
||||
{
|
||||
case ItemCategory.Material:
|
||||
return ItemCategory.Material;
|
||||
case ItemCategory.Recipe:
|
||||
case ItemCategory.Pan:
|
||||
return ItemCategory.Recipe;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException(nameof(category), category, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ public enum ShopItemType
|
|||
public sealed class ShopData {
|
||||
public int id;
|
||||
public int nameId;
|
||||
public int itemId;
|
||||
public string name;
|
||||
public int price;
|
||||
public string text;
|
||||
|
|
|
|||
Loading…
Reference in New Issue