|
|
- ChildDressItem = ChildDressItem or BaseClass(BaseItem)
- function ChildDressItem:__init()
- self.base_file = "child"
- self.layout_file = "ChildDressItem"
- self.is_delay_callback = true
- -- self.use_local_view = true
- self.model = ChildModel:GetInstance()
- self:Load()
- end
-
- function ChildDressItem:Load_callback()
- self.nodes = {
- "bg/name_txt:obj:tmp",
- "bg:obj:img","bg/chosen_con:obj","bg/lock_con:obj","bg/active_con:obj","bg/dress_icon:obj","bg/red_dot:obj",
- "bg/dress_icon/dress_des:tmp",
- "bg/dressImg:img",
- }
- self:GetChildren(self.nodes)
-
- -- 进阶星星
- self.img_star_list = {}
- for i = 1, 5 do
- self.img_star_list[i] = self:GetChild("bg/stars/star" .. i):GetComponent("Image")
- end
-
- self:InitEvent()
- if self.need_refreshData then
- self:SetData(self.data,self.callback,self.index, self.check_effect)
- self:SetChosen(self.isChosen)
- self:SetRedDot(self.isRedDot)
- self:SetScaleNum(self.scaleNum)
- end
- end
-
- function ChildDressItem:InitEvent()
- local function onBtnClickHandler(target, x, y)
- if target == self.bg_obj then
- self.callback(self)
- end
- end
- AddClickEvent(self.bg_obj, onBtnClickHandler)
- end
-
- function ChildDressItem:SetData(data,callback,index, check_effect)
- self.data = data or self.data
- self.callback = callback or self.callback
- self.last_type = self.type
- self.type = nil
- self.index = index
- self.check_effect = check_effect
- local have_num = GoodsModel:getInstance():GetTypeGoodsNum(self.data.fashion_id) or 0
- local need_num = stringtotable(self.data.upgrade_cost)[1][3]
- if self.data.active == false and have_num >= need_num then --可激活
- self.type = ChildConst.ChildDressItemType.CanActive
- elseif self.data.active == true then -- 已经激活
- self.type = ChildConst.ChildDressItemType.isActive
- else --不可激活,锁
- self.type = ChildConst.ChildDressItemType.Lock
- end
- if self.is_loaded then
- self:UpdateView( )
- else
- self.need_refreshData = true
- end
- end
-
- function ChildDressItem:UpdateView( )
- local data = self.data
- if not self.data.is_vehicle then -- 除了载具
- -- 设置原画 原画是以模型id命名的
- local figure_id = self.model:GetFashionModelID( self.data.fashion_id )
- lua_resM:setOutsideImageSprite(self, self.dressImg_img, GameResPath.GetChildDressIcon(figure_id), true)
- self.dress_des_tmp.text = "穿戴中"
- else
- lua_resM:setOutsideImageSprite(self, self.dressImg_img, GameResPath.GetChildDressIcon(self.data.fashion_id), true)
- self.dress_des_tmp.text = "骑乘中"
- end
-
-
- -- local need_star_effect = false
- if self.check_effect then
- -- self.check_effect = false
- -- logWarn('=======Msh:ChildDressItem.lua[80]=======')
- -- print('Msh:ChildDressItem.lua[81] data', self.last_type)
- -- print('Msh:ChildDressItem.lua[81] data', self.type)
- if (not self.is_in_effect) and self.last_type and self.last_type ~= ChildConst.ChildDressItemType.isActive and self.type == ChildConst.ChildDressItemType.isActive then -- 可激活到激活
- self.is_in_effect = true
- need_star_effect = true
- local function call_back( )
- self.is_in_effect = false
- end
- self:ClearUIEffect(self.dressImg)
- self:AddUIEffect("ui_hunliqiudianliang", self.dressImg, "Activity", Vector3(0, 10 ,0), 4, false, 0.6, nil, call_back)
- end
- end
-
- self.chosen_con_obj:SetActive(false)
- -- self.lock_con_obj:SetActive(false)
- self.active_con_obj:SetActive(false)
- self.dress_icon_obj:SetActive(false)
- -- self.idle_txt_txt.text = "已解锁"
- ---激活
- if self.type == ChildConst.ChildDressItemType.CanActive then --可激活
- self.active_con_obj:SetActive(true)
- -- self.idle_txt_txt.text = "可激活"
- elseif self.type == ChildConst.ChildDressItemType.Lock then --不可激活,锁
- -- self.lock_con_obj:SetActive(true)
- -- self.idle_txt_txt.text = "暂未解锁"
- end
-
- if self.data.state == 1 then --穿戴中
- self.dress_icon_obj:SetActive(true)
- -- self.idle_txt_txt.text = "穿戴中"
- end
- self.name_txt_tmp.text = self.data.fashion_name or ""
-
- -- 设置进阶星星数
- local nowLevel = tonumber(self.data.lv)
- for i = 1, 5 do
- if i < nowLevel/2 then
- if self.check_effect and tonumber(self.img_star_list[i].fillAmount) < 1 then
- self:PlayStarEffect(self.img_star_list[i].transform, i)
- end
- self.img_star_list[i].gameObject:SetActive(true)
- self.img_star_list[i].fillAmount = 1
- elseif (i-1) < nowLevel/2 then -- 最后一个
- self.img_star_list[i].gameObject:SetActive(true)
- -- self.img_star_list[i].fillAmount = 1
- if nowLevel % 2 ~= 0 then -- 单数就是一半
- if self.check_effect and tonumber(self.img_star_list[i].fillAmount) < 0.5 then
- self:PlayStarEffect(self.img_star_list[i].transform, i)
- end
- self.img_star_list[i].fillAmount = 0.5
- else
- if self.check_effect and tonumber(self.img_star_list[i].fillAmount) < 1 then
- self:PlayStarEffect(self.img_star_list[i].transform, i)
- end
- self.img_star_list[i].fillAmount = 1
- end
- else
- self.img_star_list[i].gameObject:SetActive(false)
- self.img_star_list[i].fillAmount = 0
- end
- end
- self.check_effect = false
- end
-
- function ChildDressItem:PlayStarEffect( tran, i )
- self.showing_star_effect = self.showing_star_effect or {}
- if true then
- if not self.showing_star_effect[i] then
- local function call_back( )
- self.showing_star_effect[i] = false
- end
- self:ClearUIEffect(tran)
- self:AddUIEffect("ui_jinjiestar", tran, self.layer_name, nil, 1, false, nil, nil, call_back)
- self.showing_star_effect[i] = true
- end
- end
- end
-
- function ChildDressItem:SetChosen(bool)
- self.isChosen = bool
- if self.is_loaded then
- if bool then
- self.chosen_con_obj:SetActive(true)
- -- self.name_txt_obj:SetActive(false)
- else
- self.chosen_con_obj:SetActive(false)
- -- self.name_txt_obj:SetActive(true)
- end
- else
- self.need_refreshData = true
- end
- end
- function ChildDressItem:SetScaleNum(num)
- --[[
- self.scaleNum = num or 0.7
- if self.is_loaded then
- SetLocalScale(self.transform, self.scaleNum)
- if self.scaleNum == 0.99 then
- self.bg_img.color =Color(1,1,1,0.8)
- else
- self.bg_img.color =Color(1,1,1,1)
- end
- else
- self.need_refreshData = true
- end
- ]]
- end
- function ChildDressItem:SetRedDot(bool)
- self.isRedDot = bool
-
- if self.is_loaded then
- --print("============>>> YiRan:ChildDressItem [start:83] vehicle_id :",vehicle_id,"self.isRedDot:",self.isRedDot)
- self.red_dot_obj:SetActive(self.isRedDot)
- else
- self.need_refreshData = true
- end
- end
|