PetSupportNormalItem = PetSupportNormalItem or BaseClass(BaseItem) local PetSupportNormalItem = PetSupportNormalItem function PetSupportNormalItem:__init() self.base_file = "pet" self.layout_file = "PetSupportNormalItem" self.model = PetModel:getInstance() self:Load() end function PetSupportNormalItem:Load_callback() self.nodes = { "bg:obj:img", "rareBg:img:obj",--稀有度背景标识 "petIcon:img",--宠物图标 "con_star:obj",--星星容器 "con_star/star2:img","con_star/star5:img","con_star/star1:img","con_star/star3:img","con_star/star4:img", "lockTipCon/tips:tmp", "lv:tmp", "noneBg:obj", "addImg:obj", "lockTipCon:obj", "lvBg:obj", "starBg:obj", } self:GetChildren(self.nodes) self.star = { [1] = self.star1_img, [2] = self.star2_img, [3] = self.star3_img, [4] = self.star4_img, [5] = self.star5_img } self:AddEvents() if self.need_refreshData then self:UpdateView() end end function PetSupportNormalItem:AddEvents( ) local on_click = function ( click_obj ) if self.bg_obj == click_obj then--自身的点击按钮,打开上阵选择界面 if self.is_slot_unlocked then self.model:Fire(PetConst.OPEN_PET_SUPPORT_CHOOSE_VIEW,self.support_slot) else--还没解锁这个槽位 -- self.model:Fire(PetConst.OPEN_SUPPORT_UNLOCK_VIEW,self.support_slot)--弹出解锁提示框 end end end AddClickEvent(self.bg_obj, on_click,LuaSoundManager.SOUND_UI.NONE) --上阵操作后刷新 local on_update_item = function(support_slot,old_support_slot) if self.support_slot == support_slot then local new_data = self.model:GetPetSupportDataBySlot(support_slot) self.data = new_data or 0 local need_play_effect = false if old_support_slot and old_support_slot == 0 then need_play_effect = true end self:UpdateView(need_play_effect) end end self:BindEvent(self.model, PetConst.UPDATE_SUPPORT_ITEM, on_update_item) --宠物喂养升级之后刷新等级 local pet_feed = function(vo) if not self.is_loaded then return end if not self.data or self.data == 0 then return end if vo.pet_id == self.data.pet_id then self.lv_tmp.text = vo.pet_lv end end self:BindEvent(self.model, PetConst.PET_FEED, pet_feed) end function PetSupportNormalItem:UpdateView(need_play_effect) if not self.data or self.data == 0 then--无上阵 self.con_star_obj:SetActive(false) self.starBg_obj:SetActive(false) lua_resM:setImageSprite(self, self.petIcon_img, "uiComponent_asset","com_empty") --判断是否已解锁这个位置 local support_slot_cfg = self.model:GetPetSupportSlotCfg(self.support_slot) local sum_stars = self.model:CountPetStars() if sum_stars >= support_slot_cfg.open_sum_star then--已解锁 self.is_slot_unlocked = true--标记为已解锁 self.lockTipCon_obj:SetActive(false) self.noneBg_obj:SetActive(false) self.addImg_obj:SetActive(true) else self.is_slot_unlocked = false self.lockTipCon_obj:SetActive(true) self.tips_tmp.text = string.format("<#ff203a>%s/%s", sum_stars, support_slot_cfg.open_sum_star) self.noneBg_obj:SetActive(true) self.addImg_obj:SetActive(false) end self.lv_tmp.text = "" self.lvBg_obj:SetActive(false) self.rareBg_obj:SetActive(false) lua_resM:setImageSprite(self,self.bg_img,"pet_asset","pet_item_bg_big") else self.is_slot_unlocked = true--标记为已解锁 --获取宠物相关数据 local pet_data = self.model:GetPetListById(self.data.pet_id) local pet_cfg = self.model:GetPetCfg(pet_data.pet_id, pet_data.pet_star) lua_resM:setOutsideImageSprite(self, self.petIcon_img, GameResPath.GetPetImage("pet_"..self.data.pet_id.."_"..pet_data.pet_stage),false)--宠物icon --背景:稀有度、上阵、解锁 lua_resM:setImageSprite(self,self.rareBg_img,"pet_asset","pet_rare_"..pet_cfg.rare_degree) lua_resM:setImageSprite(self,self.bg_img,"pet_asset","pet_rare_bg_"..pet_cfg.rare_degree) --星星 self.con_star_obj:SetActive(true) self.starBg_obj:SetActive(true) local max_star = self.model:GetMaxStarInStage(pet_data.pet_id,pet_data.pet_stage) local show_star = self.model:GetNowShowPetStar(pet_data.pet_star) for i=1,show_star do lua_resM:setImageSprite(self, self.star[i], "pet_asset", PetConst.stage_message[pet_data.pet_stage].star_res,true) self.star[i].gameObject:SetActive(true) end for i=show_star+1,max_star do self.star[i].gameObject:SetActive(false) end --提示文本 self.tips_tmp.text = "" self.lv_tmp.text = "LV."..pet_data.pet_lv self.lvBg_obj:SetActive(true) self.noneBg_obj:SetActive(false) self.addImg_obj:SetActive(false) self.rareBg_obj:SetActive(true) if need_play_effect then self:AddUIEffect("ui_hunliqiudianliang", self.bg, "UI", nil, 4, false, nil, false) end end end function PetSupportNormalItem:SetData(support_slot,data) self.support_slot = support_slot self.data = data if self.is_loaded then self.need_refreshData = false self:UpdateView() else self.need_refreshData = true end end function PetSupportNormalItem:__delete( ) self:ClearUIEffect(self.bg) end