849 lines
40 KiB
C#
849 lines
40 KiB
C#
using System.Collections.Generic;
|
||
using Logic;
|
||
using Logic.Action;
|
||
using UnityEngine;
|
||
using TMPro; // 如果使用TextMeshPro
|
||
using RuntimeData;
|
||
using Logic.Multilingual;
|
||
using TH1Renderer;
|
||
using UnityEngine.UIElements;
|
||
using Button = UnityEngine.UI.Button;
|
||
using Image = UnityEngine.UI.Image;
|
||
|
||
public class BottomInfoUI// : MonoBehaviour
|
||
{
|
||
private MapData _mapData;
|
||
private Main _main;
|
||
public GameObject ROBottomInfoUI;
|
||
|
||
public GameObject
|
||
_skillInfo;
|
||
private GameObject
|
||
_unitBaseInfo,
|
||
_gridBaseInfo,
|
||
_cityBaseInfo,
|
||
_actionInfo,
|
||
_unitPreviewArea, //grid/unit预览框
|
||
_gridPreviewArea,
|
||
_cityPreviewArea,
|
||
_unitTitle,
|
||
_unitDesc,
|
||
_gridTitle,
|
||
_gridDesc,
|
||
_cityTitle,
|
||
_cityDesc,
|
||
_closeButton,
|
||
_actionArea,
|
||
_debugGrid,
|
||
_debugUnit,
|
||
_debugCity;
|
||
public GameObject _hintWindow;//提示窗口
|
||
|
||
//public Tilemap borderTilemap;
|
||
//public GameObject unitPrefab;
|
||
//private GameObject bottomInfoRenderedUnit;//用来存放角色预览的临时对象
|
||
|
||
//动画控制数据
|
||
private float _slideDuration = 0.2f;
|
||
private float _slideTime;
|
||
private Vector2 _hiddenPosition = new Vector2(-530, 0);
|
||
private Vector2 _visiblePosition = new Vector2(0, 0);
|
||
//private Vector2[] _visiblePosition = { new Vector2(100, 93), new Vector2(100, 100) };
|
||
private Vector2 _startPos, _endPos;
|
||
private float _startAlpha, _endAlpha;
|
||
//private Vector2[] _size = { new Vector2(1300,300),new Vector2(1300,686)};
|
||
//private Vector2[] _size = { new Vector2(1300,686),new Vector2(1300,686)};
|
||
private bool _isAnimating = false; // 动画是否正在进行
|
||
private bool _isShow = false;
|
||
|
||
public Sprite ActionBGAvailable;
|
||
public Sprite ActionBGExpensive;
|
||
public Sprite ActionBGUnavailable;
|
||
|
||
//-------- 表现层数据UI部分 --------//
|
||
public bool UIBottomInfoStatus = false;
|
||
public bool UIBottomInfoIsGrid = false;
|
||
public bool UIBottomInfoHideFirst = false;
|
||
public uint UIBottomInfoStatusObjectId;
|
||
public List<ActionLogicBase> ActionList;
|
||
public bool HasAction;
|
||
|
||
//--------- 对象的实际显示情况 ----------//
|
||
|
||
|
||
public BottomInfoUI(Main main,MapData mapData)
|
||
{
|
||
_main = main;
|
||
_mapData = mapData;
|
||
ROBottomInfoUI = UIManager.Instance.ROUIManager.transform.Find("BottomInfoPanel").gameObject;
|
||
_gridBaseInfo = ROBottomInfoUI.transform.Find("InfoGroup/GridBaseInfo").gameObject;
|
||
_unitBaseInfo = ROBottomInfoUI.transform.Find("InfoGroup/UnitBaseInfo").gameObject;
|
||
_cityBaseInfo = ROBottomInfoUI.transform.Find("InfoGroup/CityBaseInfo").gameObject;
|
||
_actionInfo = ROBottomInfoUI.transform.Find("InfoGroup/ActionInfo").gameObject;
|
||
_skillInfo = ROBottomInfoUI.transform.Find("InfoGroup/UnitBaseInfo/SkillIconArea").gameObject;
|
||
_closeButton = ROBottomInfoUI.transform.Find("CloseButton").gameObject; // 收起按钮
|
||
_hintWindow = ROBottomInfoUI.transform.Find("HintWindow").gameObject;
|
||
_debugGrid = UIManager.Instance.ROUIManager.transform.Find("DebugPanel/PanelGroup/Selected/DebugGrid").gameObject;
|
||
_debugUnit = UIManager.Instance.ROUIManager.transform.Find("DebugPanel/PanelGroup/Selected/DebugUnit").gameObject;
|
||
_debugCity = UIManager.Instance.ROUIManager.transform.Find("DebugPanel/PanelGroup/Selected/DebugCity").gameObject;
|
||
_unitTitle = ROBottomInfoUI.transform.Find("InfoGroup/UnitBaseInfo/Title").gameObject;
|
||
_gridTitle = ROBottomInfoUI.transform.Find("InfoGroup/GridBaseInfo/Title").gameObject;
|
||
_cityTitle = ROBottomInfoUI.transform.Find("InfoGroup/CityBaseInfo/Title").gameObject;
|
||
_unitDesc = ROBottomInfoUI.transform.Find("InfoGroup/UnitBaseInfo/Desc").gameObject;
|
||
_gridDesc = ROBottomInfoUI.transform.Find("InfoGroup/GridBaseInfo/Desc").gameObject;
|
||
_cityDesc = ROBottomInfoUI.transform.Find("InfoGroup/CityBaseInfo/Desc").gameObject;
|
||
_unitPreviewArea = ROBottomInfoUI.transform.Find("InfoGroup/UnitBaseInfo/PreviewArea/Grid").gameObject;
|
||
_gridPreviewArea = ROBottomInfoUI.transform.Find("InfoGroup/GridBaseInfo/PreviewArea/Grid").gameObject;
|
||
_cityPreviewArea = ROBottomInfoUI.transform.Find("InfoGroup/CityBaseInfo/PreviewArea/Grid").gameObject;
|
||
_actionArea = ROBottomInfoUI.transform.Find("InfoGroup/ActionInfo/ActionArea").gameObject;
|
||
ActionBGAvailable = Resources.Load<Sprite>("ArtResources/TH1UI/Common/bgAvailable");
|
||
ActionBGExpensive = Resources.Load<Sprite>("ArtResources/TH1UI/Common/bgExpensive");
|
||
ActionBGUnavailable = Resources.Load<Sprite>("ArtResources/TH1UI/Common/bgUnavailable");
|
||
Init();
|
||
}
|
||
public void Update()
|
||
{
|
||
if (_isAnimating)
|
||
{
|
||
_slideTime += Time.deltaTime / _slideDuration;
|
||
if (_isShow)
|
||
{
|
||
ROBottomInfoUI.GetComponent<RectTransform>().anchoredPosition = Vector2.Lerp(_hiddenPosition, _visiblePosition, _slideTime);
|
||
ROBottomInfoUI.GetComponent<CanvasGroup>().alpha = Mathf.Lerp(0f, 1f, _slideTime);
|
||
}
|
||
else
|
||
{
|
||
ROBottomInfoUI.GetComponent<RectTransform>().anchoredPosition = Vector2.Lerp(_visiblePosition, _hiddenPosition, _slideTime);
|
||
ROBottomInfoUI.GetComponent<CanvasGroup>().alpha = Mathf.Lerp(1f, 0f, _slideTime);
|
||
}
|
||
|
||
if (_slideTime >= 1f)
|
||
{
|
||
_isAnimating = false;
|
||
_slideTime = 0f;
|
||
if(!_isShow)
|
||
ROBottomInfoUI.SetActive(false);
|
||
}
|
||
else
|
||
return;
|
||
}
|
||
|
||
//如果需要显示
|
||
if (UIBottomInfoStatus)
|
||
{
|
||
//如果不需要下滑再上滑,且已经显示了,退出,否则就说明要更新内容
|
||
if (!UIBottomInfoHideFirst && ROBottomInfoUI.activeSelf)
|
||
return;
|
||
//如果需要先下滑再上滑
|
||
if (UIBottomInfoHideFirst)
|
||
{
|
||
//设定播放下滑动画的初始参数
|
||
if (ROBottomInfoUI.activeSelf)
|
||
{
|
||
_isAnimating = true;
|
||
_isShow = false;
|
||
_slideTime = 0f;
|
||
}
|
||
UIBottomInfoHideFirst = false;
|
||
}
|
||
else
|
||
{
|
||
//设定播放上滑动画的初始参数
|
||
_isAnimating = true;
|
||
_isShow = true;
|
||
_slideTime = 0f;
|
||
UpdateInfo();
|
||
ROBottomInfoUI.SetActive(true);
|
||
}
|
||
}
|
||
//如果需要关闭
|
||
else
|
||
{
|
||
//如果已经关闭了,退出
|
||
if (!ROBottomInfoUI.activeSelf)
|
||
return;
|
||
_isAnimating = true;
|
||
_isShow = false;
|
||
_slideTime = 0f;
|
||
}
|
||
|
||
}
|
||
public void Init()
|
||
{
|
||
ROBottomInfoUI.GetComponent<RectTransform>().anchoredPosition = _hiddenPosition;
|
||
ROBottomInfoUI.GetComponent<CanvasGroup>().alpha = 0;
|
||
_isAnimating = false;
|
||
|
||
ROBottomInfoUI.SetActive(false);
|
||
|
||
//需要根据玩家civ替换图标
|
||
foreach (Transform childAction in _actionArea.transform)
|
||
{
|
||
|
||
var timg = childAction.Find("Image").GetComponent<Image>();
|
||
var ttxt = childAction.Find("Text (TMP)").GetComponent<TextMeshProUGUI>();
|
||
var actionId = childAction.GetComponent<ActionIdMono>().ActionId;
|
||
//如果是根据文明变化的图标,就替换。否则,暂时就不动了,就交给默认设置好的
|
||
if (!Table.Instance.ActionDataAssets.GetActionInfo(actionId, out var actionInfo))
|
||
continue;
|
||
if (actionInfo == null)
|
||
continue;
|
||
if (actionInfo.VarientIcon)
|
||
{
|
||
timg.sprite = Table.Instance.QueryActionIconSprite(actionId,Main.MapData.PlayerMap.SelfPlayerData);
|
||
//timg.SetNativeSize();
|
||
//childAction.Find("Image").localScale = new Vector3(0.3f, 0.3f, 0.3f);
|
||
//childAction.Find("Image").localPosition = new Vector3(0f, -40f, 0f);
|
||
}
|
||
if (actionId.ActionType == CommonActionType.BuildWonder)
|
||
{
|
||
Table.Instance.GridAndResourceDataAssets.GetWonderInfoByType(actionId.WonderType,
|
||
_mapData.PlayerMap.SelfPlayerData,out var c);
|
||
timg.sprite = c.Sprite;
|
||
|
||
|
||
MultilingualManager.Instance.SetUIText(ttxt, c.Name);
|
||
//childAction.Find("Image").localScale = new Vector3(0.2f, 0.2f, 0.2f);
|
||
//childAction.Find("Image").localPosition = new Vector3(0f, -130f, 0f);
|
||
}
|
||
}
|
||
//监听所有的Action按钮
|
||
ActionAreaClickHandler();
|
||
_closeButton.GetComponent<Button>().onClick.AddListener(SetBottomInfoHide);
|
||
}
|
||
|
||
//更新预览框的内容
|
||
public void UpdateInfo()
|
||
{
|
||
foreach (Transform child in _unitPreviewArea.transform)
|
||
GameObject.Destroy(child.gameObject);
|
||
foreach (Transform child in _gridPreviewArea.transform)
|
||
GameObject.Destroy(child.gameObject);
|
||
foreach (Transform child in _cityPreviewArea.transform)
|
||
GameObject.Destroy(child.gameObject);
|
||
|
||
//如果预览的是grid或者city
|
||
if (UIBottomInfoIsGrid && Main.MapData.GridMap.GetGridDataByGid(UIBottomInfoStatusObjectId,out var gridData))
|
||
{
|
||
//现获取对应的playerData
|
||
Main.MapData.GetPlayerDataByTerritoryGridId(UIBottomInfoStatusObjectId, out var player);
|
||
|
||
//如果是city
|
||
if (Main.MapData.GetCityDataByGid(gridData.Id, out var cityData))
|
||
{
|
||
|
||
|
||
GameObject clone =
|
||
GameObject.Instantiate(MapRenderer.Instance.ROGridMap[UIBottomInfoStatusObjectId].GetROGrid() as GameObject);
|
||
clone.transform.SetParent(_cityPreviewArea.transform);
|
||
clone.transform.localPosition = new Vector3(0,15,0);
|
||
clone.transform.Find("SelectHighlight").gameObject.SetActive(false);
|
||
_cityBaseInfo.SetActive(true);
|
||
_gridBaseInfo.SetActive(false);
|
||
_unitBaseInfo.SetActive(false);
|
||
|
||
var param = new CommonActionParams(mapData:_mapData,playerData:_mapData.PlayerMap.SelfPlayerData,cityData:cityData,mainObjectType:MainObjectType.City);
|
||
HasAction = ActionLogicFactory.MainObjectCanShowAction(param,out ActionList);
|
||
|
||
Table.Instance.CivDataAssets.GetCityInfo(cityData.Name,out var cityInfo);
|
||
_cityTitle.GetComponent<TextMeshProUGUI>().text =
|
||
MultilingualManager.Instance.GetMultilingualText(uint.Parse(cityInfo.CityName)) + " Lv." + cityData.Level;
|
||
|
||
MultilingualManager.Instance.SetUIText(_cityDesc.GetComponent<TextMeshProUGUI>(),cityInfo.CityDescription);
|
||
|
||
|
||
//显示城市边界
|
||
HashSet<uint> gridList = new HashSet<uint>();
|
||
cityData.Territory.GetAllTerritoryArea(gridList);
|
||
foreach (var gid in gridList)
|
||
{
|
||
if (_mapData.GridMap.GetGridDataByGid(gid, out var grid))
|
||
grid.CityBorderRenderMark = true;
|
||
}
|
||
|
||
|
||
//text1 城市所属
|
||
//如果是有主领土
|
||
Table.Instance.CivDataAssets.GetCivInfo(player.PlayerCivId, out var civInfo);
|
||
MultilingualManager.Instance.SetUIText(
|
||
_cityBaseInfo.transform.Find("DataInfo/Title1").GetComponent<TextMeshProUGUI>(), civInfo.CivName);
|
||
//如果是自己的城市
|
||
if (player.Id == _mapData.PlayerMap.SelfPlayerData.Id)
|
||
{
|
||
//text2 每回合收入
|
||
_cityBaseInfo.transform.Find("DataInfo/Title2").GetComponent<TextMeshProUGUI>().text = "+" + Main.CityLogic.GetCityStarsPerTurn(_mapData,cityData) + " 每回合";
|
||
|
||
//text3 人口情况
|
||
_cityBaseInfo.transform.Find("DataInfo/Title3").GetComponent<TextMeshProUGUI>().text = "人口 " + _mapData.GetUnitCount(cityData.Id) + "/" + cityData.Level;
|
||
//text4 征税所情况
|
||
int pp = 0;
|
||
if (cityData.Workshop) pp++;
|
||
pp += cityData.ParkCount;
|
||
_cityBaseInfo.transform.Find("DataInfo/Title4").GetComponent<TextMeshProUGUI>().text = "征税所 " + pp + " 个";
|
||
//text5 联通情况
|
||
if (cityData.IsCapital)
|
||
_cityBaseInfo.transform.Find("DataInfo/Title5").GetComponent<TextMeshProUGUI>().text = "首都城市";
|
||
else if (cityData.IsConnectedCapital)
|
||
_cityBaseInfo.transform.Find("DataInfo/Title5").GetComponent<TextMeshProUGUI>().text = "已联通首都贸易";
|
||
else
|
||
_cityBaseInfo.transform.Find("DataInfo/Title5").GetComponent<TextMeshProUGUI>().text = "未联通首都贸易";
|
||
|
||
//text6 奢侈品情况
|
||
_cityBaseInfo.transform.Find("DataInfo/Title6").GetComponent<TextMeshProUGUI>().text = "奢侈品 " + cityData.ParkCount + " 种";
|
||
|
||
_cityBaseInfo.transform.Find("AdviseInfo/Text").GetComponent<TextMeshProUGUI>().text = "<color=yellow>经济顾问建议:</color>" + "获得城市经验提升城市等级后,就能提高人口上限并获得更多回合金币。";
|
||
}
|
||
//如果是敌方的城市
|
||
else
|
||
{
|
||
_cityBaseInfo.transform.Find("DataInfo/Title2").GetComponent<TextMeshProUGUI>().text = "-";
|
||
_cityBaseInfo.transform.Find("DataInfo/Title3").GetComponent<TextMeshProUGUI>().text = "-";
|
||
_cityBaseInfo.transform.Find("DataInfo/Title4").GetComponent<TextMeshProUGUI>().text = "-";
|
||
_cityBaseInfo.transform.Find("DataInfo/Title5").GetComponent<TextMeshProUGUI>().text = "-";
|
||
_cityBaseInfo.transform.Find("DataInfo/Title6").GetComponent<TextMeshProUGUI>().text = "-";
|
||
_cityBaseInfo.transform.Find("AdviseInfo/Text").GetComponent<TextMeshProUGUI>().text = "<color=yellow>军事顾问建议:</color>" + "攻下敌方城市,将富庶之地纳入自己的领土吧!";
|
||
}
|
||
|
||
|
||
|
||
}
|
||
|
||
//如果是grid
|
||
else
|
||
{
|
||
GameObject clone =
|
||
GameObject.Instantiate(MapRenderer.Instance.ROGridMap[UIBottomInfoStatusObjectId].GetROGrid() as GameObject);
|
||
clone.transform.SetParent(_gridPreviewArea.transform);
|
||
clone.transform.localPosition = new Vector3(0,15,0);
|
||
clone.transform.Find("SelectHighlight").gameObject.SetActive(false);
|
||
_cityBaseInfo.SetActive(false);
|
||
_gridBaseInfo.SetActive(true);
|
||
_unitBaseInfo.SetActive(false);
|
||
|
||
|
||
var param = new CommonActionParams(mapData:_mapData,_mapData.PlayerMap.SelfPlayerData,gridData:gridData,mainObjectType:MainObjectType.Grid);
|
||
HasAction = ActionLogicFactory.MainObjectCanShowAction(param,out ActionList);
|
||
string[] showText = Table.Instance.tileInfo(gridData);
|
||
_gridTitle.GetComponent<TextMeshProUGUI>().text = showText[0];
|
||
_gridDesc.GetComponent<TextMeshProUGUI>().text = showText[1];
|
||
|
||
_gridBaseInfo.transform.Find("AdviseInfo/Text").GetComponent<TextMeshProUGUI>().text = "<color=yellow>生产顾问建议:</color>" + showText[2];
|
||
|
||
|
||
|
||
//text1 城市
|
||
//如果是有主领土
|
||
if (player != null)
|
||
{
|
||
Table.Instance.CivDataAssets.GetCivInfo(player.PlayerCivId, out var civInfo);
|
||
MultilingualManager.Instance.SetUIText(
|
||
_gridBaseInfo.transform.Find("DataInfo/Title1").GetComponent<TextMeshProUGUI>(), civInfo.CivName);
|
||
|
||
}
|
||
//如果是无主领土
|
||
else
|
||
_gridBaseInfo.transform.Find("DataInfo/Title1").GetComponent<TextMeshProUGUI>().text = "-";
|
||
|
||
|
||
//text2 地貌
|
||
_gridBaseInfo.transform.Find("DataInfo/Title2").GetComponent<TextMeshProUGUI>().text =
|
||
gridData.Terrain switch
|
||
{
|
||
TerrainType.Land => "陆地",
|
||
TerrainType.ShallowSea => "浅海",
|
||
TerrainType.DeepSea => "深海",
|
||
_ => "外太空"
|
||
};
|
||
if(gridData.Feature == TerrainFeature.Mountain)
|
||
_gridBaseInfo.transform.Find("DataInfo/Title2").GetComponent<TextMeshProUGUI>().text +=
|
||
",山脉";
|
||
if(gridData.Feature == TerrainFeature.Road)
|
||
_gridBaseInfo.transform.Find("DataInfo/Title2").GetComponent<TextMeshProUGUI>().text +=
|
||
",道路";
|
||
if(gridData.Vegetation == Vegetation.Trees)
|
||
_gridBaseInfo.transform.Find("DataInfo/Title2").GetComponent<TextMeshProUGUI>().text +=
|
||
",树林";
|
||
//text3 建筑
|
||
//奇观要特殊处理
|
||
if (gridData.Resource == ResourceType.Wonder)
|
||
{
|
||
string wonderName = Table.Instance.GridAndResourceDataAssets.GetWonderName(gridData.Wonder,player);
|
||
MultilingualManager.Instance.SetUIText(_gridBaseInfo.transform.Find("DataInfo/Title3").GetComponent<TextMeshProUGUI>(), wonderName);
|
||
_gridTitle.GetComponent<TextMeshProUGUI>().text = _gridBaseInfo.transform.Find("DataInfo/Title3").GetComponent<TextMeshProUGUI>().text;
|
||
_gridDesc.GetComponent<TextMeshProUGUI>().text = "这是一座凝聚智慧与信仰、跨越时空与文明的奇迹之作。";
|
||
}
|
||
else
|
||
{
|
||
//Debug.Log(Table.Instance.GridAndResourceDataAssets.GetResourceName(gridData.Resource));
|
||
MultilingualManager.Instance.SetUIText(_gridBaseInfo.transform.Find("DataInfo/Title3").GetComponent<TextMeshProUGUI>(),
|
||
Table.Instance.GridAndResourceDataAssets.GetResourceName(gridData.Resource));
|
||
}
|
||
|
||
//处理有level的建筑
|
||
if (gridData.Resource == ResourceType.Windmill
|
||
|| gridData.Resource == ResourceType.Sawmill
|
||
|| gridData.Resource == ResourceType.Forge
|
||
|| gridData.Resource == ResourceType.Market
|
||
|| gridData.Resource == ResourceType.Temple
|
||
|| gridData.Resource == ResourceType.ForestTemple
|
||
|| gridData.Resource == ResourceType.WaterTemple
|
||
||gridData.Resource == ResourceType.MountainTemple)
|
||
{
|
||
_gridBaseInfo.transform.Find("DataInfo/Title3").GetComponent<TextMeshProUGUI>().text += " Lv." + gridData.buildingLevel + "/8";
|
||
_gridTitle.GetComponent<TextMeshProUGUI>().text += " Lv." + gridData.buildingLevel + "/8";
|
||
}
|
||
|
||
//text4 资源
|
||
_gridBaseInfo.transform.Find("DataInfo/Title4").GetComponent<TextMeshProUGUI>().text =
|
||
gridData.Resource switch
|
||
{
|
||
ResourceType.Fish => "渔产",
|
||
ResourceType.Starfish => "鲸鱼",
|
||
ResourceType.Animal => "动物",
|
||
ResourceType.Fruit => "蔬果",
|
||
ResourceType.Metal => "矿产",
|
||
ResourceType.Crop => "庄稼",
|
||
_ => "-"
|
||
};
|
||
|
||
|
||
}
|
||
_actionInfo.SetActive(HasAction);
|
||
if(HasAction)
|
||
GenerateActionOption();
|
||
}
|
||
//如果是unit
|
||
else
|
||
{
|
||
Main.MapData.UnitMap.GetUnitDataByUnitId(UIBottomInfoStatusObjectId,out var unitData);
|
||
//筹备unit预览格子
|
||
GameObject clone = GameObject.Instantiate(MapRenderer.Instance.ROUnitMap[UIBottomInfoStatusObjectId].GetROUnit() as GameObject);
|
||
clone.transform.SetParent(_unitPreviewArea.transform);
|
||
clone.transform.localPosition = new Vector3(0,5,0);
|
||
clone.transform.localScale = new Vector3(4,4,4);
|
||
clone.transform.Find("Canvas").gameObject.SetActive(false);
|
||
clone.transform.Find("AttackHighlight").gameObject.SetActive(false);
|
||
clone.transform.Find("SelectHighlight").gameObject.SetActive(false);
|
||
clone.transform.Find("Defense").gameObject.SetActive(false);
|
||
clone.transform.Find("SuperDefense").gameObject.SetActive(false);
|
||
_cityBaseInfo.SetActive(false);
|
||
_gridBaseInfo.SetActive(false);
|
||
_unitBaseInfo.SetActive(true);
|
||
_skillInfo.SetActive(true);
|
||
|
||
|
||
|
||
var param = new CommonActionParams(mapData:_mapData,playerData:_mapData.PlayerMap.SelfPlayerData,unitData:unitData,mainObjectType:MainObjectType.Unit);
|
||
HasAction = ActionLogicFactory.MainObjectCanShowAction(param, out ActionList);
|
||
|
||
_actionInfo.SetActive(HasAction);
|
||
if(HasAction)
|
||
GenerateActionOption();
|
||
string[] showText = Table.Instance.unitInfo(unitData);
|
||
|
||
|
||
if (unitData.Veteran) showText[0] += "(老兵)";
|
||
else if (!Table.Instance.QueryUnitHasSkill(unitData.UnitType, SkillType.STATIC))
|
||
showText[0] += " " + unitData.Exp + "/3";
|
||
_unitTitle.GetComponent<TextMeshProUGUI>().text = showText[0];
|
||
_unitDesc.GetComponent<TextMeshProUGUI>().text = showText[1];
|
||
_unitBaseInfo.transform.Find("AdviseInfo/Text").GetComponent<TextMeshProUGUI>().text = "<color=yellow>军事顾问建议:</color>" + showText[2];
|
||
_unitBaseInfo.transform.Find("DataInfo/Title1").GetComponent<TextMeshProUGUI>().text = unitData.Health + "/" + unitData.GetMaxHealth();
|
||
_unitBaseInfo.transform.Find("DataInfo/Title2").GetComponent<TextMeshProUGUI>().text = unitData.GetAttackShowString(_mapData);
|
||
_unitBaseInfo.transform.Find("DataInfo/Title3").GetComponent<TextMeshProUGUI>().text = unitData.GetDefenseShowString(_mapData);
|
||
_unitBaseInfo.transform.Find("DataInfo/Title4").GetComponent<TextMeshProUGUI>().text = " " + unitData.Exp + "/3";
|
||
_unitBaseInfo.transform.Find("DataInfo/Title5").GetComponent<TextMeshProUGUI>().text = unitData.GetMoveRange().ToString();
|
||
_unitBaseInfo.transform.Find("DataInfo/Title6").GetComponent<TextMeshProUGUI>().text = unitData.GetAttackRange().ToString();
|
||
|
||
|
||
//处理Skillinfo
|
||
var skillSet = new HashSet<SkillType>();
|
||
foreach (var skill in unitData.Skills)
|
||
skillSet.Add(skill.GetSkillType());
|
||
|
||
int rk = 0;
|
||
foreach (Transform child in _skillInfo.transform)
|
||
{
|
||
child.gameObject.SetActive(false);
|
||
var skillMono = child.GetComponent<SkillIdMono>();
|
||
if (skillMono == null) continue;
|
||
if (skillSet.Contains(skillMono.SkillTpe))
|
||
{
|
||
child.gameObject.SetActive(true);
|
||
var rect = child.GetComponent<RectTransform>();
|
||
if (rect != null)
|
||
rect.anchoredPosition = new Vector2(50 + rk * 60, -35);
|
||
rk++;
|
||
}
|
||
}
|
||
|
||
if (rk == 0)
|
||
{
|
||
_skillInfo.SetActive(false);
|
||
var rect = _unitBaseInfo.transform.Find("AdviseInfo").GetComponent<RectTransform>();
|
||
if (rect != null)
|
||
{
|
||
var tt = rect.anchoredPosition;
|
||
tt.y += 70;
|
||
rect.anchoredPosition = tt;
|
||
}
|
||
|
||
}
|
||
|
||
|
||
}
|
||
|
||
//更新Debug模块的显示
|
||
UpdateDebugInfo();
|
||
|
||
}
|
||
|
||
//让每个action挂一个点击监听事件
|
||
public void ActionAreaClickHandler()
|
||
{
|
||
ActionClickedEvent[] items = _actionArea.GetComponentsInChildren<ActionClickedEvent>(true);//这里设为true,会遍历所有inactive的对象
|
||
|
||
foreach (ActionClickedEvent item in items)
|
||
{
|
||
item.OnItemClicked += ActionAreaClicked;
|
||
}
|
||
}
|
||
|
||
|
||
//处理一个action被点击后的情况
|
||
public void ActionAreaClicked(GameObject clickedItem)
|
||
{
|
||
|
||
CommonActionId fakeActionId = clickedItem.GetComponent<ActionIdMono>().ActionId;
|
||
//如果钱不够,退出
|
||
if (Table.Instance.QueryActionCost(fakeActionId) > Main.MapData.PlayerMap.SelfPlayerData.PlayerWealth)
|
||
return;
|
||
//如果没科技,退出
|
||
if (!Main.MapData.PlayerMap.SelfPlayerData.TechTree.CheckActionCan(fakeActionId))
|
||
return;
|
||
UnitData unitData = null;
|
||
CityData cityData = null;
|
||
GridData gridData = null;
|
||
MainObjectType mainObjectType = MainObjectType.None;
|
||
if (UIBottomInfoIsGrid)
|
||
{
|
||
mainObjectType = MainObjectType.Grid;
|
||
|
||
//如果是训练单位
|
||
if (fakeActionId.ActionType == CommonActionType.TrainUnit)
|
||
{
|
||
//如果是城市训练单位
|
||
if(Main.MapData.GetCityDataByGid(UIBottomInfoStatusObjectId,out cityData))
|
||
{
|
||
//城市满人口
|
||
if (Main.MapData.CheckIfCityFullPopulation(cityData)) return;
|
||
mainObjectType = MainObjectType.City;
|
||
}
|
||
else if (Main.MapData.GetCityDataByTerritoryGid(UIBottomInfoStatusObjectId, out cityData))
|
||
{
|
||
//城市满人口
|
||
if (Main.MapData.CheckIfCityFullPopulation(cityData)) return;
|
||
}
|
||
}
|
||
|
||
Main.MapData.GridMap.GetGridDataByGid(UIBottomInfoStatusObjectId,out gridData);
|
||
}
|
||
else
|
||
{
|
||
Main.MapData.UnitMap.GetUnitDataByUnitId(UIBottomInfoStatusObjectId,out unitData);
|
||
mainObjectType = MainObjectType.Unit;
|
||
}
|
||
CommonActionParams actionParams = new CommonActionParams(_mapData,
|
||
Main.MapData.PlayerMap.SelfPlayerData,unitData,cityData,gridData,null,null,mainObjectType);
|
||
|
||
//Debug.Log($"{actionId.ActionType},{actionId.WonderType},{actionId.ResourceType},{actionId.FeatureType},{actionId.UnitType},{actionId.Vegetation}");
|
||
//如果成功执行,隐藏当前面板
|
||
if (ActionLogicFactory.GetActionLogic(fakeActionId).Execute(actionParams))
|
||
{
|
||
SetBottomInfoHide();
|
||
_main.MapInteractionLogic.CancelAllHighlight();
|
||
}
|
||
|
||
//Debug.Log($"父对象收到通知:{clickedItem.name} 被点击了");
|
||
|
||
}
|
||
|
||
//生产选项板的若干选项
|
||
public void GenerateActionOption()
|
||
{
|
||
int rk = 0;
|
||
|
||
foreach (Transform child in _actionArea.transform)
|
||
{
|
||
CommonActionId tActionId = child.GetComponent<ActionIdMono>().ActionId;
|
||
child.gameObject.SetActive(false);
|
||
foreach (var actionLogic in ActionList){
|
||
if (actionLogic.CheckEqualActionId(tActionId))
|
||
{
|
||
child.gameObject.SetActive(true);
|
||
RectTransform rectTransform = child.GetComponent<RectTransform>();
|
||
if (rectTransform != null)
|
||
{
|
||
float x = (rk % 4) * 110;
|
||
float y = (rk / 4) * (-130);
|
||
rectTransform.anchoredPosition = new Vector2(x, y);
|
||
}
|
||
|
||
rk++;
|
||
TextMeshProUGUI textUIComponent = child.gameObject.transform.Find("costNumber")
|
||
.GetComponent<TextMeshProUGUI>();
|
||
Image starImage = child.gameObject.transform.Find("star").GetComponent<Image>();
|
||
starImage.gameObject.SetActive(true);
|
||
textUIComponent.gameObject.SetActive(true);
|
||
|
||
Image backImage = child.gameObject.GetComponent<Image>();
|
||
textUIComponent.color = Color.white;
|
||
backImage.sprite = ActionBGAvailable;
|
||
|
||
//如果是city的action
|
||
if (UIBottomInfoIsGrid)
|
||
{
|
||
//如果科技未解锁
|
||
if (!Main.MapData.PlayerMap.SelfPlayerData.TechTree.CheckActionCan(tActionId))
|
||
{
|
||
starImage.gameObject.SetActive(false);
|
||
textUIComponent.gameObject.SetActive(false);
|
||
backImage.sprite = ActionBGUnavailable;
|
||
}
|
||
|
||
CityData cityData;
|
||
//如果是一个满员城市在grid上生产单位,要额外判断一下这个是不是生产单位的行为
|
||
if (!Main.MapData.GetCityDataByGid(UIBottomInfoStatusObjectId,out cityData)){
|
||
if(Main.MapData.GetCityDataByTerritoryGid(UIBottomInfoStatusObjectId,out cityData)
|
||
&& Main.MapData.CheckIfCityFullPopulation(cityData)
|
||
&& tActionId.ActionType == CommonActionType.TrainUnit)
|
||
{
|
||
textUIComponent.color = Color.gray;
|
||
backImage.sprite = ActionBGUnavailable;
|
||
starImage.gameObject.SetActive(false);
|
||
textUIComponent.gameObject.SetActive(false);
|
||
}
|
||
}
|
||
//如果是一个满员城市在市中心生产单位(不用在判断是不是生产单位了)
|
||
else if (Main.MapData.CheckIfCityFullPopulation(cityData))
|
||
{
|
||
textUIComponent.color = Color.gray;
|
||
backImage.sprite = ActionBGUnavailable;
|
||
starImage.gameObject.SetActive(false);
|
||
textUIComponent.gameObject.SetActive(false);
|
||
}
|
||
//如果钱不够
|
||
if (Main.MapData.PlayerMap.SelfPlayerData.PlayerWealth < actionLogic.GetCost())
|
||
{
|
||
textUIComponent.color = Color.red;
|
||
backImage.sprite = ActionBGExpensive;
|
||
}
|
||
break;
|
||
}
|
||
//如果是unit的action
|
||
else
|
||
{
|
||
starImage.gameObject.SetActive(false);
|
||
textUIComponent.gameObject.SetActive(false);
|
||
//如果是变形为其他type的单位
|
||
if (tActionId.UnitType !=UnitType.None)
|
||
{
|
||
starImage.gameObject.SetActive(true);
|
||
textUIComponent.gameObject.SetActive(true);
|
||
if (Main.MapData.PlayerMap.SelfPlayerData.PlayerWealth < actionLogic.GetCost())
|
||
{
|
||
textUIComponent.color = Color.red;
|
||
backImage.sprite = ActionBGExpensive;
|
||
}
|
||
}
|
||
|
||
}
|
||
|
||
}
|
||
}
|
||
}
|
||
|
||
//如果数量小于3个,要居中显示
|
||
if (rk < 4)
|
||
{
|
||
int rkk = 0;
|
||
foreach (Transform child in _actionArea.transform)
|
||
{
|
||
if (child.gameObject.activeSelf)
|
||
{
|
||
|
||
RectTransform rectTransform = child.GetComponent<RectTransform>();
|
||
if (rectTransform != null)
|
||
{
|
||
float x = rkk * 110 + (4 - rk) * 55f;
|
||
rectTransform.anchoredPosition = new Vector2(x, 0);
|
||
}
|
||
rkk++;
|
||
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
//隐藏BottomInfoHid
|
||
public void SetBottomInfoHide()
|
||
{
|
||
UIBottomInfoStatus = false;
|
||
}
|
||
|
||
public void SetBottomInfoShowGrid(uint gridId)
|
||
{
|
||
UIBottomInfoHideFirst = UIBottomInfoStatus;
|
||
UIBottomInfoStatus = true;
|
||
UIBottomInfoIsGrid = true;
|
||
UIBottomInfoStatusObjectId = gridId;
|
||
}
|
||
|
||
public void SetBottomInfoShowUnit(uint unitId)
|
||
{
|
||
UIBottomInfoHideFirst = UIBottomInfoStatus;
|
||
UIBottomInfoStatus = true;
|
||
UIBottomInfoIsGrid = false;
|
||
UIBottomInfoStatusObjectId = unitId;
|
||
}
|
||
|
||
//更新Debug模块的信息
|
||
public void UpdateDebugInfo()
|
||
{
|
||
if (!DebugCenter.Instance.DebugMode)
|
||
return;
|
||
if (_mapData == null)
|
||
return;
|
||
//如果是城市格子
|
||
if (UIBottomInfoIsGrid && _mapData.GetCityDataByGid(UIBottomInfoStatusObjectId,out var city))
|
||
{
|
||
_debugGrid.SetActive(false);
|
||
_debugUnit.SetActive(false);
|
||
_debugCity.SetActive(true);
|
||
|
||
}
|
||
//如果是非城市格子
|
||
else if (UIBottomInfoIsGrid)
|
||
{
|
||
_debugGrid.SetActive(true);
|
||
_debugUnit.SetActive(false);
|
||
_debugCity.SetActive(false);
|
||
if (!Main.MapData.GridMap.GetGridDataByGid(UIBottomInfoStatusObjectId, out var gridData))
|
||
return;
|
||
_debugGrid.transform.Find("BuildingLevelValue").GetComponent<TextMeshProUGUI>().text = gridData.buildingLevel.ToString();
|
||
|
||
}
|
||
//如果是unit
|
||
else{
|
||
_debugGrid.SetActive(false);
|
||
_debugUnit.SetActive(true);
|
||
_debugCity.SetActive(false);
|
||
|
||
// 获取单位数据
|
||
if (!Main.MapData.UnitMap.GetUnitDataByUnitId(UIBottomInfoStatusObjectId, out var unitData))
|
||
return;
|
||
|
||
// 填充单位类型信息
|
||
_debugUnit.transform.Find("UnitTypeValue").GetComponent<TextMeshProUGUI>().text = unitData.UnitType.ToString();
|
||
|
||
// 填充巨人类型信息
|
||
_debugUnit.transform.Find("GiantTypeValue").GetComponent<TextMeshProUGUI>().text = unitData.GiantType.ToString();
|
||
|
||
// 填充单位ID
|
||
_debugUnit.transform.Find("UnitIdValue").GetComponent<TextMeshProUGUI>().text = unitData.Id.ToString();
|
||
|
||
// 填充AP值
|
||
_debugUnit.transform.Find("APValue").GetComponent<TextMeshProUGUI>().text = unitData.AP.ToString();
|
||
|
||
// 填充MP值
|
||
_debugUnit.transform.Find("MPValue").GetComponent<TextMeshProUGUI>().text = unitData.MP.ToString();
|
||
|
||
// 填充携带单位类型信息
|
||
if (_debugUnit.transform.Find("CarryUnitTypeValue") != null)
|
||
{
|
||
_debugUnit.transform.Find("CarryUnitTypeValue").GetComponent<TextMeshProUGUI>().text =
|
||
unitData.CarryUnitType != UnitType.None ? unitData.CarryUnitType.ToString() : "None";
|
||
}
|
||
|
||
// 填充携带巨人类型信息
|
||
if (_debugUnit.transform.Find("CarryGiantTypeValue") != null)
|
||
{
|
||
_debugUnit.transform.Find("CarryGiantTypeValue").GetComponent<TextMeshProUGUI>().text =
|
||
unitData.CarryGiantType != GiantType.None ? unitData.CarryGiantType.ToString() : "None";
|
||
}
|
||
|
||
// 填充携带单位经验值
|
||
if (_debugUnit.transform.Find("CarryExpValue") != null)
|
||
{
|
||
_debugUnit.transform.Find("CarryExpValue").GetComponent<TextMeshProUGUI>().text =
|
||
unitData.CarryUnitType != UnitType.None ? unitData.CarryExp.ToString() : "0";
|
||
}
|
||
|
||
// 填充携带单位老兵状态
|
||
if (_debugUnit.transform.Find("CarryVeteranValue") != null)
|
||
{
|
||
_debugUnit.transform.Find("CarryVeteranValue").GetComponent<TextMeshProUGUI>().text =
|
||
unitData.CarryUnitType != UnitType.None ? unitData.CarryVeteran.ToString() : "False";
|
||
}
|
||
|
||
// 获取技能组
|
||
Transform skillGroup = _debugUnit.transform.Find("SkillGroup");
|
||
|
||
// 初始化所有技能文本为空
|
||
for (int i = 0; i < 21; i++)
|
||
{
|
||
Transform skillTransform = skillGroup.Find($"Skill ({i})");
|
||
if (skillTransform != null)
|
||
{
|
||
skillTransform.GetComponent<TextMeshProUGUI>().text = "";
|
||
}
|
||
}
|
||
|
||
// 填充技能信息
|
||
int skillIndex = 0;
|
||
foreach (var skill in unitData.Skills)
|
||
{
|
||
if (skillIndex >= 9) break; // 最多显示9个技能
|
||
|
||
Transform skillTransform = skillGroup.Find($"Skill ({skillIndex})");
|
||
if (skillTransform != null)
|
||
{
|
||
// 获取技能名称
|
||
string skillName = skill.GetSkillType().ToString();
|
||
|
||
skillTransform.GetComponent<TextMeshProUGUI>().text = skillName;
|
||
}
|
||
|
||
skillIndex++;
|
||
}
|
||
}
|
||
}
|
||
|
||
// 根据索引执行对应的操作按钮点击
|
||
public void ExecuteActionButtonByIndex(int index)
|
||
{
|
||
if (!ROBottomInfoUI.activeSelf || !HasAction)
|
||
return;
|
||
|
||
// 获取所有激活的操作按钮
|
||
List<GameObject> activeButtons = new List<GameObject>();
|
||
|
||
foreach (Transform child in _actionArea.transform)
|
||
{
|
||
if (child.gameObject.activeSelf)
|
||
{
|
||
activeButtons.Add(child.gameObject);
|
||
}
|
||
}
|
||
|
||
// 检查索引是否有效
|
||
if (index >= 0 && index < activeButtons.Count)
|
||
{
|
||
GameObject targetButton = activeButtons[index];
|
||
|
||
// 直接调用ActionAreaClicked方法,传入目标按钮
|
||
ActionAreaClicked(targetButton);
|
||
}
|
||
}
|
||
}
|