TH1/Unity/Assets/Scripts/TH1_UI/View/Info/UIInfoHeroView.cs
2025-10-31 13:39:10 +08:00

207 lines
6.1 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.Collections.Generic;
using Logic.Action;
using Logic.Audio;
using Logic.Multilingual;
using TH1_Core.Managers;
using TH1_Logic.Action;
using TH1_Logic.Core;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
namespace TH1_UI.View.Info
{
public class UIInfoHeroView : Base.View
{
public Button closeButton;
public ViDelegateAssisstant.Dele OnBtnCloseClick;
[Header("需要动态显示的对象")]
public GameObject PickedTitle;
public GameObject PoolTitle;
public GameObject PoolGroup;
public GameObject PoolButtonGroup;
[Header("已出战的格子")]
public List<UIInfoHeroAvatarMono> PickedList;
[Header("选择池的格子")]
public List<UIInfoHeroAvatarMono> PoolList;
//确认选择出战英雄的按钮
public Button CheckButton;
public Button ReturnButton;
private GiantType _choiceGiantType;
public void Reset()
{
InitStart();
}
protected override void InitStart()
{
base.InitStart();
InitPickAndPoolGroup();
if (closeButton == null || CheckButton == null || ReturnButton == null) return;
closeButton.onClick.RemoveAllListeners();
closeButton.onClick.AddListener(() => { OnBtnCloseClick.Invoke(); });
ReturnButton.onClick.RemoveAllListeners();
ReturnButton.onClick.AddListener(() => { OnBtnCloseClick.Invoke(); });
CheckButton.onClick.RemoveAllListeners();
CheckButton.onClick.AddListener(OnCheckChoice);
}
//初始化InitPickGroup将基础5个职阶的图像都设置好。后续Update的时候仅仅是改变谁显示谁不显示罢了
private void InitPickAndPoolGroup()
{
if (PoolList.Count < 5 || PickedList.Count < 3) return;
var player = Main.MapData.PlayerMap.SelfPlayerData;
var table = Table.Instance.UnitTypeDataAssets;
var civ = Table.Instance.TransCivIdToCivEnum(player.PlayerCivId);
var force = Table.Instance.TransForceIdToForceEnum(player.PlayerForceId);
//Step #1 先设置PoolList的对象图样
for (int i = 0; i < 5; i++)
{
ChessType ch = i switch
{
0 => ChessType.Knight,
1 => ChessType.Queen,
2 => ChessType.King,
3 => ChessType.Bishop,
_ => ChessType.Rook,
};
PoolList[i].InPool = true;
PoolList[i].UpdateInfo(isLock:false,isBlank:false,giantType:table.GetGiantType(civ,force,ch),0,true);
PoolList[i].SetClickCallback(OnChoice);
}
//Step #2 再初始化PickedList的锁定条件
for (int i = 0; i < 3; i++)
{
if(i != 0)PickedList[i].SetLockDesc(i);
PickedList[i].InPool = false;
PickedList[i].RefreshAfterForceFinish(RefreshAfterForceFinish);
}
}
//当子节点被点击的时候,
public void OnChoice(GiantType giantType)
{
for(int i= 0;i < PoolList.Count;i++)
if(PoolList[i].GetGiantType() != giantType)
PoolList[i].Deselect();
_choiceGiantType = giantType;
SetPickedList();
}
public void RefreshAfterForceFinish()
{
SetContent();
}
public void SetContent()
{
//Step #1 设置选择英雄框
SetPoolList();
//Step #2 设置出战框
SetPickedList();
//Step #3 处理音乐
if (Table.Instance.PlayerDataAssets.GetPlayerInfo(Main.MapData.PlayerMap.SelfPlayerData, out var info))
{
AudioManager.Instance.PlayMusic(info.MusicName, 1f, 2f, true);
}
}
public void SetPickedList()
{
var heroData = Main.MapData.PlayerMap.SelfPlayerData.PlayerHeroData;
//Step 1设置Title
var txt = PickedTitle.gameObject.GetComponent<TextMeshProUGUI>();
var mul = PickedTitle.gameObject.GetComponent<MultilingualTextMono>();
if(txt != null && mul != null)
MultilingualManager.Instance.SetUIText(txt,mul.ID.ToString(),new List<string>{ heroData.HeroCount.ToString()});
//Step #2 设置英雄列表
for(int i = 0; i < PickedList.Count;i++)
{
//处理已经出战的英雄
if (i < heroData.HeroCount)
PickedList[i].UpdateInfo(isLock:false,isBlank:false,heroData.HeroList[i].GiantType,heroData.HeroList[i].UnitLevel,false);
//处理已经待选择的英雄
else if (i >= heroData.HeroCount && i < heroData.MaxHeroCount)
PickedList[i].UpdateInfo(isLock:false,isBlank:true,_choiceGiantType,0,false);
//处理已锁定的英雄槽位
else if (i >= heroData.MaxHeroCount)
PickedList[i].UpdateInfo(isLock:true,isBlank:false,GiantType.None,0,false);
}
}
public void SetPoolList()
{
var player = Main.MapData.PlayerMap.SelfPlayerData;
var heroData = Main.MapData.PlayerMap.SelfPlayerData.PlayerHeroData;
_choiceGiantType = GiantType.None;
//确认是否要pick是否显示相关的模块
bool needPick = heroData.HeroCount != heroData.MaxHeroCount;
PoolTitle.SetActive(needPick);
PoolGroup.SetActive(needPick);
PoolButtonGroup.SetActive(needPick);
if (!needPick) return;
//开始设置具体的pickAvatar
//用来设置第一个默认选择的参数
bool firstSelect = true;
for (int i = 0; i < 5; i++)
{
var hasHero = heroData.HasHero(PoolList[i].GetGiantType());
PoolList[i].gameObject.SetActive(!hasHero);
if (hasHero) continue;
uint giantLevel = 0;
if (heroData.HeroCount > 0)
giantLevel = 1;
PoolList[i].UpdateInfo(isLock:false,isBlank:false,giantType:PoolList[i].GetGiantType(),giantLevel,firstSelect);
if (firstSelect)
{
_choiceGiantType = PoolList[i].GetGiantType();
firstSelect = false;
}
}
}
public void OnCheckChoice()
{
if (_choiceGiantType == GiantType.None) return;
var heroData = Main.MapData.PlayerMap.SelfPlayerData.PlayerHeroData;
var actionId = new CommonActionId()
{ ActionType = CommonActionType.PlayerAction, PlayerActionType = PlayerActionType.SelectHero,GiantType = _choiceGiantType };
var action = ActionLogicFactory.GetActionLogic(actionId);
if (action == null) return;
var actionParams = new CommonActionParams(mapData:Main.MapData,playerData:Main.MapData.PlayerMap.SelfPlayerData);
action.CompleteExecute(actionParams);
//heroData.AddHero(_choiceGiantType);
OnBtnCloseClick();
UIManager.Instance.BottomBarUI.UpdateHeroButtonSprite();
//SetContent();
}
public void CloseView()
{
AudioManager.Instance.StopMusic();
}
}
}