using asap.core; using cfg; using GameCore; using OfferStoryChain; using TMPro; using UnityEngine; using UnityEngine.UI; [RequireComponent(typeof(RectTransform))] public class OfferStoryChainScrollSlotView : MonoBehaviour { [SerializeField] private RewardItemNew[] rewardItemList; [SerializeField] private GameObject goBuy, goDone, goLock, fxLock, goSelected; [SerializeField] private TMP_Text textPrice/* , textDiscount */; [SerializeField] private Button btnBuy; [SerializeField] private RectTransform triggerItem; private IAPItemList _iapItemList; private readonly PlayerItemData _playerItemData = GContext.container.Resolve(); private ScrollerItemViewState _state; public RectTransform RectTransform => GetComponent(); public RectTransform TriggerItem => triggerItem; private int _idx; public void Init(ScrollerItemViewData data) { var itemDataList = _playerItemData.GetItemDataByDropIdLureInflation(null, data.DropId); for (int i = 0; i < rewardItemList.Length; i++) { if (i < itemDataList.Count) rewardItemList[i].SetData(itemDataList[i]); else rewardItemList[i].gameObject.SetActive(false); } SetState(data.State); if (data.IapId != 0) { _playerItemData.ResolveIapId(data.IapId, out _iapItemList, out var priceString); textPrice.text = priceString; btnBuy.onClick.AddListener(() => OnClickBuy(data.DropId, _iapItemList, data.EventId)); } else { textPrice.text = LocalizationMgr.GetText("UI_HomePanel_101013"); btnBuy.onClick.AddListener(() => OnClickBuy(data.DropId)); } _idx = data.Index; fxLock.SetActive(false); } private async void OnClickBuy(int dropId, IAPItemList iapItemList, int eventId) { try { switch(_state) { case ScrollerItemViewState.Locked: ToastPanel.Show(LocalizationMgr.GetText("UI_ToastPanel_30")); return; case ScrollerItemViewState.Bought: return; case ScrollerItemViewState.Available: break; } var roundCount = GContext.container.Resolve().RoundCount; (var res, var rewards) = await GContext.container.Resolve().GrantReward(dropId, iapItemList, eventId); if (res) { var pc = new OfferStoryChainPurchaseContext { Index = _idx, RoundCount = roundCount, RewardsGiven = rewards }; GContext.container.Resolve().EventAggregator.Publish(pc); } else { // Something? } } catch (System.Exception e) { Debug.LogError(e); } } private async void OnClickBuy(int dropId) { try { switch(_state) { case ScrollerItemViewState.Locked: ToastPanel.Show(LocalizationMgr.GetText("UI_ToastPanel_30")); return; case ScrollerItemViewState.Bought: return; case ScrollerItemViewState.Available: break; } // if (_state != ScrollerItemViewState.Available) // return; var roundCount = GContext.container.Resolve().RoundCount; var rewards = GContext.container.Resolve().GrantReward(dropId); var pc = new OfferStoryChainPurchaseContext { Index = _idx, RoundCount = roundCount, RewardsGiven = rewards }; GContext.container.Resolve().EventAggregator.Publish(pc); } catch (System.Exception e) { Debug.LogError(e); } } // public void OnBuySuccess() // { // GContext.container.Resolve()?.MoveToNextSlotAndTryGrantFinalReward(); // } public void SetState(ScrollerItemViewState state) { _state = state; goBuy.SetActive(state != ScrollerItemViewState.Bought); goDone.SetActive(state == ScrollerItemViewState.Bought); goLock.SetActive(state == ScrollerItemViewState.Locked); goSelected.SetActive(state == ScrollerItemViewState.Available); } private void Reset() { rewardItemList = transform.Find("Item/reward").GetComponentsInChildren(); goBuy = transform.Find("Item/btn_buy").gameObject; goDone = transform.Find("Item/done").gameObject; goLock = transform.Find("Item/btn_buy/btn_green/lock").gameObject; textPrice = transform.Find("Item/btn_buy/btn_green/Ani_Container/p_text").GetComponent(); // textDiscount = transform.Find("Item/tag_more/text_more").GetComponent(); btnBuy = transform.Find("Item/btn_buy/btn_green").GetComponent