|
EquipCollectView = EquipCollectView or BaseClass(BaseView)
|
|
local EquipCollectView = EquipCollectView
|
|
local table_insert = table.insert
|
|
--[[
|
|
EquipCollectView.TabData = {
|
|
[1] = {name = "人物", level = MainRoleModel.TabOpenLevel[1]},
|
|
}
|
|
--]]
|
|
|
|
function EquipCollectView:__init()
|
|
self.base_file = "equipCollect"
|
|
self.layout_file = "EquipCollectView"
|
|
self.layer_name = "UI"
|
|
self.need_show_money = false
|
|
self.destroy_imm = true
|
|
self.use_background = G_USING_BG
|
|
self.hide_maincancas = true --全屏界面需要放开隐藏主UI
|
|
self.append_to_ctl_queue = true --添加进入控制队列
|
|
self.change_scene_close = true
|
|
|
|
self.close_fog = true
|
|
self.model_activity_bg = true
|
|
self.model_activity_bg_pos = Vector2(-132,52)
|
|
self.show_back_camera = true--打开backmodel摄像机
|
|
self.ani_right = 400
|
|
self.ani_left = -200
|
|
self.adjust_mid = {left = 262, right = 446}
|
|
self.progress_item = {}
|
|
self.progress_con_width = 277--进度条长度
|
|
self.fire_change_visible_event = true
|
|
|
|
self.model = EquipCollectModel:getInstance()
|
|
self.tab_all_close = false
|
|
self.id = 1
|
|
self.is_first = true
|
|
self.equip_item_list = {}
|
|
--根据策划给的排序规则弄的映射表
|
|
self.pos_map_list = {
|
|
[1] = EquipModel.EquipType.Weapon,
|
|
[2] = EquipModel.EquipType.Head,
|
|
[3] = EquipModel.EquipType.Hand,
|
|
[4] = EquipModel.EquipType.Body,
|
|
[5] = EquipModel.EquipType.Shoulder,
|
|
[6] = EquipModel.EquipType.Shoes,
|
|
[7] = EquipModel.EquipType.Leg,
|
|
}
|
|
self.load_callback = function ()
|
|
self:LoadSuccess()
|
|
end
|
|
self.open_callback = function ( )
|
|
self:OpenSuccess()
|
|
end
|
|
self.switch_callback = function(index)
|
|
end
|
|
self.destroy_callback = function ( )
|
|
self:DestroySuccess()
|
|
end
|
|
end
|
|
|
|
function EquipCollectView:Open( )
|
|
BaseView.Open(self)
|
|
end
|
|
|
|
function EquipCollectView:LoadSuccess()
|
|
local nodes = {
|
|
--左边
|
|
"tabWinCon", "left/left_scroll/Viewport/left_con", "left/left_scroll", "left/left_item_con", "left",
|
|
"left/left_bg:raw",
|
|
--中间
|
|
"mid/role_con", "mid/power_text:txt", "mid",
|
|
--右边
|
|
"right/active_btn/active_btn_text:tmp", "right/finish_image:obj", "right/progress_bg",
|
|
"right/progress_image:img", "right/designation_con:img", "right/desination_power_text:tmp",
|
|
"right/active_btn:obj", "right/right_bg:raw", "right/attr_scroll", "right/right_item_con",
|
|
"right/active_btn/active_btn_red:obj", "right/attr_scroll/Viewport/attr_con", "right",
|
|
"right/progress_con",
|
|
}
|
|
self:GetChildren(nodes)
|
|
self:AddEvent()
|
|
local close_callback = function()
|
|
self:Close()
|
|
end
|
|
self.tab_win = UITabWindow.New(self.tabWinCon, nil, select_callback,
|
|
close_callback, self.background_wnd, self.container, UITabWindow.SizeLargeNoTab, false,nil,true)
|
|
self.tab_win:SetTitleText("装备套装")
|
|
lua_resM:setOutsideRawImage(self, self.left_bg_raw, GameResPath.GetViewBigBg("equip_collect_bg_left"), false,func)
|
|
lua_resM:setOutsideRawImage(self, self.right_bg_raw, GameResPath.GetViewBigBg("equip_collect_bg_right"), false,func)
|
|
|
|
self.id, self.sub_id = self.model:GetEquipCollectJumpId()
|
|
end
|
|
|
|
function EquipCollectView:AddEvent()
|
|
local function on_click( target )
|
|
if target == self.close_btn_obj then
|
|
self:Close()
|
|
elseif target == self.active_btn_obj then
|
|
local cur_data = self.cur_select_data
|
|
self.model:Fire(EquipCollectConst.REQUEST_SCMD_EVENT,15220, cur_data[1].id, cur_data[1].sub_id)
|
|
end
|
|
end
|
|
AddClickEvent(self.active_btn_obj, on_click)
|
|
|
|
local function on_update( ... )
|
|
self:UpdateView()
|
|
self:UpdateRightInfo()
|
|
end
|
|
self:BindEvent(self.model,EquipCollectConst.ANS_EQUIP_COLLECT_INFO,on_update)
|
|
end
|
|
|
|
function EquipCollectView:OpenSuccess()
|
|
self:UpdateView()
|
|
self:UpdateModel()
|
|
end
|
|
|
|
function EquipCollectView:UpdateView()
|
|
self:UpdateLeftItems(true)
|
|
end
|
|
|
|
function EquipCollectView:UpdateLeftItems( need_refresh )
|
|
self.tab_cfg = self.model:GetEquipCollectCFG()
|
|
self.tab_creator = self.tab_creator or self:AddUIComponent(UI.ItemListCreator)
|
|
-- 声明点击回调
|
|
local data = {}
|
|
local type_cfg = Config.Equipmentcollecttype
|
|
for i,v in pairsByKeys(self.tab_cfg) do
|
|
if type_cfg[i].open_lv <= RoleManager.Instance.mainRoleInfo.level then
|
|
for ii,vv in pairsByKeys(v) do
|
|
table_insert(data, DeepCopy(vv))
|
|
end
|
|
end
|
|
end
|
|
self.tab_data = data
|
|
self.cur_select_data = self.tab_cfg[self.id][self.sub_id]
|
|
local call_back = function(data, id, sub_id)
|
|
self.id = id
|
|
self.sub_id = sub_id
|
|
self:UpdateLeftItems()
|
|
self:UpdateSelectVer()
|
|
end
|
|
|
|
local function final_callback( )
|
|
if self.is_first then
|
|
self.cur_select_data = self.model:GetEquipCollectCFG(self.id, self.sub_id)
|
|
self:UpdateSelectVer(true)
|
|
self.is_first = false
|
|
end
|
|
end
|
|
|
|
local tag_all_info = {
|
|
data_list = data,
|
|
item_con = self.left_con,
|
|
item_class = EquipCollectLeftItem,
|
|
item_height = 113,
|
|
start_x = 8,
|
|
start_y = -10,
|
|
space_y = 20,
|
|
scroll_view = self.left_scroll,
|
|
create_frequency = 0.01,
|
|
final_callback = final_callback,
|
|
on_update_item = function(item, i, v)
|
|
item:SetData(v, self.id, self.sub_id)
|
|
item:SetCallBackFunc(call_back)
|
|
end,
|
|
}
|
|
self.tab_creator:UpdateItems(tag_all_info)
|
|
end
|
|
--设置垂直tab选择
|
|
function EquipCollectView:UpdateSelectVer( need_refresh )
|
|
self.tab_creator:IterateItems(function(item, i, v)
|
|
item:SetSelect(self.id, self.sub_id)
|
|
end)
|
|
if need_refresh then
|
|
self:ScrollToSelectItem()
|
|
end
|
|
self:UpdateRightItems()
|
|
self:UpdateRightInfo()
|
|
end
|
|
|
|
function EquipCollectView:ScrollToSelectItem( )
|
|
for i,v in ipairs(self.tab_data) do
|
|
if v[1].id == self.id and v[1].sub_id == self.sub_id then
|
|
self.tab_creator:ScrollToItem(i)
|
|
end
|
|
end
|
|
end
|
|
--更新右边的装备
|
|
function EquipCollectView:UpdateRightItems( )
|
|
local y_offset = 135
|
|
local data = self.cur_select_data
|
|
local server_data = self.model:GetEquipCollectInfo(self.id, self.sub_id)
|
|
for i=1,7 do
|
|
local item = self.equip_item_list[i]
|
|
if not item then
|
|
if i%2 == 1 then
|
|
item = EquipCollectEquipItem.New(self.left_item_con)
|
|
item:SetPosition(-11, -math.floor((i-1)/2)*y_offset-5)
|
|
else
|
|
item = EquipCollectEquipItem.New(self.right_item_con)
|
|
item:SetPosition(-21, -math.floor((i-1)/2)*y_offset-5)
|
|
end
|
|
self.equip_item_list[i] = item
|
|
end
|
|
item:SetData(data[self.pos_map_list[i]], index, self.pos_map_list[i], server_data[self.pos_map_list[i]], "equip_collect_base_view")
|
|
end
|
|
end
|
|
--更新右边的属性栏
|
|
function EquipCollectView:UpdateRightInfo( )
|
|
local cur_data = self.cur_select_data
|
|
self.attr_creator = self.attr_creator or self:AddUIComponent(UI.ItemListCreator)
|
|
self.attr_creator:Reset()
|
|
local cur_progress = self.model:GetEquipCollectProgress(cur_data[1].id, cur_data[1].sub_id)
|
|
local cur_active_num = 0
|
|
if TableSize(cur_progress) > 0 then
|
|
cur_active_num = cur_progress.cur_active
|
|
end
|
|
local power = 0
|
|
if cur_active_num > 0 then
|
|
local attr = stringtotable(cur_data[cur_active_num].attr_total)
|
|
power = GetFighting(attr)
|
|
end
|
|
self.power_text_txt.text = power
|
|
self.active_btn_red_obj:SetActive(self.model:IsEquipCollectNeedRedById(cur_data[1].id, cur_data[1].sub_id))
|
|
local is_all_collect = self.model:CheckIsAllEquipCollected(cur_data[1].id, cur_data[1].sub_id)
|
|
self.active_btn_obj:SetActive(not is_all_collect)
|
|
self.finish_image_obj:SetActive(is_all_collect)
|
|
|
|
local cur_attr_list = {}
|
|
for i,v in ipairs(cur_data) do
|
|
if TableSize(v.attr_list) > 0 then--筛选出有属性加成的才丢进去了
|
|
table_insert(cur_attr_list, v)
|
|
end
|
|
end
|
|
|
|
local final_space = 10--前后预留的位置
|
|
local len = TableSize(cur_attr_list)
|
|
local item_width = 32
|
|
self.pos_data = self.pos_data or {}
|
|
local space_x = (self.progress_con_width - final_space * 2 - item_width) / (len - 1) --算出一个item和间隔的大小
|
|
for i,v in ipairs(cur_attr_list) do
|
|
local item = self.progress_item[i]
|
|
if not item then
|
|
item = EquipCollectProgressItem.New(self.progress_con)
|
|
self.progress_item[i] = item
|
|
self.pos_data[v.pos] = (i - 1)*space_x+final_space + 8--8是小白图到item最左边的距离
|
|
item:SetPosition((i - 1)*space_x+final_space, 8 )
|
|
end
|
|
item:SetData(v,i)
|
|
end
|
|
--构造位置数据
|
|
for i=0,7 do
|
|
if i == 0 then
|
|
self.pos_data[i] = 0
|
|
elseif i == 7 then
|
|
self.pos_data[i] = self.progress_con_width
|
|
else
|
|
if not self.pos_data[i] then
|
|
self.pos_data[i] = (self.pos_data[i-1] + self.pos_data[i+1])/2
|
|
end
|
|
end
|
|
end
|
|
self.progress_image_img.fillAmount = self.pos_data[cur_active_num]/self.progress_con_width
|
|
|
|
local sub_cfg = Config.Equipmentcollectsubtype[cur_data[1].id.."@"..cur_data[1].sub_id]
|
|
if sub_cfg then
|
|
local reward = stringtotable(sub_cfg.reward)
|
|
local designation_id = DesignationModel:getInstance():GetDesignationIdByGoodsId(reward[1][2])
|
|
local dsgt_cfg = Config.Dsgt
|
|
local power = DesignationModel:GetInstance():GetDesignationPowerById(designation_id)
|
|
if dsgt_cfg[designation_id] then
|
|
lua_resM:setOutsideImageSprite(self, self.designation_con_img, GameResPath.GetDesignImage(designation_id), true)
|
|
end
|
|
self.desination_power_text_tmp.text = string.format("战力: %s", HtmlColorTxt(power, ColorUtil.YELLOW_DARK))
|
|
end
|
|
local data = {
|
|
data_list = cur_attr_list,
|
|
item_con = self.attr_con,
|
|
item_class = EquipCollectAttrItem,
|
|
item_width = 324,
|
|
item_height = 50,
|
|
start_x = -20,
|
|
start_y = 10,
|
|
space_y = 0,
|
|
scroll_view = self.attr_scroll,
|
|
create_frequency = 0.01,
|
|
on_update_item = function(item, i, v)
|
|
item:SetData(v, i, cur_active_num)
|
|
end,
|
|
}
|
|
self.attr_creator:UpdateItems(data)
|
|
end
|
|
|
|
function EquipCollectView:UpdateModel( )
|
|
local res_data = {
|
|
father_node = self,
|
|
transform = self.role_con,
|
|
fashion_type = FuncOpenModel.TypeId.Clothes,
|
|
size = Vector2(720,720),
|
|
scale = 250,
|
|
ui_model_type = UIModelCommon.ModelType.BackModel,
|
|
}
|
|
FuncOpenModel:getInstance():SetModelRes(res_data)
|
|
end
|
|
|
|
function EquipCollectView:DestroySuccess( )
|
|
if self.tab_win then
|
|
self.tab_win:DeleteMe()
|
|
self.tab_win = nil
|
|
end
|
|
if self.money_view then
|
|
self.money_view:DeleteMe()
|
|
self.money_view = nil
|
|
end
|
|
|
|
for i,v in ipairs(self.progress_item) do
|
|
v:DeleteMe()
|
|
v = nil
|
|
end
|
|
self.progress_item = {}
|
|
|
|
for i,v in ipairs(self.equip_item_list) do
|
|
v:DeleteMe()
|
|
v = nil
|
|
end
|
|
|
|
self.equip_item_list = {}
|
|
end
|