源战役客户端
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.
 
 
 
 
 

276 rivejä
8.3 KiB

CSMainExploitRankView = CSMainExploitRankView or BaseClass(BaseView)
local CSMainExploitRankView = CSMainExploitRankView
function CSMainExploitRankView:__init()
self.base_file = "csMain"
self.layout_file = "CSMainExploitRankView"
self.layer_name = "Activity"
self.destroy_imm = true
self.use_background = true
self.change_scene_close = true
self.hide_maincancas = true --是否隐藏主界面
self.append_to_ctl_queue = false --是否要添加进界面堆栈
self.need_show_money = false --是否要显示顶部的金钱栏
self.is_set_zdepth = true
self.mainVo = RoleManager.Instance.mainRoleInfo
self.tab_item_list = {}
self.top_item_list = {}
self.model = CSMainModel:getInstance()
self.current_index = nil
self.my_contray_id = KfWorldModel:GetInstance():GetMyCountryId()
self.load_callback = function ()
self:LoadSuccess()
self:AddEvent()
end
self.open_callback = function ( )
self:OpenSuccess()
end
self.destroy_callback = function ( )
self:DestroySuccess()
end
end
function CSMainExploitRankView:Open(index)
self.current_index = index or 1
BaseView.Open(self)
end
function CSMainExploitRankView:LoadSuccess()
local nodes = {
"closeBtn:obj", "bg:raw", "tabCon", "topbg:img",
"myRankCon:obj", "myRankCon/myRankIcon:img:obj", "myRankCon/mySex:img",
"myRankCon/myVipCon", "myRankCon/myRank:tmp", "myRankCon/myName:tmp", "myRankCon/myGuildName:tmp", "myRankCon/myScore:tmp",
"rankScrollView", "rankScrollView/Viewport/rankContent",
"topCon", "titleCon",
"rewardBtn:obj", "rewardBtn/rewardRed:obj",
"rankEmpty:obj", "rankEmpty/rankEmptyTalkBg:raw",
"myRankCon/myMilitaryRank:img",
}
self:GetChildren(nodes)
lua_resM:setOutsideRawImage(self,self.bg_raw,GameResPath.GetViewBigBg("cs_main_exploit_bg"))
lua_resM:setOutsideRawImage(self, self.rankEmptyTalkBg_raw, GameResPath.GetRoleBg("empty_bg_small"))
self.model:Fire(CSMainConst.REQUEST_CCMD_EVENT,60308)
self.myVipItem = RoleVipItem.New(self.myVipCon)
end
function CSMainExploitRankView:AddEvent()
local on_click = function ( click_obj )
if self.closeBtn_obj == click_obj then
self:Close()
elseif self.rewardBtn_obj == click_obj then
self.model:Fire(CSMainConst.OPEN_CS_MAIN_EXPLOIT_RANK_DAILY_REWARD_VIEW)
end
end
AddClickEvent(self.closeBtn_obj, on_click)
AddClickEvent(self.rewardBtn_obj, on_click)
-- --60308
-- local function on_update_rank_data_extra()
-- end
-- self:BindEvent(self.model, CSMainConst.UPDATE_EXPLOIT_RANK_DATA_EXTRA, on_update_rank_data_extra)
--60307
local function on_update_rank_con(vo)
if self.current_contray_index and vo.fact == self.current_contray_index then
self:UpdateRankCon(vo)
end
end
self:BindEvent(self.model, CSMainConst.UPDATE_EXPLOIT_RANK_CON, on_update_rank_con)
local function update_red_dot(tab_id)
if not self.is_loaded then return end
if tab_id == CSMainConst.RedType.DailyReward then
self:RefreshRed()
end
end
self:BindEvent(self.model, CSMainConst.ANS_UPDATE_RED_DOT, update_red_dot)
local function CLICK_GET_WAY_ITEM( )
self:Close()
end
self:BindEvent(GlobalEventSystem, EventName.CLICK_GET_WAY_ITEM, CLICK_GET_WAY_ITEM)
end
function CSMainExploitRankView:OpenSuccess()
self:InitTab()
self:RefreshRed()
end
function CSMainExploitRankView:RefreshRed( )
local red = self.model:GetDailyRewardRed()
self.rewardRed_obj:SetActive(red)
end
function CSMainExploitRankView:InitTab( )
if not self.my_contray_id then return end
local contray_list = KfWorldModel:GetInstance():GetContrayList()
local tab_data = {}
local first_data = {name = contray_list[self.my_contray_id], contray_id = self.my_contray_id}
table.insert(tab_data, first_data)
for i,v in ipairs(contray_list) do
if i ~= self.my_contray_id then
local temp = {name = v, contray_id = i}
table.insert(tab_data, temp)
end
end
local function call_back(tab_index,contray_id)
self:SwitchTab(tab_index,contray_id)
end
for k,v in pairs(self.tab_item_list) do
v:SetVisible(false)
end
for i,v in ipairs(tab_data) do
local item = self.tab_item_list[i]
if not item then
item = CSMainExploitRankTab.New(self.tabCon)
self.tab_item_list[i] = item
end
item:SetVisible(true)
item:SetData(v,i,call_back)
item:SetAnchoredPosition(-2, 41-(i-1)*(74-5))
end
for k,v in pairs(self.tab_item_list) do
v:OnClick(self.current_index)
end
end
function CSMainExploitRankView:SwitchTab( index,contray_id )
self.current_index = index
self.current_contray_index = contray_id
self.model:Fire(CSMainConst.REQUEST_CCMD_EVENT,60307,contray_id)
end
function CSMainExploitRankView:UpdateRankCon(vo)
if not self.my_contray_id then return end
local is_my_contray = vo.fact == self.my_contray_id
if is_my_contray then
SetAnchoredPositionY(self.titleCon,73.5)
SetSizeDeltaY(self.rankScrollView,275)
SetAnchoredPositionY(self.rankScrollView,-82)
lua_resM:setOutsideImageSprite(self, self.png_img, GameResPath.GetCSMainImage("cs_main_top_di_long"),true)
else
SetAnchoredPositionY(self.titleCon,112)
SetSizeDeltaY(self.rankScrollView,305)
SetAnchoredPositionY(self.rankScrollView,-58)
lua_resM:setOutsideImageSprite(self, self.png_img, GameResPath.GetCSMainImage("cs_main_top_di_short"),true)
end
--排行榜
local sort_func = function ( a, b )
return a.rank < b.rank
end
table.sort(vo.ranks, sort_func)
local final_rank_list = {}
local max_show_ranks = Config.Legionkv["honor_max_rank"].value
for i=1,max_show_ranks do
if vo.ranks[i] then
table.insert(final_rank_list,vo.ranks[i])
end
end
if not self.item_list_com then
self.item_list_com = self:AddUIComponent(UI.ItemListCreator)
end
self.item_list_com:Reset()
local info = {
data_list = final_rank_list,
item_con = self.rankContent,
item_class = CSMainExploitRankItem,
item_width = 900,
item_height = 50,
-- space_x = 0,
-- space_y = 0,
start_x = 0,
start_y = -0.5,
scroll_view = self.rankScrollView,
create_frequency = 0.01,
on_update_item = function(item, i, v)
item:SetData(v,i)
end,
}
self.item_list_com:UpdateItems(info)
self.rankEmpty_obj:SetActive(#vo.ranks == 0)
--top5
for k,v in pairs(self.top_item_list) do
v:SetVisible(false)
end
for i=1,5 do
local top_rank_data = vo.ranks and vo.ranks[i] or nil
local item = self.top_item_list[i]
if not item then
item = CSMainExploitRankTopItem.New(self.topCon)
self.top_item_list[i] = item
end
item:SetData(top_rank_data,i,is_my_contray)
item:SetAnchoredPosition(CSMainConst.ExploitTopItemPos[i].main_pos_x, CSMainConst.ExploitTopItemPos[i].main_pos_y)
item:SetVisible(true)
end
--我的排名
if is_my_contray then
lua_resM:setOutsideImageSprite(self, self.topbg_img, GameResPath.GetCSMainImage("cs_main_top_di_long"), true)
self.myVipItem:SetData(self.mainVo.vip_flag,self.mainVo.sup_vip_type)
self.myName_tmp.text = GetCSLongName(self.mainVo.name,self.mainVo.server_num)
local sex_res = self.mainVo.sex == 1 and "com_boy" or "com_girl"
lua_resM:setImageSprite(self, self.mySex_img, "common_asset", sex_res, true)
SetAnchoredPositionX(self.mySex, -288+self.myName_tmp.preferredWidth+15)
self.myGuildName_tmp.text = self.mainVo.guild_name ~= "" and self.mainVo.guild_name or "暂无社团"
--拿到自己的排名
local my_rank = vo.myrank
local my_score = vo.myscore
if my_rank == 0 then
self.myRankIcon_obj:SetActive(false)
self.myRank_tmp.text = "未上榜"
elseif my_rank >= 1 and my_rank <= 5 then
self.myRankIcon_obj:SetActive(true)
self.myRank_tmp.text = ""
lua_resM:setImageSprite(self, self.myRankIcon_img, "csMain_asset","cs_main_rank_"..my_rank,true)
else
self.myRankIcon_obj:SetActive(false)
self.myRank_tmp.text = my_rank
end
self.myRankCon_obj:SetActive(true)
self.myScore_tmp.text = my_score
lua_resM:setOutsideImageSprite(self, self.myMilitaryRank_img, GameResPath.GetMilitaryImage("military_ranks_"..RoleManager.Instance.mainRoleInfo.military_ranks), true)
else
lua_resM:setOutsideImageSprite(self, self.topbg_img, GameResPath.GetCSMainImage("cs_main_top_di_short"), true)
self.myRankCon_obj:SetActive(false)
end
end
function CSMainExploitRankView:DestroySuccess( )
for i, v in ipairs(self.tab_item_list) do
v:DeleteMe()
end
self.tab_item_list = {}
for i, v in ipairs(self.top_item_list) do
v:DeleteMe()
end
self.top_item_list = {}
if self.myVipItem then
self.myVipItem:DeleteMe()
self.myVipItem = nil
end
end