|
- local MJDefine=MJFramework.MJImport("mj.luaScript.MJDefine")
- local CommonGroupChi = class("CommonGroupChi", function ()
- local node = cc.Node:create()
- return node
- end)
-
- function CommonGroupChi:ctor(values, viewId, groupIndex)
-
- self._values = values
- self._viewId = viewId
- self._cardNodes = {}
- self._groupIndex = groupIndex or 1
-
- self:initViews()
- end
-
- function CommonGroupChi:initViews()
-
- if not self._values then
- return
- end
-
- for index, value in ipairs(self._values) do
- local card = self:createCard(value, self._viewId, index, self._groupIndex)
- local x, y = self:getCardPosition(card, index)
- self:addChild(card)
- table.insert(self._cardNodes, card)
-
- end
-
- self:refreshZOrder()
-
- end
-
- function CommonGroupChi:getViewId()
- return self._viewId
- end
-
- function CommonGroupChi:createCard(value, viewId, index, groupIndex)
- local CardClass = require(MJDefine.MJConfig_2d.MAHJONG_CARD)
- local tmpIndex = (index >= 4) and 2 or index
- local mjIndex = (groupIndex - 1) * 3 + tmpIndex
- local mjCard = CardClass:new(value, viewId, MJDefine.MJConfig_2d.MJType.Operate, mjIndex)
- local x, y = self:getCardPosition(mjCard, index)
- mjCard:setPosition(x, y)
- return mjCard
- end
-
- function CommonGroupChi:getCardPosition(mjCard, mjIndex)
- local x = 0
- local y = 0
- local viewId = self:getViewId()
- local cardSize = mjCard:getContentSize()
- local groupOffset = self:getGroupOffsetConfig(viewId)
- local offset = groupOffset[mjIndex]
- if viewId == MJDefine.PlayerViewType.My then
- x = (mjIndex - 1) * (cardSize.width + offset.x)
- y = offset.y
- elseif viewId == MJDefine.PlayerViewType.Right then
- x = offset.x
- y = (mjIndex - 1) * (cardSize.height + offset.y)
- elseif viewId == MJDefine.PlayerViewType.Top then
- x = (1 - mjIndex) * (cardSize.width + offset.x)
- y = offset.y
- elseif viewId == MJDefine.PlayerViewType.Left then
- x = offset.x
- y = (1 - mjIndex) * (cardSize.height + offset.y)
- end
-
- return x, y
- end
-
- -- function CommonGroupChi:updateGroupSize(cardSize)
- -- local groupWidth = 0
- -- local groupHeight = 0
- -- local width = cardSize.width
- -- local height = cardSize.height
- -- local viewId = self:getViewId()
- -- local offset = MJDefine.MJConfig_2d.GroupOffsetConfig[viewId]
- -- if viewId == MJDefine.PlayerViewType.My then
- -- width = cardSize.width * 3 + offset.x * 2
- -- height = cardSize.height
- -- elseif viewId == MJDefine.PlayerViewType.Right then
- -- width = cardSize.width
- -- height = cardSize.height * 3 + offset.y * 2
- -- elseif viewId == MJDefine.PlayerViewType.Top then
- -- width = cardSize.width * 3 + offset.x * 2
- -- height = cardSize.heights
- -- elseif viewId == MJDefine.PlayerViewType.Left then
- -- width = cardSize.width
- -- height = cardSize.height * 3 + offset.y * 2
- -- end
-
- -- self:setContentSize(groupWidth, groupHeight)
- -- end
-
- function CommonGroupChi:refreshZOrder()
- local count = table.nums(self._cardNodes) or 3
- for k, v in ipairs(self._cardNodes) do
- local zorder = 0
- if self._viewId == 1 then
- zorder = (k < 4) and (count - k) or 4
- end
- v:setLocalZOrder(zorder)
- end
- end
-
- function CommonGroupChi:customRefresh(groupData)
-
- end
-
- function CommonGroupChi:getCards()
- return self._cardNodes or {}
- end
-
- function CommonGroupChi:getValues()
- return self._values or {}
- end
-
- function CommonGroupChi:getGroupIndex()
- return self._groupIndex
- end
- ---
- -- 获取组合牌偏移配置
- -- @param viewId
- -- @return
- --
- function CommonGroupChi:getGroupOffsetConfig(viewId)
- return MJDefine.MJConfig_2d.GroupCardOffsetConfig[viewId]
- end
-
- return CommonGroupChi
|