237 lines
6.4 KiB
C#
237 lines
6.4 KiB
C#
using Cysharp.Threading.Tasks;
|
||
using Gameplay;
|
||
using PhxhSDK;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using TMPro;
|
||
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
using Button = UnityEngine.UI.Button;
|
||
using Image = UnityEngine.UI.Image;
|
||
|
||
public class UI_TeamMarkChooseController : UIWindow
|
||
{
|
||
//UI GameObj
|
||
///Auto Gen Start///
|
||
public Image Image_Bg;
|
||
public Button Button_Close;
|
||
public RecycleView ScrollView_TeamMark;
|
||
public Image Image_TeamMark;
|
||
public Image Image_Empty;
|
||
public Image Image_Selected;
|
||
public Image Image_Lock;
|
||
public Image Image_CurrTeamMark;
|
||
public Image Image_CurrEmpty;
|
||
public Button Button_Confirm;
|
||
public Button Button_CantConfirm;
|
||
public TMP_Text Text_TeamMarkName;
|
||
public TMP_Text Text_Description;
|
||
public TMP_Text Text_Nothing;
|
||
public TMP_Text Text_Title;
|
||
|
||
private RawImage GaussianBlurMask;
|
||
|
||
///Auto Gen End///
|
||
|
||
List<TeamMarkManager.TeamMark> teamMarks = new List<TeamMarkManager.TeamMark>();
|
||
private int curIndex;
|
||
private int chooseIndex;
|
||
Action<int> OnSuccessChosen;
|
||
|
||
class ChooseData
|
||
{
|
||
public int teamMarkID;
|
||
/// <summary>
|
||
/// 选中标记后的回调
|
||
/// </summary>
|
||
public Action<int> OnChooseMark;
|
||
|
||
public ChooseData(int teamMarkID, Action<int> OnChooseMark)
|
||
{
|
||
this.teamMarkID = teamMarkID;
|
||
this.OnChooseMark = OnChooseMark;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 带回调的打开方法
|
||
/// </summary>
|
||
/// <param name="teamMarkID">原先选中的队标ID</param>
|
||
/// <param name="OnChooseMark">回调将传入选中队标ID作为参数,如: 510001</param>
|
||
/// <returns></returns>
|
||
public static async UniTask<UIWindow> Open(int teamMarkID, Action<int> OnChooseMark = null)
|
||
{
|
||
CommonUtils.CaptureScreenshot();
|
||
var data = new ChooseData(teamMarkID, OnChooseMark);
|
||
|
||
return await UIManager.Instance.CreateAndOpenWindow(UINameConst.UITeamMarkChoose, data);
|
||
}
|
||
|
||
// deal with input data
|
||
public override void PreLoad(object data = null)
|
||
{
|
||
var chooseData = data as ChooseData;
|
||
TeamMarkManager.Instance.SelectedMarkIndex = chooseData.teamMarkID;
|
||
DebugUtil.Log("选择的队标ID:" + chooseData.teamMarkID);
|
||
teamMarks = TeamMarkManager.Instance.ShownList;
|
||
DebugUtil.Log("队标数目:" + teamMarks.Count);
|
||
OnSuccessChosen = chooseData.OnChooseMark;//回调
|
||
|
||
curIndex = 0;
|
||
for (int i = 0; i < teamMarks.Count; i++)
|
||
{
|
||
if (teamMarks[i].ID == chooseData.teamMarkID)
|
||
{
|
||
curIndex = i;
|
||
break;
|
||
}
|
||
}
|
||
chooseIndex = curIndex;
|
||
|
||
#region 预加载图标
|
||
foreach(var item in teamMarks)
|
||
{
|
||
var IconPath = item.iconKey;
|
||
AssetManager.Instance.PostPreload<Sprite>(IconPath).Forget();
|
||
}
|
||
#endregion
|
||
}
|
||
|
||
// Use this for initialization
|
||
public override void OnInit()
|
||
{
|
||
//bind UI GameObj
|
||
UI_TeamMarkChooseBinder.GetComponents(this);
|
||
GaussianBlurMask = GetComponent<RawImage>("GaussianBlurMask");
|
||
GaussianBlurMask.texture = CommonUtils.GetScreenTexture2D();
|
||
ScrollView_TeamMark = GetComponent<RecycleView>("Image_Bg/ScrollView_TeamMark");
|
||
|
||
BindButton(Button_Close, OnCloseClick);
|
||
BindButton(Button_Confirm, OnConfirmClick);
|
||
|
||
ScrollView_TeamMark.Init(_RefreshPoolItem);//SetItemCountFunc(() => list.Count);
|
||
ScrollView_TeamMark.ShowList(teamMarks.Count);//UpdateData();
|
||
|
||
RefreshIconInfo();
|
||
}
|
||
|
||
//invoke when open window
|
||
protected override void OnShowWindow(object data = null)
|
||
{
|
||
|
||
}
|
||
|
||
//invoke when reload window
|
||
protected override void OnReloadWindow(object data = null)
|
||
{
|
||
|
||
}
|
||
|
||
//invoke when close window
|
||
protected override void OnHideWindow()
|
||
{
|
||
|
||
}
|
||
|
||
public override UniTask<bool> OnBack(object data = null)
|
||
{
|
||
if (teamMarks[curIndex].ID != TeamMarkManager.Instance.SelectedMarkIndex)
|
||
{
|
||
OnSuccessChosen?.Invoke(teamMarks[curIndex].ID);
|
||
DebugUtil.Log("选择的队标ID:" + teamMarks[curIndex].ID);
|
||
}
|
||
CloseWindow();
|
||
return base.OnBack(data);
|
||
}
|
||
|
||
//invoke when destroy
|
||
public override void OnRelease()
|
||
{
|
||
base.OnRelease();
|
||
#region 预加载释放
|
||
foreach (var item in teamMarks)
|
||
{
|
||
var IconPath = item.iconKey;
|
||
AssetManager.Instance.Unload(IconPath);
|
||
}
|
||
#endregion
|
||
}
|
||
|
||
#region scroll_view
|
||
private void _RefreshPoolItem(GameObject go, int index)
|
||
{
|
||
var iconData = teamMarks[index];
|
||
var TeamMarkIcon = CommonUtils.GetComponent<Image>(go, "Image_TeamMark");
|
||
var btn = CommonUtils.GetComponent<Button>(go, "Button_Choose");
|
||
var Image_Selected = CommonUtils.GetGameObject(go, "Image_Selected");
|
||
var Image_Lock = CommonUtils.GetGameObject(go, "Image_Lock");
|
||
|
||
var IconPath = iconData.iconKey;
|
||
TeamMarkIcon.sprite = AssetManager.Instance.GetPreLoadResult<Sprite>(IconPath);//await LoadAssetAsync<Sprite>(IconPath);
|
||
|
||
ClearBind(btn);
|
||
BindButton(btn, () =>
|
||
{
|
||
chooseIndex = index;
|
||
RefreshIconInfo();
|
||
});
|
||
|
||
Image_Lock.SetActive(index >= TeamMarkManager.Instance.UnlockMarksCnt);
|
||
if(index == curIndex)
|
||
{
|
||
Image_Selected.SetActive(true);
|
||
}
|
||
else
|
||
{
|
||
Image_Selected.SetActive(false);
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
void RefreshIconInfo()
|
||
{
|
||
var iconName = teamMarks[chooseIndex].nameKey;
|
||
Text_TeamMarkName.text = CommonUtils.GetLocalizeText(iconName);
|
||
var description = teamMarks[chooseIndex].sourcePathKey;
|
||
Text_Description.text = CommonUtils.GetLocalizeText(description);
|
||
var IconPath = teamMarks[chooseIndex].iconKey;
|
||
Image_CurrTeamMark.sprite = AssetManager.Instance.GetPreLoadResult<Sprite>(IconPath);//await LoadAssetAsync<Sprite>(IconPath);
|
||
|
||
if (chooseIndex >= TeamMarkManager.Instance.UnlockMarksCnt)//未解锁
|
||
{
|
||
Button_CantConfirm.gameObject.SetActive(true);
|
||
Text_Description.gameObject.SetActive(true);//显示获取途径
|
||
}
|
||
else
|
||
{
|
||
Button_CantConfirm.gameObject.SetActive(false);
|
||
Text_Description.gameObject.SetActive(false);//隐藏获取途径
|
||
}
|
||
if (curIndex == chooseIndex)
|
||
{
|
||
Button_CantConfirm.gameObject.SetActive(true);
|
||
}
|
||
}
|
||
|
||
#region button_click
|
||
protected override void OnCloseClick()
|
||
{
|
||
if (teamMarks[curIndex].ID != TeamMarkManager.Instance.SelectedMarkIndex)
|
||
{
|
||
OnSuccessChosen?.Invoke(teamMarks[curIndex].ID);
|
||
DebugUtil.Log("选择的队标ID:" + teamMarks[curIndex].ID);
|
||
}
|
||
base.OnCloseClick();
|
||
CloseWindow();
|
||
}
|
||
|
||
private void OnConfirmClick()
|
||
{
|
||
curIndex = chooseIndex;
|
||
ScrollView_TeamMark.ShowList(teamMarks.Count);
|
||
RefreshIconInfo();
|
||
}
|
||
|
||
#endregion
|
||
}
|