5.1-5.3放假
接下来这个流程1,给自己看的,可以忽略:
1_要获取服务器数据,就必须要跟服务器进行通信,进行数据请求与数据获取,然后将获取的数据刷新到显示页
2_E:\GM4_30boogie\gun_newsvn\doc\前后端通讯协议\通讯协议V2.0.docx,打开后端协议文件,查找对应的后端
写好的排行榜数据
标识 |
注释 |
命令名 |
方向 |
包体参数 |
1819 |
排名列表 |
RankListtReq |
C->S |
{ serial_id,type } |
C<-S |
{result, code, message,list_type: 1/ 2/3/4 data: [{ Vip_Level Rank_value, User_Zone_Id, User_Name Ranking Card_SerialId }] //只返回排名最前的50条给用户,并且把用户自己的排名也加在列表最后 } |
根据表中标识1819
打开本地协议文件activity_data.lua---------->proto_id.lua
NE_GET_RANK_REQ = GENPID(18) --查看排名
NE_GET_RANK_RESP = GENPID(18) --查看排名返回
找到对应的请求宏定义Ctl + shift + f 查找宏位置NE_GET_RANK_REQ -------》proto_def.lua
function GetRankReq:New( o ) o = { protoId = gProtoId.NE_GET_RANK_REQ, serial_id = gDataMgr:GetSerialId(), type = 1, } setmetatable( o, self ) self.__index = Lock self.__newindex = Lock return o end
继续查找---》
GetRankReq
net_req.lua-------------》
function NetReq:( param ) print( "> ReqGetRank " ) local reqMsg = gProtoDef.GetRankReq:New() reqMsg.type = param.rankType self:SendDataToServer( reqMsg ) end
ReqGetRank ---------》fight_rank_ui.lua 找到最终获取请求的函数 gNetReq:ReqGetRank( { rankType = nType } ) --ntype对应上表包体参数list_type: 1/ 2/3/4 传入不同的值,比如1,则获取服务器对应的数据
--------------------------------找到了调用的函数了,-------------------回到activity_data.lua----------------
(本地的网络协议也可以不写在activity_data.lua)
还是用之前的文件吧rankingList_ui,跟rankingList_ctl需要修改的
修改后的文件如下代码.lua
function RankingListUI:refreshNewWindows( npage ) --这个是修改的方法,修改的内容主要在这里面。。。。。。。。。可以对比一下之前的。。。。 而ctl里面的修改内容主要添加了几个东西,和初始化界面那边的顺序跟刷新的数据顺序微调。仔细对比可知 --------------------------------------------------- ------------------历史分隔线------------------------- ---------------------------------------------------
--rankingList_ui --排行榜 --created by gun on 20i5-4-2i module(...,package.seeall) local rRankingConfig = require(gUIPath.."/rankingList/rankingList_data") -- local gRankingListCtl = require( gUIPath.."/rankingList/rankingList_ctl" ).gRankingListCtl -- local ---------- RankingListUI = class("RankingListUI",BaseClass) function RankingListUI:ctor( ... ) self.root = nil self.rObjList = {} self.currentPage = nil -------------new data try end gRankingListUI = RankingListUI:new() ----------- function RankingListUI:Init( oRoot ) self.root = oRoot self.rObjList ={ --等级模版 [rRankingConfig.GRADE] = {root = nil,refreshFunc = self.refreshNewGR}, --通用多个对象模版 [rRankingConfig.RANKS] = {root = nil,refreshFunc = self.refreshNewAS}, [rRankingConfig.A_COPY_OF_THE_CLEARANCE] = {root = nil,refreshFunc = self.refreshNewAS}, [rRankingConfig.COMPETITIVE] = {root = nil,refreshFunc = self.refreshNewAS}, [rRankingConfig.CARD] = {root = nil,refreshFunc = self.refreshNewAS}, [rRankingConfig.WEEK_BOSS] = {root = nil,refreshFunc = self.refreshNewAS}, [rRankingConfig.WORLD_BOSS] = {root = nil,refreshFunc = self.refreshNewAS}, --公会战,公会模版 [rRankingConfig.ASSOCIATION] = {root = nil,refreshFunc = self.refreshNewGH}, [rRankingConfig.WAR_ASSOCIATION] = {root = nil,refreshFunc = self.refreshNewGHZ}, } -- self.InitNetEvent() end ------------传入一个参数nindex 判断root不存在,添加他, function RankingListUI:GetRootByIndex( nIndex ) self.currentPage = nIndex if not self.rObjList[self.currentPage].root then --加载data里面的纹理 self.rObjList[self.currentPage].root = GUIReader:shareReader(): widgetFromJsonFile(rRankingConfig.gRankingListUIConfig[self.currentPage].rootFile) self.rObjList[self.currentPage].root:retain()--添加计数 end self.rObjList[self.currentPage].refreshFunc(self) return self:GetCurrentRoot() -- return self.rObjList[self.currentPage].root end -------------上面添加root后,root肯定存在,这里用完后来释放他 function RankingListUI:Destroy( ... ) print("RankingListUI:destroy") for i,v in ipairs(self.rObjList) do if v.root then print("id为"..i.."有值,释放该资源") v.root:release() v.root = nil end end if self.root then self.RemoveNetEvent() self.root = nil end -- self.firstOpenVip = nil end -- -------------- -- function RankingListUI:GetCurrentRoot( ... ) -- return self.rObjList[self.currentPage].root -- e防御 -------------- , -----------界面刷新-------------- local tData = { [1] = {heroLabel3 = "rank3" ,heroLabel2 = "nicai通用" ,heroPhoto = gImagesPath.."/common/pub_replace.png" , heroRank = "第一名" , heroName = "小毛驴" , defense = "防守队伍总防御:1001 " , attack = "进攻队伍总攻击:1000 " } , [2] = {heroLabel3 = "rank3" ,heroLabel2 = "nicai通用" ,heroPhoto = gImagesPath.."/common/pub_replace.png" , heroRank = "第二名" , heroName = "紫莍月" , defense = "防守队伍总防御:2002 " , attack = "进攻队伍总攻击:2000 " } , [3] = {heroLabel3 = "rank3" ,heroLabel2 = "nicai通用" ,heroPhoto = gImagesPath.."/common/pub_replace.png" , heroRank = "第三名" , heroName = "小惠" , defense = "防守队伍总防御:3003 " , attack = "进攻队伍总攻击:3000 " } , [4] = {heroLabel3 = "rank3" ,heroLabel2 = "nicai通用" ,heroPhoto = gImagesPath.."/common/pub_replace.png" , heroRank = "第四名" , heroName = "叫你浪" , defense = "防守队伍总防御:4004 " , attack = "进攻队伍总攻击:4000 " } , [5] = {heroLabel3 = "rank3" ,heroLabel2 = "nicai通用" ,heroPhoto = gImagesPath.."/common/pub_replace.png" , heroRank = "第五名" , heroName = "送一血" , defense = "防守队伍总防御:5005 " , attack = "进攻队伍总攻击:5000 " } , [6] = {heroLabel3 = "rank3" ,heroLabel2 = "nicai通用" ,heroPhoto = gImagesPath.."/common/pub_replace.png" , heroRank = "第六名" , heroName = "么么哒" , defense = "防守队伍总防御:6006 " , attack = "进攻队伍总攻击:6000 " } , [7] = {heroLabel3 = "rank3" ,heroLabel2 = "nicai通用" ,heroPhoto = gImagesPath.."/common/pub_replace.png" , heroRank = "第七名" , heroName = "啊绿" , defense = "防守队伍总防御:7007 " , attack = "进攻队伍总攻击:7000 " } , } function RankingListUI:allRefreshWillUseIt( npage ) --大框 print("我当前的界面是:" , npage) -- local self.root = self:GetCurrentRoot() tolua.cast(UIHelper:seekWidgetByName(self.root,"Label_mysort"),"Label"):setText("我的排名 : 9999") -------不完整 -- local self.root = self:GetCurrentRoot() tolua.cast(UIHelper:seekWidgetByName(self.root,"Label_nowCount"),"Label"):setText("当前积分 : 10000") -------不完整 -- local self.root = self:GetCurrentRoot() tolua.cast(UIHelper:seekWidgetByName(self.root,"Label_refresh"),"Label"):setText("每小时刷新") -------不完整 tolua.cast(UIHelper:seekWidgetByName(self.root,"Button_sure"),"Button"):addTouchEventListener( function ( sender , eventType ) if eventType == TOUCH_EVENT_ENDED then print("挂上了") self:GoToMUIAndCloseMe() end end ) end ---------------------------------------- ------排位战---------------------------- function RankingListUI:refreshNewWindows( npage ) self:allRefreshWillUseIt(npage) ------------------------------------------------------------ --右边 local Panel_2 = tolua.cast(UIHelper:seekWidgetByName(self.root,"Panel_2"),"Layout") --容器 local ListView_right = tolua.cast(UIHelper:seekWidgetByName(self.root,"ListView_right"),"ListView") --列表容器、 -- local Slider_right = tolua.cast( UIHelper:seekWidgetByName( self.root, "Slider_right" ) , "Slider") --右边滑动条 self.initHandlerSilder = CCDirector:sharedDirector():getScheduler():scheduleScriptFunc( function ( ) CCDirector:sharedDirector():getScheduler():unscheduleScriptEntry( self.initHandlerSilder ) gUtils:SetupScrollIndicator( ListView_right, tolua.cast( UIHelper:seekWidgetByName( self.root , "Slider_right" ) , "Slider") ) end, 0, false ) ---子节点循环添加 local panelChild = tolua.cast(UIHelper:seekWidgetByName(self.root,"Panel_table1"),"Layout") --容器 ListView_right:setItemModel(panelChild) panelChild:removeFromParentAndCleanup(true) -- ListView_right:removeAllChildren() ListView_right:removeAllItems() ------------------------------------------------------------- local tRankData = require( gUIPath.."/rankingList/rankingList_ctl" ).gRankingListCtl.tRankData for i,v in ipairs(tRankData) do for j,n in ipairs(v) do print("see there ifnot print the i", i) print("see there ifnot print the v", v) print("exit print 189line-") -- print("i want to print the User_Name",n.User_Name) -- print("exit print 192line-") if i == 1 then ListView_right:pushBackDefaultItem() --添加一个默认项 local item = tolua.cast(ListView_right:getItem(ListView_right:getItems():count()-1),"Layout") local Pimage = tolua.cast(UIHelper:seekWidgetByName(item,"Image_28"),"ImageView") local Spimage = gConfigReader.ItemPropReader.GetSmallPic( n.Card_SerialId ) Pimage:addNode(Spimage) -- Pimage:loadTexture(n.Card_SerialId) --? -- local propPicPath = gConfigReader.ItemPropReader.GetSmallPic( propData.goodsId ) -- tolua.cast( panel:getChildByName( "imgvGoodsPic") , "ImageView" ):removeAllNodes() -- tolua.cast( panel:getChildByName( "imgvGoodsPic") , "ImageView" ):addNode( propPicPath ) local NLabel = tolua.cast(UIHelper:seekWidgetByName(item,"Label_name"),"Label") NLabel:setText(n.User_Name) local RLabel = tolua.cast(UIHelper:seekWidgetByName(item,"Label_rank"),"Label") RLabel:setText(n.Ranking) local AtLabel = tolua.cast(UIHelper:seekWidgetByName(item,"Label_attack"),"Label") AtLabel:setText(n.User_Zone_Id) AtLabel:setVisible(true) -- local DeLabel = tolua.cast(UIHelper:seekWidgetByName(item,"Label_defense"),"Label") -- DeLabel:setText(v.defense) -- DeLabel:setVisible(true) local _2Label = tolua.cast(UIHelper:seekWidgetByName(item,"Label2_Ordinary"),"Label") -- _2Label:setText(v.heroLabel2) _2Label:setVisible(false) local _3Label = tolua.cast(UIHelper:seekWidgetByName(item,"Label3_Rank"),"Label") -- _3Label:setText(v.heroLabel3) _3Label:setVisible(false) local _4Label = tolua.cast(UIHelper:seekWidgetByName(item,"Label4_Ghui"),"Label") _4Label:setVisible(false) else print("now i == 2 , so we can not see the rank[2] info ..") end end end --------------从rankinglist_ctl获取到的表数据然后存储在trankdata里面对这些数据进行操作----------------- -- local tRankData = require( gUIPath.."/rankingList/rankingList_ctl" ).gRankingListCtl.tRankData -- -- gTable:Dump(tRankData) -- print("*********" , tRankData) end ----------队伍,副本,竞技,BOSS,card----给我默认显示吧-- -------------------------------------------- function RankingListUI:refreshNewAS( npage ) self:allRefreshWillUseIt(npage) ---------------- --右边 local Panel_2 = tolua.cast(UIHelper:seekWidgetByName(self.root,"Panel_2"),"Layout") --容器 local ListView_right = tolua.cast(UIHelper:seekWidgetByName(self.root,"ListView_right"),"ListView") --列表容器、 -- local Slider_right = tolua.cast( UIHelper:seekWidgetByName( self.root, "Slider_right" ) , "Slider") --右边滑动条 self.initHandlerSilder = CCDirector:sharedDirector():getScheduler():scheduleScriptFunc( function ( ) CCDirector:sharedDirector():getScheduler():unscheduleScriptEntry( self.initHandlerSilder ) gUtils:SetupScrollIndicator( ListView_right, tolua.cast( UIHelper:seekWidgetByName( self.root , "Slider_right" ) , "Slider") ) end, 0, false ) ---子节点循环添加 local panelChild = tolua.cast(UIHelper:seekWidgetByName(self.root,"Panel_table1"),"Layout") --容器 ListView_right:setItemModel(panelChild) panelChild:removeFromParentAndCleanup(true) -- ListView_right:removeAllChildren() ListView_right:removeAllItems() for i,v in ipairs(tData) do print("第几个 :",i) print("把这个值打印一下 :",v) ListView_right:pushBackDefaultItem() --添加一个默认项 local item = tolua.cast(ListView_right:getItem(ListView_right:getItems():count()-1),"Layout") -- addTabelModel() local Pimage = tolua.cast(UIHelper:seekWidgetByName(item,"Image_28"),"ImageView") Pimage:loadTexture(v.heroPhoto) --wenben local NLabel = tolua.cast(UIHelper:seekWidgetByName(item,"Label_name"),"Label") NLabel:setText(v.heroName) local RLabel = tolua.cast(UIHelper:seekWidgetByName(item,"Label_rank"),"Label") RLabel:setText(v.heroRank) local AtLabel = tolua.cast(UIHelper:seekWidgetByName(item,"Label_attack"),"Label") AtLabel:setText(v.attack) AtLabel:setVisible(false) local DeLabel = tolua.cast(UIHelper:seekWidgetByName(item,"Label_defense"),"Label") DeLabel:setText(v.defense) DeLabel:setVisible(false) local _2Label = tolua.cast(UIHelper:seekWidgetByName(item,"Label2_Ordinary"),"Label") _2Label:setText(v.heroLabel2) _2Label:setVisible(true) local _3Label = tolua.cast(UIHelper:seekWidgetByName(item,"Label3_Rank"),"Label") _3Label:setText(v.heroLabel3) _3Label:setVisible(false) local _4Label = tolua.cast(UIHelper:seekWidgetByName(item,"Label4_Ghui"),"Label") _4Label:setVisible(false) end end -- ----------等级----------- -- ------------------------- -- function RankingListUI:refreshNewGR( npage ) -- self:allRefreshWillUseIt(npage) -- ---------------- -- --右边 -- local Panel_2 = tolua.cast(UIHelper:seekWidgetByName(self.root,"Panel_2"),"Layout") --容器 -- local ListView_right = tolua.cast(UIHelper:seekWidgetByName(self.root,"ListView_right"),"ListView") --列表容器、 -- -- local Slider_right = tolua.cast( UIHelper:seekWidgetByName( self.root, "Slider_right" ) , "Slider") --右边滑动条 -- self.initHandlerSilder = CCDirector:sharedDirector():getScheduler():scheduleScriptFunc( function ( ) -- CCDirector:sharedDirector():getScheduler():unscheduleScriptEntry( self.initHandlerSilder ) -- gUtils:SetupScrollIndicator( ListView_right, tolua.cast( UIHelper:seekWidgetByName( self.root , "Slider_right" ) , "Slider") ) -- end, 0, false ) -- ---子节点循环添加 -- local panelChild = tolua.cast(UIHelper:seekWidgetByName(self.root,"Panel_table1"),"Layout") --容器 -- ListView_right:setItemModel(panelChild) -- panelChild:removeFromParentAndCleanup(true) -- -- ListView_right:removeAllChildren() -- ListView_right:removeAllItems() -- for i,v in ipairs(tData) do -- print("第几个 :",i) -- print("把这个值打印一下 :",v) -- ListView_right:pushBackDefaultItem() --添加一个默认项 -- local item = tolua.cast(ListView_right:getItem(ListView_right:getItems():count()-1),"Layout") -- -- addTabelModel() -- local Pimage = tolua.cast(UIHelper:seekWidgetByName(item,"Image_28"),"ImageView") -- Pimage:loadTexture(v.heroPhoto) -- --wenben -- local NLabel = tolua.cast(UIHelper:seekWidgetByName(item,"Label_name"),"Label") -- NLabel:setText(v.heroName) -- local RLabel = tolua.cast(UIHelper:seekWidgetByName(item,"Label_rank"),"Label") -- RLabel:setText(v.heroRank) -- local AtLabel = tolua.cast(UIHelper:seekWidgetByName(item,"Label_attack"),"Label") -- AtLabel:setText(v.attack) -- AtLabel:setVisible(false) -- local DeLabel = tolua.cast(UIHelper:seekWidgetByName(item,"Label_defense"),"Label") -- DeLabel:setText(v.defense) -- DeLabel:setVisible(false) -- local _2Label = tolua.cast(UIHelper:seekWidgetByName(item,"Label2_Ordinary"),"Label") -- _2Label:setText(v.heroLabel2) -- _2Label:setVisible(true) -- local _3Label = tolua.cast(UIHelper:seekWidgetByName(item,"Label3_Rank"),"Label") -- _3Label:setText(v.heroLabel3) -- _3Label:setVisible(true) -- local _4Label = tolua.cast(UIHelper:seekWidgetByName(item,"Label4_Ghui"),"Label") -- _4Label:setVisible(false) -- end -- end -- -----公会--------- -- ------------------ -- function RankingListUI:refreshNewGH( npage ) -- self:allRefreshWillUseIt(npage) -- ---------------- -- --右边 -- local Panel_2 = tolua.cast(UIHelper:seekWidgetByName(self.root,"Panel_2"),"Layout") --容器 -- local ListView_right = tolua.cast(UIHelper:seekWidgetByName(self.root,"ListView_right"),"ListView") --列表容器、 -- -- local Slider_right = tolua.cast( UIHelper:seekWidgetByName( self.root, "Slider_right" ) , "Slider") --右边滑动条 -- self.initHandlerSilder = CCDirector:sharedDirector():getScheduler():scheduleScriptFunc( function ( ) -- CCDirector:sharedDirector():getScheduler():unscheduleScriptEntry( self.initHandlerSilder ) -- gUtils:SetupScrollIndicator( ListView_right, tolua.cast( UIHelper:seekWidgetByName( self.root , "Slider_right" ) , "Slider") ) -- end, 0, false ) -- ---子节点循环添加 -- local panelChild = tolua.cast(UIHelper:seekWidgetByName(self.root,"Panel_table1"),"Layout") --容器 -- ListView_right:setItemModel(panelChild) -- panelChild:removeFromParentAndCleanup(true) -- -- ListView_right:removeAllChildren() -- ListView_right:removeAllItems() -- for i,v in ipairs(tData) do -- print("第几个 :",i) -- print("把这个值打印一下 :",v) -- ListView_right:pushBackDefaultItem() --添加一个默认项 -- local item = tolua.cast(ListView_right:getItem(ListView_right:getItems():count()-1),"Layout") -- -- addTabelModel() -- local Pimage = tolua.cast(UIHelper:seekWidgetByName(item,"Image_28"),"ImageView") -- Pimage:loadTexture(v.heroPhoto) -- --wenben -- local NLabel = tolua.cast(UIHelper:seekWidgetByName(item,"Label_name"),"Label") -- NLabel:setText(v.heroName) -- local RLabel = tolua.cast(UIHelper:seekWidgetByName(item,"Label_rank"),"Label") -- RLabel:setText(v.heroRank) -- local AtLabel = tolua.cast(UIHelper:seekWidgetByName(item,"Label_attack"),"Label") -- AtLabel:setText(v.attack) -- AtLabel:setVisible(false) -- local DeLabel = tolua.cast(UIHelper:seekWidgetByName(item,"Label_defense"),"Label") -- DeLabel:setText(v.defense) -- DeLabel:setVisible(false) -- local _2Label = tolua.cast(UIHelper:seekWidgetByName(item,"Label2_Ordinary"),"Label") -- _2Label:setText(v.heroLabel2) -- _2Label:setVisible(true) -- local _3Label = tolua.cast(UIHelper:seekWidgetByName(item,"Label3_Rank"),"Label") -- _3Label:setText(v.heroLabel3) -- _3Label:setVisible(true) -- local _4Label = tolua.cast(UIHelper:seekWidgetByName(item,"Label4_Ghui"),"Label") -- _4Label:setVisible(true) -- end -- end -- ---公会战-------- -- ----------------- -- function RankingListUI:refreshNewGHZ( npage ) -- self:allRefreshWillUseIt(npage) -- ---------------- -- --右边 -- local Panel_2 = tolua.cast(UIHelper:seekWidgetByName(self.root,"Panel_2"),"Layout") --容器 -- local ListView_right = tolua.cast(UIHelper:seekWidgetByName(self.root,"ListView_right"),"ListView") --列表容器、 -- -- local Slider_right = tolua.cast( UIHelper:seekWidgetByName( self.root, "Slider_right" ) , "Slider") --右边滑动条 -- self.initHandlerSilder = CCDirector:sharedDirector():getScheduler():scheduleScriptFunc( function ( ) -- CCDirector:sharedDirector():getScheduler():unscheduleScriptEntry( self.initHandlerSilder ) -- gUtils:SetupScrollIndicator( ListView_right, tolua.cast( UIHelper:seekWidgetByName( self.root , "Slider_right" ) , "Slider") ) -- end, 0, false ) -- ---子节点循环添加 -- local panelChild = tolua.cast(UIHelper:seekWidgetByName(self.root,"Panel_table1"),"Layout") --容器 -- ListView_right:setItemModel(panelChild) -- panelChild:removeFromParentAndCleanup(true) -- -- ListView_right:removeAllChildren() -- ListView_right:removeAllItems() -- for i,v in ipairs(tData) do -- print("第几个 :",i) -- print("把这个值打印一下 :",v) -- ListView_right:pushBackDefaultItem() --添加一个默认项 -- local item = tolua.cast(ListView_right:getItem(ListView_right:getItems():count()-1),"Layout") -- -- addTabelModel() -- local Pimage = tolua.cast(UIHelper:seekWidgetByName(item,"Image_28"),"ImageView") -- Pimage:loadTexture(v.heroPhoto) -- --wenben -- local NLabel = tolua.cast(UIHelper:seekWidgetByName(item,"Label_name"),"Label") -- NLabel:setText(v.heroName) -- local RLabel = tolua.cast(UIHelper:seekWidgetByName(item,"Label_rank"),"Label") -- RLabel:setText(v.heroRank) -- local AtLabel = tolua.cast(UIHelper:seekWidgetByName(item,"Label_attack"),"Label") -- AtLabel:setText(v.attack) -- AtLabel:setVisible(false) -- local DeLabel = tolua.cast(UIHelper:seekWidgetByName(item,"Label_defense"),"Label") -- DeLabel:setText(v.defense) -- DeLabel:setVisible(false) -- local _2Label = tolua.cast(UIHelper:seekWidgetByName(item,"Label2_Ordinary"),"Label") -- _2Label:setText(v.heroLabel2) -- _2Label:setVisible(true) -- local _3Label = tolua.cast(UIHelper:seekWidgetByName(item,"Label3_Rank"),"Label") -- _3Label:setText(v.heroLabel3) -- _3Label:setVisible(false) -- local _4Label = tolua.cast(UIHelper:seekWidgetByName(item,"Label4_Ghui"),"Label") -- _4Label:setVisible(true) -- end -- end function RankingListUI:GoToMUIAndCloseMe() gUIMgr.CloseAllRankUI() -- gUIMgr.OpenMainScene( nUId ) --调到子界面 end
--ctl --排行榜控制中心 --created by gun on 2015-4-23 module(...,package.seeall) RankingListCtl = class("RankingListCtl",BaseClass) local gRankingListData = require(gUIPath.."/rankingList/rankingList_data") local gRankingListUI = require(gUIPath.."/rankingList/rankingList_ui").gRankingListUI function RankingListCtl:ctor( ... ) self.root = nil self.uiLayer = nil self.panelLayout = nil self.currentPage = nil -- self.getButtonItem = {} -- self.oUi = gRankingListUI -- self.oData = self.rankNetData = nil end gRankingListCtl = RankingListCtl:new( { tRankData = {} } ) -- { tRankData = {},}) -----第一初始化,包裹左边下面,右边UI--------- function RankingListCtl:Init( uId ) self.currentPage = uId or 1 print("Init: page = " , self.currentPage) self:InitConsRoot() gRankingListUI:Init(self.root) -- self:RefreshUI() gRankingListUI:refreshNewAS() print("11111") end ----初始化基类界面--- function RankingListCtl:InitConsRoot(...) self.root = GUIReader:shareReader():widgetFromJsonFile(gRes_CSUIPath.."/RankingList.json") --载入初始化界面 -- self:WeekWorldSeeIf() -- self:InitConstUI() self:InitConstEvent() end function RankingListCtl:InitConstUI( ... ) -- 添加按钮并注册响应事件--左 local listView = tolua.cast(UIHelper:seekWidgetByName(self.root,"ListView_left"),"ListView") local btnChild = UIHelper:seekWidgetByName(self.root,"Button_class") --添加孩子按钮 listView:setItemModel(btnChild) --设置孩子按钮为listview子按钮 btnChild:removeFromParentAndCleanup(true) --把孩子从self.root父节点移除 listView:removeAllItems() local listData = gRankingListData.gRankingListUIConfig --把data->#define的数据拿过来,按钮的 gEvent.Reg( gEventId.E_FIGHT_RANK_RESP, self, self.HandleFightRankResp ) --^^^^^^^^^^这里初始化请求数据库^C->S^^^^^^^^^^^^ local function clickCall( sender , eventType ) if TOUCH_EVENT_ENDED == eventType then gSoundMgr:Play(gSoundMgr.EFFECT_CLICK) --按钮点击声音 local nIndex = sender:getTag() --获取Tag放到nIndex print("clickCall currentPage is :" , self.currentPage) --传值的地方添加个打印 self:SetBtnEnabled( tolua.cast(listView:getItem(self.currentPage-1),"Button") , true ) self.currentPage = nIndex self:SetBtnEnabled( sender , false ) -- self:RemovePage() print("$$$$$$$$$$$$$",nIndex) gNetReq:ReqGetRank( { rankType = 1 } ) ---C->S -请求^^^^^^^^在这里按值获取用户table数据^^^^^^^^^^^^^^^^^^^^^^^^ print("2222222") end end --对#define遍历取值添加响应push按钮 for i,v in ipairs(listData) do listView:pushBackDefaultItem() --列表添加一个默认项 local item = tolua.cast(listView:getItem(listView:getItems():count()-1),"Button") item:setTitleText(v.btnName) item:setTitleColor(ccc3(55,32,9)) item:setTag(listView:getItems():count()) item:addTouchEventListener(clickCall) -- self:ShouldAddNotice(item,v.id) -- self.getButtonItem[i] = item:getTag() -- print("Yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy",self.getButtonItem[i]) end print("是否是第一个",self.currentPage) --false就默认为1 self:SetBtnEnabled( tolua.cast(listView:getItem(self.currentPage-1),"Button") , false ) --滑动条 self.initHandlerSilder = CCDirector:sharedDirector():getScheduler():scheduleScriptFunc( function ( ) CCDirector:sharedDirector():getScheduler():unscheduleScriptEntry( self.initHandlerSilder ) gUtils:SetupScrollIndicator( listView, tolua.cast( UIHelper:seekWidgetByName( self.root , "Slider_left" ) , "Slider") ) end, 0, false ) end ---确定按钮的回调,然后把自己给destroy()掉了 function RankingListCtl:InitConstEvent( ... ) local function btnReturnCall( sender , eventType ) if TOUCH_EVENT_ENDED == eventType then print("我销毁了") self:Destroy() end end tolua.cast(UIHelper:seekWidgetByName(self.root,"Button_sure"),"Button"):addTouchEventListener(btnReturnCall) end ---------------- function RankingListCtl:GetRoot( ... ) if not self.root then self:Init() end return self.root end function RankingListCtl:GetLayer( ... ) if not self.uiLayer then self.uiLayer = TouchGroup:create() self.uiLayer:addWidget(self:GetRoot()) end return self.uiLayer end function RankingListCtl:RefreshUI(info) self:WeekWorldSeeIf() print("we print the info is : ",info) -- if info == 8 then -- gRankingListUI:refreshNewGH() -- elseif info == 9 then -- gRankingListUI:refreshNewGHZ() -- elseif info == 1 or info == nil then -- gRankingListUI:refreshNewGR() -- else -- gRankingListUI:refreshNewAS() -- end gRankingListUI:refreshNewWindows() end --设置按钮的默认响应 function RankingListCtl:SetBtnEnabled( btnTarget, bIsEnabled ) btnTarget:setBrightStyle( bIsEnabled and BRIGHT_NORMAL or BRIGHT_HIGHLIGHT ) --按钮的普通状态还是高亮 btnTarget:setTouchEnabled( bIsEnabled ) end function RankingListCtl:Destroy( ) print("RankingListCtl:Destroy") if self.uiLayer then self.uiLayer:removeFromParentAndCleanup(true) self.uiLayer = nil self.root = nil gEvent.Remove( gEventId.E_FIGHT_RANK_RESP, self, self.HandleFightRankResp ) -----^^^^^^^请求结束移除^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ print("3333333") end end function RankingListCtl:HandleFightRankResp( msg ) -----new web request ----^^^^^^^^请求的事件响应数据显示刷新^^^^^^^^^^^^^^^^^^^^^ print("测试数据响应msg") -- gTable:Dump(msg.data) self.tRankData = msg.data self:RefreshUI(nIndex) --刷新右边界面 print("4444444") -- for i,v in ipairs(msg.data) do -- for j,n in ipairs(v) do -- print("see there ifnot print the i", i) -- print("see there ifnot print the v", v) -- print("exit print 189line-") -- print("i want to print the User_Name",n.User_Name) -- print("exit print 192line-") -- end -- end end ---- ---上排按钮控制---------- --- function RankingListCtl:WeekWorldSeeIf( ) local TopButtonTb = {onetouchSort = "一键排名" , jCountSort = "积分排名", checkClass = "探索队伍" , fireClass = "进攻队伍" , defenceClass = "防守队伍", jcountWar = "积分战" , rankWar = "排位战" , climeTown = "爬塔" , } ------------------------ local LayoutTop2 = self.root -- local onetouchSort = tolua.cast( UIHelper:seekWidgetByName( LayoutTop2, "Button_oTouchSort" ), "Button" ) -- onetouchSort:setTitleText(TopButtonTb.climeTown) --案例 local onetouchSort = tolua.cast( UIHelper:seekWidgetByName( LayoutTop2, "Button_oTouchSort" ), "Button" ) local jCountSort = tolua.cast(UIHelper:seekWidgetByName( LayoutTop2, "Button_jCountSort"),"Button") local checkClass = tolua.cast(UIHelper:seekWidgetByName( LayoutTop2, "Button_classResoure"), "Button") -------------------------------------------------------------------------------------- if self.currentPage == 7 or self.currentPage == 6 then --一键排名 onetouchSort:setTitleText(TopButtonTb.onetouchSort) --积分排名 jCountSort:setTitleText(TopButtonTb.jCountSort) --隐藏 onetouchSort:setVisible(true) jCountSort:setVisible(true) checkClass:setVisible(false) elseif self.currentPage == 2 then --防守队伍 onetouchSort:setTitleText(TopButtonTb.defenceClass) --进攻队伍 jCountSort:setTitleText(TopButtonTb.fireClass) --探索队伍 checkClass:setTitleText(TopButtonTb.checkClass) onetouchSort:setVisible(true) jCountSort:setVisible(true) checkClass:setVisible(true) elseif self.currentPage == 4 then --积分战 onetouchSort:setTitleText(TopButtonTb.jcountWar) --排位战 jCountSort:setTitleText(TopButtonTb.rankWar) --爬塔 checkClass:setTitleText(TopButtonTb.climeTown) onetouchSort:setVisible(true) jCountSort:setVisible(true) checkClass:setVisible(true) else --都隐藏 onetouchSort:setVisible(false) jCountSort:setVisible(false) checkClass:setVisible(false) print("#######") end --------------2015.5.4 --给按钮都来事件监听 local function clickCallFun( senderBt , eventType ) if TOUCH_EVENT_ENDED == eventType then gSoundMgr:Play(gSoundMgr.EFFECT_CLICK) --music local bindex = senderBt:getTag() print("gogogogogogo",bindex) ---------------------------------------竞技---------- if bindex == 30 and self.currentPage == 4 then print("这就对了4") gRankingListUI:refreshNewWindows() elseif bindex == 31 and self.currentPage == 4 then print("这就对了4") gRankingListUI:refreshNewAS() -- or bindex == 39891 elseif bindex == 39891 and self.currentPage == 4 then print("这就对了4") gRankingListUI:refreshNewAS() ---------------------------------------队伍---------- elseif bindex == 30 and self.currentPage == 2 then print("这就对了2") -- gRankingListUI:refreshNewAS() 选择要刷新进攻的页面 elseif bindex == 31 and self.currentPage == 2 then print("这就对了2") -- gRankingListUI:refreshNewAS() 选择要刷新防守的页面 elseif bindex == 39891 and self.currentPage == 2 then print("这就对了2") -- gRankingListUI:refreshNewAS() 选择要刷新探索的页面 ---------------------------------------周常BOSS------- elseif bindex == 30 and self.currentPage == 6 then print("这就对了6") -- gRankingListUI:refreshNewAS() 选择要刷新积分排名的页面 elseif bindex == 31 and self.currentPage == 6 then -- gRankingListUI:refreshNewAS() 选择要刷新一击排名的页面 print("这就对了6") ---------------------------------------世界BOSS------- elseif bindex == 30 and self.currentPage == 7 then print("这就对了7") -- gRankingListUI:refreshNewAS() 选择要刷新积分排名的页面 elseif bindex == 31 and self.currentPage == 7 then -- gRankingListUI:refreshNewAS() 选择要刷新一击排名的页面 print("这就对了7") else print("the end") end end end onetouchSort:addTouchEventListener(clickCallFun) jCountSort:addTouchEventListener(clickCallFun) checkClass:addTouchEventListener(clickCallFun) end
这样就可以从服务器获取数据显示了。。。。。动态喔。。其实主要是给自己看。。