源战役客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

129 lines
3.4 KiB

  1. TreasureHouseRewardView = TreasureHouseRewardView or BaseClass(BaseView)
  2. local TreasureHouseRewardView = TreasureHouseRewardView
  3. local table_insert = table.insert
  4. function TreasureHouseRewardView:__init()
  5. self.base_file = "treasureHouse"
  6. self.layout_file = "TreasureHouseRewardView"
  7. self.layer_name = "Activity"
  8. self.destroy_imm = true
  9. self.use_background = true --全屏界面默认使用这个参数
  10. --self.hide_maincancas = true --全屏界面需要放开隐藏主UI
  11. self.change_scene_close = true
  12. self.append_to_ctl_queue = false --是否要添加进界面堆栈
  13. self.need_show_money = false --是否要显示顶部的金钱栏
  14. self.jump_close = true --用于某些界面跳转了之后就需要关掉界面
  15. self.model = TreasureHouseModel:getInstance()
  16. self.load_callback = function ()
  17. self:LoadSuccess()
  18. end
  19. self.open_callback = function ( )
  20. self:OpenSuccess()
  21. end
  22. self.switch_callback = function(index)
  23. self:SwitchTab(index)
  24. end
  25. self.destroy_callback = function ( )
  26. self:DestroySuccess()
  27. end
  28. end
  29. function TreasureHouseRewardView:Open( )
  30. --self.data = data
  31. BaseView.Open(self)
  32. end
  33. function TreasureHouseRewardView:LoadSuccess()
  34. local nodes = {
  35. "bg:raw", "close_btn:obj", "item_scroll", "item_scroll/Viewport/item_con",
  36. }
  37. self:GetChildren(nodes)
  38. self:AddEvent()
  39. lua_resM:setOutsideRawImage(self,self.bg_raw,GameResPath.GetViewBigBg("treasureHouse_reward_bg"),false)
  40. end
  41. function TreasureHouseRewardView:AddEvent()
  42. local function on_click( ... )
  43. self:Close()
  44. end
  45. AddClickEvent(self.close_btn_obj, on_click)
  46. end
  47. function TreasureHouseRewardView:OpenSuccess()
  48. self:UpdateView()
  49. end
  50. function TreasureHouseRewardView:UpdateView()
  51. if not self.item_list_com then
  52. self.item_list_com = self:AddUIComponent(UI.ItemListCreator)
  53. end
  54. local cfg = Config.Treasurehouseitems
  55. local period = 1
  56. local base_info = self.model:GetTreasureHouseBaseInfo()
  57. if TableSize(base_info) > 0 then
  58. period = base_info.curr_period
  59. end
  60. local cfg_data = {}
  61. for i,v in ipairs(cfg) do
  62. if v.period <= period then
  63. if not cfg_data[v.is_rare] then
  64. cfg_data[v.is_rare] = {}
  65. end
  66. table_insert(cfg_data[v.is_rare], v)
  67. end
  68. end
  69. --开始拼接数据
  70. local data = {}
  71. local max_count = 7--一行最多7个奖励
  72. local count = 0
  73. for i=2,0,-1 do
  74. count = 0
  75. table_insert(data, {is_title = true, is_rare = i})
  76. local temp_cfg = cfg_data[i]
  77. if temp_cfg then
  78. local sort_func = function ( a, b )
  79. return a.show_index > b.show_index
  80. end
  81. table.sort(temp_cfg, sort_func)
  82. local temp_data = {}
  83. for ii,vv in ipairs(temp_cfg) do
  84. if count < max_count then
  85. table_insert(temp_data, vv)
  86. count = count + 1
  87. else
  88. table_insert(data, DeepCopy(temp_data))
  89. temp_data = {}--重置
  90. table_insert(temp_data, vv)
  91. count = 1
  92. end
  93. end
  94. --最后还要插入一个 不管够不够
  95. if TableSize(temp_data) > 0 then
  96. temp_data.is_last = true
  97. table_insert(data, DeepCopy(temp_data))
  98. end
  99. end
  100. end
  101. local info = {
  102. data_list = data,
  103. item_con = self.item_con,
  104. scroll_view = self.item_scroll,
  105. item_class = TreasureHouseRewardItem,
  106. start_y = 6, start_x = 50,
  107. create_frequency = 0.02,
  108. create_num_per_time = 3,
  109. reuse_item_num = 15,
  110. get_item_height = function(i)
  111. return (data[i].is_title and 30 or 80)
  112. end,
  113. space_y = 0,
  114. on_update_item = function(item, i, v)
  115. item:SetData(i, v)
  116. end,
  117. }
  118. self.item_list_com:UpdateItems(info)
  119. end
  120. function TreasureHouseRewardView:DestroySuccess( )
  121. end