-- <*
|
|
-- @Author: Saber
|
|
-- @Description: 圣物进阶页签界面
|
|
-- *>
|
|
PsionicAdvanceView = PsionicAdvanceView or BaseClass(BaseItem)
|
|
local PsionicAdvanceView = PsionicAdvanceView
|
|
|
|
function PsionicAdvanceView:__init(parent_wnd,prefab_asset,layer_name)
|
|
self.base_file = "psionic"
|
|
self.layout_file = "PsionicAdvanceView"
|
|
self.parent_wnd = parent_wnd
|
|
self.layer_name = layer_name
|
|
self.star_list = {}
|
|
self.attr_item = {}
|
|
self.upgrade_need_num = 0 -- 本次升级需要的材料数
|
|
self.upgrade_auto_buy = false -- 升阶自动购买
|
|
self.last_slot_exp = 0
|
|
self.last_slot_lv = 0
|
|
self.is_animating = false -- 进度动画中
|
|
self.model = PsionicModel:getInstance()
|
|
self.goods_model = GoodsModel:getInstance()
|
|
self:Load()
|
|
end
|
|
|
|
function PsionicAdvanceView:Load_callback()
|
|
local nodes = {
|
|
"upgrade_btn:obj",
|
|
"upgrade_auto_btn:obj",
|
|
"break_btn:obj",
|
|
"ques_btn:obj",
|
|
"progress_fill:img",
|
|
"tips:tmp",
|
|
-- 属性容器
|
|
"attr_scroll", "attr_scroll/Viewport/attr_con",
|
|
-- 等级,经验
|
|
"level:tmp",
|
|
"exp_val:tmp",
|
|
-- 红点
|
|
"upgrade_btn/upgrade_red:obj",
|
|
"upgrade_auto_btn/upgrade_auto_red:obj",
|
|
"break_btn/break_red:obj", "break_btn/break_btn_lb:tmp",
|
|
"power:txt",
|
|
-- 进阶素材容器
|
|
"cost_item_con", "cost_item_name:tmp", "cost_item_num:tmp",
|
|
"advance_lv_effect_con",
|
|
}
|
|
self:GetChildren(nodes)
|
|
self.break_btn_lb_tmp.text = "前往突破"
|
|
self.break_red_obj:SetActive(false)
|
|
self.cost_item = UIObjPool:getInstance():PopItem(UIObjPool.UIType.AwardItem, self.cost_item_con)
|
|
self.cost_item:SetAnchoredPosition(0, 0)
|
|
self.cost_item:SetItemSize(62, 62)
|
|
self.cost_item:SetVisible(false)
|
|
|
|
self:AddEvents()
|
|
if self.need_refreshData then
|
|
self:UpdateView()
|
|
end
|
|
end
|
|
|
|
-- 需特殊处理隐藏时的特效表现
|
|
function PsionicAdvanceView:SetVisible(state, force_hide)
|
|
BaseItem.SetVisible(self, state, force_hide)
|
|
if not state then
|
|
self:ClearUIEffect(self.advance_lv_effect_con)
|
|
self.showing_lv_effect = false
|
|
if self.attr_item_creator then
|
|
self.attr_item_creator:IterateItems(function( item, i )
|
|
self:ClearUIEffect(item.attr_effect_con)
|
|
item.showing_attr_effect = false
|
|
end)
|
|
end
|
|
end
|
|
end
|
|
|
|
function PsionicAdvanceView:AddEvents( )
|
|
local function click_event(target, x, y)
|
|
if target == self.upgrade_btn_obj then -- 升阶
|
|
self:OnUpgradeBtnClick(false, false)
|
|
elseif target == self.upgrade_auto_btn_obj then -- 一键升阶
|
|
self:OnUpgradeBtnClick(false, true)
|
|
elseif target == self.break_btn_obj then -- 突破
|
|
if self.data then
|
|
self.model:Fire(PsionicConst.OPEN_MAIN_VIEW, true, PsionicConst.TabId.PWash) -- 切换到洗练界面
|
|
end
|
|
-- self:OnUpgradeBtnClick(true)
|
|
elseif target == self.ques_btn_obj then -- 问号
|
|
GlobalEventSystem:Fire(EventName.OPEN_INSTRUCTION_VIEW, 13900)
|
|
end
|
|
end
|
|
AddClickEvent(self.upgrade_btn_obj, click_event)
|
|
AddClickEvent(self.upgrade_auto_btn_obj, click_event)
|
|
AddClickEvent(self.break_btn_obj, click_event)
|
|
AddClickEvent(self.ques_btn_obj, click_event)
|
|
|
|
local function update_advance_red(tab_id)
|
|
if not tab_id or tab_id == PsionicConst.TabId.PAdvance then
|
|
self:UpdateLevelData(true) -- 有可能是道具刷新了,保险起见还是多刷新一次等级数据
|
|
self:UpdateAdvanceRed()
|
|
end
|
|
end
|
|
self:BindEvent(self.model, PsionicConst.UPDATE_RED_BY_TABID, update_advance_red)
|
|
|
|
local function update_slot_data(pos)
|
|
if pos and self.data and self.data.subtype == pos then
|
|
self:UpdateView(true)
|
|
end
|
|
end
|
|
self:BindEvent(self.model, PsionicConst.UPDATE_SLOT_DATA, update_slot_data)
|
|
end
|
|
|
|
-- 传入改装备的服务器数据 data:装备vo (GoodsModel:GetPsionicEquipBySlot)
|
|
function PsionicAdvanceView:SetData( data )
|
|
self.data = data
|
|
if self.is_loaded then
|
|
self.need_refreshData = false
|
|
self:UpdateView()
|
|
else
|
|
self.need_refreshData = true
|
|
end
|
|
end
|
|
|
|
function PsionicAdvanceView:UpdateView(show_exp_anim)
|
|
-- self.upgrade_auto_buy = self.auto_buy_tog.isOn
|
|
if self.data then
|
|
self:UpdateLevelData(show_exp_anim)
|
|
self:UpdateAttrItem(show_exp_anim)
|
|
self:UpdateAdvanceRed()
|
|
end
|
|
end
|
|
|
|
-- 更新等级信息
|
|
function PsionicAdvanceView:UpdateLevelData(show_exp_anim)
|
|
self.cur_equip_grade_cfg = self.model:GetPsionicEquipGradeCfg(self.data.type_id)
|
|
self.slot_data = self.model:GetPsionicSlotData(self.data.subtype)
|
|
self.cur_exp_cfg = Config.Nucleonlv[self.slot_data.lv]
|
|
self.advance_cost_cfg = nil
|
|
|
|
local next_lv = self.cur_exp_cfg.next
|
|
self.next_exp_cfg = Config.Nucleonlv[next_lv]
|
|
-- 存在下一等级且阶段相同,则可以直接升级,否则需要提示转到突破
|
|
local has_next = next_lv ~= 0 and self.next_exp_cfg
|
|
self:UpdateAdvanceProgress(show_exp_anim)
|
|
-- 加载消费道具
|
|
self.advance_cost_cfg = stringtotable(self.cur_exp_cfg.cost)[1]
|
|
local typeId, lock = self.goods_model:GetMappingTypeId(self.advance_cost_cfg[1], self.advance_cost_cfg[2])
|
|
local has_num = self.goods_model:GetTypeGoodsNum(typeId)
|
|
self.cost_item:SetData(typeId, 0, nil, nil, lock)
|
|
self.cost_item:SetVisible(true)
|
|
self.cost_item_name_tmp.text = self.goods_model:getGoodsName(typeId, true, true)
|
|
self.cost_item_num_tmp.text = string.format("剩余数量:<color=%s>%s</color>",
|
|
has_num > 0 and ColorUtil.GREEN_DARK or ColorUtil.RED_DARK, has_num)
|
|
local cost_goods_value = Config.Nucleonkv["nucleon_equip_value"].value
|
|
local need_num = math.ceil((self.cur_exp_cfg.exp - self.slot_data.exp) / cost_goods_value)
|
|
-- 缓存升级所需材料数
|
|
self.upgrade_need_num = need_num
|
|
-- 更新道具表现和按钮
|
|
local is_exp_max = self.slot_data.exp >= self.cur_exp_cfg.exp
|
|
local show_break = self.next_exp_cfg.grade > self.cur_exp_cfg.grade and is_exp_max or false
|
|
self.upgrade_auto_btn_obj:SetActive(not show_break)
|
|
self.upgrade_btn_obj:SetActive(not show_break)
|
|
self.break_btn_obj:SetActive(has_next and show_break)
|
|
end
|
|
|
|
function PsionicAdvanceView:UpdateAdvanceProgress(show_anim)
|
|
local next_lv = self.cur_exp_cfg.next -- 这里还需要判断是否已经满级
|
|
local function final_result()
|
|
self.level_tmp.text = string.format("Lv.%s", self.slot_data.lv)
|
|
self.exp_val_tmp.text = next_lv == 0 and self.slot_data.exp == self.cur_exp_cfg.exp and "MAX"
|
|
or string.format("%s / %s", self.slot_data.exp, self.cur_exp_cfg.exp)
|
|
self.progress_fill_img.fillAmount = self.slot_data.exp / self.cur_exp_cfg.exp
|
|
end
|
|
if show_anim then
|
|
if self.last_slot_exp == self.slot_data.exp and self.last_slot_lv == self.slot_data.lv then -- 经验和等级都没有变化,则啥也不做
|
|
return
|
|
end
|
|
-- 文本的表现比较恶心,要做很多计算
|
|
local temp_lv, temp_exp = self.last_slot_lv, self.last_slot_exp
|
|
local need_exp, add_exp = 0, 0
|
|
local target_lv, target_exp = self.slot_data.lv, self.slot_data.exp
|
|
local lv_cfg
|
|
for i = temp_lv, target_lv do
|
|
if target_lv == temp_lv then
|
|
add_exp = target_exp - temp_exp
|
|
break
|
|
end
|
|
lv_cfg = Config.Nucleonlv[i]
|
|
need_exp = need_exp + lv_cfg.exp
|
|
if i == temp_lv then
|
|
add_exp = add_exp + lv_cfg.exp - self.last_slot_exp
|
|
elseif i == target_lv then
|
|
add_exp = add_exp + target_exp
|
|
else
|
|
add_exp = add_exp + lv_cfg.exp
|
|
end
|
|
end
|
|
-- 递归检测等级表现
|
|
local function check_exp_lv(exp, lv)
|
|
if exp >= Config.Nucleonlv[lv].exp then
|
|
exp = exp - Config.Nucleonlv[lv].exp
|
|
lv = lv + 1
|
|
return check_exp_lv(exp, lv)
|
|
end
|
|
return exp, lv
|
|
end
|
|
local function duration_callback(percent)
|
|
if percent < 1 then
|
|
local exp, lv = check_exp_lv(temp_exp + add_exp * percent, temp_lv)
|
|
self.level_tmp.text = string.format("Lv.%s", lv)
|
|
self.exp_val_tmp.text = string.format("%s / %s", math.ceil(exp), Config.Nucleonlv[lv].exp)
|
|
else -- 为1时直接使用协议数据
|
|
final_result()
|
|
end
|
|
end
|
|
local round = self.slot_data.lv - self.last_slot_lv
|
|
local last_progress = self.slot_data.exp / self.cur_exp_cfg.exp
|
|
local function end_callback()
|
|
duration_callback(1)
|
|
self.is_animating = false
|
|
end
|
|
-- 调用图片动画
|
|
self.is_animating = true
|
|
ImageProgressAction(self.progress_fill, round, last_progress, 0.5, duration_callback, end_callback)
|
|
-- 播放经验条特效
|
|
-- 进度条流光特效
|
|
if not self.showing_lv_effect then
|
|
local function call_back( )
|
|
self.showing_lv_effect = false
|
|
end
|
|
self:ClearUIEffect(self.advance_lv_effect_con)
|
|
self:AddUIEffect("ui_jinjiejindu", self.advance_lv_effect_con, self.layer_name, Vector3(-110,0,0), 1, false, 0.75, nil, call_back)
|
|
self.showing_lv_effect = true
|
|
end
|
|
else
|
|
-- 不做动画,直接使用协议数据
|
|
final_result()
|
|
end
|
|
self.last_slot_exp = self.slot_data.exp
|
|
self.last_slot_lv = self.slot_data.lv
|
|
end
|
|
|
|
-- 加载属性条目
|
|
function PsionicAdvanceView:UpdateAttrItem(show_exp_anim)
|
|
-- local has_next = self.next_exp_cfg and self.next_exp_cfg.grade == self.cur_exp_cfg.grade
|
|
local has_next = self.next_exp_cfg and self.next_exp_cfg.next ~= 0 or false
|
|
-- 更新战斗力表现
|
|
self:UpdatePower(self.data.basic_attrs)
|
|
self.attr_item_creator = self.attr_item_creator or self:AddUIComponent(UI.ItemListCreator)
|
|
local info = {
|
|
data_list = self.data.cfg_attrs,
|
|
scroll_view = self.attr_scroll,
|
|
item_con = self.attr_con,
|
|
prefab_ab_name = "psionic",
|
|
prefab_res_name = "PsionicAdvanceAttrItem",
|
|
item_height = 30,
|
|
create_frequency = 0.01,
|
|
alignment = UnityEngine.TextAnchor.UpperLeft,
|
|
child_names = {
|
|
"attr_name:obj:tmp",
|
|
"attr_val:obj:tmp",
|
|
"attr_effect_con",
|
|
},
|
|
on_update_item = function(item, i, v)
|
|
local attr_name = WordManager:GetProperties(v[1])
|
|
-- 初始值要加上等级与等级成长的值
|
|
local val = WordManager:GetPropertyValue(v[1], v[2] + v[3] * self.slot_data.lv)
|
|
item.attr_name_tmp.text = attr_name
|
|
if has_next then -- 存在下一级数据,展示提升
|
|
local val_next = WordManager:GetPropertyValue(v[1], v[3])
|
|
val = string.format("%s <color=%s>+%s</color>",
|
|
val, ColorUtil.GREEN_DARK, val_next)
|
|
end
|
|
item.attr_val_tmp.text = val
|
|
if show_exp_anim and not item.showing_attr_effect then
|
|
local function call_back( )
|
|
item.showing_attr_effect = false
|
|
end
|
|
self:ClearUIEffect(item.attr_effect_con)
|
|
self:AddUIEffect("ui_jinjieshuxing", item.attr_effect_con, self.layer_name, Vector3(-175,0,0), 1, false, 0.75, nil, call_back)
|
|
item.showing_attr_effect = true
|
|
end
|
|
end,
|
|
}
|
|
self.attr_item_creator:UpdateItems(info)
|
|
end
|
|
|
|
-- 更新战斗力以及自动对齐表现
|
|
function PsionicAdvanceView:UpdatePower(attr_cur)
|
|
local t_p_cur = GetFighting(attr_cur)
|
|
self.power_txt.text = "f" .. (t_p_cur or 0)
|
|
end
|
|
|
|
function PsionicAdvanceView:UpdateAdvanceRed( )
|
|
local slot_red = false
|
|
if self.data then
|
|
slot_red = self.model:GetPsionicAdvanceRed(self.data.subtype)
|
|
if self.upgrade_auto_btn_obj.activeSelf then
|
|
self.upgrade_auto_red_obj:SetActive(slot_red)
|
|
end
|
|
-- if self.break_btn_obj.activeSelf then
|
|
-- self.break_red_obj:SetActive(slot_red)
|
|
-- end
|
|
end
|
|
end
|
|
|
|
-- 一键升阶按钮点击触发 needs_break:是否需要发送成槽位突破协议
|
|
function PsionicAdvanceView:OnUpgradeBtnClick(needs_break, auto_lv)
|
|
if not self.advance_cost_cfg then return end
|
|
if self.is_animating then return end
|
|
local cost_goods_id = self.advance_cost_cfg[2]
|
|
local item_num = GoodsModel:getInstance():GetTypeGoodsNum(cost_goods_id)
|
|
-- 槽位升级是否自动购买/是否自动升级
|
|
local upgrade_auto_buy, upgrade_auto_lv = 0, auto_lv and 1 or 0
|
|
local function ok_callback()
|
|
if needs_break then
|
|
self.model:Fire(PsionicConst.REQUEST_CCMD_EVENT, 13906, self.data.subtype)
|
|
else
|
|
self.model:Fire(PsionicConst.REQUEST_CCMD_EVENT, 13905, self.data.subtype, upgrade_auto_buy, upgrade_auto_lv)
|
|
end
|
|
end
|
|
if self.upgrade_auto_buy then
|
|
local function double_check_toggle_callback(flag)
|
|
self.model._hide_double_check_advance_flag = flag
|
|
end
|
|
upgrade_auto_buy = 1
|
|
upgrade_auto_lv = 1
|
|
if item_num >= self.upgrade_need_num then -- 数量达到要求,直接发协议
|
|
ok_callback()
|
|
else
|
|
upgrade_auto_buy = 1
|
|
upgrade_auto_lv = 1
|
|
if self.model._hide_double_check_advance_flag then
|
|
ok_callback()
|
|
return
|
|
end
|
|
local cost_cfg = Config.Goodsprice[cost_goods_id]
|
|
local total_cost = (self.upgrade_need_num - item_num) * (cost_cfg and cost_cfg.price or 0)
|
|
local priceText = string.format("<color=%s>%s</color> 彩钻自动补齐%s?", ColorUtil.YELLOW_DARK, total_cost, GoodsModel:getInstance():getGoodsName(cost_goods_id, true))
|
|
local data = {
|
|
insufficientText = "",
|
|
price = total_cost,
|
|
priceText = priceText,
|
|
titleText = "提示",
|
|
ok_callback = ok_callback,
|
|
no_need_toggle = false,
|
|
toggle_function = double_check_toggle_callback,
|
|
}
|
|
GlobalEventSystem:Fire(EventName.OPEN_COM_TOGGLE_TIP_VIEW, data)
|
|
end
|
|
else
|
|
if item_num > 0 then
|
|
ok_callback()
|
|
else
|
|
-- 没有自动购买的前提下,没有道具再弹出tips
|
|
UIToolTipMgr:getInstance():AppendGoodsTips(cost_goods_id, x, y, nil, nil, nil, nil, true)
|
|
end
|
|
end
|
|
end
|
|
|
|
function PsionicAdvanceView:__delete( )
|
|
if self.cost_item then
|
|
UIObjPool:getInstance():PushItem(UIObjPool.UIType.AwardItem, self.cost_item)
|
|
end
|
|
self.cost_item = nil
|
|
|
|
self:ClearUIEffect(self.advance_lv_effect_con)
|
|
end
|