ItemSourcePanel.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using Core.Language;
  4. using Excel2Json;
  5. using Fort23.Core;
  6. using Fort23.UTool;
  7. using GameLogic.Bag;
  8. using Mono.Utility;
  9. namespace Fort23.Mono
  10. {
  11. [UIBinding(prefab = "ItemSourcePanel")]
  12. public partial class ItemSourcePanel : UIPanel
  13. {
  14. List<SkipToWidget> skipToWidgets = new List<SkipToWidget>();
  15. private CTask<bool> callBack;
  16. private bool isSkipto = false;
  17. private bool isMainPanel;
  18. private void Init()
  19. {
  20. isPopUi = true;
  21. isAddStack = false;
  22. }
  23. protected override void AddEvent()
  24. {
  25. }
  26. protected override void DelEvent()
  27. {
  28. }
  29. public override void AddButtonEvent()
  30. {
  31. }
  32. public async override CTask<bool> AsyncInit(object[] uiData)
  33. {
  34. foreach (var skipToWidget in skipToWidgets)
  35. {
  36. UIManager.Instance.DormancyGComponent(skipToWidget);
  37. }
  38. skipToWidgets.Clear();
  39. int itemId = (int)uiData[0];
  40. callBack = uiData[1] as CTask<bool>;
  41. isMainPanel = (bool)uiData[2];
  42. ItemConfig itemConfig = ConfigComponent.Instance.Get<ItemConfig>(itemId);
  43. Text_ItemName.text = LanguageManager.Instance.Text(itemConfig.itemName);
  44. WidgetItem widgetItem =
  45. await UIManager.Instance.CreateGComponentForObject<WidgetItem>(WidgetItemGam, null);
  46. widgetItem.InitWidget(new ItemInfo(itemId), false);
  47. Text_ItemCount.text = PlayerManager.Instance.BagController.GetItemCount(itemId).ToString();
  48. if (itemConfig.SkiptoID != null)
  49. {
  50. foreach (var skiptoId in itemConfig.SkiptoID)
  51. {
  52. SkipToWidget skipToWidget = await UIManager.Instance.CreateGComponent<SkipToWidget>(null, Content);
  53. skipToWidget.CustonInit(skiptoId);
  54. skipToWidgets.Add(skipToWidget);
  55. skipToWidget.OnClick = OnClick;
  56. }
  57. }
  58. return await base.AsyncInit(uiData);
  59. }
  60. private async void OnClick(ItemWidgetBasic obj)
  61. {
  62. SkipToWidget skipToWidget = obj as SkipToWidget;
  63. if (!SkiptoHelper.IsSkipto(skipToWidget.SkiptoConfig.ID))
  64. {
  65. TipMessagePanel.OpenTipMessagePanel(SkiptoHelper.SkiptoTips(skipToWidget.SkiptoConfig.ID));
  66. return;
  67. }
  68. isSkipto = true;
  69. await UIManager.Instance.HideUIUIPanel(this);
  70. await SkiptoHelper.Skipto(skipToWidget.SkiptoConfig.ID,isMainPanel);
  71. callBack?.SetResult(isSkipto);
  72. }
  73. public static async CTask<bool> OpenPanel(int itemId, bool isMainPanel = false)
  74. {
  75. CTask<bool> callBack = CTask<bool>.Create();
  76. await UIManager.Instance.LoadAndOpenPanel<ItemSourcePanel>(null, UILayer.Top,
  77. uiData: new object[] { itemId, callBack, isMainPanel }, isShowBG: true);
  78. return await callBack;
  79. }
  80. public async override CTask Close()
  81. {
  82. foreach (var skipToWidget in skipToWidgets)
  83. {
  84. UIManager.Instance.DormancyGComponent(skipToWidget);
  85. }
  86. skipToWidgets.Clear();
  87. callBack?.SetResult(isSkipto);
  88. isSkipto = false;
  89. await base.Close();
  90. }
  91. }
  92. }