Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 

98 rader
3.0 KiB

  1. using System;
  2. using CIG.Translation;
  3. using CIGEnums;
  4. using SUISS.Core;
  5. using SUISSEngine;
  6. using UnityEngine;
  7. using UnityEngine.UI;
  8. public class BuildingShopItem : ShopItem
  9. {
  10. public void Init(CIGBuilding building, bool isLocked, Action<CIGBuilding> onClick)
  11. {
  12. base.Init(delegate
  13. {
  14. onClick(building);
  15. });
  16. isLocked |= !building.IsUnlocked;
  17. this._lockObject.gameObject.SetActive(isLocked);
  18. this._objectButton.interactable = !isLocked;
  19. Material asset = SingletonMonobehaviour<MaterialAssetCollection>.Instance.GetAsset((!isLocked) ? MaterialType.UIClip : MaterialType.UIClipGreyscale);
  20. GridTile tile = building.tile;
  21. this._frameImage.sprite = SingletonMonobehaviour<SurfaceSpriteAssetCollection>.Instance.GetAsset((SurfaceType)tile.requiredGridType);
  22. this._frameImage.material = asset;
  23. this._buildingTopImage.sprite = tile.spriteRenderer.sprite;
  24. this._buildingTopImage.material = asset;
  25. if (tile.bottomRenderer != null)
  26. {
  27. this._buildingBottomImage.sprite = tile.bottomRenderer.sprite;
  28. this._buildingBottomImage.gameObject.SetActive(true);
  29. this._buildingBottomImage.material = asset;
  30. }
  31. else
  32. {
  33. this._buildingBottomImage.gameObject.SetActive(false);
  34. }
  35. this._buildingText.LocalizedString = building.LocalName;
  36. if (isLocked)
  37. {
  38. this._costIcon.sprite = SingletonMonobehaviour<UISpriteAssetCollection>.Instance.GetAsset(UISpriteType.XPSmall);
  39. this._costText.LocalizedString = Localization.Concat(new ILocalizedString[]
  40. {
  41. Localization.Key("level"),
  42. Localization.LiteralWhiteSpace,
  43. Localization.Integer(building.NextUnlockLevel)
  44. });
  45. this._badgeObject.gameObject.SetActive(false);
  46. }
  47. else
  48. {
  49. Currencies purchasePrice = building.PurchasePrice;
  50. bool flag = !purchasePrice.ContainsApproximate("Cash") && !purchasePrice.ContainsApproximate("Gold");
  51. this._costIcon.gameObject.SetActive(!flag);
  52. this._badgeObject.gameObject.SetActive(flag);
  53. if (purchasePrice.ContainsApproximate("Cash"))
  54. {
  55. this._costIcon.sprite = SingletonMonobehaviour<UISpriteAssetCollection>.Instance.GetAsset(UISpriteType.CashSmall);
  56. this._costText.LocalizedString = Localization.Integer(purchasePrice.GetValue("Cash"));
  57. }
  58. else if (purchasePrice.ContainsApproximate("Gold"))
  59. {
  60. this._costIcon.sprite = SingletonMonobehaviour<UISpriteAssetCollection>.Instance.GetAsset(UISpriteType.GoldSmall);
  61. this._costText.LocalizedString = Localization.Integer(purchasePrice.GetValue("Gold"));
  62. }
  63. else
  64. {
  65. this._costText.LocalizedString = Localization.Key("free");
  66. }
  67. }
  68. }
  69. [SerializeField]
  70. private Image _frameImage;
  71. [SerializeField]
  72. private Image _buildingTopImage;
  73. [SerializeField]
  74. private Image _buildingBottomImage;
  75. [SerializeField]
  76. private LocalizedText _buildingText;
  77. [SerializeField]
  78. private Image _costIcon;
  79. [SerializeField]
  80. private LocalizedText _costText;
  81. [SerializeField]
  82. private GameObject _lockObject;
  83. [SerializeField]
  84. private GameObject _badgeObject;
  85. [SerializeField]
  86. private Button _objectButton;
  87. }