using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class StoreWin : UIBase { [SerializeField] OwnMoneyCell ownMoneyCellWithShop; //有刷新功能的商店 [SerializeField] GameObject refreshGo; [SerializeField] Image refreshMoneyIcon; [SerializeField] Text refreshMoneyText; [SerializeField] Button refreshButton; [SerializeField] GroupButtonEx normalShopBtn; [SerializeField] GroupButtonEx guildShopBtn; [SerializeField] GroupButtonEx heroShopBtn; [SerializeField] ScrollerController scroller; protected override void InitComponent() { refreshButton.AddListener(RefreshStore); normalShopBtn.AddListener(() => { OnSelectStoreFuncType(1); }); guildShopBtn.AddListener(() => { OnSelectStoreFuncType(2); }); heroShopBtn.AddListener(() => { OnSelectStoreFuncType(3); }); } protected override void OnPreOpen() { scroller.OnRefreshCell += OnRefreshCell; StoreModel.Instance.RefreshShopEvent += Display; StoreModel.Instance.RefreshBuyShopLimitEvent += Display; GuildManager.Instance.EnterOrQuitGuildEvent += EnterOrQuitGuildEvent; Display(); } protected override void OnPreClose() { scroller.OnRefreshCell -= OnRefreshCell; StoreModel.Instance.RefreshShopEvent -= Display; StoreModel.Instance.RefreshBuyShopLimitEvent -= Display; GuildManager.Instance.EnterOrQuitGuildEvent -= EnterOrQuitGuildEvent; StoreModel.Instance.selectStoreFuncType = StoreFunc.Normal; } void Display() { if (StoreModel.Instance.selectStoreFuncType == StoreFunc.Normal) { normalShopBtn.SelectBtn(); } else if (StoreModel.Instance.selectStoreFuncType == StoreFunc.Guild) { guildShopBtn.SelectBtn(); } else if (StoreModel.Instance.selectStoreFuncType == StoreFunc.Hero) { heroShopBtn.SelectBtn(); } guildShopBtn.SetColorful(null, PlayerDatas.Instance.fairyData.HasFairy); ShowMoney(); CreateScroller(); } void EnterOrQuitGuildEvent(bool isEnter) { if (!isEnter && StoreModel.Instance.selectStoreFuncType == StoreFunc.Guild) { StoreModel.Instance.selectStoreFuncType = StoreFunc.Normal; } Display(); } void CreateScroller() { if (!StoreModel.Instance.storeTypeDict.ContainsKey((int)StoreModel.Instance.selectStoreFuncType)) { return; } scroller.Refresh(); var list = StoreModel.Instance.storeTypeDict[(int)StoreModel.Instance.selectStoreFuncType]; for (int i = 0; i < list.Count; i++) { if (i % 3 == 0) { scroller.AddCell(ScrollerDataType.Header, i); } } scroller.Restart(); } void OnRefreshCell(ScrollerDataType type, CellView cell) { var _cell = cell as StoreLineCell; _cell.Display(cell.index); } void ShowMoney() { if (!StoreModel.Instance.shopMoneyTypeDict.ContainsKey((int)StoreModel.Instance.selectStoreFuncType)) { return; } var moneyType = StoreModel.Instance.shopMoneyTypeDict[(int)StoreModel.Instance.selectStoreFuncType]; ownMoneyCellWithShop.moneyType = moneyType; ownMoneyCellWithShop.Display(true); if (StoreModel.Instance.selectStoreFuncType == StoreFunc.Hero) { refreshGo.SetActive(true); refreshMoneyIcon.SetIconWithMoneyType(StoreModel.Instance.heroSoulRefreshMoneyType); if (StoreModel.Instance.shopRefreshCntDict.ContainsKey((int)StoreModel.Instance.selectStoreFuncType)) { if (StoreModel.Instance.shopRefreshCntDict[(int)StoreModel.Instance.selectStoreFuncType] >= StoreModel.Instance.heroSoulRefreshFreeCount) { refreshMoneyText.text = StoreModel.Instance.heroSoulRefreshMoney.ToString(); } else { refreshMoneyText.text = Language.Get("L1127"); } } else { refreshMoneyText.text = Language.Get("L1127"); } } else { refreshGo.SetActive(false); } } void RefreshStore() { if (StoreModel.Instance.selectStoreFuncType != StoreFunc.Hero) { return; } var useCnt = 0; if (StoreModel.Instance.shopRefreshCntDict.ContainsKey((int)StoreModel.Instance.selectStoreFuncType)) { if (StoreModel.Instance.shopRefreshCntDict[(int)StoreModel.Instance.selectStoreFuncType] >= StoreModel.Instance.heroSoulRefreshFreeCount) { useCnt = StoreModel.Instance.heroSoulRefreshMoney; } } if (UIHelper.CheckMoneyCount(StoreModel.Instance.heroSoulRefreshMoneyType, useCnt, 2)) { StoreModel.Instance.RefreshStore((int)StoreFunc.Hero); } } void OnSelectStoreFuncType(int index) { if (index == 2) { if (!PlayerDatas.Instance.fairyData.HasFairy) { SysNotifyMgr.Instance.ShowTip("NoGuild"); return; } } StoreModel.Instance.selectStoreFuncType = (StoreFunc)index; Display(); } }