源战役客户端
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 
 
 

244 řádky
7.8 KiB

PetSupportRankItem = PetSupportRankItem or BaseClass(BaseItem)
local PetSupportRankItem = PetSupportRankItem
function PetSupportRankItem:__init()
self.base_file = "pet"
self.layout_file = "PetSupportRankItem"
self.model = PetModel:getInstance()
self:Load()
end
function PetSupportRankItem:Load_callback()
self.nodes = {
"bg:img",
"rareBg:img","raceIcon:img","petIcon:img",
-- "progress:img",
-- "supporValue:tmp",--声援率
"name:tmp",
"roleCon:obj",
"roleCon/roleName:tmp", "roleCon/vipCon", "roleCon/headCon",
"des:tmp",
"rankBg:img",
"rankNum:tmp",
"rewardBtn:obj:img",
"race:tmp",
"noneTip:obj",
"rewardBtn/rewardRed:obj",
--------------------
"roleCon/designation_con/name_text:tmp",
"roleCon/designation_con/effect",
"roleCon/designation_con:obj",
"roleCon/designation_con/designation_small_image:img:obj",
"roleCon/designation_con/designation_image:img:obj", "petBg:img",
}
self:GetChildren(self.nodes)
lua_resM:setOutsideImageSprite(self, self.bg_img, GameResPath.GetPetImage("pet_support_rank_item_di"))
self.roleItem = HeadRoleItem.New(self.headCon)
self.roleItem:SetItemSize(67,67)
self.vipItem = RoleVipItem.New(self.vipCon)
self:AddEvents()
if self.need_refreshData then
self:UpdateView()
end
end
function PetSupportRankItem:AddEvents( )
local on_click = function ( click_obj )
if self.rewardBtn_obj == click_obj then
if self.reward_state == 0 then
self.model:Fire(PetConst.REQUEST_CCMD_EVENT,16315,self.data.pet_id)
local rank_cfg = self.model:GetPetSupportRankCfg(self.data.rank)
local reward_kv_cfg = stringtotable(rank_cfg.server_reward)
local data = {}
data.award = reward_kv_cfg
data.not_show_anim = true
GlobalEventSystem:Fire(EventName.OPEN_COM_AWARD_RESULT_VIEW,data)
elseif self.reward_state == 1 then
Message.show("已领过奖励")
end
end
end
AddClickEvent(self.rewardBtn_obj, on_click)
local function onUpdateRewardState()
self:UpdateRewardState()
end
self:BindEvent(self.model, PetConst.UPDATE_RANK_REWARD_STATE, onUpdateRewardState)
end
function PetSupportRankItem:UpdateView( )
--排名
if self.data.rank>=1 and self.data.rank<=3 then
self.rankNum_tmp.text = ""
lua_resM:setImageSprite(self,self.rankBg_img,"common_asset","com_rank_4_"..self.data.rank,true)
else
self.rankNum_tmp.text = self.data.rank
lua_resM:setImageSprite(self,self.rankBg_img,"uiComponent_asset","com_empty")
end
-- --声援率
-- self.supporValue_tmp.text = string.format("%0.1f",self.data.support_ratio/100).."%"
-- self.progress_img.fillAmount = (self.data.support_ratio/100)/100
--宠物信息
local pet_cfg = self.model:GetPetCfg(self.data.pet_id, 1)
self.name_tmp.text = Trim(pet_cfg.pet_name)
-- ..PetConst.PetRace[pet_cfg.pet_race].color_str
-- ..PetConst.PetRace[pet_cfg.pet_race].str2
-- .."</color>"
self.race_tmp.text = PetConst.PetRace[pet_cfg.pet_race].str1
lua_resM:setImageSprite(self,self.petBg_img,"pet_asset","pet_rare_bg_"..pet_cfg.rare_degree)
lua_resM:setImageSprite(self,self.raceIcon_img,"pet_asset","pet_race_"..pet_cfg.pet_race,true)
lua_resM:setImageSprite(self,self.rareBg_img,"pet_asset","pet_rare_"..pet_cfg.rare_degree)
lua_resM:setOutsideImageSprite(self, self.petIcon_img, GameResPath.GetPetImage("pet_"..self.data.pet_id.."_1"))
--属性最高拥有者
-- self.roleName_tmp.text = self.data.player_name
if self.data.player_id == 0 then
self.noneTip_obj:SetActive(true)
self.roleCon_obj:SetActive(false)
else
self.noneTip_obj:SetActive(false)
self.roleCon_obj:SetActive(true)
self.vipItem:SetData(self.data.vip_flag,self.data.sup_vip_type)
if self.data.vip_flag == 0 then
SetAnchoredPositionX(self.roleName,42)
else
SetAnchoredPositionX(self.roleName,79)
end
--玩家数据
local head_data = {
vo = {
id = self.data.player_id,
sex = self.data.sex,
profile_photo_id = self.data.photo_id,
dress_board_id = self.data.dress_id,
}
}
self.roleItem:SetData(head_data)
if self.data.server_num == 0 then
self.roleName_tmp.text = self.data.player_name
else
self.roleName_tmp.text = GetCSLongName(self.data.player_name,self.data.server_num)
end
end
local rank_cfg = self.model:GetPetSupportRankCfg(self.data.rank)
if rank_cfg then
--描述性语句
local des_msg = rank_cfg and Trim(rank_cfg.pet_expression) or ""
self.des_tmp.text = " "..des_msg
else
self.des_tmp.text = string.format("区区第%s,好气哦!",WordManager:getHanZiNumber(self.data.rank))
end
--前三称号
if self.data.rank>=1 and self.data.rank<=3 then
local top_designation = rank_cfg.top_designation
self.designation_con_obj:SetActive(true)
self.designation_small_image_obj:SetActive(false)
self.designation_image_obj:SetActive(false)
self.name_text_tmp.text = ""
cc.ActionManager:getInstance():removeAllActionsFromTarget(self.designation_image)
local dsgt_cfg = Config.Dsgt[top_designation]
if self.designation_image_obj then
self.designation_image_obj:SetActive(false)
end
if dsgt_cfg then
if dsgt_cfg.type == 1 then--文字称号(文字称号也用图片了)
lua_resM:setOutsideImageSprite(self, self.designation_small_image_img, GameResPath.GetDesignImage(dsgt_cfg.id), true)
self.designation_small_image_obj:SetActive(true)
elseif dsgt_cfg.type == 2 then
lua_resM:setOutsideImageSprite(self, self.designation_image_img, GameResPath.GetDesignImage(dsgt_cfg.id), true)
self.designation_image_obj:SetActive(true)
elseif dsgt_cfg.type == 3 then
if not self.dynamic_image_obj then
self.dynamic_image_obj = UiFactory.createChild(self.designation_image, UIType.Image, "dynamic_image")
self.dynamic_image_img = self.dynamic_image_obj:GetComponent("Image")
self.dynamic_image = self.dynamic_image_obj.transform
SetAnchoredPosition(self.dynamic_image,0,0)
else
self.dynamic_image_obj:SetActive(true)
end
SetSizeDelta(self.designation_image, 210*0.8,90*0.8)
self.designation_image_obj:SetActive(true)
local data = DeepCopy(DesignationModel:GetInstance():GetDynamicDesignationCFG(top_designation))
for i,v in ipairs(data) do
v.not_auto_size = true
end
local res = Split(data[1].res,"_")--分割出来配置 然后取文字
local font_res = res[1] or ""
lua_resM:setImageSprite(self, self.dynamic_image_img, data[1].ab, font_res.."_font", false)
local action = cc.Animation.New(data,0.15)
cc.ActionManager:getInstance():addAction(cc.RepeatForever.New(action),self.designation_image.transform)
end
end
else
self.designation_con_obj:SetActive(false)
cc.ActionManager:getInstance():removeAllActionsFromTarget(self.designation_image)
end
self:UpdateRewardState()
end
function PetSupportRankItem:UpdateRewardState( )
--领奖状态
self.reward_state = 0 --0未领取 1-已领取
local reward_data = self.model:GetPetRankRewardData()
for k,v in pairs(reward_data) do
if v.pet_id == self.data.pet_id then
self.reward_state = v.is_received
end
end
if self.data.rank>=1 and self.data.rank<=3 then
self.rewardBtn_obj:SetActive(true)
if self.reward_state == 0 then
SetImageGray(self.rewardBtn_img, false)
self.rewardRed_obj:SetActive(true)
elseif self.reward_state == 1 then
SetImageGray(self.rewardBtn_img, true)
self.rewardRed_obj:SetActive(false)
end
else
self.rewardBtn_obj:SetActive(false)
end
end
function PetSupportRankItem:SetData(data)
self.data = data
if self.is_loaded then
self.need_refreshData = false
self:UpdateView()
else
self.need_refreshData = true
end
end
function PetSupportRankItem:__delete( )
cc.ActionManager:getInstance():removeAllActionsFromTarget(self.designation_image)
if self.roleItem then
self.roleItem:DeleteMe()
self.roleItem = nil
end
if self.vipItem then
self.vipItem:DeleteMe()
self.vipItem = nil
end
end