diff --git a/Gameton-06/Assets/Gameton/Resources/UI/Prefabs/UI.ShopUI.prefab b/Gameton-06/Assets/Gameton/Resources/UI/Prefabs/UI.ShopUI.prefab index 70b2a2d1..5a8e6c3b 100644 --- a/Gameton-06/Assets/Gameton/Resources/UI/Prefabs/UI.ShopUI.prefab +++ b/Gameton-06/Assets/Gameton/Resources/UI/Prefabs/UI.ShopUI.prefab @@ -22663,12 +22663,12 @@ GameObject: m_Component: - component: {fileID: 2640998817256912009} m_Layer: 5 - m_Name: PositionPopUpLayout + m_Name: PotionPopUpLayout m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 - m_IsActive: 0 + m_IsActive: 1 --- !u!224 &2640998817256912009 RectTransform: m_ObjectHideFlags: 0 diff --git a/Gameton-06/Assets/Gameton/Scripts/UI/ShopItemUI.cs b/Gameton-06/Assets/Gameton/Scripts/UI/ShopItemUI.cs new file mode 100644 index 00000000..01c1696f --- /dev/null +++ b/Gameton-06/Assets/Gameton/Scripts/UI/ShopItemUI.cs @@ -0,0 +1,61 @@ +using System.Collections; +using System.Collections.Generic; +using TMPro; +using UniRx; +using UnityEngine; +using UnityEngine.UI; + +namespace TON +{ + // View + public class ShopItemUI : MonoBehaviour + { + [SerializeField] private Image image; + [SerializeField] private TextMeshProUGUI title; + [SerializeField] private TextMeshProUGUI txtPrice; + [SerializeField] private Button buyButton; + + public void Bind(ShopItemPresenter presenter) + { + + } + } + + // Presenter + public class ShopItemPresenter + { + public ReactiveProperty Price { get; set; } + public ReactiveProperty PotionType { get; set; } + public ReactiveProperty Quantity { get; set; } + public ReactiveCommand BuyCommand { get; set; } + + private ShopItemModel _model; + + public ShopItemPresenter(ShopPresenter shopPresenter, ShopItemModel model) + { + _model = model; + + Price = new ReactiveProperty(_model.Price); + PotionType = new ReactiveProperty(_model.PotionType); + Quantity = new ReactiveProperty(_model.Quantity); + + BuyCommand = new ReactiveCommand(); + BuyCommand.Subscribe(_ => shopPresenter.BuyPotion(this)); + } + } + + // Model + public class ShopItemModel + { + public int Price; + public string PotionType; + public int Quantity; + + public ShopItemModel(int price, string postionType, int quantity) + { + Price = price; + PotionType = postionType; + Quantity = quantity; + } + } +} diff --git a/Gameton-06/Assets/Gameton/Scripts/UI/ShopItemUI.cs.meta b/Gameton-06/Assets/Gameton/Scripts/UI/ShopItemUI.cs.meta new file mode 100644 index 00000000..bf425b6c --- /dev/null +++ b/Gameton-06/Assets/Gameton/Scripts/UI/ShopItemUI.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 87c3d53b1193f3c4bb806d0427e769ca +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Gameton-06/Assets/Gameton/Scripts/UI/ShopPresenter.cs b/Gameton-06/Assets/Gameton/Scripts/UI/ShopPresenter.cs new file mode 100644 index 00000000..c9f383c4 --- /dev/null +++ b/Gameton-06/Assets/Gameton/Scripts/UI/ShopPresenter.cs @@ -0,0 +1,70 @@ +using System.Collections; +using System.Collections.Generic; +using UniRx; +using UnityEngine; + +namespace TON +{ + public class ShopPresenter + { + private int hpPotionPrice1 = 200; // HP 포션 가격 + private int hpPotionPrice5 = 1000; // HP 포션 가격 + private int hpPotionPrice20 = 3600; // HP 포션 가격 + private int mpPotionPrice1 = 400; // MP 포션 가격 + private int mpPotionPrice5 = 2000; // MP 포션 가격 + private int mpPotionPrice20 = 7600; // MP 포션 가격 + + + private PlayerDataManager playerDataManager; + private List shopItemModels = new(); + + public ReactiveCollection ShopItems { get; } = new(); + + public ShopPresenter() + { + // 싱글톤으로 PlayerDataManager 접근 + playerDataManager = PlayerDataManager.Singleton; + + if (playerDataManager == null) + { + Debug.LogError("PlayerDataManager가 초기화되지 않았습니다."); + } + + shopItemModels.Add(new ShopItemModel(hpPotionPrice1, "hp", 1)); + shopItemModels.Add(new ShopItemModel(hpPotionPrice5, "hp", 5)); + shopItemModels.Add(new ShopItemModel(hpPotionPrice20, "hp", 20)); + shopItemModels.Add(new ShopItemModel(mpPotionPrice1, "mp", 1)); + shopItemModels.Add(new ShopItemModel(mpPotionPrice5, "mp", 5)); + shopItemModels.Add(new ShopItemModel(mpPotionPrice20, "mp", 20)); + + foreach (var item in shopItemModels) + { + ShopItems.Add(new ShopItemPresenter(this, item)); + } + } + + // 포션 구매 메서드 + private void BuyPotion(int price, string potionType, int quantity) + { + if (playerDataManager.goldAmount >= price) + { + playerDataManager.UseGold(price, (isSuccess) => + { + if (isSuccess) + { + if (potionType == "hp") + { + playerDataManager.AddPotion("HP", quantity); + } + else if (potionType == "mp") + { + playerDataManager.AddPotion("MP", quantity); + } + + UIManager.Singleton.UpdateCashData(); + } + }); + } + } + } +} diff --git a/Gameton-06/Assets/Gameton/Scripts/UI/ShopPresenter.cs.meta b/Gameton-06/Assets/Gameton/Scripts/UI/ShopPresenter.cs.meta new file mode 100644 index 00000000..2da51346 --- /dev/null +++ b/Gameton-06/Assets/Gameton/Scripts/UI/ShopPresenter.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 8729e0724cdac06409677bf2e8bec238 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Gameton-06/Assets/Gameton/Scripts/UI/ShopUI.cs b/Gameton-06/Assets/Gameton/Scripts/UI/ShopUI.cs index 0d8a33ca..aa17b845 100644 --- a/Gameton-06/Assets/Gameton/Scripts/UI/ShopUI.cs +++ b/Gameton-06/Assets/Gameton/Scripts/UI/ShopUI.cs @@ -6,56 +6,12 @@ namespace TON { [SerializeField] private GameObject HeartPopUp; [SerializeField] private GameObject PositionPopUp; - - [SerializeField] private int hpPotionPrice1 = 200; // HP 포션 가격 - [SerializeField] private int hpPotionPrice5 = 1000; // HP 포션 가격 - [SerializeField] private int hpPotionPrice20 = 3600; // HP 포션 가격 - [SerializeField] private int mpPotionPrice1 = 400; // MP 포션 가격 - [SerializeField] private int mpPotionPrice5 = 2000; // MP 포션 가격 - [SerializeField] private int mpPotionPrice20 = 7600; // MP 포션 가격 - - private PlayerDataManager playerDataManager; - - void Start() - { - // 싱글톤으로 PlayerDataManager 접근 - playerDataManager = PlayerDataManager.Singleton; - - if (playerDataManager == null) - { - Debug.LogError("PlayerDataManager가 초기화되지 않았습니다."); - } - } - + public void OnClickLobbyButton() { Main.Singleton.ChangeScene(SceneType.Lobby); } - // 포션 구매 메서드 - private void BuyPotion(int price, string potionType, int quantity) - { - if (playerDataManager.goldAmount >= price) - { - playerDataManager.UseGold(price, (isSuccess) => - { - if (isSuccess) - { - if (potionType == "hp") - { - playerDataManager.AddPotion("HP", quantity); - } - else if (potionType == "mp") - { - playerDataManager.AddPotion("MP", quantity); - } - - UIManager.Singleton.UpdateCashData(); - } - }); - } - } - // HP 포션 구매 버튼 클릭 시 호출 public void OnClickBuyHpPotion1Button() {