|
|
- -- <*
- -- @Author: Saber
- -- @Description: 藏宝图 限时商店界面
- -- *>
- TreasureMapShopView = TreasureMapShopView or BaseClass(BaseView)
- local TreasureMapShopView = TreasureMapShopView
-
- function TreasureMapShopView:__init()
- self.base_file = "treasureMap"
- self.layout_file = "TreasureMapShopView"
- self.layer_name = "UI"
- self.destroy_imm = true
- self.use_background = true --全屏界面默认使用这个参数,非全屏界面自行设置
- self.hide_maincancas = false --全屏界面需要隐藏主UI
- self.change_scene_close = true --是否切换场景时关闭(弹出界面使用)
-
- self.model = TreasureMapModel:getInstance()
- self.has_receive_free_goods = false -- 是否已经领取了免费商品
- self.auto_close_time = 30
-
- self.load_callback = function ()
- self:LoadSuccess()
- self:AddEvent()
- end
- self.open_callback = function ( )
- self:UpdateView()
- self:AutoCloseTimer()
- end
- self.destroy_callback = function ( )
- self:DestroySuccess()
- end
- end
-
- function TreasureMapShopView:Open(vo)
- self.vo = vo
- BaseView.Open(self)
- end
-
- function TreasureMapShopView:LoadSuccess()
- local nodes = {
- "win_bg:raw", "close_btn:obj",
- "item_scroll", "item_scroll/Viewport/item_con",
- "auto_close:tmp",
- }
- self:GetChildren(nodes)
- lua_resM:setOutsideRawImage(self, self.win_bg_raw, GameResPath.GetViewBigBg("tm_shop_bg"))
- end
-
- function TreasureMapShopView:AddEvent()
- local function click_event(target)
- if target == self.close_btn_obj then
- if not self.has_receive_free_goods then -- 如果未领取免费商品,关闭界面时需要自动领取
- self.model:Fire(TreasureMapConst.REQUEST_CCMD_EVENT, 42412)
- end
- self:Close()
- end
- end
- AddClickEvent(self.close_btn_obj, click_event)
-
- local function updateFreeStatus(status)
- self.has_receive_free_goods = status
- end
- self:BindEvent(self.model, TreasureMapConst.UPDATE_SHOP_FREE_RECEIVE_STATUS, updateFreeStatus)
- end
-
- function TreasureMapShopView:UpdateView()
- -- 加载配置
- local free_cfg = Config.Treasureeventrewards[tonumber(self.vo.free_reward)]
- local paid_cfg = Config.Treasuremapdoor[tonumber(self.vo.limit_reward)]
- -- 整合奖励配置
- local data = {}
- if free_cfg then
- local rewards = stringtotable(free_cfg.rewards)
- for k, v in ipairs(rewards) do
- data[#data+1] = {reward = v, is_free = true}
- end
- end
- if paid_cfg then
- local rewards = stringtotable(paid_cfg.rewards)
- for k, v in ipairs(rewards) do
- data[#data+1] = {reward = v, is_free = false}
- end
- end
-
- self.shop_item_creator = self.shop_item_creator or self:AddUIComponent(UI.ItemListCreator)
- local info = {
- data_list = data,
- item_con = self.item_con,
- scroll_view = self.item_scroll,
- item_class = TreasureMapShopItem,
- item_width = 171,
- item_height = 240,
- start_x = 6.5,
- start_y = -4,
- space_x = 29,
- space_y = 2,
- create_frequency = 0.01,
- alignment = UnityEngine.TextAnchor.UpperLeft,
- on_update_item = function(item, i, v)
- item:SetData(v, self.vo.expire_time, self.vo.limit_reward)
- end,
- }
- self.shop_item_creator:UpdateItems(info)
- end
-
- function TreasureMapShopView:AutoCloseTimer( )
- local end_time = TimeUtil:getServerTime() + self.auto_close_time
- local function auto_close_time_func()
- local left_time = end_time - TimeUtil:getServerTime()
- if left_time > 0 then
- self.auto_close_tmp.text = string.format("<color=%s>%s</color> 秒后自动关闭", ColorUtil.GREEN_DARK, left_time)
- else
- if not self.has_receive_free_goods then -- 如果未领取免费商品,关闭界面时需要自动领取
- self.model:Fire(TreasureMapConst.REQUEST_CCMD_EVENT, 42412)
- end
- self:Close()
- end
- end
- auto_close_time_func()
- self:ClearAutoCloseTimer()
- self.auto_close_time_func_id = GlobalTimerQuest:AddPeriodQuest(auto_close_time_func, 0.5, -1)
- end
-
- function TreasureMapShopView:ClearAutoCloseTimer( )
- if self.auto_close_time_func_id then
- GlobalTimerQuest:CancelQuest(self.auto_close_time_func_id)
- self.auto_close_time_func_id = nil
- end
- end
-
- function TreasureMapShopView:DestroySuccess( )
- if not self.has_receive_free_goods then -- 如果未领取免费商品,关闭界面时需要自动领取
- self.model:Fire(TreasureMapConst.REQUEST_CCMD_EVENT, 42412)
- end
- self:ClearAutoCloseTimer()
- self.model:SetTreasureMapShopRestNumData(nil)
- -- 关闭界面后,请求最新的限时商城数据
- self.model:Fire(TreasureMapConst.REQUEST_CCMD_EVENT, 42414)
- self.model._check_tm_tips = TreasureMapConst.Normal
- self.model:CheckTreasureTipUseViewOpen()
- end
|