源战役客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

204 lines
4.9 KiB

AdventureBookItem = AdventureBookItem or BaseClass(BaseItem)
local AdventureBookItem = AdventureBookItem
local math_abs = math.abs
AdventureBookItem.ITEM_OFFSET = 380
function AdventureBookItem:__init()
self.base_file = "adventureBook"
self.layout_file = "AdventureBookItem"
self.is_delay_callback = true
self.model = AdventureBookModel:getInstance()
self.need_refreshData = false
self.real_index = -1
self.is_lock = false
self.cur_scale = -1
self.drag_begin_x = 0
self.max_book_index = 10
self.curr_pos_x = 0
self:Load()
end
function AdventureBookItem:Load_callback()
self:LoadSuccess()
self:InitEvent()
if self.need_refreshData then
self:SetData(self.data)
end
end
function AdventureBookItem:LoadSuccess()
self.icon_img,
self.chapt_img,
self.state_img = self:GetChildImages({
"icon",
"chapt",
"state",
})
self.state_object,
self.lock_object,
self.select_object = self:GetChildGameObjects(
{
"state",
"lock",
"select",
})
self.lock_txt,
self.content_txt = self:GetChildTexts({
"lock/text",
"content",
})
end
function AdventureBookItem:InitEvent()
end
function AdventureBookItem:OnClickItem()
if not self.is_loaded then
return
end
if self.is_lock then
Message.show("暂未解锁本书")
else
self.model:Fire(AdventureBookModel.UPDATE_ADVENTURE_BOOK_DETAIL_VIEW, self.data.type, self.data.subtype)
end
end
function AdventureBookItem:SetData(data)
self.data = data
if not self.data then return end
if self.is_loaded then
local info = self.model:GetBookInfo(self.data.type, self.data.subtype)
if info then
self:SetLockState(false)
self.state_object:SetActive(true)
if info.status == 0 then --进行中
lua_resM:setImageSprite(self,self.state_img,"adventureBook_asset", "tyui_jxz")
elseif info.status == 1 then --可激活
lua_resM:setImageSprite(self,self.state_img,"adventureBook_asset", "tyui_kjh")
elseif info.status == 2 then --已完成
lua_resM:setImageSprite(self,self.state_img,"adventureBook_asset", "tyui_ywc")
end
self.content_txt.text = "获得" ..Trim(self.data.reward_name)
else
self:SetLockState(true)
self.state_object:SetActive(false)
self.content_txt.text = ""
end
local show_index = self.model:GetBookShowIndex(self.data.type)
if show_index == self.data.subtype then
self:SetItemScale(1)
self.select_object:SetActive(true)
else
self:SetItemScale(0.8)
self.select_object:SetActive(false)
end
self.max_book_index = TableSize(Config.Adventurebook)
lua_resM:setImageSprite(self,self.chapt_img,"adventureBook_asset", "zjui_title_" .. self.data.subtype,true)
lua_resM:setOutsideImageSprite(self, self.icon_img, GameResPath.GetImage("adventureBook","zjui_bg1_"..self.data.subtype),true)
else
self.need_refreshData = true
end
end
function AdventureBookItem:SetLockState(bool)
self.is_lock = bool
self.lock_object:SetActive(bool)
if bool then
self.icon_img.gray = true
local unlock = ErlangParser:GetInstance():Parse(self.data.unlock_condition)
if unlock and unlock[1] then
if unlock[1][1] == "book" then
local last_data = Config.Adventurebook[unlock[1][2].."@"..unlock[1][3]]
if last_data then
self.lock_txt.text = "激活"..Trim(last_data.name).."后解锁"
end
end
end
else
self.icon_img.gray = false
end
end
function AdventureBookItem:__delete()
end
function AdventureBookItem:SetItemScale(scale)
scale = scale > 0.8 and scale or 0.8
if self.cur_scale ~= scale then
self.cur_scale = scale
self:SetScale(scale)
end
end
function AdventureBookItem:DragBegin()
self:SetDragBeginX()
end
function AdventureBookItem:Drag(x,y)
if not self.is_loaded then
return
end
self:SetAnchoredPosition(self.drag_begin_x + x,0)
self.curr_pos_x = self.transform.anchoredPosition.x
if self.curr_pos_x < - AdventureBookItem.ITEM_OFFSET * 2 then
local new_pos_x = self.curr_pos_x + AdventureBookItem.ITEM_OFFSET * 4
self:SetAnchoredPosition(new_pos_x,0)
self:SetDragBeginX(new_pos_x - x)
local subtype = self.data.subtype + 4
if subtype > self.max_book_index then
subtype = subtype - self.max_book_index
end
local data = Config.Adventurebook[self.data.type .. "@" .. subtype]
if data then
self:SetData(data)
end
elseif self.curr_pos_x > AdventureBookItem.ITEM_OFFSET * 2 then
local new_pos_x = self.curr_pos_x - AdventureBookItem.ITEM_OFFSET * 4
self:SetAnchoredPosition(new_pos_x,0)
self:SetDragBeginX(new_pos_x - x)
local subtype = self.data.subtype - 4
if subtype < 1 then
subtype = subtype + self.max_book_index
end
local data = Config.Adventurebook[self.data.type .. "@" .. subtype]
if data then
self:SetData(data)
end
end
self:SetItemScale(1 - 0.2 * math_abs(self.curr_pos_x) / AdventureBookItem.ITEM_OFFSET)
end
function AdventureBookItem:DragEnd()
self:SetDragBeginX()
end
function AdventureBookItem:SetDragBeginX(x)
if not self.is_loaded then
return
end
self.drag_begin_x = x or self.transform.anchoredPosition.x
end