123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255 |
- 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 int _needItemId;
- private int _needItemCount;
- private List<ItemData> _bonusList;
- 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;
- this.clickBlankToClose = false;
- _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 as object[])[0];
- _needItemId = (int)(viewData as object[])[1];
- _needItemCount = (int)(viewData as object[])[2];
- _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;
- string title = levelCfg.name;
- switch (levelCfg.type)
- {
- case ConstInstanceZonesType.Story:
- title = MainStoryDataManager.CurrentChapterOrder + "-" + InstanceZonesDataManager.currentLevelOrder + " " + levelCfg.name;
- break;
- }
- _ui.m_txtName.text = title;
- _ui.m_c1.selectedIndex = _needItemId <= 0 || _needItemCount <= 0 || ItemDataManager.GetItemNum(_needItemId) >= _needItemCount ? 0 : 1;
- updateNeedItem();
- 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 _fightTimes, out string title);
- if (_fightTimes == 0)
- {
- StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(_levelID);
- if (levelCfg.type == ConstInstanceZonesType.Story)
- {
- ItemUtil.AddPower("体力不足", StartFight);
- }
- else if (levelCfg.type == ConstInstanceZonesType.Studio)
- {
- var studioCfg = StudioCfgArray.Instance.GetCfg(levelCfg.chapterId);
- if (!RoleLimitDataManager.CheckPlayTimesEnough(studioCfg.limit, 1))
- {
- PromptController.Instance.ShowFloatTextPrompt("挑战次数不足");
- ViewManager.Show<StudioBuyNumView>(studioCfg.limit);
- }
- else
- {
- ItemUtil.AddPower("体力不足", StartFight);
- }
- }
- return;
- }
- // this.clickBlankToClose = false;
- // _ui.m_t0.Play(() =>
- // {
- _fightTimes = _fightType == 1 ? 1 : _fightTimes;
- _ui.m_btnExit.visible = false;
- _ui.m_btnFightTimes.visible = false;
- _ui.m_comCostCurrent.visible = false;
- _ui.m_list.RemoveChildrenToPool();
- InstanceZonesDataManager.isQuicklyFighting = true;
- // InstanceZonesSProxy.FinishStoryFightQuickly(_levelID, _fightType == 1 ? 1 : times).Coroutine();
- _index = 0;
- ReqFightQuickly(null);
- // });
- }
- private async void ReqFightQuickly(object param)
- {
- long hasCount = ItemDataManager.GetItemNum(_needItemId);
- bool isFinish = _needItemId > 0 && _needItemCount > 0 && hasCount >= _needItemCount;
- _ui.m_txtItemNeedNum.text = string.Format("还需:{0}个", Math.Max(0, _needItemCount - hasCount));
- if (_index >= _fightTimes || isFinish)
- {
- if (isFinish)
- {
- _ui.m_txtItemNeedNum.text = "材料已足够";
- PromptController.Instance.ShowFloatTextPrompt("材料已足够");
- }
- ShowEnding();
- }
- else
- {
- List<ItemData> result = await InstanceZonesSProxy.FinishStoryFightQuickly(_levelID, 1);
- ET.Log.Debug("result:" + result.Count);
- if (result != null)
- {
- _bonusList = result;
- ShowBonusItem();
- _index++;
- Timers.inst.Add(0.3f, 1, ReqFightQuickly);
- }
- }
- }
- private void ShowBonusItem()
- {
- _ui.m_list.AddItemFromPool("ui://Main/StoryFightQuicklyBonusListItem");//AddChild(listItem.target);
- GObject obj = _ui.m_list.GetChildAt(_index);
- UI_StoryFightQuicklyBonusListItem listItem = UI_StoryFightQuicklyBonusListItem.Proxy(obj);
- listItem.m_list.itemRenderer = ListItemRender;
- listItem.m_txtTimes.SetVar("n", "" + NumberUtil.GetChiniseNumberText(_index + 1)).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;
- UI_StoryFightQuicklyBonusListItem.ProxyEnd();
- _ui.m_list.ScrollToView(_index, true);
- }
- private void ShowEnding()
- {
- // UI_StoryFightQuicklyComplete completeItem = UI_StoryFightQuicklyComplete.Proxy();
- _ui.m_list.AddItemFromPool("ui://Main/StoryFightQuicklyComplete");//AddChild(completeItem.target);
- // UI_StoryFightQuicklyComplete.ProxyEnd();
- InstanceZonesDataManager.isQuicklyFighting = false;
- _ui.m_btnExit.visible = true;
- _ui.m_list.ScrollToView(_index, true);
- UpdateBtnFightTimes();
- updateNeedItem();
- // _ui.m_comCostCurrent.visible = true;
- _index = 0;
- // this.clickBlankToClose = true;
- }
- private void ListItemRender(int index, GObject item)
- {
- 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).ShowName = true;
- (item.data as ItemView).SetComItemScale = 0.8f;
- (item.data as ItemView).SetTxtCountPos(210, 160);
- (item.data as ItemView).SetTxtNamePos(110, 200);
- // (item.data as ItemView).ShowHasCount = false;
- }
- private void UpdateBtnFightTimes()
- {
- if (_ui.m_btnExit.visible)
- {
- StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(_levelID);
- InstanceZonesDataManager.GetCanFightTime(_type, _storyType, _levelID, out _fightTimes, out string title);
- _ui.m_btnFightTimes.title = _fightType == 1 ? "挑战一次" : title;
- _ui.m_btnFightTimes.visible = _fightTimes > 0;
- _fightTimes = _fightType == 1 ? 1 : _fightTimes;
- int power = _fightTimes * levelCfg.power;
- ItemUtil.SetItemNeedNum(_ui.m_comCostCurrent, ConstItemID.POWER, power);
- _ui.m_comCostCurrent.visible = _fightTimes > 0 && power > 0;
- }
- }
- private void updateNeedItem()
- {
- bool isFinish = _needItemId > 0 && _needItemCount > 0 && ItemDataManager.GetItemNum(_needItemId) >= _needItemCount;
- if (isFinish)
- {
- _needItemCount = 0;
- }
- if (_ui.m_c1.selectedIndex == 0) return;
- _ui.m_txtItemName.text = string.Format("目标道具:{0}", ItemCfgArray.Instance.GetCfg(_needItemId).name);
- long hasCount = ItemDataManager.GetItemNum(_needItemId);
- _ui.m_txtItemNeedNum.text = (_needItemCount - hasCount) <= 0 ? "材料已足够" : string.Format("还需:{0}个", Math.Max(0, _needItemCount - hasCount));
- }
- }
- }
|