|
|
- GuideWelcomeView = GuideWelcomeView or BaseClass(BaseView)
- local GuideWelcomeView = GuideWelcomeView
-
- function GuideWelcomeView:__init()
- self.base_file = "guide"
- self.layout_file = "GuideWelcomeView"
- self.layer_name = "Top"
- self.destroy_imm = true
- self.use_background = true
- self.change_scene_close = true
- self.append_to_ctl_queue = false --是否要添加进界面堆栈
- self.need_show_money = false --是否要显示顶部的金钱栏
- self.hide_maincancas = true
- -- self.hide_maincancas = true
- -- self.click_bg_toClose = true
-
- self.award_list = {}
-
- self.load_callback = function ()
- self:LoadSuccess()
- self:AddEvent()
- end
- self.open_callback = function ( )
- self:OpenSuccess()
- end
- self.destroy_callback = function ( )
- self:DestroySuccess()
- end
- end
-
- function GuideWelcomeView:Open(chapter_id)
- self.chapter_id = chapter_id or 1
- BaseView.Open(self)
- end
-
- function GuideWelcomeView:Close( )
- GlobalEventSystem:Fire(EventName.FORCE_TO_DO_TASK, true)
- BaseView.Close(self)
- end
-
- function GuideWelcomeView:LoadSuccess()
- self.icon_obj = self:GetChild("icon").gameObject
- self.icon_img = self:GetChild("icon"):GetComponent("Image")
- self.time_text = self:GetChild("time"):GetComponent("Text")
- self.cont = self:GetChild("cont")
-
- self:UpdateAward()
- end
-
- function GuideWelcomeView:AddEvent()
- local function on_btn_click( )
- self:CancelTimer()
- self:PlayAnimal()
- end
- AddClickEvent(self.icon_obj, on_btn_click)
- end
-
- function GuideWelcomeView:OpenSuccess()
- GlobalEventSystem:Fire(EventName.STOP_AUTO_DO_TASK)
- GlobalEventSystem:Fire(EventName.STOPAUTOFIGHT)
- self:UpdateTimer()
- end
-
- function GuideWelcomeView:UpdateTimer( )
- local left_time = 10
-
- local function on_timer( )
- local str = HtmlColorTxt(left_time, "#ffc658") .. " 秒后自动发车"
- self.time_text.text = str
- left_time = left_time -1
- if left_time <= 0 then
- self:CancelTimer()
- self:PlayAnimal()
- return
- end
- end
- on_timer()
- if not self.count_down_timer then
- self.count_down_timer = GlobalTimerQuest:AddPeriodQuest(on_timer, 1, -1)
- end
- end
-
- function GuideWelcomeView:CancelTimer( )
- if self.count_down_timer then
- GlobalTimerQuest:CancelQuest(self.count_down_timer)
- self.count_down_timer = nil
- end
- end
-
- function GuideWelcomeView:UpdateAward( )
- local chapter_id = self.chapter_id or 1
- lua_resM:setOutsideImageSprite(self, self.icon_img, GameResPath.GetViewBigBg("guide_welcome_view_".. chapter_id), false)
- local awards = self:GetChapterAwardsCfg(chapter_id)
- if IsTableEmpty(awards) then
- return
- end
- for i=1,3 do
- local award = awards[i] or {}
- local item = self.award_list[i]
- if not item then
- item = UIObjPool:getInstance():PopItem(UIObjPool.UIType.AwardItem, self.cont)
- self.award_list[i] = item
- end
- item:SetItemSize(84, 84)
- item:SetPosition((i-1)*94, 0)
- item:SetVisible(true)
- local typeId, lock = GoodsModel:getInstance():GetMappingTypeId(award[2], award[3])
- item:SetData(typeId, award[4], nil, nil, lock)
- end
- end
-
- function GuideWelcomeView:GetChapterAwardsCfg( chapter_id )
- if not chapter_id then
- return {}
- end
-
- self.chapter_award_cfg = self.chapter_award_cfg or {}
- if self.chapter_award_cfg[chapter_id] then
- return self.chapter_award_cfg[chapter_id]
- end
-
- local career = RoleManager.Instance.mainRoleInfo.career
- if career == 0 then
- return {}
- end
- local chapter_cfg = Config.Chapter[chapter_id]
- if not chapter_cfg then
- return {}
- end
- local temp_cfg = stringtotable(chapter_cfg.awards)
- local temp_awards = {}
- for i,v in ipairs(temp_cfg) do
- if v[1] and (v[1] == 0 or v[1] == career) then
- table.insert(temp_awards, v)
- end
- end
- self.chapter_award_cfg[chapter_id] = temp_awards
- return temp_awards
- end
-
- function GuideWelcomeView:PlayAnimal( )
- do self:Close() return end
- local function end_func( )
- self:Close()
- end
- local target_pos = MainUIController.Instance:GetChapterAwardPos( )
- -- if self.chapter_id <= 3 then
- -- target_pos = Vector3(-ScreenWidth/2+ClientConfig.iphone_x_offset_right+2+16.84+50, ScreenHeight/2-50-76-128.3-88, 0)
- -- else
- -- target_pos = Vector3(-ScreenWidth/2+ClientConfig.iphone_x_offset_right+2+16.84+50, creenHeight/2-50-76-128.3-88, 0)
- -- end
- if IsTableEmpty(target_pos) then
- end_func()
- return
- end
- local time = 0.8
- local target_scale = Vector3(0.7, 0.7, 0.7)
- TweenLite.to(self, self.cont, TweenLite.UiAnimationType.POS, target_pos, time, end_func)
- TweenLite.to(self, self.cont, TweenLite.UiAnimationType.SCALE, target_scale, time)
- end
-
- function GuideWelcomeView:DestroySuccess( )
- self:CancelTimer()
-
- for i,item in pairs(self.award_list) do
- UIObjPool:getInstance():PushItem(UIObjPool.UIType.AwardItem, item)
- end
- self.award_list = {}
- end
|