记录上次关卡的自动跳转

main
yurui 2025-03-10 15:07:40 +08:00
parent e57d7b1224
commit 47c19fc603
1 changed files with 43 additions and 23 deletions

View File

@ -300,6 +300,10 @@ public class UI_LevelSelectController : UIWindow
/// 选中章节
/// </summary>
private readonly Action<ChapterInfo, E_LevelDifficulty> selectChapterAction;
/// <summary>
/// 上次战斗的关卡
/// </summary>
private LevelInfo lastFightLevel;
#region 属性
/// <summary>
@ -365,10 +369,12 @@ public class UI_LevelSelectController : UIWindow
/// </summary>
/// <param name="chapterInfo"></param>
/// <param name="isLastFight">是否上次战斗的关卡</param>
public void SetInfo(ChapterInfo info, bool isLastFight)
public void SetInfo(ChapterInfo info, LevelInfo lastFightLevelInfo)
{
chapterInfo = info;
lastFightLevel = lastFightLevelInfo;
redPointUIController.NodeID = chapterInfo.RedPoint.ID;
textChapterName.text = chapterInfo.Name;
textChapterDesc.text = chapterInfo.Desc;
@ -397,14 +403,17 @@ public class UI_LevelSelectController : UIWindow
IsDifficultLock = true;
}
goLast.IsScaleShow(isLastFight);
goLast.IsScaleShow(lastFightLevel.ChapterInfo.Cfg.Id == chapterInfo.Cfg.Id);
IsScaleShow = true;
}
private void OnClick()
{
selectChapterAction?.Invoke(chapterInfo, E_LevelDifficulty.Easy);
if (null == lastFightLevel || lastFightLevel.ChapterInfo.Cfg.Id != chapterInfo.Cfg.Id)
selectChapterAction?.Invoke(chapterInfo, E_LevelDifficulty.Easy);
else
selectChapterAction?.Invoke(chapterInfo, lastFightLevel.GroupInfo.Cfg.LevelDifficulty);
}
}
@ -412,10 +421,7 @@ public class UI_LevelSelectController : UIWindow
/// 选项字典
/// </summary>
private readonly Dictionary<int, ChapterItem> dicChapterItem = new();
/// <summary>
/// 上次战斗的章节id
/// </summary>
private int lastFightChapterId;
private LevelInfo lastLevelInfo;
public MainChapter(GameObject root, Action<ChapterInfo, E_LevelDifficulty> selectChapter) : base(root, E_ChapterType.Main, selectChapter)
{
@ -425,11 +431,7 @@ public class UI_LevelSelectController : UIWindow
{
base.SetInfo();
LevelInfo levelInfo = LevelManager.Instance.GetLastFightLevelInfo(chapterType);
if (null == levelInfo)
lastFightChapterId = -1;
else
lastFightChapterId = levelInfo.ChapterInfo.Cfg.Id;
lastLevelInfo = LevelManager.Instance.GetLastFightLevelInfo(chapterType);
recycleView.ShowList(listChapterInfo.Count);
@ -459,7 +461,7 @@ public class UI_LevelSelectController : UIWindow
}
ChapterInfo chapterInfo = listChapterInfo[index];
chapterItem.SetInfo(chapterInfo, chapterInfo.Cfg.Id == lastFightChapterId);
chapterItem.SetInfo(chapterInfo, lastLevelInfo);
}
}
@ -980,17 +982,17 @@ public class UI_LevelSelectController : UIWindow
{
if (null == chapterInfo)
{
levelList.SetInfo(null);
levelList.SetInfo(null, E_ChapterType.Count);
return;
}
if (!chapterInfo.TryGetGroupInfo(levelDifficulty, out levelGroupInfo))
{
levelList.SetInfo(null);
levelList.SetInfo(null, E_ChapterType.Count);
return;
}
levelList.SetInfo(levelGroupInfo.ListLevelInfo);
levelList.SetInfo(levelGroupInfo.ListLevelInfo, levelGroupInfo.ChapterInfo.Cfg.Type);
}
}
@ -1792,7 +1794,7 @@ public class UI_LevelSelectController : UIWindow
recycleView.Init(RefreshCell);
}
public async void SetInfo(List<LevelInfo> listInfo)
public async void SetInfo(List<LevelInfo> listInfo, E_ChapterType chapterType)
{
listLevelInfo = listInfo;
if (null == listLevelInfo)
@ -1803,15 +1805,33 @@ public class UI_LevelSelectController : UIWindow
return;
}
int index = 0; // 最后一个解锁的关卡信息
for (int i = listInfo.Count - 1; i >= 0; --i)
#region 记录需要跳转到的指定位置
int index = -1; // 上次通过位置
LevelInfo lastlevelInfo = LevelManager.Instance.GetLastFightLevelInfo(chapterType);
if (null != lastlevelInfo)
{
if (listInfo[i].IsLock)
continue;
for (int i = 0; i < listLevelInfo.Count; ++i)
{
if (listLevelInfo[i].Cfg.Id != lastlevelInfo.Cfg.Id)
continue;
index = i;
break;
index = i;
break;
}
}
if (-1 == index)
{
index = 0; // 最后一个解锁的关卡信息
for (int i = listLevelInfo.Count - 1; i >= 0; --i)
{
if (listLevelInfo[i].IsLock)
continue;
index = i;
break;
}
}
#endregion
recycleView.ShowList(listLevelInfo.Count);
IsScaleShow = true;