|
- using System;
- using System.Collections.Generic;
- using CIG;
- using CIG.Translation;
- using CIGEnums;
- using SUISS.Core;
- using Tweening;
- using UnityEngine;
- using UnityEngine.UI;
-
- public class IAPShopItem : ShopItem
- {
- public void Init(CIG3StoreProduct storeProduct, ShopType shopType, int index, Action<CIG3StoreProduct> onClick, CIG3StoreProduct cheapestStoreProduct = null)
- {
- base.Init(delegate
- {
- onClick(storeProduct);
- });
- bool isSale = storeProduct.IsSale;
- ILocalizedString localizedString = Localization.EmptyLocalizedString;
- switch (shopType)
- {
- case ShopType.Shop_gold:
- case ShopType.Shop_goldSale:
- this.UpdateImages(CurrencyIAPType.Gold, isSale, index, this.GetPercentage(isSale, storeProduct, cheapestStoreProduct, "Gold"));
- localizedString = Localization.Integer(storeProduct.Currencies.GetValue("Gold"));
- goto IL_12A;
- case ShopType.Shop_cash:
- case ShopType.Shop_cashSale:
- this.UpdateImages(CurrencyIAPType.Cash, isSale, index, this.GetPercentage(isSale, storeProduct, cheapestStoreProduct, "Cash"));
- localizedString = Localization.Integer(storeProduct.Currencies.GetValue("Cash"));
- goto IL_12A;
- case ShopType.Shop_cranes:
- this.UpdateImages(CurrencyIAPType.Crane, false, 0, 0m);
- localizedString = Localization.Key("crane");
- goto IL_12A;
- }
- UnityEngine.Debug.LogWarning("[IAPShopItem] No settings implemented for shopType " + shopType);
- this.UpdateImages(CurrencyIAPType.Crane, false, 0, 0m);
- IL_12A:
- this._titleLabel.LocalizedString = localizedString;
- this._priceLabel.LocalizedString = Localization.Literal(storeProduct.FormattedPrice);
- if (isSale)
- {
- this._raysTweener.Play();
- }
- }
-
- private decimal GetPercentage(bool isSale, CIG3StoreProduct storeProduct, CIG3StoreProduct cheapestProduct, string currencyType)
- {
- decimal num = 1m;
- if (cheapestProduct != null && storeProduct != cheapestProduct)
- {
- decimal value = cheapestProduct.Currencies.GetValue(currencyType);
- decimal d = (!(value == 0m)) ? (storeProduct.Currencies.GetValue(currencyType) / value) : 0m;
- decimal price = cheapestProduct.Price;
- decimal num2 = (!(price == 0m)) ? (storeProduct.Price / price) : 0m;
- num = ((!(num2 == 0m)) ? (d / num2) : 1m);
- }
- return (!isSale) ? num : (num * 2m);
- }
-
- private void UpdateImages(CurrencyIAPType iapType, bool isSale = false, int index = 0, decimal percentage = 0m)
- {
- CurrencyIAPAssetCollection.CurrencyIAPSettings asset = SingletonMonobehaviour<CurrencyIAPAssetCollection>.Instance.GetAsset(iapType);
- List<CurrencyIAPAssetCollection.CurrencyObjectSettings> currencyObjectSettings = asset.CurrencyObjectSettings;
- int count = currencyObjectSettings.Count;
- CurrencyIAPAssetCollection.CurrencyObjectSettings currencyObjectSettings2;
- if (index >= 0 && index < count)
- {
- currencyObjectSettings2 = currencyObjectSettings[index];
- }
- else if (count > 0)
- {
- currencyObjectSettings2 = currencyObjectSettings[count - 1];
- UnityEngine.Debug.LogWarningFormat("[IAPShopItem] No object settings assigned for index={0}", new object[]
- {
- index
- });
- }
- else
- {
- currencyObjectSettings2 = null;
- UnityEngine.Debug.LogErrorFormat("[IAPShopItem] No object settings assigned for iapType={0},index={1}", new object[]
- {
- iapType,
- index
- });
- }
- if (currencyObjectSettings2 != null)
- {
- this._iapItemImage.sprite = currencyObjectSettings2.CurrencySprite;
- this._iapItemImage.SetNativeSize();
- this._iapItemImage.transform.localPosition = currencyObjectSettings2.CurrencySpritePosition;
- string attentionBannerLocalizationKey = currencyObjectSettings2.AttentionBannerLocalizationKey;
- bool flag = !string.IsNullOrEmpty(attentionBannerLocalizationKey);
- this._attentionBannerObject.SetActive(flag);
- if (flag)
- {
- this._attentionBannerText.LocalizedString = Localization.Key(attentionBannerLocalizationKey);
- }
- bool active = percentage > 1m;
- this._valueBadgeObject.SetActive(active);
- if (percentage > 1m)
- {
- this._valueBadgeImage.sprite = currencyObjectSettings2.ValueBadgeSprite;
- this._valueBadgeImage.SetNativeSize();
- this._valueBadgeObject.transform.localPosition = currencyObjectSettings2.ValueBadgePosition;
- this._valueBadgeText.fontSize = currencyObjectSettings2.ValueBadgeFontSize;
- this._valueBadgeLabel.LocalizedString = Localization.Percentage((float)percentage, 0);
- if (isSale)
- {
- this._valueBadgeTweener.Play();
- }
- }
- }
- this._innerFrameImage.sprite = asset.BackgroundSprite;
- this._raysImage.color = asset.RaysColor;
- }
-
- [SerializeField]
- private Image _innerFrameImage;
-
- [SerializeField]
- private Image _iapItemImage;
-
- [SerializeField]
- private LocalizedText _priceLabel;
-
- [SerializeField]
- private LocalizedText _titleLabel;
-
- [SerializeField]
- private Image _raysImage;
-
- [SerializeField]
- private Tweener _raysTweener;
-
- [SerializeField]
- private GameObject _attentionBannerObject;
-
- [SerializeField]
- private LocalizedText _attentionBannerText;
-
- [SerializeField]
- private GameObject _valueBadgeObject;
-
- [SerializeField]
- private Tweener _valueBadgeTweener;
-
- [SerializeField]
- private Image _valueBadgeImage;
-
- [SerializeField]
- private Text _valueBadgeText;
-
- [SerializeField]
- private LocalizedText _valueBadgeLabel;
- }
|