|
|
- SoulPowerItem = SoulPowerItem or BaseClass(BaseItem)
- local SoulPowerItem = SoulPowerItem
-
- function SoulPowerItem:__init()
- self.base_file = "soulPower"
- self.layout_file = "SoulPowerItem"
- self.model = SoulPowerModel:getInstance()
-
- self.old_lock_state = nil
-
- self:Load()
- end
-
- function SoulPowerItem:Load_callback()
- self.nodes = {
- "Icon:img:obj", "bg:img", "select:obj", "dizuo", "IconGray:img:obj", "next:obj",
- }
- self:GetChildren(self.nodes)
-
- SetImageGray(self.IconGray_img, true)
- self.select_obj:SetActive(true)
- SetAnchoredPositionY(self.select,35)
-
- self:AddEvents()
- if self.need_refreshData then
- self:BeforeUpdate()
- end
- end
-
- function SoulPowerItem:AddEvents( )
- local update_soul_power_view = function()
- if not self.is_loaded then return end
- if self.model.has_create_once then
- self:BeforeUpdate()
- end
- end
- self:BindEvent(self.model, SoulPowerConst.UPDATE_SOUL_POWER_VIEW, update_soul_power_view)
- end
-
- function SoulPowerItem:BeforeUpdate()
- local sp_grade, sp_lv = self.model:GetSoulPowerNowGradeLv()
-
- if self.index == sp_lv + 1 then
- self.next_obj:SetActive(true)
- else
- self.next_obj:SetActive(false)
- end
-
- if self.old_lock_state then
- self.old_lock_state = self.index > sp_lv
- SetImageGray(self.bg_img, true)
- self.in_anim_state = true
- self:DoActiveEffect()
- if self.delay_timer_1 then
- TimerQuest.CancelQuest(GlobalTimerQuest, self.delay_timer_1)
- self.delay_timer_1 = nil
- end
- local function delay_method( )
- self:UpdateView()
- self.in_anim_state = false
- end
- self.delay_timer_1 = setTimeout(delay_method, 0.5)
- else
- --之前就已经是激活状态且现在还是激活,那就不进行update了
- if self.old_active_state and self.index <= sp_lv then
- self.old_active_state = true
- else
- --如果还在播放激活特效动画,这个时候不允许update
- if not self.in_anim_state then
- self:UpdateView()
- end
- end
- end
- end
-
- function SoulPowerItem:UpdateView( )
- self:ClearUIEffect(self.dizuo)
-
- self:ClearUIEffect(self.Icon)
-
-
- if self.index >= 3 and self.index <= 6 then
- SetLocalScale(self.Icon,0.95,0.95,1)
- SetLocalScale(self.select,0.95,0.95,1)
- lua_resM:setImageSprite(self, self.bg_img, "soulPower_asset","soul_power_img_7",true)
- else
- SetLocalScale(self.Icon,1,1,1)
- SetLocalScale(self.select,1,1,1)
- lua_resM:setImageSprite(self, self.bg_img, "soulPower_asset","soul_power_img_8",true)
- end
-
- local sp_grade, sp_lv = self.model:GetSoulPowerNowGradeLv()
-
- if self.index <= sp_lv then
- -- SetImageGray(self.Icon_img, false)
- self.Icon_obj:SetActive(true)
- SetImageGray(self.bg_img, false)
- self.IconGray_obj:SetActive(false)
- else
- -- SetImageGray(self.Icon_img, true)
- self.Icon_obj:SetActive(false)
- SetImageGray(self.bg_img, true)
- self.IconGray_obj:SetActive(true)
- end
-
- -- if self.index == sp_lv + 1 then
- -- self.next_obj:SetActive(true)
- -- else
- -- self.next_obj:SetActive(false)
- -- end
-
-
- local function delay_method( )
- if self.index <= sp_lv then
- self:AddUIEffect("ui_hunlidizuo", self.dizuo, "UI", nil, 4, true)
- self:AddUIEffect("ui_hunliqiu", self.Icon, "UI", nil, 5, true)
- end
-
- -- self:AddUIEffect("ui_hunliqiudianliang", self.bg, "Activity", nil, 2, true)
- -- self:AddUIEffect("ui_hunliqiudizuo", self.bg, "Activity", nil, 2, true)
- end
- self.delay_timer_2 = setTimeout(delay_method, 0.02)
-
- --之前是否是未激活状态
- self.old_lock_state = self.index > sp_lv
- --之前是否是激活状态
- self.old_active_state = self.index <= sp_lv
-
-
- self:ArrowAnimation(0)
-
- end
-
- function SoulPowerItem:ArrowAnimation(time)
- local random_time = math.random(1.5,2.8)
- self:StopAnim()
- local call_fun = function ()
- local function onCompleted()
- self:ArrowAnimation(time)
- end
- self.tween_id3 =TweenLite.to(self, self.Icon,TweenLite.UiAnimationType.ANCHORED_POSY,50, random_time, onCompleted)
- end
- local onDelay = function( )
- self.tween_id2 =TweenLite.to(self, self.Icon,TweenLite.UiAnimationType.ANCHORED_POSY,15, random_time, call_fun)
- end
- self.arrow_timer_id = setTimeout(onDelay, time)
- end
-
- function SoulPowerItem: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 SoulPowerItem:DoActiveEffect( )
- self:ClearUIEffect(self.select)
- local sp_grade, sp_lv = self.model:GetSoulPowerNowGradeLv()
- if self.index == sp_lv then
- self:AddUIEffect("ui_hunliqiudianliang", self.select, "UI", nil, 4.5, false,nil,nil,nil,nil,1)
- end
- end
-
- function SoulPowerItem:SetData( data, index)
- self.data = data
- self.index = index
- if self.is_loaded then
- self.need_refreshData = false
- self:BeforeUpdate()
- else
- self.need_refreshData = true
- end
- end
-
- function SoulPowerItem:__delete( )
- self:StopAnim()
- self:ClearUIEffect(self.dizuo)
- self:ClearUIEffect(self.select)
- self:ClearUIEffect(self.Icon)
-
- if self.delay_timer_2 then
- TimerQuest.CancelQuest(GlobalTimerQuest, self.delay_timer_2)
- self.delay_timer_2 = nil
- end
- if self.delay_timer_1 then
- TimerQuest.CancelQuest(GlobalTimerQuest, self.delay_timer_1)
- self.delay_timer_1 = nil
- end
- end
|