GodActivityLimitView = GodActivityLimitView or BaseClass(BaseItem) local GodActivityLimitView = GodActivityLimitView -- GodActivityLimitView.Width = 200 -- GodActivityLimitView.Height = 90 local FILL_VALUE = { [1] = 0.21, [2] = 0.4, [3] = 0.58, [4] = 0.77, [5] = 1, } function GodActivityLimitView:__init(parent_wnd,prefab_asset,layer_name) self.base_file = "godActivity" self.layout_file = "GodActivityLimitView" self.layer_name = layer_name self.model = GodModel:getInstance() self.per_start = 0.085 self.per_end = 0.915 self.all_per = self.per_end - self.per_start self.full_screen = true self.ani_right = 400 self.adjust_mid = {left = 257, right = 800} self:Load() self.model:Fire(GodConst.REQ_ACTIVITY_LIMIT_INFO) CustomActivityModel:getInstance():SetGoodsCanFly(false) end function GodActivityLimitView:Load_callback() self.nodes = { "icon_money_ten:img", "icon_money_one:img:obj", "lb_money_ten:tmp", "lb_money_one:tmp", "img_ad_des:img", "con_model", "lb_all_time:tmp", "model_click:obj", "img_per:img", "lb_per:tmp", "red_one:obj","red_bd:obj", "btn_tip:obj", "btn_one:obj", "btn_ten:obj", "btn_one/lb_btn_one:tmp", "btn_ten/lb_btn_ten:tmp", "con_extra_item", "scroll_1", "scroll_1/Viewport/Content_1", "bg_1:raw","bg_2:raw","bg_3:raw","bg_4:raw","click_mask:obj", "con_item_5", "con_item_2", "con_item_4", "con_item_3", "con_item_1", -- "btn_reward_detail:obj", "di_bg:raw", "bg:raw", "fill_img:img", "btn_see_more:obj", "lb_ac_time:tmp", "free_label:tmp", } self:GetChildren(self.nodes) self:AddEvents() SetAnchoredPosition(self.con_model, -65 - 30, 41 + 15) self.lb_btn_one_tmp.text = "单次召唤" self.lb_btn_ten_tmp.text = "十回召唤" self:UpdateView() self:SetPoolReward() -- lua_resM:setOutsideRawImage(self,self.bg_1_raw,"/client/assets/icon/god/bg/god_draw_bg_5.png") -- lua_resM:setOutsideRawImage(self,self.bg_2_raw,"/client/assets/icon/god/bg/god_draw_bg_6.png") -- lua_resM:setOutsideRawImage(self,self.bg_3_raw,"/client/assets/icon/god/bg/god_draw_bg_7.png") -- lua_resM:setOutsideRawImage(self,self.bg_4_raw,"/client/assets/icon/god/bg/god_draw_bg_8.png") lua_resM:setOutsideRawImage(self,self.bg_raw, GameResPath.GetGodBg( "god_ac_bg" ) ) lua_resM:setOutsideRawImage(self,self.di_bg_raw, GameResPath.GetGodBg( "god_ac_bg2" ) ) end function GodActivityLimitView:RefreshRed( ) if self.is_loaded then --宠物生活技能 每日免费抽奖一次 local left_free_draw_times = self.model:GetGodLeftFreeDrawTimes() local free_red = left_free_draw_times > 0 local num = GoodsModel:getInstance():GetTypeGoodsNum(self.model.acitvity_cost_id) self.red_one_obj:SetActive(num > 0 or free_red) end end function GodActivityLimitView:AddEvents( ) local function call_back( target ) if target == self.btn_tip_obj then EventSystem.Fire(GlobalEventSystem,EventName.OPEN_INSTRUCTION_VIEW, 173 .. "@" .. 91) elseif target == self.btn_one_obj then self:StartGo(1) elseif target == self.btn_ten_obj then self:StartGo(10) elseif target == self.model_click_obj then local base_data = self.model:GetActivityLimitInfo() if not base_data then return end local conf = self.model:GetLimitConfByPhase(base_data.phase) if not conf then return end GodModel:getInstance():Fire(GodConst.OPEN_GOD_INFO_VIEW,tonumber(conf.god_id)) elseif target == self.btn_reward_detail_obj then local show_list = {} local lv = RoleManager.Instance.mainRoleInfo.level for k,v in pairs(Config.Godlimitpool) do if (v.phase == base_data.phase or v.phase == 0) and v.need_lv <= lv then local temp = stringtotable(v.awards)[1] temp[4] = v.is_show table.insert( show_list, temp ) end end local function sort_call( a,b ) return a[4] < b[4] end table.sort( show_list, sort_call ) elseif target == self.btn_see_more_obj then self.model:Fire(GodConst.OPEN_PREVIEW_VIEW, true) end end AddClickEvent(self.btn_tip_obj,call_back,false) AddClickEvent(self.btn_one_obj,call_back,false) AddClickEvent(self.btn_ten_obj,call_back,false) AddClickEvent(self.model_click_obj,call_back,false) AddClickEvent(self.btn_reward_detail_obj,call_back,false) AddClickEvent(self.btn_see_more_obj,call_back,false) local function ANS_ACTIVITY_LIMIT_INFO( ) self:UpdateView() end self:BindEvent(self.model, GodConst.ANS_ACTIVITY_LIMIT_INFO, ANS_ACTIVITY_LIMIT_INFO) local function on_update_red_dot( ) self:RefreshRed() self:RefreshMoney() end self:BindEvent(self.model, GodConst.UpdateRedDot, on_update_red_dot) local function ANS_ACTIVITY_PLAY( pool_type, draw_type, result_data ) --抽奖完成,显示抽奖特效 if pool_type == GodConst.ActivityType.Limit then self:ShowDrawEffect(pool_type, draw_type, result_data) self.click_mask_obj:SetActive(true) end end self:BindEvent(self.model, GodConst.ANS_ACTIVITY_PLAY, ANS_ACTIVITY_PLAY) end function GodActivityLimitView:SetPoolReward( ) if not self.is_loaded then return end local base_data = self.model:GetActivityLimitInfo() if not base_data then return end ------------------------- local show_list = {} local lv = RoleManager.Instance.mainRoleInfo.level for k,v in pairs(Config.Godlimitpool) do if (v.phase == base_data.phase or v.phase == 0) and v.need_lv <= lv and v.is_show ~= 0 then local temp = stringtotable(v.awards)[1] temp[4] = v.is_show table.insert( show_list, temp ) end end local function sort_call( a,b ) return a[4] < b[4] end table.sort( show_list, sort_call ) self.award_item_con_1 = self.award_item_con_1 or self:AddUIComponent(UI.ItemListCreator) local item_data_list = { data_list = show_list, item_con = self.Content_1, scroll_view = self.scroll_1, obj_pool_type = UIObjPool.UIType.AwardItem, item_width = 78, item_height = 78, start_x = 10, start_y = -10, space_x = 10, space_y = 10, create_frequency = 0.01, alignment = UnityEngine.TextAnchor.UpperLeft, on_update_item = function(item, i, v) item:IsNeedShowSeries(true) item:SetDataWithMapId(v[2], 0, v[1]) item:SetItemSize(78, 78) end, } self.award_item_con_1:UpdateItems(item_data_list) end function GodActivityLimitView:StartGo( use_type ) local conf_tag = use_type == 1 and "lottery_single" or "lottery_ten" local have_num = GoodsModel:getInstance():GetTypeGoodsNum(self.model.acitvity_cost_id) local one_cost_conf = Config.Godkv[conf_tag].value_content local need_num = stringtotable(one_cost_conf)[1][3] --宠物生活技能 local left_free_draw_times = self.model:GetGodLeftFreeDrawTimes() if left_free_draw_times > 0 and use_type == 1 then self.model:Fire(GodConst.REQ_ACTIVITY_PLAY, use_type == 1 and 1 or 2,0) return end if have_num >= need_num then self.model:Fire(GodConst.REQ_ACTIVITY_PLAY, use_type == 1 and 1 or 2,0) else local function yes_call( ) self.model:Fire(GodConst.REQ_ACTIVITY_PLAY, use_type == 1 and 1 or 2,1) end local price = GoodsModel:getInstance():GetGoodsPrice(self.model.acitvity_cost_id) local need_cost = price * (need_num - have_num) local have_money = RoleManager.Instance.mainRoleInfo:GetRealJin() local good_name = GoodsModel:getInstance():getGoodsName(self.model.acitvity_cost_id,true) local content = string.format( "%s 购买 %sx%s 召唤 %s 次神座", need_cost,good_name,need_num - have_num,use_type ) if self.model.isAutoBuyActivityLimit then yes_call() else local function toggle_function( flag ) self.model.isAutoBuyActivityLimit = flag end --需要显示购买提示界面 local data = { titleText = "温馨提示", nameText = "", price = need_cost, okText = "确定", gold_res = "ui_momey_icon_1",--货币类型 priceText = content, ok_callback = yes_call, toggle_function = toggle_function, nameText = "是否花费", insufficientText = "", } GlobalEventSystem:Fire(EventName.OPEN_COM_TOGGLE_TIP_VIEW, data) end end end function GodActivityLimitView:UpdateView( ) local function call_backack( ) if self._use_delete_method then return end self:UpdateCountAward() self:UpdateBlessAwardList() self:RefreshModel() self:RefreshMoney() self:RefreshRed() end TimeManager.GetInstance():StartTime("GodActivityLimitView_CheckRedDot", 0.2, call_backack) self:UpdateTime( ) end function GodActivityLimitView:RefreshMoney( ) local one_cost_conf = Config.Godkv["lottery_single"].value_content local ten_cost_conf = Config.Godkv["lottery_ten"].value_content one_cost_conf = stringtotable(one_cost_conf)[1] ten_cost_conf = stringtotable(ten_cost_conf)[1] local goods_id = one_cost_conf[2] local goods_num = GoodsModel:getInstance():GetTypeGoodsNum( goods_id ) -- if goods_num > 0 then local goods_icon = GoodsModel:getInstance():GetGoodsBasicByTypeId( goods_id ).goods_icon lua_resM:setOutsideImageSprite(self,self.icon_money_ten_img,GameResPath.GetGoodsIcon(goods_icon),false) lua_resM:setOutsideImageSprite(self,self.icon_money_one_img,GameResPath.GetGoodsIcon(goods_icon),false) self.lb_money_one_tmp.text = "x" .. one_cost_conf[3] self.lb_money_ten_tmp.text = "x" .. ten_cost_conf[3] -- else -- local price = GoodsModel:getInstance():GetGoodsPrice(goods_id) -- local goods_icon = GoodsModel:getInstance():GetGoodsBasicByTypeId( 100000 ).goods_icon -- lua_resM:setOutsideImageSprite(self,self.icon_money_rest_img,GameResPath.GetGoodsIcon(goods_icon),true) -- lua_resM:setOutsideImageSprite(self,self.icon_money_ten_img,GameResPath.GetGoodsIcon(goods_icon),true) -- lua_resM:setOutsideImageSprite(self,self.icon_money_one_img,GameResPath.GetGoodsIcon(goods_icon),true) -- self.lb_money_ten_tmp.text = price * one_cost_conf[3] -- self.lb_money_one_tmp.text = price * ten_cost_conf[3] -- self.lb_money_rest_tmp.text = WordManager:ConvertNum(RoleManager.Instance.mainRoleInfo.jin) -- end --宠物生活技能 每日免费抽奖一次 local left_free_draw_times = self.model:GetGodLeftFreeDrawTimes() if left_free_draw_times > 0 then self.icon_money_one_obj:SetActive(false) self.lb_money_one_tmp.text = "" self.free_label_tmp.text = "本次免费" else self.icon_money_one_obj:SetActive(true) self.free_label_tmp.text = "" end end function GodActivityLimitView:RefreshModel( force ) if force then self.model_show_id = false end if not self.is_loaded then return end local base_data = self.model:GetActivityLimitInfo() if not base_data then return end local conf = self.model:GetLimitConfByPhase(base_data.phase) if not conf then return end local res_id = self.model:GetGodShowModelResID(conf.god_id) if res_id ~= self.model_show_id then local res_data = { father_node = self, transform = self.con_model, fashion_type = FuncOpenModel.TypeId.God, raycast_size = Vector2(0,0), figure_id = res_id, position = Vector3(0,-300,-500), size = Vector2(720,720), scale = 135, layer_name = self.layer_name, ui_model_type = UIModelCommon.ModelType.Model, } FuncOpenModel:getInstance():SetModelRes(res_data) self.model_show_id = res_id end ------------------------- lua_resM:setOutsideImageSprite(self,self.img_ad_des_img, "/client/assets/icon/godActivity/godActivity_ad_"..conf.god_id..".png" ,true) end --保底奖励 function GodActivityLimitView:UpdateCountAward( ) if not self.is_loaded then return end local base_data = self.model:GetActivityLimitInfo() if not base_data then return end local conf = self.model:GetLimitConfByPhase(base_data.phase) if not conf then return end local count_award = stringtotable(conf.count_award) local last_get = 0 for k,v in pairs(base_data.counts_award) do last_get = last_get < v.award_id and v.award_id or last_get end local show_info = false--当前需要展示的数据 for i,v in ipairs(count_award) do if v[1] > last_get then show_info = v break end end if not show_info then return end self.award_count = self.award_count or UIObjPool:getInstance():PopItem(UIObjPool.UIType.AwardItem,self.con_extra_item) self.award_count:SetItemSize(78,78) self.award_count:SetPosition(0,1.5) self.award_count:SetDataWithMapId(show_info[3][1][2], show_info[3][1][3], show_info[3][1][1]) local function call_back( ) self.model:Fire(GodConst.REQ_ACTIVITY_GET_MIN_AWARD, tonumber(show_info[1])) end self.award_count:SetCallBack(call_back) ------------------------- self.lb_per_tmp.text = base_data.counts .. "/" .. show_info[2] local per = base_data.counts/show_info[2] per = per > 1 and 1 or per self.red_bd_obj:SetActive(per == 1) ------------------------- --进度条不完整,要特殊算 per = per * self.all_per + self.per_start self.img_per_img.fillAmount = per end --累计奖励 function GodActivityLimitView:UpdateBlessAwardList( ) if not self.is_loaded then return end local base_data = self.model:GetActivityLimitInfo() if not base_data then return end local conf = self.model:GetLimitConfByPhase(base_data.phase) if not conf then return end ------------------------- local blessing_award = stringtotable(conf.blessing_award)--累计奖励 ------------------------- self.list_item = self.list_item or {} self.fill_img_img.fillAmount = 0 local function status_callback( index, is_match ) if is_match then local new_value = FILL_VALUE[index] if new_value > self.fill_img_img.fillAmount then self.fill_img_img.fillAmount = new_value end end end for i,v in ipairs(blessing_award) do self.list_item[i] = self.list_item[i] or self:CreateItem(GodActivityRewardItem, self["con_item_" .. i], self.layer_name,"GodActivityRewardTwoItem") self.list_item[i]:SetData("limit",v, status_callback, i) end self.lb_all_time_tmp.text = string.format("累计次数:%d",base_data.blessing) end function GodActivityLimitView:SetData( data ) self.data = data if self.is_loaded then self.need_refreshData = false self:UpdateView() else self.need_refreshData = true end end function GodActivityLimitView:ShowDrawEffect( pool_type, draw_type, result_data ) if not self.is_loaded then return end self.delay_show_reward = function() if self.delay_result_id then GlobalTimerQuest:CancelQuest(self.delay_result_id) self.delay_result_id = nil end self.model:Fire(GodConst.OPEN_ACTIVITY_RESULT_VIEW, result_data ) self.model.draw_ing = false if self._use_delete_method then return end self.click_mask_obj:SetActive(false) end self.model.draw_ing = true -- self.delay_result_id = setTimeout(self.delay_show_reward,3.5) local data = { name = "ui_shenzuochoujiang", scale = 1.5, pos = co.TempVector2(80, 50), time = 1, end_func = self.delay_show_reward, } self.model:Fire(GodConst.OPEN_ACTIVITY_EFFECT_VIEW,data) end -- 刷新活动持续日期 function GodActivityLimitView:UpdateTime( ) if not self.is_loaded then return end local base_data = self.model:GetActivityLimitInfo() if not base_data then return end local stime_str = TimeUtil:timeConversion(base_data.begin_time, "yyyy.mm.dd") local etime_str = TimeUtil:timeConversion(base_data.end_time, "yyyy.mm.dd") self.lb_ac_time_tmp.text = stime_str .. "~" .. etime_str end function GodActivityLimitView:__delete( ) self.model.draw_ing = false CustomActivityModel:getInstance():SetGoodsCanFly(true) if self.delay_result_id then GlobalTimerQuest:CancelQuest(self.delay_result_id) self.delay_result_id = nil ------------------------- if self.delay_show_reward then local function delay( ) self.delay_show_reward() end setTimeout(delay,0.2) end end end