using System; using System.Collections; using System.Collections.Generic; using System.Linq; using cfg; using DG.Tweening; using TMPro; using Unity.VisualScripting; using UnityEngine; using UnityEngine.UI; public class LevelPanel : MonoBehaviour { public int ChapterID => chapterId; private int chapterId; public int LevelID => levelID; private int levelID; [SerializeField] private Button startGameButton; [SerializeField] private Button upButton; [SerializeField] private Button dowButton; [SerializeField] private Button mainButton; [SerializeField] private Button homeButton; [SerializeField] private Image homeImage; [SerializeField] private List tourObjects; [SerializeField] private List _list; [SerializeField] private List starList; [SerializeField] private TextMeshProUGUI leveName; [SerializeField] private TextMeshProUGUI levelText; [SerializeField] private AnimationCurve ani; [SerializeField] private GameObject wait; [SerializeField] private Transform spiriStart; [SerializeField] private Transform spiriEnd; [SerializeField] private Transform spiriAni; [SerializeField] private Slider _slider; private int aniIndex; private void OnEnable() { startGameButton.onClick.AddListener(StartGame); upButton.onClick.AddListener(UpData); dowButton.onClick.AddListener(DownData); homeButton.onClick.AddListener(HomeEvent); } private void OnDisable() { startGameButton.onClick.RemoveListener(StartGame); upButton.onClick.RemoveListener(UpData); dowButton.onClick.RemoveListener(DownData); homeButton.onClick.RemoveListener(HomeEvent); } private void HomeEvent() { MainPanel.ins.HomePanel(); } private void UpData() { var levelData = JsonTab.Instance.tables.Chapter.Get(chapterId); int index = levelData.Chapternext; if (index-1<0) { BoxDebug.Log("已经最上级界面"); return; } foreach (var bc in JsonTab.Instance.tables.Chapter.DataList) { if (levelData.Chapternext-1==bc.Chapternext) { StartPanel(bc.ID); return; } } } private void MainPanelOpen() { } public void HomePanelOpen() { } private void DownData() { int index = 0; for (var i = 0; i < JsonTab.Instance.tables.Chapter.DataList.Count; i++) { if (JsonTab.Instance.tables.Chapter.DataList[i].ID==levelID) { index = i; break; } } if (index+1>=JsonTab.Instance.tables.Chapter.DataList.Count) { BoxDebug.Log("已经最后页面"); return; } foreach (var bc in JsonTab.Instance.tables.Chapter.DataList[index+1].Contain) { var data= JsonTab.Instance.tables.Level.Get(bc); if (DataManager.LevelOpen(data.Front)) { StartPanel(JsonTab.Instance.tables.Chapter.DataList[index+1].ID); return; } } BoxDebug.Log("未解锁"); } public void StartPanel(int id) { if (id==0) { id = 11001; } chapterId = id; DataManager.chapter = id; // var bo=DataManager.LevelOpen(id); var levelData = JsonTab.Instance.tables.Chapter.Get(id); levelText.text = JsonTab.Instance.tables.DisplayTxt.Get(levelData.Chaptername).Text; foreach (var levelButton in tourObjects) { levelButton._panel = this; levelButton.Reset(); } int index = 0; foreach (var data in levelData.Contain) { tourObjects[index].SetLevelData(data); var _blevelData= JsonTab.Instance.tables.Level.Get(data); if (DataManager.LevelOpen(_blevelData.Front)) { levelID = data; } index++; } ResetButton(); SetTaskDisplay(levelID); var bdata= JsonTab.Instance.tables.Level.Get(levelID); homeImage.sprite = Resources.Load("Map/"+bdata.Icon); upButton.gameObject.SetActive(levelData.Chapternext!=1); BChapter nextDatas = null; foreach (var bChapter in JsonTab.Instance.tables.Chapter.DataList.Where(bChapter => bChapter.Chaptername==levelData.Chaptername+1)) { nextDatas = bChapter; } if (nextDatas==null) { dowButton.gameObject.SetActive(false); } else { foreach (var ctx in nextDatas.Contain) { var _blevelData= JsonTab.Instance.tables.Level.Get(ctx); if (DataManager.LevelOpen(_blevelData.Front)) { dowButton.gameObject.SetActive(true); return; } } dowButton.gameObject.SetActive(false); } homeImage.GetComponent().DOLocalMove(new Vector3(0,10,0),5f,true).SetEase(ani).SetLoops(-1); wait.SetActive(false); spiriAni.localPosition = new Vector3(1000, 1000,0); aniIndex = 0; } private void ResetButton() { foreach (var button in tourObjects) { button.SelelObj(); } } public void SaveLevelID(int id) { levelID = id; ResetButton(); SetTaskDisplay(id); } public void SetTaskDisplay(int id) { var data=JsonTab.Instance.tables.Level.Get(id); leveName.text = JsonTab.Instance.tables.DisplayTxt.Get(data.Name).Text; _list[0].InitData(id, data.Maintasks); if (DataManager.GetTask(id, data.Maintasks)) { starList[0].color = Color.white; } else { starList[0].color = Color.gray; } for (int i = 1; i < _list.Count; i++) { _list[i].gameObject.SetActive(false); starList[i].gameObject.SetActive(false); } for (int i = 0; i < data.Additionaltasks.Count; i++) { _list[i+1].gameObject.SetActive(true); starList[i+1].gameObject.SetActive(true); if (DataManager.GetTask(id, data.Additionaltasks[i])) { starList[i+1].color=Color.white; } else { starList[i+1].color=Color.gray; } _list[i+1].InitData(id,data.Additionaltasks[i]); } homeImage.sprite = Resources.Load("Map/" + data.Icon); } public void StartGame() { wait.SetActive(true); spiriAni.position = spiriStart.position; spiriAni.DOMove(spiriEnd.position, 2f).OnComplete(() => { aniIndex++; if (aniIndex>=2) { MainPanel.ins.StartPanelEvent(); GameManager.ins.soundSystem.EventAudio(); wait.SetActive(false); } }); DataManager.chapter = chapterId; GameManager.ins.ResetLevel(levelID, () => { aniIndex++; if (aniIndex>=2) { MainPanel.ins.StartPanelEvent(); GameManager.ins.soundSystem.EventAudio(); wait.SetActive(false); } }); } // Start is called before the first frame update void Start() { } // Update is called once per frame void Update() { } }