|
- local Abbreviation = {}
-
- function Abbreviation.addBackLayer(__node, __num)
- local num = __num or 200
- local bBack = cc.LayerColor:create(cc.c4b(0, 0, 0, num))
- __node:addChild(bBack, -1)
- bBack:setPosition(cc.p(0, 0))
- return bBack
- end
- --创建按钮
- function Abbreviation.createMenu(__node, __z_order, __tag, __pos, __anchorpoint)
- local menu = cc.Menu:create()
- __node:addChild(menu)
- menu:setLocalZOrder(__z_order or 0)
- menu:setTag(__tag or 0)
- menu:setPosition(__pos or cc.p(0,0))
- menu:setAnchorPoint(__anchorpoint or cc.p(0.5,0.5))
- return menu
- end
- --菜单栏
- function Abbreviation.createItemWithFile(__file, __node, __pos, __callBack, __change)
- assert(type(__callBack)=="function", "Abbreviation.createItemWithFile error, must have a callback")
- local sp = display.newSprite(__file)
- local sp_hover = display.newSprite(__file)
- sp_hover:setColor(cc.c3b(100, 100, 100))
- local sp_dis = display.newSprite(__file)
- sp_dis:setColor(cc.c3b(100, 100, 100))
-
- local item = cc.MenuItemSprite:create(sp, sp_hover, sp_dis)
- :onClicked(__callBack)
- __node:addChild(item)
- item:setPosition(__pos)
- return item
- end
-
- --菜单栏
- function Abbreviation.createItemAll(__files, __node, __pos, __callBack, __change)
- assert(type(__callBack)=="function", "Abbreviation.createItemAll error, must have a callback")
- local sp = display.newSprite(__files[1])
- local sp_hover = display.newSprite(__files[1])
- sp_hover:setColor(cc.c3b(100, 100, 100))
- local sp_dis = display.newSprite(__files[2])
-
- local item = cc.MenuItemSprite:create(sp, sp_hover, sp_dis)
- :onClicked(__callBack)
- __node:addChild(item)
- item:setPosition(__pos)
- return item
- end
-
- --菜单栏
- function Abbreviation.createItemFont(__node, __pos ,__str, __fontsize, __color, __disCol, __bold, __callBack)
- assert(type(__callBack)=="function", "Abbreviation.createItemLabel error, must have a callback")
- local item = cc.MenuItemFont:create(__str)
- :onClicked(__callBack)
- __node:addChild(item)
- item:setPosition(__pos)
- item:setFontSizeObj(__fontsize)
- item:setColor(__color)
- item:setDisabledColor(__disCol)
- local sysFont = Abbreviation.getSystemFont()
- if __bold then
- sysFont = Abbreviation.getBoldFont()
- end
- item:setFontNameObj(sysFont)
- return item
- end
-
- --
- function Abbreviation.createLabel(__node, __pos, __str, __fontsize, __color,__shadow)
- local label = cc.Label:createWithTTF(__str, "fonts/huakangziti.TTF", __fontsize)
- :align(display.CENTER, __pos)
- :addTo(__node)
- label:setColor(__color or display.COLOR_WHITE)
- if (__shadow) then
- label:enableShadow()
- end
- return label
- end
-
- --获取平台字体
- function Abbreviation.getSystemFont()
- return "res/default/msyh.ttc"
- end
-
- --获取平台加粗字体
- function Abbreviation.getBoldFont()
- return "res/default/msyh.ttc"
- end
-
- --更改显示系统字体的lable(创建新lable,并隐藏旧lable)
- function Abbreviation.changeSystemLabel(__oldLabel, __outLineColor)
- local label = cc.Label:createWithSystemFont(__oldLabel:getString(), Abbreviation.getSystemFont(), __oldLabel:getFontSize())
- __oldLabel:getParent():addChild(label, __oldLabel:getLocalZOrder())
- label:setAnchorPoint(__oldLabel:getAnchorPoint())
- label:setPosition(__oldLabel:getPositionX(), __oldLabel:getPositionY())
- label:setTextColor(__oldLabel:getTextColor())
- __oldLabel:setVisible(false)
- if (__outLineColor) then
- label:enableOutline(__outLineColor, 1)
- end
- return label
- end
-
- --改变lable大小,返回新lable,隐藏旧lable
- function Abbreviation.changeSystemLabelRect(__oldLabel, __size, __hAlignment, __outLineColor, __vAlignment)
- local hAlignment = __hAlignment or cc.TEXT_ALIGNMENT_CENTER --cc.TEXT_ALIGNMENT_LEFT==0 cc.TEXT_ALIGNMENT_CENTER==1
- local vAlignment = __vAlignment or cc.VERTICAL_TEXT_ALIGNMENT_CENTER --居中对齐
- local size = __size
-
- local label = cc.Label:createWithSystemFont(__oldLabel:getString(), Abbreviation.getSystemFont(), __oldLabel:getFontSize(), size, hAlignment, vAlignment)
- label:setLineBreakWithoutSpace(true)
- __oldLabel:getParent():addChild(label, __oldLabel:getLocalZOrder())
- label:setAnchorPoint(__oldLabel:getAnchorPoint())
- label:setPosition(__oldLabel:getPositionX(), __oldLabel:getPositionY())
- label:setTextColor(__oldLabel:getTextColor())
- __oldLabel:setVisible(false)
- return label
- end
-
- --以系统字体创建lable,并开启阴影
- function Abbreviation.createSystemLabel(__node, __pos, __str, __fontsize, __color, __bold, __hAlignment, __shadow)
- local sysFont = Abbreviation.getSystemFont()
- if __bold then
- sysFont = Abbreviation.getBoldFont()
- end
- __hAlignment = __hAlignment or display.CENTER
- -- local label = cc.Label:createWithSystemFont(__str, sysFont, __fontsize)
- local label = cc.Label:create(__str, "res/default/msyh.ttc", __fontsize)
- :align(__hAlignment, __pos)
- :addTo(__node)
- label:setColor(__color or display.COLOR_WHITE)
- if (__shadow) then
- label:enableShadow()
- end
- return label
- end
-
- --创建精灵
- function Abbreviation.createSprite(__file, __node, __pos, __scale9, __z_order, __tag, __anchorpoint)
- local x = __pos and __pos.x or 0
- local y = __pos and __pos.y or 0
- local params = {
- scale9 = __scale9,
- capInsets = cc.rect(24, 24, 3, 3)
- }
- if not __scale9 then
- params = nil
- end
- local sp = display.newSprite(__file, x, y, params)
- dump(__node, "Abbreviation.createSprite = __node")
- print("Abbreviation.createSprite = sp = ", sp)
- __node:addChild(sp)
- sp:setLocalZOrder(__z_order or 0)
- sp:setTag(__tag or 0)
- sp:setAnchorPoint(__anchorpoint or cc.p(0.5,0.5))
- return sp
- end
-
- --创建精灵
- function Abbreviation.createImageView(__file, __node, __pos, __scale9, __z_order, __tag, __anchorpoint)
- local x = __pos and __pos.x or 0
- local y = __pos and __pos.y or 0
-
- local sp = ccui.ImageView:create(__file)
- if __scale9 then
- sp:setScale9Enabled(true)
- sp:setCapInsets(cc.rect(23, 23, 4, 4))
- end
- sp:setPosition(cc.p(x, y))
- __node:addChild(sp)
- sp:setLocalZOrder(__z_order or 0)
- sp:setTag(__tag or 0)
- sp:setAnchorPoint(__anchorpoint or cc.p(0.5,0.5))
- return sp
- end
-
- --创建定宽label
- function Abbreviation.createFixWLabel(__node, __pos, __str, __fontsize, __color, __width)
- local label = cc.Text:createNode();
- label:setDefaults();
- local config = label:getFontConfig();
- config.fontSize = __fontsize or 20;
- label:setFontConfig(config);
- label:setColor(__color)
- label:setTextAreaSize(cc.size(__width, 0))
- label:setLinePadding(2)
- label:setAnchorPoint(cc.p(0.5, 0.5))
- label:setPosition(__pos)
- label:setText(__str or "")
- __node:addChild(label)
- return label
- end
- return Abbreviation--Abbreviation_lua--Abbreviation.lua
|