源战役客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

604 regels
20 KiB

MarketBuyHallView = MarketBuyHallView or BaseClass(BaseItem)
local MarketBuyHallView = MarketBuyHallView
local table_insert = table.insert
function MarketBuyHallView:__init()
self.base_file = "market"
self.layout_file = "MarketBuyHallView"
self.model = MarketModel:GetInstance()
self.sell_type = 0
self.series_limit = 0
self.color = 99
self.career_limit = 0
self.page_size = 8
self.sort_id = 1--1:时间排序 2:当前竞拍价排序 3:一口价排序
self.sort_order = 0--0:表示顺序(从大到小) 1:表示倒序(从小到大)
self.sort_data = {
1,0,0
}
self.is_first = true--是否第一次进入
self.tab_item_list = {}
self.cur_hor_tab_index = 1 --水平tab选择
self:Load()
end
function MarketBuyHallView:Load_callback()
self.nodes = {
"title/auction_con/auction_arrow","title/price_con/price_arrow","title/time_con/time_arrow",
"right_scroll/Viewport/right_con","left_scroll","left_scroll/Viewport/left_con","empty/empty_talk_image:raw",
"right_scroll:obj","series_con:obj","color_con:obj","series_con/series_drop","color_con/color_drop",
"title/auction_con:obj","title/price_con:obj","title/time_con:obj","career_con/career_text:tmp",
"empty/girl:raw","empty/empty_text:tmp","empty:obj","tab_con","career_con:obj", "career_con/career_drop",
}
self:GetChildren(self.nodes)
lua_resM:setOutsideRawImage(self, self.empty_talk_image_raw, GameResPath.GetViewBigBg("com_empty_bg1"), false)
lua_resM:setOutsideRawImage(self, self.girl_raw, GameResPath.GetRoleBg("team_empty_bg_267_589"), false)
self:InitDropDown()
self:AddEvents()
if self.need_refreshData then
self:UpdateView()
end
for index=1,3 do
if index == 1 then
self.time_arrow.localRotation = self.sort_data[index] == 1 and Quaternion.Euler(0,0,0) or Quaternion.Euler(0,0,180)
elseif index == 2 then
self.auction_arrow.localRotation = self.sort_data[index] == 1 and Quaternion.Euler(0,0,0) or Quaternion.Euler(0,0,180)
elseif index == 3 then
self.price_arrow.localRotation = self.sort_data[index] == 1 and Quaternion.Euler(0,0,0) or Quaternion.Euler(0,0,180)
end
end
end
function MarketBuyHallView:AddEvents( )
local function on_update_goods( )
self:UpdateGoodsList()
end
self.on_update_goods_id = self.model:BindOne("market_goods_list", on_update_goods)
self.on_update_guild_goods_id = self.model:BindOne("market_guild_goods_list", on_update_goods)
local function touch_end(target,pos_x, pos_y)
self:OnTouchEnd(pos_x, pos_y)
end
AddDragEndEvent(self.right_scroll_obj,touch_end)
function on_click_sort( target )
if target == self.auction_con_obj then--拍卖排序
self:SelectSort(2)
elseif target == self.price_con_obj then--一口价排序
self:SelectSort(3)
elseif target == self.time_con_obj then--时间排序
self:SelectSort(1)
end
end
AddClickEvent(self.auction_con_obj, on_click_sort)
AddClickEvent(self.price_con_obj, on_click_sort)
AddClickEvent(self.time_con_obj, on_click_sort)
local function on_refresh_data( )
if self.cur_hor_tab_index == 1 then
self.model:CleanMarketGoodsInfo()
else
self.model:CleanMarketGuildGoodsInfo()
end
self.need_reset = true
self:OnTouchEnd(0,0,true)
end
self.on_refresh_data_id = self.model:Bind(MarketModel.MARKET_BUY_SUCCESS, on_refresh_data)
end
function MarketBuyHallView:SelectSort( index )
self.sort_id = index
self.sort_order = self.sort_data[index] == 1 and 1 or 0
self.sort_data[index] = self.sort_data[index] == 1 and 0 or 1
if index == 1 then
self.time_arrow.localRotation = self.sort_data[index] == 1 and Quaternion.Euler(0,0,0) or Quaternion.Euler(0,0,180)
elseif index == 2 then
self.auction_arrow.localRotation = self.sort_data[index] == 1 and Quaternion.Euler(0,0,0) or Quaternion.Euler(0,0,180)
elseif index == 3 then
self.price_arrow.localRotation = self.sort_data[index] == 1 and Quaternion.Euler(0,0,0) or Quaternion.Euler(0,0,180)
end
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:OnTouchEnd(0,0,true)
end
function MarketBuyHallView: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
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:OnTouchEnd(0,0,true)
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_level_func(index)
self.series_index = index
if index == 1 then
self.series_limit = 0
else
self.series_limit = cfg_lv[index-1].stage
end
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:OnTouchEnd(0,0,true)
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_level_func,122,38,nil,prefab_data)
else
self.combox_series:ResetData(list,self.series_index,update_level_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:OnTouchEnd(0,0,true)
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 MarketBuyHallView: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)
SetAnchoredPositionX(self.color_con, 144)
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:OnTouchEnd(0,0,true)
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)
SetAnchoredPositionX(self.color_con, 144)
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:OnTouchEnd(0,0,true)
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)
SetAnchoredPositionX(self.color_con, 372)
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)
SetAnchoredPositionX(self.color_con, 144)
end
end
function MarketBuyHallView:UpdateView( )
self:SetHorTabCon()
end
function MarketBuyHallView:SetData(tab_id )
self.cur_hor_tab_index = tab_id or self.cur_hor_tab_index
if self.is_loaded then
self.need_refreshData = false
self:UpdateView()
else
self.need_refreshData = true
end
end
function MarketBuyHallView:SetHorTabCon( )
for i,v in ipairs(self.tab_item_list) do
v:SetVisible(false)
end
local data = {"世界拍卖", "社团拍卖"}
local function click_func( index )
self:SwitchHorTab(index)
end
local count = 0
for i,v in ipairs(data) do
local item = self.tab_item_list[count+1]
if not item then
item = MarketHorTabItem.New(self.tab_con)
item:SetPosition(count * 124, 0)
self.tab_item_list[count+1] = item
end
item:SetClickFunc(click_func)
count = count + 1
item:SetData(count, v)
item:SetVisible(true)
end
self:SwitchHorTab(self.cur_hor_tab_index)
end
function MarketBuyHallView:SwitchHorTab( index, sub_type )
self.is_first = true--为了能刷新列表
for i,v in pairs(self.tab_item_list) do
v:SetSelect(i==index)
end
self.cur_hor_tab_index = index--当前选的tab
if self.cur_hor_tab_index == 2 then
self.model:SetHasGuildGoods(false)
end
if self.cur_hor_tab_index == 1 then
self.sell_type = 0
self.sell_sub_type = nil
else
self.sell_type = 0
self.sell_sub_type = nil
end
self.need_reset = true
self:UpdateVerTabBtns(true)
end
function MarketBuyHallView:UpdateVerTabBtns( need_refresh )
if self.cur_hor_tab_index == 1 then
self.tab_cfg = self.model:GetMarketCFG()
else
self.tab_cfg = self.model:GetMarketGuildCFG()
end
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
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--没选中就默认选第一个
if self.model:CheckMarketCanSelectZero(self.sell_type) then
self.sell_sub_type = 0
else
self.sell_sub_type = 1
end
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
local sell_sub_type_temp = nil
if self.model:CheckMarketCanSelectZero(self.sell_type) then
sell_sub_type_temp = 0
else
sell_sub_type_temp = 1
end
if self.cur_hor_tab_index == 1 then
self.model:CleanMarketGoodsInfoByType(self.sell_type or self.last_sell_type, self.sell_sub_type or sell_sub_type_temp)
else
self.model:CleanMarketGuildGoodsInfoByType(self.sell_type or self.last_sell_type, self.sell_sub_type or sell_sub_type_temp)
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)
if self.cur_hor_tab_index == 1 then
item:SetData(v, i, self.sell_type, self.sell_sub_type)
else
item:SetData(v, i, self.sell_type, self.sell_sub_type, MarketModel.VER_TAB_TYPE.GUILD_TYPE)
end
item:SetCallBackFunc(call_back)
end,
}
self.tab_creator:UpdateItems(tag_all_info)
if self.is_first then
self:UpdateSelectVer(true)
self:UpdateGoodsList()
-- self:OnTouchEnd(0,0,true)
self.is_first = false
end
if need_refresh then
self:UpdateFliter()
end
end
--设置垂直tab选择
function MarketBuyHallView:UpdateSelectVer( need_refresh )
self.tab_creator:IterateItems(function(item, i, v)
item:SetSelect(self.sell_type, self.sell_sub_type)
end)
self:OnTouchEnd(0,0,true)
if need_refresh then
self:ScrollToSelectItem()
end
end
function MarketBuyHallView:ScrollToSelectItem( )
if not self.sell_sub_type then--如果没有选中第二层的item就默认选第一个
self.sell_sub_type = 1
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 MarketBuyHallView:UpdateGoodsList( )
local goods_list = self.model:GetMarketGoodsInfo(self.sell_type or self.last_sell_type, self.sell_sub_type)
if self.cur_hor_tab_index == 2 then
goods_list = self.model:GetMarketGuildGoodsInfo(self.sell_type or self.last_sell_type, self.sell_sub_type)
end
local data = {}
local page = TableSize(goods_list)
for i=1,page do
if goods_list[page] then
for i,v in ipairs(goods_list[i]) do
data[#data+1] = v
end
end
end
if TableSize(data) == 0 then
self.empty_obj:SetActive(true)
self.empty_text_tmp.text = "还没有该类商品出售哦~"
else
self.empty_obj:SetActive(false)
end
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 = MarketGoodsItem,
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 MarketBuyHallView:RequestGoodsListWithPage(page)
--判断page是否合法
if self.cur_hor_tab_index == 1 and not self.model:IsLastGoodsPage(self.sell_type or self.last_sell_type, self.sell_sub_type) then
self.model:Fire(MarketModel.REQUEST_CCMD_EVENT, 15501, self.cur_hor_tab_index, self.sell_type or self.last_sell_type, self.sell_sub_type, self.series_limit,
self.color, self.career_limit, self.page_size, page, self.sort_id, self.sort_order)
elseif self.cur_hor_tab_index == 2 and not self.model:IsLastGuildGoodsPage(self.sell_type or self.last_sell_type, self.sell_sub_type) then
self.model:Fire(MarketModel.REQUEST_CCMD_EVENT, 15501, self.cur_hor_tab_index, self.sell_type or self.last_sell_type, self.sell_sub_type, self.series_limit,
self.color, self.career_limit, self.page_size, page, self.sort_id, self.sort_order)
else
-- Message.show("已经是最后一页了哦~")
end
end
function MarketBuyHallView:OnTouchEnd(pos_x,pos_y, is_force)
local tempPos = self.right_con.transform.localPosition --获取拖动的值
local num = 0
if self.cur_hor_tab_index == 2 then
num = self.model:GetMarketGuildGoodsListNum(self.sell_type or self.last_sell_type, self.sell_sub_type)
else
num = self.model:GetMarketGoodsListNum(self.sell_type or self.last_sell_type, self.sell_sub_type)
end
local page = math.ceil(num / self.page_size)
local total_height = MarketGoodsItem.HEIGHT * num
if tempPos.y - MarketGoodsItem.HEIGHT * (num-self.page_size) >= 0 or is_force then
self:RequestGoodsListWithPage(page + 1)
end
end
--用来请求一下当前选中页签内容
function MarketBuyHallView:RefreshData( )
if self.cur_hor_tab_index == 1 then
self.model:CleanMarketGoodsInfo()
else
self.model:CleanMarketGuildGoodsInfo()
end
self:UpdateView()
end
function MarketBuyHallView:__delete()
self.model:CleanMarketGoodsInfo()
self.model:CleanMarketGuildGoodsInfo()
if self.on_update_goods_id then
self.model:UnBind(self.on_update_goods_id)
self.on_update_goods_id = nil
end
if self.on_update_guild_goods_id then
self.model:UnBind(self.on_update_guild_goods_id)
self.on_update_guild_goods_id = nil
end
for _, v in pairs(self.tab_item_list) do
v:DeleteMe()
v = nil
end
self.tab_item_list = {}
if self.on_refresh_data_id then
self.model:UnBind(self.on_refresh_data_id)
self.on_refresh_data_id = nil
end
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