1707 lines
53 KiB
C#
1707 lines
53 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.Data;
|
||
using System.Linq;
|
||
using System.Net.Sockets;
|
||
using System.Threading;
|
||
using cfg.FightCfg;
|
||
using cfg.LevelCfg;
|
||
using Cysharp.Threading.Tasks;
|
||
using Framework;
|
||
using Gameplay;
|
||
using Gameplay.Common;
|
||
using Gameplay.Level;
|
||
using Gameplay.Net;
|
||
using PhxhSDK;
|
||
using TMPro;
|
||
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
using Constants = Framework.Constants;
|
||
|
||
public class UI_LevelSelectController : UIWindow
|
||
{
|
||
/// <summary>
|
||
/// 打开关卡选择界面
|
||
/// </summary>
|
||
/// <param name="levelInfo">有数据则跳转到对应关卡选项,没有数据则显示默认</param>
|
||
/// <returns></returns>
|
||
public static async UniTask<UIWindow> Open(LevelInfo levelInfo = null)
|
||
{
|
||
// 切换场景会有瞬间卡顿,先打开UI
|
||
UIWindow uiWindow = await UIManager.Instance.CreateAndOpenWindow(UINameConst.UI_LevelSelect, levelInfo);
|
||
|
||
CommonUtils.ChangeUIScene(Constants.UI_LEVEL_SELECTED_SCENE_PATH); // 切换到关卡选择场景
|
||
CameraManager.Instance.SetMainCameraActive(true);
|
||
|
||
return uiWindow;
|
||
}
|
||
|
||
#region 结构
|
||
/// <summary>
|
||
/// 页签模式
|
||
/// </summary>
|
||
private enum E_PageModeType
|
||
{
|
||
None,
|
||
/// <summary>
|
||
/// 章节
|
||
/// </summary>
|
||
Chapter,
|
||
/// <summary>
|
||
/// 关卡
|
||
/// </summary>
|
||
Level,
|
||
}
|
||
|
||
/// <summary>
|
||
/// 模式按钮
|
||
/// </summary>
|
||
private class ModeButton : UIGameObjectWrapper
|
||
{
|
||
#region UI
|
||
/// <summary>
|
||
/// 章节按钮
|
||
/// </summary>
|
||
private Button button;
|
||
/// <summary>
|
||
/// 选中状态
|
||
/// </summary>
|
||
private GameObject goSelect;
|
||
/// <summary>
|
||
/// 未选中状态
|
||
/// </summary>
|
||
private GameObject goUnSelect;
|
||
/// <summary>
|
||
/// 选中箭头
|
||
/// </summary>
|
||
private GameObject goTriangle;
|
||
#endregion
|
||
|
||
/// <summary>
|
||
/// 选择模式
|
||
/// </summary>
|
||
private readonly Action<E_ChapterType> selectModeAction;
|
||
/// <summary>
|
||
/// 章节类型
|
||
/// </summary>
|
||
private readonly E_ChapterType chapterType;
|
||
|
||
public bool IsSelect
|
||
{
|
||
set
|
||
{
|
||
goSelect.IsScaleShow(value);
|
||
goTriangle.IsScaleShow(value);
|
||
goUnSelect.IsScaleShow(!value);
|
||
}
|
||
}
|
||
|
||
public ModeButton(GameObject root, E_ChapterType type, Action<E_ChapterType> selectMode) : base(root, true)
|
||
{
|
||
chapterType = type;
|
||
selectModeAction = selectMode;
|
||
|
||
button = GoRoot.GetComponent<Button>();
|
||
goSelect = FindObj("Image_Selected");
|
||
goUnSelect = FindObj("Image_Unselect");
|
||
goTriangle = FindObj("Image_Triangle");
|
||
|
||
IsSelect = false;
|
||
|
||
BindButton(button, OnClick);
|
||
}
|
||
|
||
private void OnClick()
|
||
{
|
||
selectModeAction?.Invoke(chapterType);
|
||
}
|
||
}
|
||
|
||
#region 章节
|
||
/// <summary>
|
||
/// 章节基类
|
||
/// </summary>
|
||
private abstract class ChapterBase : UIGameObjectWrapper
|
||
{
|
||
/// <summary>
|
||
/// 动态列表
|
||
/// </summary>
|
||
protected RecycleView recycleView;
|
||
|
||
/// <summary>
|
||
/// 电池
|
||
/// </summary>
|
||
private readonly Batterie batterie;
|
||
/// <summary>
|
||
/// wifi
|
||
/// </summary>
|
||
private readonly NetSignal netSignal;
|
||
/// <summary>
|
||
/// 章节信息
|
||
/// </summary>
|
||
protected readonly E_ChapterType chapterType;
|
||
/// <summary>
|
||
/// 章节信息
|
||
/// </summary>
|
||
protected List<ChapterInfo> listChapterInfo;
|
||
/// <summary>
|
||
/// 选择章节回调
|
||
/// </summary>
|
||
private readonly Action<ChapterInfo> selectChapterAction;
|
||
|
||
public new bool IsScaleShow
|
||
{
|
||
get
|
||
{
|
||
if (GoRoot.transform.localScale.x == 0f)
|
||
return false;
|
||
|
||
if (GoRoot.transform.localScale.y == 0f)
|
||
return false;
|
||
|
||
return true;
|
||
}
|
||
set
|
||
{
|
||
GoRoot.IsScaleShow(value);
|
||
IsEnableRecycleView = value;
|
||
if (value)
|
||
recycleView.ScrollRect.verticalNormalizedPosition = 1f;
|
||
}
|
||
}
|
||
|
||
public bool IsEnableRecycleView
|
||
{
|
||
set
|
||
{
|
||
recycleView.ScrollRect.enabled = value;
|
||
}
|
||
}
|
||
|
||
public ChapterBase(GameObject root, E_ChapterType chapter, Action<ChapterInfo> selectChapter) : base(root)
|
||
{
|
||
chapterType = chapter;
|
||
selectChapterAction = selectChapter;
|
||
|
||
recycleView = GetComponent<RecycleView>("RecycleView");
|
||
|
||
batterie = new Batterie(FindObj("Image_BottomBar/BatteryRoot"));
|
||
netSignal = new NetSignal(FindObj("Image_BottomBar/SignalRoot"));
|
||
|
||
IsScaleShow = false;
|
||
|
||
recycleView.Init(RefreshCell);
|
||
}
|
||
|
||
public virtual void SetInfo()
|
||
{
|
||
RefreshBatterie();
|
||
RefreshNetSignal();
|
||
|
||
if (!LevelManager.Instance.TryGetChapterInfosByType(chapterType, out listChapterInfo))
|
||
{
|
||
DebugUtil.LogError($"没有获取到{chapterType}类型的章节信息");
|
||
return;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 刷新电量
|
||
/// </summary>
|
||
/// <param name="batteryPower"></param>
|
||
public void RefreshBatterie()
|
||
{
|
||
batterie.SetInfo();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 刷新信号
|
||
/// </summary>
|
||
/// <param name="networkSignal"></param>
|
||
public void RefreshNetSignal()
|
||
{
|
||
netSignal.SetInfo();
|
||
}
|
||
|
||
protected abstract void RefreshCell(GameObject cell, int index);
|
||
|
||
/// <summary>
|
||
/// 点击章节
|
||
/// </summary>
|
||
/// <param name="chapterInfo"></param>
|
||
protected void OnChapter(ChapterInfo chapterInfo)
|
||
{
|
||
selectChapterAction?.Invoke(chapterInfo);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 主线章节
|
||
/// </summary>
|
||
private class MainChapter : ChapterBase
|
||
{
|
||
/// <summary>
|
||
/// 列表章节选项
|
||
/// </summary>
|
||
private class ChapterItem : UIGameObjectWrapper
|
||
{
|
||
#region UI
|
||
/// <summary>
|
||
/// 选中章节
|
||
/// </summary>
|
||
private Button button;
|
||
/// <summary>
|
||
/// 章节名
|
||
/// </summary>
|
||
private TMP_Text textChapterName;
|
||
/// <summary>
|
||
/// 章节描述
|
||
/// </summary>
|
||
private TMP_Text textChapterDesc;
|
||
/// <summary>
|
||
/// 简单星星数量
|
||
/// </summary>
|
||
private TMP_Text textEasyStarCount;
|
||
/// <summary>
|
||
/// 困难星星数量
|
||
/// </summary>
|
||
private TMP_Text textDifficultStarCount;
|
||
/// <summary>
|
||
/// 上次泊车标志
|
||
/// </summary>
|
||
private GameObject goLast;
|
||
/// <summary>
|
||
/// 简单星星未激活状态
|
||
/// </summary>
|
||
private GameObject goEasyStar;
|
||
/// <summary>
|
||
/// 简单星星激活状态
|
||
/// </summary>
|
||
private GameObject goEasyStarEnable;
|
||
/// <summary>
|
||
/// 困难星星未激活状态
|
||
/// </summary>
|
||
private GameObject goDifficultStar;
|
||
/// <summary>
|
||
/// 困难星星激活状态
|
||
/// </summary>
|
||
private GameObject goDifficultStarEnable;
|
||
#endregion
|
||
|
||
/// <summary>
|
||
/// 章节信息
|
||
/// </summary>
|
||
private ChapterInfo chapterInfo;
|
||
/// <summary>
|
||
/// 选中章节
|
||
/// </summary>
|
||
private readonly Action<ChapterInfo> selectChapterAction;
|
||
|
||
#region 属性
|
||
/// <summary>
|
||
/// 是否显示简单星星
|
||
/// </summary>
|
||
public bool IsShowEasyStar
|
||
{
|
||
set
|
||
{
|
||
goEasyStarEnable.IsScaleShow(value);
|
||
goEasyStar.IsScaleShow(!value);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 是否显示困难星星
|
||
/// </summary>
|
||
public bool IsShowDiffcultStar
|
||
{
|
||
set
|
||
{
|
||
goDifficultStarEnable.IsScaleShow(value);
|
||
goDifficultStar.IsScaleShow(!value);
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
public ChapterItem(GameObject root, Action<ChapterInfo> selectChapter) : base(root)
|
||
{
|
||
selectChapterAction = selectChapter;
|
||
|
||
button = GoRoot.GetComponent<Button>();
|
||
textChapterName = GetComponent<TMP_Text>("Text_LevelName");
|
||
textChapterDesc = GetComponent<TMP_Text>("Text_Episode");
|
||
textEasyStarCount = GetComponent<TMP_Text>("UI_Easy/Text_Progress");
|
||
textDifficultStarCount = GetComponent<TMP_Text>("UI_Difficult/Text_Progress");
|
||
goLast = FindObj("Image_Last");
|
||
goEasyStar = FindObj("UI_Easy/Image_StarOff");
|
||
goEasyStarEnable = FindObj("UI_Easy/Image_StarOn");
|
||
goDifficultStar = FindObj("UI_Difficult/Image_StarOff");
|
||
goDifficultStarEnable = FindObj("UI_Difficult/Image_StarOn");
|
||
|
||
BindButton(button, OnClick);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 入口
|
||
/// </summary>
|
||
/// <param name="chapterInfo"></param>
|
||
/// <param name="isLastFight">是否上次战斗的关卡</param>
|
||
public void SetInfo(ChapterInfo info, bool isLastFight)
|
||
{
|
||
chapterInfo = info;
|
||
|
||
textChapterName.text = chapterInfo.Name;
|
||
textChapterDesc.text = chapterInfo.Desc;
|
||
|
||
if (chapterInfo.TryGetGroupInfo(E_LevelDifficulty.Easy, out LevelGroupInfo easyGroupInfo))
|
||
{
|
||
textEasyStarCount.text = $"{easyGroupInfo.StarCount}/{easyGroupInfo.StarMax}";
|
||
IsShowEasyStar = easyGroupInfo.StarCount >= easyGroupInfo.StarMax;
|
||
}
|
||
else
|
||
{
|
||
textEasyStarCount.text = "0/0";
|
||
IsShowEasyStar = false;
|
||
}
|
||
|
||
if (chapterInfo.TryGetGroupInfo(E_LevelDifficulty.Hard, out LevelGroupInfo diffcultGroupInfo))
|
||
{
|
||
textDifficultStarCount.text = $"{diffcultGroupInfo.StarCount}/{diffcultGroupInfo.StarMax}";
|
||
IsShowDiffcultStar = diffcultGroupInfo.StarCount >= diffcultGroupInfo.StarMax;
|
||
}
|
||
else
|
||
{
|
||
textDifficultStarCount.text = "0/0";
|
||
IsShowDiffcultStar = false;
|
||
}
|
||
|
||
goLast.IsScaleShow(isLastFight);
|
||
|
||
IsScaleShow = true;
|
||
}
|
||
|
||
private void OnClick()
|
||
{
|
||
selectChapterAction?.Invoke(chapterInfo);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 选项字典
|
||
/// </summary>
|
||
private readonly Dictionary<int, ChapterItem> dicChapterItem = new();
|
||
/// <summary>
|
||
/// 上次战斗的章节id
|
||
/// </summary>
|
||
private int lastFightChapterId;
|
||
|
||
public MainChapter(GameObject root, Action<ChapterInfo> selectChapter) : base(root, E_ChapterType.Main, selectChapter)
|
||
{
|
||
}
|
||
|
||
public override void SetInfo()
|
||
{
|
||
base.SetInfo();
|
||
|
||
LevelInfo levelInfo = LevelManager.Instance.GetLastFightLevelInfo(chapterType);
|
||
if (null == levelInfo)
|
||
lastFightChapterId = -1;
|
||
else
|
||
lastFightChapterId = levelInfo.ChapterInfo.Cfg.Id;
|
||
|
||
recycleView.ShowList(listChapterInfo.Count);
|
||
|
||
IsScaleShow = true;
|
||
}
|
||
|
||
protected override void RefreshCell(GameObject cell, int index)
|
||
{
|
||
if (!dicChapterItem.TryGetValue(cell.GetInstanceID(), out ChapterItem chapterItem))
|
||
{
|
||
chapterItem = new(cell, OnChapter);
|
||
dicChapterItem.Add(cell.GetInstanceID(), chapterItem);
|
||
}
|
||
|
||
if (null == listChapterInfo)
|
||
{
|
||
DebugUtil.LogError("章节列表无效");
|
||
chapterItem.IsScaleShow = false;
|
||
return;
|
||
}
|
||
|
||
if (index < 0 || index >= listChapterInfo.Count)
|
||
{
|
||
DebugUtil.LogError("越界");
|
||
chapterItem.IsScaleShow = false;
|
||
return;
|
||
}
|
||
|
||
ChapterInfo chapterInfo = listChapterInfo[index];
|
||
chapterItem.SetInfo(chapterInfo, chapterInfo.Cfg.Id == lastFightChapterId);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 资源章节
|
||
/// </summary>
|
||
private class ResourceChapter : ChapterBase
|
||
{
|
||
/// <summary>
|
||
/// 列表章节选项
|
||
/// </summary>
|
||
private class ChapterItem : UIGameObjectWrapper
|
||
{
|
||
#region UI
|
||
/// <summary>
|
||
/// 选中章节
|
||
/// </summary>
|
||
private Button button;
|
||
/// <summary>
|
||
/// 章节名
|
||
/// </summary>
|
||
private TMP_Text textChapterName;
|
||
/// <summary>
|
||
/// 章节描述
|
||
/// </summary>
|
||
private TMP_Text textChapterDesc;
|
||
/// <summary>
|
||
/// 星星数量
|
||
/// </summary>
|
||
private TMP_Text textStarCount;
|
||
/// <summary>
|
||
/// 上次泊车标志
|
||
/// </summary>
|
||
private GameObject goLast;
|
||
/// <summary>
|
||
/// 星星未激活状态
|
||
/// </summary>
|
||
private GameObject goStar;
|
||
/// <summary>
|
||
/// 星星激活状态
|
||
/// </summary>
|
||
private GameObject goStarEnable;
|
||
#endregion
|
||
|
||
/// <summary>
|
||
/// 章节信息
|
||
/// </summary>
|
||
private ChapterInfo chapterInfo;
|
||
/// <summary>
|
||
/// 选中章节
|
||
/// </summary>
|
||
private readonly Action<ChapterInfo> selectChapterAction;
|
||
|
||
/// <summary>
|
||
/// 是否显示星星
|
||
/// </summary>
|
||
public bool IsShowStar
|
||
{
|
||
set
|
||
{
|
||
goStarEnable.IsScaleShow(value);
|
||
goStar.IsScaleShow(!value);
|
||
}
|
||
}
|
||
|
||
public ChapterItem(GameObject root, Action<ChapterInfo> selectChapter) : base(root)
|
||
{
|
||
selectChapterAction = selectChapter;
|
||
|
||
button = GoRoot.GetComponent<Button>();
|
||
textChapterName = GetComponent<TMP_Text>("Text_LevelName");
|
||
textChapterDesc = GetComponent<TMP_Text>("Text_Episode");
|
||
textStarCount = GetComponent<TMP_Text>("UI_Collect/Text_Progress");
|
||
goLast = FindObj("Image_Last");
|
||
goStar = FindObj("UI_Collect/Image_StarOff");
|
||
goStarEnable = FindObj("UI_Collect/Image_StarOn");
|
||
|
||
BindButton(button, OnClick);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 入口
|
||
/// </summary>
|
||
/// <param name="chapterInfo"></param>
|
||
/// <param name="isLastFight">是否上次战斗的关卡</param>
|
||
public void SetInfo(ChapterInfo info, bool isLastFight)
|
||
{
|
||
chapterInfo = info;
|
||
|
||
textChapterName.text = chapterInfo.Name;
|
||
textChapterDesc.text = chapterInfo.Desc;
|
||
|
||
if (chapterInfo.TryGetGroupInfo(E_LevelDifficulty.None, out LevelGroupInfo easyGroupInfo))
|
||
{
|
||
textStarCount.text = $"{easyGroupInfo.StarCount}/{easyGroupInfo.StarMax}";
|
||
IsShowStar = easyGroupInfo.StarCount >= easyGroupInfo.StarMax;
|
||
}
|
||
else
|
||
{
|
||
textStarCount.text = "0/0";
|
||
IsShowStar = false;
|
||
}
|
||
|
||
goLast.IsScaleShow(isLastFight);
|
||
|
||
IsScaleShow = true;
|
||
}
|
||
|
||
private void OnClick()
|
||
{
|
||
selectChapterAction?.Invoke(chapterInfo);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 选项字典
|
||
/// </summary>
|
||
private readonly Dictionary<int, ChapterItem> dicChapterItem = new();
|
||
/// <summary>
|
||
/// 上次战斗的章节id
|
||
/// </summary>
|
||
private int lastFightChapterId;
|
||
|
||
public ResourceChapter(GameObject root, Action<ChapterInfo> selectChapter) : base(root, E_ChapterType.Resource, selectChapter)
|
||
{ }
|
||
|
||
public override void SetInfo()
|
||
{
|
||
base.SetInfo();
|
||
|
||
LevelInfo levelInfo = LevelManager.Instance.GetLastFightLevelInfo(chapterType);
|
||
if (null == levelInfo)
|
||
lastFightChapterId = -1;
|
||
else
|
||
lastFightChapterId = levelInfo.ChapterInfo.Cfg.Id;
|
||
|
||
recycleView.ShowList(listChapterInfo.Count);
|
||
|
||
IsScaleShow = true;
|
||
}
|
||
|
||
protected override void RefreshCell(GameObject cell, int index)
|
||
{
|
||
if (!dicChapterItem.TryGetValue(cell.GetInstanceID(), out ChapterItem chapterItem))
|
||
{
|
||
chapterItem = new(cell, OnChapter);
|
||
dicChapterItem.Add(cell.GetInstanceID(), chapterItem);
|
||
}
|
||
|
||
if (null == listChapterInfo)
|
||
{
|
||
DebugUtil.LogError("章节列表无效");
|
||
chapterItem.IsScaleShow = false;
|
||
return;
|
||
}
|
||
|
||
if (index < 0 || index >= listChapterInfo.Count)
|
||
{
|
||
DebugUtil.LogError("越界");
|
||
chapterItem.IsScaleShow = false;
|
||
return;
|
||
}
|
||
|
||
ChapterInfo chapterInfo = listChapterInfo[index];
|
||
chapterItem.SetInfo(chapterInfo, chapterInfo.Cfg.Id == lastFightChapterId);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 剧情章节
|
||
/// </summary>
|
||
private class StoryChapter : ChapterBase
|
||
{
|
||
/// <summary>
|
||
/// 列表章节选项
|
||
/// </summary>
|
||
private class ChapterItem : UIGameObjectWrapper
|
||
{
|
||
#region UI
|
||
/// <summary>
|
||
/// 选中章节
|
||
/// </summary>
|
||
private Button button;
|
||
/// <summary>
|
||
/// 章节名
|
||
/// </summary>
|
||
private TMP_Text textChapterName;
|
||
/// <summary>
|
||
/// 章节描述
|
||
/// </summary>
|
||
private TMP_Text textChapterDesc;
|
||
/// <summary>
|
||
/// 上次泊车标志
|
||
/// </summary>
|
||
private GameObject goLast;
|
||
#endregion
|
||
|
||
/// <summary>
|
||
/// 章节信息
|
||
/// </summary>
|
||
private ChapterInfo chapterInfo;
|
||
/// <summary>
|
||
/// 选中章节
|
||
/// </summary>
|
||
private readonly Action<ChapterInfo> selectChapterAction;
|
||
|
||
public ChapterItem(GameObject root, Action<ChapterInfo> selectChapter) : base(root)
|
||
{
|
||
selectChapterAction = selectChapter;
|
||
|
||
button = GoRoot.GetComponent<Button>();
|
||
textChapterName = GetComponent<TMP_Text>("Text_LevelName");
|
||
textChapterDesc = GetComponent<TMP_Text>("Text_Episode");
|
||
goLast = FindObj("Image_Last");
|
||
|
||
BindButton(button, OnClick);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 入口
|
||
/// </summary>
|
||
/// <param name="chapterInfo"></param>
|
||
/// <param name="isLastFight">是否上次战斗的关卡</param>
|
||
public void SetInfo(ChapterInfo info, bool isLastFight)
|
||
{
|
||
chapterInfo = info;
|
||
|
||
textChapterName.text = chapterInfo.Name;
|
||
textChapterDesc.text = chapterInfo.Desc;
|
||
|
||
goLast.IsScaleShow(isLastFight);
|
||
|
||
IsScaleShow = true;
|
||
}
|
||
|
||
private void OnClick()
|
||
{
|
||
selectChapterAction?.Invoke(chapterInfo);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 选项字典
|
||
/// </summary>
|
||
private readonly Dictionary<int, ChapterItem> dicChapterItem = new();
|
||
/// <summary>
|
||
/// 上次战斗的章节id
|
||
/// </summary>
|
||
private int lastFightChapterId;
|
||
|
||
public StoryChapter(GameObject root, Action<ChapterInfo> selectChapter) : base(root, E_ChapterType.Storyline, selectChapter)
|
||
{
|
||
}
|
||
|
||
public override void SetInfo()
|
||
{
|
||
base.SetInfo();
|
||
|
||
LevelInfo levelInfo = LevelManager.Instance.GetLastFightLevelInfo(chapterType);
|
||
if (null == levelInfo)
|
||
lastFightChapterId = -1;
|
||
else
|
||
lastFightChapterId = levelInfo.ChapterInfo.Cfg.Id;
|
||
|
||
recycleView.ShowList(listChapterInfo.Count);
|
||
|
||
IsScaleShow = true;
|
||
}
|
||
|
||
protected override void RefreshCell(GameObject cell, int index)
|
||
{
|
||
if (!dicChapterItem.TryGetValue(cell.GetInstanceID(), out ChapterItem chapterItem))
|
||
{
|
||
chapterItem = new(cell, OnChapter);
|
||
dicChapterItem.Add(cell.GetInstanceID(), chapterItem);
|
||
}
|
||
|
||
if (null == listChapterInfo)
|
||
{
|
||
DebugUtil.LogError("章节列表无效");
|
||
chapterItem.IsScaleShow = false;
|
||
return;
|
||
}
|
||
|
||
if (index < 0 || index >= listChapterInfo.Count)
|
||
{
|
||
DebugUtil.LogError("越界");
|
||
chapterItem.IsScaleShow = false;
|
||
return;
|
||
}
|
||
|
||
ChapterInfo chapterInfo = listChapterInfo[index];
|
||
chapterItem.SetInfo(chapterInfo, chapterInfo.Cfg.Id == lastFightChapterId);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 战役章节
|
||
/// </summary>
|
||
private class WarChapter : ChapterBase
|
||
{
|
||
public WarChapter(GameObject root, Action<ChapterInfo> selectChapter) : base(root, E_ChapterType.War, selectChapter)
|
||
{
|
||
|
||
}
|
||
|
||
protected override void RefreshCell(GameObject cell, int index)
|
||
{
|
||
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 关卡
|
||
/// <summary>
|
||
/// 选关基类
|
||
/// </summary>
|
||
private abstract class SelectLevelBase : UIGameObjectWrapper
|
||
{
|
||
/// <summary>
|
||
/// 关卡难度
|
||
/// </summary>
|
||
protected E_LevelDifficulty levelDifficulty;
|
||
/// <summary>
|
||
/// 章节信息
|
||
/// </summary>
|
||
protected readonly E_ChapterType chapterType;
|
||
/// <summary>
|
||
/// 关卡列表
|
||
/// </summary>
|
||
protected readonly LevelList levelList;
|
||
/// <summary>
|
||
/// 章节信息
|
||
/// </summary>
|
||
protected ChapterInfo chapterInfo;
|
||
|
||
public bool IsEnableRecycleView
|
||
{
|
||
set { levelList.IsEnableRecycleView = value; }
|
||
}
|
||
|
||
public SelectLevelBase(GameObject root, E_ChapterType chapter, LevelList list) : base(root)
|
||
{
|
||
chapterType = chapter;
|
||
levelList = list;
|
||
levelDifficulty = chapterType switch
|
||
{
|
||
E_ChapterType.Main => E_LevelDifficulty.Easy,
|
||
E_ChapterType.Resource or
|
||
E_ChapterType.Storyline or
|
||
E_ChapterType.War or
|
||
_ => E_LevelDifficulty.None,
|
||
};
|
||
}
|
||
|
||
public virtual void SetInfo(ChapterInfo info)
|
||
{
|
||
chapterInfo = info;
|
||
|
||
RefreshLevelList();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 刷新关卡列表
|
||
/// </summary>
|
||
protected virtual void RefreshLevelList()
|
||
{
|
||
if (null == chapterInfo)
|
||
{
|
||
levelList.SetInfo(null);
|
||
return;
|
||
}
|
||
|
||
if (!chapterInfo.TryGetGroupInfo(levelDifficulty, out LevelGroupInfo levelGroupInfo))
|
||
{
|
||
levelList.SetInfo(null);
|
||
return;
|
||
}
|
||
|
||
levelList.SetInfo(levelGroupInfo.ListLevelInfo);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 主线选关类
|
||
/// </summary>
|
||
private class MainSelectLevel : SelectLevelBase
|
||
{
|
||
#region UI
|
||
/// <summary>
|
||
/// 简单
|
||
/// </summary>
|
||
private Button buttonEasy;
|
||
/// <summary>
|
||
/// 困难
|
||
/// </summary>
|
||
private Button buttonDifficult;
|
||
/// <summary>
|
||
/// 领取奖励
|
||
/// </summary>
|
||
private Button buttonGetReward;
|
||
/// <summary>
|
||
/// 星星进度文本
|
||
/// </summary>
|
||
private TMP_Text textStarProgress;
|
||
/// <summary>
|
||
/// 星星进度条
|
||
/// </summary>
|
||
private Image imageStarProgress;
|
||
/// <summary>
|
||
/// 不能领取奖励状态
|
||
/// </summary>
|
||
private GameObject goGetRewardOff;
|
||
/// <summary>
|
||
/// 简单选中
|
||
/// </summary>
|
||
private GameObject goEasySelect;
|
||
/// <summary>
|
||
/// 简单未选中
|
||
/// </summary>
|
||
private GameObject goEasyUnselect;
|
||
/// <summary>
|
||
/// 困难选中
|
||
/// </summary>
|
||
private GameObject goDifficultSelect;
|
||
/// <summary>
|
||
/// 困难未选中
|
||
/// </summary>
|
||
private GameObject goDifficultUnselect;
|
||
#endregion
|
||
|
||
#region 属性
|
||
/// <summary>
|
||
/// 简单是否选中
|
||
/// </summary>
|
||
public bool IsEasySelect
|
||
{
|
||
set
|
||
{
|
||
goEasySelect.IsScaleShow(value);
|
||
goEasyUnselect.IsScaleShow(!value);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 困难是否选中
|
||
/// </summary>
|
||
public bool IsDifficultSelect
|
||
{
|
||
set
|
||
{
|
||
goDifficultSelect.IsScaleShow(value);
|
||
goDifficultUnselect.IsScaleShow(!value);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 是否显示领取奖励
|
||
/// </summary>
|
||
public bool IsShowGetReward
|
||
{
|
||
set
|
||
{
|
||
buttonGetReward.gameObject.IsScaleShow(value);
|
||
goGetRewardOff.IsScaleShow(!value);
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
public MainSelectLevel(GameObject root, LevelList levelList) : base(root, E_ChapterType.Main, levelList)
|
||
{
|
||
buttonEasy = GetComponent<Button>("Image_MainMission/UI_Easy");
|
||
buttonDifficult = GetComponent<Button>("Image_MainMission/UI_Difficult");
|
||
buttonGetReward = GetComponent<Button>("UI_StarProgress/Button_GetRewardOn");
|
||
textStarProgress = GetComponent<TMP_Text>("UI_StarProgress/Image_StarProgress/Text_Progress");
|
||
imageStarProgress = GetComponent<Image>("UI_StarProgress/Image_StarProgress/Image_ProgressBar");
|
||
goGetRewardOff = FindObj("UI_StarProgress/Button_GetRewardOff");
|
||
goEasySelect = FindObj("Image_MainMission/UI_Easy/UI_Selected");
|
||
goEasyUnselect = FindObj("Image_MainMission/UI_Easy/UI_Unselect");
|
||
goDifficultSelect = FindObj("Image_MainMission/UI_Difficult/UI_Selected");
|
||
goDifficultUnselect = FindObj("Image_MainMission/UI_Difficult/UI_Unselect");
|
||
|
||
switch (levelDifficulty)
|
||
{
|
||
case E_LevelDifficulty.Easy:
|
||
{
|
||
IsEasySelect = true;
|
||
IsDifficultSelect = false;
|
||
}
|
||
break;
|
||
case E_LevelDifficulty.Hard:
|
||
{
|
||
IsEasySelect = false;
|
||
IsDifficultSelect = true;
|
||
}
|
||
break;
|
||
default:
|
||
{
|
||
DebugUtil.LogError($"未处理类型{levelDifficulty}");
|
||
}
|
||
break;
|
||
}
|
||
|
||
BindButton(buttonEasy, () => { OnDifficult(E_LevelDifficulty.Easy); });
|
||
BindButton(buttonDifficult, () => { OnDifficult(E_LevelDifficulty.Hard); });
|
||
}
|
||
|
||
public override void SetInfo(ChapterInfo info)
|
||
{
|
||
base.SetInfo(info);
|
||
|
||
if (chapterInfo.TryGetGroupInfo(levelDifficulty, out LevelGroupInfo easyGroupInfo))
|
||
{
|
||
textStarProgress.text = $"{easyGroupInfo.StarCount}/{easyGroupInfo.StarMax}";
|
||
imageStarProgress.fillAmount = (float)easyGroupInfo.StarCount / easyGroupInfo.StarMax;
|
||
}
|
||
else
|
||
{
|
||
textStarProgress.text = "0/0";
|
||
imageStarProgress.fillAmount = 1f;
|
||
}
|
||
|
||
IsScaleShow = true;
|
||
}
|
||
|
||
protected override void RefreshLevelList()
|
||
{
|
||
base.RefreshLevelList();
|
||
|
||
if (chapterInfo.TryGetGroupInfo(levelDifficulty, out LevelGroupInfo easyGroupInfo))
|
||
{
|
||
textStarProgress.text = $"{easyGroupInfo.StarCount}/{easyGroupInfo.StarMax}";
|
||
imageStarProgress.fillAmount = (float)easyGroupInfo.StarCount / easyGroupInfo.StarMax;
|
||
}
|
||
else
|
||
{
|
||
textStarProgress.text = "0/0";
|
||
imageStarProgress.fillAmount = 1f;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 点击关卡难度
|
||
/// </summary>
|
||
/// <param name="levelDifficulty"></param>
|
||
private void OnDifficult(E_LevelDifficulty difficulty)
|
||
{
|
||
levelDifficulty = difficulty;
|
||
switch (levelDifficulty)
|
||
{
|
||
case E_LevelDifficulty.Easy:
|
||
{
|
||
IsEasySelect = true;
|
||
IsDifficultSelect = false;
|
||
}
|
||
break;
|
||
case E_LevelDifficulty.Hard:
|
||
{
|
||
IsEasySelect = false;
|
||
IsDifficultSelect = true;
|
||
}
|
||
break;
|
||
default:
|
||
{
|
||
DebugUtil.LogError($"未处理类型{levelDifficulty}");
|
||
}
|
||
break;
|
||
}
|
||
|
||
RefreshLevelList();
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 资源选关类
|
||
/// </summary>
|
||
private class ResourceSelectLevel : SelectLevelBase
|
||
{
|
||
public ResourceSelectLevel(GameObject root, LevelList levelList) : base(root, E_ChapterType.Resource, levelList)
|
||
{
|
||
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 剧情选关类
|
||
/// </summary>
|
||
private class StorySelectLevel : SelectLevelBase
|
||
{
|
||
public StorySelectLevel(GameObject root, LevelList levelList) : base(root, E_ChapterType.Storyline, levelList)
|
||
{
|
||
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 战役选关类
|
||
/// </summary>
|
||
private class WarSelectLevel : SelectLevelBase
|
||
{
|
||
public WarSelectLevel(GameObject root, LevelList levelList) : base(root, E_ChapterType.War, levelList)
|
||
{
|
||
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 关卡列表类
|
||
/// </summary>
|
||
private class LevelList : UIGameObjectWrapper
|
||
{
|
||
/// <summary>
|
||
/// 关卡选项
|
||
/// </summary>
|
||
private class LevelItem : UIGameObjectWrapper
|
||
{
|
||
#region UI
|
||
/// <summary>
|
||
/// 按钮
|
||
/// </summary>
|
||
private Button button;
|
||
/// <summary>
|
||
/// 昼夜
|
||
/// </summary>
|
||
private Image imageTime;
|
||
/// <summary>
|
||
/// 天气
|
||
/// </summary>
|
||
private Image imageWeather;
|
||
/// <summary>
|
||
/// 环境
|
||
/// </summary>
|
||
private Image imageEnviroment;
|
||
/// <summary>
|
||
/// 昼夜文本
|
||
/// </summary>
|
||
private TMP_Text textTime;
|
||
/// <summary>
|
||
/// 天气文本
|
||
/// </summary>
|
||
private TMP_Text textWeather;
|
||
/// <summary>
|
||
/// 环境文本
|
||
/// </summary>
|
||
private TMP_Text textEnviroment;
|
||
/// <summary>
|
||
/// 关卡名
|
||
/// </summary>
|
||
private TMP_Text textLevelName;
|
||
/// <summary>
|
||
/// 节点位置
|
||
/// </summary>
|
||
private RectTransform rtsRoot;
|
||
/// <summary>
|
||
/// 向上的线
|
||
/// </summary>
|
||
private GameObject goUp;
|
||
/// <summary>
|
||
/// 直线
|
||
/// </summary>
|
||
private GameObject goStraight;
|
||
/// <summary>
|
||
/// 向下的线
|
||
/// </summary>
|
||
private GameObject goDown;
|
||
/// <summary>
|
||
/// 主线关卡信息
|
||
/// </summary>
|
||
private GameObject goMainInfo;
|
||
/// <summary>
|
||
/// 战役关卡信息
|
||
/// </summary>
|
||
private GameObject goWarInfo;
|
||
/// <summary>
|
||
/// 星级列表
|
||
/// </summary>
|
||
private GameObject[] goStars;
|
||
/// <summary>
|
||
/// 星级根节点
|
||
/// </summary>
|
||
private GameObject goStarRoot;
|
||
#endregion
|
||
|
||
/// <summary>
|
||
/// 关卡信息
|
||
/// </summary>
|
||
private LevelInfo levelInfo;
|
||
/// <summary>
|
||
/// 关卡点击回调
|
||
/// </summary>
|
||
private readonly Action<LevelInfo> levelAction;
|
||
|
||
public LevelItem(GameObject root, Action<LevelInfo> level) : base(root)
|
||
{
|
||
levelAction = level;
|
||
|
||
button = GoRoot.GetComponent<Button>();
|
||
imageTime = GetComponent<Image>("Root/Image_LevelInfo/Image_Time");
|
||
imageWeather = GetComponent<Image>("Root/Image_LevelInfo/Image_Weather");
|
||
imageEnviroment = GetComponent<Image>("Root/Image_LevelInfo/Image_Enviroment");
|
||
textTime = GetComponent<TMP_Text>("Root/Image_LevelInfo/Image_Time/Text");
|
||
textWeather = GetComponent<TMP_Text>("Root/Image_LevelInfo/Image_Weather/Text");
|
||
textEnviroment = GetComponent<TMP_Text>("Root/Image_LevelInfo/Image_Enviroment/Text");
|
||
textLevelName = GetComponent<TMP_Text>("Root/ImageChoose/Text_Level");
|
||
rtsRoot = FindObj("Root").GetComponent<RectTransform>();
|
||
goUp = FindObj("Root/ImageUp");
|
||
goStraight = FindObj("Root/ImageStraight");
|
||
goDown = FindObj("Root/ImageDown");
|
||
goMainInfo = FindObj("Root/Image_LevelInfo");
|
||
goWarInfo = FindObj("Root/Image_LevelInfoWar");
|
||
goStarRoot = FindObj("Root/UI_Stars");
|
||
Transform tsStarRoot = goStarRoot.transform;
|
||
goStars = new GameObject[tsStarRoot.childCount];
|
||
for (int i = 0; i < tsStarRoot.childCount; ++i)
|
||
{
|
||
goStars[i] = tsStarRoot.GetChild(i).gameObject;
|
||
}
|
||
|
||
goStraight.IsScaleShow(false);
|
||
|
||
BindButton(button, OnClick);
|
||
}
|
||
|
||
public async void SetInfo(LevelInfo info, int index, bool isLast)
|
||
{
|
||
levelInfo = info;
|
||
|
||
textLevelName.text = info.Name;
|
||
if ((index & 1) == 1) // 奇数
|
||
{
|
||
rtsRoot.anchoredPosition = new Vector2(-170f, 0f);
|
||
goUp.IsScaleShow(!isLast);
|
||
goDown.IsScaleShow(false);
|
||
}
|
||
else // 偶数
|
||
{
|
||
rtsRoot.anchoredPosition = new Vector2(-170f, 72f);
|
||
goUp.IsScaleShow(false);
|
||
goDown.IsScaleShow(!isLast);
|
||
}
|
||
|
||
switch (info.ChapterInfo.Cfg.Type)
|
||
{
|
||
case E_ChapterType.Main:
|
||
{
|
||
bool[] starResults = info.StarResult;
|
||
for (int i = 0; i < goStars.Length && i < starResults.Length; ++i)
|
||
{
|
||
goStars[i].IsScaleShow(starResults[i]);
|
||
}
|
||
|
||
await AssetManager.Instance.WaitAllPreloads();
|
||
|
||
DataEnviorment environmentConfig = CommonUtils.GetEnvironmentConfig(levelInfo.Environment);
|
||
imageEnviroment.sprite = AssetManager.Instance.GetPreLoadResult<Sprite>(environmentConfig.Icon);
|
||
textEnviroment.text = CommonUtils.GetLocalizeText(environmentConfig.NameLocal);
|
||
|
||
DataEnWeather weatherConfig = CommonUtils.GetWeatherConfig(levelInfo.Cfg.LevelWeather);
|
||
imageWeather.sprite = AssetManager.Instance.GetPreLoadResult<Sprite>(weatherConfig.Icon);
|
||
textWeather.text = CommonUtils.GetLocalizeText(weatherConfig.NameLocal);
|
||
|
||
DataDayNightProp dayNightConfig = CommonUtils.GetDayNightConfig(levelInfo.Cfg.LevelTime);
|
||
imageTime.sprite = AssetManager.Instance.GetPreLoadResult<Sprite>(dayNightConfig.Icon);
|
||
textTime.text = CommonUtils.GetLocalizeText(dayNightConfig.NameLocal);
|
||
|
||
goStarRoot.IsScaleShow(true);
|
||
goMainInfo.IsScaleShow(true);
|
||
goWarInfo.IsScaleShow(false);
|
||
}
|
||
break;
|
||
case E_ChapterType.Resource:
|
||
{
|
||
goStarRoot.IsScaleShow(false);
|
||
goMainInfo.IsScaleShow(false);
|
||
goWarInfo.IsScaleShow(false);
|
||
}
|
||
break;
|
||
case E_ChapterType.Storyline:
|
||
{
|
||
goStarRoot.IsScaleShow(false);
|
||
goMainInfo.IsScaleShow(false);
|
||
goWarInfo.IsScaleShow(false);
|
||
}
|
||
break;
|
||
case E_ChapterType.War:
|
||
{
|
||
goStarRoot.IsScaleShow(false);
|
||
goMainInfo.IsScaleShow(false);
|
||
goWarInfo.IsScaleShow(true);
|
||
}
|
||
break;
|
||
default:
|
||
{
|
||
DebugUtil.LogError($"未处理类型{info.ChapterInfo.Cfg.Type}");
|
||
}
|
||
break;
|
||
}
|
||
|
||
IsScaleShow = true;
|
||
}
|
||
|
||
private void OnClick()
|
||
{
|
||
levelAction?.Invoke(levelInfo);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 循环列表
|
||
/// </summary>
|
||
private RecycleView recycleView;
|
||
/// <summary>
|
||
/// 关卡信息列表
|
||
/// </summary>
|
||
private List<LevelInfo> listLevelInfo;
|
||
/// <summary>
|
||
/// 关卡字典
|
||
/// </summary>
|
||
private readonly Dictionary<int, LevelItem> dicLevelItem = new();
|
||
private readonly Action<LevelInfo> levelAction;
|
||
|
||
public bool IsEnableRecycleView
|
||
{
|
||
set { recycleView.ScrollRect.enabled = value; }
|
||
}
|
||
|
||
public LevelList(GameObject root, Action<LevelInfo> level) : base(root)
|
||
{
|
||
levelAction = level;
|
||
|
||
recycleView = GetComponent<RecycleView>("RecycleView");
|
||
|
||
IsEnableRecycleView = false;
|
||
|
||
recycleView.Init(RefreshCell);
|
||
}
|
||
|
||
public void SetInfo(List<LevelInfo> listInfo)
|
||
{
|
||
listLevelInfo = listInfo;
|
||
if (null == listLevelInfo)
|
||
{
|
||
DebugUtil.LogError("无效的关卡信息列表");
|
||
return;
|
||
}
|
||
|
||
recycleView.ShowList(listLevelInfo.Count);
|
||
|
||
IsScaleShow = true;
|
||
}
|
||
|
||
private void RefreshCell(GameObject cell, int index)
|
||
{
|
||
if (!dicLevelItem.TryGetValue(cell.GetInstanceID(), out LevelItem levelItem))
|
||
{
|
||
levelItem = new(cell, OnLevel);
|
||
dicLevelItem.Add(cell.GetInstanceID(), levelItem);
|
||
}
|
||
|
||
if (null == listLevelInfo)
|
||
return;
|
||
|
||
if (index < 0 || index >= listLevelInfo.Count)
|
||
return;
|
||
|
||
levelItem.SetInfo(listLevelInfo[index], index, index == listLevelInfo.Count - 1);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 点击关卡
|
||
/// </summary>
|
||
/// <param name="levelInfo"></param>
|
||
private void OnLevel(LevelInfo levelInfo)
|
||
{
|
||
levelAction?.Invoke(levelInfo);
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
/// <summary>
|
||
/// 电池
|
||
/// </summary>
|
||
private class Batterie : UIGameObjectWrapper
|
||
{
|
||
/// <summary>
|
||
/// 电池电量
|
||
/// </summary>
|
||
private readonly List<GameObject> listBatteryPower;
|
||
|
||
public Batterie(GameObject root) : base(root)
|
||
{
|
||
listBatteryPower = new(GoRoot.transform.childCount);
|
||
for (int i = 0; i < GoRoot.transform.childCount; ++i)
|
||
{
|
||
listBatteryPower.Add(GoRoot.transform.GetChild(i).gameObject);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 入口
|
||
/// </summary>
|
||
/// <param name="batteryPower"></param>
|
||
public void SetInfo()
|
||
{
|
||
int showCount = Mathf.CeilToInt(listBatteryPower.Count * DeviceHelper.GetBatteryLevel());
|
||
if (showCount >= listBatteryPower.Count)
|
||
showCount = listBatteryPower.Count - 1;
|
||
|
||
for (int i = 0; i < listBatteryPower.Count; ++i)
|
||
{
|
||
listBatteryPower[i].IsScaleShow(i == showCount);
|
||
}
|
||
|
||
IsScaleShow = true;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// WIFI
|
||
/// </summary>
|
||
private class NetSignal : UIGameObjectWrapper
|
||
{
|
||
private readonly int[] signalThreshold = new int[] { 30, 60, 120, 200, 300 };//网络延迟阶梯值
|
||
/// <summary>
|
||
/// Wifi信号
|
||
/// </summary>
|
||
private readonly List<GameObject> listWifi;
|
||
|
||
public NetSignal(GameObject root) : base(root)
|
||
{
|
||
listWifi = new(GoRoot.transform.childCount);
|
||
for (int i = 0; i < GoRoot.transform.childCount; ++i)
|
||
{
|
||
listWifi.Add(GoRoot.transform.GetChild(i).gameObject);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 入口
|
||
/// </summary>
|
||
/// <param name="networkSignal"></param>
|
||
public void SetInfo(float networkSignal)
|
||
{
|
||
int showCount = Mathf.CeilToInt(listWifi.Count * networkSignal);
|
||
for (int i = 0; i < listWifi.Count; ++i)
|
||
{
|
||
listWifi[i].IsScaleShow(i + 1 == showCount);
|
||
}
|
||
}
|
||
|
||
public void SetInfo()
|
||
{
|
||
var rtt = NetManager.Instance.RTT;//rtt 毫秒
|
||
int showCnt = 0;
|
||
for (int i = 0; i < signalThreshold.Length; i++)
|
||
{
|
||
if (rtt < signalThreshold[i])
|
||
{
|
||
showCnt = signalThreshold.Length - i;
|
||
break;
|
||
}
|
||
}
|
||
for (int i = 0; i < listWifi.Count; ++i)
|
||
{
|
||
listWifi[i].IsScaleShow(showCnt > 0);
|
||
--showCnt;
|
||
}
|
||
|
||
IsScaleShow = true;
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region UI
|
||
/// <summary>
|
||
/// 返回
|
||
/// </summary>
|
||
private Button buttonBack;
|
||
/// <summary>
|
||
/// 主页
|
||
/// </summary>
|
||
private Button buttonHome;
|
||
/// <summary>
|
||
/// 模式根节点
|
||
/// </summary>
|
||
private GameObject goModeRoot;
|
||
/// <summary>
|
||
/// 章节根节点
|
||
/// </summary>
|
||
private GameObject goChapterRoot;
|
||
/// <summary>
|
||
/// 关卡根节点
|
||
/// </summary>
|
||
private GameObject goLevelRoot;
|
||
#endregion
|
||
|
||
#region 私有字段
|
||
/// <summary>
|
||
/// 模式按钮字典
|
||
/// </summary>
|
||
private readonly Dictionary<E_ChapterType, ModeButton> dicModeButton = new();
|
||
/// <summary>
|
||
/// 章节列表字典
|
||
/// </summary>
|
||
private readonly Dictionary<E_ChapterType, ChapterBase> dicChapter = new();
|
||
/// <summary>
|
||
/// 选关UI字典
|
||
/// </summary>
|
||
private readonly Dictionary<E_ChapterType, SelectLevelBase> dicSelectLevel = new();
|
||
/// <summary>
|
||
/// 货币栏
|
||
/// </summary>
|
||
private UI_CurrencyList currencyList;
|
||
/// <summary>
|
||
/// 是否隐藏
|
||
/// </summary>
|
||
private bool isHide;
|
||
/// <summary>
|
||
/// 计时器
|
||
/// </summary>
|
||
private float timer;
|
||
/// <summary>
|
||
/// 是否显示选关
|
||
/// </summary>
|
||
private bool isShowSelectLevel;
|
||
/// <summary>
|
||
/// 当前选择模式类型
|
||
/// </summary>
|
||
private E_ChapterType curMode;
|
||
#endregion
|
||
|
||
/// <summary>
|
||
/// 是否显示选关卡
|
||
/// </summary>
|
||
public bool IsShowSelectLevel
|
||
{
|
||
get { return isShowSelectLevel; }
|
||
set
|
||
{
|
||
isShowSelectLevel = value;
|
||
|
||
goModeRoot.IsScaleShow(!isShowSelectLevel);
|
||
goChapterRoot.IsScaleShow(!isShowSelectLevel);
|
||
goLevelRoot.IsScaleShow(isShowSelectLevel);
|
||
|
||
if (dicChapter.TryGetValue(curMode, out ChapterBase chapterBase))
|
||
chapterBase.IsEnableRecycleView = !isShowSelectLevel;
|
||
|
||
if (dicSelectLevel.TryGetValue(curMode, out SelectLevelBase selectLevelBase))
|
||
selectLevelBase.IsEnableRecycleView = isShowSelectLevel;
|
||
}
|
||
}
|
||
|
||
public override void PreLoad(object data = null)
|
||
{
|
||
CommonUtils.PreLoadOrUnloadEnvironmentWeatherDayNightIcon(true);
|
||
}
|
||
|
||
public override void OnInit()
|
||
{
|
||
buttonBack = GetComponent<Button>("Button_Back/Button_back");
|
||
buttonHome = GetComponent<Button>("Button_Back/Button_Home");
|
||
currencyList = GetComponent<UI_CurrencyList>("UI_CurrencyList");
|
||
goModeRoot = FindObj("UI_ModeSelect");
|
||
goChapterRoot = FindObj("UI_LiuHaiRight");
|
||
goLevelRoot = FindObj("UI_LevelSelect");
|
||
|
||
#region 模式按钮
|
||
dicModeButton.Add(E_ChapterType.Main, new ModeButton(FindObj("UI_ModeSelect/UI_MainMission"), E_ChapterType.Main, OnMode));
|
||
dicModeButton.Add(E_ChapterType.Resource, new ModeButton(FindObj("UI_ModeSelect/UI_ResourcesCollection"), E_ChapterType.Resource, OnMode));
|
||
dicModeButton.Add(E_ChapterType.Storyline, new ModeButton(FindObj("UI_ModeSelect/UI_Story"), E_ChapterType.Storyline, OnMode));
|
||
dicModeButton.Add(E_ChapterType.War, new ModeButton(FindObj("UI_ModeSelect/UI_War"), E_ChapterType.War, OnMode));
|
||
#endregion
|
||
|
||
#region 章节
|
||
dicChapter.Add(E_ChapterType.Main, new MainChapter(FindObj("UI_LiuHaiRight/Image_MainMission"), OnChapter));
|
||
dicChapter.Add(E_ChapterType.Resource, new ResourceChapter(FindObj("UI_LiuHaiRight/Image_ResourcesCollection"), OnChapter));
|
||
dicChapter.Add(E_ChapterType.Storyline, new StoryChapter(FindObj("UI_LiuHaiRight/Image_Story"), OnChapter));
|
||
dicChapter.Add(E_ChapterType.War, new WarChapter(FindObj("UI_LiuHaiRight/Image_War"), OnChapter));
|
||
#endregion
|
||
|
||
#region 选关
|
||
LevelList levelList = new(FindObj("UI_LevelSelect/UI_LevelPoints"), OnLevel);
|
||
dicSelectLevel.Add(E_ChapterType.Main, new MainSelectLevel(FindObj("UI_LevelSelect/UI_MainMission"), levelList));
|
||
dicSelectLevel.Add(E_ChapterType.Resource, new ResourceSelectLevel(FindObj("UI_LevelSelect/UI_ResourcesCollection"), levelList));
|
||
dicSelectLevel.Add(E_ChapterType.Storyline, new StorySelectLevel(FindObj("UI_LevelSelect/UI_Story"), levelList));
|
||
dicSelectLevel.Add(E_ChapterType.War, new WarSelectLevel(FindObj("UI_LevelSelect/UI_War"), levelList));
|
||
#endregion
|
||
|
||
currencyList.SetData(GLConfig.Inst.data.GoldItemId, GLConfig.Inst.data.DiamondItemId, GLConfig.Inst.data.EnergyPointID);
|
||
curMode = E_ChapterType.Count;
|
||
|
||
BindButton(buttonBack, OnBack);
|
||
BindButton(buttonHome, OnHome);
|
||
|
||
EventManager.Instance.Register(EventManager.EventName.ChapterInfoChange, OnRefresh);
|
||
EventManager.Instance.Register(EventManager.EventName.LevelUnlock, OnRefresh);
|
||
EventManager.Instance.Register(EventManager.EventName.LevelInfoChanged, OnRefresh);
|
||
}
|
||
|
||
protected override void OnShowWindow(object data = null)
|
||
{
|
||
if (isHide)
|
||
{
|
||
isHide = false;
|
||
return;
|
||
}
|
||
|
||
base.OnShowWindow(data);
|
||
|
||
if (data is LevelInfo levelInfo)
|
||
OnMode(levelInfo.ChapterInfo.Cfg.Type);
|
||
else
|
||
OnMode(E_ChapterType.Main);
|
||
|
||
currencyList.Refresh();
|
||
}
|
||
|
||
protected override void OnHideWindow()
|
||
{
|
||
isHide = true;
|
||
}
|
||
|
||
protected override void OnReloadWindow(object data = null)
|
||
{
|
||
OnRefresh();
|
||
}
|
||
|
||
protected override void OnUpdate()
|
||
{
|
||
timer += Time.deltaTime;
|
||
if (timer >= 1f) // 每秒刷新电量和信号
|
||
{
|
||
if (dicChapter.TryGetValue(curMode, out ChapterBase chapterBase))
|
||
{
|
||
chapterBase.RefreshBatterie();
|
||
chapterBase.RefreshNetSignal();
|
||
}
|
||
|
||
timer -= 1f;
|
||
}
|
||
}
|
||
|
||
public override async UniTask<bool> OnBack(object data = null)
|
||
{
|
||
OnBack();
|
||
|
||
await UniTask.Yield();
|
||
|
||
return true;
|
||
}
|
||
|
||
public override void OnRelease()
|
||
{
|
||
EventManager.Instance.Unregister(EventManager.EventName.ChapterInfoChange, OnRefresh);
|
||
EventManager.Instance.Unregister(EventManager.EventName.LevelUnlock, OnRefresh);
|
||
EventManager.Instance.Unregister(EventManager.EventName.LevelInfoChanged, OnRefresh);
|
||
|
||
CommonUtils.PreLoadOrUnloadEnvironmentWeatherDayNightIcon(false);
|
||
|
||
base.OnRelease();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 刷新面板
|
||
/// </summary>
|
||
private void OnRefresh()
|
||
{
|
||
/*if (dicPanel.TryGetValue(curPage, out BaseChoosePanel baseChoosePanel))
|
||
{
|
||
baseChoosePanel.ChapterType = curChapterType;
|
||
baseChoosePanel.ChapterInfo = curLevelGroupInfo;
|
||
baseChoosePanel.SetInfo();
|
||
}*/
|
||
}
|
||
|
||
#region 回调方法
|
||
/// <summary>
|
||
/// 返回
|
||
/// </summary>
|
||
private void OnBack()
|
||
{
|
||
if (IsShowSelectLevel)
|
||
IsShowSelectLevel = false;
|
||
else
|
||
OnHome();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 主页
|
||
/// </summary>
|
||
private void OnHome()
|
||
{
|
||
CommonUtils.ChangeUIScene(Constants.MAIN_SCENE_PATH);
|
||
CloseWindow();
|
||
UIManager.Instance.ShowAllUI();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 选择模式
|
||
/// </summary>
|
||
/// <param name="chapterType"></param>
|
||
private void OnMode(E_ChapterType type)
|
||
{
|
||
if (curMode == type)
|
||
return;
|
||
|
||
if (dicModeButton.TryGetValue(curMode, out ModeButton oldModeButton))
|
||
oldModeButton.IsSelect = false;
|
||
|
||
if (dicChapter.TryGetValue(curMode, out ChapterBase oldChapterBase))
|
||
oldChapterBase.IsScaleShow = false;
|
||
|
||
if (dicSelectLevel.TryGetValue(curMode, out SelectLevelBase oldSelectLevelBase))
|
||
oldSelectLevelBase.IsScaleShow = false;
|
||
|
||
curMode = type;
|
||
|
||
if (dicModeButton.TryGetValue(curMode, out ModeButton newModeButton))
|
||
newModeButton.IsSelect = true;
|
||
|
||
if (dicChapter.TryGetValue(curMode, out ChapterBase newChapterBase))
|
||
newChapterBase.SetInfo();
|
||
|
||
switch (curMode)
|
||
{
|
||
case E_ChapterType.Main:
|
||
{
|
||
IsShowSelectLevel = false;
|
||
}
|
||
break;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 选择章节
|
||
/// </summary>
|
||
/// <param name="type"></param>
|
||
private void OnChapter(ChapterInfo chapterInfo)
|
||
{
|
||
if (!dicSelectLevel.TryGetValue(chapterInfo.Cfg.Type, out SelectLevelBase selectLevelBase))
|
||
{
|
||
DebugUtil.LogError($"不存在{chapterInfo.Cfg.Type}的关卡选择面板");
|
||
return;
|
||
}
|
||
|
||
selectLevelBase.SetInfo(chapterInfo);
|
||
|
||
IsShowSelectLevel = true;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 点击关卡
|
||
/// </summary>
|
||
/// <param name="levelInfo"></param>
|
||
private async void OnLevel(LevelInfo levelInfo)
|
||
{
|
||
if (null == levelInfo)
|
||
return;
|
||
|
||
if (E_ChapterType.Storyline == levelInfo.ChapterInfo.Cfg.Type)
|
||
LevelManager.Instance.TryEnterLevel(levelInfo.Cfg.Id);
|
||
else
|
||
await UI_LevelDetailController.Open(levelInfo);
|
||
}
|
||
#endregion
|
||
} |