1265 lines
55 KiB
C#
1265 lines
55 KiB
C#
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using Logic;
|
||
using Logic.Action;
|
||
using Logic.CrashSight;
|
||
using UnityEngine;
|
||
using TMPro; // 如果使用TextMeshPro
|
||
using RuntimeData;
|
||
using Logic.Multilingual;
|
||
using Logic.Skill;
|
||
using MongoDB.Driver.Linq;
|
||
using TH1_Core.Events;
|
||
using TH1_Core.Managers;
|
||
using TH1_Logic.Core;
|
||
using TH1_UI.HintUI;
|
||
using TH1Renderer;
|
||
using TH1Resource;
|
||
using UI;
|
||
using UI.HintUI;
|
||
using Unity.VisualScripting;
|
||
using UnityEditor;
|
||
using UnityEngine.UIElements;
|
||
using Button = UnityEngine.UI.Button;
|
||
using Image = UnityEngine.UI.Image;
|
||
|
||
public class BottomInfoUI// : MonoBehaviour
|
||
{
|
||
public GameObject ROBottomInfoUI;
|
||
|
||
public GameObject
|
||
_skillInfo;
|
||
private GameObject
|
||
_unitBaseInfo,
|
||
_gridBaseInfo,
|
||
_cityBaseInfo,
|
||
_playerBaseInfo,
|
||
_playerInfoAvatar,
|
||
_gridCamera,
|
||
_cityCamera,
|
||
_actionInfo,
|
||
_unitPreviewArea, //grid/unit预览框
|
||
_gridPreviewArea,
|
||
_cityPreviewArea,
|
||
_unitTitle,
|
||
_unitDesc,
|
||
_gridTitle,
|
||
_gridDesc,
|
||
_cityTitle,
|
||
_cityDesc,
|
||
_closeButton,
|
||
_actionArea,
|
||
_debugGrid,
|
||
_debugUnit,
|
||
_debugCity;
|
||
|
||
//public Tilemap borderTilemap;
|
||
//public GameObject unitPrefab;
|
||
//private GameObject bottomInfoRenderedUnit;//用来存放角色预览的临时对象
|
||
|
||
//缓存玩家的金币情况,用来判断是否要刷新bottominfo界面
|
||
private int _playerWealthCache;
|
||
//动画控制数据
|
||
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 BottomInfoUI()
|
||
{
|
||
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;
|
||
_playerBaseInfo = ROBottomInfoUI.transform.Find("InfoGroup/PlayerBaseInfo").gameObject;
|
||
_playerInfoAvatar = ROBottomInfoUI.transform.Find("InfoGroup/PlayerBaseInfo/Avatar").gameObject;
|
||
_gridCamera = ROBottomInfoUI.transform.Find("InfoGroup/GridBaseInfo/PreviewArea/TileMapPreviewCamera").gameObject;
|
||
_cityCamera = ROBottomInfoUI.transform.Find("InfoGroup/CityBaseInfo/PreviewArea/TileMapPreviewCamera").gameObject;
|
||
_actionInfo = ROBottomInfoUI.transform.Find("InfoGroup/ActionInfo").gameObject;
|
||
_skillInfo = ROBottomInfoUI.transform.Find("InfoGroup/UnitBaseInfo/SkillIconArea").gameObject;
|
||
_closeButton = ROBottomInfoUI.transform.Find("CloseButton").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").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 (Main.MapData == null) return;
|
||
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 (_playerWealthCache != Main.MapData.PlayerMap.SelfPlayerData.PlayerWealth)
|
||
{
|
||
_playerWealthCache = Main.MapData.PlayerMap.SelfPlayerData.PlayerWealth;
|
||
UpdateInfo();
|
||
}
|
||
//如果不需要下滑再上滑,且已经显示了,退出,否则就说明要更新内容
|
||
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);
|
||
|
||
//处理hint trigger,然后需要根据玩家civ替换图标
|
||
foreach (Transform childAction in _actionArea.transform)
|
||
{
|
||
//step #0 获取基础信息
|
||
var timg = childAction.Find("Image").GetComponent<Image>();
|
||
var ttxt = childAction.Find("Text (TMP)").GetComponent<TextMeshProUGUI>();
|
||
var actionId = childAction.GetComponent<ActionIdMono>().ActionId;
|
||
var hintTrigger = childAction.GetComponent<HintTrigger>().DataProvider;
|
||
//step #1 处理hint trigger
|
||
hintTrigger.ActionIdData = actionId;
|
||
|
||
//step #2 处理需要根据文明替换资源的图标
|
||
//如果是根据文明变化的图标,就替换。否则,暂时就不动了,就交给默认设置好的
|
||
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,
|
||
Main.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.RemoveAllListeners();
|
||
_closeButton.GetComponent<Button>().onClick.AddListener(SetBottomInfoHide);
|
||
}
|
||
|
||
|
||
//更新Action模块的内容
|
||
public void UpdateInfoAction(bool show,List<ActionLogicBase> actionList)
|
||
{
|
||
if (!show)
|
||
{
|
||
_actionInfo.SetActive(false);
|
||
return;
|
||
}
|
||
|
||
_actionInfo.SetActive(true);
|
||
|
||
GenerateActionOption(actionList);
|
||
|
||
}
|
||
//更新player模块的内容
|
||
public void UpdateInfoPlayer(bool show,PlayerData player)
|
||
{
|
||
if (_playerBaseInfo == null || _playerInfoAvatar == null || _playerInfoAvatar == null)
|
||
{
|
||
LogSystem.LogError("UpdateInfoPlayer _playerBaseInfo _playerInfoAvatar _playerInfoAvatar is null");
|
||
return;
|
||
}
|
||
|
||
_playerBaseInfo.SetActive(true);
|
||
if (!show)
|
||
{
|
||
_playerInfoAvatar.SetActive(false);
|
||
_playerBaseInfo.transform.Find("NoMeetText")?.gameObject.SetActive(false);
|
||
return;
|
||
}
|
||
|
||
//处理未结识玩家的领土问题(不显示头像,显示一段文字)
|
||
if (!Main.MapData.PlayerMap.SelfPlayerData.MeetPlayers.Contains(player.Id))
|
||
{
|
||
_playerInfoAvatar.SetActive(false);
|
||
_playerBaseInfo.transform.Find("NoMeetText")?.gameObject.SetActive(true);
|
||
return;
|
||
}
|
||
_playerBaseInfo.transform.Find("NoMeetText")?.gameObject.SetActive(false);
|
||
_playerInfoAvatar.SetActive(true);
|
||
|
||
Table.Instance.PlayerDataAssets.GetPlayerInfo(player,out var info);
|
||
if (info == null)
|
||
{
|
||
LogSystem.LogError("UpdateInfoPlayer info is null");
|
||
return;
|
||
}
|
||
_playerInfoAvatar.transform.Find("ImageMask/ImageChar").GetComponent<Image>().sprite = info.LeaderIllustration;
|
||
var txt = _playerInfoAvatar.transform.Find("NameMask/Text").GetComponent<TextMeshProUGUI>();
|
||
MultilingualManager.Instance.SetUIText(txt,info.ForceName);
|
||
|
||
//绑定点击事件
|
||
_playerInfoAvatar.GetComponent<Button>()?.onClick.RemoveAllListeners();
|
||
_playerInfoAvatar.GetComponent<Button>()?.onClick.AddListener(() =>
|
||
{
|
||
var infoUI = new ShowUIInfoDiplomacy() { Pid = player.Id };
|
||
EventManager.Publish(infoUI);
|
||
SetBottomInfoHide();
|
||
});
|
||
|
||
|
||
}
|
||
public void UpdateInfoUnit(bool show,UnitData unit)
|
||
{
|
||
if (!show)
|
||
{
|
||
_unitBaseInfo.SetActive(false);
|
||
return;
|
||
}
|
||
|
||
_unitBaseInfo.SetActive(true);
|
||
_skillInfo.SetActive(true);
|
||
Main.MapData.GetPlayerDataByUnitId(unit.Id,out var playerData);
|
||
Table.Instance.UnitTypeDataAssets.GetUnitSprite(Main.MapData,unit, out var sprite);
|
||
//筹备unit预览格子
|
||
_unitPreviewArea.transform.Find("UnitImage").GetComponent<Image>().sprite = sprite;
|
||
|
||
string[] showText = Table.Instance.unitInfo(unit);
|
||
|
||
string tmpTitle = "";
|
||
string tmpDesc = "";
|
||
if (!Table.Instance.UnitTypeDataAssets.GetUnitTypeInfo(unit.UnitType, unit.GiantType,unit.UnitLevel, out var info))
|
||
{
|
||
LogSystem.LogError("BottomInfoUI can't find unittype dataasset");
|
||
return;
|
||
}
|
||
else
|
||
{
|
||
if (!uint.TryParse(info.Name,out var mul))
|
||
tmpTitle += info.Name;
|
||
else
|
||
tmpTitle += MultilingualManager.Instance.GetMultilingualText(mul);
|
||
|
||
if (!uint.TryParse(info.Desc,out var mul2))
|
||
tmpDesc += info.Desc;
|
||
else
|
||
tmpDesc += MultilingualManager.Instance.GetMultilingualText(mul2);
|
||
}
|
||
|
||
|
||
//如果是船上单位,要增加“(船内单位名)”
|
||
if (unit.GetSkill(SkillType.CARRY, out var _))
|
||
{
|
||
if (!Table.Instance.UnitTypeDataAssets.GetUnitTypeInfo(unit.CarryUnitType, unit.CarryGiantType,unit.CarryUnitLevel,
|
||
out var carryInfo))
|
||
{
|
||
LogSystem.LogError("BottomInfoUI can't find carryunittype dataasset");
|
||
return;
|
||
}
|
||
|
||
if (!uint.TryParse(carryInfo.Name,out var mul))
|
||
tmpTitle += "(" + carryInfo.Name + ")";
|
||
else
|
||
tmpTitle += "(" + MultilingualManager.Instance.GetMultilingualText(mul) + ")";
|
||
}
|
||
|
||
|
||
|
||
//如果是老兵 加上“已升级”
|
||
if (unit.Veteran) tmpTitle += "(已升级)";
|
||
else if (!unit.GetSkill(SkillType.STATIC,out var _))
|
||
tmpTitle += " " + unit.Exp + "/3";
|
||
if (unit.UnitType == UnitType.Giant)
|
||
tmpTitle += "Lv." +unit.UnitLevel;
|
||
|
||
//step #3 处理giantHint的特殊情况
|
||
var giantUpgradeHint = _unitBaseInfo.transform.Find("GiantUpgradeHint");
|
||
if (giantUpgradeHint != null)
|
||
{
|
||
if(unit.UnitType != UnitType.Giant)
|
||
giantUpgradeHint.gameObject.SetActive(false);
|
||
else
|
||
{
|
||
giantUpgradeHint.gameObject.SetActive(true);
|
||
var hint = giantUpgradeHint.GetComponent<HintTrigger>();
|
||
if(hint != null)
|
||
hint.DataProvider.GiantType = unit.GiantType;
|
||
}
|
||
}
|
||
|
||
|
||
//step #4 生成具体的每个unit信息栏目的文字信息
|
||
|
||
//MultilingualManager.Instance.SetUIText(_unitTitle.GetComponent<TextMeshProUGUI>(),info.Name);
|
||
//MultilingualManager.Instance.SetUIText(_unitDesc.GetComponent<TextMeshProUGUI>(),info.Desc);
|
||
_unitTitle.GetComponent<TextMeshProUGUI>().text = tmpTitle;
|
||
_unitDesc.GetComponent<TextMeshProUGUI>().text = tmpDesc;//showText[1];
|
||
_unitBaseInfo.transform.Find("AdviseInfo/Text").GetComponent<TextMeshProUGUI>().text = "<color=yellow>咲夜的建议:</color>" + showText[2];
|
||
_unitBaseInfo.transform.Find("DataInfo/Title1").GetComponent<TextMeshProUGUI>().text = unit.Health + "/" + unit.GetMaxHealth();
|
||
_unitBaseInfo.transform.Find("DataInfo/Title2").GetComponent<TextMeshProUGUI>().text = unit.GetAttackShowString(Main.MapData);
|
||
_unitBaseInfo.transform.Find("DataInfo/Title3").GetComponent<TextMeshProUGUI>().text = unit.GetDefenseShowString(Main.MapData);
|
||
|
||
_unitBaseInfo.transform.Find("DataInfo/Title4").GetComponent<TextMeshProUGUI>().text = " " + unit.Exp + "/3";
|
||
if (unit.GetSkill(SkillType.STATIC, out var _))
|
||
{
|
||
var txt = _unitBaseInfo.transform.Find("DataInfo/Title4").GetComponent<TextMeshProUGUI>();
|
||
txt.text = "-/-";
|
||
}
|
||
|
||
_unitBaseInfo.transform.Find("DataInfo/Title5").GetComponent<TextMeshProUGUI>().text = unit.GetMoveRange().ToString();
|
||
_unitBaseInfo.transform.Find("DataInfo/Title6").GetComponent<TextMeshProUGUI>().text = unit.GetAttackRange().ToString();
|
||
|
||
|
||
//Step #5 处理Skillinfo
|
||
int rk = 0;
|
||
//var skillSet = new HashSet<SkillType>();
|
||
//先把所有ui skill隐藏
|
||
foreach (Transform child in _skillInfo.transform)
|
||
child.gameObject.SetActive(false);
|
||
//遍历unit的每一个skii
|
||
foreach (var skill in unit.Skills)
|
||
{
|
||
|
||
foreach (Transform child in _skillInfo.transform)
|
||
{
|
||
var skillMono = child.GetComponent<SkillIdMono>();
|
||
if (skillMono == null) continue;
|
||
//如果找到一个ui skill和 unit.skill一致
|
||
if (skillMono.SkillTpe == skill.GetSkillType() && skill.ShowSkill)
|
||
{
|
||
child.gameObject.SetActive(true);
|
||
//设置叠层
|
||
child.Find("Level").gameObject.SetActive(false);
|
||
if (skill.Level > 0 || skill.ShowSkillLevel)
|
||
{
|
||
child.Find("Level")?.gameObject.SetActive(true);
|
||
var txt = child.Find("Level/Text")?.GetComponent<TextMeshProUGUI>();
|
||
if(txt != null)txt.text = skill.Level.ToString();
|
||
}
|
||
|
||
//设置持续时间标识
|
||
child.Find("Time").gameObject.SetActive(false);
|
||
if (skill.HasTimeLimit)
|
||
{
|
||
child.Find("Time")?.gameObject.SetActive(true);
|
||
var txt = child.Find("Time/Text")?.GetComponent<TextMeshProUGUI>();
|
||
if(txt != null)txt.text = skill.LastTime.ToString();
|
||
}
|
||
|
||
|
||
var rect = child.GetComponent<RectTransform>();
|
||
if (rect != null)
|
||
rect.anchoredPosition = new Vector2(50 + rk * 60, -35);
|
||
rk++;
|
||
//设置skill的hinttrigger
|
||
var skillHintTrigger = child.GetComponent<HintTrigger>();
|
||
if (skillHintTrigger != null)
|
||
{
|
||
skillHintTrigger.DataProvider.SkillTypeData = skillMono.SkillTpe;
|
||
skillHintTrigger.DataProvider.UnitType = unit.UnitType;
|
||
skillHintTrigger.DataProvider.GiantType = unit.GiantType;
|
||
skillHintTrigger.DataProvider.UnitLevel = unit.UnitLevel;
|
||
}
|
||
|
||
continue;
|
||
}
|
||
|
||
|
||
|
||
}
|
||
}
|
||
|
||
|
||
//Step #6 设置MissionDesc
|
||
|
||
GiantType giantType = unit.GiantType;
|
||
uint giantLevel = unit.UnitLevel;
|
||
var MissionObject = _unitBaseInfo.transform.Find("GiantMissionGroup").gameObject;
|
||
var MissionDesc = _unitBaseInfo.transform.Find("GiantMissionGroup/GiantMissionDesc/Text")
|
||
.GetComponent<TextMeshProUGUI>();
|
||
|
||
|
||
MissionObject.SetActive(unit.UnitType == UnitType.Giant && unit.UnitLevel < 3);
|
||
if (unit.UnitType == UnitType.Giant && playerData == Main.MapData.PlayerMap.SelfPlayerData)
|
||
{
|
||
if (!Table.Instance.HeroDataAssets.GetHeroInfo(giantType, out var heroInfo)) return;
|
||
if (heroInfo.TaskList.Count <= giantLevel) return;
|
||
if (!Main.MapData.PlayerMap.SelfPlayerData.PlayerHeroData.GetHeroTask(giantType, out var task)) return;
|
||
var param1 = task.LevelShowString();
|
||
var param2 = task.TargetLevelShowString();
|
||
var param3 = "";
|
||
if (task.SkillType != SkillType.NONE &&
|
||
Table.Instance.SkillDataAssets.GetSkillInfo(task.SkillType, out var skillInfo))
|
||
param3 = MultilingualManager.Instance.GetMultilingualText(uint.Parse(skillInfo.SkillName));
|
||
var taskDesc = heroInfo.TaskList[(int)giantLevel].Desc;
|
||
var taskFinishedDesc = Table.Instance.TextDataAssets.HeroTaskFinishedDesc;
|
||
if (task.IsForceFinished)
|
||
MultilingualManager.Instance.SetUIText(MissionDesc, taskFinishedDesc);
|
||
else
|
||
MultilingualManager.Instance.SetUIText(MissionDesc, taskDesc,
|
||
new List<string> { param1, param2, param3 });
|
||
}
|
||
else MissionObject.SetActive(false);
|
||
|
||
|
||
|
||
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;
|
||
}
|
||
|
||
}
|
||
}
|
||
//更新预览框的内容
|
||
|
||
public void UpdateInfoGrid(bool show,GridData grid)
|
||
{
|
||
if (!show)
|
||
{
|
||
_gridBaseInfo.SetActive(false);
|
||
return;
|
||
}
|
||
|
||
_gridBaseInfo.SetActive(true);
|
||
|
||
Main.MapData.GetPlayerDataByTerritoryGridId(grid.Id, out var player);
|
||
|
||
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);
|
||
SetLayerRecursively(clone, LayerMask.NameToLayer("Preview"));
|
||
_gridCamera.SetActive(true);
|
||
Timer.Instance.TimerRegister(_gridCamera, () => { _gridCamera.SetActive(false); }, 0.001f,"HideCamera");
|
||
|
||
|
||
//text0 title和desc
|
||
|
||
var title = _gridTitle.GetComponent<TextMeshProUGUI>();
|
||
var desc = _gridDesc.GetComponent<TextMeshProUGUI>();
|
||
|
||
|
||
string[] showText = Table.Instance.tileInfo(grid);
|
||
_gridBaseInfo.transform.Find("AdviseInfo/Text").GetComponent<TextMeshProUGUI>().text = "<color=yellow>咲夜的建议:</color>" + showText[2];
|
||
|
||
var resource = grid.Resource;
|
||
//处理隐藏没有科技情况下 metal、starfish、crop的情况
|
||
if (grid.Resource == ResourceType.Crop)
|
||
if (!Main.MapData.PlayerMap.SelfPlayerData.TechTree.CheckIfHasTech(TechType.Organization) &&
|
||
!Main.MapData.PlayerMap.SelfPlayerData.TechTree.CheckIfHasTech(TechType.Farming))
|
||
resource = ResourceType.None;
|
||
if (grid.Resource == ResourceType.Metal)
|
||
if (!Main.MapData.PlayerMap.SelfPlayerData.TechTree.CheckIfHasTech(TechType.Mining) &&
|
||
!Main.MapData.PlayerMap.SelfPlayerData.TechTree.CheckIfHasTech(TechType.Climbing))
|
||
resource = ResourceType.None;
|
||
if (grid.Resource == ResourceType.Starfish)
|
||
if (!Main.MapData.PlayerMap.SelfPlayerData.TechTree.CheckIfHasTech(TechType.Navigation) &&
|
||
!Main.MapData.PlayerMap.SelfPlayerData.TechTree.CheckIfHasTech(TechType.Sailing))
|
||
resource = ResourceType.None;
|
||
|
||
|
||
|
||
//用玩家看得到的resource来获取rsourceInfo
|
||
if (!Table.Instance.GridAndResourceDataAssets.GetResourceInfo(resource, out var resourceInfo))
|
||
{
|
||
LogSystem.LogError("BottomUIInfo Cant' find resource Info!!!!");
|
||
return;
|
||
}
|
||
|
||
string levelSuffix = $" Lv.{grid.buildingLevel}/{resourceInfo.MaxLevel}";
|
||
if (grid.Resource == ResourceType.Wonder)
|
||
levelSuffix =
|
||
":" + MultilingualManager.Instance.GetMultilingualText(uint.Parse(Table.Instance.GridAndResourceDataAssets.GetWonderName(grid.Wonder, player)));
|
||
|
||
//step #3 现在的到了显示在玩家面前的resource真实情况,开始处理
|
||
if (resource != ResourceType.None)
|
||
{
|
||
|
||
Table.Instance.GridAndResourceDataAssets.GetResourceVarientInfo(resource, player,grid,out var tname, out var tdesc);
|
||
if(tname != "")MultilingualManager.Instance.SetUIText(title, tname);
|
||
if(tdesc != "")MultilingualManager.Instance.SetUIText(desc,tdesc);
|
||
|
||
//处理常规情况
|
||
else
|
||
{
|
||
MultilingualManager.Instance.SetUIText(
|
||
title,
|
||
resourceInfo.ResourceName,
|
||
(resourceInfo.HasLevel || resourceInfo.Resource == ResourceType.Wonder) ? new List<string> { levelSuffix } : null
|
||
);
|
||
MultilingualManager.Instance.SetUIText(desc,resourceInfo.ResourceDesc,
|
||
(resourceInfo.Resource is ResourceType.Temple or ResourceType.WaterTemple or ResourceType.KingTemple or ResourceType.MountainTemple or ResourceType.ForestTemple) ?
|
||
new List<string>{grid.buildingLevel.ToString()} : null );
|
||
}
|
||
|
||
}
|
||
else if(grid.Vegetation == Vegetation.Trees)
|
||
{
|
||
if (Table.Instance.GridAndResourceDataAssets.GetVegetationInfo(out var info))
|
||
{
|
||
MultilingualManager.Instance.SetUIText(title,info.ResourceName);
|
||
MultilingualManager.Instance.SetUIText(desc,info.ResourceDesc);
|
||
}
|
||
else
|
||
{
|
||
LogSystem.LogError("BottomInfoUI vegetation can't find in data asset");
|
||
}
|
||
|
||
}
|
||
else if (grid.Feature == TerrainFeature.Mountain)
|
||
{
|
||
if (Table.Instance.GridAndResourceDataAssets.GetMountainInfo(out var info))
|
||
{
|
||
MultilingualManager.Instance.SetUIText(title,info.ResourceName);
|
||
MultilingualManager.Instance.SetUIText(desc,info.ResourceDesc);
|
||
}
|
||
else
|
||
{
|
||
LogSystem.LogError("BottomInfoUI mountain can't find in data asset");
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (Table.Instance.GridAndResourceDataAssets.GetTerrainInfo(grid.Terrain,out var info))
|
||
{
|
||
MultilingualManager.Instance.SetUIText(title,info.ResourceName);
|
||
MultilingualManager.Instance.SetUIText(desc,info.ResourceDesc);
|
||
}
|
||
else
|
||
{
|
||
LogSystem.LogError("BottomInfoUI terrain can't find in data asset");
|
||
}
|
||
}
|
||
|
||
//step #4 设置下方的信息表格
|
||
//text1 城市
|
||
//如果是有主领土
|
||
if (player != null)
|
||
{
|
||
Table.Instance.PlayerDataAssets.GetPlayerInfo(player,out var playerInfo);
|
||
MultilingualManager.Instance.SetUIText(
|
||
_gridBaseInfo.transform.Find("DataInfo/Title1").GetComponent<TextMeshProUGUI>(), playerInfo.ForceName);
|
||
|
||
}
|
||
//如果是无主领土
|
||
else
|
||
MultilingualManager.Instance.SetUIText(
|
||
_gridBaseInfo.transform.Find("DataInfo/Title1").GetComponent<TextMeshProUGUI>(), Table.Instance.TextDataAssets.BottomInfoGridNoPlayerGridSubTitle1);
|
||
//_gridBaseInfo.transform.Find("DataInfo/Title1").GetComponent<TextMeshProUGUI>().text = "-";
|
||
|
||
|
||
//text2 地貌
|
||
_gridBaseInfo.transform.Find("DataInfo/Title2").GetComponent<TextMeshProUGUI>().text =
|
||
grid.Terrain switch
|
||
{
|
||
TerrainType.Land => "陆地",
|
||
TerrainType.ShallowSea => "浅海",
|
||
TerrainType.DeepSea => "深海",
|
||
_ => "外太空"
|
||
};
|
||
if(grid.Feature == TerrainFeature.Mountain)
|
||
_gridBaseInfo.transform.Find("DataInfo/Title2").GetComponent<TextMeshProUGUI>().text +=
|
||
",山脉";
|
||
if(grid.Feature == TerrainFeature.Road)
|
||
_gridBaseInfo.transform.Find("DataInfo/Title2").GetComponent<TextMeshProUGUI>().text +=
|
||
",道路";
|
||
if(grid.Vegetation == Vegetation.Trees)
|
||
_gridBaseInfo.transform.Find("DataInfo/Title2").GetComponent<TextMeshProUGUI>().text +=
|
||
",树林";
|
||
//text3 建筑
|
||
MultilingualManager.Instance.SetUIText(_gridBaseInfo.transform.Find("DataInfo/Title3").GetComponent<TextMeshProUGUI>(),
|
||
Table.Instance.GridAndResourceDataAssets.GetResourceName(grid.Resource));
|
||
|
||
MultilingualManager.Instance.SetUIText(
|
||
_gridBaseInfo.transform.Find("DataInfo/Title3").GetComponent<TextMeshProUGUI>(),
|
||
resourceInfo.ResourceName,
|
||
(resourceInfo.HasLevel || resource == ResourceType.Wonder) ? new List<string> { levelSuffix } : null
|
||
);
|
||
|
||
|
||
|
||
|
||
//text4 资源
|
||
_gridBaseInfo.transform.Find("DataInfo/Title4").GetComponent<TextMeshProUGUI>().text =
|
||
grid.Resource switch
|
||
{
|
||
ResourceType.Fish => "渔产",
|
||
ResourceType.Starfish => "鲸鱼",
|
||
ResourceType.Animal => "动物",
|
||
ResourceType.Fruit => "蔬果",
|
||
ResourceType.Metal => "矿产",
|
||
ResourceType.Crop => "庄稼",
|
||
_ => "-"
|
||
};
|
||
|
||
|
||
|
||
}
|
||
|
||
public void UpdateInfoCity(bool show,CityData city)
|
||
{
|
||
if (!show)
|
||
{
|
||
_cityBaseInfo.SetActive(false);
|
||
return;
|
||
}
|
||
|
||
_cityBaseInfo.SetActive(true);
|
||
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);
|
||
SetLayerRecursively(clone, LayerMask.NameToLayer("Preview"));
|
||
_cityBaseInfo.SetActive(true);
|
||
_cityCamera.SetActive(true);
|
||
Timer.Instance.TimerRegister(_cityCamera, () => { _cityCamera.SetActive(false); }, 0.001f,"HideCamera");
|
||
Table.Instance.CivDataAssets.GetCityInfo(city.Name,out var cityInfo);
|
||
_cityTitle.GetComponent<TextMeshProUGUI>().text =
|
||
MultilingualManager.Instance.GetMultilingualText(uint.Parse(cityInfo.CityName)) + " Lv." + city.Level;
|
||
|
||
MultilingualManager.Instance.SetUIText(_cityDesc.GetComponent<TextMeshProUGUI>(),cityInfo.CityDescription);
|
||
|
||
//显示城市边界
|
||
HashSet<uint> gridList = new HashSet<uint>();
|
||
city.Territory.GetAllTerritoryArea(gridList);
|
||
foreach (var gid in gridList)
|
||
{
|
||
if (Main.MapData.GridMap.GetGridDataByGid(gid, out var grid))
|
||
grid.CityBorderRenderMark = true;
|
||
}
|
||
|
||
|
||
if (!Main.MapData.GetPlayerDataByCityId(city.Id, out var player)) return;
|
||
|
||
//text1 城市所属
|
||
//如果是有主领土
|
||
Table.Instance.PlayerDataAssets.GetPlayerInfo(player,out var playerInfo);
|
||
MultilingualManager.Instance.SetUIText(
|
||
_cityBaseInfo.transform.Find("DataInfo/Title1").GetComponent<TextMeshProUGUI>(), playerInfo.ForceName);
|
||
//如果是自己的城市
|
||
if (player.Id == Main.MapData.PlayerMap.SelfPlayerData.Id)
|
||
{
|
||
//text2 每回合收入
|
||
_cityBaseInfo.transform.Find("DataInfo/Title2").GetComponent<TextMeshProUGUI>().text = "+" + Main.CityLogic.GetCityStarsPerTurn(Main.MapData,city) + " 每回合";
|
||
|
||
//text3 人口情况
|
||
_cityBaseInfo.transform.Find("DataInfo/Title3").GetComponent<TextMeshProUGUI>().text = "人口 " + Main.MapData.GetUnitCount(city.Id) + "/" + city.Level;
|
||
//text4 征税所情况
|
||
/*int pp = 0;
|
||
if (city.Workshop) pp++;
|
||
pp += city.ParkCount;
|
||
var par = new List<string>();
|
||
par.Add(pp.ToString());
|
||
*/
|
||
//MultilingualManager.Instance.SetUIText(_cityBaseInfo.transform.Find("DataInfo/Title4").GetComponent<TextMeshProUGUI>(),par);
|
||
//text6 奢侈品情况
|
||
_cityBaseInfo.transform.Find("DataInfo/Title4").GetComponent<TextMeshProUGUI>().text = "奢侈品 " + (city.ParkCount + (city.Workshop?1:0)) + " 种";
|
||
//text5 联通情况
|
||
if (city.IsCapital)
|
||
_cityBaseInfo.transform.Find("DataInfo/Title5").GetComponent<TextMeshProUGUI>().text = "首都城市";
|
||
else if (city.IsConnectedCapital)
|
||
_cityBaseInfo.transform.Find("DataInfo/Title5").GetComponent<TextMeshProUGUI>().text = "已联通首都贸易";
|
||
else
|
||
_cityBaseInfo.transform.Find("DataInfo/Title5").GetComponent<TextMeshProUGUI>().text = "未联通首都贸易";
|
||
|
||
|
||
|
||
_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>" + "攻下敌方城市,将富庶之地纳入自己的领土吧!";
|
||
}
|
||
}
|
||
private void UpdateInfo()
|
||
{
|
||
//step #1 清理grid和city的preview窗口(这一步做的不好,但是先这样吧
|
||
foreach (Transform child in _gridPreviewArea.transform)
|
||
GameObject.Destroy(child.gameObject);
|
||
foreach (Transform child in _cityPreviewArea.transform)
|
||
GameObject.Destroy(child.gameObject);
|
||
|
||
//step #2 确认当前是gird/city/unit,设置好每个模块的true false和基本参数(gridData, cityData, playerData), 还有HasAction的信息
|
||
//0 for grid 1 for city 2 for unit
|
||
int infoType = 0;
|
||
GridData grid = null;
|
||
CityData city = null;
|
||
PlayerData player = null;
|
||
UnitData unit = null;
|
||
bool showCity = false;
|
||
bool showUnit = false;
|
||
bool showGrid = false;
|
||
bool showPlayer = false;
|
||
bool showAction = false;
|
||
var actionList = new List<ActionLogicBase>();
|
||
//如果预览的是grid或者city
|
||
if (UIBottomInfoIsGrid)
|
||
{
|
||
if (Main.MapData.GridMap.GetGridDataByGid(UIBottomInfoStatusObjectId, out grid))
|
||
{
|
||
//现获取对应的playerData
|
||
Main.MapData.GetPlayerDataByTerritoryGridId(UIBottomInfoStatusObjectId, out player);
|
||
|
||
//如果是city
|
||
if (Main.MapData.GetCityDataByGid(grid.Id, out city))
|
||
{
|
||
showCity = true;
|
||
showPlayer = true;
|
||
var param = new CommonActionParams(mapData:Main.MapData,playerData:Main.MapData.PlayerMap.SelfPlayerData,cityData:city,mainObjectType:MainObjectType.City);
|
||
showAction = ActionLogicFactory.MainObjectCanShowAction(param,out actionList);
|
||
}
|
||
|
||
//如果是grid
|
||
else
|
||
{
|
||
showGrid = true;
|
||
if (Main.MapData.GetPlayerDataByTerritoryGridId(grid.Id,out var _))
|
||
showPlayer = true;
|
||
var param = new CommonActionParams(mapData:Main.MapData,Main.MapData.PlayerMap.SelfPlayerData,gridData:grid,mainObjectType:MainObjectType.Grid);
|
||
showAction = ActionLogicFactory.MainObjectCanShowAction(param,out actionList);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
LogSystem.LogError("bottomInfoUI show grid , gid can't find gridData");
|
||
}
|
||
|
||
}
|
||
//如果是unit
|
||
else
|
||
{
|
||
showUnit = true;
|
||
showPlayer = true;
|
||
if (Main.MapData.UnitMap.GetUnitDataByUnitId(UIBottomInfoStatusObjectId, out unit))
|
||
{
|
||
Main.MapData.GetPlayerDataByUnitId(unit.Id,out player);
|
||
if (player.Id == Main.MapData.PlayerMap.SelfPlayerId)
|
||
{
|
||
var param = new CommonActionParams(mapData:Main.MapData,playerData:player,unitData:unit,mainObjectType:MainObjectType.Unit);
|
||
showAction = ActionLogicFactory.MainObjectCanShowAction(param, out actionList);
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
//Step #3 按照流程现显示每一个模块
|
||
UpdateInfoPlayer(showPlayer,player);
|
||
UpdateInfoUnit(showUnit,unit);
|
||
UpdateInfoGrid(showGrid,grid);
|
||
UpdateInfoCity(showCity,city);
|
||
UpdateInfoAction(showAction,actionList);
|
||
|
||
//更新Debug模块的显示
|
||
UpdateDebugInfo();
|
||
|
||
}
|
||
|
||
//让每个action挂一个点击监听事件
|
||
public void ActionAreaClickHandler()
|
||
{
|
||
ActionClickedEvent[] items = _actionArea.GetComponentsInChildren<ActionClickedEvent>(true);//这里设为true,会遍历所有inactive的对象
|
||
|
||
foreach (ActionClickedEvent item in items)
|
||
{
|
||
item.ClearListeners();
|
||
item.OnItemClicked += ActionAreaClicked;
|
||
}
|
||
}
|
||
|
||
|
||
//处理一个action被点击后的情况
|
||
public void ActionAreaClicked(GameObject clickedItem)
|
||
{
|
||
|
||
CommonActionId fakeActionId = clickedItem.GetComponent<ActionIdMono>().ActionId;
|
||
|
||
UnitData unitData = null;
|
||
CityData cityData = null;
|
||
GridData gridData = null;
|
||
MainObjectType mainObjectType = MainObjectType.None;
|
||
if (UIBottomInfoIsGrid)
|
||
{
|
||
mainObjectType = (fakeActionId.ActionType == CommonActionType.TrainUnit && Main.MapData.GetCityDataByGid(UIBottomInfoStatusObjectId,out cityData))
|
||
? MainObjectType.City : MainObjectType.Grid;
|
||
Main.MapData.GridMap.GetGridDataByGid(UIBottomInfoStatusObjectId,out gridData);
|
||
}
|
||
else
|
||
{
|
||
Main.MapData.UnitMap.GetUnitDataByUnitId(UIBottomInfoStatusObjectId,out unitData);
|
||
mainObjectType = MainObjectType.Unit;
|
||
}
|
||
CommonActionParams actionParams = new CommonActionParams(Main.MapData,
|
||
Main.MapData.PlayerMap.SelfPlayerData,unitData,cityData,gridData,null,null,null,mainObjectType);
|
||
|
||
//如果执行不通过,
|
||
if (!ActionLogicFactory.GetActionLogic(fakeActionId).CheckCan(actionParams)) return;
|
||
//如果成功执行,隐藏当前面板
|
||
if (ActionLogicFactory.GetActionLogic(fakeActionId).CompleteExecute(actionParams))
|
||
{
|
||
SetBottomInfoHide();
|
||
Main.Instance.MapInteractionLogic.CancelAllHighlight();
|
||
}
|
||
}
|
||
|
||
//生产选项板的若干选项
|
||
public void GenerateActionOption(List<ActionLogicBase> ActionList)
|
||
{
|
||
int rk = 0;
|
||
|
||
//如果没有任何ActionList内容,直接将ActionInfo setActive false
|
||
if (ActionList.Count == 0)
|
||
{
|
||
_actionInfo.SetActive(false);
|
||
return;
|
||
}
|
||
_actionInfo.SetActive(true);
|
||
|
||
//处理城市满员提示
|
||
var fullPopHint = ROBottomInfoUI.transform.Find("InfoGroup/ActionInfo/FullPopHint").gameObject;
|
||
fullPopHint.SetActive(false);
|
||
//TODO 后面要改成根据数据生成的
|
||
//遍历Transform列表里的每一个选项
|
||
foreach (Transform child in _actionArea.transform)
|
||
{
|
||
CommonActionId tActionId = child.GetComponent<ActionIdMono>().ActionId;
|
||
child.gameObject.SetActive(false);
|
||
//遍历每个ActionList的对象,看看有没有和Transform列表当前这个匹配的
|
||
foreach (var actionLogic in ActionList){
|
||
if (actionLogic.CheckEqualActionId(tActionId))
|
||
{
|
||
//step #1 显示对象
|
||
child.gameObject.SetActive(true);
|
||
|
||
//step #2 排好对象行列位置
|
||
RectTransform rectTransform = child.GetComponent<RectTransform>();
|
||
if (rectTransform != null)
|
||
{
|
||
float x = (rk % 4) * 110;
|
||
float y = (rk / 4) * (-130);
|
||
rectTransform.anchoredPosition = new Vector2(x, y);
|
||
}
|
||
|
||
//step #3 当前action是第几个,计数
|
||
rk++;
|
||
|
||
//step #4 默认要钱,价格标签显示
|
||
TextMeshProUGUI textUIComponent = child.gameObject.transform.Find("costNumber")
|
||
.GetComponent<TextMeshProUGUI>();
|
||
Image starImage = child.gameObject.transform.Find("star").GetComponent<Image>();
|
||
if (actionLogic.GetCost() > 0)
|
||
{
|
||
starImage.gameObject.SetActive(true);
|
||
textUIComponent.gameObject.SetActive(true);
|
||
}
|
||
else
|
||
{
|
||
starImage.gameObject.SetActive(false);
|
||
textUIComponent.gameObject.SetActive(false);
|
||
}
|
||
|
||
//step #5 设置选项的底图,设置价格标签颜色为白色
|
||
Image backImage = child.gameObject.GetComponent<Image>();
|
||
textUIComponent.color = Color.white;
|
||
backImage.sprite = ActionBGAvailable;
|
||
|
||
//step #6 根据city和unit分头设置
|
||
//step #6 part 1 如果是city或者grid的action
|
||
if (UIBottomInfoIsGrid)
|
||
{
|
||
|
||
//如果科技未解锁
|
||
if (!Main.MapData.PlayerMap.SelfPlayerData.TechTree.CheckActionCan(tActionId))
|
||
{
|
||
|
||
|
||
starImage.gameObject.SetActive(false);
|
||
textUIComponent.gameObject.SetActive(false);
|
||
backImage.sprite = ActionBGUnavailable;
|
||
}
|
||
|
||
//如果是hero,要考虑因为冷却时间导致的锁
|
||
if (tActionId.GiantType != GiantType.None)
|
||
{
|
||
Table.Instance.UnitTypeDataAssets.GetUnitTypeInfo(UnitType.Giant, tActionId.GiantType, 0,
|
||
out var info);
|
||
//如果在冷却死亡惩罚时间内,也要显示灰色,并且加上漏斗
|
||
if (info != null && Main.MapData.PlayerMap.SelfPlayerData.giantPenalty[(uint)info.ChessType] > 0)
|
||
{
|
||
Transform cd = child.Find("ColdDown");
|
||
TextMeshProUGUI txt = cd?.Find("Text")?.GetComponent<TextMeshProUGUI>();
|
||
if(cd != null) cd.gameObject.SetActive(true);
|
||
if (txt != null) txt.text = Main.MapData.PlayerMap.SelfPlayerData.giantPenalty[(uint)info.ChessType].ToString();
|
||
backImage.sprite = ActionBGUnavailable;
|
||
}
|
||
else
|
||
{
|
||
Transform cd = child.Find("ColdDown");
|
||
if(cd != null) cd.gameObject.SetActive(false);
|
||
|
||
backImage.sprite = ActionBGAvailable;
|
||
}
|
||
}
|
||
|
||
//获取gid上方的cityData (有可能为null)
|
||
Main.MapData.GetCityDataByGid(UIBottomInfoStatusObjectId, out var cityOnGrid);
|
||
Main.MapData.GetCityDataByTerritoryGid(UIBottomInfoStatusObjectId, out var gridCity);
|
||
|
||
bool needPopulationButFull = Main.MapData.CheckIfCityFullPopulation(gridCity)
|
||
&& Table.Instance.UnitTypeDataAssets.GetUnitTypeInfo(tActionId.UnitType,
|
||
tActionId.GiantType, tActionId.UnitLevel, out var unitInfo)
|
||
&& !unitInfo.Skills.Contains(SkillType.NOPOPULATION);
|
||
|
||
//如果是一个满员城市在grid上生产单位,要额外判断一下这个是不是生产单位的行为(而且生产的不是那种不占人口的兵
|
||
if (needPopulationButFull && tActionId.ActionType == CommonActionType.TrainUnit)
|
||
{
|
||
textUIComponent.color = Color.gray;
|
||
backImage.sprite = ActionBGUnavailable;
|
||
starImage.gameObject.SetActive(false);
|
||
textUIComponent.gameObject.SetActive(false);
|
||
fullPopHint.SetActive(true);
|
||
}
|
||
|
||
|
||
//获得当前grid
|
||
Main.MapData.GridMap.GetGridDataByGid(UIBottomInfoStatusObjectId, out var gridData);
|
||
//根据获得的最新报价,更新价格
|
||
textUIComponent.text = actionLogic.GetCost(gridData?.buildingLevel ?? 0).ToString();
|
||
//如果钱不够 并且不是满员城市的生产有人口需求的单位的行为,并且不是未研发科技
|
||
if (Main.MapData.PlayerMap.SelfPlayerData.PlayerWealth < actionLogic.GetCost(gridData?.buildingLevel ?? 0) &&
|
||
//!(needPopulationButFull && tActionId.ActionType == CommonActionType.TrainUnit)
|
||
backImage.sprite != ActionBGUnavailable
|
||
)
|
||
{
|
||
textUIComponent.color = Color.red;
|
||
backImage.sprite = ActionBGExpensive;
|
||
}
|
||
break;
|
||
}
|
||
//step #6 part 2 如果是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++;
|
||
|
||
}
|
||
}
|
||
}
|
||
|
||
//用完ActionList清空,方便你我他
|
||
ActionList.Clear();
|
||
}
|
||
|
||
//隐藏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 (Main.MapData == null) return;
|
||
//如果是城市格子
|
||
if (UIBottomInfoIsGrid && Main.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 || !_actionInfo.activeSelf) 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);
|
||
}
|
||
}
|
||
|
||
// 递归设置层级的辅助方法
|
||
private void SetLayerRecursively(GameObject obj, int newLayer)
|
||
{
|
||
obj.layer = newLayer;
|
||
|
||
foreach (Transform child in obj.transform)
|
||
{
|
||
SetLayerRecursively(child.gameObject, newLayer);
|
||
}
|
||
}
|
||
}
|