源战役客户端
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 
 

150 行
4.9 KiB

TreasureHouseTaskItem = TreasureHouseTaskItem or BaseClass(BaseItem)
local TreasureHouseTaskItem = TreasureHouseTaskItem
function TreasureHouseTaskItem:__init()
self.base_file = "treasureHouse"
self.layout_file = "TreasureHouseTaskItem"
self.model = TreasureHouseModel:GetInstance()
self:Load()
end
function TreasureHouseTaskItem:Load_callback()
self.nodes = {
"btn:obj:imgex", "goods_image:img", "desc_text:tmp", "cost_image:img:obj", "num_text:tmp", "bg", "cost_text:tmp",
"btn/btn_red:obj", "btn/btn_text:tmp",
}
self:GetChildren(self.nodes)
self:AddEvents()
if self.need_refreshData then
self:UpdateView()
end
end
function TreasureHouseTaskItem:AddEvents( )
local function on_click( )
if self.server_data then--有服务端的话 就要看看状态
if self.server_data.state == 0 then--未完成
if not self.is_buy then
local link = stringtotable(self.data.link) or {}
if TableSize(link) > 0 then
OpenFun.Open(link[1],link[2])
end
else--购买的走购买协议
if self.buy_type == 1 then--彩钻购买的
if GoodsModel:getInstance():IsJinEnough(self.buy_cost) then
self.model:Fire(TreasureHouseConst.REQ_TREASURE_HOUSE_SCMD, 10405, self.data.id)
else
local qc_data = {
price = self.buy_cost,
}
GlobalEventSystem:Fire(EventName.OPEN_RECHARGE_TIP_VIEW, true, qc_data)
end
else
self.model:Fire(TreasureHouseConst.REQ_TREASURE_HOUSE_SCMD, 10405, self.data.id)
end
end
elseif self.server_data.state == 1 then--已完成
if not self.is_buy then
self.model:Fire(TreasureHouseConst.REQ_TREASURE_HOUSE_SCMD, 10404, self.data.id)
else
self.model:Fire(TreasureHouseConst.REQ_TREASURE_HOUSE_SCMD, 10405, self.data.id)
end
elseif self.server_data.state == 2 then--已领取
Message.show("今天已经完成这个任务了哦", "fault")
end
else
if not self.is_buy then
local link = stringtotable(self.data.link) or {}
if TableSize(link) > 0 then
OpenFun.Open(link[1],link[2])
end
else--购买的走购买协议
self.model:Fire(TreasureHouseConst.REQ_TREASURE_HOUSE_SCMD, 10405, self.data.id)
end
end
end
AddClickEvent(self.btn_obj, on_click)
end
function TreasureHouseTaskItem:UpdateView( )
local desc = Trim(self.data.desc)
local details = stringtotable(self.data.details)
local cur_num = 0
local num = GoodsModel:getInstance():GetTypeGoodsNum(TreasureHouseConst.TREASURE_HOUSE_TICKET_ID)
local goods_icon = GoodsModel:getInstance():GetGoodsBasicByTypeId( TreasureHouseConst.TREASURE_HOUSE_TICKET_ID ).goods_icon
lua_resM:setOutsideImageSprite(self,self.goods_image_img,GameResPath.GetGoodsIcon(goods_icon),false)
local color_str = ColorUtil.RED_DARK
self.num_text_tmp.text = 1
if details[1] == "buy" then--如果是购买类型的 就要显示购买
self.is_buy = true
self.buy_cost = details[2][1][3]
self.buy_type = details[2][1][1]
cur_num = self.data.daily_max
color_str = ColorUtil.GREEN_DARK
self.btn_text_tmp.text = "购买"
self.cost_image_obj:SetActive(true)
lua_resM:setOutsideImageSprite(self,self.cost_image_img,GameResPath.GetGoodsIcon(details[2][1][2]),false)
self.cost_text_tmp.text = self.buy_cost
SetAnchoredPositionY(self.btn, 14)
else
self.btn_text_tmp.text = "去完成"
self.is_buy = false
self.cost_image_obj:SetActive(false)
self.cost_text_tmp.text = ""
SetAnchoredPositionY(self.btn, 0)
end
local str = string.format("%s(%s/%s)", desc, HtmlColorTxt(cur_num, color_str), self.data.daily_max)
self.btn_red_obj:SetActive(false)
self.btn_imgex.gray = false
if self.server_data then
local num = self.server_data.times
if self.is_buy then
if num == self.data.daily_max then
color_str = ColorUtil.RED_DARK
else
color_str = ColorUtil.GREEN_DARK
end
else
if num == self.data.daily_max then
color_str = ColorUtil.GREEN_DARK
end
end
str = string.format("%s(%s/%s)", desc, HtmlColorTxt(num, color_str), self.data.daily_max)
self.btn_red_obj:SetActive(self.server_data.state == 1)
self.btn_imgex.gray = self.server_data.state == 2
if self.server_data.state == 2 then
SetTMPSharedMaterial(self.btn_text_tmp,ShaderTools.TMPSharedMaterialType.FZZZOutlineDarkGrayBtn)
self.btn_text_tmp.text = "已完成"
elseif self.server_data.state == 1 then
self.btn_text_tmp.text = "完成"
SetTMPSharedMaterial(self.btn_text_tmp,ShaderTools.TMPSharedMaterialType.FZZZOutlineDarkOrangeBtn)
end
end
self.desc_text_tmp.text = str
end
function TreasureHouseTaskItem:SetData(index, data )
self.index = index
self.data = data
if self.is_loaded then
self.need_refreshData = false
self:UpdateView()
else
self.need_refreshData = true
end
end
function TreasureHouseTaskItem:SetServerData( data )
self.server_data = data
if self.is_loaded then
self.need_refreshData = false
self:UpdateView()
else
self.need_refreshData = true
end
end
function TreasureHouseTaskItem:__delete( )
end