diff --git a/popcorn/Assets/MyGame/Scenes/shopping/Scripts/ShopHeaderView.cs b/popcorn/Assets/MyGame/Scenes/shopping/Scripts/ShopHeaderView.cs index 85cfce0f..929189f8 100644 --- a/popcorn/Assets/MyGame/Scenes/shopping/Scripts/ShopHeaderView.cs +++ b/popcorn/Assets/MyGame/Scenes/shopping/Scripts/ShopHeaderView.cs @@ -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 Tab => tab; - private readonly ReactiveProperty tab = new ReactiveProperty(); + public IReadOnlyReactiveProperty Tab => tab; + private readonly ReactiveProperty tab = new ReactiveProperty(); 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; diff --git a/popcorn/Assets/MyGame/Scenes/shopping/Scripts/ShopItemDetailView.cs b/popcorn/Assets/MyGame/Scenes/shopping/Scripts/ShopItemDetailView.cs new file mode 100644 index 00000000..68547fa1 --- /dev/null +++ b/popcorn/Assets/MyGame/Scenes/shopping/Scripts/ShopItemDetailView.cs @@ -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(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; + } +} \ No newline at end of file diff --git a/popcorn/Assets/MyGame/Scenes/shopping/Scripts/ShopItemDetailView.cs.meta b/popcorn/Assets/MyGame/Scenes/shopping/Scripts/ShopItemDetailView.cs.meta new file mode 100644 index 00000000..ddbad85e --- /dev/null +++ b/popcorn/Assets/MyGame/Scenes/shopping/Scripts/ShopItemDetailView.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 2014f6a58b674f40ad557f809d8b21f2 +timeCreated: 1631188062 \ No newline at end of file diff --git a/popcorn/Assets/MyGame/Scenes/shopping/Scripts/ShopItemPurchaseButton.cs b/popcorn/Assets/MyGame/Scenes/shopping/Scripts/ShopItemPurchaseButton.cs index cf37159d..13a0d90c 100644 --- a/popcorn/Assets/MyGame/Scenes/shopping/Scripts/ShopItemPurchaseButton.cs +++ b/popcorn/Assets/MyGame/Scenes/shopping/Scripts/ShopItemPurchaseButton.cs @@ -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(); diff --git a/popcorn/Assets/MyGame/Scenes/shopping/Scripts/ShopItemView.cs b/popcorn/Assets/MyGame/Scenes/shopping/Scripts/ShopItemView.cs index 08cdeb7d..7fe20a67 100644 --- a/popcorn/Assets/MyGame/Scenes/shopping/Scripts/ShopItemView.cs +++ b/popcorn/Assets/MyGame/Scenes/shopping/Scripts/ShopItemView.cs @@ -12,5 +12,27 @@ public class ShopItemView : MonoBehaviour [SerializeField] private Text price; [SerializeField] private Text stockCount; + public IObservable DetailButtonObservable => detailButton.OnClickAsObservable().TakeUntilDestroy(this); public IObservable 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); + } } diff --git a/popcorn/Assets/MyGame/Scenes/shopping/Scripts/ShopListView.cs b/popcorn/Assets/MyGame/Scenes/shopping/Scripts/ShopListView.cs index 682ca8f7..0156a3d8 100644 --- a/popcorn/Assets/MyGame/Scenes/shopping/Scripts/ShopListView.cs +++ b/popcorn/Assets/MyGame/Scenes/shopping/Scripts/ShopListView.cs @@ -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); + } + } } diff --git a/popcorn/Assets/MyGame/Scripts/SpreadsheetData.cs b/popcorn/Assets/MyGame/Scripts/SpreadsheetData.cs index 8e5cc12d..61cc29ed 100644 --- a/popcorn/Assets/MyGame/Scripts/SpreadsheetData.cs +++ b/popcorn/Assets/MyGame/Scripts/SpreadsheetData.cs @@ -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;