|
- local MJSound = MJFramework.MJImport("mj.luaScript.MJSound")
- local CommonOutCardView = MJFramework.MJFrameworkClassImprot("mj.luaScript.Common.2d.CommonOutCardView")
-
- local MJDefine=MJFramework.MJImport("mj.luaScript.MJDefine")
- local OutCardView2D = class("OutCardView2D", CommonOutCardView)
-
- function OutCardView2D:ctor(...)
- OutCardView2D.super.ctor(self, ...)
- end
-
- function OutCardView2D:getOutCardPosition(mjCard, mjIndex)
- local x = 0
- local y = 0
- local viewId = self:getViewId()
- local playerCount = app.room:getMaxPlayerCount()
- local mjRowCount = MJDefine.MJConfig_2d.OutCardRowCount[playerCount][viewId]
- local col = mjIndex % mjRowCount
- col = col == 0 and mjRowCount or col
- local row = math.ceil(mjIndex / mjRowCount)
-
- local startPos = MJDefine.MJConfig_2d.OutCardStartPos[viewId]
- local offset = MJDefine.MJConfig_2d.OutCardOffsetConfig[viewId]
- local cardSize = mjCard:getContentSize()
-
- if playerCount == 2 then
- startPos = MJDefine.MJConfig_2d.OutCardStartPos2[viewId]
- offset = MJDefine.MJConfig_2d.OutCardOffsetConfig2[viewId]
- end
-
- if viewId == MJDefine.PlayerViewType.My then
- x = startPos.x + (col - 1) * (cardSize.width + offset.x)
- --y = startPos.y + (1 - row) * (cardSize.height + offset.y)
- y = startPos.y + (row - 1) * (cardSize.height + offset.y)
- elseif viewId == MJDefine.PlayerViewType.Right then
- --x = startPos.x + (row - 1) * (cardSize.width + offset.x)
- x = startPos.x + (1 - row) * (cardSize.width + offset.x)
- y = startPos.y + (col - 1) * (cardSize.height + offset.y)
- elseif viewId == MJDefine.PlayerViewType.Top then
- x = startPos.x + (1 - col) * (cardSize.width + offset.x)
- --y = startPos.y + (row - 1) * (cardSize.height + offset.y)
- y = startPos.y + (1 - row) * (cardSize.height + offset.y)
- elseif viewId == MJDefine.PlayerViewType.Left then
- --x = startPos.x + (1 - row) * (cardSize.width + offset.x)
- x = startPos.x + (row - 1) * (cardSize.width + offset.x)
- y = startPos.y + (1 - col) * (cardSize.height + offset.y)
- end
-
- return x, y
- end
-
- function OutCardView2D:refreshZOrder()
- local viewId = self:getViewId()
- if viewId == MJDefine.PlayerViewType.My or viewId == MJDefine.PlayerViewType.Right then
- local count = table.nums(self._outCardNodes)
- for k, v in ipairs(self._outCardNodes or {}) do
- v:setLocalZOrder(count - k)
- end
- else
-
- end
- end
-
- function OutCardView2D:onOutCard(card, callback)
- MJSound.PlayOutCard()
- self:addCard(card)
- self:refreshZOrder()
- if callback then
- callback()
- end
- self:runOutCardAction(card)
- end
-
- --³öÅÆ¶¯»
- function OutCardView2D:runOutCardAction(value,callback)
- local outCard=self._outCardNodes[#self._outCardNodes]
- local linshui_mj_color = loadUserInfo("mj_linshui_desktop_2d_mjType") or MJDefine.DesktopType.TwoDL
- local CardClass
- if linshui_mj_color == "2dl" then
- CardClass = require("mj_linshui.luaScript.Views.2d.Card_2d_L")
- else
- CardClass = require(MJDefine.MJConfig_2d.MAHJONG_CARD)
- end
-
- local showCard = CardClass:new(value, 4, MJDefine.MJConfig_2d.MJType.Stand, 1)
- --local showCard=MJ:new(value,MJDefine.MJType.Stand,MJDefine.MyViewId,self.desktopType)
- self:addChild(showCard)
- showCard:setLocalZOrder(9999)
-
- --showCard:setScale(MJDefine.MJ_OUT_CARD_SCALE)
- showCardPostion = {
- [1] = {x = 1015*g_radio_x, y = 423*g_radio_y},
- [2] = {x = 641*g_radio_x, y = 571*g_radio_y},
- [3] = {x = 265*g_radio_x, y = 423*g_radio_y},
- [4] = {x = 640*g_radio_x, y = 210*g_radio_y},
- }
- showCard:setPosition(showCardPostion[self._viewId])
- local rotate=0
- if self._viewId==MJDefine.PlayerViewType.Left then
- rotate=-45
- elseif self._viewId==MJDefine.PlayerViewType.Right then
- rotate=45
- end
- local actions={
- --cc.ScaleTo:create(MJDefine.MJ_TIME_OUT_CARD_SCALE,1),
- cc.DelayTime:create(MJDefine.MJ_TIME_OUT_CARD_WAIT),
- --[[cc.Spawn:create(
- cc.Spawn:create(
- cc.MoveTo:create(MJDefine.MJ_TIME_OUT_CARD,outCard:getPosition()),
- cc.ScaleTo:create(MJDefine.MJ_TIME_OUT_CARD,MJDefine.MJ_OUT_CARD_SCALE)
- ),
- cc.RotateBy:create(MJDefine.MJ_TIME_OUT_CARD,rotate)
- ),--]]
- cc.CallFunc:create(function()
- -- MJSound.PlayOutCard()
- if outCard and not tolua.isnull(outCard) then
- --outCard:setVisible(true)
- end
- showCard:setVisible(false)
- if callback then callback() end
- end),
- cc.RemoveSelf:create(),
-
- }
- showCard:runAction(cc.Sequence:create(actions))
- end
-
- function OutCardView2D:onSelectCard(event)
- if not event then
- return
- end
- local value = event.value;
- for k, v in ipairs(self._outCardNodes or {}) do
- if (not value) or value <= 0 then
- v:setNormalColor()
- else
- if v:getValue() == value then
- v:setColor(cc.c3b(243, 147, 9))
- else
- v:setNormalColor()
- end
- end
- end
- end
-
- return OutCardView2D
|