UI_HeroMustCardElement.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677
  1. using UnityEngine;
  2. using System.Collections;
  3. using UnityEngine.UI;
  4. using System;
  5. /// <summary>
  6. /// 英雄半身卡牌元素
  7. /// </summary>
  8. public class UI_HeroMustCardElement : GameBehavior
  9. {
  10. /// <summary>
  11. /// 接收传递来的数据
  12. /// </summary>
  13. public string mData;
  14. /// <summary>
  15. /// 是否是玩家已拥有
  16. /// </summary>
  17. public bool mIsPlayerOwn = false;
  18. /// <summary>
  19. /// 是否已经满足解锁条件
  20. /// </summary>
  21. public bool mIsMeetUnLockCondition = false;
  22. /// <summary>
  23. /// 是否可以通过购买方式获得
  24. /// </summary>
  25. public bool mIsCanBuy = false;
  26. /// <summary>
  27. /// 数据
  28. /// </summary>
  29. public string mHeroModelIdData = null;
  30. /// <summary>
  31. /// 数据
  32. /// </summary>
  33. public string mHeroUIDData = null;
  34. /// <summary>
  35. /// 背景,点击选中
  36. /// </summary>
  37. private GameObject mBG = null;
  38. /// <summary>
  39. /// 英雄等阶边框
  40. /// </summary>
  41. private Image mBorder = null;
  42. /// <summary>
  43. /// 已解锁 标识
  44. /// </summary>
  45. private GameObject mOkFlag;
  46. /// <summary>
  47. /// 选中标志
  48. /// </summary>
  49. private GameObject mSelected;
  50. /// <summary>
  51. /// 英雄卡牌图标
  52. /// </summary>
  53. private Image mBustIcon = null;
  54. /// <summary>
  55. /// 元素图标
  56. /// </summary>
  57. private Image myusnsuIcon;
  58. /// <summary>
  59. /// 职业类型图标
  60. /// </summary>
  61. private Image mzhiyeIcon;
  62. /// <summary>
  63. /// 星级
  64. /// </summary>
  65. private GameObject mStar;
  66. /// <summary>
  67. /// 等阶
  68. /// </summary>
  69. private Image mDengjieIcon;
  70. /// <summary>
  71. /// 好感度
  72. /// </summary>
  73. private GameObject mFavorIcon;
  74. /// <summary>
  75. /// 等级
  76. /// </summary>
  77. private Text mLevelText = null;
  78. /// <summary>
  79. /// 神血
  80. /// </summary>
  81. private Text mBloodText = null;
  82. /// <summary>
  83. /// 碎片数量
  84. /// </summary>
  85. private Text mPiecesNumText = null;
  86. /// <summary>
  87. /// 锁定标识符
  88. /// </summary>
  89. private GameObject mlockIcon;
  90. /// <summary>
  91. /// 上阵标识符
  92. /// </summary>
  93. private GameObject mfightIcon;
  94. /// <summary>
  95. /// 上阵按钮
  96. /// </summary>
  97. private GameObject mUseButton;
  98. /// <summary>
  99. /// 查询按钮
  100. /// </summary>
  101. private GameObject mQueryButton;
  102. /// <summary>
  103. /// 购买按钮
  104. /// </summary>
  105. private GameObject mbuyButton;
  106. /////// <summary>
  107. /////// 未解锁按钮
  108. /////// </summary>
  109. ////private GameObject mlockButton;
  110. /////// <summary>
  111. /////// 获取按钮
  112. /////// </summary>
  113. ////private GameObject mhuoquButton;
  114. /// <summary>
  115. /// 是否需要关注同步更新英雄数据
  116. /// </summary>
  117. private bool mIsNeedReceiveUpdateData;
  118. /// <summary>
  119. /// 是否显示操作按钮
  120. /// </summary>
  121. private bool isShowOperateButton;
  122. private GameObject mLevelInfoObj;
  123. private GameObject mBloodInfoObj;
  124. private GameObject mPiecesInfoObj;
  125. /// <summary>
  126. /// 初始化
  127. /// </summary>
  128. /// <param name="isNeedReceiveUpdateData">是否需要同步数据</param>
  129. public void Init(bool isNeedReceiveUpdateData = false, bool isShowOperateButton = false)
  130. {
  131. mIsNeedReceiveUpdateData = isNeedReceiveUpdateData;
  132. mLevelInfoObj = transform.Find("bg/levelInfo").gameObject;
  133. mBloodInfoObj = transform.Find("bg/blood").gameObject;
  134. mPiecesInfoObj = transform.Find("bg/pieces").gameObject;
  135. mBorder = transform.Find("bg/border").gameObject.GetComponent<Image>();
  136. mBG = transform.Find("bg").gameObject;
  137. mBustIcon = transform.Find("bg/bustIcon").gameObject.GetComponent<Image>();
  138. myusnsuIcon = transform.Find("bg/yuansuIcon").gameObject.GetComponent<Image>();
  139. mzhiyeIcon = transform.Find("bg/zhiyeIcon").gameObject.GetComponent<Image>();
  140. mlockIcon = transform.Find("bg/lockIcon").gameObject;
  141. mfightIcon = transform.Find("bg/fightIcon").gameObject;
  142. mLevelText = transform.Find("bg/levelInfo/value_levelText").gameObject.GetComponent<Text>();
  143. mBloodText = transform.Find("bg/blood/value_bloodText").gameObject.GetComponent<Text>();
  144. mPiecesNumText = transform.Find("bg/pieces/value_piecesText").gameObject.GetComponent<Text>();
  145. mDengjieIcon = transform.Find("bg/dengjieIcon").gameObject.GetComponent<Image>();
  146. mStar = transform.Find("bg/star").gameObject;
  147. mSelected = transform.Find("bg/selected").gameObject;
  148. UI_HeroStarComponment starMono = mStar.GetComponent<UI_HeroStarComponment>();
  149. if (starMono == null)
  150. {
  151. AssemblyHelper.Instance.BindScript("UI_HeroStarComponment", mStar);
  152. starMono = mStar.GetComponent<UI_HeroStarComponment>();
  153. }
  154. mOkFlag = transform.Find("bg/okFlag").gameObject;
  155. mOkFlag.SetActive(false);
  156. mUseButton = transform.Find("bg/useButton").gameObject;
  157. mQueryButton = transform.Find("bg/queryButton").gameObject;
  158. mbuyButton = transform.Find("bg/buyButton").gameObject;
  159. ////////mlockButton = transform.Find("bg/lockButton").gameObject;
  160. ////////mhuoquButton = transform.Find("bg/huoquButton").gameObject;
  161. this.isShowOperateButton = isShowOperateButton;
  162. EventTriggerListener.Get(mBG).onClick = OnClicked_Select;
  163. if (isShowOperateButton)
  164. {
  165. EventTriggerListener.Get(mUseButton).onClick = OnClicked_UseButton;
  166. EventTriggerListener.Get(mQueryButton).onClick = OnClicked_QueryButton;
  167. EventTriggerListener.Get(mbuyButton).onClick = OnClicked_BuyHeroButton;
  168. //////EventTriggerListener.Get(mlockButton).onClick = OnClicked_LockButton;
  169. //////EventTriggerListener.Get(mhuoquButton).onClick = OnClicked_GetMethodButton;
  170. }
  171. else
  172. {
  173. mUseButton.SetActive(false);
  174. mQueryButton.SetActive(false);
  175. }
  176. ////LogHelper.LogError("isShowOperateButton::" + isShowOperateButton);
  177. mbuyButton.SetActive(false);
  178. //////mlockButton.SetActive(false);
  179. //////mhuoquButton.SetActive(false);
  180. mSelected.SetActive(false);
  181. mlockIcon.SetActive(false);
  182. mfightIcon.SetActive(false);
  183. mBustIcon.enabled = false;
  184. mzhiyeIcon.enabled = false;
  185. myusnsuIcon.enabled = false;
  186. mDengjieIcon.enabled = false;
  187. mBorder.enabled = false;
  188. if (mIsNeedReceiveUpdateData && !hasRegistListeners)
  189. {
  190. hasRegistListeners = true;
  191. Player player = UserProxy.Instance.player;
  192. player.collectHero.RefreshUIViewHeroDataChangeEvent += OnRefreshDisplayHeroUI;
  193. //////player.collectHero.RefreshUIViewHeroLockStateEvent += OnRefreshDisplayLockHeroStateUI;
  194. }
  195. }
  196. private bool hasRegistListeners = false;
  197. /// <summary>
  198. /// 点击卡牌事件
  199. /// </summary>
  200. public Action<GameObject> Action_SelectedSomeCard;
  201. /// <summary>
  202. /// 点击卡牌上阵事件
  203. /// </summary>
  204. public Action<GameObject> Action_UseButton;
  205. /// <summary>
  206. /// 点击卡牌查询事件
  207. /// </summary>
  208. public Action<GameObject> Action_QueryButton;
  209. /// <summary>
  210. /// 点击卡牌 购买按钮
  211. /// </summary>
  212. public Action<GameObject> Action_BuyButton;
  213. /////// <summary>
  214. /////// 点击卡牌 未解锁按钮
  215. /////// </summary>
  216. ////public Action<GameObject> Action_UNLockButton;
  217. /// <summary>
  218. /// 点击卡牌 获取按钮
  219. /// </summary>
  220. public Action<GameObject> Action_GetMethodButton;
  221. /// <summary>
  222. /// 获取途径按钮
  223. /// </summary>
  224. /// <param name="go"></param>
  225. private void OnClicked_GetMethodButton(GameObject go)
  226. {
  227. if (mSelected.activeSelf == false)
  228. {
  229. return;
  230. }
  231. if (Action_GetMethodButton != null)
  232. {
  233. Action_GetMethodButton(this.gameObject);
  234. }
  235. }
  236. /// <summary>
  237. ///
  238. /// </summary>
  239. /// <param name="go"></param>
  240. private void OnClicked_BuyHeroButton(GameObject go)
  241. {
  242. if (mSelected.activeSelf == false)
  243. {
  244. return;
  245. }
  246. if (Action_BuyButton != null)
  247. {
  248. Action_BuyButton(this.gameObject);
  249. }
  250. }
  251. /////// <summary>
  252. ///////
  253. /////// </summary>
  254. /////// <param name="go"></param>
  255. ////private void OnClicked_LockButton(GameObject go)
  256. ////{
  257. //// if (mSelected.activeSelf == false)
  258. //// {
  259. //// return;
  260. //// }
  261. //// if (Action_UNLockButton != null)
  262. //// {
  263. //// Action_UNLockButton(this.gameObject);
  264. //// }
  265. ////}
  266. /// <summary>
  267. /// 点击查询按钮
  268. /// </summary>
  269. /// <param name="go"> 按钮对象 </param>
  270. private void OnClicked_QueryButton(GameObject go)
  271. {
  272. if (mSelected.activeSelf == false)
  273. {
  274. return;
  275. }
  276. if (Action_QueryButton != null)
  277. {
  278. Action_QueryButton(this.gameObject);
  279. }
  280. }
  281. /// <summary>
  282. /// 点击上阵按钮
  283. /// </summary>
  284. /// <param name="go">点击对象</param>
  285. private void OnClicked_UseButton(GameObject go)
  286. {
  287. LogHelper.Log("点击上阵按钮");
  288. if (mSelected.activeSelf == false)
  289. {
  290. return;
  291. }
  292. if (Action_UseButton != null)
  293. {
  294. Action_UseButton(this.gameObject);
  295. }
  296. }
  297. /// <summary>
  298. /// 点击选择某个卡牌
  299. /// </summary>
  300. /// <param name="go">点击对象</param>
  301. private void OnClicked_Select(GameObject go)
  302. {
  303. if (Action_SelectedSomeCard != null)
  304. {
  305. //UI_GuideManager.Instance.CloseGuideOver(EGuide_GuideType.Hero, 1);
  306. Action_SelectedSomeCard(this.gameObject);
  307. }
  308. }
  309. /// <summary>
  310. /// 设置数据
  311. /// </summary>
  312. /// <param name="data"> 数据 </param>
  313. public void SetData(string data)
  314. {
  315. mData = data;
  316. int index = data.LastIndexOf('_');
  317. if (index >= 0)
  318. {
  319. mHeroUIDData = data.Substring(0, index);
  320. mHeroModelIdData = data.Substring(index + 1);
  321. }
  322. else
  323. {
  324. mHeroUIDData = data;
  325. }
  326. RefreshUI();
  327. }
  328. /// <summary>
  329. /// 刷新显示具体数据
  330. /// </summary>
  331. private void RefreshUI()
  332. {
  333. mlockIcon.SetActive(false);
  334. mfightIcon.SetActive(false);
  335. mBorder.enabled = false;
  336. mBustIcon.enabled = false;
  337. mzhiyeIcon.enabled = false;
  338. myusnsuIcon.enabled = false;
  339. mDengjieIcon.enabled = false;
  340. mLevelText.text = string.Empty;
  341. UI_HeroStarComponment starMono = mStar.GetComponent<UI_HeroStarComponment>();
  342. starMono.StarNum = 0;
  343. Player player = UserProxy.Instance.player;
  344. GameHeroVo vo = null;
  345. mIsPlayerOwn = false;
  346. if (!string.IsNullOrEmpty(mHeroUIDData))
  347. {
  348. GameHeroVo temp = UserProxy.Instance.player.collectHero.GetHeroGameInfoByHeroUId(mHeroUIDData);
  349. if (temp == null)
  350. {
  351. mIsPlayerOwn = false;
  352. vo = new GameHeroVo();
  353. vo.typeId = mHeroModelIdData;
  354. vo.level = 1;
  355. vo.strengthLevel = 0;
  356. vo.curStar = 0;
  357. //vo.heroSourceData = (HeroVo)sm_hero.GetMoByID(mHeroModelIdData).Clone();
  358. }
  359. else
  360. {
  361. vo = temp;
  362. mHeroModelIdData = vo.typeId;
  363. mIsPlayerOwn = true;
  364. }
  365. }
  366. mBorder.enabled = true;
  367. mzhiyeIcon.enabled = true;
  368. myusnsuIcon.enabled = true;
  369. mDengjieIcon.enabled = true;
  370. mLevelText.text = "等级 " + vo.level.ToString();
  371. IconManager.Instance.SetIcon(mzhiyeIcon.GetComponent<Image>(), IconPrefixConst.ZhiyeIcon, vo.mo.zhiyeIcon);
  372. IconManager.Instance.SetIcon(myusnsuIcon.GetComponent<Image>(), IconPrefixConst.YuansuIcon, vo.mo.yuansuIcon);
  373. IconManager.Instance.SetIcon(mBustIcon.GetComponent<Image>(), IconPrefixConst.HeroBustIcon, vo.mo.bustIcon, true, () =>
  374. {
  375. mBustIcon.enabled = true;
  376. });
  377. starMono.StarNum = vo.curStar;
  378. var cstVo = sm_heroextra_dengjie.GetMoById(vo.mo.zhenxidu - 1);
  379. if (cstVo != null)
  380. {
  381. IconManager.Instance.SetIcon(mDengjieIcon.GetComponent<Image>(), IconPrefixConst.HeroDengjieIcon, cstVo.icon, true);
  382. IconManager.Instance.SetIcon(mBorder.GetComponent<Image>(), IconPrefixConst.HeroDengjie_BorderIcon, cstVo.heroBorder_normal);
  383. }
  384. mIsMeetUnLockCondition = false;
  385. mIsCanBuy = vo.mo.isCanBuy == 1;
  386. if (mIsPlayerOwn)
  387. {
  388. mOkFlag.SetActive(false);
  389. mLevelInfoObj.SetActive(true);
  390. mBloodInfoObj.SetActive(true);
  391. mPiecesInfoObj.SetActive(false);
  392. mlockIcon.SetActive(vo.isLocked);
  393. bool isFight = player.heroTeamConfig.CheckSomeHeroBeUsed(mHeroUIDData);
  394. mfightIcon.SetActive(isFight);
  395. mBustIcon.material = null;
  396. mBG.GetComponent<Image>().material = null;
  397. }
  398. else
  399. {
  400. mLevelInfoObj.SetActive(false);
  401. mBloodInfoObj.SetActive(false);
  402. mPiecesInfoObj.SetActive(true);
  403. mlockIcon.SetActive(false);
  404. mfightIcon.SetActive(false);
  405. Material gray = new Material(Shader.Find("UISprites/DefaultGray"));
  406. mBustIcon.material = gray;
  407. mBG.GetComponent<Image>().material = gray;
  408. }
  409. int lastBloodId = vo.curBloodId - 1;
  410. mBloodText.text = "0%";
  411. //var lVo = sm_heroextra_godblood.GetMoById(lastBloodId);
  412. //if (lVo != null)
  413. //{
  414. // mBloodText.text = lVo.targetGodPercent + "%";
  415. //}
  416. if (!mIsPlayerOwn)
  417. {
  418. var segvo = sm_segment.QuerySegmentInfoByHeroModelID(mHeroModelIdData);
  419. if (segvo != null)
  420. {
  421. int temp = 0;// player.collectPieces.GetPiecesNum(segvo.typeId.ToString());
  422. mPiecesNumText.text = temp + "/" + segvo.mergePrototypeNeedNum;
  423. mIsMeetUnLockCondition = temp >= segvo.mergePrototypeNeedNum;
  424. }
  425. else
  426. {
  427. mPiecesNumText.text = "0";
  428. }
  429. }
  430. Text cost = mbuyButton.transform.Find("Text").GetComponent<Text>();
  431. GameObject cashIcon = mbuyButton.transform.Find("cash").gameObject;
  432. GameObject goldIcon = mbuyButton.transform.Find("gold").gameObject;
  433. if (vo.mo.cashPrice > 0)
  434. {
  435. cost.text = "" + vo.mo.cashPrice;
  436. cashIcon.SetActive(true);
  437. goldIcon.SetActive(false);
  438. }
  439. else if (vo.mo.goldPrice > 0)
  440. {
  441. cost.text = "" + vo.mo.goldPrice;
  442. cashIcon.SetActive(false);
  443. goldIcon.SetActive(true);
  444. }
  445. else
  446. {
  447. cashIcon.SetActive(false);
  448. goldIcon.SetActive(false);
  449. }
  450. mOkFlag.SetActive(mIsMeetUnLockCondition);
  451. }
  452. /// <summary>
  453. /// 刷新卡牌的选中状态
  454. /// </summary>
  455. /// <param name="isSelected">选中状态</param>
  456. public void RefreshSelectedState(bool isSelected)
  457. {
  458. Player player = UserProxy.Instance.player;
  459. mSelected.SetActive(isSelected);
  460. ////if (isShowOperateButton)
  461. ////{
  462. //// mUseButton.SetActive(isSelected);
  463. //// mQueryButton.SetActive(isSelected);
  464. ////}
  465. if (mIsPlayerOwn)
  466. {
  467. ////////mlockButton.SetActive(false);
  468. mbuyButton.SetActive(false);
  469. //////////mhuoquButton.SetActive(false);
  470. //购买按钮+ 未解锁按钮为false
  471. mOkFlag.SetActive(false);
  472. if (isShowOperateButton)
  473. {
  474. mUseButton.SetActive(isSelected);
  475. mQueryButton.SetActive(isSelected);
  476. }
  477. }
  478. else
  479. {
  480. mOkFlag.SetActive(mIsMeetUnLockCondition);
  481. mUseButton.SetActive(false);
  482. mQueryButton.SetActive(false);
  483. //购买按钮+ 未解锁按钮为false
  484. mbuyButton.SetActive(isSelected && mIsCanBuy);
  485. //////////mlockButton.SetActive(!mIsMeetUnLockCondition && isSelected);
  486. //////////mhuoquButton.SetActive(mIsMeetUnLockCondition && isSelected && !mIsCanBuy);
  487. }
  488. }
  489. /// <summary>
  490. /// 注册事件
  491. /// </summary>
  492. public override void distroyListeners()
  493. {
  494. base.distroyListeners();
  495. if (mIsNeedReceiveUpdateData && hasRegistListeners)
  496. {
  497. Player player = UserProxy.Instance.player;
  498. player.collectHero.RefreshUIViewHeroDataChangeEvent -= OnRefreshDisplayHeroUI;
  499. //////player.collectHero.RefreshUIViewHeroLockStateEvent -= OnRefreshDisplayLockHeroStateUI;
  500. hasRegistListeners = false;
  501. }
  502. }
  503. /// <summary>
  504. /// 删除事件
  505. /// </summary>
  506. public override void registListeners()
  507. {
  508. base.registListeners();
  509. if (mIsNeedReceiveUpdateData && !hasRegistListeners)
  510. {
  511. hasRegistListeners = true;
  512. Player player = UserProxy.Instance.player;
  513. player.collectHero.RefreshUIViewHeroDataChangeEvent += OnRefreshDisplayHeroUI;
  514. //////player.collectHero.RefreshUIViewHeroLockStateEvent += OnRefreshDisplayLockHeroStateUI;
  515. }
  516. }
  517. ///////// <summary>
  518. /////////
  519. ///////// </summary>
  520. ///////// <param name="sender"></param>
  521. ///////// <param name="e"></param>
  522. //////public void OnRefreshDisplayLockHeroStateUI(object sender, EventArgs e)
  523. //////{
  524. ////// if (mHeroModelIdData == sender.ToString())
  525. ////// {
  526. ////// RefreshUI();
  527. ////// bool isselected = mSelected.activeSelf;
  528. ////// RefreshSelectedState(isselected);
  529. ////// }
  530. //////}
  531. /// <summary>
  532. /// 接收 英雄数值发生变化处理
  533. /// </summary>
  534. /// <param name="sender">变化的英雄UID</param>
  535. /// <param name="e">暂时无用</param>
  536. public void OnRefreshDisplayHeroUI(object sender, EventArgs e)
  537. {
  538. string heroUID = (string)sender;
  539. if (mIsPlayerOwn && heroUID == mHeroUIDData)
  540. {
  541. RefreshUI();
  542. }
  543. }
  544. /// <summary>
  545. /// 刷新卡的状态,主要是锁定状态+ 上阵状态
  546. /// </summary>
  547. /// <param name="isInTeam">是否在队伍中</param>
  548. internal void RefreshCardLockAndFightState(bool isInTeam)
  549. {
  550. if (mIsPlayerOwn)
  551. {
  552. mOkFlag.SetActive(false);
  553. mfightIcon.SetActive(isInTeam);
  554. GameHeroVo vo = UserProxy.Instance.player.collectHero.GetHeroGameInfoByHeroUId(mHeroUIDData);
  555. if (vo != null)
  556. {
  557. mlockIcon.SetActive(vo.isLocked);
  558. }
  559. }
  560. else
  561. {
  562. mfightIcon.SetActive(false);
  563. mlockIcon.SetActive(false);
  564. }
  565. }
  566. }