|
|
- TreasureHouseRewardView = TreasureHouseRewardView or BaseClass(BaseView)
- local TreasureHouseRewardView = TreasureHouseRewardView
- local table_insert = table.insert
- function TreasureHouseRewardView:__init()
- self.base_file = "treasureHouse"
- self.layout_file = "TreasureHouseRewardView"
- self.layer_name = "Activity"
- self.destroy_imm = true
- self.use_background = true --全屏界面默认使用这个参数
- --self.hide_maincancas = true --全屏界面需要放开隐藏主UI
- self.change_scene_close = true
- self.append_to_ctl_queue = false --是否要添加进界面堆栈
- self.need_show_money = false --是否要显示顶部的金钱栏
- self.jump_close = true --用于某些界面跳转了之后就需要关掉界面
- self.model = TreasureHouseModel:getInstance()
-
- self.load_callback = function ()
- self:LoadSuccess()
- end
- self.open_callback = function ( )
- self:OpenSuccess()
- end
- self.switch_callback = function(index)
- self:SwitchTab(index)
- end
- self.destroy_callback = function ( )
- self:DestroySuccess()
- end
- end
-
- function TreasureHouseRewardView:Open( )
- --self.data = data
- BaseView.Open(self)
- end
-
- function TreasureHouseRewardView:LoadSuccess()
- local nodes = {
- "bg:raw", "close_btn:obj", "item_scroll", "item_scroll/Viewport/item_con",
- }
- self:GetChildren(nodes)
- self:AddEvent()
- lua_resM:setOutsideRawImage(self,self.bg_raw,GameResPath.GetViewBigBg("treasureHouse_reward_bg"),false)
- end
-
- function TreasureHouseRewardView:AddEvent()
- local function on_click( ... )
- self:Close()
- end
- AddClickEvent(self.close_btn_obj, on_click)
- end
-
- function TreasureHouseRewardView:OpenSuccess()
- self:UpdateView()
- end
-
- function TreasureHouseRewardView:UpdateView()
- if not self.item_list_com then
- self.item_list_com = self:AddUIComponent(UI.ItemListCreator)
- end
- local cfg = Config.Treasurehouseitems
- local period = 1
- local base_info = self.model:GetTreasureHouseBaseInfo()
- if TableSize(base_info) > 0 then
- period = base_info.curr_period
- end
- local cfg_data = {}
- for i,v in ipairs(cfg) do
- if v.period <= period then
- if not cfg_data[v.is_rare] then
- cfg_data[v.is_rare] = {}
- end
- table_insert(cfg_data[v.is_rare], v)
- end
- end
- --开始拼接数据
- local data = {}
- local max_count = 7--一行最多7个奖励
- local count = 0
- for i=2,0,-1 do
- count = 0
- table_insert(data, {is_title = true, is_rare = i})
- local temp_cfg = cfg_data[i]
- if temp_cfg then
- local sort_func = function ( a, b )
- return a.show_index > b.show_index
- end
- table.sort(temp_cfg, sort_func)
- local temp_data = {}
- for ii,vv in ipairs(temp_cfg) do
- if count < max_count then
- table_insert(temp_data, vv)
- count = count + 1
- else
- table_insert(data, DeepCopy(temp_data))
- temp_data = {}--重置
- table_insert(temp_data, vv)
- count = 1
- end
- end
- --最后还要插入一个 不管够不够
- if TableSize(temp_data) > 0 then
- temp_data.is_last = true
- table_insert(data, DeepCopy(temp_data))
- end
- end
- end
-
- local info = {
- data_list = data,
- item_con = self.item_con,
- scroll_view = self.item_scroll,
- item_class = TreasureHouseRewardItem,
- start_y = 6, start_x = 50,
- create_frequency = 0.02,
- create_num_per_time = 3,
- reuse_item_num = 15,
- get_item_height = function(i)
- return (data[i].is_title and 30 or 80)
- end,
- space_y = 0,
- on_update_item = function(item, i, v)
- item:SetData(i, v)
- end,
- }
- self.item_list_com:UpdateItems(info)
- end
-
- function TreasureHouseRewardView:DestroySuccess( )
-
- end
|