346 lines
12 KiB
C#
346 lines
12 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using Animancer;
|
|
using Logic;
|
|
using Logic.Action;
|
|
using Logic.Audio;
|
|
using Logic.CrashSight;
|
|
using Logic.Multilingual;
|
|
using RuntimeData;
|
|
using TH1_Core.Events;
|
|
using TH1_Core.Managers;
|
|
using TH1_Logic.Core;
|
|
using TH1_UI.Components;
|
|
using TH1_UI.HintUI;
|
|
using TH1Resource;
|
|
using TMPro;
|
|
using UI.HintUI;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace TH1_UI.View.Info
|
|
{
|
|
public class UIInfoGridInfoView : Base.View
|
|
{
|
|
public Button closeButton;
|
|
public ViDelegateAssisstant.Dele OnBtnCloseClick;
|
|
|
|
[Header("GridInfo相关")]
|
|
public GameObject GridInfoArea;
|
|
public GameObject GridPreview;
|
|
public TextMeshProUGUI GridInfoTitle;
|
|
public TextMeshProUGUI GridInfoDesc;
|
|
public TextMeshProUGUI GridInfoTerrainTxt;
|
|
public TextMeshProUGUI GridInfoResourceTxt;
|
|
public TextMeshProUGUI GridInfoBuildingTxt;
|
|
|
|
|
|
[Header("CityInfo相关")]
|
|
public GameObject CityInfoArea;
|
|
public GameObject CityPreview;
|
|
public GameObject CityInfoDataArea;
|
|
public TextMeshProUGUI CityInfoTitle;
|
|
public TextMeshProUGUI CityInfoDesc;
|
|
public TextMeshProUGUI CityInfoCoinTxt;
|
|
public TextMeshProUGUI CityInfoTechTxt;
|
|
public TextMeshProUGUI CityInfoDiamondTxt;
|
|
public TextMeshProUGUI CityInfoPopulationTxt;
|
|
public TextMeshProUGUI CityInfoConnectTxt;
|
|
|
|
[Header("UnitInfo相关")]
|
|
public GameObject UnitInfoArea;
|
|
public GameObject UnitPreview;
|
|
public GameObject SkillArea;
|
|
public TextMeshProUGUI UnitInfoTitle;
|
|
public TextMeshProUGUI UnitInfoDesc;
|
|
public TextMeshProUGUI UnitInfoAttackTxt;
|
|
public TextMeshProUGUI UnitInfoDefendTxt;
|
|
public TextMeshProUGUI UnitInfoHealthTxt;
|
|
public TextMeshProUGUI UnitInfoMoveTxt;
|
|
public TextMeshProUGUI UnitInfoRangeTxt;
|
|
|
|
[Header("CommonInfo相关")]
|
|
public GameObject AvatarArea;
|
|
|
|
public GameObject AvatarHint;
|
|
public GameObject Avatar;
|
|
public GameObject AvatarTitleArea;
|
|
public TextMeshProUGUI AvatarTitle;
|
|
public Image AvatarImg;
|
|
public Button AvatarBtn;
|
|
|
|
public GameObject TaskArea;
|
|
public GameObject ActionArea;
|
|
public RectTransform VerticalGroup;
|
|
|
|
protected override void InitStart()
|
|
{
|
|
base.InitStart();
|
|
closeButton.onClick.RemoveAllListeners();
|
|
closeButton.onClick.AddListener(() => { OnBtnCloseClick.Invoke(); });
|
|
//CheckPanel.InitStart(RefreshStatus);
|
|
|
|
|
|
}
|
|
|
|
public void SetContent(ShowUIInfoGridInfo evt)
|
|
{
|
|
SetContentAvatar(evt);
|
|
SetContentGrid(evt);
|
|
SetContentUnit(evt);
|
|
SetContentCity(evt);
|
|
SetContentSkill(evt);
|
|
SetContentAction(evt);
|
|
SetContentTask(evt);
|
|
LayoutRebuilder.ForceRebuildLayoutImmediate(VerticalGroup);
|
|
}
|
|
|
|
public void SetContentAvatar(ShowUIInfoGridInfo evt)
|
|
{
|
|
AvatarArea.SetActive(true);
|
|
|
|
PlayerData player = null;
|
|
switch (evt.type)
|
|
{
|
|
case UIGridInfoType.grid: // City is on a grid, so its ID is a GID
|
|
Main.MapData.GetPlayerDataByTerritoryGridId(evt.id, out player);
|
|
break;
|
|
case UIGridInfoType.unit:
|
|
Main.MapData.GetPlayerDataByUnitId(evt.id, out player);
|
|
break;
|
|
}
|
|
|
|
if (player == null || !Table.Instance.PlayerDataAssets.GetPlayerInfo(player, out var info))
|
|
{
|
|
AvatarTitleArea.SetActive(false);
|
|
AvatarHint.SetActive(false);
|
|
Avatar.SetActive(false);
|
|
return;
|
|
}
|
|
|
|
AvatarTitleArea.SetActive(true);
|
|
AvatarHint.SetActive(true);
|
|
Avatar.SetActive(true);
|
|
|
|
if(!Main.MapData.PlayerMap.SelfPlayerData.MeetPlayers.Contains(player.Id))
|
|
{
|
|
AvatarBtn.onClick.RemoveAllListeners();
|
|
AvatarImg.sprite = Table.Instance.PlayerDataAssets.CommonPlayerAvatar;
|
|
AvatarTitle.text = "???";
|
|
LayoutRebuilder.ForceRebuildLayoutImmediate(AvatarTitleArea.GetComponent<RectTransform>());
|
|
return;
|
|
}
|
|
|
|
|
|
AvatarImg.sprite = info.LeaderAvatar;
|
|
MultilingualManager.Instance.SetUIText(AvatarTitle,info.ForceName);
|
|
LayoutRebuilder.ForceRebuildLayoutImmediate(AvatarTitleArea.GetComponent<RectTransform>());
|
|
|
|
AvatarBtn.onClick.RemoveAllListeners();
|
|
AvatarBtn.onClick.AddListener(() =>
|
|
{
|
|
EventManager.Publish(new ShowUIInfoDiplomacy() { Pid = player.Id });
|
|
OnBtnCloseClick.Invoke();
|
|
});
|
|
}
|
|
|
|
|
|
public void SetContentGrid(ShowUIInfoGridInfo evt)
|
|
{
|
|
if (evt.type != UIGridInfoType.grid || !Main.MapData.GridMap.GetGridDataByGid(evt.id, out var grid) || Main.MapData.GetCityDataByGid(evt.id, out var _))
|
|
{
|
|
GridInfoArea.SetActive(false);
|
|
return;
|
|
}
|
|
GridInfoArea.SetActive(true);
|
|
|
|
|
|
//Step #1 GridPreview
|
|
// TODO: Grid Preview
|
|
|
|
//Step #2 Title & Desc
|
|
//title 逻辑 -> building > resource > forest > mountain > plain
|
|
string title = "";
|
|
string desc = "";
|
|
|
|
|
|
|
|
|
|
//如果显示建筑或者资源
|
|
if (grid.Resource != ResourceType.None && Main.MapData.PlayerMap.SelfPlayerData.CanShowResource(grid.Resource))
|
|
{
|
|
title = Table.Instance.GridAndResourceDataAssets.GetResourceNameWithLevel(grid);
|
|
//var spr = Table.Instance.GridAndResourceDataAssets.GetResourceSprite(grid.Resource, grid.Player(Main.MapData), grid);
|
|
Table.Instance.GridAndResourceDataAssets.GetResourceInfo(grid.Resource, out var resourceInfo);
|
|
desc = resourceInfo.ResourceDesc;
|
|
}
|
|
//如果显示树木
|
|
else if(grid.Vegetation == Vegetation.Trees)
|
|
{
|
|
Table.Instance.GridAndResourceDataAssets.GetVegetationInfo(out var vegetationInfo);
|
|
title = vegetationInfo.ResourceName;
|
|
desc = vegetationInfo.ResourceDesc;
|
|
}
|
|
//如果显示山脉
|
|
else if(grid.Feature == TerrainFeature.Mountain)
|
|
{
|
|
Table.Instance.GridAndResourceDataAssets.GetMountainInfo(out var mountainInfo);
|
|
title = mountainInfo.ResourceName;
|
|
desc = mountainInfo.ResourceDesc;
|
|
}
|
|
//如果显示地形
|
|
else
|
|
{
|
|
Table.Instance.GridAndResourceDataAssets.GetTerrainInfo(grid.Terrain, out var terrainInfo);
|
|
title = terrainInfo.ResourceName;
|
|
desc = terrainInfo.ResourceDesc;
|
|
}
|
|
MultilingualManager.Instance.SetUIText(GridInfoTitle, title);
|
|
MultilingualManager.Instance.SetUIText(GridInfoDesc, desc);
|
|
|
|
//Step #3 设置详细info
|
|
//resource
|
|
if (grid.Resource != ResourceType.None && Table.Instance.GridAndResourceDataAssets.GetResourceInfo(grid.Resource, out var resourceInfo2))
|
|
{
|
|
if (resourceInfo2.ResourceSubType == ResourceSubType.Building)
|
|
{
|
|
MultilingualManager.Instance.SetUIText(GridInfoBuildingTxt,Table.Instance.GridAndResourceDataAssets.GetResourceNameWithLevel(grid));
|
|
//处理盖在建筑下面的资源
|
|
if (grid.ResourceUnderBuilding != ResourceType.None &&
|
|
Table.Instance.GridAndResourceDataAssets.GetResourceInfo(grid.ResourceUnderBuilding,
|
|
out var resourceInfo3) && resourceInfo3.ResourceSubType == ResourceSubType.Resource)
|
|
MultilingualManager.Instance.SetUIText(GridInfoResourceTxt,
|
|
Table.Instance.GridAndResourceDataAssets.GetResourceName(grid.ResourceUnderBuilding));
|
|
else GridInfoResourceTxt.text = "-";
|
|
}
|
|
else
|
|
{
|
|
GridInfoBuildingTxt.text = "-";
|
|
if(Main.MapData.PlayerMap.SelfPlayerData.CanShowResource(grid.Resource))
|
|
MultilingualManager.Instance.SetUIText(GridInfoResourceTxt, Table.Instance.GridAndResourceDataAssets.GetResourceName(grid.Resource));
|
|
else GridInfoResourceTxt.text = "-";
|
|
}
|
|
}
|
|
else
|
|
{
|
|
GridInfoBuildingTxt.text = "-";
|
|
GridInfoResourceTxt.text = "-";
|
|
}
|
|
//terrain
|
|
if (grid.Feature == TerrainFeature.Mountain)
|
|
{
|
|
Table.Instance.GridAndResourceDataAssets.GetMountainInfo(out var mountainInfo);
|
|
MultilingualManager.Instance.SetUIText(GridInfoTerrainTxt, mountainInfo.ResourceName);
|
|
}
|
|
else if (grid.Vegetation == Vegetation.Trees)
|
|
{
|
|
Table.Instance.GridAndResourceDataAssets.GetVegetationInfo(out var vegetationInfo);
|
|
MultilingualManager.Instance.SetUIText(GridInfoTerrainTxt, vegetationInfo.ResourceName);
|
|
}
|
|
else
|
|
{
|
|
Table.Instance.GridAndResourceDataAssets.GetTerrainInfo(grid.Terrain,out var terrainInfo);
|
|
MultilingualManager.Instance.SetUIText(GridInfoTerrainTxt, terrainInfo.ResourceName);
|
|
}
|
|
}
|
|
|
|
public void SetContentUnit(ShowUIInfoGridInfo evt)
|
|
{
|
|
if (evt.type != UIGridInfoType.unit)
|
|
{
|
|
UnitInfoArea.SetActive(false);
|
|
return;
|
|
}
|
|
|
|
}
|
|
|
|
public void SetContentCity(ShowUIInfoGridInfo evt)
|
|
{
|
|
if (evt.type != UIGridInfoType.grid || !Main.MapData.GetCityDataByGid(evt.id,out var city)
|
|
|| !Main.MapData.GetPlayerDataByCityId(city.Id, out var player))
|
|
{
|
|
CityInfoArea.SetActive(false);
|
|
return;
|
|
}
|
|
|
|
CityInfoArea.SetActive(true);
|
|
|
|
// Step 1: Preview (Placeholder)
|
|
// TODO: City Preview rendering is complex and depends on MapRenderer, skipped for now.
|
|
|
|
// Step 2: Title & Description
|
|
Table.Instance.CivDataAssets.GetCityInfo(city.Name, out var cityInfo);
|
|
CityInfoTitle.text = MultilingualManager.Instance.GetMultilingualText(uint.Parse(cityInfo.CityName)) + " Lv." + city.Level;
|
|
MultilingualManager.Instance.SetUIText(CityInfoDesc, cityInfo.CityDescription);
|
|
|
|
// Step 3: Detailed Info (differs for self vs. others)
|
|
if (player.Id == Main.MapData.PlayerMap.SelfPlayerData.Id)
|
|
{
|
|
CityInfoDataArea.SetActive(true);
|
|
var tb = Table.Instance.TextDataAssets;
|
|
CityInfoCoinTxt.text = "+" + Main.CityLogic.GetCityStarsPerTurn(Main.MapData, city)+ MultilingualManager.Instance.GetMultilingualText(uint.Parse(tb.GridInfoText_PerTurn));
|
|
CityInfoTechTxt.text = "+" + Main.CityLogic.GetCityTechPointPerTurn(Main.MapData, city) + MultilingualManager.Instance.GetMultilingualText(uint.Parse(tb.GridInfoText_PerTurn));
|
|
CityInfoPopulationTxt.text = MultilingualManager.Instance.GetMultilingualText(uint.Parse(tb.GridInfoText_Population)) + Main.MapData.GetUnitCount(city.Id) + "/" + city.Level;
|
|
CityInfoDiamondTxt.text = (city.ParkCount + (city.Workshop ? 1 : 0)) + MultilingualManager.Instance.GetMultilingualText(uint.Parse(tb.GridInfoText_Diamond));
|
|
CityInfoConnectTxt.text = city.IsCapital ? MultilingualManager.Instance.GetMultilingualText(uint.Parse(tb.GridInfoText_Capital)) : (city.IsConnectedCapital ? MultilingualManager.Instance.GetMultilingualText(uint.Parse(tb.GridInfoText_Connected)) :
|
|
MultilingualManager.Instance.GetMultilingualText(uint.Parse(tb.GridInfoText_Unconnected)));
|
|
}
|
|
else
|
|
CityInfoDataArea.SetActive(false);
|
|
|
|
|
|
|
|
}
|
|
|
|
public void SetContentSkill(ShowUIInfoGridInfo evt)
|
|
{
|
|
|
|
}
|
|
|
|
public void SetContentAction(ShowUIInfoGridInfo evt)
|
|
{
|
|
//Step #1 确定格位够不够
|
|
//ResourceCache.Instance.SpriteCache.ActionBGAvailable
|
|
var actionList = new List<ActionLogicBase>();
|
|
bool showAction = false;
|
|
var subType = evt.type;
|
|
if (subType == UIGridInfoType.unit && Main.MapData.UnitMap.GetUnitDataByUnitId(evt.id,out var unit))
|
|
{
|
|
var param = new CommonActionParams(mapData:Main.MapData,playerData:Main.MapData.PlayerMap.SelfPlayerData,unitData:unit,mainObjectType:MainObjectType.Unit);
|
|
showAction = ActionLogicFactory.MainObjectCanShowAction(param, out actionList);
|
|
|
|
}
|
|
else if (subType == UIGridInfoType.grid && Main.MapData.GetCityDataByGid(evt.id,out var city))
|
|
{
|
|
var param = new CommonActionParams(mapData:Main.MapData,playerData:Main.MapData.PlayerMap.SelfPlayerData,cityData:city,mainObjectType:MainObjectType.City);
|
|
showAction = ActionLogicFactory.MainObjectCanShowAction(param,out actionList);
|
|
}
|
|
else if (subType == UIGridInfoType.grid && Main.MapData.GridMap.GetGridDataByGid(evt.id,out var grid))
|
|
{
|
|
var param = new CommonActionParams(mapData:Main.MapData,Main.MapData.PlayerMap.SelfPlayerData,gridData:grid,mainObjectType:MainObjectType.Grid);
|
|
showAction = ActionLogicFactory.MainObjectCanShowAction(param,out actionList);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Step #2 确定
|
|
|
|
}
|
|
|
|
public void SetContentTask(ShowUIInfoGridInfo evt)
|
|
{
|
|
|
|
}
|
|
|
|
public void CloseView()
|
|
{
|
|
AudioManager.Instance.StopMusic();
|
|
}
|
|
|
|
}
|
|
|
|
}
|