LuckyBoxPreShowView.cs 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. using UI.LuckyBox;
  2. using UI.CommonGame;
  3. using System.Collections.Generic;
  4. using FairyGUI;
  5. namespace GFGGame
  6. {
  7. public class LuckyBoxPreShowView : BaseWindow
  8. {
  9. private UI_LuckyBoxPreShowUI _ui;
  10. private List<LuckyBoxBonusData> _bonusList;
  11. public override void Dispose()
  12. {
  13. if (_ui != null)
  14. {
  15. _ui.Dispose();
  16. _ui = null;
  17. }
  18. base.Dispose();
  19. }
  20. protected override void OnInit()
  21. {
  22. base.OnInit();
  23. _ui = UI_LuckyBoxPreShowUI.Create();
  24. this.viewCom = _ui.target;
  25. this.viewCom.Center();
  26. this.modal = true;
  27. }
  28. protected override void OnShown()
  29. {
  30. base.OnShown();
  31. int boxId = (int)this.viewData;
  32. LuckyBoxCfg cfg = LuckyBoxCfgArray.Instance.GetCfg(boxId);
  33. string probShow = cfg.probShow.Replace("\\n", "\n");
  34. _ui.m_compText.m_txtShow.text = probShow;
  35. _bonusList = LuckyBoxDataManager.Instance.GetCurrentShowList(boxId);
  36. _ui.m_list.RemoveChildrenToPool();
  37. _ui.m_list.itemRenderer = ListItemRenderer;
  38. _ui.m_list.numItems = _bonusList.Count;
  39. }
  40. protected override void OnHide()
  41. {
  42. base.OnHide();
  43. if (_ui.m_list.numItems > 0) _ui.m_list.ScrollToView(0);
  44. _ui.m_list.RemoveChildrenToPool();
  45. }
  46. private void ListItemRenderer(int index, GObject item)
  47. {
  48. UI_CompLuckyBoxBonusListItem listItem = UI_CompLuckyBoxBonusListItem.Proxy(item);
  49. LuckyBoxBonusData luckyBoxBonusData = _bonusList[index];
  50. listItem.m_txtName.text = luckyBoxBonusData.name;
  51. if (listItem.m_list.data == null)
  52. {
  53. listItem.m_list.itemRenderer = ListItemRewardRender;
  54. }
  55. List<ItemData> bonusData = new List<ItemData>();
  56. bool hasSame = false;
  57. foreach (var info in luckyBoxBonusData.itemList) {
  58. hasSame = false;
  59. foreach (var infoBonus in bonusData) {
  60. if (info.id == infoBonus.id)
  61. hasSame = true;
  62. }
  63. if(!hasSame)
  64. bonusData.Add(info);
  65. }
  66. listItem.m_list.data = bonusData;
  67. listItem.m_list.numItems = bonusData.Count;
  68. listItem.m_list.ResizeToFit();
  69. listItem.target.height = listItem.m_list.y + listItem.m_list.height;
  70. UI_CompLuckyBoxBonusListItem.ProxyEnd();
  71. }
  72. private void ListItemRewardRender(int index, GObject obj)
  73. {
  74. ItemData itemData = (obj.parent.data as List<ItemData>)[index];
  75. if (obj.data == null)
  76. {
  77. obj.data = new ItemView(obj as GComponent);
  78. }
  79. (obj.data as ItemView).SetData(itemData);
  80. (obj.data as ItemView).ImgHasVisible = ItemDataManager.GetItemNum(itemData.id) > 0;
  81. }
  82. }
  83. }