122 lines
3.9 KiB
C#
122 lines
3.9 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using Logic.Multilingual;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace TH1_Renderer
|
|
{
|
|
public class CityInfoMono : MonoBehaviour
|
|
{
|
|
public RectTransform CityInfoBar;
|
|
public Image BG;
|
|
public Image ConnectIcon;
|
|
public Image CapitalIcon;
|
|
public Image EmbassyIcon;
|
|
public Image EmbassyWarIcon;
|
|
public Image CoinIcon;
|
|
public TextMeshProUGUI CoinText;
|
|
public Image TechIcon;
|
|
public TextMeshProUGUI TechText;
|
|
|
|
public TextMeshProUGUI CityName;
|
|
public Transform LevelBar;
|
|
|
|
public GameObject HousePrefab;
|
|
|
|
public Color BGBlue;
|
|
public Color BGRed;
|
|
private List<CityInfoHouseMono> _houseList = null;
|
|
|
|
|
|
|
|
|
|
private void PrepareHouseList(int level)
|
|
{
|
|
if(_houseList == null)
|
|
_houseList = new List<CityInfoHouseMono>();
|
|
while (_houseList.Count < level)
|
|
{
|
|
|
|
var obj = Instantiate(HousePrefab,LevelBar);
|
|
var mono = obj.GetComponent<CityInfoHouseMono>();
|
|
if (mono == null) continue;
|
|
_houseList.Add(mono);
|
|
obj.SetActive(true);
|
|
}
|
|
for(int i = level;i < _houseList.Count;i++)
|
|
_houseList[i].gameObject.SetActive(false);
|
|
|
|
//TODO 这里check是否要强制刷新layout group
|
|
}
|
|
|
|
public void SetBG(bool self)
|
|
{
|
|
BG.color = self ? BGBlue : BGRed;
|
|
}
|
|
|
|
public void SetLevelBar(bool showLevelBar,int level,int levelExp,int pop)
|
|
{
|
|
LevelBar.gameObject.SetActive(showLevelBar);
|
|
PrepareHouseList(level);
|
|
for (int i = 0; i < level; i++)
|
|
{
|
|
CityInfoHouseMono.CityInfoHouseStatusEnum status = i + 1 > Mathf.Abs(levelExp) ? CityInfoHouseMono.CityInfoHouseStatusEnum.NoExp:
|
|
(levelExp > 0 ? CityInfoHouseMono.CityInfoHouseStatusEnum.Exp: CityInfoHouseMono.CityInfoHouseStatusEnum.LackExp);
|
|
_houseList[i]?.SetContent(pop > i,status);
|
|
}
|
|
|
|
}
|
|
|
|
public void SetConnect(bool connect)
|
|
{
|
|
ConnectIcon.gameObject.SetActive(connect);
|
|
LayoutRebuilder.ForceRebuildLayoutImmediate(CityInfoBar);
|
|
}
|
|
|
|
public void SetCapital(bool capital)
|
|
{
|
|
CapitalIcon.gameObject.SetActive(capital);
|
|
LayoutRebuilder.ForceRebuildLayoutImmediate(CityInfoBar);
|
|
}
|
|
|
|
public void SetEmbassy(bool embassy)
|
|
{
|
|
EmbassyIcon.gameObject.SetActive(embassy);
|
|
LayoutRebuilder.ForceRebuildLayoutImmediate(CityInfoBar);
|
|
}
|
|
|
|
public void SetWarEmbassy(bool warEmbassy)
|
|
{
|
|
EmbassyWarIcon.gameObject.SetActive(warEmbassy);
|
|
LayoutRebuilder.ForceRebuildLayoutImmediate(CityInfoBar);
|
|
}
|
|
|
|
public void SetCoin(bool coinIcon,int coin)
|
|
{
|
|
CoinIcon.gameObject.SetActive(coinIcon);
|
|
CoinText.gameObject.SetActive(coinIcon);
|
|
if (coinIcon)
|
|
CoinText.text = coin.ToString();
|
|
LayoutRebuilder.ForceRebuildLayoutImmediate(CityInfoBar);
|
|
}
|
|
public void SetTech(bool techIcon,int tech)
|
|
{
|
|
TechIcon.gameObject.SetActive(techIcon);
|
|
TechText.gameObject.SetActive(techIcon);
|
|
if (techIcon)
|
|
TechText.text = tech.ToString();
|
|
LayoutRebuilder.ForceRebuildLayoutImmediate(CityInfoBar);
|
|
}
|
|
|
|
public void SetCityName(string cityName_ENCODE)
|
|
{
|
|
MultilingualManager.Instance.SetUIText(CityName,cityName_ENCODE);
|
|
LayoutRebuilder.ForceRebuildLayoutImmediate(CityInfoBar);
|
|
}
|
|
|
|
|
|
|
|
}
|
|
} |