123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174 |
- 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 _storyType;
- private List<List<ItemData>> _totalBonusList;
- private int _index;
- private int _expAdd;
- private int _power;
- private int _fightTimes;
- private const int _timeCount = 10;
- 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(() =>
- {
- this.Hide();
- });
- _ui.m_btnFightTimes.onClick.Add(() =>
- {
- StartFight(_fightTimes);
- });
- }
- protected override void OnShown()
- {
- base.OnShown();
- int count = (int)viewData;
- _levelID = StoryDataManager.currentLevelCfgId;
- _storyType = _levelID/GameConst.STORY_LEVEL_KEY_NUM / 10000;
- StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(_levelID);
- StoryFightCfg fightCfg = StoryFightCfgArray.Instance.GetCfg(levelCfg.fightID);
- _expAdd = fightCfg.exp;
- _power = levelCfg.power;
- StartFight(count);
- EventAgent.AddEventListener(ConstMessage.NUMERIC_CHANGE, UpdateBtnFightTimes);
- EventAgent.AddEventListener(ConstMessage.STORY_FIGHT_QUICKLY_SUCCESS, StartShowBonus);
- }
- protected override void OnHide()
- {
- base.OnHide();
- Timers.inst.Remove(ShowBonusItem);
- EventAgent.RemoveEventListener(ConstMessage.NUMERIC_CHANGE, UpdateBtnFightTimes);
- EventAgent.RemoveEventListener(ConstMessage.STORY_FIGHT_QUICKLY_SUCCESS, StartShowBonus);
- }
- private void StartFight(int count)
- {
- int time = StoryDataManager.GetCanFightTime(_levelID);
- if (_storyType == ConstStoryType.NORMAL_TYPE && time < count)
- {
- ItemUtil.AddPower("体力不足", () => { StartFight(count); });
- return;
- }
- _ui.m_btnExit.visible = false;
- _ui.m_btnFightTimes.visible = false;
- _ui.m_txtPowerDesc.visible = false;
- _ui.m_list.RemoveChildren();
- //_totalBonusList = new List<List<ItemData>>();
- //for (int i = 1; i <= count; i++)
- //{
- // bool fistPassLastLvl = false;
- // bool curLvfirstPass = false;
- // List<ItemData> bonusList = StoryDataManager.PassCurrentLevel(out fistPassLastLvl, out curLvfirstPass);
- // _totalBonusList.Add(bonusList);
- //}
- StorySProxy.FinishStoryFightQuickly(_levelID, count).Coroutine();
- }
- private void StartShowBonus(EventContext eventContext)
- {
- _totalBonusList = (List<List<ItemData>>)eventContext.data;
- _index = 0;
- ShowBonusItem();
- Timers.inst.Add(0.3f, 0, ShowBonusItem);
- }
- private void ShowBonusItem(object param = null)
- {
- if (_index < _totalBonusList.Count)
- {
- List<ItemData> bonusList = _totalBonusList[_index] as List<ItemData>;
- 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++;
- }
- else
- {
- UI_StoryFightQuicklyComplete completeItem = UI_StoryFightQuicklyComplete.Proxy();
- _ui.m_list.AddChild(completeItem.target);
- Timers.inst.Remove(ShowBonusItem);
- _ui.m_btnExit.visible = true;
- UpdateBtnFightTimes();
- }
- _ui.m_list.scrollPane.ScrollBottom();
- }
- private void ListItemRender(int index, GObject item)
- {
- List<ItemData> bonusList = _totalBonusList[_index] as List<ItemData>;
- 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);
- int time = StoryDataManager.GetCanFightTime(_levelID);
- time = Math.Min(GameConst.MAX_COUNT_FIGHT_QUICKLY, time);
- _ui.m_btnFightTimes.visible = time > 0;
- _ui.m_txtPowerDesc.visible = _ui.m_btnFightTimes.visible;
- if (_storyType == ConstStoryType.NORMAL_TYPE)
- {
- _ui.m_btnFightTimes.visible = true;
- _fightTimes = (int)viewData;
- _ui.m_btnFightTimes.text = "挑战" + NumberUtil.GetChiniseNumberText((int)viewData) + "次";
- }
- else if (_storyType == ConstStoryType.HARD_TYPE)
- {
- _ui.m_btnFightTimes.visible = time > 1;
- if (_ui.m_btnFightTimes.visible)
- {
- _fightTimes = time;
- _ui.m_btnFightTimes.text = "挑战" + NumberUtil.GetChiniseNumberText(time) + "次";
- }
- }
- if (_ui.m_txtPowerDesc.visible)
- {
- int power = time * levelCfg.power;
- _ui.m_txtPowerDesc.SetVar("v1", "" + power).FlushVars();
- }
- }
- }
- }
- }
|