SwallowCoreAttrItem = SwallowCoreAttrItem or BaseClass(BaseItem)
|
|
local SwallowCoreAttrItem = SwallowCoreAttrItem
|
|
|
|
function SwallowCoreAttrItem:__init()
|
|
self.base_file = "bag"
|
|
self.layout_file = "SwallowCoreAttrItem"
|
|
self.model = BagModel:getInstance()
|
|
|
|
self:Load()
|
|
end
|
|
|
|
function SwallowCoreAttrItem:Load_callback()
|
|
self.nodes = {
|
|
"attr:tmp", "star:img:obj", "bg", "attrIcon:obj:img", "lockTips:tmp", "star/starRed:obj", "star/lock:obj",
|
|
}
|
|
self:GetChildren(self.nodes)
|
|
|
|
self:AddEvents()
|
|
if self.need_refreshData then
|
|
self:UpdateView()
|
|
end
|
|
end
|
|
|
|
function SwallowCoreAttrItem:AddEvents( )
|
|
local on_click = function ( click_obj )
|
|
if self.star_obj == click_obj then
|
|
self:DoUnlock()--激活
|
|
end
|
|
end
|
|
AddClickEvent(self.star_obj, on_click)
|
|
|
|
local function update_swallow_attr_show()
|
|
self:UpdateAttrShow()
|
|
end
|
|
self:BindEvent(self.model,BagModel.REFRESH_SWALLOW_INIT,update_swallow_attr_show)
|
|
self:BindEvent(self.model,BagModel.UPDATE_SWALLOW_ATTR_SHOW,update_swallow_attr_show)
|
|
end
|
|
|
|
function SwallowCoreAttrItem:DoUnlock( )
|
|
local can_unlock = self.model:SwallowCanUnlock(self.data.lv)
|
|
if can_unlock then
|
|
self.model:Fire(BagModel.REQUEST_PROTOCOL,15027)
|
|
end
|
|
end
|
|
|
|
function SwallowCoreAttrItem:UpdateView( )
|
|
self:SetSelfPosition()
|
|
self:UpdateAttrShow()
|
|
|
|
end
|
|
|
|
function SwallowCoreAttrItem:UpdateAttrShow( )
|
|
local is_locked = self.data.lv > self.model.swallow_active_lv
|
|
|
|
local can_unlock = self.model:SwallowCanUnlock(self.data.lv)
|
|
self.starRed_obj:SetActive(can_unlock)
|
|
|
|
if is_locked then
|
|
self.attrIcon_obj:SetActive(false)
|
|
lua_resM:setImageSprite(self, self.star_img, "bag_asset","bag_swallow_star_gray")
|
|
self.lock_obj:SetActive(true)
|
|
|
|
self.lockTips_tmp.text = string.format("Lv.%s 解锁",self.data.lv)
|
|
self.attr_tmp.text = ""
|
|
else
|
|
self.attrIcon_obj:SetActive(true)
|
|
lua_resM:setImageSprite(self, self.star_img, "bag_asset","bag_swallow_star")
|
|
self.lock_obj:SetActive(false)
|
|
|
|
local attr_data = stringtotable(self.data.attr_point)
|
|
self.lockTips_tmp.text = ""
|
|
self.attr_tmp.text = string.format("%s<color=%s>+%s</color>",WordManager:GetProperties(attr_data[1][1]),ColorUtil.WHITE,WordManager:GetPropertyValue(attr_data[1][1],attr_data[1][2]))
|
|
SetAttrIconByColorType(self, self.attrIcon_img, attr_data[1][1], nil, 3)
|
|
end
|
|
end
|
|
|
|
function SwallowCoreAttrItem:SetSelfPosition( )
|
|
if self.item_id == 1 then
|
|
self:SetAnchoredPosition(-80,118)
|
|
SetSizeDelta(self.star,82,82)
|
|
SetLocalPosition(self.star,105,35)
|
|
SetLocalScale(self.bg,-1,1,1)
|
|
elseif self.item_id == 2 then
|
|
self:SetAnchoredPosition(-248,23)
|
|
SetSizeDelta(self.star,65,65)
|
|
SetLocalPosition(self.star,102,22)
|
|
SetLocalScale(self.bg,-1,1,1)
|
|
elseif self.item_id == 3 then
|
|
self:SetAnchoredPosition(-240,-151)
|
|
SetSizeDelta(self.star,102,102)
|
|
SetLocalPosition(self.star,95,40)
|
|
SetLocalScale(self.bg,-1,1,1)
|
|
elseif self.item_id == 4 then
|
|
self:SetAnchoredPosition(129,-191)
|
|
SetSizeDelta(self.star,82,82)
|
|
SetLocalPosition(self.star,-102,33)
|
|
SetLocalScale(self.bg,1,1,1)
|
|
elseif self.item_id == 5 then
|
|
self:SetAnchoredPosition(240,-84)
|
|
SetSizeDelta(self.star,65,65)
|
|
SetLocalPosition(self.star,-105,27)
|
|
SetLocalScale(self.bg,1,1,1)
|
|
elseif self.item_id == 6 then
|
|
self:SetAnchoredPosition(283,32)
|
|
SetSizeDelta(self.star,102,102)
|
|
SetLocalPosition(self.star,-110,33)
|
|
SetLocalScale(self.bg,1,1,1)
|
|
end
|
|
|
|
if self.item_id >= 1 and self.item_id <= 3 then
|
|
SetAnchoredPosition(self.lockTips,-8,4)
|
|
SetAnchoredPosition(self.attr,22,4)
|
|
SetAnchoredPosition(self.attrIcon,-56,4)
|
|
else
|
|
SetAnchoredPosition(self.lockTips,14,4)
|
|
SetAnchoredPosition(self.attr,33,4)
|
|
SetAnchoredPosition(self.attrIcon,-45,4)
|
|
end
|
|
|
|
self:ArrowAnimation(0)
|
|
end
|
|
|
|
--图片上下移动
|
|
function SwallowCoreAttrItem:ArrowAnimation(time)
|
|
local end_y = 0
|
|
local start_y = 0
|
|
local anim_time = 0
|
|
if self.item_id == 1 then-- 118
|
|
end_y = 109
|
|
start_y = 120
|
|
anim_time = 1.8
|
|
elseif self.item_id == 2 then-- 23
|
|
start_y = 25
|
|
end_y = 15
|
|
anim_time = 1.9
|
|
elseif self.item_id == 3 then-- -151
|
|
end_y = -155
|
|
start_y = -145
|
|
anim_time = 1.7
|
|
elseif self.item_id == 4 then-- -191
|
|
start_y = -195
|
|
end_y = -186
|
|
anim_time = 2
|
|
elseif self.item_id == 5 then-- -84
|
|
end_y = -90
|
|
start_y = -79
|
|
anim_time = 2.1
|
|
elseif self.item_id == 6 then-- 32
|
|
start_y = 37
|
|
end_y = 27
|
|
anim_time = 1.9
|
|
end
|
|
self:StopAnim()
|
|
local call_fun = function ()
|
|
local function onCompleted()
|
|
self:ArrowAnimation(time)
|
|
end
|
|
self.tween_id3 =TweenLite.to(self, self.transform,TweenLite.UiAnimationType.ANCHORED_POSY,end_y,anim_time,onCompleted)
|
|
end
|
|
local onDelay = function( )
|
|
self.tween_id2 =TweenLite.to(self, self.transform,TweenLite.UiAnimationType.ANCHORED_POSY,start_y, anim_time, call_fun)
|
|
end
|
|
self.arrow_timer_id = setTimeout(onDelay, time)
|
|
end
|
|
|
|
function SwallowCoreAttrItem:StopAnim()
|
|
if self.tween_id2 then
|
|
TweenLite.Stop(self.tween_id2)
|
|
self.tween_id2 = nil
|
|
end
|
|
if self.tween_id3 then
|
|
TweenLite.Stop(self.tween_id3)
|
|
self.tween_id3 = nil
|
|
end
|
|
if self.arrow_timer_id then
|
|
GlobalTimerQuest:CancelQuest(self.arrow_timer_id)
|
|
self.arrow_timer_id = nil
|
|
end
|
|
end
|
|
|
|
function SwallowCoreAttrItem:SetData( data,item_id )
|
|
self.data = data
|
|
self.item_id = item_id
|
|
if self.is_loaded then
|
|
self.need_refreshData = false
|
|
self:UpdateView()
|
|
else
|
|
self.need_refreshData = true
|
|
end
|
|
end
|
|
|
|
function SwallowCoreAttrItem:__delete( )
|
|
self:StopAnim()
|
|
end
|