给白日门弄一个复古的公告界面,有点折腾图层的顺序

给白日门弄一个复古的公告界面,有点折腾图层的顺序,过程总是很苦恼啊,但是结果是完美的。

bdf7827b25235546

这里我用到了好几个有意思的功能,之前我是不了解的。这里我直接上代码吧,因为代码里有些猫腻。

LUA_RET = {
	{
		n = "SceneNotice",
		parent = 0,
		v = true,
		type = 0,
		id = 1,
		w = 1136,
		h = 640
	},
	{
		tag = 15,
		sy = 15,
		h = 520,
		type = 1,
		w = 839,
		color = "255|255|255",
		sx = 15,
		n = "Image_Bg",
		ay = 0.5,
		sw = 15,
		ax = 0.5,
		parent = 1,
		v = true,
		y = 320,
		id = 2,
		sh = 15,
		x = 568
	},
	{
		id = 6,
		sy = 24,
		h = 76,
		type = 0,
		w = 240,
		tag = 231,
		c = false,
		res = "",--选中的?
		sx = 77,
		n = "box_render",
		sw = 77,
		t = true,
		parent = 5,
		v = true,
		y = 444,
		color = "255|255|255",
		sh = 24
	},
	{
		tag = 511,
		sy = 19,
		h = 74,
		type = 1,
		w = 236,
		color = "255|255|255",
		res = "55",
		sx = 49,
		n = "img_selected",
		ay = 0.5,
		sw = 49,
		ax = 0.5,
		parent = 6,
		v = true,
		y = 45.6536,
		id = 7,
		sh = 19,
		x = 135.0641
	},
	{
		tag = 75,
		sy = 15,
		h = 46,
		type = 1,
		w = 45,
		color = "255|255|255",
		res = "img_type1",
		sx = 14,
		n = "img_type",
		ay = 0.5,
		sw = 14,
		ax = 0.5,
		parent = 6,
		v = true,
		y = 1145.6531,
		id = 8,
		sh = 15,
		x = 29.2132
	},
	{
		id = 9,
		n = "txt_type",
		h = 16,
		type = 3,
		w = 40,
		ht = 1,
		text = "公告",
		tag = 508,
		ay = 0.5,
		fs = 15,
		ax = 0.5,
		fr = "DFYuan.ttf",
		parent = 6,
		v = true,
		y = 1154.0919,
		color = "255|165|0",
		x = 21.0851
	},
	{
		tag = 514,
		color = "255|255|0",
		h = 30,
		type = 3,
		w = 150,
		ht = 1,
		text = "开服公告",
		n = "title",
		ay = 0.5,
		fs = 22,
		ax = 0.5,
		fr = "DFYuan.ttf",
		parent = 6,
		v = true,
		y = 33.1236,
		id = 10,
		x = 73.4685,
		vt = 1
	},
	{
		tag = 15,
		sy = 15,
		h = 35,
		type = 1,
		w = 260,
		color = "255|255|255",
		sx = 15,
		n = "Image_Bg44",--顶部标题。
		ay = 0.5,
		sw = 15,
		ax = 0.5,
		parent = 1,
		v = true,
		y = 554.4753,
		id = 413,
		sh = 15,
		x = 497.6451,
	},
	{
		tag = 15,
		sy = 15,
		h = 609,
		type = 1,
		w = 800,
		color = "255|255|255",
		sx = 15,
		n = "Image_Bg5",
		res = "",--整体背景图
		ay = 0.5,
		sw = 15,
		ax = 0.5,
		parent = 1,
		v = true,
		y = 320,
		id = 16,
		sh = 15,
		x = 538
	},
	{
		tag = 16,
		sy = 15,
		h = 609,
		type = 3,
		w = 800,
		color = "255|255|255",
		sx = 15,
		n = "Image_Bg3",--开服公告这个背景图	
		ay = 0.5,
		sw = 15,
		ax = 0.5,
		parent = 1,
		v = true,
		y = 403,
		id = 414,
		sh = 15,
		x = 668
	},
	{
		tag = 16,
		sy = 15,
		h = 609,
		type = 3,
		w = 800,
		color = "255|255|255",
		sx = 15,
		n = "Image_Bg6",--开服公告 -- 内容 这个背景图	
		ay = 0.5,
		sw = 15,
		ax = 0.5,
		parent = 1,
		v = true,
		y = 403,
		id = 415,
		sh = 15,
		x = 668
	},
	
	
	
	
	
	
	
	
	
	
	
	{
		type = 1,
		n = "box_annc",
		h = 552,
		sy = 15,
		w = 1015,
		color = "255|255|255",
		res = "notice",
		ud = "nocache",
		sx = 15,
		tag = 513,
		ay = 0.5,
		sw = 15,
		ax = 0.5,
		parent = 1,
		v = true,
		y = 320,
		id = 300,
		sh = 15,
		x = 568
	},
	{
		tag = 232,
		color = "255|165|0",
		h = 35,
		type = 3,
		w = 260,
		ht = 1,
		text = "重要提示",
		n = "annc_Title",
		ay = 0.5,
		fs = 32,
		ax = 0.5,
		fr = "DFYuan.ttf",
		parent = 300,
		v = true,
		y = 1504.4753,
		id = 4,
		x = 617.6451,
		vt = 1
	},
	{
		n = "scroll_annc",
		d = 1,
		h = 420,
		type = 8,
		w = 700,
		parent = 300,
		tag = 78,
		color = "255|255|255",
		c = false,
		v = true,
		y = 455.8589,
		id = 12,
		ay = 1,
		x = 290.3415,
		t = true
	},
	{
		n = "list_type",
		d = 1,
		h = 520,
		type = 9,
		w = 240,
		parent = 300,
		tag = 70,
		color = "255|255|255",
		c = false,
		v = true,
		y = 496.6744,
		id = 5,
		ay = 1,
		x = 116.895,
		t = true
	},
	{
		type = 2,
		n = "btn_enter",
		h = 30,
		sy = 9,
		w = 31,
		color = "255|255|255",
		res = "btn_guanbi3",
		ud = "0x000000",
		sx = 10,
		tag = 77,
		ay = 0.5,
		sw = 10,
		t = true,
		fs = 20,
		ax = 0.5,
		tcolor = "255|224|139",
		parent = 300,
		v = true,
		y = 551.3363,
		id = 211,
		sh = 9,
		x = 948.7302
	},
}

上面是UI层。

--self.box_annc:loadTexture("zhuxijing_noti_7", ccui.TextureResType.plistType)
		local txtTypeStr = {
	"活动",
	"开服",
	"促销",
	"提示",
	"警告",
	"攻略",
	"通知"
}

SceneNotice = class("SceneNotice", function()
    return display.newScene("SceneNotice")
end)

function SceneNotice:ctor()
	self.xmlPanel=nil
	self.box_annc=nil
	self.btn_Enter=nil
	self.anncList=nil
	self.list_type=nil
	self.updateComplete=false
	self.anncTitle = nil
end

function SceneNotice:onEnter()
	self.xmlPanel = UILuaLoader.load("uilayout/SceneNotice.uif")

	if self.xmlPanel then
		self.box_annc = self.xmlPanel:getChildByName("box_annc")

		self.box_annc:setPosition(cc.p(display.cx, display.cy))

		self.btn_enter = self.box_annc:getChildByName("btn_enter")
		
		local imgBg = self.xmlPanel:getChildByName("Image_Bg"):align(display.CENTER, display.cx, display.cy)
		asyncload_callback("needload/img_battle.png", self.xmlPanel:getChildByName("Image_Bg"):align(display.CENTER, display.cx, display.cy), function (filepath, texture)
			if utilapp.isObjectExist(imgBg) then
				imgBg:loadTexture(filepath):scale(cc.MAX_SCALE)
			end
		end)
		--util.asyncload(self.xmlPanel, "box_annc", "needload/img_notice.png")

		--local anim = ccui.ImageView:create("com_bg_kuang_5",ccui.TextureResType.plistType)
			--:setContentSize(cc.size(800,609))
			--:addTo(imgBg)
			--:align(display.CENTER, display.cx + 0, display.cy-0)
			--:setScale(0.9)	图片缩放
		
			--:setContentSize(cc.size(150,479))
			--:setOpacity(100)
			
		local Image_Bg5 = self.xmlPanel:getChildByName("Image_Bg5"):align(display.CENTER, display.cx, display.cy)
		:loadTexture("com_bg_kuang_5",ccui.TextureResType.plistType):scale(display.height/640)
		
		--标题 顶部
		local annc_Title2 = self.xmlPanel:getChildByName("Image_Bg44")
		local anim23 = ccui.ImageView:create("gonggao",ccui.TextureResType.plistType)
			:setContentSize(cc.size(12,22))
			:addTo(annc_Title2)
			:align(display.CENTER, display.cx + 400, display.cy-500)
			:setPosition(cc.p(186,50))
			
		self.btn_enter:addClickEventListener(function (sender)
			print("进入游戏")
			self:doLogin()
		end)

		self.anncTitle = self.box_annc:getWidgetByName("annc_Title")

		self:addChild(self.xmlPanel)
			
			
		self.updateComplete = true

		self.box_annc:setVisible(false)
		self:showAnnc()

		--开服公告这个背景图	
		local Image_Bg3 = self.xmlPanel:getChildByName("Image_Bg3"):align(display.CENTER, display.cx, display.cy)
		local anim2 = ccui.ImageView:create("com_bg_kuang_6",ccui.TextureResType.plistType)
			:setContentSize(cc.size(150,479))
			:addTo(Image_Bg3)
			:align(display.CENTER, display.cx -250, display.cy+500)
			
			:setScale9Enabled(true)
			:setAnchorPoint(cc.p(0,0))
			:setCapInsets(cc.rect(15,35,80,5))
			:setPosition(cc.p(6,50))

		--开服公告详细内容 这个背景图	
		local Image_Bg6 = self.xmlPanel:getChildByName("Image_Bg6"):align(display.CENTER, display.cx, display.cy)
		local anim2 = ccui.ImageView:create("com_bg_kuang_6",ccui.TextureResType.plistType)
			:setContentSize(cc.size(520,479))
			:addTo(Image_Bg6)
			:align(display.CENTER, display.cx -250, display.cy+500)
			
			:setScale9Enabled(true)
			:setAnchorPoint(cc.p(0,0))
			:setCapInsets(cc.rect(15,35,80,5))
			:setPosition(cc.p(256,50))
	end
end

function SceneNotice:openDoor(ui)
	local startNum = 1
	local doorNum = 7
	local img_left = ui:getWidgetByName("img_leftdoor")
	local img_right = ui:getWidgetByName("img_rightdoor")

	img_right:setFlippedX(true)
	img_left:setPositionX(display.cx)
	img_right:setPositionX(display.cx)

	local function startOpen()
		asyncload_callback("needload/OpenDoor/img_door"..startNum..".jpg", img_left, function (filepath, texture)
			if util.isObjectExist(img_left) then
				img_left:loadTexture(filepath):scale(display.height/640)
			end
			if util.isObjectExist(img_right) then
				img_right:loadTexture(filepath):scale(display.height/640)
			end
		end)
		startNum = startNum + 1
		if startNum >= 8 then
			img_left:runAction(cca.fadeOut(0.5))
			img_right:runAction(cca.fadeOut(0.5))
			self:showAnnc()
		end
	end
	
	ui:runAction(cca.rep(cca.seq({cca.delay(0.25),cca.cb(startOpen)}),tonumber(7)))
end

function SceneNotice:showAnnc(  )
	self.box_annc:setVisible(true)
	self:getAnncInfo()
end

function SceneNotice:onExit()
	cc.SpriteManager:getInstance():removeFramesByFile("uipic/SceneNotice")
	cc.CacheManager:getInstance():releaseUnused(false)
end

function SceneNotice:doLogin(args)
	if self.updateComplete then
		self.updateComplete = false

		asyncload_frames("uipic/SceneSelectServer", ".png", function ()
			if game.gameKey and game.gameKey ~= "" then
				display.replaceScene(SceneSelectServer.new())
			else
				display.replaceScene(SceneLogin.new())
			end
		end)
	end
end

function SceneNotice:getAnncInfo()
	self.anncList = self.box_annc:getChildByName("list_type")
	self.anncList:setTouchEnabled(true)
	self.anncList:setBounceEnabled(true)
	
			
	local scroll_ptinfo=self.box_annc:getChildByName("scroll_annc")
	local fileUtils = cc.FileUtils:getInstance()

	local path=fileUtils:getWritablePath().."annc.json"
	if fileUtils:isFileExist(path) then
		local anncStr=fileUtils:getStringFromFile(path)
		anncStr=string.gsub(anncStr,"\\","")
		local anncTab1=string.split(anncStr,"###")
		game.annc={}
		for k,v in pairs(anncTab1) do
			local anncTab2=string.split(v,"|||")
			if anncTab2 and #anncTab2>1 then
				local annc={}
				annc["title"] = anncTab2[1]
				--annc["type1"] = tonumber(anncTab2[2])  -- 左上角类型[活动,公告,促销]
				annc["type2"] = 2  			 -- 右上角类型[hot,new]
				annc["content"]=anncTab2[2]
				table.insert(game.annc, annc)
			end
		end
		if not self.list_type then
			local params={
				list=self.anncList,
				layout={repeatY=#anncTab1,repeatX=1,spaceX=0,spaceY=9},
				updateItemfunc=function(item)
					local index=item.index
					-- 标题
					local title = item:getChildByName("title");
					title:setString(item.data.title)

					-- 角标
					local imgType = item:getChildByName("img_type")
					imgType:loadTexture("img_type"..item.data.type1, ccui.TextureResType.plistType)
					
					-- 类型
					local txtType = item:getChildByName("txt_type")
					if txtType then
						print(222)
						txtType:setString(txtTypeStr[item.data.type1]) --setRotation(-45):
						:runAction(cca.rotateBy(0,-45))
					else
						print(txtTypeStr[item.data.type1])
						txtType = ccui.Text:create(txtTypeStr[item.data.type1], FONT_NAME, 16)
						:setTextColor(game.getColor(0xFF3E3E))
						:addTo(item)
						:runAction(cca.rotateBy(0,-45))
						--:addTo(var.layerGuide, 5)
					end
				end,
				selectItemfunc=function(item)
					local child=scroll_ptinfo:getChildByName("rich_annc")
					if child then
						scroll_ptinfo:removeChild(child)
					end
          			local rich_label = utilapp.newRichLabel(cc.size(550,0),5)
					rich_label:setName("rich_annc")
					rich_label:setAnchorPoint(cc.p(0.5, 1))
					scroll_ptinfo:addChild(rich_label)
					local anncMsg=item.data["content"]
					self.anncTitle:setString(item.data.title)
					utilapp.setRichLabel(rich_label,anncMsg, "", 22, "0x4d4d4d")
					scroll_ptinfo:setInnerContainerSize(cc.size(550,rich_label:getRealHeight()))

					local realHeight = rich_label:getRealHeight() < 410 and 410 or rich_label:getRealHeight()
					rich_label:setPosition(cc.p(scroll_ptinfo:getContentSize().width/2, realHeight))
					rich_label:setVisible(true)
				end,
				data=game.annc
			}
			self.list_type=UIList.new(params)
			self.list_type:setSelectedIndex(1)
			self.anncList:show()
		end
	end
	self.box_annc:show()
end

return SceneNotice

这里是功能层。

 

请登录后发表评论

    没有回复内容