MainMapUIView.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. using FairyGUI;
  2. using UnityEngine;
  3. using XGame;
  4. using XGame.Database;
  5. using XGame.Framework.Map;
  6. namespace FL.Map.UI
  7. {
  8. public class MainMapUIView : EntityView<MainMapUIVM>
  9. {
  10. public Transform CombatValRoot => VM.CombatValRoot;
  11. public Transform PlayerRoot => VM.PlayerRoot;
  12. public Transform MonsterRoot => VM.MonsterRoot;
  13. public Transform BossRoot => VM.BossRoot;
  14. protected override void OnEnable(object intent)
  15. {
  16. VM.Canvas.worldCamera = StageCamera.main;
  17. VM.ChallengeBtn.onClick.AddListener(OnClickChallengeBtn);
  18. }
  19. protected override void OnDisable()
  20. {
  21. VM.ChallengeBtn.onClick.RemoveAllListeners();
  22. VM.Canvas.worldCamera = null;
  23. }
  24. public void RefreshChapter(int chapterId)
  25. {
  26. var chapter = ChapterTableRepo.Get(chapterId);
  27. if (chapter == null)
  28. {
  29. Log.Error($"找不到ChapterTable. chapterId: {chapterId}");
  30. return;
  31. }
  32. var isBossPart = chapter.Part_type == 1;
  33. if ( isBossPart)
  34. {
  35. VM.ChallengeBtn.gameObject.SetActive(false);
  36. }
  37. var isBossFailed = VM.ChallengeBtn.gameObject.activeSelf; // boss挑战失败显示挑战按钮隐藏副本进度条
  38. //Log.Debug($"MainMapUIView RefreshChapter Id:{chapterId} isBoss:{isBossPart} isBossFailed:{isBossFailed}");
  39. // 副本进度只在非boss且挑战按钮隐藏的时候显示
  40. VM.MapInfoRoot.SetActive(!isBossPart);
  41. if (VM.MapInfoRoot.activeSelf)
  42. {
  43. VM.MapNameTxt.text = $"{chapter.Name} {chapter.Chapter}-{chapter.Section}";
  44. VM.MapProgress.SetActive(!isBossFailed);
  45. if (!isBossFailed )
  46. {
  47. VM.MapProgressImg.fillAmount = (chapter.Part - 1) / 4f;
  48. ((RectTransform)VM.CurProgressImg.transform).anchoredPosition = new Vector2(56 * (chapter.Part - 1) - 112, 0);
  49. }
  50. }
  51. }
  52. public void SetBossFailed(bool isFailed)
  53. {
  54. VM.ChallengeBtn.gameObject.SetActive(isFailed);
  55. }
  56. private void OnClickChallengeBtn()
  57. {
  58. EventSingle.Instance.Notify(EventDefine.GameMainMapChallengeBoss);
  59. VM.ChallengeBtn.gameObject.SetActive (false);
  60. }
  61. }
  62. }