PsionicWashAttrItem = PsionicWashAttrItem or BaseClass(BaseItem)
|
|
local PsionicWashAttrItem = PsionicWashAttrItem
|
|
local WordManager = WordManager
|
|
|
|
function PsionicWashAttrItem:__init(parent_wnd,prefab_asset,layer_name)
|
|
self.base_file = "psionic"
|
|
self.layout_file = "PsionicWashAttrItem"
|
|
self.parent_wnd = parent_wnd
|
|
self.layer_name = layer_name
|
|
self.last_slot = 0
|
|
self.last_val_data = 0
|
|
self.no_effect = true
|
|
self.model = PsionicModel:getInstance()
|
|
self:Load()
|
|
end
|
|
|
|
function PsionicWashAttrItem:Load_callback()
|
|
local nodes = {
|
|
"attr_icon:img",
|
|
"fill:img",
|
|
"attr_val:tmp", "attr_name:tmp",
|
|
"attr_effect_con",
|
|
}
|
|
self:GetChildren(nodes)
|
|
|
|
self:AddEvents()
|
|
if self.need_refreshData then
|
|
self:UpdateView()
|
|
end
|
|
end
|
|
|
|
function PsionicWashAttrItem:AddEvents( )
|
|
|
|
end
|
|
|
|
-- 需特殊处理隐藏时的特效表现
|
|
function PsionicWashAttrItem:SetVisible(state, force_hide)
|
|
BaseItem.SetVisible(self, state, force_hide)
|
|
if not state then
|
|
self:ClearUIEffect(self.attr_effect_con)
|
|
self.showing_attr_effect = false
|
|
end
|
|
end
|
|
|
|
function PsionicWashAttrItem:SetData( slot, data, cur_attr_val )
|
|
if self.last_slot ~= slot then -- 切换槽位时清空数据
|
|
self.last_val_data = 0
|
|
self.last_slot = slot
|
|
self.no_effect = true
|
|
end
|
|
self.data = data
|
|
self.cur_attr_val = cur_attr_val -- 当前属性值
|
|
if self.is_loaded then
|
|
self.need_refreshData = false
|
|
self:UpdateView()
|
|
else
|
|
self.need_refreshData = true
|
|
end
|
|
end
|
|
|
|
function PsionicWashAttrItem:UpdateView( )
|
|
if self.data then
|
|
SetAttrIconByColorType(self, self.attr_icon_img, self.data[1], true, 1)
|
|
self.fill_img.fillAmount = self.last_val_data / self.data[2]
|
|
local temp_last_val_data = self.last_val_data
|
|
self.attr_name_tmp.text = WordManager:GetProperties(self.data[1])
|
|
local function final_result()
|
|
self.attr_val_tmp.text = string.format("<color=%s>%s</color>/%s", ColorUtil.GREEN_DARK,
|
|
WordManager:GetPropertyValue(self.data[1], self.cur_attr_val), WordManager:GetPropertyValue(self.data[1], self.data[2]))
|
|
self.fill_img.fillAmount = self.cur_attr_val / self.data[2]
|
|
end
|
|
if temp_last_val_data == self.cur_attr_val then -- 值没有变化,直接用最终结果
|
|
final_result()
|
|
else
|
|
local function duration_callback(percent)
|
|
if percent < 1 then
|
|
self.attr_val_tmp.text = string.format("<color=%s>%s</color>/%s", ColorUtil.GREEN_DARK,
|
|
WordManager:GetPropertyValue(self.data[1], (self.cur_attr_val - temp_last_val_data) * percent + temp_last_val_data),
|
|
WordManager:GetPropertyValue(self.data[1], self.data[2]))
|
|
else
|
|
final_result()
|
|
end
|
|
end
|
|
local function end_callback()
|
|
duration_callback(1)
|
|
end
|
|
local last_progress = self.cur_attr_val / self.data[2]
|
|
ImageProgressAction(self.fill, 0, last_progress, 0.5, duration_callback, end_callback)
|
|
-- 出现属性变化的洗练item需要每次都播放特效
|
|
if not self.no_effect and not self.showing_attr_effect then
|
|
local function call_back()
|
|
self.showing_attr_effect = false
|
|
end
|
|
self:ClearUIEffect(self.attr_effect_con)
|
|
self:AddUIEffect("ui_jinjiejindu", self.attr_effect_con, self.layer_name, Vector3(-130,0,0), 1, false, 0.75, nil, call_back)
|
|
self.showing_attr_effect = true
|
|
end
|
|
end
|
|
self.last_val_data = self.cur_attr_val
|
|
-- 加载完第一次后才可以播放特效
|
|
self.no_effect = false
|
|
end
|
|
end
|
|
|
|
function PsionicWashAttrItem:__delete( )
|
|
self:ClearUIEffect(self.attr_effect_con)
|
|
end
|