123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250 |
- using FairyGUI;
- using UI.CommonGame;
- using UI.Main;
- using System.Collections.Generic;
- namespace GFGGame
- {
- public class StoryChapterView : BaseView
- {
- private UI_StoryChapterUI _ui;
- private int _chapterID;
- private GComponent _compChapter;
- private ValueBarController _valueBarController;
- private GObject _unPasslevelItem;
- private GObject _endLevelItem;
- public override void Dispose()
- {
- if (_valueBarController != null)
- {
- _valueBarController.Dispose();
- _valueBarController = null;
- }
- base.Dispose();
- }
- protected override void Init()
- {
- base.Init();
- _ui = UI_StoryChapterUI.Create();
- viewCom = _ui.target;
- isfullScreen = true;
- }
- protected override void OnInit()
- {
- base.OnInit();
- _valueBarController = new ValueBarController(_ui.m_valueBar);
- _ui.m_btnBack.onClick.Add(OnClickBtnBack);
- _ui.m_btnHome.onClick.Add(OnClickBtnHome);
- _ui.m_bonusBox1.target.onClick.Add(() =>
- {
- OnClickBonusBox(_ui.m_bonusBox1, 0);
- });
- _ui.m_bonusBox2.target.onClick.Add(() =>
- {
- OnClickBonusBox(_ui.m_bonusBox2, 1);
- });
- _ui.m_bonusBox3.target.onClick.Add(() =>
- {
- OnClickBonusBox(_ui.m_bonusBox3, 2);
- });
- }
- protected override void OnShown()
- {
- base.OnShown();
- _chapterID = (int)viewData;
- StoryDataManager.currentChapter = _chapterID;
- _compChapter = (GComponent)UIPackage.CreateObject("Main", "CompChapter" + _chapterID);
- _ui.m_chapter.AddChild(_compChapter);
- InitChapter();
- _valueBarController.OnShown();
- if (GuideDataManager.GetGuideCount(ConstGuideId.SINGLE_FIGHT_GUIDE) <= 0)
- {
- Timers.inst.AddUpdate(UpdateToCheckGuide);
- }
- }
- protected override void OnHide()
- {
- base.OnHide();
- _unPasslevelItem = null;
- _endLevelItem = null;
- GuideController.HideGuide();
- _ui.m_chapter.RemoveChildren(0, 0, true);
- _valueBarController.OnHide();
- Timers.inst.Remove(UpdateToCheckGuide);
- }
- private void OnClickBtnBack()
- {
- ViewManager.GoBackFrom(ViewName.STORY_CHAPTER_VIEW);
- }
- private void OnClickBtnHome()
- {
- GuideController.TryCompleteGuide(ConstGuideId.SINGLE_FIGHT_GUIDE);
- GameController.GoBackToMainView();
- }
- private void InitChapter()
- {
- StoryChapterCfg chapterCfg = StoryChapterCfgArray.Instance.GetCfg(_chapterID);
- _ui.m_txtChapterName.text = StoryUtil.GetChapterOrderText(_chapterID) + "·" + chapterCfg.name;
- int starCountChapter = StoryDataManager.GetChapterStarCount(_chapterID);
- _ui.m_txtStarCount.text = "" + starCountChapter + "/" + chapterCfg.bonusStar3;
- UpdateBonusBoxName(_ui.m_bonusBox1, "" + chapterCfg.bonusStar1);
- UpdateBonusBoxName(_ui.m_bonusBox2, "" + chapterCfg.bonusStar2);
- UpdateBonusBoxName(_ui.m_bonusBox3, "" + chapterCfg.bonusStar3);
- UpdateBonusBoxStatus(_ui.m_bonusBox1, 0);
- UpdateBonusBoxStatus(_ui.m_bonusBox2, 1);
- UpdateBonusBoxStatus(_ui.m_bonusBox3, 2);
- int endLevel = 0;
- for (int i = 0; i < _compChapter.numChildren; i++)
- {
- GObject obj = _compChapter.GetChildAt(i);
- if (obj.name.IndexOf("g") == 0)
- {
- UI_CompStoryLevelItem levelItem = UI_CompStoryLevelItem.Proxy(obj);
- int level = int.Parse(levelItem.target.name.Replace("g", ""));
- if (StoryDataManager.CheckLevelUnlock(_chapterID, level))
- {
- levelItem.target.visible = true;
- levelItem.target.onClick.Clear();
- levelItem.target.onClick.Add(OnClickLevelItem);
- string levelID = _chapterID + "_" + level;
- string showId = StoryUtil.GetNormalChapterId(_chapterID) + "_" + level;
- levelItem.m_txtOrder.text = showId;
- StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(levelID);
- if (levelCfg != null)
- {
- if (levelCfg.fightID.Length > 0)
- {
- levelItem.m_bg.url = "ui://Main/zx_gka_zb_2";
- int score = StoryDataManager.GetScoreHighest(levelID);
- if (score <= 0)
- {
- levelItem.m_flower.target.visible = false;
- }
- else
- {
- levelItem.m_flower.target.visible = true;
- int starCount = StoryDataManager.GetStarCountHistory(levelID, score);
- StoryUtil.UpdateStar(starCount, levelItem.m_flower.target);
- }
- }
- else
- {
- levelItem.m_bg.url = "ui://Main/zx_gka_zb_1";
- levelItem.m_flower.target.visible = false;
- }
- levelItem.m_iconUnPass.visible = !StoryDataManager.CheckLevelPass(_chapterID, level);
- if (levelItem.m_iconUnPass.visible)
- {
- _unPasslevelItem = levelItem.target;
- }
- if (level > endLevel)
- {
- endLevel = level;
- _endLevelItem = levelItem.target;
- }
- }
- else
- {
- levelItem.target.visible = false;
- }
- }
- else
- {
- levelItem.target.visible = false;
- }
- }
- }
- if (_endLevelItem != null)
- {
- float tx = _endLevelItem.x + _endLevelItem.width / 2;
- float ty = _endLevelItem.y + _endLevelItem.height / 2;
- tx = tx - _ui.m_chapter.width / 2;
- ty = ty - _ui.m_chapter.height / 2;
- _ui.m_chapter.scrollPane.SetPosX(tx, false);
- _ui.m_chapter.scrollPane.SetPosY(ty, false);
- }
- }
- private void OnClickLevelItem(EventContext context)
- {
- UI_CompStoryLevelItem levelItem = UI_CompStoryLevelItem.Proxy(context.sender as GObject);
- int level = int.Parse(levelItem.target.name.Replace("g", ""));
- StoryController.ShowLevelView(_chapterID, level);
- }
- private void UpdateBonusBoxName(UI_CompBonusBox bonusBox, string name)
- {
- bonusBox.m_txtName.text = name;
- }
- private void UpdateBonusBoxStatus(UI_CompBonusBox bonusBox, int index)
- {
- int status = StoryDataManager.GetChapterBonusStatus(StoryDataManager.currentChapter, index);
- bonusBox.m_iconActive.visible = status == ConstBonusStatus.CAN_GET;
- if (status == ConstBonusStatus.GOT)
- {
- bonusBox.m_icon.url = "ui://Main/zx_gka_baoxiang_2";
- }
- else
- {
- bonusBox.m_icon.url = "ui://Main/zx_gka_baoxiang_1";
- }
- bonusBox.target.data = status;
- }
- private void OnClickBonusBox(UI_CompBonusBox bonusBox, int index)
- {
- int status = (int)bonusBox.target.data;
- if (status == ConstBonusStatus.CAN_GET)
- {
- List<ItemData> bonusList = StoryDataManager.GetChapterBonus(StoryDataManager.currentChapter, index);
- if (bonusList != null && bonusList.Count > 0)
- {
- ViewManager.Show(ViewName.GET_BONUS_VIEW, bonusList);
- }
- UpdateBonusBoxStatus(bonusBox, index);
- }
- else if (status == ConstBonusStatus.GOT)
- {
- PromptController.Instance.ShowFloatTextPrompt("这个宝箱已经被领取过了");
- }
- else
- {
- PromptController.Instance.ShowFloatTextPrompt("关卡总分不足,继续加油吧。");
- }
- }
- private void UpdateToCheckGuide(object param)
- {
- if (this.viewCom.parent != null)
- {
- int index = this.viewCom.parent.GetChildIndex(this.viewCom);
- if (index == this.viewCom.parent.numChildren - 1 && GRoot.inst.GetTopWindow() == null)
- {
- if (StoryDataManager.CheckLevelPass(1, 4))
- {
- GuideController.TryGuideByGuideId(_ui.m_btnHome, ConstGuideId.SINGLE_FIGHT_GUIDE, 1, false, "点击按钮,进入主界面");
- }
- else
- {
- if (_unPasslevelItem != null)
- {
- GuideController.TryGuideChapterViewLevelItem(_unPasslevelItem);
- }
- }
- }
- }
- }
- }
- }
|