using FairyGUI; using UI.Main; using System.Collections; using UI.CommonGame; using System; using System.Collections.Generic; namespace GFGGame { public class StoryFightQuicklyView : BaseWindow { private UI_StoryFightQuicklyUI _ui; private int _fightID; private int _levelID; private int _type; private int _storyType; private int _fightType; private List> _totalBonusList; private int _index; private int _expAdd; private int _power; private int _fightTimes; private const int _timeCount = 10; public override void Dispose() { if (_ui != null) { _ui.Dispose(); _ui = null; } base.Dispose(); } protected override void OnInit() { base.OnInit(); _ui = UI_StoryFightQuicklyUI.Create(); this.viewCom = _ui.target; this.viewCom.Center(); this.modal = true; _ui.m_btnExit.onClick.Add(Hide); _ui.m_btnFightTimes.onClick.Add(StartFight); } protected override void AddEventListener() { base.AddEventListener(); EventAgent.AddEventListener(ConstMessage.NUMERIC_CHANGE, UpdateBtnFightTimes); EventAgent.AddEventListener(ConstMessage.STORY_FIGHT_QUICKLY_SUCCESS, StartShowBonus); } protected override void OnShown() { base.OnShown(); _fightType = (int)viewData; _levelID = InstanceZonesDataManager.currentLevelCfgId; InstanceZonesDataManager.isQuicklyFighting = true; StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(_levelID); StoryFightCfg fightCfg = StoryFightCfgArray.Instance.GetCfg(levelCfg.fightID); _type = levelCfg.type; _storyType = levelCfg.subType; _expAdd = fightCfg.exp; _power = levelCfg.power; StartFight(); } protected override void OnHide() { base.OnHide(); Timers.inst.Remove(ShowBonusItem); ViewManager.GoBackFrom(typeof(StoryFightQuicklyView).Name); InstanceZonesDataManager.isQuicklyFighting = false; } protected override void RemoveEventListener() { base.RemoveEventListener(); EventAgent.RemoveEventListener(ConstMessage.NUMERIC_CHANGE, UpdateBtnFightTimes); EventAgent.RemoveEventListener(ConstMessage.STORY_FIGHT_QUICKLY_SUCCESS, StartShowBonus); } private void StartFight() { InstanceZonesDataManager.GetCanFightTime(_type, _storyType, _levelID, out int times, out string title); if (_storyType == ConstInstanceZonesSubType.Normal && times < _fightType) { ItemUtil.AddPower("体力不足", () => { StartFight(); }); return; } this.clickBlankToClose = false; _ui.m_t0.Play(() => { _ui.m_btnExit.visible = false; _ui.m_btnFightTimes.visible = false; _ui.m_txtPowerDesc.visible = false; _ui.m_list.RemoveChildren(); InstanceZonesDataManager.isQuicklyFighting = true; InstanceZonesSProxy.FinishStoryFightQuickly(_levelID, _fightType == 1 ? 1 : times).Coroutine(); this.clickBlankToClose = true; }); } private void StartShowBonus(EventContext eventContext) { _totalBonusList = (List>)eventContext.data; _index = 0; ShowBonusItem(); Timers.inst.Add(0.3f, 0, ShowBonusItem); } private void ShowBonusItem(object param = null) { if (_index < _totalBonusList.Count) { List bonusList = _totalBonusList[_index] as List; UI_StoryFightQuicklyBonusListItem listItem = UI_StoryFightQuicklyBonusListItem.Proxy(); listItem.m_list.itemRenderer = ListItemRender; _ui.m_list.AddChild(listItem.target); int order = _index + 1; listItem.m_txtTimes.SetVar("n", "" + NumberUtil.GetChiniseNumberText(order)).FlushVars(); listItem.m_txtExp.SetVar("n", "" + _expAdd).FlushVars(); listItem.m_list.numItems = bonusList.Count; listItem.m_list.ResizeToFit(); listItem.target.height = listItem.m_list.y + listItem.m_list.height; _index++; UI_StoryFightQuicklyBonusListItem.ProxyEnd(); } else { UI_StoryFightQuicklyComplete completeItem = UI_StoryFightQuicklyComplete.Proxy(); _ui.m_list.AddChild(completeItem.target); UI_StoryFightQuicklyComplete.ProxyEnd(); Timers.inst.Remove(ShowBonusItem); InstanceZonesDataManager.isQuicklyFighting = false; _ui.m_btnExit.visible = true; UpdateBtnFightTimes(); } _ui.m_list.ScrollToView(_index - 1, true); //.ScrollBottom(); } private void ListItemRender(int index, GObject item) { List bonusList = _totalBonusList[_index] as List; ItemData itemData = bonusList[index] as ItemData; if (item.data == null) { item.data = new ItemView(item as GComponent); } (item.data as ItemView).SetData(itemData); (item.data as ItemView).TxtHasCountVisble = false; } private void UpdateBtnFightTimes() { if (_ui.m_btnExit.visible) { StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(_levelID); InstanceZonesDataManager.GetCanFightTime(_type, _storyType, _levelID, out int times, out string title); _ui.m_btnFightTimes.title = _fightType == 1 ? "挑战一次" : title; _ui.m_btnFightTimes.visible = times > 0; if (_type == ConstInstanceZonesType.Story && _storyType == ConstInstanceZonesSubType.Normal) { _ui.m_btnFightTimes.visible = true; times = _fightType == 1 ? 1 : GameConst.MAX_COUNT_FIGHT_QUICKLY; } _ui.m_txtPowerDesc.visible = _ui.m_btnFightTimes.visible; if (_ui.m_txtPowerDesc.visible) { int power = times * levelCfg.power; _ui.m_txtPowerDesc.SetVar("v1", "" + power).FlushVars(); } } } } }