ChildHeartTaskView = ChildHeartTaskView or BaseClass(BaseView) local ChildHeartTaskView = ChildHeartTaskView function ChildHeartTaskView:__init() self.base_file = "child" self.layout_file = "ChildHeartTaskView" self.layer_name = "UI" self.destroy_imm = true self.use_background = G_USING_BG --全屏界面默认使用这个参数 self.hide_maincancas = true --全屏界面需要放开隐藏主UI self.change_scene_close = true self.append_to_ctl_queue = false --是否要添加进界面堆栈 self.need_show_money = false --是否要显示顶部的金钱栏 self.fire_change_visible_event = true self.blur_activity_bg = true self.close_fog = true self.task_item_list = {} -- 同心每日任务item self.reward_item_list = {} -- 奖励item self.model = ChildModel:getInstance() self.model:ChangeHeartTaskChildSex( ) self.load_callback = function () self:LoadSuccess() self:AddEvent() 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 ChildHeartTaskView:Open( ) --self.data = data BaseView.Open(self) end function ChildHeartTaskView:LoadSuccess() local nodes = { "taskScroll/Viewport/taskCon", "taskScroll", "rewardCon", "fillImg:img", "heartValue:txt","close:obj", "modelCon", "bg:raw", "tipDes:tmp", "modelCon2", "btn_buy:obj:img", -- "btn_buy/lb_btn_buy:tmp", "btn_buy/con_btn_buy_effect", "black_bg:obj", "black_bg/lb_price:tmp", } self:GetChildren(nodes) self:UpdateBaseView( ) end function ChildHeartTaskView:UpdateBaseView( ) lua_resM:setOutsideRawImage(self, self.bg_raw, GameResPath.GetViewBigBg("child_heart_bg_1186_601"), false) self.tipDes_tmp.text = string.format("任务每日%s刷新", HtmlColorTxt( "04:00", ColorUtil.GREEN_DARK)) local function bg_back_func( ... ) if self.background_wnd and self.background_wnd:GetComponent("RawImageExtend") then self:MoveUIToBack(self.background_wnd:GetComponent("RawImageExtend")) end self:MoveUIToBack(self.bg_raw) end if self.background_wnd then bg_back_func() else self.bg_back_func = bg_back_func end local open_day = ServerTimeModel:getInstance():GetOpenServerDay() self.btn_buy_obj:SetActive(open_day >= 6) -- 开服6天后开放这个 self.lb_price_tmp.text = "" if open_day >= 6 then SetAnchoredPositionY(self.con_btn_buy_effect, 2.5) self:AddUIEffect("ui_effect_shouchong05_2", self.con_btn_buy_effect, self.layer_name, nil, 0.9, false,nil,nil,nil,nil,nil,UIPartical.RenderingOther_List.UIBackward) end end function ChildHeartTaskView:AddEvent() local on_click = function ( click_obj ) if self.close_obj == click_obj then self:Close() elseif self.btn_buy_obj == click_obj then local cur_heart_value = self.child_info.heart_link_exp or 0 local buy_count = self.model:GetMaxHeartValue() - cur_heart_value if buy_count <= 0 then Message.show("同心值已满,请尽快领取奖励!") return end local price_cfg = Config.Goodsprice[260001] -- 同心值价值配在价格表 local per_heart_link_price = price_cfg.price local ask_str = string.format('%s 补充 %s点 同心值?', HtmlColorTxt(buy_count * per_heart_link_price, ColorUtil.YELLOW_DARK), HtmlColorTxt(buy_count, ColorUtil.YELLOW_DARK) ) local function ok_callback( ) self.model:Fire(ChildConst.CHILD_REQ_EVENT, 16506, 3, 0, 0) end local function use_function( toggle_tip_data,call_fun_sum ) if not self.model.recovery_toggle then GlobalEventSystem:Fire(EventName.OPEN_COM_TOGGLE_TIP_VIEW, toggle_tip_data) else call_fun_sum() end end local buy_tip_data = { gold_type = price_cfg.price_type,--货币类型 cost_price = buy_count * per_heart_link_price,--消耗金额 ok_callback = ok_callback,--成功 togglePriceStr = ask_str,--提示语 use_function = use_function,--最终调用 no_need_toggle = true, } CustomActivityModel:getInstance():BuyTips(buy_tip_data) end end AddClickEvent(self.close_obj, on_click) AddClickEvent(self.btn_buy_obj, on_click) -- 更新任务 local function updata_child_task_info_fun() self:UpdateTaskCon() end self.updata_child_task_info_id = self.model:Bind(ChildConst.UPDATA_CHILD_TASK_INFO, updata_child_task_info_fun) -- 更新同心值 local function update_heart_link_value() self:UpdateHeartLink( ) self:UpdateRewardCon( ) end self.update_heart_link_value_id = self.model:Bind(ChildConst.UPDATE_HEART_LINK_VALUE, update_heart_link_value) -- 更新同心奖励状态 local function update_heartlink_reward_status() self:UpdateRewardCon( ) end self.update_heartlink_reward_status_id = self.model:Bind(ChildConst.UPDATE_HEARTLINK_REWARD_STATUS, update_heartlink_reward_status) end -- 更新孩子模型 function ChildHeartTaskView:UpdateRoleModel( ) -- local child_sex = self.model:GetHeartTaskChildSex( ) SetLocalPositionX(self.modelCon, -248 + 82) SetLocalPositionX(self.modelCon2, -248 - 82) local show_figure_id = self.model:GetChildOriginalModelID(1) local res_data = { father_node = self, transform = self.modelCon, fashion_type = FuncOpenModel.TypeId.Child, figure_id = show_figure_id, ui_model_type = UIModelCommon.ModelType.BackModel, can_rotate = false, scale = 400 } FuncOpenModel:getInstance():SetModelRes(res_data) local show_figure_id = self.model:GetChildOriginalModelID(2) local res_data = { father_node = self, transform = self.modelCon2, fashion_type = FuncOpenModel.TypeId.Child, figure_id = show_figure_id, ui_model_type = UIModelCommon.ModelType.BackModel, can_rotate = false, scale = 400 } FuncOpenModel:getInstance():SetModelRes(res_data) end function ChildHeartTaskView:OpenSuccess() self:UpdateView() end function ChildHeartTaskView:UpdateView() self:UpdateHeartLink( ) self:UpdateTaskCon() self:UpdateRewardCon() self:UpdateRoleModel( ) end function ChildHeartTaskView:UpdateShowPrice( ) local open_day = ServerTimeModel:getInstance():GetOpenServerDay() local need_show = false if open_day >= 6 then local cur_heart_value = self.child_info.heart_link_exp or 0 local buy_count = self.model:GetMaxHeartValue() - cur_heart_value local price_cfg = Config.Goodsprice[260001] -- 同心值价值配在价格表 local per_heart_link_price = price_cfg.price if buy_count > 0 then need_show = true self.lb_price_tmp.text = WordManager:GetMoneyFaceStr( 2 ) .. HtmlColorTxt( (per_heart_link_price * buy_count), ColorUtil.YELLOW_DARK) end end self.black_bg_obj:SetActive(need_show) end -- 更新同心值 function ChildHeartTaskView:UpdateHeartLink( ) self.child_info = self.model:GetChildInfo() if not self.child_info then -- logWarn('=======Msh:ChildHeartTaskView.lua[67]====没有宝宝信息哦===') return end local info = self.child_info local exp = info.heart_link_exp or 0 exp = Mathf.Clamp(exp, 0, self.model:GetMaxHeartValue()) -- 当前同心值 self.heartValue_txt.text = exp -- 同心进度条 self.fillImg_img.fillAmount = exp / self.model:GetMaxHeartValue() if self.model:IsHeartValueMax() then SetImageGray(self.btn_buy_img, true) -- SetTMPSharedMaterial(self.lb_btn_buy_tmp, ShaderTools.TMPSharedMaterialType.FZZZOutlineDarkGrayBtn) else SetImageGray(self.btn_buy_img, false) -- SetTMPSharedMaterial(self.lb_btn_buy_tmp, ShaderTools.TMPSharedMaterialType.FZZZOutlineDarkOrangeBtn) end self:UpdateShowPrice() end -- 每日任务 function ChildHeartTaskView:UpdateTaskCon( ) local ITEM_HEIGHT = 83 local INTERVAL_X = 5 local count = 0 -- logWarn('=======Msh:ChildHeartTaskView.lua[97]=======') -- PrintTable(self.model:GetChildDailyTaskList()) local index = 0 for i, v in ipairs(self.model:GetChildDailyTaskList()) do if v.task_id ~= 11 then -- 11 是孩子培养任务 不需要显示 index = index + 1 local item = self.task_item_list[index] if item == nil then item = ChildMainTaskItem.New(self.taskCon) self.task_item_list[index] = item end item:SetData(v) -- item:SetAnchoredPosition(0, -(index - 1) * (INTERVAL_X + ITEM_HEIGHT)) end end -- SetSizeDeltaY(self.taskCon, index * (INTERVAL_X + ITEM_HEIGHT)) end -- 同心阶段奖励 function ChildHeartTaskView:UpdateRewardCon( ) --local reward_list = self.model:GetHeartRewardData( ) local FILLIMG_WIDTH = GetSizeDeltaX(self.fillImg) local PER_WIDTH = FILLIMG_WIDTH / self.model:GetMaxHeartValue() local click_callback = function (reward_id) self.model:Fire(ChildConst.CHILD_REQ_EVENT, 16539, 1, reward_id) end for heart_value, data in pairsByKeys(self.model:GetChildLinkHeartInfo()) do local item = self.reward_item_list[heart_value] if item == nil then item = ChildHeartRewardItem.New(self.rewardCon) self.reward_item_list[heart_value] = item end item:SetData(data, click_callback) item:SetAnchoredPosition( heart_value * PER_WIDTH, 0) end end function ChildHeartTaskView:SwitchTab( index ) end function ChildHeartTaskView:DestroySuccess( ) for i,v in pairs(self.task_item_list) do v:DeleteMe() end for i,v in pairs(self.reward_item_list) do v:DeleteMe() end if self.updata_child_task_info_id then self.model:UnBind(self.updata_child_task_info_id) self.updata_child_task_info_id = nil end if self.update_heart_link_value_id then self.model:UnBind(self.update_heart_link_value_id) self.update_heart_link_value_id = nil end if self.update_heartlink_reward_status_id then self.model:UnBind(self.update_heartlink_reward_status_id) self.update_heartlink_reward_status_id = nil end self:ClearUIEffect(self.con_btn_buy_effect) end