LuckyBoxPreShowView.cs 3.2 KB

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