using System; using System.Collections.Generic; using ET; using FairyGUI; using UI.Studio; namespace GFGGame { public class StudioBaseView : BaseWindow { protected UI_StudioEctypeUI _ui; private ValueBarController _valueBarController; protected StudioCfg studioCfg; protected List storyLevelCfgs; protected StudioData studioData; protected int curIndex = 0; public override void Dispose() { if (_valueBarController != null) { _valueBarController.Dispose(); _valueBarController = null; } if (_ui != null) { _ui.Dispose(); _ui = null; } base.Dispose(); } protected override void OnInit() { base.OnInit(); packageName = UI_StudioEctypeUI.PACKAGE_NAME; _ui = UI_StudioEctypeUI.Create(); this.viewCom = _ui.target; isfullScreen = true; _valueBarController = new ValueBarController(_ui.m_valueBar); _ui.m_list.itemRenderer = ListItemRender; // _ui.m_list.onClickItem.Add(OnCliclListItem); _ui.m_list.SetVirtual(); _ui.m_btnBuy.onClick.Add(OnCliclBtnBuy); } protected override void AddEventListener() { base.AddEventListener(); EventAgent.AddEventListener(ConstMessage.BUY_STUDIO_PLAY_TIMES, UpdateView); EventAgent.AddEventListener(ConstMessage.NOTICE_STUDIO_PLAY_TIMES, UpdateView); } protected override void OnShown() { base.OnShown(); _valueBarController.OnShown(); // _valueBarController.Controller(1); _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("gzs_bjbj"); UpdateView(); Timers.inst.Add(1, 0, UpdateShowTime); } protected override void OnHide() { base.OnHide(); _valueBarController.OnHide(); studioCfg = null; storyLevelCfgs = null; studioData = null; Timers.inst.Remove(UpdateShowTime); } protected override void RemoveEventListener() { base.RemoveEventListener(); EventAgent.RemoveEventListener(ConstMessage.BUY_STUDIO_PLAY_TIMES, UpdateView); EventAgent.RemoveEventListener(ConstMessage.NOTICE_STUDIO_PLAY_TIMES, UpdateView); } protected void UpdateView() { studioData = StudioDataManager.Instance.GetStudioDataById(this.studioCfg.id); _ui.m_txtNum.text = string.Format("剩余次数:{0}/{1}", this.studioData.TotalPlayTimes - this.studioData.PlayTimes, studioCfg.num); } private void UpdateShowTime(object param) { long curTime = TimeHelper.ServerNow(); long endTime = GameGlobal.myNumericComponent.GetAsInt(NumericType.DailyResetSecs); _ui.m_txtTime.text = string.Format("{0}后刷新", TimeUtil.FormattingTime(curTime, endTime * 1000)); } private void ListItemRender(int index, GObject obj) { UI_ListItem item = UI_ListItem.Proxy(obj); StudioDataManager.Instance.IsCanFight(storyLevelCfgs, index, out bool canFight, out string content); ItemData itemData = StoryBonusDataCache.GetBonusData(storyLevelCfgs[index].id).bonusBase[0]; ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemData.id); item.m_loaIcon.url = ResPathUtil.GetIconPath(itemCfg); item.m_star.selectedIndex = InstanceZonesDataManager.GetStarCountHistory(storyLevelCfgs[index].id); item.m_imgLock.visible = canFight ? false : true; item.m_txtTitle.text = canFight ? storyLevelCfgs[index].name : content; if (canFight) curIndex = index; if (item.m_loaIcon.data == null) { item.m_loaIcon.onClick.Add(OnLoaItemClick); } item.m_loaIcon.data = index; if (item.m_loaBg.data == null) { item.m_loaBg.onClick.Add(OnCliclListItem); } item.m_loaBg.data = index; UI_ListItem.ProxyEnd(); } private void OnCliclListItem(EventContext context) { GObject obj = context.sender as GObject; int index = (int)obj.data; StoryLevelCfg storyLevelCfg = storyLevelCfgs[index]; StudioDataManager.Instance.IsCanFight(storyLevelCfgs, index, out bool canFight, out string content); if (!canFight) { PromptController.Instance.ShowFloatTextPrompt(content); return; } StudioDataManager.Instance.PROPERTY_SELECT_INDEX = _ui.m_listProperty.selectedIndex; StudioDataManager.Instance.TYPE_SELECT_INDEX = _ui.m_c1.selectedIndex; InstanceZonesController.ShowLevelView(storyLevelCfg.id, StudioDataManager.Instance.OnFinishStudioStoryLevel); } private void OnLoaItemClick(EventContext context) { GObject obj = context.sender as GObject; int index = (int)obj.data; ItemData itemData = StoryBonusDataCache.GetBonusData(storyLevelCfgs[index].id).bonusBase[0]; ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemData.id); GoodsItemTipsController.ShowItemTips(itemCfg.id); } private void OnCliclBtnBuy() { ViewManager.Show(this.studioCfg.id); } } }