LuckyBoxPreShowView.cs 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. long playTimes = LuckyBoxDataManager.Instance.GetPlayTimes(cfg.id);
  40. _ui.m_txtPlayTimes.SetVar("name", cfg.name).SetVar("times", playTimes + "").FlushVars();
  41. }
  42. protected override void OnHide()
  43. {
  44. base.OnHide();
  45. if (_ui.m_list.numItems > 0) _ui.m_list.ScrollToView(0);
  46. _ui.m_list.RemoveChildrenToPool();
  47. }
  48. private void ListItemRenderer(int index, GObject item)
  49. {
  50. UI_CompLuckyBoxBonusListItem listItem = UI_CompLuckyBoxBonusListItem.Proxy(item);
  51. LuckyBoxBonusData luckyBoxBonusData = _bonusList[index];
  52. listItem.m_txtName.text = luckyBoxBonusData.name;
  53. if (listItem.m_list.data == null)
  54. {
  55. listItem.m_list.itemRenderer = ListItemRewardRender;
  56. }
  57. List<ItemData> bonusData = new List<ItemData>();
  58. bool hasSame = false;
  59. foreach (var info in luckyBoxBonusData.itemList) {
  60. hasSame = false;
  61. foreach (var infoBonus in bonusData) {
  62. if (info.id == infoBonus.id)
  63. hasSame = true;
  64. }
  65. if(!hasSame)
  66. bonusData.Add(info);
  67. }
  68. listItem.m_list.data = bonusData;
  69. listItem.m_list.numItems = bonusData.Count;
  70. listItem.m_list.ResizeToFit();
  71. listItem.target.height = listItem.m_list.y + listItem.m_list.height;
  72. UI_CompLuckyBoxBonusListItem.ProxyEnd();
  73. }
  74. private void ListItemRewardRender(int index, GObject obj)
  75. {
  76. ItemData itemData = (obj.parent.data as List<ItemData>)[index];
  77. if (obj.data == null)
  78. {
  79. obj.data = new ItemView(obj as GComponent);
  80. }
  81. (obj.data as ItemView).SetData(itemData);
  82. (obj.data as ItemView).ImgHasVisible = ItemDataManager.GetItemNum(itemData.id) > 0;
  83. }
  84. }
  85. }