1073 lines
33 KiB
C#
1073 lines
33 KiB
C#
using cfg.CharacterCfg;
|
||
using Framework;
|
||
using NLDPB;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using Gameplay;
|
||
using PhxhSDK;
|
||
using TMPro;
|
||
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
using Image = UnityEngine.UI.Image;
|
||
using Cysharp.Threading.Tasks;
|
||
using Gameplay.Guide;
|
||
|
||
public class UISelectCharacterController : UIWindow
|
||
{
|
||
/// <summary>
|
||
/// 打开角色界面(队伍编辑)
|
||
/// </summary>
|
||
/// <param name="team"></param>
|
||
/// <param name="index"></param>
|
||
/// <returns></returns>
|
||
public static async UniTask<UIWindow> Open(Team team, int index)
|
||
{
|
||
InputData inputData = new()
|
||
{
|
||
OpenType = E_OpenType.EditTeam,
|
||
Data = team,
|
||
Idx = index
|
||
};
|
||
|
||
return await UIManager.Instance.CreateAndOpenWindow(UINameConst.UISelectCharacter, inputData);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 打开角色界面
|
||
/// </summary>
|
||
/// <param name="team"></param>
|
||
/// <param name="index"></param>
|
||
/// <returns></returns>
|
||
public static async UniTask<UIWindow> Open()
|
||
{
|
||
InputData inputData = new()
|
||
{
|
||
OpenType = E_OpenType.Default
|
||
};
|
||
|
||
return await UIManager.Instance.CreateAndOpenWindow(UINameConst.UISelectCharacter, inputData);
|
||
}
|
||
|
||
#region 结构
|
||
private struct InputData
|
||
{
|
||
public E_OpenType OpenType;
|
||
public Team Data;
|
||
public int Idx;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 打开类型
|
||
/// </summary>
|
||
private enum E_OpenType
|
||
{
|
||
/// <summary>
|
||
/// 默认
|
||
/// </summary>
|
||
Default,
|
||
/// <summary>
|
||
/// 队伍编辑
|
||
/// </summary>
|
||
EditTeam
|
||
}
|
||
|
||
/// <summary>
|
||
/// 角色排序类型
|
||
/// </summary>
|
||
private enum E_CharacterSortType
|
||
{
|
||
/// <summary>
|
||
/// 按星级(稀有度)排序
|
||
/// </summary>
|
||
EStar,
|
||
/// <summary>
|
||
/// 按等级排序
|
||
/// </summary>
|
||
ELevel,
|
||
/// <summary>
|
||
/// 按进修等级排序
|
||
/// </summary>
|
||
EAwake,
|
||
/// <summary>
|
||
/// 按考核等级排序
|
||
/// </summary>
|
||
EBreak,
|
||
/// <summary>
|
||
/// 按好感度排序
|
||
/// </summary>
|
||
ELikely,
|
||
}
|
||
|
||
/// <summary>
|
||
/// 排序状态
|
||
/// </summary>
|
||
private enum E_SortState
|
||
{
|
||
/// <summary>
|
||
/// 不排序
|
||
/// </summary>
|
||
None = 0,
|
||
/// <summary>
|
||
/// 升序
|
||
/// </summary>
|
||
Up,
|
||
/// <summary>
|
||
/// 降序
|
||
/// </summary>
|
||
Down,
|
||
}
|
||
|
||
public class CultivateStruct
|
||
{
|
||
public List<CharacterDataInfo> showList;
|
||
public CharacterDataInfo info;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 角色
|
||
/// </summary>
|
||
private class CharacterItem : UIGameObjectWrapper
|
||
{
|
||
#region UI
|
||
private Image imageBg;
|
||
/// <summary>
|
||
/// 等级进度条
|
||
/// </summary>
|
||
private Image imageLevel;
|
||
/// <summary>
|
||
/// 职业图标
|
||
/// </summary>
|
||
private Image imageProfessionLogo;
|
||
/// <summary>
|
||
/// 角色立绘
|
||
/// </summary>
|
||
private Image imagePoster;
|
||
/// <summary>
|
||
/// 等级
|
||
/// </summary>
|
||
private TMP_Text textLevel;
|
||
/// <summary>
|
||
/// 角色名
|
||
/// </summary>
|
||
private TMP_Text textCharacterName;
|
||
/// <summary>
|
||
/// 角色稀有度颜色遮罩
|
||
/// </summary>
|
||
private Image RarityCover;
|
||
private TMP_Text textDebugId;
|
||
/// <summary>
|
||
/// 遮罩
|
||
/// </summary>
|
||
private GameObject goMask;
|
||
/// <summary>
|
||
/// 卸下
|
||
/// </summary>
|
||
private GameObject goClear;
|
||
private Button button;
|
||
private RedPointUIController RedPointUI;
|
||
#endregion
|
||
|
||
private CharacterDataInfo info;
|
||
/// <summary>
|
||
/// 星星列表
|
||
/// </summary>
|
||
private readonly List<GameObject> listStar;
|
||
private readonly Action<CharacterDataInfo> callback;
|
||
|
||
public bool IsShowMask
|
||
{
|
||
set { goMask.IsScaleShow(value); }
|
||
}
|
||
|
||
public bool IsShowClear
|
||
{
|
||
set{ goClear.IsScaleShow(value); }
|
||
}
|
||
|
||
public bool IsShowPoster
|
||
{
|
||
set { imagePoster.gameObject.IsScaleShow(value); }
|
||
}
|
||
|
||
public CharacterItem(GameObject root, Action<CharacterDataInfo> callbackAction) : base(root)
|
||
{
|
||
callback = callbackAction;
|
||
|
||
imageBg = GetComponent<Image>("Bg");//GoRoot.
|
||
imageLevel = GetComponent<Image>("Bg/Image_Poster/Image_Rect/Image_LevelBar");
|
||
imageProfessionLogo = GetComponent<Image>("Bg/Image_Poster/Image_Rect/Image_ProfessionLogo");
|
||
imagePoster = GetComponent<Image>("Bg/Image_Poster");
|
||
textLevel = GetComponent<TMP_Text>("Bg/Image_Poster/Image_Rect/Image_LevelBar/Text_Level");
|
||
textCharacterName = GetComponent<TMP_Text>("Bg/Image_Poster/Image_ColorCover/Image_CharacterName/Text_CharacterName");
|
||
RarityCover = GetComponent<Image>("Bg/Image_Poster/Image_ColorCover");
|
||
textDebugId = GetComponent<TMP_Text>("Bg/DebugID");
|
||
goMask = FindObj("Bg/Image_Mask");
|
||
goClear = FindObj("Bg/Image_Clear");
|
||
button = GoRoot.GetComponent<Button>();
|
||
RedPointUI = GetComponent<RedPointUIController>("Bg/UI_RedPoint");
|
||
|
||
Transform tsStarRoot = FindObj("Bg/Image_Poster/Image_ColorCover/Image_CharacterName/Stars").transform;
|
||
listStar = new(tsStarRoot.childCount);
|
||
for (int i = 0; i < tsStarRoot.childCount; ++i)
|
||
{
|
||
listStar.Add(tsStarRoot.GetChild(i).gameObject);
|
||
}
|
||
|
||
BindButton(button, OnClick);
|
||
}
|
||
|
||
public async void SetInfo(CharacterDataInfo characterDataInfo, E_OpenType openType, Team team)
|
||
{
|
||
info = characterDataInfo;
|
||
|
||
RedPointUI.NodeID = info.RedPointNode.ID;
|
||
DataCharacterBreak breakCfg = TableManager.Instance.Tables.CharacterBreak.Get(info.Cfg.RoleID, (int)info.BreakLevel);
|
||
int levelLimit = breakCfg?.LevelLimit ?? 1000;
|
||
|
||
if (info.Level >= levelLimit)
|
||
{
|
||
imageLevel.fillAmount = 1f;
|
||
//imageLevel.fillAmount = (float)info.Level / levelLimit;
|
||
}
|
||
else
|
||
{
|
||
var LevelExpCfg = TableManager.Instance.Tables.CharacterLevelExp;
|
||
imageLevel.fillAmount = info.Exp * 1.0f / (LevelExpCfg.Get((int)info.Level + 1).EXP == 0 ? 1 : LevelExpCfg.Get((int)info.Level + 1).EXP);
|
||
}
|
||
textLevel.text = info.Level.ToString();
|
||
imageProfessionLogo.sprite = AssetManager.Instance.GetPreLoadResult<Sprite>(TableManager.Instance.Tables.JobAttri.GetOrDefault((int)info.Cfg.Job).IconPath);
|
||
//await LoadAssetAsync<Sprite>(TableManager.Instance.Tables.JobAttri.GetOrDefault((int)info.Cfg.Job).IconPath);
|
||
textCharacterName.text = CommonUtils.GetLocalizeText(info.Cfg.Name);
|
||
|
||
IsShowMask = openType == E_OpenType.EditTeam && team.IsCharacterInTeam(info.Uid);
|
||
|
||
var imgPath =
|
||
CommonUtils.GetCharacterPicPath(info.Cfg.RoleID, CommonUtils.ECharacterPicPathType.SelectCharacter);
|
||
var sprite = AssetManager.Instance.GetPreLoadResult<Sprite>(imgPath);//获取预加载好的角色立绘
|
||
CommonUtils.RefreshCharacter2DPic(imagePoster, sprite);
|
||
|
||
|
||
for (int i = 0; i < listStar.Count; i++)
|
||
{
|
||
GameObject goStar = listStar[i];
|
||
goStar.IsScaleShow((i + 1) < info.Cfg.StartStar);
|
||
}
|
||
var coverPath = "Assets/Art/UI/Texture/UI_Pic_Main/UI_Pic_ShowAllCharacter/SAC_AllPart/";
|
||
if (info.Cfg.StartStar == 3)
|
||
{
|
||
RarityCover.sprite = await LoadAssetAsync<Sprite>(coverPath + "UI_RarityWhite.png");//白色:三星
|
||
}
|
||
else if (info.Cfg.StartStar == 4)
|
||
{
|
||
RarityCover.sprite = await LoadAssetAsync<Sprite>(coverPath + "UI_RarityBlue.png");//蓝色:四星
|
||
}
|
||
else
|
||
{
|
||
RarityCover.sprite = await LoadAssetAsync<Sprite>(coverPath + "UI_RarityRed.png");//红色:五星
|
||
}
|
||
|
||
textDebugId.gameObject.IsScaleShow(DisplayIDForCeHua.IsDisplayID);
|
||
textDebugId.text = $"ID:{info.Cfg.RoleID}";
|
||
|
||
IsShowPoster = true;
|
||
IsShowClear = false;
|
||
imageBg.color = new Color(imageBg.color.r, imageBg.color.g, imageBg.color.b, 1f);
|
||
|
||
IsScaleShow = true;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 队伍编辑特殊下阵入口
|
||
/// </summary>
|
||
public void SetInfoByTeamEditorEmpty()
|
||
{
|
||
info = null;
|
||
|
||
IsShowPoster = false;
|
||
IsShowMask = false;
|
||
IsShowClear = true;
|
||
imageBg.color = new Color(imageBg.color.r, imageBg.color.g, imageBg.color.b, 0f);
|
||
|
||
IsScaleShow = true;
|
||
}
|
||
|
||
private void OnClick()
|
||
{
|
||
callback?.Invoke(info);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 排序按钮
|
||
/// </summary>
|
||
private class SortItem : UIGameObjectWrapper
|
||
{
|
||
private readonly Color SELECT_COLOR = Color.white;
|
||
private readonly Color NORMAL_COLOR = new(1f, 1f, 1f, 0.3f);
|
||
|
||
private Button button;
|
||
/// <summary>
|
||
/// 升序状态
|
||
/// </summary>
|
||
private GameObject goUp;
|
||
/// <summary>
|
||
/// 降序状态
|
||
/// </summary>
|
||
private GameObject goDown;
|
||
/// <summary>
|
||
/// 排序名
|
||
/// </summary>
|
||
private TMP_Text text;
|
||
|
||
/// <summary>
|
||
/// 排序回调
|
||
/// </summary>
|
||
private readonly Action<SortItem> sortAction;
|
||
/// <summary>
|
||
/// 排序类型
|
||
/// </summary>
|
||
private E_CharacterSortType sortType;
|
||
/// <summary>
|
||
/// 排序状态
|
||
/// </summary>
|
||
private E_SortState sortState;
|
||
|
||
/// <summary>
|
||
/// 排序状态
|
||
/// </summary>
|
||
public E_SortState SortState
|
||
{
|
||
get { return sortState; }
|
||
set
|
||
{
|
||
sortState = value;
|
||
switch (sortState)
|
||
{
|
||
case E_SortState.Up:
|
||
{
|
||
goUp.IsScaleShow(true);
|
||
goDown.IsScaleShow(false);
|
||
}
|
||
break;
|
||
case E_SortState.Down:
|
||
{
|
||
goUp.IsScaleShow(false);
|
||
goDown.IsScaleShow(true);
|
||
}
|
||
break;
|
||
default:
|
||
{
|
||
goUp.IsScaleShow(false);
|
||
goDown.IsScaleShow(false);
|
||
IsSelect = false;
|
||
}
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
|
||
public E_CharacterSortType SortType
|
||
{
|
||
set { sortType = value; }
|
||
get { return sortType; }
|
||
}
|
||
|
||
public bool IsSelect
|
||
{
|
||
set { text.color = value ? SELECT_COLOR : NORMAL_COLOR; }
|
||
}
|
||
|
||
public SortItem(GameObject root, E_CharacterSortType sortType, Action<SortItem> sort) : base(root)
|
||
{
|
||
this.sortType = sortType;
|
||
sortAction = sort;
|
||
|
||
button = GoRoot.GetComponent<Button>();
|
||
goUp = FindObj("Image_Default/Image_UP");
|
||
goDown = FindObj("Image_Default/Image_Down");
|
||
text = GetComponent<TMP_Text>("Text_Default");
|
||
|
||
SortState = E_SortState.None;
|
||
|
||
BindButton(button, OnClick);
|
||
|
||
IsScaleShow = true;
|
||
}
|
||
|
||
private void OnClick()
|
||
{
|
||
//if (SortState == E_SortState.None)
|
||
// SortState = E_SortState.Down;
|
||
//else if (SortState == E_SortState.Down)
|
||
// SortState = E_SortState.Up;
|
||
//else
|
||
// SortState = E_SortState.None;
|
||
|
||
if (SortState == E_SortState.Down)
|
||
SortState = E_SortState.Up;
|
||
else
|
||
SortState = E_SortState.Down;
|
||
//改为两种状态切换
|
||
|
||
sortAction?.Invoke(this);
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
/// <summary>
|
||
/// 没有角色状态
|
||
/// </summary>
|
||
private GameObject goEmpty;
|
||
/// <summary>
|
||
/// 循环列表
|
||
/// </summary>
|
||
private RecycleView recycleView;
|
||
|
||
/// <summary>
|
||
/// 下拉框全选值
|
||
/// </summary>
|
||
private const int DROPDOWN_ALL_VALUE = -1;
|
||
/// <summary>
|
||
/// 职业下拉框全选图标路径
|
||
/// </summary>
|
||
private const string DROPDOWN_JOBALL_ICON_PATH = "Assets/Art/UI/Texture/Icon/Job/UI_Profession_All.png";
|
||
|
||
#region 私有变量
|
||
/// <summary>
|
||
/// 势力下拉框
|
||
/// </summary>
|
||
private UITextDropdown<int> factionDropDown;
|
||
/// <summary>
|
||
/// 其他下拉框
|
||
/// </summary>
|
||
private UITextDropdown<int> otherDropDown;
|
||
/// <summary>
|
||
/// 职业下拉框
|
||
/// </summary>
|
||
private UIImageDropDown<int> jobDropDown;
|
||
/// <summary>
|
||
/// 职业配置
|
||
/// </summary>
|
||
private JobAttri jobAttriCfg;
|
||
/// <summary>
|
||
/// 势力排序
|
||
/// </summary>
|
||
private FactionAttri factionAttriCfg;
|
||
/// <summary>
|
||
/// 打开界面类型
|
||
/// </summary>
|
||
private E_OpenType openType = E_OpenType.Default;
|
||
/// <summary>
|
||
/// 打开时传入队伍信息
|
||
/// </summary>
|
||
private Team curTeam;
|
||
/// <summary>
|
||
/// 打开时传入的队伍索引
|
||
/// </summary>
|
||
private int teamIndex;
|
||
/// <summary>
|
||
/// 角色字典
|
||
/// </summary>
|
||
private readonly Dictionary<int, CharacterItem> dicCharacter = new();
|
||
/// <summary>
|
||
/// 当前筛选的势力
|
||
/// </summary>
|
||
private int selectFractionIndex = DROPDOWN_ALL_VALUE;
|
||
/// <summary>
|
||
/// 当前筛选的职业
|
||
/// </summary>
|
||
private int selectJobIndex = DROPDOWN_ALL_VALUE;
|
||
/// <summary>
|
||
/// 所有角色列表
|
||
/// </summary>
|
||
private List<CharacterDataInfo> listAllCharacter = new();
|
||
/// <summary>
|
||
/// 要显示的角色列表
|
||
/// </summary>
|
||
private readonly List<CharacterDataInfo> listShowCharacter = new();
|
||
/// <summary>
|
||
/// 排序选项列表
|
||
/// </summary>
|
||
private readonly List<SortItem> listSortItem = new();
|
||
/// <summary>
|
||
/// 当前选择排序
|
||
/// </summary>
|
||
private SortItem curSortItem;
|
||
#endregion
|
||
|
||
public override async void PreLoad(object data = null)
|
||
{
|
||
if (data == null)
|
||
return;
|
||
|
||
InputData input = (InputData)data;
|
||
openType = input.OpenType;
|
||
if (openType == E_OpenType.EditTeam)
|
||
{
|
||
curTeam = input.Data;
|
||
teamIndex = input.Idx;
|
||
}
|
||
|
||
#region 获取配置
|
||
jobAttriCfg = TableManager.Instance.Tables.JobAttri;
|
||
factionAttriCfg = TableManager.Instance.Tables.FactionAttri;
|
||
#endregion
|
||
|
||
#region 获取角色数据
|
||
listAllCharacter = CharacterDataInfoManager.Instance.DataList;
|
||
for (int i = 0; i < listAllCharacter.Count; i++)
|
||
{
|
||
string path = CommonUtils.GetCharacterPicPath(listAllCharacter[i].Cfg.RoleID, CommonUtils.ECharacterPicPathType.SelectCharacter);
|
||
AssetManager.Instance.PostPreload<Sprite>(path).Forget();
|
||
}
|
||
#endregion
|
||
|
||
#region 获取职业图标
|
||
foreach (Ejob factionItem in Enum.GetValues(typeof(Ejob)))
|
||
{
|
||
DataJobAttri dataJobAttri = jobAttriCfg.Get((int)factionItem);
|
||
if (null == dataJobAttri)
|
||
{
|
||
DebugUtil.LogError($"配置获取失败,id: {(int)factionItem}");
|
||
continue;
|
||
}
|
||
|
||
AssetManager.Instance.PostPreload<Sprite>(dataJobAttri.IconPath).Forget();
|
||
}
|
||
AssetManager.Instance.PostPreload<Sprite>(DROPDOWN_JOBALL_ICON_PATH).Forget();
|
||
#endregion
|
||
}
|
||
|
||
public override void OnInit()
|
||
{
|
||
recycleView = GetComponent<RecycleView>("ScrollView_SelectCharacter");
|
||
//recycleView.cell = FindObj("ScrollView_SelectCharacter/Viewport/Content/Cell");
|
||
goEmpty = FindObj("Nothing");
|
||
|
||
factionDropDown = new UITextDropdown<int>(FindObj("Image_BG/Button_Group"), FindObj("Image_BG/Button_Group/Text_Group"), FactionDropdownValueChanged, FactionDropdownData2Text);
|
||
otherDropDown = new UITextDropdown<int>(FindObj("Image_BG/Image_Menu/Button_ChangeLevel"), FindObj("Image_BG/Image_Menu/Button_AdvanceLevel/Text_Default"), OtherDropdownValueChanged, OtherDropdownData2Text);
|
||
jobDropDown = new UIImageDropDown<int>(FindObj("Image_BG/Button_Profession"), FindObj("Image_BG/Button_Profession/Text_Profession"), JobDropdownValueChanged, JobDropdownData2Text, JobDropdownData2Image);
|
||
listSortItem.Add(new SortItem(FindObj("Image_BG/Image_Menu/Button_Rarity"), E_CharacterSortType.EStar, OnSort));
|
||
listSortItem.Add(new SortItem(FindObj("Image_BG/Image_Menu/Button_Level"), E_CharacterSortType.ELevel, OnSort));
|
||
listSortItem.Add(new SortItem(FindObj("Image_BG/Image_Menu/Button_AdvanceLevel"), E_CharacterSortType.EAwake, OnSort));
|
||
|
||
//进入时默认选择一种排序
|
||
curSortItem = listSortItem[1];
|
||
listSortItem[1].SortState = E_SortState.Down;
|
||
recycleView.Init(OnRefreshItem);
|
||
|
||
AddDropDownOption();
|
||
|
||
BindButton("Image_BG/Button_Back/Button_back", OnBack);
|
||
BindButton("Image_BG/Button_Back/Button_Home", OnHome);
|
||
|
||
//OnSort(listSortItem[1]);
|
||
}
|
||
|
||
protected override void OnShowWindow(object data = null)
|
||
{
|
||
base.OnShowWindow(data);
|
||
|
||
RefreshUI();
|
||
|
||
EventManager.Instance.Register(EventManager.EventName.EN_ShowAllCharacterSortType, OnReceiveShowAllCharacterSortEvent);
|
||
EventManager.Instance.Register(EventManager.EventName.EN_CharacterLevelUp, (Action<UpgradeType>)OnCharacterLevelup);
|
||
}
|
||
|
||
protected override void OnHideWindow()
|
||
{
|
||
EventManager.Instance.Unregister(EventManager.EventName.EN_CharacterLevelUp, (Action<UpgradeType>)OnCharacterLevelup);
|
||
EventManager.Instance.Unregister(EventManager.EventName.EN_ShowAllCharacterSortType, OnReceiveShowAllCharacterSortEvent);
|
||
|
||
base.OnHideWindow();
|
||
}
|
||
|
||
public override void OnRelease()
|
||
{
|
||
#region 卸载职业图标
|
||
foreach (Ejob factionItem in Enum.GetValues(typeof(Ejob)))
|
||
{
|
||
AssetManager.Instance.Unload(jobAttriCfg.Get((int)factionItem).IconPath);
|
||
}
|
||
AssetManager.Instance.Unload(DROPDOWN_JOBALL_ICON_PATH);
|
||
#endregion
|
||
|
||
#region 卸载角色立绘
|
||
for (int i = 0; i < listAllCharacter.Count; i++)
|
||
{
|
||
string path = CommonUtils.GetCharacterPicPath(listAllCharacter[i].Cfg.RoleID, CommonUtils.ECharacterPicPathType.SelectCharacter);
|
||
AssetManager.Instance.Unload(path);
|
||
}
|
||
#endregion
|
||
|
||
foreach (CharacterItem characterItem in dicCharacter.Values)
|
||
{
|
||
characterItem.Dispose();
|
||
}
|
||
dicCharacter.Clear();
|
||
|
||
base.OnRelease();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 队伍编辑返回
|
||
/// </summary>
|
||
private void BackInTeam()
|
||
{
|
||
if (openType == E_OpenType.EditTeam)
|
||
EventManager.Instance.Send(EventManager.EventName.TeamModified, curTeam.TeamIndex);
|
||
|
||
CloseWindow();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 排序角色
|
||
/// </summary>
|
||
/// <param name="sortType"></param>
|
||
private void SortCharacter()
|
||
{
|
||
if (curSortItem == null || curSortItem.SortState == E_SortState.None)
|
||
return;
|
||
|
||
switch (curSortItem.SortType)
|
||
{
|
||
case E_CharacterSortType.EStar:
|
||
{
|
||
if (curSortItem.SortState == E_SortState.Up)
|
||
listShowCharacter.Sort((a, b) => { return CharacterSort(a, b, a.Cfg.StartStar.CompareTo(b.Cfg.StartStar)); });
|
||
else
|
||
listShowCharacter.Sort((a, b) => { return CharacterSort(a, b, b.Cfg.StartStar.CompareTo(a.Cfg.StartStar)); });
|
||
}
|
||
return;
|
||
case E_CharacterSortType.ELevel:
|
||
{
|
||
if (curSortItem.SortState == E_SortState.Up)
|
||
listShowCharacter.Sort((a, b) => { return CharacterSort(a, b, a.Level.CompareTo(b.Level)); });
|
||
else
|
||
listShowCharacter.Sort((a, b) => { return CharacterSort(a, b, b.Level.CompareTo(a.Level)); });
|
||
}
|
||
return;
|
||
case E_CharacterSortType.EAwake:
|
||
{
|
||
if (curSortItem.SortState == E_SortState.Up)
|
||
listShowCharacter.Sort((a, b) => { return CharacterSort(a, b, a.AwakeLevel.CompareTo(b.AwakeLevel)); });
|
||
else
|
||
listShowCharacter.Sort((a, b) => { return CharacterSort(a, b, b.AwakeLevel.CompareTo(a.AwakeLevel)); });
|
||
}
|
||
return;
|
||
case E_CharacterSortType.EBreak:
|
||
{
|
||
if (curSortItem.SortState == E_SortState.Up)
|
||
listShowCharacter.Sort((a, b) => { return CharacterSort(a, b, a.BreakLevel.CompareTo(b.BreakLevel)); });
|
||
else
|
||
listShowCharacter.Sort((a, b) => { return CharacterSort(a, b, b.BreakLevel.CompareTo(a.BreakLevel)); });
|
||
}
|
||
return;
|
||
case E_CharacterSortType.ELikely:
|
||
{
|
||
if (curSortItem.SortState == E_SortState.Up)
|
||
listShowCharacter.Sort((a, b) => { return CharacterSort(a, b, a.LikelyLevel.CompareTo(b.LikelyLevel)); });
|
||
else
|
||
listShowCharacter.Sort((a, b) => { return CharacterSort(a, b, b.LikelyLevel.CompareTo(a.LikelyLevel)); });
|
||
}
|
||
return;
|
||
default:
|
||
{
|
||
DebugUtil.LogError("未处理类型");
|
||
}
|
||
return;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 角色排序多层逻辑
|
||
/// 按等级>稀有度>突破等级>觉醒等级>好感度>ID这样的优先级依次来排
|
||
/// 遇到同级别情况就往后一个优先级取
|
||
/// </summary>
|
||
/// <param name="a"></param>
|
||
/// <param name="b"></param>
|
||
/// <param name="FirstCompare"></param>
|
||
/// <returns></returns>
|
||
int CharacterSort(CharacterDataInfo a, CharacterDataInfo b, int FirstCompare)
|
||
{
|
||
int ret = FirstCompare;
|
||
if (ret != 0)
|
||
return FirstCompare;
|
||
else
|
||
{
|
||
ret = b.Level.CompareTo(a.Level);//等级
|
||
if (ret != 0) return ret;
|
||
ret = b.Cfg.StartStar.CompareTo(a.Cfg.StartStar);//稀有度
|
||
if (ret != 0) return ret;
|
||
ret = b.BreakLevel.CompareTo(a.BreakLevel);//突破等级
|
||
if (ret != 0) return ret;
|
||
ret = b.AwakeLevel.CompareTo(a.AwakeLevel);//觉醒等级
|
||
if (ret != 0) return ret;
|
||
ret = b.LikelyLevel.CompareTo(a.LikelyLevel);//好感度
|
||
if (ret != 0) return ret;
|
||
ret = a.Cfg.RoleID.CompareTo(b.Cfg.RoleID);//ID
|
||
return ret;
|
||
}
|
||
}
|
||
|
||
|
||
#region 刷新方法
|
||
/// <summary>
|
||
/// 刷新动态列表
|
||
/// </summary>
|
||
/// <param name="cell"></param>
|
||
/// <param name="index"></param>
|
||
private void OnRefreshItem(GameObject cell, int index)
|
||
{
|
||
if (!dicCharacter.TryGetValue(cell.GetInstanceID(), out CharacterItem item))
|
||
{
|
||
item = new CharacterItem(cell, OnCharacter);
|
||
dicCharacter.Add(cell.GetInstanceID(), item);
|
||
}
|
||
|
||
if (openType == E_OpenType.Default && (index < 0 || index >= listShowCharacter.Count))
|
||
{
|
||
DebugUtil.LogError($"索引错误 {index}");
|
||
return;
|
||
}
|
||
|
||
var realIndex = openType == E_OpenType.EditTeam && index != 0 ? index - 1 : index;
|
||
if (openType == E_OpenType.EditTeam && index <= 0)
|
||
item.SetInfoByTeamEditorEmpty();
|
||
else
|
||
item.SetInfo(listShowCharacter[realIndex], openType, curTeam);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 刷新全部
|
||
/// </summary>
|
||
private void RefreshUI()
|
||
{
|
||
SelectListByJobAndFraction(); // 先筛选
|
||
SortCharacter(); // 再排序
|
||
|
||
if (listShowCharacter.Count == 0)
|
||
goEmpty.IsScaleShow(true);
|
||
else
|
||
{
|
||
goEmpty.IsScaleShow(false);
|
||
var count = listShowCharacter.Count;
|
||
if (openType == E_OpenType.EditTeam)
|
||
{
|
||
++count;
|
||
}
|
||
recycleView.ShowList(count);
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 回调方法
|
||
/// <summary>
|
||
/// 返回
|
||
/// </summary>
|
||
private void OnBack()
|
||
{
|
||
if (openType == E_OpenType.EditTeam)
|
||
{
|
||
BackInTeam();
|
||
return;
|
||
}
|
||
CloseWindow();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 主页
|
||
/// </summary>
|
||
private void OnHome()
|
||
{
|
||
if (GuideManager.Instance.IsGuiding && GuideManager.Instance.IsEditTeamGuide) // 编队引导不能退出
|
||
return;
|
||
|
||
UIManager.Instance.CloseAllNormalExcept(UINameConst.UI_MainPanel);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 排序
|
||
/// </summary>
|
||
private void OnSort(SortItem item)
|
||
{
|
||
curSortItem = item;
|
||
foreach (SortItem sortItem in listSortItem)
|
||
{
|
||
if (sortItem != curSortItem)
|
||
{
|
||
sortItem.SortState = E_SortState.None;
|
||
}
|
||
sortItem.IsSelect = sortItem == curSortItem;
|
||
}
|
||
RefreshUI();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 点击角色
|
||
/// </summary>
|
||
/// <param name="go"></param>
|
||
private async void OnCharacter(CharacterDataInfo info)
|
||
{
|
||
if (openType != E_OpenType.EditTeam)
|
||
{
|
||
CultivateStruct cultivateStruct = new()
|
||
{
|
||
showList = listShowCharacter,
|
||
info = info
|
||
};
|
||
|
||
await UIManager.Instance.CreateAndOpenWindow(UINameConst.UI_Cultivate, cultivateStruct);
|
||
|
||
return;
|
||
}
|
||
|
||
if (info == null)
|
||
{
|
||
curTeam.DoCharacterDown(teamIndex);
|
||
RefreshUI();
|
||
EventManager.Instance.Send(EventManager.EventName.TeamEditModelClear, teamIndex);
|
||
BackInTeam();
|
||
return;
|
||
}
|
||
|
||
uint id = info.Uid;
|
||
if (curTeam.IsCharacterInTeam(id))
|
||
{
|
||
uint[] ids = curTeam.GetCharacterIDs();
|
||
int idx = Array.IndexOf(ids, id);
|
||
if (idx >= 0)
|
||
EventManager.Instance.Send(EventManager.EventName.TeamEditModelClear, idx);
|
||
|
||
curTeam.DoCharacterDown(id);
|
||
}
|
||
|
||
curTeam.DoCharacterUp(teamIndex, id);
|
||
EventManager.Instance.Send(EventManager.EventName.TeamEditModelCreate, new TeamPreviewNode.CharAddData { ID = id, Idx = teamIndex });
|
||
DialogueManager.Instance.PlayDiaogue((int)id, cfg.DialogueCfg.E_DialogueType.JoinTeam);
|
||
|
||
RefreshUI();
|
||
BackInTeam();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 角色升级
|
||
/// </summary>
|
||
/// <param name="type"></param>
|
||
private void OnCharacterLevelup(UpgradeType type)
|
||
{
|
||
if (type != UpgradeType.UtLevel)
|
||
return;
|
||
|
||
RefreshUI();
|
||
}
|
||
|
||
private void OnReceiveShowAllCharacterSortEvent()
|
||
{
|
||
DebugUtil.Log("事件接收成功");
|
||
}
|
||
#endregion
|
||
|
||
#region DropDown
|
||
/// <summary>
|
||
/// 势力下拉框获取文本
|
||
/// </summary>
|
||
/// <param name="value"></param>
|
||
/// <returns></returns>
|
||
private string FactionDropdownData2Text(int value)
|
||
{
|
||
if (value == DROPDOWN_ALL_VALUE)
|
||
return CommonUtils.GetLocalizeText("cultivate_AllFraction");
|
||
else
|
||
return CommonUtils.GetLocalizeText(E_LocalizePrefix.faction, factionAttriCfg.Get(value).Faction);// factionAttriCfg.Get(value).DisplayName
|
||
}
|
||
|
||
/// <summary>
|
||
/// 职业下拉框获取文本
|
||
/// </summary>
|
||
/// <param name="value"></param>
|
||
/// <returns></returns>
|
||
private string JobDropdownData2Text(int value)
|
||
{
|
||
if (value == DROPDOWN_ALL_VALUE)
|
||
return CommonUtils.GetLocalizeText("cultivate_AllJob");
|
||
else
|
||
return CommonUtils.GetLocalizeText(jobAttriCfg.Get(value).DisplayName);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 职业下拉框获取图片
|
||
/// </summary>
|
||
/// <param name="value"></param>
|
||
/// <returns></returns>
|
||
private Sprite JobDropdownData2Image(int value)
|
||
{
|
||
if (value == DROPDOWN_ALL_VALUE)
|
||
return AssetManager.Instance.GetPreLoadResult<Sprite>(DROPDOWN_JOBALL_ICON_PATH);
|
||
else
|
||
return AssetManager.Instance.GetPreLoadResult<Sprite>(jobAttriCfg.Get(value).IconPath);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 其他下拉框获取文本
|
||
/// </summary>
|
||
/// <param name="value"></param>
|
||
/// <returns></returns>
|
||
private string OtherDropdownData2Text(int value)
|
||
{
|
||
return GetCharactererSortTypeLocalize((E_CharacterSortType)value);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 势力下拉框选中回调
|
||
/// </summary>
|
||
/// <param name="value"></param>
|
||
private void FactionDropdownValueChanged(int value)
|
||
{
|
||
if (selectFractionIndex == value)
|
||
return;
|
||
|
||
selectFractionIndex = value;
|
||
|
||
if (value != DROPDOWN_ALL_VALUE && !IsExistEligible())
|
||
{
|
||
CommonUtils.ShowMessageTips(CommonUtils.GetLocalizeText("cultivate_notHaveFractionJob"));
|
||
return;
|
||
}
|
||
|
||
RefreshUI();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 职业下拉框选中回调
|
||
/// </summary>
|
||
/// <param name="value"></param>
|
||
private void JobDropdownValueChanged(int value)
|
||
{
|
||
if (selectJobIndex == value)
|
||
return;
|
||
|
||
selectJobIndex = value;
|
||
|
||
if (value != DROPDOWN_ALL_VALUE && !IsExistEligible())
|
||
{
|
||
CommonUtils.ShowMessageTips(CommonUtils.GetLocalizeText("cultivate_notHaveFractionJob"));
|
||
return;
|
||
}
|
||
|
||
RefreshUI();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 其他下拉框选中回调
|
||
/// </summary>
|
||
/// <param name="value"></param>
|
||
private void OtherDropdownValueChanged(int value)
|
||
{
|
||
listSortItem[^1].SortType = (E_CharacterSortType)value;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 添加下拉框选项
|
||
/// </summary>
|
||
private void AddDropDownOption()
|
||
{
|
||
List<int> listDropDownData;
|
||
|
||
#region 添加势力下拉框选项
|
||
listDropDownData = new() { DROPDOWN_ALL_VALUE };
|
||
foreach (Efaction faction in Enum.GetValues(typeof(Efaction)))
|
||
{
|
||
listDropDownData.Add((int)faction);
|
||
}
|
||
factionDropDown.SetData(listDropDownData);
|
||
#endregion
|
||
|
||
#region 职业下拉框选项
|
||
listDropDownData = new() { DROPDOWN_ALL_VALUE };
|
||
foreach (Ejob factionItem in Enum.GetValues(typeof(Ejob)))
|
||
{
|
||
listDropDownData.Add(((int)factionItem));
|
||
}
|
||
jobDropDown.SetData(listDropDownData);
|
||
#endregion
|
||
|
||
#region 其他下拉框选项
|
||
listDropDownData = new();
|
||
foreach (E_CharacterSortType sortType in Enum.GetValues(typeof(E_CharacterSortType)))
|
||
{
|
||
if (sortType == E_CharacterSortType.EStar)
|
||
continue;
|
||
|
||
if (sortType == E_CharacterSortType.ELevel)
|
||
continue;
|
||
|
||
listDropDownData.Add((int)sortType);
|
||
}
|
||
otherDropDown.SetData(listDropDownData);
|
||
#endregion
|
||
}
|
||
|
||
private string GetCharactererSortTypeLocalize(E_CharacterSortType sortType)
|
||
{
|
||
return sortType switch
|
||
{
|
||
E_CharacterSortType.EAwake => CommonUtils.GetLocalizeText("culitivate_AwakeLevel"),
|
||
E_CharacterSortType.EBreak => CommonUtils.GetLocalizeText("culitivate_BreakLevel"),
|
||
E_CharacterSortType.ELikely => CommonUtils.GetLocalizeText("culitivate_likely"),
|
||
_ => "",
|
||
};
|
||
}
|
||
|
||
/// <summary>
|
||
/// 是否存在符合条件的
|
||
/// </summary>
|
||
/// <param name="fraction"></param>
|
||
/// <returns></returns>
|
||
private bool IsExistEligible()
|
||
{
|
||
foreach (CharacterDataInfo info in listAllCharacter)
|
||
{
|
||
if (!IsConditionValid(selectFractionIndex, (int)info.Cfg.Fraction))
|
||
continue;
|
||
|
||
if (!IsConditionValid(selectJobIndex, (int)info.Cfg.Job))
|
||
continue;
|
||
|
||
return true;
|
||
}
|
||
|
||
return false;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 筛选势力和职业
|
||
/// </summary>
|
||
private void SelectListByJobAndFraction()
|
||
{
|
||
listShowCharacter.Clear();
|
||
for (int i = 0; i < listAllCharacter.Count; i++)
|
||
{
|
||
if (!IsConditionValid(selectFractionIndex, (int)listAllCharacter[i].Cfg.Fraction))
|
||
continue;
|
||
|
||
if (!IsConditionValid(selectJobIndex, (int)listAllCharacter[i].Cfg.Job))
|
||
continue;
|
||
|
||
listShowCharacter.Add(listAllCharacter[i]);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 筛选条件是否有效
|
||
/// </summary>
|
||
private bool IsConditionValid(int selectId, int comparisonsId)
|
||
{
|
||
if (selectId == DROPDOWN_ALL_VALUE)
|
||
return true;
|
||
|
||
return selectId == comparisonsId;
|
||
}
|
||
#endregion
|
||
}
|