using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using cfg.FightCfg;
using cfg.LevelCfg;
using Cysharp.Threading.Tasks;
using Framework;
using Gameplay;
using Gameplay.Common;
using Gameplay.Level;
using PhxhSDK;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
using Button = UnityEngine.UI.Button;
using Constants = Framework.Constants;
using Image = UnityEngine.UI.Image;
public class UI_LevelSelectController : UIWindow
{
public TMP_Text Text_ChapterName;
public TMP_Text Text_ChapterNum;
public Image Image_ProcessBar;
public Button Button_GetAll;
public TMP_Text Text_StarNum;
public Button Button_Easy;
public Button Button_Hard;
///
/// 打开关卡选择界面
///
/// 有数据则跳转到对应关卡选项,没有数据则显示默认
///
public static async UniTask 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 类
///
/// 电池
///
private class Batterie : UIGameObjectWrapper
{
///
/// 电池电量
///
private readonly List 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);
}
}
///
/// 入口
///
///
public void SetInfo(float batteryPower)
{
int showCount = Mathf.CeilToInt(listBatteryPower.Count * batteryPower);
for (int i = 0; i < listBatteryPower.Count; ++i)
{
listBatteryPower[i].IsScaleShow(i + 1 == showCount);
}
}
}
///
/// WIFI
///
private class NetSignal : UIGameObjectWrapper
{
///
/// Wifi信号
///
private readonly List 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);
}
}
///
/// 入口
///
///
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);
}
}
}
///
/// 选择面板基类
///
private abstract class BaseChoosePanel : UIGameObjectWrapper
{
protected ScrollRect scrollRect;
///
/// 章节类型
///
private LevelChapterType chapterType;
///
/// 章节信息
///
private LevelGroupInfo levelGroupInfo;
public LevelChapterType ChapterType
{
get { return chapterType; }
set { chapterType = value; }
}
public LevelGroupInfo ChapterInfo
{
get { return levelGroupInfo; }
set { levelGroupInfo = value; }
}
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);
if (scrollRect == null)
return;
scrollRect.enabled = value;
}
}
public BaseChoosePanel(GameObject root) : base(root)
{
}
public abstract void SetInfo();
}
///
/// 模式选择面板
///
private class ModeChoosePanel : BaseChoosePanel
{
///
/// 模式选项
///
private class ModeItem : UIGameObjectWrapper
{
#region UI
///
/// 模式名
///
private TMP_Text textModeName;
///
/// 当前关卡名
///
private TMP_Text textCurLevelName;
///
/// 当前关卡编号
///
private TMP_Text textCurLevelNum;
///
/// 上一次关卡名
///
private TMP_Text textLastLevelName;
///
/// 上一次关卡编号
///
private TMP_Text textLastLevelNum;
///
/// 当前关卡
///
private GameObject goCurLevel;
///
/// 上一次关卡
///
private GameObject goLastLevel;
///
/// 选择章节按钮
///
private Button buttonSelectChapter;
///
/// 进入当前关卡按钮
///
private Button buttonCurLevel;
///
/// 进入上一次关卡按钮
///
private Button buttonLastLevel;
#endregion
///
/// 关卡章节类型
///
private readonly LevelChapterType type;
///
/// 点击模式
///
private readonly Action mode;
///
/// 点击关卡
///
private readonly Action level;
private LevelInfo curLevelInfo;
private LevelInfo lastLevelInfo;
public ModeItem(GameObject root, LevelChapterType levelChapterType, Action modeAction, Action levelAction) : base(root)
{
type = levelChapterType;
mode = modeAction;
level = levelAction;
buttonSelectChapter = GoRoot.GetComponent