123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677 |
- using UnityEngine;
- using System.Collections;
- using UnityEngine.UI;
- using System;
- /// <summary>
- /// 英雄半身卡牌元素
- /// </summary>
- public class UI_HeroMustCardElement : GameBehavior
- {
- /// <summary>
- /// 接收传递来的数据
- /// </summary>
- public string mData;
- /// <summary>
- /// 是否是玩家已拥有
- /// </summary>
- public bool mIsPlayerOwn = false;
- /// <summary>
- /// 是否已经满足解锁条件
- /// </summary>
- public bool mIsMeetUnLockCondition = false;
- /// <summary>
- /// 是否可以通过购买方式获得
- /// </summary>
- public bool mIsCanBuy = false;
- /// <summary>
- /// 数据
- /// </summary>
- public string mHeroModelIdData = null;
- /// <summary>
- /// 数据
- /// </summary>
- public string mHeroUIDData = null;
- /// <summary>
- /// 背景,点击选中
- /// </summary>
- private GameObject mBG = null;
- /// <summary>
- /// 英雄等阶边框
- /// </summary>
- private Image mBorder = null;
- /// <summary>
- /// 已解锁 标识
- /// </summary>
- private GameObject mOkFlag;
- /// <summary>
- /// 选中标志
- /// </summary>
- private GameObject mSelected;
- /// <summary>
- /// 英雄卡牌图标
- /// </summary>
- private Image mBustIcon = null;
-
- /// <summary>
- /// 元素图标
- /// </summary>
- private Image myusnsuIcon;
- /// <summary>
- /// 职业类型图标
- /// </summary>
- private Image mzhiyeIcon;
- /// <summary>
- /// 星级
- /// </summary>
- private GameObject mStar;
- /// <summary>
- /// 等阶
- /// </summary>
- private Image mDengjieIcon;
- /// <summary>
- /// 好感度
- /// </summary>
- private GameObject mFavorIcon;
- /// <summary>
- /// 等级
- /// </summary>
- private Text mLevelText = null;
- /// <summary>
- /// 神血
- /// </summary>
- private Text mBloodText = null;
- /// <summary>
- /// 碎片数量
- /// </summary>
- private Text mPiecesNumText = null;
- /// <summary>
- /// 锁定标识符
- /// </summary>
- private GameObject mlockIcon;
- /// <summary>
- /// 上阵标识符
- /// </summary>
- private GameObject mfightIcon;
- /// <summary>
- /// 上阵按钮
- /// </summary>
- private GameObject mUseButton;
- /// <summary>
- /// 查询按钮
- /// </summary>
- private GameObject mQueryButton;
- /// <summary>
- /// 购买按钮
- /// </summary>
- private GameObject mbuyButton;
- /////// <summary>
- /////// 未解锁按钮
- /////// </summary>
- ////private GameObject mlockButton;
- /////// <summary>
- /////// 获取按钮
- /////// </summary>
- ////private GameObject mhuoquButton;
- /// <summary>
- /// 是否需要关注同步更新英雄数据
- /// </summary>
- private bool mIsNeedReceiveUpdateData;
- /// <summary>
- /// 是否显示操作按钮
- /// </summary>
- private bool isShowOperateButton;
- private GameObject mLevelInfoObj;
- private GameObject mBloodInfoObj;
- private GameObject mPiecesInfoObj;
-
- /// <summary>
- /// 初始化
- /// </summary>
- /// <param name="isNeedReceiveUpdateData">是否需要同步数据</param>
- 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<Image>();
- mBG = transform.Find("bg").gameObject;
- mBustIcon = transform.Find("bg/bustIcon").gameObject.GetComponent<Image>();
- myusnsuIcon = transform.Find("bg/yuansuIcon").gameObject.GetComponent<Image>();
- mzhiyeIcon = transform.Find("bg/zhiyeIcon").gameObject.GetComponent<Image>();
- mlockIcon = transform.Find("bg/lockIcon").gameObject;
- mfightIcon = transform.Find("bg/fightIcon").gameObject;
- mLevelText = transform.Find("bg/levelInfo/value_levelText").gameObject.GetComponent<Text>();
- mBloodText = transform.Find("bg/blood/value_bloodText").gameObject.GetComponent<Text>();
- mPiecesNumText = transform.Find("bg/pieces/value_piecesText").gameObject.GetComponent<Text>();
- mDengjieIcon = transform.Find("bg/dengjieIcon").gameObject.GetComponent<Image>();
- mStar = transform.Find("bg/star").gameObject;
- mSelected = transform.Find("bg/selected").gameObject;
- UI_HeroStarComponment starMono = mStar.GetComponent<UI_HeroStarComponment>();
- if (starMono == null)
- {
- AssemblyHelper.Instance.BindScript("UI_HeroStarComponment", mStar);
- starMono = mStar.GetComponent<UI_HeroStarComponment>();
- }
- 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;
- /// <summary>
- /// 点击卡牌事件
- /// </summary>
- public Action<GameObject> Action_SelectedSomeCard;
- /// <summary>
- /// 点击卡牌上阵事件
- /// </summary>
- public Action<GameObject> Action_UseButton;
- /// <summary>
- /// 点击卡牌查询事件
- /// </summary>
- public Action<GameObject> Action_QueryButton;
- /// <summary>
- /// 点击卡牌 购买按钮
- /// </summary>
- public Action<GameObject> Action_BuyButton;
- /////// <summary>
- /////// 点击卡牌 未解锁按钮
- /////// </summary>
- ////public Action<GameObject> Action_UNLockButton;
- /// <summary>
- /// 点击卡牌 获取按钮
- /// </summary>
- public Action<GameObject> Action_GetMethodButton;
- /// <summary>
- /// 获取途径按钮
- /// </summary>
- /// <param name="go"></param>
- private void OnClicked_GetMethodButton(GameObject go)
- {
- if (mSelected.activeSelf == false)
- {
- return;
- }
- if (Action_GetMethodButton != null)
- {
- Action_GetMethodButton(this.gameObject);
- }
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="go"></param>
- private void OnClicked_BuyHeroButton(GameObject go)
- {
- if (mSelected.activeSelf == false)
- {
- return;
- }
- if (Action_BuyButton != null)
- {
- Action_BuyButton(this.gameObject);
- }
- }
- /////// <summary>
- ///////
- /////// </summary>
- /////// <param name="go"></param>
- ////private void OnClicked_LockButton(GameObject go)
- ////{
- //// if (mSelected.activeSelf == false)
- //// {
- //// return;
- //// }
- //// if (Action_UNLockButton != null)
- //// {
- //// Action_UNLockButton(this.gameObject);
- //// }
- ////}
- /// <summary>
- /// 点击查询按钮
- /// </summary>
- /// <param name="go"> 按钮对象 </param>
- private void OnClicked_QueryButton(GameObject go)
- {
- if (mSelected.activeSelf == false)
- {
- return;
- }
- if (Action_QueryButton != null)
- {
- Action_QueryButton(this.gameObject);
- }
- }
- /// <summary>
- /// 点击上阵按钮
- /// </summary>
- /// <param name="go">点击对象</param>
- private void OnClicked_UseButton(GameObject go)
- {
- LogHelper.Log("点击上阵按钮");
- if (mSelected.activeSelf == false)
- {
- return;
- }
- if (Action_UseButton != null)
- {
- Action_UseButton(this.gameObject);
- }
- }
- /// <summary>
- /// 点击选择某个卡牌
- /// </summary>
- /// <param name="go">点击对象</param>
- private void OnClicked_Select(GameObject go)
- {
- if (Action_SelectedSomeCard != null)
- {
- //UI_GuideManager.Instance.CloseGuideOver(EGuide_GuideType.Hero, 1);
- Action_SelectedSomeCard(this.gameObject);
- }
- }
- /// <summary>
- /// 设置数据
- /// </summary>
- /// <param name="data"> 数据 </param>
- 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();
- }
- /// <summary>
- /// 刷新显示具体数据
- /// </summary>
- 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<UI_HeroStarComponment>();
- 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<Image>(), IconPrefixConst.ZhiyeIcon, vo.mo.zhiyeIcon);
- IconManager.Instance.SetIcon(myusnsuIcon.GetComponent<Image>(), IconPrefixConst.YuansuIcon, vo.mo.yuansuIcon);
- IconManager.Instance.SetIcon(mBustIcon.GetComponent<Image>(), 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<Image>(), IconPrefixConst.HeroDengjieIcon, cstVo.icon, true);
- IconManager.Instance.SetIcon(mBorder.GetComponent<Image>(), 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<Image>().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<Image>().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<Text>();
- 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);
- }
- /// <summary>
- /// 刷新卡牌的选中状态
- /// </summary>
- /// <param name="isSelected">选中状态</param>
- 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);
- }
- }
- /// <summary>
- /// 注册事件
- /// </summary>
- public override void distroyListeners()
- {
- base.distroyListeners();
- if (mIsNeedReceiveUpdateData && hasRegistListeners)
- {
- Player player = UserProxy.Instance.player;
- player.collectHero.RefreshUIViewHeroDataChangeEvent -= OnRefreshDisplayHeroUI;
- //////player.collectHero.RefreshUIViewHeroLockStateEvent -= OnRefreshDisplayLockHeroStateUI;
- hasRegistListeners = false;
- }
- }
- /// <summary>
- /// 删除事件
- /// </summary>
- public override void registListeners()
- {
- base.registListeners();
- if (mIsNeedReceiveUpdateData && !hasRegistListeners)
- {
- hasRegistListeners = true;
- Player player = UserProxy.Instance.player;
- player.collectHero.RefreshUIViewHeroDataChangeEvent += OnRefreshDisplayHeroUI;
- //////player.collectHero.RefreshUIViewHeroLockStateEvent += OnRefreshDisplayLockHeroStateUI;
- }
- }
- ///////// <summary>
- /////////
- ///////// </summary>
- ///////// <param name="sender"></param>
- ///////// <param name="e"></param>
- //////public void OnRefreshDisplayLockHeroStateUI(object sender, EventArgs e)
- //////{
- ////// if (mHeroModelIdData == sender.ToString())
- ////// {
- ////// RefreshUI();
- ////// bool isselected = mSelected.activeSelf;
- ////// RefreshSelectedState(isselected);
- ////// }
- //////}
- /// <summary>
- /// 接收 英雄数值发生变化处理
- /// </summary>
- /// <param name="sender">变化的英雄UID</param>
- /// <param name="e">暂时无用</param>
- public void OnRefreshDisplayHeroUI(object sender, EventArgs e)
- {
- string heroUID = (string)sender;
- if (mIsPlayerOwn && heroUID == mHeroUIDData)
- {
- RefreshUI();
- }
- }
- /// <summary>
- /// 刷新卡的状态,主要是锁定状态+ 上阵状态
- /// </summary>
- /// <param name="isInTeam">是否在队伍中</param>
- 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);
- }
- }
- }
|