Skip to content

Commit

Permalink
add iap shop resource image path rule
Browse files Browse the repository at this point in the history
  • Loading branch information
jonny-jeahyunchoi committed Dec 10, 2024
1 parent ba2c82b commit 6d08655
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8585,7 +8585,7 @@ MonoBehaviour:
- {fileID: 3000915477837454109}
- {fileID: 9151308653001728383}
- {fileID: 3138576735815653638}
rewardLayout: {fileID: 5017105035265833004}
rewardLayout: {fileID: 3253513295592729325}
mileageObj: {fileID: 8465437567864997215}
mileageText: {fileID: 2892489026414283078}
--- !u!114 &4140235205676321935
Expand Down
33 changes: 31 additions & 2 deletions nekoyume/Assets/_Scripts/ApiClient/IAPServiceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Text.Json;
using System.Threading.Tasks;
using Libplanet.Crypto;
using Nekoyume.L10n;
using UniRx;
using UnityEngine;

Expand Down Expand Up @@ -35,6 +36,34 @@ public static bool CheckSku(this InAppPurchaseServiceClient.ProductSchema produc
{
return product.GoogleSku == sku || product.AppleSku == sku || product.AppleSkuK == sku;
}
public static string GetCode(this InAppPurchaseServiceClient.ProductSchema product)
{
var skuInfos = product.GoogleSku.Split("_");
return skuInfos.Last();
}
public static string GetPopupTitleText(this InAppPurchaseServiceClient.ProductSchema product)
{
if (!DateTime.TryParse(product.OpenTimestamp, out var openDate))
{
NcDebug.LogError($"Invalid OpenTimestamp: {product.OpenTimestamp}");
return L10nManager.Localize($"MOBILE_SHOP_PRODUCT_{product.GetCode()}_POPUP_TITLE");
}

if (!DateTime.TryParse(product.CloseTimestamp, out var closeDate))
{
NcDebug.LogError($"Invalid CloseTimestamp: {product.CloseTimestamp}");
return L10nManager.Localize($"MOBILE_SHOP_PRODUCT_{product.GetCode()}_POPUP_TITLE");
}
return L10nManager.Localize($"MOBILE_SHOP_PRODUCT_{product.GetCode()}_POPUP_TITLE", openDate.ToString("MM/dd"),closeDate.ToString("MM/dd"));
}
public static string GetListImagePath(this InAppPurchaseServiceClient.ProductSchema product)
{
return $"shop/images/product/list/{product.GetCode()}.png";
}
public static string GetDetailImagePath(this InAppPurchaseServiceClient.ProductSchema product)
{
return $"shop/images/product/detail/{product.GetCode()}.png";
}
}

public class IAPServiceManager : IDisposable
Expand All @@ -60,13 +89,13 @@ public IAPServiceManager(string url, InAppPurchaseServiceClient.Store store)
Debug.LogError($"[{nameof(IAPServiceManager)}] IAPServiceHost is null.");
return;
}

_client = new InAppPurchaseServiceClient(url);
_store = store;

// 플렛폼에 따라 기본적으로 사용하는 패키지 이름이 다르기 때문에 그에 맞게 설정해준다.
#if UNITY_IOS || UNITY_ANDROID
if(InAppPurchaseServiceClient.PackageNameTypeConverter.InvalidEnumMapping.TryGetValue(Application.identifier, out var packageName))
if (InAppPurchaseServiceClient.PackageNameTypeConverter.InvalidEnumMapping.TryGetValue(Application.identifier, out var packageName))
{
_packageName = Enum.Parse<InAppPurchaseServiceClient.PackageName>(packageName);
}
Expand Down
20 changes: 16 additions & 4 deletions nekoyume/Assets/_Scripts/UI/Module/IAP/IAPShopProductCellView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public class IAPShopProductCellView : MonoBehaviour
[SerializeField]
private IAPRewardView[] rewardViews;
[SerializeField]
private GameObject rewardLayout;
private CenteredGridLayout rewardLayout;
[SerializeField]
private GameObject mileageObj;
[SerializeField]
Expand Down Expand Up @@ -133,7 +133,7 @@ public async UniTask RefreshLocalized()
private async UniTask DownLoadImage()
{
backgroundImage.sprite = await Util.DownloadTexture($"{MobileShop.MOBILE_L10N_SCHEMA.Host}/{_data.BgPath}");
productImage.sprite = await Util.DownloadTexture($"{MobileShop.MOBILE_L10N_SCHEMA.Host}/{_data.Path}");
productImage.sprite = await Util.DownloadTexture($"{MobileShop.MOBILE_L10N_SCHEMA.Host}/{_data.GetListImagePath()}");
productImage.SetNativeSize();
}

Expand Down Expand Up @@ -167,13 +167,13 @@ private void Refresh()
_rect.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, 0, 230);
bottomButtonLayoutElement.minHeight = 65;
bottomLayout.spacing = 0;
rewardLayout.SetActive(false);
rewardLayout.gameObject.SetActive(false);
break;
case InAppPurchaseServiceClient.ProductAssetUISize._1x2:
_rect.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, 0, 467);
bottomButtonLayoutElement.minHeight = 75;
bottomLayout.spacing = 3;
rewardLayout.SetActive(true);
rewardLayout.gameObject.SetActive(true);

var iapRewardIndex = 0;
foreach (var item in _data.FavList)
Expand All @@ -192,6 +192,18 @@ private void Refresh()
iapRewardIndex++;
}
}

//4개인 경우 2x2로 배치
if(iapRewardIndex == 4)
{
rewardLayout.constraint = GridLayoutGroup.Constraint.FixedColumnCount;
rewardLayout.constraintCount = 2;
}
else
{
rewardLayout.constraint = GridLayoutGroup.Constraint.Flexible;
}

for (; iapRewardIndex < rewardViews.Length; iapRewardIndex++)
{
rewardViews[iapRewardIndex].gameObject.SetActive(false);
Expand Down
7 changes: 4 additions & 3 deletions nekoyume/Assets/_Scripts/UI/Widget/Popup/ShopListPopup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ public void PurchaseButtonLoadingEnd()

private async UniTask DownloadTexture()
{
productBgImage.sprite = await Util.DownloadTexture($"{MobileShop.MOBILE_L10N_SCHEMA.Host}/{L10nManager.Localize(_data.PopupPathKey)}");
productBgImage.sprite = await Util.DownloadTexture($"{MobileShop.MOBILE_L10N_SCHEMA.Host}/{_data.GetDetailImagePath()}");
}

public async UniTask Show(InAppPurchaseServiceClient.ProductSchema data, UnityEngine.Purchasing.Product purchasingData, bool ignoreShowAnimation = false)
Expand Down Expand Up @@ -231,7 +231,9 @@ public async UniTask Show(InAppPurchaseServiceClient.ProductSchema data, UnityEn
break;
}

if(_data.Mileage > 0)
titleText.text = _data.GetPopupTitleText().Replace("\\n", "\n");

if (_data.Mileage > 0)
{
mileageObject.SetActive(true);
mileageText.text = _data.Mileage.ToString("N0");
Expand All @@ -242,7 +244,6 @@ public async UniTask Show(InAppPurchaseServiceClient.ProductSchema data, UnityEn
}

// Initialize IAP Reward

var iapRewardIndex = 0;
foreach (var item in _data.FavList)
{
Expand Down

0 comments on commit 6d08655

Please sign in to comment.