//using Boo.Lang;
using TowerDefense.Level;
using TowerDefense.Towers;
using UnityEngine;
using UnityEngine.UI;
namespace TowerDefense.UI.HUD
{
///
/// Controls the UI objects that draw the tower data
///
[RequireComponent(typeof(Canvas))]
public class TowerUI : MonoBehaviour
{
///
/// The text object for the name
///
public Text towerName;
///
/// The text object for the description
///
public Text description;
public Text upgradeDescription;
///
/// The attached sell button
///
public Button sellButton;
///
/// The attached upgrade button
///
public Button upgradeButton;
///
/// Component to display the relevant information of the tower
///
public TowerInfoDisplay towerInfoDisplay;
public RectTransform panelRectTransform;
public GameObject[] confirmationButtons;
///
/// The main game camera
///
protected Camera m_GameCamera;
///
/// The current tower to draw
///
protected Tower m_Tower;
///
/// The canvas attached to the gameObject
///
protected Canvas m_Canvas;
///
/// Draws the tower data on to the canvas,在界面上显示塔防信息,显示操作和信息界面。
/// 继续修改,确保其它方面的内容处理。
///
///
/// The tower to gain info from
///
public virtual void Show(Tower towerToShow)
{
if (towerToShow == null)
{
return;
}
m_Tower = towerToShow;
AdjustPosition();
int sellValue = m_Tower.GetSellLevel();
///
// TEST COED TO DELETE:
if( sellButton != null)
{
// TEST CODE TO DELETE:
if( m_Tower != null )
GameUI.instance.startDragTower(m_Tower);
/** 以下代码用于测试合成:
if((!m_Tower.isAtMaxLevel) && GameUI.instance.deleteSameLvlTower( m_Tower))
{
GameUI.instance.UpgradeSelectedTower();
}*/
return;
}
else
{
if (GameUI.instance.towerInList(m_Tower) )
return;
}
m_Canvas.enabled = true;
///
if (sellButton != null)
{
sellButton.gameObject.SetActive(sellValue > 0);
}
if (upgradeButton != null)
{
upgradeButton.interactable =
LevelManager.instance.currency.CanAfford(m_Tower.GetCostForNextLevel());
bool maxLevel = m_Tower.isAtMaxLevel;
upgradeButton.gameObject.SetActive(!maxLevel);
if (!maxLevel)
{
upgradeDescription.text =
m_Tower.levels[m_Tower.currentLevel + 1].upgradeDescription.ToUpper();
}
}
LevelManager.instance.currency.currencyChanged += OnCurrencyChanged;
towerInfoDisplay.Show(towerToShow);
foreach (var button in confirmationButtons)
{
button.SetActive(false);
}
}
///
/// Hides the tower info UI and the radius visualizer
///
public virtual void Hide()
{
m_Tower = null;
if (GameUI.instanceExists)
{
GameUI.instance.HideRadiusVisualizer();
}
m_Canvas.enabled = false;
LevelManager.instance.currency.currencyChanged -= OnCurrencyChanged;
}
///
/// Upgrades the tower through
///
public void UpgradeButtonClick()
{
GameUI.instance.UpgradeSelectedTower();
}
///
/// Sells the tower through
///
public void SellButtonClick()
{
GameUI.instance.SellSelectedTower();
}
///
/// Get the text attached to the buttons
///
protected virtual void Awake()
{
m_Canvas = GetComponent