NLDClient-yudde/ProjectNLD/Assets/Code/Scripts/Gameplay/JumpTo/JumpToManager.cs

257 lines
8.5 KiB
C#
Raw Normal View History

2023-12-27 19:42:58 +08:00
using System;
using System.Collections.Generic;
using cfg;
2024-05-31 16:36:36 +08:00
using cfg.ActorCfg;
using cfg.LevelCfg;
2024-10-15 18:48:43 +08:00
using Cysharp.Threading.Tasks;
using Framework;
2023-12-27 19:42:58 +08:00
using Gameplay;
using Gameplay.Level;
using PhxhSDK;
2023-12-27 19:42:58 +08:00
namespace Gameplay
{
public class JumpToManager
{
/// <summary>
/// 异步跳转方法字典,带回调
/// </summary>
2024-10-18 13:31:45 +08:00
private static readonly Dictionary<JumpFuncType, Delegate> _jumpDicAsync = new()
{
[JumpFuncType.Cultivate_Character] = (Action<int, Action>)JumpToCultivateCharacterAsync,
[JumpFuncType.Level_Select] = (Action<int, Action>)JumpToLevelSelectAsync,
[JumpFuncType.Level_Detail] = (Action<int, Action>)JumpToLevelDetailAsync,
[JumpFuncType.Item_Shop] = (Action<int, Action>)JumpToShopDetailAsync,
[JumpFuncType.PVP_Main] = (Action<Action>)JumpToPvpMainAsync,
[JumpFuncType.Gacha] = (Action<int, Action>)JumpToGachaAsync,
2023-12-27 19:42:58 +08:00
};
2024-10-18 13:31:45 +08:00
private static readonly Dictionary<JumpFuncType, Delegate> _jumpDic = new()
2024-10-15 18:48:43 +08:00
{
2024-10-18 13:31:45 +08:00
[JumpFuncType.Level_Select] = (Func<int, UniTask>)JumpToLevelSelect,
[JumpFuncType.PVP_Main] = (Func<UniTask>)JumpToPvpMain,
[JumpFuncType.TeamInfoByGuide] = (Func<int, UniTask>)JumpToTeamInfoByGuide,
[JumpFuncType.TeamSelect] = (Func<int, UniTask>)JumpToTeamSelectByGuide,
2024-10-15 18:48:43 +08:00
};
private static void _DoJumpFunc(JumpFuncType key)
2023-12-27 19:42:58 +08:00
{
2024-10-18 13:31:45 +08:00
var action = _jumpDicAsync[key];
2023-12-27 19:42:58 +08:00
if (action is Action act)
{
act();
}
}
2024-05-31 16:36:36 +08:00
private static void _DoJumpFunc<T>(JumpFuncType key, T param)
{
2024-10-18 13:31:45 +08:00
var action = _jumpDicAsync[key];
if (action is Action<T> act)
{
act(param);
}
}
2023-12-27 19:42:58 +08:00
private static void _DoJumpFunc<T, Action>(JumpFuncType key, T param, Action callback)
{
var action = _jumpDicAsync[key];
if (action is Action<T, Action> act)
{
act(param, callback);
}
}
2024-10-15 18:48:43 +08:00
private static async UniTask _DoJumpFuncAsync(JumpFuncType key)
{
2024-10-18 13:31:45 +08:00
var action = _jumpDic[key];
2024-10-15 18:48:43 +08:00
if (action is Func<UniTask> act)
{
await act();
}
}
private static async UniTask _DoJumpFuncAsync<T>(JumpFuncType key, T param)
{
2024-10-18 13:31:45 +08:00
var action = _jumpDic[key];
2024-10-15 18:48:43 +08:00
if (action is Func<T,UniTask> act)
{
await act(param);
}
}
public static void JumpFunc(JumpFuncType key)
{
_DoJumpFunc(key);
}
public static void JumpFunc<T>(JumpFuncType key, T param)
{
_DoJumpFunc(key, param);
}
2024-05-31 16:36:36 +08:00
public static void JumpFunc<T, Action>(JumpFuncType key, T param, Action callback)
{
_DoJumpFunc(key, param, callback);
}
2024-10-15 18:48:43 +08:00
public static async UniTask JumpFuncAsync(JumpFuncType key)
{
await _DoJumpFuncAsync(key);
}
public static async UniTask JumpFuncAsync<T>(JumpFuncType key, T param)
{
await _DoJumpFuncAsync(key, param);
}
/// <summary>
/// 跳转至培养角色界面
/// </summary>
/// <param name="uid"></param>
/// <param name="onLoadWindowCallback"></param>
public static async void JumpToCultivateCharacterAsync(int uid, Action onLoadWindowCallback)
2023-12-27 19:42:58 +08:00
{
DebugUtil.Log("跳转至培养角色界面,传入角色参数:" + uid + "\n逻辑请在此处实现");
2024-07-04 16:32:27 +08:00
await UISelectCharacterController.Open();
onLoadWindowCallback?.Invoke();
2023-12-27 19:42:58 +08:00
}
2024-06-24 13:44:39 +08:00
/// <summary>
/// 跳转关卡选择
/// </summary>
/// <param name="levelId"></param>
public static async void JumpToLevelSelectAsync(int levelId, Action onLoadWindowCallback)
2024-06-24 13:44:39 +08:00
{
DebugUtil.Log("Jump to : " + levelId);
DataLevel data = TableManager.Instance.Tables.Level.Get(levelId);
if (data == null)
{
await UI_LevelSelectController.Open();
return;
}
2024-09-05 13:41:39 +08:00
LevelManager.Instance.TryGetLevelInfoByID(levelId, out LevelInfo levelInfo);
2024-06-24 13:44:39 +08:00
await UI_LevelSelectController.Open(levelInfo);
onLoadWindowCallback?.Invoke();
2024-06-24 13:44:39 +08:00
}
2024-10-15 18:48:43 +08:00
/// <summary>
/// 跳转关卡选择
/// </summary>
/// <param name="levelId"></param>
2024-10-18 13:31:45 +08:00
public static async UniTask JumpToLevelSelect(int levelId)
2024-10-15 18:48:43 +08:00
{
DebugUtil.Log("Jump to : " + levelId);
DataLevel data = TableManager.Instance.Tables.Level.Get(levelId);
if (data == null)
{
await UI_LevelSelectController.Open();
return;
}
LevelManager.Instance.TryGetLevelInfoByID(levelId, out LevelInfo levelInfo);
await UI_LevelSelectController.Open(levelInfo);
}
public static async void JumpToLevelDetailAsync(int levelId, Action onLoadWindowCallback)
{
DebugUtil.Log("Jump to : " + levelId);
DataLevel data = TableManager.Instance.Tables.Level.Get(levelId);
2024-05-31 16:36:36 +08:00
if (data == null)
{
DebugUtil.Log("Jump to level detail failed, level id not found: " + levelId);
return;
}
2024-09-05 13:41:39 +08:00
LevelManager.Instance.TryGetLevelInfoByID(levelId, out LevelInfo levelInfo);
await UI_LevelSelectController.Open(levelInfo);
await UniTask.Yield();
2024-09-05 13:41:39 +08:00
await UI_LevelDetailController.Open(levelInfo);
onLoadWindowCallback?.Invoke();
}
2024-10-15 18:48:43 +08:00
/// <summary>
2024-10-18 13:31:45 +08:00
/// 跳转到队伍信息(引导用)
2024-10-15 18:48:43 +08:00
/// </summary>
/// <param name="levelId"></param>
2024-10-18 13:31:45 +08:00
public static async UniTask JumpToTeamInfoByGuide(int levelId)
2024-10-15 18:48:43 +08:00
{
DebugUtil.Log("Jump to : " + levelId);
DataLevel data = TableManager.Instance.Tables.Level.Get(levelId);
if (data == null)
{
2024-10-18 13:31:45 +08:00
DebugUtil.Log("Jump to team info failed, level id not found: " + levelId);
return;
}
LevelManager.Instance.TryGetLevelInfoByID(levelId, out LevelInfo levelInfo);
//await UI_LevelSelectController.Open(levelInfo);
//await UI_LevelDetailController.Open(levelInfo);
await UI_TeamAndSkillSelectController.Open(levelInfo, false, 1);
Team team = TeamEditManager.Instance.GetSelectTeam();
await UI_TeamInfoController.Open(team);
}
/// <summary>
/// 跳转队伍选择(引导用)
/// </summary>
/// <param name="levelId"></param>
/// <returns></returns>
public static async UniTask JumpToTeamSelectByGuide(int levelId)
{
DebugUtil.Log("Jump to : " + levelId);
DataLevel data = TableManager.Instance.Tables.Level.Get(levelId);
if (data == null)
{
DebugUtil.Log("Jump to team select failed, level id not found: " + levelId);
2024-10-15 18:48:43 +08:00
return;
}
LevelManager.Instance.TryGetLevelInfoByID(levelId, out LevelInfo levelInfo);
2024-10-17 16:45:44 +08:00
//await UI_LevelSelectController.Open(levelInfo);
//await UI_LevelDetailController.Open(levelInfo);
2024-10-15 18:48:43 +08:00
await UI_TeamAndSkillSelectController.Open(levelInfo, false, 1);
}
2024-05-31 16:36:36 +08:00
public static async void JumpToShopDetailAsync(int shopID, Action onLoadWindowCallback)
2024-05-31 16:36:36 +08:00
{
DebugUtil.Log("Jump to Shop : " + shopID);
var shopCfg = TableManager.Instance.Tables.Shop;
if (!shopCfg.DataMap.TryGetValue(shopID, out var shop))
{
DebugUtil.Log("Jump to shop detail failed, shop id not found: " + shopID);
return;
}
2025-03-19 14:34:57 +08:00
await UI_ShopNewController.Open(shopID);
onLoadWindowCallback?.Invoke();
2024-05-31 16:36:36 +08:00
}
public static async void JumpToPvpMainAsync(Action onLoadWindowCallback)
{
await UI_PVPMainController.Open();
onLoadWindowCallback?.Invoke();
}
2024-10-11 19:29:01 +08:00
2024-10-18 13:31:45 +08:00
public static async UniTask JumpToPvpMain()
2024-10-15 18:48:43 +08:00
{
await UI_PVPMainController.Open();
}
public static async void JumpToGachaAsync(int GachaID, Action onLoadWindowCallback)
2024-10-11 19:29:01 +08:00
{
await UI_DrawMainPanelController.Open();
onLoadWindowCallback?.Invoke();
2024-10-11 19:29:01 +08:00
}
2023-12-27 19:42:58 +08:00
}
}