--接houmee实习日记22-30<2>
--rankingList_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 =
end
gRankingListCtl = RankingListCtl:new()
-----第一初始化,包裹左边下面,右边UI---------
function RankingListCtl:Init( uId )
self.currentPage = uId or 1
print("Init: page = " , self.currentPage)
self:InitConsRoot()
gRankingListUI:Init(self.root)
self:RefreshUI()
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的数据拿过来,按钮的
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)
self:RefreshUI(nIndex) --刷新右边界面
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)
-- gTable:Dump(self.getButtonItem) --
self:WeekWorldSeeIf()
print("we print the info is : ",info)
if info == 8 then
-- gRankingListUI:refreshNewWindows()
gRankingListUI:refreshNewGH()
elseif info == 9 then
gRankingListUI:refreshNewGHZ()
elseif info == 1 or info == nil then
gRankingListUI:refreshNewGR()
else
gRankingListUI:refreshNewAS()
end
end
--设置按钮的默认响应
function RankingListCtl:SetBtnEnabled( btnTarget, bIsEnabled )
btnTarget:setBrightStyle( bIsEnabled and BRIGHT_NORMAL or BRIGHT_HIGHLIGHT ) --按钮的普通状态还是高亮
btnTarget:setTouchEnabled( bIsEnabled )
end
function gRankingListCtl:Destroy( )
print("gRankingListCtl:Destroy")
if self.uiLayer then
self.uiLayer:removeFromParentAndCleanup(true)
self.uiLayer = nil
self.root = nil
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
--逻辑层代码上完了,现在介绍一下3个文件具体的实现的详细功能,其实代码里有注释一部分,能看懂大概就知道实现什么--功能了
来看看MVC实现的思路
1Cocosstudio把简版界面弄出来 --- 2data获取生成的JSon数据与图片资源---3ui生成界面并添加响应事件-----------
4用户交互-----请求----ctl接收请求并响应处理请求-------》再发送数据给2--------->2告诉3ui来修改UI界面-----------反馈给用户
customer <------------------ customer
| |
ctl (C) ui (V)
| |
|----send---> data(M) --------- > |
RankingList_data
data// dataMgr //两个类
-迭代器 -#define(button) <-Json -基类RankinglistData - init -界面是否显示
-如果没有初始化在这里初始化 -响应函数
dataMgr
基类2 init--->geshowTable进行初始化
-如果没有这里初始化
------------------------eeeeeeeeee至于rankinglist_ui跟rankinglist_ctl自己看看吧,码字累---------------------
------至于一些常见功能调用与实现,会在houmee实习日记22-30<4>里介绍,具体的控件调用哦,其实都是在代码里面的,,整理出来方便自己看。。回顾一下
-------------另外要显示界面,需要在游戏中添加这个layer,
--ui_manager.lua
--需要下面的代码添加到相对应的场景中
function OpenAllRankUI()
local gRankingListCtl = require(gUIPath.."/rankingList/rankingList_ctl").gRankingListCtl
gUICtl:AddLayer( gRankingListCtl:GetLayer() )
end
function CloseAllRankUI()
local gRankingListCtl = require(gUIPath.."/rankingList/rankingList_ctl").gRankingListCtl
-- gUICtl:RemoveLayer(gRankingListCtl:GetLayer())
gRankingListCtl:Destroy()
end