MarketAttentionView = MarketAttentionView or BaseClass(BaseItem)
|
|
local MarketAttentionView = MarketAttentionView
|
|
local table_insert = table.insert
|
|
|
|
function MarketAttentionView:__init()
|
|
self.base_file = "market"
|
|
self.layout_file = "MarketAttentionView"
|
|
self.model = MarketModel:GetInstance()
|
|
self.sell_type = 1
|
|
self.is_first = true--是否第一次进入
|
|
self.series_limit = 0
|
|
self.career_limit = RoleManager.Instance.mainRoleInfo.career--默认拿自己的防具
|
|
self.color = 99
|
|
self.tab_item_list = {}
|
|
self:Load()
|
|
end
|
|
|
|
function MarketAttentionView:Load_callback()
|
|
self.nodes = {
|
|
"series_con:obj","right_scroll","series_con/series_drop","color_con:obj","clean_btn:obj",
|
|
"left_scroll/Viewport/left_con","right_scroll/Viewport/right_con","left_scroll","color_con/color_drop",
|
|
"career_con/career_drop", "career_con/career_text:tmp", "career_con:obj",
|
|
}
|
|
self:GetChildren(self.nodes)
|
|
self:InitDropDown()
|
|
|
|
self:AddEvents()
|
|
if self.need_refreshData then
|
|
self:UpdateView()
|
|
end
|
|
end
|
|
|
|
function MarketAttentionView:AddEvents( )
|
|
local function on_click( ... )
|
|
self.model:Fire(MarketModel.REQUEST_CCMD_EVENT, 15516, self.sell_type or self.last_sell_type, self.sell_sub_type)
|
|
end
|
|
AddClickEvent(self.clean_btn_obj, on_click)
|
|
end
|
|
|
|
function MarketAttentionView:InitDropDown()
|
|
local list = {}
|
|
local cfg_color = Config.Marketgoodsselectbycolor
|
|
table.insert(list,"所有品质")
|
|
for i,v in ipairs(cfg_color) do
|
|
table.insert(list, v.describe)
|
|
end
|
|
self.color_index = 1
|
|
local function update_color_func(index)
|
|
self.color_index = index
|
|
if index == 1 then
|
|
self.color = 99
|
|
else
|
|
self.color = index-1
|
|
end
|
|
self.need_reset = true
|
|
self:UpdateGoodsList()
|
|
end
|
|
|
|
local prefab_data = {Combox = "Combox",ComboxView = "ComboxView", ComboxItem = "ComboxItem", offset_y = -#list*ComboxItem.Height-9, show_type = "down"}
|
|
if not self.combox_color then
|
|
self.combox_color = Combox.New(self.color_drop,list,update_color_func,122,38,nil,prefab_data)
|
|
else
|
|
self.combox_color:ResetData(list,self.color_index,update_color_func,122,38)
|
|
end
|
|
|
|
local list = {}
|
|
local cfg_lv = Config.Marketgoodsselectbylev
|
|
table.insert(list,"不限套装")
|
|
for i,v in ipairs(cfg_lv) do
|
|
table.insert(list, v.stage.."代")
|
|
end
|
|
local function update_series_func(index)
|
|
self.series_index = index
|
|
if index == 1 then
|
|
self.series_limit = 0
|
|
else
|
|
self.series_limit = cfg_lv[index-1].id
|
|
end
|
|
self.need_reset = true
|
|
self:UpdateGoodsList()
|
|
end
|
|
|
|
local prefab_data = {Combox = "Combox",ComboxView = "ComboxView", ComboxItem = "ComboxItem", offset_y = -#list*ComboxItem.Height-9, show_type = "down"}
|
|
if not self.combox_series then
|
|
self.combox_series = Combox.New(self.series_drop,list,update_series_func,122,38,nil,prefab_data)
|
|
else
|
|
self.combox_series:ResetData(list,self.series_index,update_series_func,122,38)
|
|
end
|
|
|
|
local list = {}
|
|
local cfg_career = Config.Marketgoodsselectbycareer
|
|
table.insert(list,"不限职业")
|
|
for i,v in ipairs(cfg_career) do
|
|
table.insert(list, v.describe)
|
|
end
|
|
local function update_career_func(index)
|
|
self.career_index = index
|
|
if index == 1 then
|
|
self.career_limit = 0
|
|
else
|
|
self.career_limit = cfg_career[index-1].id
|
|
end
|
|
if not self.is_first then
|
|
if self.cur_hor_tab_index == 1 then
|
|
self.model:CleanMarketGoodsInfoByType(self.sell_type or self.last_sell_type, self.sell_sub_type)
|
|
else
|
|
self.model:CleanMarketGuildGoodsInfoByType(self.sell_type or self.last_sell_type, self.sell_sub_type)
|
|
end
|
|
self.need_reset = true
|
|
self:UpdateGoodsList()
|
|
end
|
|
end
|
|
|
|
local prefab_data = {Combox = "Combox",ComboxView = "ComboxView", ComboxItem = "ComboxItem", offset_y = -#list*ComboxItem.Height-9, show_type = "down"}
|
|
if not self.combox_career then
|
|
self.combox_career = Combox.New(self.career_drop,list,update_career_func,122,38,nil,prefab_data)
|
|
else
|
|
self.combox_career:ResetData(list,self.career_index,update_career_func,122,38)
|
|
end
|
|
end
|
|
|
|
function MarketAttentionView:UpdateView( )
|
|
self:UpdateVerTabBtns(true)
|
|
end
|
|
|
|
function MarketAttentionView:UpdateVerTabBtns( need_refresh )
|
|
self.tab_cfg = self.model:GetMarketGoodsCFG()
|
|
self.tab_creator = self.tab_creator or self:AddUIComponent(UI.ItemListCreator)
|
|
-- 声明点击回调
|
|
local data = {}
|
|
if (self.sell_type and need_refresh) or self.tab_all_close then
|
|
for i,v in pairsByKeys(self.tab_cfg) do
|
|
if i == self.sell_type then--如果是当前选中的第一层
|
|
table_insert(data, DeepCopy(v))
|
|
data[#data].is_tab = true
|
|
table_insert(data, {name = "全部", is_zero = true, sell_sub_type = 0, sell_type = i})--为了插一个全部
|
|
for ii,vv in pairsByKeys(v) do
|
|
table_insert(data, DeepCopy(vv))
|
|
end
|
|
else
|
|
table_insert(data, DeepCopy(v))
|
|
data[#data].is_tab = true
|
|
end
|
|
end
|
|
else
|
|
data = self.tab_data
|
|
end
|
|
if not self.sell_sub_type then--没选中就默认选第一个
|
|
self.sell_sub_type = 0
|
|
end
|
|
self.tab_data = data
|
|
local call_back = function(data, sell_type, sell_sub_type)
|
|
local need_refresh = self.sell_type ~= sell_type
|
|
self.need_reset = true
|
|
if sell_type == 0 then
|
|
self.career_limit = 0--热卖的话就不用筛职业
|
|
elseif sell_type ~= 0 and sell_type ~= 1 and sell_type ~= 3 then --其他类别的 不筛选职业和套装
|
|
self.career_limit = 0
|
|
self.series_limit = 0
|
|
elseif sell_type == 1 and need_refresh then --切页签了 要默认筛自己的防具
|
|
local cfg_career = MarketConst.Sex
|
|
local career = RoleManager.Instance.mainRoleInfo.career
|
|
local career_index = self.model:GetMarketDefultSelectIndexByType(MarketConst.FliterType.Armor, career)
|
|
self.career_limit = cfg_career[career_index-1].id
|
|
elseif sell_type == 3 and need_refresh then --切页签了 要默认筛自己的武器
|
|
local career = RoleManager.Instance.mainRoleInfo.career
|
|
-- local cfg_career = MarketConst.Career
|
|
-- local career_index = self.model:GetMarketDefultSelectIndexByType(MarketConst.FliterType.Armor, career)
|
|
-- self.career_limit = self.model:GetMarketFliterCareerBySex(cfg_career[career_index-1].id)
|
|
self.career_limit = career
|
|
end
|
|
if not need_refresh and not sell_sub_type then--如果不需要刷新 且点到了tab 意思就是要收起来tab
|
|
self.need_reset = false
|
|
self.tab_all_close = true
|
|
self.last_sell_type = self.sell_type --先保存起来上一个选中的tab
|
|
self.sell_type = nil
|
|
else
|
|
self.tab_all_close = false
|
|
self.sell_type = sell_type
|
|
end
|
|
if sell_sub_type then
|
|
self.sell_sub_type = sell_sub_type
|
|
elseif need_refresh then
|
|
self.sell_sub_type = sell_sub_type
|
|
end
|
|
self:UpdateVerTabBtns(need_refresh)
|
|
self:UpdateSelectVer(need_refresh)
|
|
end
|
|
|
|
local tag_all_info = {
|
|
data_list = data,
|
|
item_con = self.left_con,
|
|
item_class = MarketVerTabItem,
|
|
item_width = 206,
|
|
get_item_height = function(i)
|
|
return data[i].is_tab and 56 or 48
|
|
end,
|
|
reuse_item_num = 12,
|
|
start_x = 2,
|
|
start_y = -10,
|
|
space_y = 2,
|
|
scroll_view = self.left_scroll,
|
|
create_frequency = 0.01,
|
|
on_update_item = function(item, i, v)
|
|
item:SetData(v, i, self.sell_type, self.sell_sub_type, MarketModel.VER_TAB_TYPE.ATTENTION_TYPE)
|
|
item:SetCallBackFunc(call_back)
|
|
end,
|
|
}
|
|
self.tab_creator:UpdateItems(tag_all_info)
|
|
if self.is_first then
|
|
self:UpdateSelectVer(true)
|
|
self:UpdateGoodsList()
|
|
self.is_first = false
|
|
end
|
|
if need_refresh then
|
|
self:UpdateFliter()
|
|
end
|
|
end
|
|
|
|
--设置垂直tab选择
|
|
function MarketAttentionView:UpdateSelectVer( need_refresh )
|
|
self.tab_creator:IterateItems(function(item, i, v)
|
|
item:SetSelect(self.sell_type, self.sell_sub_type)
|
|
end)
|
|
self:UpdateGoodsList()
|
|
if need_refresh then
|
|
self:ScrollToSelectItem()
|
|
end
|
|
end
|
|
|
|
function MarketAttentionView:ScrollToSelectItem( )
|
|
if not self.sell_sub_type then--如果没有选中第二层的item就默认选第一个
|
|
self.sell_sub_type = 0
|
|
end
|
|
for i,v in ipairs(self.tab_data) do
|
|
if v.sell_type == self.sell_type and v.sell_sub_type == self.sell_sub_type then
|
|
self.tab_creator:ScrollToItem(i-1)
|
|
end
|
|
end
|
|
end
|
|
|
|
function MarketAttentionView:UpdateGoodsList( )
|
|
local goods_list = self.model:GetMarketGoodsCFG(self.sell_type or self.last_sell_type, self.sell_sub_type) or {}
|
|
local data = {}
|
|
local color_pass, series_pass, career_pass
|
|
-- local lv_min, lv_max = self.model:GetMarketFliterLv(self.series_limit)
|
|
if self.sell_sub_type == 0 then--如果是全部 就要遍历两层
|
|
for i,v in pairsByKeys(goods_list) do
|
|
for ii,vv in ipairs(v) do
|
|
if self.color ~= 99 or self.series_limit ~= 0 or self.career_limit ~= 0 then--需要筛选品质 职业 套
|
|
if self.color ~= 99 then
|
|
if vv.color == self.color then
|
|
color_pass = true
|
|
else
|
|
color_pass = false
|
|
end
|
|
else
|
|
color_pass = true
|
|
end
|
|
|
|
if color_pass then--如果颜色判断通过 判断职业限制
|
|
career_pass = self.model:CheckMarketGoodsCanWear(self.career_limit, vv.career)
|
|
else
|
|
career_pass = false
|
|
end
|
|
|
|
if career_pass then--如果颜色判断通过 再判断套装限制
|
|
if self.series_limit ~= 0 then
|
|
if self.series_limit == vv.series then
|
|
series_pass = true
|
|
else
|
|
series_pass = false
|
|
end
|
|
else
|
|
series_pass = true
|
|
end
|
|
if series_pass then
|
|
table_insert(data, vv)
|
|
end
|
|
else
|
|
|
|
end
|
|
else
|
|
table_insert(data, vv)
|
|
end
|
|
end
|
|
end
|
|
else
|
|
for i,v in ipairs(goods_list) do
|
|
if self.color ~= 99 or self.series_limit ~= 0 or self.career_limit ~= 0 then--需要筛选品质 职业 套
|
|
if self.color ~= 99 then
|
|
if v.color == self.color then
|
|
color_pass = true
|
|
else
|
|
color_pass = false
|
|
end
|
|
else
|
|
color_pass = true
|
|
end
|
|
|
|
if color_pass then--如果颜色判断通过 判断职业限制
|
|
career_pass = self.model:CheckMarketGoodsCanWear(self.career_limit, v.career)
|
|
else
|
|
career_pass = false
|
|
end
|
|
|
|
if career_pass then--如果职业判断通过 再判断套装限制
|
|
if self.series_limit ~= 0 then
|
|
if self.series_limit == v.series then
|
|
series_pass = true
|
|
else
|
|
series_pass = false
|
|
end
|
|
else
|
|
series_pass = true
|
|
end
|
|
if series_pass then
|
|
table_insert(data, v)
|
|
end
|
|
end
|
|
else
|
|
table_insert(data, v)
|
|
end
|
|
end
|
|
end
|
|
|
|
local function sortfunction( a,b )
|
|
local a_attention = self.model:IsMarketAttentionGoods(a.type_id)
|
|
local b_attention = self.model:IsMarketAttentionGoods(b.type_id)
|
|
if a_attention == b_attention then
|
|
return a.type_id < b.type_id
|
|
else
|
|
return a_attention
|
|
end
|
|
end
|
|
table.sort( data, sortfunction )
|
|
|
|
if not self.goods_list_com then
|
|
self.goods_list_com = self:AddUIComponent(UI.ItemListCreator)
|
|
end
|
|
if self.need_reset then
|
|
self.goods_list_com:Reset()
|
|
self.need_reset = false
|
|
end
|
|
local info = {
|
|
data_list = data,
|
|
item_con = self.right_con,
|
|
scroll_view = self.right_scroll,
|
|
item_class = MarketAttentionItem,
|
|
start_y = 0, start_x = 8,
|
|
create_frequency = 0.02,
|
|
create_num_per_time = 3,
|
|
item_height = 100,
|
|
space_y = 0,
|
|
on_update_item = function(item, i, v)
|
|
item:SetData(i, v)
|
|
end,
|
|
}
|
|
self.goods_list_com:UpdateItems(info)
|
|
end
|
|
|
|
--更新筛选栏状态
|
|
function MarketAttentionView:UpdateFliter( )
|
|
local fliter_type = self.model:GetFliterType(self.sell_type,self.sell_sub_type)
|
|
if fliter_type == MarketConst.FliterType.Armor then
|
|
self.career_con_obj:SetActive(true)
|
|
self.series_con_obj:SetActive(true)
|
|
self.color_con_obj:SetActive(true)
|
|
self.career_text_tmp.text = "性别"
|
|
|
|
local list = {}
|
|
local cfg_career = MarketConst.Sex
|
|
local career = RoleManager.Instance.mainRoleInfo.career
|
|
self.career_index = self.model:GetMarketDefultSelectIndexByType(fliter_type, career)
|
|
table.insert(list,"不限性别")
|
|
for i,v in ipairs(cfg_career) do
|
|
table.insert(list, v.name)
|
|
end
|
|
local function update_career_func(index)
|
|
self.career_index = index
|
|
if index == 1 then
|
|
self.career_limit = 0
|
|
else
|
|
self.career_limit = self.model:GetMarketFliterCareerBySex(cfg_career[index-1].id)
|
|
end
|
|
if not self.is_first then
|
|
if self.cur_hor_tab_index == 1 then
|
|
self.model:CleanMarketGoodsInfoByType(self.sell_type or self.last_sell_type, self.sell_sub_type)
|
|
else
|
|
self.model:CleanMarketGuildGoodsInfoByType(self.sell_type or self.last_sell_type, self.sell_sub_type)
|
|
end
|
|
self.need_reset = true
|
|
self:UpdateGoodsList()
|
|
end
|
|
end
|
|
local prefab_data = {Combox = "Combox",ComboxView = "ComboxView", ComboxItem = "ComboxItem", offset_y = -#list*ComboxItem.Height-9, show_type = "down"}
|
|
if not self.combox_career then
|
|
self.combox_career = Combox.New(self.career_drop,list,update_career_func,122,38,nil,prefab_data)
|
|
else
|
|
self.combox_career:ResetData(list,self.career_index,update_career_func,122,38,nil,true, prefab_data)
|
|
end
|
|
elseif fliter_type == MarketConst.FliterType.Weapon then
|
|
self.career_con_obj:SetActive(true)
|
|
self.series_con_obj:SetActive(true)
|
|
self.color_con_obj:SetActive(true)
|
|
self.career_text_tmp.text = "职业"
|
|
|
|
local list = {}
|
|
local cfg_career = MarketConst.Career
|
|
local career = RoleManager.Instance.mainRoleInfo.career
|
|
self.career_index = self.model:GetMarketDefultSelectIndexByType(fliter_type, career)
|
|
table.insert(list,"不限职业")
|
|
for i,v in ipairs(cfg_career) do
|
|
table.insert(list, v.name)
|
|
end
|
|
local function update_career_func(index)
|
|
self.career_index = index
|
|
if index == 1 then
|
|
self.career_limit = 0
|
|
else
|
|
self.career_limit = cfg_career[index-1].id
|
|
end
|
|
if not self.is_first then
|
|
if self.cur_hor_tab_index == 1 then
|
|
self.model:CleanMarketGoodsInfoByType(self.sell_type or self.last_sell_type, self.sell_sub_type)
|
|
else
|
|
self.model:CleanMarketGuildGoodsInfoByType(self.sell_type or self.last_sell_type, self.sell_sub_type)
|
|
end
|
|
self.need_reset = true
|
|
self:UpdateGoodsList()
|
|
end
|
|
end
|
|
local prefab_data = {Combox = "Combox",ComboxView = "ComboxView", ComboxItem = "ComboxItem", offset_y = -#list*ComboxItem.Height-9, show_type = "down"}
|
|
if not self.combox_career then
|
|
self.combox_career = Combox.New(self.career_drop,list,update_career_func,122,38,nil,prefab_data)
|
|
else
|
|
self.combox_career:ResetData(list,self.career_index,update_career_func,122,38,nil,true,prefab_data)
|
|
end
|
|
elseif fliter_type == MarketConst.FliterType.Other then
|
|
self.career_con_obj:SetActive(false)
|
|
self.series_con_obj:SetActive(false)
|
|
self.color_con_obj:SetActive(true)
|
|
elseif fliter_type == MarketConst.FliterType.Hot then
|
|
self.career_con_obj:SetActive(false)
|
|
self.series_con_obj:SetActive(true)
|
|
self.color_con_obj:SetActive(true)
|
|
end
|
|
end
|
|
|
|
function MarketAttentionView:SetData( data )
|
|
self.data = data
|
|
if self.is_loaded then
|
|
self.need_refreshData = false
|
|
self:UpdateView()
|
|
else
|
|
self.need_refreshData = true
|
|
end
|
|
end
|
|
|
|
function MarketAttentionView:__delete( )
|
|
if self.combox_career then
|
|
self.combox_career:DeleteMe()
|
|
self.combox_career = nil
|
|
end
|
|
if self.combox_series then
|
|
self.combox_series:DeleteMe()
|
|
self.combox_series = nil
|
|
end
|
|
if self.combox_color then
|
|
self.combox_color:DeleteMe()
|
|
self.combox_color = nil
|
|
end
|
|
end
|