using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System;
///
/// 英雄半身卡牌元素
///
public class UI_HeroMustCardElement : GameBehavior
{
///
/// 接收传递来的数据
///
public string mData;
///
/// 是否是玩家已拥有
///
public bool mIsPlayerOwn = false;
///
/// 是否已经满足解锁条件
///
public bool mIsMeetUnLockCondition = false;
///
/// 是否可以通过购买方式获得
///
public bool mIsCanBuy = false;
///
/// 数据
///
public string mHeroModelIdData = null;
///
/// 数据
///
public string mHeroUIDData = null;
///
/// 背景,点击选中
///
private GameObject mBG = null;
///
/// 英雄等阶边框
///
private Image mBorder = null;
///
/// 已解锁 标识
///
private GameObject mOkFlag;
///
/// 选中标志
///
private GameObject mSelected;
///
/// 英雄卡牌图标
///
private Image mBustIcon = null;
///
/// 元素图标
///
private Image myusnsuIcon;
///
/// 职业类型图标
///
private Image mzhiyeIcon;
///
/// 星级
///
private GameObject mStar;
///
/// 等阶
///
private Image mDengjieIcon;
///
/// 好感度
///
private GameObject mFavorIcon;
///
/// 等级
///
private Text mLevelText = null;
///
/// 神血
///
private Text mBloodText = null;
///
/// 碎片数量
///
private Text mPiecesNumText = null;
///
/// 锁定标识符
///
private GameObject mlockIcon;
///
/// 上阵标识符
///
private GameObject mfightIcon;
///
/// 上阵按钮
///
private GameObject mUseButton;
///
/// 查询按钮
///
private GameObject mQueryButton;
///
/// 购买按钮
///
private GameObject mbuyButton;
///////
/////// 未解锁按钮
///////
////private GameObject mlockButton;
///////
/////// 获取按钮
///////
////private GameObject mhuoquButton;
///
/// 是否需要关注同步更新英雄数据
///
private bool mIsNeedReceiveUpdateData;
///
/// 是否显示操作按钮
///
private bool isShowOperateButton;
private GameObject mLevelInfoObj;
private GameObject mBloodInfoObj;
private GameObject mPiecesInfoObj;
///
/// 初始化
///
/// 是否需要同步数据
public void Init(bool isNeedReceiveUpdateData = false, bool isShowOperateButton = false)
{
mIsNeedReceiveUpdateData = isNeedReceiveUpdateData;
mLevelInfoObj = transform.Find("bg/levelInfo").gameObject;
mBloodInfoObj = transform.Find("bg/blood").gameObject;
mPiecesInfoObj = transform.Find("bg/pieces").gameObject;
mBorder = transform.Find("bg/border").gameObject.GetComponent();
mBG = transform.Find("bg").gameObject;
mBustIcon = transform.Find("bg/bustIcon").gameObject.GetComponent();
myusnsuIcon = transform.Find("bg/yuansuIcon").gameObject.GetComponent();
mzhiyeIcon = transform.Find("bg/zhiyeIcon").gameObject.GetComponent();
mlockIcon = transform.Find("bg/lockIcon").gameObject;
mfightIcon = transform.Find("bg/fightIcon").gameObject;
mLevelText = transform.Find("bg/levelInfo/value_levelText").gameObject.GetComponent();
mBloodText = transform.Find("bg/blood/value_bloodText").gameObject.GetComponent();
mPiecesNumText = transform.Find("bg/pieces/value_piecesText").gameObject.GetComponent();
mDengjieIcon = transform.Find("bg/dengjieIcon").gameObject.GetComponent();
mStar = transform.Find("bg/star").gameObject;
mSelected = transform.Find("bg/selected").gameObject;
UI_HeroStarComponment starMono = mStar.GetComponent();
if (starMono == null)
{
AssemblyHelper.Instance.BindScript("UI_HeroStarComponment", mStar);
starMono = mStar.GetComponent();
}
mOkFlag = transform.Find("bg/okFlag").gameObject;
mOkFlag.SetActive(false);
mUseButton = transform.Find("bg/useButton").gameObject;
mQueryButton = transform.Find("bg/queryButton").gameObject;
mbuyButton = transform.Find("bg/buyButton").gameObject;
////////mlockButton = transform.Find("bg/lockButton").gameObject;
////////mhuoquButton = transform.Find("bg/huoquButton").gameObject;
this.isShowOperateButton = isShowOperateButton;
EventTriggerListener.Get(mBG).onClick = OnClicked_Select;
if (isShowOperateButton)
{
EventTriggerListener.Get(mUseButton).onClick = OnClicked_UseButton;
EventTriggerListener.Get(mQueryButton).onClick = OnClicked_QueryButton;
EventTriggerListener.Get(mbuyButton).onClick = OnClicked_BuyHeroButton;
//////EventTriggerListener.Get(mlockButton).onClick = OnClicked_LockButton;
//////EventTriggerListener.Get(mhuoquButton).onClick = OnClicked_GetMethodButton;
}
else
{
mUseButton.SetActive(false);
mQueryButton.SetActive(false);
}
////LogHelper.LogError("isShowOperateButton::" + isShowOperateButton);
mbuyButton.SetActive(false);
//////mlockButton.SetActive(false);
//////mhuoquButton.SetActive(false);
mSelected.SetActive(false);
mlockIcon.SetActive(false);
mfightIcon.SetActive(false);
mBustIcon.enabled = false;
mzhiyeIcon.enabled = false;
myusnsuIcon.enabled = false;
mDengjieIcon.enabled = false;
mBorder.enabled = false;
if (mIsNeedReceiveUpdateData && !hasRegistListeners)
{
hasRegistListeners = true;
Player player = UserProxy.Instance.player;
player.collectHero.RefreshUIViewHeroDataChangeEvent += OnRefreshDisplayHeroUI;
//////player.collectHero.RefreshUIViewHeroLockStateEvent += OnRefreshDisplayLockHeroStateUI;
}
}
private bool hasRegistListeners = false;
///
/// 点击卡牌事件
///
public Action Action_SelectedSomeCard;
///
/// 点击卡牌上阵事件
///
public Action Action_UseButton;
///
/// 点击卡牌查询事件
///
public Action Action_QueryButton;
///
/// 点击卡牌 购买按钮
///
public Action Action_BuyButton;
///////
/////// 点击卡牌 未解锁按钮
///////
////public Action Action_UNLockButton;
///
/// 点击卡牌 获取按钮
///
public Action Action_GetMethodButton;
///
/// 获取途径按钮
///
///
private void OnClicked_GetMethodButton(GameObject go)
{
if (mSelected.activeSelf == false)
{
return;
}
if (Action_GetMethodButton != null)
{
Action_GetMethodButton(this.gameObject);
}
}
///
///
///
///
private void OnClicked_BuyHeroButton(GameObject go)
{
if (mSelected.activeSelf == false)
{
return;
}
if (Action_BuyButton != null)
{
Action_BuyButton(this.gameObject);
}
}
///////
///////
///////
///////
////private void OnClicked_LockButton(GameObject go)
////{
//// if (mSelected.activeSelf == false)
//// {
//// return;
//// }
//// if (Action_UNLockButton != null)
//// {
//// Action_UNLockButton(this.gameObject);
//// }
////}
///
/// 点击查询按钮
///
/// 按钮对象
private void OnClicked_QueryButton(GameObject go)
{
if (mSelected.activeSelf == false)
{
return;
}
if (Action_QueryButton != null)
{
Action_QueryButton(this.gameObject);
}
}
///
/// 点击上阵按钮
///
/// 点击对象
private void OnClicked_UseButton(GameObject go)
{
LogHelper.Log("点击上阵按钮");
if (mSelected.activeSelf == false)
{
return;
}
if (Action_UseButton != null)
{
Action_UseButton(this.gameObject);
}
}
///
/// 点击选择某个卡牌
///
/// 点击对象
private void OnClicked_Select(GameObject go)
{
if (Action_SelectedSomeCard != null)
{
//UI_GuideManager.Instance.CloseGuideOver(EGuide_GuideType.Hero, 1);
Action_SelectedSomeCard(this.gameObject);
}
}
///
/// 设置数据
///
/// 数据
public void SetData(string data)
{
mData = data;
int index = data.LastIndexOf('_');
if (index >= 0)
{
mHeroUIDData = data.Substring(0, index);
mHeroModelIdData = data.Substring(index + 1);
}
else
{
mHeroUIDData = data;
}
RefreshUI();
}
///
/// 刷新显示具体数据
///
private void RefreshUI()
{
mlockIcon.SetActive(false);
mfightIcon.SetActive(false);
mBorder.enabled = false;
mBustIcon.enabled = false;
mzhiyeIcon.enabled = false;
myusnsuIcon.enabled = false;
mDengjieIcon.enabled = false;
mLevelText.text = string.Empty;
UI_HeroStarComponment starMono = mStar.GetComponent();
starMono.StarNum = 0;
Player player = UserProxy.Instance.player;
GameHeroVo vo = null;
mIsPlayerOwn = false;
if (!string.IsNullOrEmpty(mHeroUIDData))
{
GameHeroVo temp = UserProxy.Instance.player.collectHero.GetHeroGameInfoByHeroUId(mHeroUIDData);
if (temp == null)
{
mIsPlayerOwn = false;
vo = new GameHeroVo();
vo.typeId = mHeroModelIdData;
vo.level = 1;
vo.strengthLevel = 0;
vo.curStar = 0;
//vo.heroSourceData = (HeroVo)sm_hero.GetMoByID(mHeroModelIdData).Clone();
}
else
{
vo = temp;
mHeroModelIdData = vo.typeId;
mIsPlayerOwn = true;
}
}
mBorder.enabled = true;
mzhiyeIcon.enabled = true;
myusnsuIcon.enabled = true;
mDengjieIcon.enabled = true;
mLevelText.text = "等级 " + vo.level.ToString();
IconManager.Instance.SetIcon(mzhiyeIcon.GetComponent(), IconPrefixConst.ZhiyeIcon, vo.mo.zhiyeIcon);
IconManager.Instance.SetIcon(myusnsuIcon.GetComponent(), IconPrefixConst.YuansuIcon, vo.mo.yuansuIcon);
IconManager.Instance.SetIcon(mBustIcon.GetComponent(), IconPrefixConst.HeroBustIcon, vo.mo.bustIcon, true, () =>
{
mBustIcon.enabled = true;
});
starMono.StarNum = vo.curStar;
var cstVo = sm_heroextra_dengjie.GetMoById(vo.mo.zhenxidu - 1);
if (cstVo != null)
{
IconManager.Instance.SetIcon(mDengjieIcon.GetComponent(), IconPrefixConst.HeroDengjieIcon, cstVo.icon, true);
IconManager.Instance.SetIcon(mBorder.GetComponent(), IconPrefixConst.HeroDengjie_BorderIcon, cstVo.heroBorder_normal);
}
mIsMeetUnLockCondition = false;
mIsCanBuy = vo.mo.isCanBuy == 1;
if (mIsPlayerOwn)
{
mOkFlag.SetActive(false);
mLevelInfoObj.SetActive(true);
mBloodInfoObj.SetActive(true);
mPiecesInfoObj.SetActive(false);
mlockIcon.SetActive(vo.isLocked);
bool isFight = player.heroTeamConfig.CheckSomeHeroBeUsed(mHeroUIDData);
mfightIcon.SetActive(isFight);
mBustIcon.material = null;
mBG.GetComponent().material = null;
}
else
{
mLevelInfoObj.SetActive(false);
mBloodInfoObj.SetActive(false);
mPiecesInfoObj.SetActive(true);
mlockIcon.SetActive(false);
mfightIcon.SetActive(false);
Material gray = new Material(Shader.Find("UISprites/DefaultGray"));
mBustIcon.material = gray;
mBG.GetComponent().material = gray;
}
int lastBloodId = vo.curBloodId - 1;
mBloodText.text = "0%";
//var lVo = sm_heroextra_godblood.GetMoById(lastBloodId);
//if (lVo != null)
//{
// mBloodText.text = lVo.targetGodPercent + "%";
//}
if (!mIsPlayerOwn)
{
var segvo = sm_segment.QuerySegmentInfoByHeroModelID(mHeroModelIdData);
if (segvo != null)
{
int temp = 0;// player.collectPieces.GetPiecesNum(segvo.typeId.ToString());
mPiecesNumText.text = temp + "/" + segvo.mergePrototypeNeedNum;
mIsMeetUnLockCondition = temp >= segvo.mergePrototypeNeedNum;
}
else
{
mPiecesNumText.text = "0";
}
}
Text cost = mbuyButton.transform.Find("Text").GetComponent();
GameObject cashIcon = mbuyButton.transform.Find("cash").gameObject;
GameObject goldIcon = mbuyButton.transform.Find("gold").gameObject;
if (vo.mo.cashPrice > 0)
{
cost.text = "" + vo.mo.cashPrice;
cashIcon.SetActive(true);
goldIcon.SetActive(false);
}
else if (vo.mo.goldPrice > 0)
{
cost.text = "" + vo.mo.goldPrice;
cashIcon.SetActive(false);
goldIcon.SetActive(true);
}
else
{
cashIcon.SetActive(false);
goldIcon.SetActive(false);
}
mOkFlag.SetActive(mIsMeetUnLockCondition);
}
///
/// 刷新卡牌的选中状态
///
/// 选中状态
public void RefreshSelectedState(bool isSelected)
{
Player player = UserProxy.Instance.player;
mSelected.SetActive(isSelected);
////if (isShowOperateButton)
////{
//// mUseButton.SetActive(isSelected);
//// mQueryButton.SetActive(isSelected);
////}
if (mIsPlayerOwn)
{
////////mlockButton.SetActive(false);
mbuyButton.SetActive(false);
//////////mhuoquButton.SetActive(false);
//购买按钮+ 未解锁按钮为false
mOkFlag.SetActive(false);
if (isShowOperateButton)
{
mUseButton.SetActive(isSelected);
mQueryButton.SetActive(isSelected);
}
}
else
{
mOkFlag.SetActive(mIsMeetUnLockCondition);
mUseButton.SetActive(false);
mQueryButton.SetActive(false);
//购买按钮+ 未解锁按钮为false
mbuyButton.SetActive(isSelected && mIsCanBuy);
//////////mlockButton.SetActive(!mIsMeetUnLockCondition && isSelected);
//////////mhuoquButton.SetActive(mIsMeetUnLockCondition && isSelected && !mIsCanBuy);
}
}
///
/// 注册事件
///
public override void distroyListeners()
{
base.distroyListeners();
if (mIsNeedReceiveUpdateData && hasRegistListeners)
{
Player player = UserProxy.Instance.player;
player.collectHero.RefreshUIViewHeroDataChangeEvent -= OnRefreshDisplayHeroUI;
//////player.collectHero.RefreshUIViewHeroLockStateEvent -= OnRefreshDisplayLockHeroStateUI;
hasRegistListeners = false;
}
}
///
/// 删除事件
///
public override void registListeners()
{
base.registListeners();
if (mIsNeedReceiveUpdateData && !hasRegistListeners)
{
hasRegistListeners = true;
Player player = UserProxy.Instance.player;
player.collectHero.RefreshUIViewHeroDataChangeEvent += OnRefreshDisplayHeroUI;
//////player.collectHero.RefreshUIViewHeroLockStateEvent += OnRefreshDisplayLockHeroStateUI;
}
}
/////////
/////////
/////////
/////////
/////////
//////public void OnRefreshDisplayLockHeroStateUI(object sender, EventArgs e)
//////{
////// if (mHeroModelIdData == sender.ToString())
////// {
////// RefreshUI();
////// bool isselected = mSelected.activeSelf;
////// RefreshSelectedState(isselected);
////// }
//////}
///
/// 接收 英雄数值发生变化处理
///
/// 变化的英雄UID
/// 暂时无用
public void OnRefreshDisplayHeroUI(object sender, EventArgs e)
{
string heroUID = (string)sender;
if (mIsPlayerOwn && heroUID == mHeroUIDData)
{
RefreshUI();
}
}
///
/// 刷新卡的状态,主要是锁定状态+ 上阵状态
///
/// 是否在队伍中
internal void RefreshCardLockAndFightState(bool isInTeam)
{
if (mIsPlayerOwn)
{
mOkFlag.SetActive(false);
mfightIcon.SetActive(isInTeam);
GameHeroVo vo = UserProxy.Instance.player.collectHero.GetHeroGameInfoByHeroUId(mHeroUIDData);
if (vo != null)
{
mlockIcon.SetActive(vo.isLocked);
}
}
else
{
mfightIcon.SetActive(false);
mlockIcon.SetActive(false);
}
}
}