您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 

160 行
5.3 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using CIG;
  4. using CIG.Translation;
  5. using CIGEnums;
  6. using SUISS.Core;
  7. using Tweening;
  8. using UnityEngine;
  9. using UnityEngine.UI;
  10. public class IAPShopItem : ShopItem
  11. {
  12. public void Init(CIG3StoreProduct storeProduct, ShopType shopType, int index, Action<CIG3StoreProduct> onClick, CIG3StoreProduct cheapestStoreProduct = null)
  13. {
  14. base.Init(delegate
  15. {
  16. onClick(storeProduct);
  17. });
  18. bool isSale = storeProduct.IsSale;
  19. ILocalizedString localizedString = Localization.EmptyLocalizedString;
  20. switch (shopType)
  21. {
  22. case ShopType.Shop_gold:
  23. case ShopType.Shop_goldSale:
  24. this.UpdateImages(CurrencyIAPType.Gold, isSale, index, this.GetPercentage(isSale, storeProduct, cheapestStoreProduct, "Gold"));
  25. localizedString = Localization.Integer(storeProduct.Currencies.GetValue("Gold"));
  26. goto IL_12A;
  27. case ShopType.Shop_cash:
  28. case ShopType.Shop_cashSale:
  29. this.UpdateImages(CurrencyIAPType.Cash, isSale, index, this.GetPercentage(isSale, storeProduct, cheapestStoreProduct, "Cash"));
  30. localizedString = Localization.Integer(storeProduct.Currencies.GetValue("Cash"));
  31. goto IL_12A;
  32. case ShopType.Shop_cranes:
  33. this.UpdateImages(CurrencyIAPType.Crane, false, 0, 0m);
  34. localizedString = Localization.Key("crane");
  35. goto IL_12A;
  36. }
  37. UnityEngine.Debug.LogWarning("[IAPShopItem] No settings implemented for shopType " + shopType);
  38. this.UpdateImages(CurrencyIAPType.Crane, false, 0, 0m);
  39. IL_12A:
  40. this._titleLabel.LocalizedString = localizedString;
  41. this._priceLabel.LocalizedString = Localization.Literal(storeProduct.FormattedPrice);
  42. if (isSale)
  43. {
  44. this._raysTweener.Play();
  45. }
  46. }
  47. private decimal GetPercentage(bool isSale, CIG3StoreProduct storeProduct, CIG3StoreProduct cheapestProduct, string currencyType)
  48. {
  49. decimal num = 1m;
  50. if (cheapestProduct != null && storeProduct != cheapestProduct)
  51. {
  52. decimal value = cheapestProduct.Currencies.GetValue(currencyType);
  53. decimal d = (!(value == 0m)) ? (storeProduct.Currencies.GetValue(currencyType) / value) : 0m;
  54. decimal price = cheapestProduct.Price;
  55. decimal num2 = (!(price == 0m)) ? (storeProduct.Price / price) : 0m;
  56. num = ((!(num2 == 0m)) ? (d / num2) : 1m);
  57. }
  58. return (!isSale) ? num : (num * 2m);
  59. }
  60. private void UpdateImages(CurrencyIAPType iapType, bool isSale = false, int index = 0, decimal percentage = 0m)
  61. {
  62. CurrencyIAPAssetCollection.CurrencyIAPSettings asset = SingletonMonobehaviour<CurrencyIAPAssetCollection>.Instance.GetAsset(iapType);
  63. List<CurrencyIAPAssetCollection.CurrencyObjectSettings> currencyObjectSettings = asset.CurrencyObjectSettings;
  64. int count = currencyObjectSettings.Count;
  65. CurrencyIAPAssetCollection.CurrencyObjectSettings currencyObjectSettings2;
  66. if (index >= 0 && index < count)
  67. {
  68. currencyObjectSettings2 = currencyObjectSettings[index];
  69. }
  70. else if (count > 0)
  71. {
  72. currencyObjectSettings2 = currencyObjectSettings[count - 1];
  73. UnityEngine.Debug.LogWarningFormat("[IAPShopItem] No object settings assigned for index={0}", new object[]
  74. {
  75. index
  76. });
  77. }
  78. else
  79. {
  80. currencyObjectSettings2 = null;
  81. UnityEngine.Debug.LogErrorFormat("[IAPShopItem] No object settings assigned for iapType={0},index={1}", new object[]
  82. {
  83. iapType,
  84. index
  85. });
  86. }
  87. if (currencyObjectSettings2 != null)
  88. {
  89. this._iapItemImage.sprite = currencyObjectSettings2.CurrencySprite;
  90. this._iapItemImage.SetNativeSize();
  91. this._iapItemImage.transform.localPosition = currencyObjectSettings2.CurrencySpritePosition;
  92. string attentionBannerLocalizationKey = currencyObjectSettings2.AttentionBannerLocalizationKey;
  93. bool flag = !string.IsNullOrEmpty(attentionBannerLocalizationKey);
  94. this._attentionBannerObject.SetActive(flag);
  95. if (flag)
  96. {
  97. this._attentionBannerText.LocalizedString = Localization.Key(attentionBannerLocalizationKey);
  98. }
  99. bool active = percentage > 1m;
  100. this._valueBadgeObject.SetActive(active);
  101. if (percentage > 1m)
  102. {
  103. this._valueBadgeImage.sprite = currencyObjectSettings2.ValueBadgeSprite;
  104. this._valueBadgeImage.SetNativeSize();
  105. this._valueBadgeObject.transform.localPosition = currencyObjectSettings2.ValueBadgePosition;
  106. this._valueBadgeText.fontSize = currencyObjectSettings2.ValueBadgeFontSize;
  107. this._valueBadgeLabel.LocalizedString = Localization.Percentage((float)percentage, 0);
  108. if (isSale)
  109. {
  110. this._valueBadgeTweener.Play();
  111. }
  112. }
  113. }
  114. this._innerFrameImage.sprite = asset.BackgroundSprite;
  115. this._raysImage.color = asset.RaysColor;
  116. }
  117. [SerializeField]
  118. private Image _innerFrameImage;
  119. [SerializeField]
  120. private Image _iapItemImage;
  121. [SerializeField]
  122. private LocalizedText _priceLabel;
  123. [SerializeField]
  124. private LocalizedText _titleLabel;
  125. [SerializeField]
  126. private Image _raysImage;
  127. [SerializeField]
  128. private Tweener _raysTweener;
  129. [SerializeField]
  130. private GameObject _attentionBannerObject;
  131. [SerializeField]
  132. private LocalizedText _attentionBannerText;
  133. [SerializeField]
  134. private GameObject _valueBadgeObject;
  135. [SerializeField]
  136. private Tweener _valueBadgeTweener;
  137. [SerializeField]
  138. private Image _valueBadgeImage;
  139. [SerializeField]
  140. private Text _valueBadgeText;
  141. [SerializeField]
  142. private LocalizedText _valueBadgeLabel;
  143. }