diff --git a/lua_probject/base_project/Game/Controller/LoginController.lua b/lua_probject/base_project/Game/Controller/LoginController.lua index 4ebb24cb..e675d631 100644 --- a/lua_probject/base_project/Game/Controller/LoginController.lua +++ b/lua_probject/base_project/Game/Controller/LoginController.lua @@ -16,7 +16,7 @@ end local _LocalConfigAllGame={ 10,13,14,15,22,33,65,66,67,77,88, -101,102,103,104,105,106,107,108, +101,102,103,104,105,106,107,108,16, 301,201,202,203 } diff --git a/lua_probject/extend_project/extend/majiang/ningxiang/CS_GameEvent.lua b/lua_probject/extend_project/extend/majiang/ningxiang/CS_GameEvent.lua new file mode 100644 index 00000000..5ec65988 --- /dev/null +++ b/lua_probject/extend_project/extend/majiang/ningxiang/CS_GameEvent.lua @@ -0,0 +1,44 @@ + +local CS_GameEvent = { + -- 发牌 + SendCards = "SendCards", + + EventTurn = "EventTurn", + + OutHint = "OutHint", + + GetCard = "GetCard", + + OutCard = "OutCard", + + FangziAction = "FangziAction", + + FZTips = "FZTips", + -- 胡牌 + ZPHuCard = "ZPHuCard", + -- 结算事件 + ZPResult1 = "ZPResult1", + -- 大结算事件 + ZPResult2 = "ZPResult2", + + EventNiao = "EventNiao", + + EventQSTip = "EventQSTip", + + EvnetQSAction = "EvnetQSAction", + + EventKaiGang = "EventKaiGang", + + EvnetHaiDi = "EvnetHaiDi", + + EvnetPiaoTip = "EvnetPiaoTip", + + EvnetPiao = "EvnetPiao", + + EventTingTip = "EventTingTip", + + EventTing = "EventTing", + + EventXiPai="EventXiPai", +} +return CS_GameEvent \ No newline at end of file diff --git a/lua_probject/extend_project/extend/majiang/ningxiang/CS_Win_Type.lua b/lua_probject/extend_project/extend/majiang/ningxiang/CS_Win_Type.lua new file mode 100644 index 00000000..881b637f --- /dev/null +++ b/lua_probject/extend_project/extend/majiang/ningxiang/CS_Win_Type.lua @@ -0,0 +1,18 @@ +local CS_Win_Type = { + "小七对", + "将将胡", + "清一色", + "碰碰胡", + "杠上花", + "杠上炮", + "全求人", + "海底捞月", + "海底炮", + "抢杠胡", + "小胡", + "天胡", + "天听胡", + "门清", +} +return CS_Win_Type + diff --git a/lua_probject/extend_project/extend/majiang/ningxiang/CardCheck.lua b/lua_probject/extend_project/extend/majiang/ningxiang/CardCheck.lua new file mode 100644 index 00000000..422b4b57 --- /dev/null +++ b/lua_probject/extend_project/extend/majiang/ningxiang/CardCheck.lua @@ -0,0 +1,295 @@ +-- 检测牌是否存在 +local function checkCard(eventCard,cardList,num) + num = num == nil and 1 or num + local result = 0 + for i = 1,#cardList do + if (cardList[i] == eventCard) then + result = result + 1 + if(result ==num) then + return true + end + end + end + return false +end + +-- 移除指定数量的牌 +local function removeCard(cardList, card,count) + for i=1,count do + list_remove(cardList,card) + end +end + +local function checkCardAndRomve(eventCard,cardList,num) + if(checkCard(eventCard,cardList,num)) then + removeCard(cardList,eventCard,num) + return true + end + return false +end + +-- 获取列表中牌数量 +local function cardNum(eventCard,cardList) + local result = 0 + for i=1,#cardList do + local card = cardList[i] + if (card == eventCard) then + result = result + 1 + end + end + return result +end + +local zhongid = 412 + + +local M = { + pair_count = 0, + cardList = nil, + stack = nil, + jiang = true +} + + +function M:push(cardGroup) + self.stack[#self.stack+1] = cardGroup +end + +function M:rollBack() + local cardGroup = self.stack[#self.stack] + table.remove(self.stack,#self.stack) + for _,card in ipairs(cardGroup) do + self.cardList[#self.cardList + 1] = card + end + table.sort(self.cardList) +end + +function M:tryShunzi(card) + if (card < 400 and card % 100 > 7) then + return false + end + if (checkCard(card + 1, self.cardList) and checkCard(card + 2, self.cardList)) then + removeCard(self.cardList, card, 1) + removeCard(self.cardList, card + 1, 1) + removeCard(self.cardList, card + 2, 1) + local cardGroup = {card,card+1,card+2} + self:push(cardGroup) + return true + end + return false +end + +function M:tryKezi(card) + if (checkCardAndRomve(card, self.cardList, 3)) then + local cardGroup = {card,card,card} + self:push(cardGroup) + return true + end + return false +end + +function M:tryPair(card) + if (self.pair_count > 0) then + return false + end + if (self.jiang) then + if (not (card % 100 == 2 or card % 100 == 5 or card % 100 == 8)) then + return false + end + end + if (checkCardAndRomve(card, self.cardList, 2)) then + local cardGroup = {card,card} + self:push(cardGroup) + self.pair_count = 1 + return true + end + return false +end + +function M:tryWin() + if (#self.cardList == 0 and self.pair_count == 1) then + return true + end + + if (#self.cardList == 0) then + return false + end + + local activeCard = self.cardList[1] + if (self:tryPair(activeCard)) then + if (self:tryWin()) then + return true + end + self.pair_count = 0 + self:rollBack() + end + + if (self:tryKezi(activeCard)) then + if (self:tryWin()) then + return true + end + self:rollBack() + end + + if (self:tryShunzi(activeCard)) then + if (self:tryWin()) then + return true + end + self:rollBack() + end + + + return false +end + + + +local function init(self,cardInhand,addCard,jiang) + self.stack = {} + self.pair_count = 0 + self.jiang = jiang + self.cardList = membe_clone(cardInhand) + self.cardList[#self.cardList+1] = addCard + table.sort(self.cardList) + return self:tryWin() +end + +local function quanqiuren(cardInhand,drawCard) + if (#cardInhand > 1) then + return false + end + if (cardInhand[1] ~= drawCard) then + return false + end + return true +end + +local function qingyise(fzList, cardInhand, drawCard) + local se = math.floor(cardInhand[1] / 100) + if (math.floor(drawCard / 100) ~= se) then + return false + end + for i=1,#fzList do + local fz = fzList[i] + if (se ~= math.floor(fz.card / 100)) then + return false + end + end + for i=1,#cardInhand do + if (se ~= math.floor(cardInhand[i] / 100)) then + return false + end + end + return true +end + + + +local function jiangjiang(fzList, cardInhand,drawCard) + if (drawCard % 100 ~= 2 and drawCard % 100 ~= 5 and drawCard % 100 ~= 8) then + return false + end + for i=1,#fzList do + local fz = fzList[i] + if (fz.type == FZType.Chi) then + return false + end + if (fz.card % 100 ~= 2 and fz.card % 100 ~= 5 and fz.card % 100 ~= 8) then + return false + end + end + for i=1,#cardInhand do + local card = cardInhand[i] + if (card % 100 ~= 2 and card % 100 ~= 5 and card % 100 ~= 8) then + return false + end + end + return true +end + +local function checkQidui(cardList) + if (#cardList== 0) then + return true + end + local card = cardList[1] + if (cardNum(card, cardList) >= 2) then + removeCard(cardList, card, 2) + if checkQidui(cardList) then + return true + end + end +end + +local function qixiaodui(cardInhand, drawCard) + if (#cardInhand ~= 13) then + return false + end + + local cardlist = membe_clone(cardInhand) + cardlist[#cardlist+1] = drawCard + return checkQidui(cardlist) +end + + +local function CheckPengPeng(cardList, jiang) + if (#cardList== 0) then + return true + end + local card = cardList[1] + if (cardNum(card, cardList) >= 3) then + removeCard(cardList, card, 3) + return CheckPengPeng(cardList, jiang) + elseif (cardNum(card, cardList) == 2) and not jiang then + removeCard(cardList, card, 3) + jiang = true + return CheckPengPeng(cardList, jiang) + end +end +local function pengpenghu(cardInhand, fzList, drawCard) + for i = 1, #fzList do + local tem = fzList[i] + if tem.type == FZType.Chi then + return false + end + end + local cardlist = membe_clone(cardInhand) + cardlist[#cardlist+1] = drawCard + return CheckPengPeng(cardlist, false) +end + +function M.tingPai(cardInhand,fzList) + local self = setmetatable({}, {__index = M}) + local tingList = {} + if not cardInhand or #cardInhand == 0 then + return tingList + end + for k=100,300,100 do + for i=1,9 do + local tem = k + i + local result = false + result = qixiaodui(cardInhand,tem) + if not result then + result = quanqiuren(cardInhand,tem) + end + if not result then + result = jiangjiang(fzList,cardInhand,tem) + end + if not result then + if qingyise(fzList,cardInhand,tem) then + result = init(self,cardInhand,tem,false) + else + result = init(self,cardInhand,tem,true) + end + end + if not result then + result = pengpenghu(cardInhand, fzList, tem) + end + if(result) then + tingList[#tingList + 1] = tem + end + end + end + return tingList +end + +return M \ No newline at end of file diff --git a/lua_probject/extend_project/extend/majiang/ningxiang/EXClearingView.lua b/lua_probject/extend_project/extend/majiang/ningxiang/EXClearingView.lua new file mode 100644 index 00000000..e5e117a7 --- /dev/null +++ b/lua_probject/extend_project/extend/majiang/ningxiang/EXClearingView.lua @@ -0,0 +1,559 @@ +require("Game.View.ResultView") +local CS_Win_Type = import(".CS_Win_Type") + +local CS_ClearingView = {} + +local M = CS_ClearingView + +function CS_ClearingView.new(blur_view) + setmetatable(M, {__index = ResultView}) + local self = setmetatable({}, {__index = M}) + -- self._full = true + ResultView.init(self, "ui://Main_Majiang/clearing") + + self._currenIndex = 0 + self._blur_view = blur_view + self._close_zone = false + self._close_destroy = true + + self.xiPaiCtr=self._view:GetController("xipai") + + self:InitMaPai() + return self +end + + +function M:InitMaPai() + self.maPaiCtr=self._view:GetController("mapai") + self.maPaiCtr.selectedIndex=0 + + self.maPaiList={} + + for i=1,10 do + local tempMP=self._view:GetChild("niao"..i) + table.insert(self.maPaiList,tempMP) + end + +end + + +function M:IsMapaiShow(niao,isShow) + if niao then + niao.visible=isShow + end +end + + +function M:SetMaPaiValue(niao,value) + if niao then + niao.icon='ui://Main_Majiang/' ..get_majiang_prefix(DataManager.CurrenRoom.game_id).."201_"..value + end +end + +function M:SetMaPaiColor(niao,num) + niao:GetController("color").selectedIndex=num +end + +function M:HideAllMapai() + for i=1,#self.maPaiList do + self:IsMapaiShow(self.maPaiList[i],false) + self:SetMaPaiColor(self.maPaiList[i],0) + end +end + + + +function M:ShowSelectMaPai(niaoList) + if niaoList and #niaoList>0 then + self.maPaiCtr.selectedIndex=1 + self:HideAllMapai() + for i=1,#niaoList do + self:IsMapaiShow(self.maPaiList[i],true) + self:SetMaPaiValue(self.maPaiList[i],niaoList[i].card) + if niaoList[i].score>0 then + self:SetMaPaiColor(self.maPaiList[i],2) + end + end + else + self.maPaiCtr.selectedIndex=0 + end +end + + +function M:InitData(over, room, result, total_result, callback) + self._callback = callback + local _overCtr = self._view:GetController("over") + local btn_confirm = self._view:GetChild("btn_confirm") + local btn_result = self._view:GetChild("btn_showResult") + local btn_close = self._view:GetChild("big_result"):GetChild("btn_close") + local _btnCtr = self._view:GetController("button") + local _sdkCtr = self._view:GetController("sdk") + local ctr_type = self._view:GetController("type") + self._view:GetChild("tex_roominfo").text = string.format("房号%s 局%s/%s %s", room.room_id, room.curren_round, room.room_config.round, os.date("%Y-%m-%d %H:%M:%S", os.time())) + self._view:GetChild("tex_gameinfo").text = string.gsub(room.room_config:GetDes(), "\r", "") + -- self._view:GetChild("tex_roomnum").text = room.room_id + -- self._view:GetChild("tex_data").text = os.date("%Y-%m-%d %H:%M", os.time()) + -- self._view:GetChild("tex_time").text = os.date("%H:%M", os.time()) + + local paixingxiangqing=self._view:GetChild("btn_detal") + paixingxiangqing.visible=false + local fanhuipaixing=self._view:GetChild("btn_fanhuipaixing") + fanhuipaixing.visible=false + + local round=DataManager.CurrenRoom.room_config.config.times or 1 + local xpconfig=DataManager.CurrenRoom.room_config.config.xi_pai + if xpconfig and round>1 then + self.xiPaiCtr.selectedIndex=1 + else + self.xiPaiCtr.selectedIndex=0 + end + + + if result then + self:ShowSelectMaPai(result.niao) + end + + -- 初始化查看桌面状态标记 + + + if over ~= 2 then + local xipai=self._view:GetChild("btn_xipai") + xipai.touchable=true + xipai.onClick:Add(function() + local xiPaiCallBack=function () + xipai.touchable=false + self.xiPaiCtr.selectedIndex=0 + ViewUtil.ErrorTip(1000000,"申请洗牌成功") + end + local _gamectr = ControllerManager.GetController(GameController) + _gamectr:SendXiPaiAction(xiPaiCallBack) + end) + if result and result.xipai_score then + --xipai.text="洗牌 积分x"..result.xipai_score + end + + if result.liuju then + ctr_type.selectedIndex = 3 + else + local info_list = result.info_list + for i = 1, #info_list do + local is_win = info_list[i].is_win + if is_win then + if info_list[i].seat == room.self_player.seat then + ctr_type.selectedIndex = 1 + else + ctr_type.selectedIndex = 2 + end + end + end + end + if over == 0 then + _btnCtr.selectedIndex = 0 + _sdkCtr.selectedIndex = 1 + btn_confirm.onClick:Add(function() + local _gamectr = ControllerManager.GetController(GameController) + _gamectr:PlayerReady() + self:DestroyWithCallback() + end) + self:AddClearItem(room, result.info_list, nil, over, result.niao, result.active_player) + elseif over == 1 then + self.xiPaiCtr.selectedIndex=0 + _btnCtr.selectedIndex = 1 + _sdkCtr.selectedIndex = 1 + btn_result.onClick:Add(function() + _overCtr.selectedIndex = 1 + _btnCtr.selectedIndex = 0 + _sdkCtr.selectedIndex = 0 + self.maPaiCtr.selectedIndex=0 + if self._qsinfo_view then + self._qsinfo_view:Dispose() + end + end) + btn_close.onClick:Add(function() + ViewManager.ChangeView(ViewManager.View_Lobby) + end) + self:AddClearItem(room, result.info_list, total_result.info_list, over, result.niao, result.active_player) + end + else + self.xiPaiCtr.selectedIndex=0 + _overCtr.selectedIndex = 1 + self.maPaiCtr.selectedIndex=0 + btn_close.onClick:Add(function() + ViewManager.ChangeView(ViewManager.View_Lobby) + end) + self:AddClearItem(room, nil, total_result.info_list, over) + end +end + +function M:AddClearItem(room, data, total_data,over, niao, active_player) + local n = over + 1 + local list_view1 = self._view:GetChild("player_list_1") + local list_view2 = self._view:GetChild("player_list_2") + if 0 == over or 1 == over then + -- 把鸟放到中的人列表中 + for i = 1, #niao do + if niao[i].score > 0 then + local p = room:GetPlayerById(niao[i].playerId) + for j = 1, #data do + if data[j].seat == p.seat then + if not data[j].niao then + data[j].niao = {} + end + table.insert(data[j].niao, niao[i].card) + end + end + end + end + table.sort(data, function(a,b) return a.seat > b.seat end) + list_view1:RemoveChildrenToPool() + for i=1,#data do + local item = list_view1:AddItemFromPool() + self:FillItemData(room, data[i], item, active_player, niao) + end + if #data == 3 then + list_view1.lineGap = 54 + elseif #data == 2 then + list_view1.lineGap = 108 + end + if 1 == over then + self:FillItemData2(room, total_data, list_view2) + end + elseif 2 == over then + self:FillItemData2(room, total_data, list_view2) + end +end + +function M:FillItemData(room, data, item, active_player) + local _gamectr = ControllerManager.GetController(GameController) + local p = room:GetPlayerBySeat(data["seat"]) + item:GetChild("playerName").text = p.self_user.nick_name + if data.win_count > 3 then + item:GetController("mult_win").selectedIndex = 1 + -- item:GetChild("tex_win_count").text = string.char(97 + data.win_count - 4) .. "连" + end + + local huadd = data["hu_score"] + local qsadd = data["qs_score"] + local birdadd = data["niao_score"] + local qs_niao_list = data["qs_niao_list"] + local total = data["round_score"] + + -- if room.room_config.fengding and huadd + birdadd >= 28 then + if data.fengding then + item:GetController("fengding").selectedIndex = 1 + else + item:GetController("fengding").selectedIndex = 0 + end + + local sp = " " + local str = "胡:"..huadd.."分" + str = str..sp.."扎鸟:"..birdadd.."分" + str = str..sp.."起手胡:"..qsadd.."分" + -- if #qs_niao_list > 0 then + -- str = str .. "(摇骰点数:" .. qs_niao_list[1].card .. " " .. qs_niao_list[2].card .. ")" + -- end + if data["piao_niao_score"] then + str = str..sp.."飘鸟:"..data["piao_niao_score"].."分" + end + item:GetChild("score1").text = str + local win_list = data["win_list"] + local remove_win_card = true + if win_list then + local str1 = "" + item:GetController("hu_list").selectedIndex = 1 + for i = 1, #win_list do + local str2 = "" + if win_list[i].type == 1 then + local value = win_list[i].value + str2 = value == 1 and "" or (value == 2 and "豪华" or (value == 3 and "双豪华" or "三豪华")) + str2 = str2 .. "小七对" + else + if win_list[i].type == 5 then + remove_win_card = false + end + str2 = CS_Win_Type[win_list[i].type] + end + str1 = str1..str2..sp + end + item:GetChild("score3").text = str1 + end + + -- 手牌 + local hand_cards = data["hand_card"] + table.sort(hand_cards, ViewUtil.HandCardSort) + local hand_list_view = item:GetChild("hand_card_list") + hand_list_view:RemoveChildrenToPool() + if data["is_win"] and active_player == p.self_user.account_id and remove_win_card then + list_remove(hand_cards, data["win_card"]) + end + for i=1,#hand_cards do + local card = hand_list_view:AddItemFromPool() + card.icon = "ui://Main_Majiang/" .. self:GetPrefix() .. "202_"..hand_cards[i] + end + hand_list_view.width = 52 * #hand_cards + + local fz_card = p.fz_list + local fz_card_list = item:GetChild("fz_card_list") + fz_card_list.width = 157 * #fz_card * 0.8 + fz_card_list:RemoveChildrenToPool() + for i=1,#fz_card do + if fz_card[i].type == FZType.Peng then + local item = fz_card_list:AddItemFromPool("ui://Main_Majiang/clearing_fz_3") + for j=1,3 do + local card = item:GetChild("card_" .. j) + card.icon = "ui://Main_Majiang/" .. self:GetPrefix() .. "202_"..fz_card[i].card + end + elseif fz_card[i].type == FZType.Chi then + local item = fz_card_list:AddItemFromPool("ui://Main_Majiang/clearing_fz_3") + for j = 1,3 do + local card = item:GetChild("card_" .. j) + card.icon = "ui://Main_Majiang/" .. self:GetPrefix() .. "202_"..fz_card[i].opcard[j] + end + elseif fz_card[i].type == FZType.Gang or fz_card[i].type == FZType.Gang_An or fz_card[i].type == FZType.Gang_Peng then + local item = fz_card_list:AddItemFromPool("ui://Main_Majiang/clearing_fz_4") + for j=1,4 do + local card = item:GetChild("card_" .. j) + if fz_card[i].type == FZType.Gang_An and j == 4 then + card.icon = "ui://Main_Majiang/202_00" + else + card.icon = "ui://Main_Majiang/" .. self:GetPrefix() .. "202_"..fz_card[i].card + end + end + end + end + + -- local total_score = data["total_score"] + if total >= 0 then + item:GetChild("score2win").text = "+" .. total + -- item:GetChild("score2win").grayed = false + else + item:GetChild("score2lose").text = total + -- item:GetChild("score2win").grayed = true + end + + local hp_nonnegative = room:checkHpNonnegative() + item:GetController("nonnegative").selectedIndex = hp_nonnegative and 1 or 0 + if hp_nonnegative then + local hp_info = data.hp_info + local ctr_hp_limit = item:GetController("hp_limit") + local hp = d2ad(hp_info.round_actual_hp) + if hp >= 0 then hp = "+" .. tostring(hp) end + item:GetChild("tex_hp").text = hp + ctr_hp_limit.selectedIndex = hp_info.upper_limit and 1 or 0 + end + + local is_win = data["is_win"] or false + item:GetController("win").selectedIndex = is_win and 0 or 1 + --print(p.self_user.account_id, active_player) + if p.self_user.account_id == active_player and is_win == false and not data["liuju"] then + item:GetController("win").selectedIndex = 2 + end + local win_card = item:GetChild("win_card") + if is_win then + win_card.icon = "ui://Main_Majiang/" .. self:GetPrefix() .. "202_"..data["win_card"] + end + if data.niao then + item:GetController("niao").selectedIndex = 1 + local lst_niao = item:GetChild("list_niao") + lst_niao:RemoveChildrenToPool() + local niao = data.niao + for i = 1, #niao do + local card_niao = lst_niao:AddItemFromPool() + card_niao.icon = "ui://Main_Majiang/" .. self:GetPrefix() .. "202_" .. niao[i] + end + end + if p.seat == room.banker_seat then + item:GetController("bank").selectedIndex = 1 + end + + -- item.onClick:Set(function() + -- self:__AddQSInfo(data.qs_info_list, p.self_user.nick_name, room) + -- end) +end + +function M:FillItemData2(room, data, list) + -- 赋值result_info,聊天室分享需要 + local player_list = {} + for i = 1, #data do + player_list[i] = {} + local user = room:GetPlayerBySeat(data[i].seat).self_user + player_list[i].id = user.account_id + player_list[i].hp_info = data[i].hp_info + player_list[i].score = data[i].total_score + player_list[i].house = room.owner_id == player_list[i].id and 1 or 0 + player_list[i].nick = user.nick_name + player_list[i].head_url = user.head_url + + local settle_log = data[i].settle_log + player_list[i].param = {} + player_list[i].param[1]={} + player_list[i].param[1].key = "大胡自摸:" + player_list[i].param[1].value = tostring(data[i].settle_log.da_zimo) + player_list[i].param[2]={} + player_list[i].param[2].key = "小胡自摸:" + player_list[i].param[2].value = tostring(data[i].settle_log.xiao_zimo) + player_list[i].param[3]={} + player_list[i].param[3].key = "大胡接炮:" + player_list[i].param[3].value = tostring(data[i].settle_log.da_jie_pao) + player_list[i].param[4]={} + player_list[i].param[4].key = "小胡接炮:" + player_list[i].param[4].value = tostring(data[i].settle_log.xiao_jie_pao) + player_list[i].param[5]={} + player_list[i].param[5].key = "大胡点炮:" + player_list[i].param[5].value = tostring(data[i].settle_log.da_dian_pao) + player_list[i].param[6]={} + player_list[i].param[6].key = "小胡点炮:" + player_list[i].param[6].value = tostring(data[i].settle_log.xiao_dian_pao) + end + local round = room.room_config.round + self:GenerateRoomResultInfo(round, room.room_config:GetGameName(), room.room_id, room.create_time, player_list) + -- self:SetGSListlineGap(-10) + + local big_result = self._view:GetChild("big_result") + big_result:GetChild("txt_room_info").text = string.format("%s 房号%s 局%s/%s", os.date("%Y/%m/%d", os.time()), room.room_id, room.curren_round, room.room_config.round) + local lst_p = big_result:GetChild("player_list") + if #player_list == 3 then + lst_p.columnGap = 108 + elseif #player_list == 2 then + lst_p.columnGap = 208 + end + self:InitBigResult(room, 30) + local show_detail = room.hpOnOff == 1 + for i = 1, lst_p.numChildren do + local com_p = lst_p:GetChildAt(i - 1) + local list_param = com_p:GetChild("list_param") + for j = 1, list_param.numChildren do + local tem = list_param:GetChildAt(j - 1) + tem:GetChild("txt_value").textFormat.size = 30 + end + if show_detail then + local score = 0 + if com_p:GetController("pn").selectedIndex == 0 then + score = com_p:GetChild("txt_navigate").text + else + score = com_p:GetChild("txt_positive").text + end + score = score / room.score_times + com_p:GetChild("tex_detail_score").text = string.format("%s × %s倍", score, room.score_times) + end + end + if room.group_id ~= 0 then + big_result:GetController("group").selectedIndex = 1 + end + DataManager.CurrenRoom = nil +end + +-- 起手胡详情 +function M:__AddQSInfo(data, nick, room) + if self._qsinfo_view then + self._qsinfo_view:Dispose() + end + local qsinfo = UIPackage.CreateObjectFromURL("ui://Extend_MJ_NingXiang/qs_info") + self._qsinfo_view = qsinfo + qsinfo:GetChild("btn_close").onClick:Add(function() + qsinfo:Dispose() + end) + qsinfo:GetChild("tex_nick").text = nick + local lst_qs = qsinfo:GetChild("lst_qs") + lst_qs:RemoveChildrenToPool() + if #data > 0 then + for i = 1, #data do + local tem = data[i] + local item = lst_qs:AddItemFromPool() + local lst_card = item:GetChild("lst_card") + -- 整理起手胡板牌 + local card_map = {} + for j = 1, #tem.win_list do + local opcard = tem.win_list[j].opcard + local cards = {} + for k = 1, #opcard do + local card = opcard[k] + if cards[card] then + cards[card] = cards[card] + 1 + else + cards[card] = 1 + end + end + for k,v in pairs(cards) do + local card = k + if card_map[card] then + if card_map[card] < cards[card] then + card_map[card] = cards[card] + end + else + card_map[card] = cards[card] + end + end + end + local all_cards = {} + for j,v in pairs(card_map) do + for k = 1, v do + table.insert(all_cards, j) + end + end + table.sort(all_cards) + for j = 1, #all_cards do + local citem = lst_card:AddItemFromPool() + citem.touchable = false + citem.icon = "ui://Main_Majiang/" .. self:GetPrefix() .. "202_"..all_cards[j] + end + local cs_zhua_niao = room.room_config.niao_type == 2 + qsinfo:GetController("niao").selectedIndex = cs_zhua_niao and 1 or 0 + item:GetChild("tex_touzi").text = cs_zhua_niao and (tem.niao[1].card .. " " .. tem.niao[2].card) or "" + item:GetChild("tex_score").text = tem.score + item:GetChild("tex_niao_score").text = cs_zhua_niao and tem.niao_score or "" + end + else + qsinfo:GetController("c1").selectedIndex = 1 + end + if #data > 1 then + qsinfo.height = qsinfo.height + 56 * (#data - 1) + end + + local _view_start_pos = nil + local _touch_start_pos = nil + self._view:AddChild(qsinfo) + local btn_di = qsinfo:GetChild("btn_di") + btn_di.onTouchBegin:Add(function(context) + _view_start_pos = Vector2(qsinfo.x, qsinfo.y) + _touch_start_pos = self._view:GlobalToLocal(Vector2(context.inputEvent.x, context.inputEvent.y)) + end) + btn_di.onTouchMove:Add(function(context) + local xy = self._view:GlobalToLocal(Vector2.New(context.inputEvent.x,context.inputEvent.y)) + local dist = Vector2(xy.x - _touch_start_pos.x, xy.y - _touch_start_pos.y) + local posx = _view_start_pos.x + dist.x + local posy = _view_start_pos.y + dist.y + local max_x = self._view.width - qsinfo.width + local max_y = self._view.height - qsinfo.height + qsinfo.x = posx < 0 and 0 or posx > max_x and max_x or posx + qsinfo.y = posy < 0 and 0 or posy > max_y and max_y or posy + end) + qsinfo:Center() +end + +function M:LoadHead(p, room) + local btn_head = self._view:GetChild("btn_head") + for i = 1, #room.player_list do + local player = room.player_list[i] + if p.seat == player.seat and player.self_user.head_url ~= "" then + ImageLoad.Load(player.self_user.head_url, btn_head.icon) + end + end +end + +local prefix +function M:GetPrefix() + -- if not prefix then + prefix = get_majiang_prefix(10) + -- end + return prefix +end + +function M:DestroyWithCallback() + if self._callback then + self._callback() + end + self:Destroy() +end + +return M \ No newline at end of file diff --git a/lua_probject/extend_project/extend/majiang/ningxiang/EXGameController.lua b/lua_probject/extend_project/extend/majiang/ningxiang/EXGameController.lua new file mode 100644 index 00000000..8ec6da53 --- /dev/null +++ b/lua_probject/extend_project/extend/majiang/ningxiang/EXGameController.lua @@ -0,0 +1,427 @@ +local CS_Protocol = import(".Protocol") +local FZTipList = require("main.majiang.FZData") +local CS_GameEvent = import(".CS_GameEvent") + +local M = {} + +--- Create a new CS_GameController +function M.new() + setmetatable(M,{__index = GameController}) + local self = setmetatable({}, {__index = M}) + self:init("测试麻将") + self.class = "CS_GameController" + return self +end + +function M:init(name) + GameController.init(self,name) + + self._eventmap[CS_Protocol.GAME_EVT_PLAYER_DEAL] = self.OnEventSendCards + self._eventmap[CS_Protocol.GAME_EVT_CHANGE_ACTIVE_PLAYER] = self.OnEventTurn + + self._eventmap[CS_Protocol.GAME_EVT_DRAW] = self.OnEventTakeCard + self._eventmap[CS_Protocol.GAME_EVT_DISCARD_TIP] = self.OnEventOutHint + self._eventmap[CS_Protocol.GAME_EVT_DISCARD] = self.OnEventOutCard + + self._eventmap[CS_Protocol.GAME_EVT_FZTIPS] = self.OnEventFzTips + self._eventmap[CS_Protocol.GAME_EVT_ACTION] = self.OnEventFzAction + + self._eventmap[CS_Protocol.GAME_EVT_HU] = self.OnEventHu + + self._eventmap[CS_Protocol.GAME_EVT_RESULT1] = self.OneventResult1 + self._eventmap[CS_Protocol.GAME_EVT_RESULT2] = self.OnEventResult2 + self._eventmap[CS_Protocol.GAME_EVT_NIAO] = self.OnEventNiao + + self._eventmap[CS_Protocol.GAME_EVT_QSTIP] = self.OnEventQSTip + self._eventmap[CS_Protocol.GAME_EVT_QSWIN] = self.OnEventQSAction + self._eventmap[CS_Protocol.GAME_EVT_OPENKONG] = self.OnEventKaiGang + self._eventmap[CS_Protocol.GAME_EVT_HAIDI] = self.OnEventHaidi + self._eventmap[CS_Protocol.GAME_EVT_PIAOTIP] = self.OnEventPiaoTip + self._eventmap[CS_Protocol.GAME_EVT_PIAO] = self.OnEventPiao + self._eventmap[CS_Protocol.GAME_EVT_TING_TIP] = self.OnEventTingTip + self._eventmap[CS_Protocol.GAME_EVT_TING] = self.OnEventTing + self._eventmap[CS_Protocol.GAME_EVENT_XIPAI] = self.OnEventXiPai + self._eventmap[CS_Protocol.GAME_EVENT_NOTIFY_XIPAI] = self.OnEventXiPaiAnim +end + +local __pre_delete_card = false +-- 发送出牌指令到服务器 +function M:SendOutCard(card, callback) + local _room = self._room + local p = _room.self_player + + local _data = {} + _data["card"] = card + _data["card_list"] = p.card_list + if p.outcard_list and #p.outcard_list>0 then + _data["outcard_list"] = p.outcard_list + end + + + local _client = ControllerManager.GameNetClinet + _client:send(CS_Protocol.GAME_DIS_CARD, _data) + + -- 进行预删牌处理 + + _room.curren_outcard_seat = -1 + list_remove(p.card_list,card) + table.sort(p.card_list, ViewUtil.HandCardSort) + p.hand_left_count = p.hand_left_count - 1 + if not p.outcard_list then p.outcard_list = {} end + p.outcard_list[#p.outcard_list+1] = card + __pre_delete_card = true + callback() +end + +-- 发送放子选择到服务器 +function M:SendAction(id) + local _data = {} + _data["id"] = id + local _client = ControllerManager.GameNetClinet + _client:send(CS_Protocol.GAME_ACTION, _data) +end + + +function M:SendXiPaiAction(callBack) + local _data = {} + local _client = ControllerManager.GameNetClinet + _client:send(CS_Protocol.GAME_XIPAI, _data) + self.XiPaiCallBack=callBack +end + +function M:OnEventXiPai(evt_data) + if evt_data["result"]==0 then + if self.XiPaiCallBack then + self.XiPaiCallBack() + end + else + ViewUtil.ErrorTip(1000000,"申请洗牌失败") + end + +end + + + +function M:OnEventXiPaiAnim(evt_data) + printlog("洗牌动画===》》》》") + pt(evt_data) + local playeridList = evt_data["list"] + local my_isXiPai=false + local other_isXiPai=false + if playeridList and #playeridList>0 then + for i=1,#playeridList do + local p = self._room:GetPlayerById(playeridList[i]) + if p== self._room.self_player then + my_isXiPai=true + else + other_isXiPai=true + end + end + end + + self._cacheEvent:Enqueue(function() + DispatchEvent(self._dispatcher,CS_GameEvent.EventXiPai,my_isXiPai,other_isXiPai) + end) +end + + +function M:OnEventSendCards(evt_data) + if ViewManager.GetCurrenView().dview_class == LobbyView then + self:ReturnToRoom() + return + end + local _room = self._room + -- if(_room.CurnrenState == StateType.Ready) then + -- _room.CurnrenState = StateType.Palying + -- end + -- _room.curren_round = _room.curren_round + 1 + _room.curren_round = evt_data["round"] + if _room.curren_round > 0 then _room.playing = true end + + -- _room.SelfPlayer.AutoOutCard = false + local handcards = evt_data["card_list"] + local p = _room.self_player + local seat = evt_data["bank_seat"] + local left_count = evt_data["left_count"] + self._cacheEvent:Enqueue(function() + _room.banker_seat = seat + for i=1,#_room.player_list do + _room.player_list[i].hand_left_count = _room.player_list[i].seat == _room.banker_seat and 14 or 13 + _room.player_list[i].fz_list = {} + _room.player_list[i].card_list = {} + end + p.card_list = handcards + self._room.self_player.hand_left_count = #handcards + table.sort( handcards, ViewUtil.HandCardSort ) + DispatchEvent(self._dispatcher,CS_GameEvent.SendCards, left_count) + end) +end + +function M:OnEventOutCard(evt_data) + local seat = evt_data["seat"] + local card = evt_data["card"] + local p = self._room:GetPlayerBySeat(seat) + self._cacheEvent:Enqueue(function() + local _room = self._room + if seat == _room.self_player.seat and __pre_delete_card then + __pre_delete_card = false + else + if seat == _room.self_player.seat then + list_remove(p.card_list, card) + table.sort(p.card_list, ViewUtil.HandCardSort) + end + p.hand_left_count = p.hand_left_count - 1 + if not p.outcard_list then p.outcard_list = {} end + p.outcard_list[#p.outcard_list+1] = card + DispatchEvent(self._dispatcher,CS_GameEvent.OutCard, p, card) + end + end) +end + + +function M:OnEventTakeCard(evt_data) + local _room = self._room + local seat = evt_data["seat"] + local card = evt_data["card"] + local left_count = evt_data["left_count"] + local p = _room:GetPlayerBySeat(seat) + self._cacheEvent:Enqueue(function() + p.hand_left_count = p.hand_left_count +1 + if (seat == _room.self_player.seat) then + _room.self_player.card_list[#_room.self_player.card_list+1] = card + -- table.sort( _room.self_player.card_list, ViewUtil.HandCardSort ) + end + DispatchEvent(self._dispatcher,CS_GameEvent.GetCard, seat, card, left_count) + end) +end + +function M:OnEventOutHint(evt_data) + self._cacheEvent:Enqueue(function() + DispatchEvent(self._dispatcher,CS_GameEvent.OutHint, evt_data) + end) +end + +function M:OnEventTurn(evt_data) + local seat = evt_data["seat"] + self._cacheEvent:Enqueue(function() + DispatchEvent(self._dispatcher,CS_GameEvent.EventTurn, seat) + end) +end + +function M:OnEventFzTips(evt_data) + self._cacheEvent:Enqueue(function() + local tiplist = FZTipList.new() + local list = evt_data["tip_list"] + for i=1,#list do + local dtip = list[i] + local tip = {} + tip.id = dtip["id"] + tip.weight = dtip["weight"] + tip.card = dtip["card"] + tip.type = dtip["type"] + tip.opcard = dtip["opcard"] + tiplist:AddTip(tip) + end + DispatchEvent(self._dispatcher,CS_GameEvent.FZTips, tiplist) + end) +end + +function M:OnEventFzAction(evt_data) + local _room = self._room + local playerid = evt_data["playerid"] + local card = evt_data["card"] + local actice_card = evt_data["active_card"] + local type = evt_data["type"] + local from_seat = evt_data["from_seat"] + local opcard = evt_data["opcard"] + local opengang = evt_data["opengang"] + -- local openkong = evt_data["openkong"] + + local p = _room:GetPlayerById(playerid) + self._cacheEvent:Enqueue(function() + local fz = nil + local index = -1 + local ftype = type + if (ftype == FZType.Gang_Peng) then + for i=1,#p.fz_list do + if (p.fz_list[i].card == card) then + p.fz_list[i].card = card + fz = p.fz_list[i] + fz.type = type + index = i -1 + break + end + end + end + fz = {} + fz.card = card + fz.type = type + fz.opengang = opengang + if (index == -1) then + if (ftype == FZType.Chi) then + local data ={} + data[1] = opcard[1] + data[2] = card + data[3] = opcard[2] + fz.opcard =data + end + p.fz_list[#p.fz_list+1] = fz + end + fz.from_seat = from_seat + local remove_num = #opcard + + if (p == _room.self_player) then + for i=1,remove_num do + list_remove(p.card_list,opcard[i]) + end + end + + p.hand_left_count = p.hand_left_count - remove_num + if not (fz.type == FZType.Gang_An or (fz.type == FZType.Gang_Peng and not fz.opengang)) then + -- if (fz.Type == FZType.Chi) then card = actice_card end + local fp = _room:GetPlayerBySeat(from_seat) + if card == fp.outcard_list[#fp.outcard_list] then + table.remove(fp.outcard_list,#fp.outcard_list) + else + table.remove(fp.outcard_list,#fp.outcard_list - 1) + end + end + + DispatchEvent(self._dispatcher,CS_GameEvent.FangziAction, fz, p, index) + end) +end + +function M:OnEventHu(evt_data) + local cards = evt_data["card"] + local win_p = self._room:GetPlayerBySeat(evt_data["seat"]) + local lose_p = self._room:GetPlayerBySeat(evt_data["from_seat"]) + local win_card = evt_data["win_card"] + local win_list = evt_data["win_list"] + + self._cacheEvent:Enqueue(function() + win_p.card_list = cards + table.sort( win_p.card_list, ViewUtil.HandCardSort) + DispatchEvent(self._dispatcher,CS_GameEvent.ZPHuCard, evt_data["seat"], evt_data["from_seat"], win_card, cards, win_list) + end) +end + +function M:OneventResult1(evt_data) + local over = evt_data.type + --0:小结算 1:小大结算 2:大结算 + self._room.playing = false + if 0 == over then + local result = evt_data.result + self._cacheEvent:Enqueue(function() + for i = 1, #self._room.player_list do + local p = self._room.player_list[i] + p.hand_left_count = 0 + p.outcard_list = {} + end + DispatchEvent(self._dispatcher,CS_GameEvent.ZPResult1, result); + end) + elseif 1 == over or 2 == over then + DataManager.CurrenRoom.Over = true + ControllerManager.SetGameNetClient(nil,true) + local total_result = evt_data.total_result + local result = evt_data.result + self._cacheEvent:Enqueue(function() + DispatchEvent(self._dispatcher,CS_GameEvent.ZPResult2, result, total_result, over); + end) + end +end + +function M:OnEventNiao(evt_data) + local list = evt_data["niao"] + local start_seat = evt_data["start_seat"] + self._cacheEvent:Enqueue(function() + DispatchEvent(self._dispatcher,CS_GameEvent.EventNiao, list, start_seat) + end) +end + +function M:OnEventQSTip(evt_data) + self._cacheEvent:Enqueue(function() + DispatchEvent(self._dispatcher,CS_GameEvent.EventQSTip, evt_data) + end) +end + +function M:OnEventQSAction(evt_data) + self._cacheEvent:Enqueue(function() + DispatchEvent(self._dispatcher,CS_GameEvent.EvnetQSAction, evt_data) + end) +end + +function M:OnEventKaiGang(evt_data) + local seat = evt_data["seat"] + local p = self._room:GetPlayerBySeat(seat) + local cardList = evt_data.info.cardList + local card = evt_data.card + self._room.remain_cards = evt_data.left_count + self._cacheEvent:Enqueue(function() + for i = 1, #cardList do + p.outcard_list[#p.outcard_list + 1] = cardList[i] + end + DispatchEvent(self._dispatcher,CS_GameEvent.EventKaiGang, evt_data, self._room.self_player.outcard_list) + end) +end + +function M:OnEventHaidi() + self._cacheEvent:Enqueue(function() + DispatchEvent(self._dispatcher,CS_GameEvent.EvnetHaiDi, evt_data) + end) +end + +function M:OnEventPiaoTip(evt_data) + if ViewManager.GetCurrenView().dview_class == LobbyView then + self:ReturnToRoom() + return + end + + self._cacheEvent:Enqueue(function() + self._room.playing = true + DispatchEvent(self._dispatcher,CS_GameEvent.EvnetPiaoTip, evt_data) + end) +end + +function M:OnEventTingTip() + self._cacheEvent:Enqueue(function() + DispatchEvent(self._dispatcher,CS_GameEvent.EventTingTip) + end) +end + +function M:OnEventTing(evt_data) + self._cacheEvent:Enqueue(function() + local seat = evt_data.seat + DispatchEvent(self._dispatcher,CS_GameEvent.EventTing, seat) + end) +end + +function M:OnEventPiao(evt_data) + self._cacheEvent:Enqueue(function() + DispatchEvent(self._dispatcher,CS_GameEvent.EvnetPiao, evt_data.seat, evt_data.num) + end) +end + +function M:GetPosString( seat ) + if DataManager.CurrenRoom.room_config.people_num ~= 4 then return"" end + if seat == 1 then + return "北" + elseif seat == 2 then + return "西" + elseif seat == 3 then + return "南" + elseif seat == 4 then + return "东" + end +end + +function M:Discard(card) + local _data = {} + _data["card"] = card + local _room = self._room + local _client = ControllerManager.GameNetClinet + -- list_remove(_room.SelfPlayer.Cards,card) + -- table.sort(_room.SelfPlayer.Cards) + _client:send(CS_Protocol.Game_Da, _data) +end + +return M \ No newline at end of file diff --git a/lua_probject/extend_project/extend/majiang/ningxiang/EXGameInfo.lua b/lua_probject/extend_project/extend/majiang/ningxiang/EXGameInfo.lua new file mode 100644 index 00000000..170fed31 --- /dev/null +++ b/lua_probject/extend_project/extend/majiang/ningxiang/EXGameInfo.lua @@ -0,0 +1,354 @@ +local EXGameInfo = {} + +local M = EXGameInfo + + +function EXGameInfo.new(blur_view) + setmetatable(M, {__index = IGameInfo}) + local self = setmetatable({}, {__index = M}) + self.class = "EXGameInfo" + + UIPackage.AddPackage("extend/majiang/ningxiang/ui/Info_MJ_NingXiang") + return self +end + +function M:FillData() + self._maxPlayer = 4 -- 默认玩家人数 + self._roundChoice = 4 -- 回合选项数 + if oldGameVersion==1 then + self._config = UIPackage.CreateObjectFromURL("ui://Info_MJ_NingXiang/Cgm_create_room") + else + self._config = UIPackage.CreateObjectFromURL("ui://Info_MJ_NingXiang/Cgm_create_room_yueyang") + end + + if oldGameVersion==2 then + self._config:GetController("xipai").selectedIndex=0 + + self.xipaiValueText=self._config:GetChild('xipaifen') + self.xipaiValueText.text=1 + self.xipaiValue=1 + + self.anchouValueText=self._config:GetChild('anchoufen') + self.anchouValueText.text=1 + self.anchouValue=1 + + local btn_cr = self._config:GetChild('sdsrbtn') + btn_cr.onClick:Set( + function() + + local gniv = GroupNumberInputView_Game.new(nil, function(num) + + local value = limit + if otype == 1 then + value = value + ad2d(num) + elseif otype == - 1 then + value = value - ad2d(num) + else + value = ad2d(num) + end + + if value < 0 then + ViewUtil.ErrorTip(1,"输入数据异常!") + end + + self.xipaiValueText.text=value/d2ad + self.xipaiValue=value/d2ad + + end, 3, nil) + gniv:Show() + + + end + ) + + + local btn_cr2 = self._config:GetChild('anchoubtn') + btn_cr2.onClick:Set( + function() + + local gniv = GroupNumberInputView_Game.new(nil, function(num) + + local value = limit + if otype == 1 then + value = value + ad2d(num) + elseif otype == - 1 then + value = value - ad2d(num) + else + value = ad2d(num) + end + + if value < 0 then + ViewUtil.ErrorTip(1,"输入数据异常!") + end + + self.anchouValueText.text=value/d2ad + self.anchouValue=value/d2ad + + end, 3, nil) + gniv:Show() + + + end + ) + + end + +end + +local _help_url= "ui://Info_MJ_NingXiang/Com_help" +function M:GetHelpUrl() + return _help_url +end + +local _icon_url = "ui://Info_MJ_NingXiang/icon" +function M:GetIconUrl() + return _icon_url +end + +local _icon_url1 = "ui://Info_MJ_NingXiang/icon1" +function M:GetIconUrl1() + return _icon_url1 +end + +local _play_list ={} --{"长沙麻将","三人长沙","二人长沙"} +function M:GetPlayList() + return _play_list +end + +function M:SelectedConfigData() + local _config = self._config + local round = _config:GetController("round").selectedIndex + 1 --== 0 and 1 or 2 + self._maxPlayer = _config:GetController("play_list").selectedIndex+2 + + local zhuangxian = _config:GetChild("btn_zhuangxian").selected and true or false + -- local piaofen = _config:GetChild("btn_piaofen").selected and true or false + local zimo = _config:GetChild("btn_zimo").selected and true or false + local AA = _config:GetController("Cost").selectedIndex + -- local liuliushun = _config:GetChild("btn_liuliushun").selected and true or false + -- local queyise = _config:GetChild("btn_queyise").selected and true or false + -- local banbanhu = _config:GetChild("btn_banbanhu").selected and true or false + -- local dasixi = _config:GetChild("btn_dasixi").selected and true or false + local jiejiegao = _config:GetChild("btn_jiejiegao").selected and true or false + local santong = _config:GetChild("btn_santong").selected and true or false + local yizhihua = _config:GetChild("btn_yizhihua").selected and true or false + local zhongtusixi = _config:GetChild("btn_zhongtusixi").selected and true or false + local zhongtuliuliushun = _config:GetChild("btn_zhongtuliuliushun").selected and true or false + + local niao_type = _config:GetController("niao").selectedIndex + local niao_num = _config:GetController("niao_num").selectedIndex + local niao_db_num = _config:GetController("niao_db_num").selectedIndex + local niao = niao_type == 1 and (niao_db_num == 0 and 1 or 2) or (niao_type == 0 and (niao_num == 0 and 2 or (niao_num == 1 and 4 or 6)) or 2) + local piao_niao = _config:GetChild("btn_piao_niao").selected + local two_pair = _config:GetChild("btn_two_pair").selected + local no_jiang = _config:GetChild("btn_no_jiang").selected + local four_win = _config:GetChild("btn_four_win").selected + local native_hu = _config:GetChild("btn_native_hu").selected + local queyimen = _config:GetChild("btn_queyimen").selected + + --获取封顶控制器状态 + local fengding_score = 0 + local fengding = false + + if _config:GetController("fengding") then + fengding_score=_config:GetController("fengding").selectedIndex + -- 判断:0 为 false,1/2/3 等为 true + fengding = (fengding_score > 0) + end + + local banyiquan = _config:GetChild("btn_banyiquan").selected + local menqing = _config:GetChild("btn_menqing").selected + local piao_niao1=0 + if _config:GetController('piao') then + piao_niao1=_config:GetController('piao').selectedIndex + end + local piao1=false + local piao2=false + local piao3=false + local piao_niao_opt=0 + if piao_niao1==2 then + piao_niao_opt=_config:GetController("piaofen").selectedIndex + end + + local xi_pai=false + local xi_paifen=0 + if _config:GetChild("xipai") then + xi_pai=_config:GetChild("xipai").selected + end + + local niaofen_opt=0 + local niaofen_score=1 + local difen_score=1 + local kai_gong=0 + if oldGameVersion==2 then + niaofen_opt=_config:GetController("niaoadd").selectedIndex + niaofen_score= tonumber(_config:GetController("niaodf").selectedPage) + difen_score= tonumber(_config:GetController("jcdifen").selectedPage) + kai_gong=_config:GetController("kaigang").selectedIndex + end + + +--------- + local _data = {} + _data["opt"] = round + _data["maxPlayers"] = self._maxPlayer + + _data["zhuangxian"] = zhuangxian + _data["zimo"] = zimo + _data["AA"] = AA + -- _data["piaofen"] = piaofen + -- _data["liuliushun"] = liuliushun + -- _data["queyise"] = queyise + -- _data["banbanhu"] = banbanhu + -- _data["dasixi"] = dasixi + _data["jiejiegao"] = jiejiegao + _data["santong"] = santong + _data["yizhihua"] = yizhihua + _data["zhongtusixi"] = zhongtusixi + _data["zhongtuliuliushun"] = zhongtuliuliushun + + _data["niao_type"] = niao_type + + + if oldGameVersion==1 then + _data["niao"] = niao + else + _data["niao"] = tonumber(_config:GetController("niao_num").selectedPage) + end + + + if oldGameVersion==1 then + _data["piao_niao"] = piao_niao + else + _data["piao_niao"] = piao_niao1 + end + _data["two_pair"] = two_pair + _data["no_jiang"] = no_jiang + _data["four_win"] = four_win + _data["native_hu"] = native_hu + _data["queyimen"] = queyimen + _data["fengding"] = fengding + _data["banyiquan"] = banyiquan + _data["menqing"] = menqing + _data["fengding_score"] = fengding_score + --_data['piao'] = piao + _data['piao1'] = piao1 + _data['piao2'] = piao2 + _data['piao3'] = piao3 + + auto_piao=false + if piao_niao1==2 then + if piao1 or piao2 or piao3 then + auto_piao=true + end + end + + if oldGameVersion==2 then + _data['auto_piao'] = auto_piao + end + + _data['xi_pai'] = xi_pai + _data['piao_niao_opt'] = piao_niao_opt + + local xi_pai_score=0 + local an_chou_score=0 + if oldGameVersion==2 then + xi_pai_score=self.xipaiValue + an_chou_score=self.anchouValue + end + + _data['xi_pai_score'] = ad2d(xi_pai_score) + _data['an_chou_score'] = ad2d(an_chou_score) + + if oldGameVersion==2 then + _data['niaofen_opt'] = niaofen_opt + _data['niaofen_score'] = niaofen_score + _data['difen_score'] = difen_score + _data['kai_gong'] = kai_gong + + end + + + pt(_data) + return _data +end + + + +function M:LoadConfigData(data) + pt(data) + local _config = self._config + _config:GetController("round").selectedIndex = data.opt - 1 -- == 1 and 0 or 1 + _config:GetController("play_list").selectedIndex = data.maxPlayers-2 + + _config:GetChild("btn_zhuangxian").selected = data.zhuangxian + _config:GetChild("btn_zimo").selected = data.zimo + _config:GetController("Cost").selectedIndex = data.AA + -- _config:GetChild("btn_piaofen").selected = data.piaofen + -- _config:GetChild("btn_liuliushun").selected = data.liuliushun + -- _config:GetChild("btn_queyise").selected = data.queyise + -- _config:GetChild("btn_banbanhu").selected = data.banbanhu + -- _config:GetChild("btn_dasixi").selected = data.dasixi + _config:GetChild("btn_jiejiegao").selected = data.jiejiegao + _config:GetChild("btn_santong").selected = data.santong + _config:GetChild("btn_yizhihua").selected = data.yizhihua + _config:GetChild("btn_zhongtusixi").selected = data.zhongtusixi + _config:GetChild("btn_zhongtuliuliushun").selected = data.zhongtuliuliushun + + _config:GetController("niao").selectedIndex = data.niao_type + + if oldGameVersion==1 then + _config:GetController("niao_num").selectedIndex = data.niao_type ~= 0 and 0 or (data.niao == 4 and 1 or (data.niao == 6 and 2 or 0)) + else + _config:GetController("niao_num").selectedIndex=data.niao/2-1 + end + _config:GetController("niao_db_num").selectedIndex = data.niao_type ~= 1 and 0 or (data.niao == 1 and 0 or 1) + if oldGameVersion==1 then + _config:GetChild("btn_piao_niao").selected = data.piao_niao + end + _config:GetChild("btn_two_pair").selected = data.two_pair + _config:GetChild("btn_no_jiang").selected = data.no_jiang + _config:GetChild("btn_four_win").selected = data.four_win + _config:GetChild("btn_native_hu").selected = data.native_hu + _config:GetChild("btn_queyimen").selected = data.queyimen + _config:GetChild("btn_fengding").selected = data.fengding or false + _config:GetChild("btn_banyiquan").selected = data.banyiquan or false + _config:GetChild("btn_menqing").selected = data.menqing or false + + if _config:GetController("fengding") then + _config:GetController("fengding").selectedIndex=data.fengding_score + end + + if _config:GetController("piao") then + _config:GetController("piao").selectedIndex=data.piao_niao + _config:GetChild('pf1').selected=data.piao1 + _config:GetChild('pf2').selected=data.piao2 + _config:GetChild('pf3').selected=data.piao3 + end + + if _config:GetChild("xipai") then + _config:GetChild("xipai").selected=data.xi_pai + end + + if _config:GetController("piaofen") then + _config:GetController("piaofen").selectedIndex=data.piao_niao_opt + end + + if oldGameVersion==2 then + self.xipaiValueText.text=data.xi_pai_score/d2ad(1000) + self.xipaiValue=data.xi_pai_score/d2ad(1000) + + self.anchouValueText.text=data.an_chou_score/d2ad(1000) + self.anchouValue=data.an_chou_score/d2ad(1000) + end + + if oldGameVersion==2 then + _config:GetController("niaoadd").selectedIndex=data.niaofen_opt or 0 + _config:GetController("niaodf").selectedIndex=data.niaofen_score-1 + _config:GetController("jcdifen").selectedIndex=data.difen_score-1 + _config:GetController("kaigang").selectedIndex=data.kai_gong + end + + end + +return M + \ No newline at end of file diff --git a/lua_probject/extend_project/extend/majiang/ningxiang/EXMainView.lua b/lua_probject/extend_project/extend/majiang/ningxiang/EXMainView.lua new file mode 100644 index 00000000..ca47b6e6 --- /dev/null +++ b/lua_probject/extend_project/extend/majiang/ningxiang/EXMainView.lua @@ -0,0 +1,1224 @@ +local MJPlayerSelfCardInfoView = import(".MJPlayerSelfCardInfoView") +local MJPlayerCardInfoView = import(".MJPlayerCardInfoView") +local MJMainView = require("main.majiang.MJMainView") +local CS_ClearingView = import(".EXClearingView") +local CS_GameEvent = import(".CS_GameEvent") +local PlayerInfoView = import(".EXPlayerInfoView") +local HuTipView = import("main.majiang.HuTipView") +local SettingView = import("main.majiang.MJSettingViewNew") + +-- local Fix_Msg_Chat = { +-- "你真棒!", +-- "快点出牌咯", +-- "神仙怕左手", +-- "这个吃得好", +-- "天灵灵 地灵灵 来支好牌行不行", +-- "我一听牌你就自摸", +-- "做了一天的最佳炮手", +-- "摸了一天的烂牌", +-- "不要走 决战到天亮", +-- "大家小心 我马上自摸", +-- "上家是冤家 放个牌吃行不行", +-- "冲动是魔鬼 犹豫也是", +-- "这局我糊了 请大家吃饭", +-- "这牌来得有点着急 简直让人疯狂", +-- } + + +local M = {} + +--- Create a new CS_MainView +function M.new() + setmetatable(M,{__index = MJMainView}) + local self = setmetatable({}, {__index = M}) + self.class = "CS_MainView" + self.asset_group = "NingXiang_MJ" + self:init() + ViewUtil.PlayMuisc(self.asset_group, "extend/majiang/ningxiang/sound/bg.mp3") + + return self +end + +function M:InitView(url) + local room = self._room + self._style = 1 + self._gps_style = 1 + self._full = true + -- self.Fix_Msg_Chat = Fix_Msg_Chat + UIPackage.AddPackage("extend/majiang/ningxiang/ui/Extend_MJ_NingXiang") + MJMainView.InitView(self,"ui://Main_Majiang/Main_"..room.room_config.people_num .. "_s2") + + self._view:GetChild('wanfa_text').text = room.room_config.people_num .. '人长麻 ' .. room.score_times .. '倍' + + self.LaiziBG=self._view:GetChild('n103') + self.LaiziBG.text="鬼牌" + self.LaiziBG.visible=false + self.selectLaiziBtn=self._view:GetChild('selectlaizi') + self.Laizi1Btn=self._view:GetChild('selectlaizi1') + self.Laizi2Btn=self._view:GetChild('selectlaizi2') + self.Laizi1Btn.visible=false + self.Laizi2Btn.visible=false + self.selectLaiziBtn.visible=false + + self._hu_tip = HuTipView.new(self) + self:PlayerChangeLineState() + + --print("CS_MainView") + if (room.playing or room.curren_round > 0) or room.status == 1 then + self:ReloadRoom() + end +end + + +function M:NewMJPlayerCardInfoView(view,index) + if index == 1 then + return MJPlayerSelfCardInfoView.new(view,self) + end + return MJPlayerCardInfoView.new(view,self) +end + +function M:EventInit() + MainView.EventInit(self) + local _room = self._room + local _view = self._view + local _gcm_outcard_url = UIPackage.GetItemURL("Main_Majiang", "Gcm_OutCard") + local _player_info = self._player_info + local _gamectr = self._gamectr + + _gamectr:AddEventListener(CS_GameEvent.EventXiPai,function( ... ) + local arg = {...} + local currentPlayer1=arg[1] + local currentPlayer2=arg[2] + self._popEvent = false + if ( currentPlayer1 ) then + + local xipaiCB=function () + self._popEvent = true + end + self:PlayXiPai(xipaiCB) + + end + + + if ( currentPlayer2 ) then + --self._popEvent = false + local xipaiCB2=function () + self._popEvent = true + end + self:PlayXiPai1(xipaiCB2) + end + + + end) + + _gamectr:AddEventListener(CS_GameEvent.SendCards,function( ... ) + local arg = {...} + self._tex_LeftCard.text = arg[1] + local info = self._player_card_info[1] + info._player.auto_out_card = false + self:UpdateRound() + self._state.selectedIndex = 1 + local list = _room.player_list + for i=1,#list do + local p = list[i] + local info = self._player_info[self:GetPos(p.seat)] + info:FillData(p) + info:MarkBank(p.seat == _room.banker_seat) + info:Ready(false) + local card_info = self._player_card_info[self:GetPos(p.seat)] + card_info:UpdateHandCard() + end + end) + _gamectr:AddEventListener(CS_GameEvent.EventTurn, function(...) + local arg = {...} + self._left_time = 15 + local seat = arg[1] + self:UpdateCardBox(self:GetPos(seat)) + end) + + _gamectr:AddEventListener(CS_GameEvent.OutHint, function(...) + local arg = {...} + local auto = arg[1].auto + if auto then + local p = self._room.self_player + local my_info = self._player_card_info[1] + if not my_info._player then info._player = {} end + my_info._player.auto_out_card = true + -- coroutine.start(function() + -- coroutine.wait(0.5) + -- self:OutCard(p.card_list[#p.card_list]) + -- end) + end + _room.curren_outcard_seat = _room.self_player.seat + --printlog("OutHint===>>>",_room.curren_outcard_seat) + local info = self._player_card_info[self:GetPos(_room.self_player.seat)] + info:UpdateHandCard(true) + end) + + + local _gcm_outcard_url ="ui://Main_Majiang/Gcm_OutCard" + _gamectr:AddEventListener(CS_GameEvent.OutCard, function(...) + self:__CloseTip() + self:ClearQSHTips() + self._left_time = 0 + local arg = {...} + local p = arg[1] + local seat = p.seat + local card = arg[2] + local info = self._player_card_info[self:GetPos(seat)] + self:RemoveCursor() + info:UpdateHandCard() + local outcard = UIPackage.CreateObjectFromURL(_gcm_outcard_url) + info:UpdateOutCardList(outcard, card, self._cursor) + self:PlaySound(p.self_user.sex,tostring(card)) + self:PlayMJSound("chupai.mp3") + if seat == _room.self_player.seat then + _room.curren_outcard_seat = -1 + end + end) + _gamectr:AddEventListener(CS_GameEvent.GetCard, function(...) + self:__CloseTip() + if self.kg_card then + self.kg_card:Dispose() + end + local arg = {...} + local seat = arg[1] + local card = arg[2] + self._tex_LeftCard.text = arg[3] + -- self:UpdateRoomInfo() + local info = self._player_card_info[self:GetPos(seat)] + info:UpdateHandCard(true) + end) + + _gamectr:AddEventListener(CS_GameEvent.FZTips, function(...) + local arg = {...} + local _tip = arg[1] + self:__FangziTip(_tip) + end) + + _gamectr:AddEventListener(CS_GameEvent.FangziAction, handler(self,self.OnFangziAction)) + + _gamectr:AddEventListener(CS_GameEvent.ZPHuCard, function(...) + if self.kg_card then + self.kg_card:Dispose() + end + self._left_time = 0 + self:UpdateCardBox(0) + self:__CloseTip() + self._popEvent = false + local arg = {...} + local win_seat = arg[1] + local lose_seat = arg[2] + local win_card = arg[3] + local cards = arg[4] + local win_list = arg[5] + local index = self:GetPos(win_seat) + local info = self._player_card_info[index] + self:RemoveCursor() + info:UpdateHandCard(false, true) + + local obj_win_card = UIPackage.CreateObjectFromURL("ui://Main_Majiang/Btn_Card") + obj_win_card.icon = "ui://Main_Majiang/" .. self:GetPrefix() .. "202_" .. win_card + obj_win_card:GetController("bg").selectedIndex = 1 + info._view:AddChild(obj_win_card) + obj_win_card:Center() + + local player = _room:GetPlayerBySeat(win_seat) + local hu_sound = win_seat == lose_seat and ("zimo"..math.random(1, 3)) or ("hu"..math.random(1, 2)) + self:PlaySound(player.self_user.sex, hu_sound) + if win_list[1].type == 11 then + local url, pNode + if win_seat ~= _room.self_player.seat then + url = "ui://Main_Majiang/别人胡" + pNode = info._mask_liangpai + elseif win_seat == _room.self_player.seat then + url = "ui://Main_Majiang/自己胡牌" + pNode = self._view + end + if win_seat == lose_seat then + url = "ui://Main_Majiang/eff_zimo" + end + local he = UIPackage.CreateObjectFromURL(url) + pNode:AddChild(he) + he:GetTransition("t2"):Play() + if win_seat == _room.self_player.seat then + he:Center() + elseif url == "ui://Main_Majiang/eff_zimo" then + he.scaleY = 0.4 + he.scaleX = 0.4 + he.x = he.width * 0.4 * 0.5 * -1 + he.y = he.height * 0.4 * 0.5 * -1 + end + coroutine.start(function() + coroutine.wait(2) + obj_win_card:Dispose() + he:Dispose() + self._popEvent = true + end) + else + local pNode = info._view + local url = (index == 1 or index == 3) and "eff_list1" or "eff_list2" + local he_list = UIPackage.CreateObjectFromURL("ui://Extend_MJ_NingXiang/" .. url) + he_list.touchable = false + pNode:AddChild(he_list) + he_list:Center() + coroutine.start(function() + for i = 1 ,#win_list do + local tem = win_list[i] + local com_name = "he" .. tem.type + if tem.type == 1 then + com_name = com_name .. "_" .. tem.value + end + local item = he_list:GetChild("list"):AddItemFromPool("ui://Extend_MJ_NingXiang/" .. com_name) + coroutine.wait(0.3) + end + if player.win_count and player.win_count >= 3 then + he_list:GetChild("list"):AddItemFromPool("ui://Extend_MJ_NingXiang/he_4w") + end + coroutine.wait(2) + obj_win_card:Dispose() + he_list:Dispose() + self._popEvent = true + end) + end + end) + + _gamectr:AddEventListener(CS_GameEvent.EventNiao, function(...) + local arg = {...} + self._popEvent = false + local list = arg[1] + local start_seat = arg[2] + ViewUtil.PlaySound("NingXiang_MJ", "extend/majiang/ningxiang/sound/zhuaniao.mp3") + coroutine.start(self.RunNiao,self,list, start_seat) + end) + + _gamectr:AddEventListener(CS_GameEvent.ZPResult1, function(...) + self._popEvent = false + self:__CloseTip() + if self._com_haidi then + self._com_haidi:Dispose() + self._com_haidi = nil + end + if self.kg_card then + self.kg_card:Dispose() + _room.kg_card={} + end + self._left_time = 0 + self:UpdateCardBox(0) + local arg = {...} + local result = arg[1] + local liuju = result.liuju + local data = result.info_list + local niao = result.niao + if liuju then + local le = UIPackage.CreateObjectFromURL("ui://Main_Majiang/LiuJu") + self._view:AddChild(le) + le:Center() + le:GetTransition("t0"):Play() + coroutine.start(function() + coroutine.wait(1) + le:Dispose() + end) + end + self:RemoveCursor() + if self._clearingView == nil then + self._clearingView = CS_ClearingView.new(self._view) + coroutine.start(function() + coroutine.wait(0.5) + if self._clearingView._is_destroy then return end + self._clearingView:Show() + self._popEvent = true + end) + end + + if _room.curren_round ~= _room.room_config.round then + -- if #niao == 0 then self._view:GetChild("n13").visible = false end + self._clearingView:InitData(0, _room, result, nil, function(...) + for i = 1, #data do + local p = _room:GetPlayerBySeat(data[i].seat) + p.total_score = data[i].total_score + local card_info = self._player_card_info[self:GetPos(p.seat)] + local info = self._player_info[self:GetPos(p.seat)] + card_info:Clear() + card_info:ResetCardType() + if _room:checkHpNonnegative() then + p.cur_hp = data[i].hp_info.cur_hp + end + info:UpdateScore() + info._view:GetChild("zhanji").visible = true + local num = data[i].hp_info.total_hp + if num > 0 then + info._view:GetController("text_color").selectedIndex = 0 + info._view:GetChild("text_jifen").text = "+" .. d2ad(num) + else + info._view:GetController("text_color").selectedIndex = 1 + info._view:GetChild("text_jifen").text = d2ad(num) + end + + info._view:GetChild("mask_piao").title = "" + info._view:GetController("piao_niao").selectedIndex = 0 + p.win_count = data[i].win_count + if p.win_count >= 3 then + info._view:GetController("three_win").selectedIndex = 1 + info._view:GetChild("com_three_win"):GetChild("tex_win").text = p.win_count + info._view:GetChild("com_three_win"):GetTransition("t0"):Play() + else + info._view:GetController("three_win").selectedIndex = 0 + end + info._view:GetController("ting").selectedIndex = 0 + p.fz_list = {} + p.auto_play=false + end + DataManager.CurrenRoom.self_player.card_list = {} + self._state.selectedIndex = 2 + self._clearingView = nil + end) + end + self._player_card_info[1]:ShowHuTip() + end) + + _gamectr:AddEventListener(CS_GameEvent.ZPResult2, function(...) + if self._com_haidi then + self._com_haidi:Dispose() + self._com_haidi = nil + end + self:UnmarkSelfTuoguan() + self._left_time = 0 + self:UpdateCardBox(0) + local arg = {...} + local total_result = arg[2] + local result = arg[1] + local over = arg[3] + self._clearingView = CS_ClearingView.new() + coroutine.start(function() + coroutine.wait(0.5) + self._clearingView:Show() + end) + self._clearingView:InitData(over, _room, result, total_result) + ControllerManager.ChangeController(LoddyController) + end) + + _gamectr:AddEventListener(CS_GameEvent.EventQSTip, function(...) + local arg = {...} + local data = arg[1] + local tip = data["types"] + local lit = data["tip_list"] + local htype = lit[1]["type"] + local tip_qishou + if htype == 7 then + tip_qishou = UIPackage.CreateObject("Extend_MJ_NingXiang", "pop_tip_qishou") + elseif htype == 8 then + tip_qishou = UIPackage.CreateObject("Extend_MJ_NingXiang", "pop_tip_zhongtu") + end + local tipList = tip_qishou:GetChild("list") + for i = 1, #tip do + local item = tipList:AddItemFromPool() + item:GetChild("icon").url = "ui://Extend_MJ_NingXiang/qs" .. tip[i].type + item:GetChild("num").text = tip[i].value + end + local id = lit[1].id + tip_qishou:GetChild("btn_qs").onClick:Add(function() + _gamectr:SendAction(id) + tip_qishou:Dispose() + end) + local btn_close = tip_qishou:GetChild("btn_close") + btn_close.onClick:Add(function() + _gamectr:SendAction(0) + tip_qishou:Dispose() + end) + self._view:AddChild(tip_qishou) + tip_qishou:Center() + self._com_qishou = tip_qishou + end) + + _gamectr:AddEventListener(CS_GameEvent.EvnetQSAction, function(...) + local arg = {...} + local data = arg[1] + self._popEvent = false + self:__QsHu(data) + end) + + _gamectr:AddEventListener(CS_GameEvent.EventKaiGang, function(...) + + local arg = {...} + local data = arg[1] + local outlist = arg[2] + self._popEvent = false + self:__KaiGang(data) + end) + + _gamectr:AddEventListener(CS_GameEvent.EvnetHaiDi, function() + self:__Haidi() + end) + + _gamectr:AddEventListener(CS_GameEvent.EvnetPiaoTip, function() + self:UpdateRound() + self._tex_LeftCard.text = "0" + self._state.selectedIndex = 1 + if oldGameVersion==1 then + self:__PiaoNiaoTip() + else + self:__PiaoNiaoTip1() + end + end) + + _gamectr:AddEventListener(CS_GameEvent.EvnetPiao, function(...) + local arg = {...} + local seat = arg[1] + local num = arg[2] + if num > 0 then + local head_info = self._player_info[self:GetPos(seat)] + head_info._view:GetChild("mask_piao").title = "飘分 " .. num + head_info._view:GetController("piao_niao").selectedIndex = 1 + end + if seat == _room.self_player.seat then + if self._com_piao then + self._com_piao:Dispose() + self._com_piao = nil + end + end + end) + + _gamectr:AddEventListener(CS_GameEvent.EventTingTip, function(...) + local com_tip = UIPackage.CreateObject("Main_Majiang", "Gcm_action_tips") + com_tip:GetController("hide_bg").selectedIndex = 1 + self._chipeng_tip = com_tip + + local _lit_fanzi = com_tip:GetChild("lit_fanzi") + _lit_fanzi:RemoveChildrenToPool() + + local _btn_ting = _lit_fanzi:AddItemFromPool("ui://Main_Majiang/Btn_fztip") + _btn_ting.icon = "ui://Main_Majiang/fztip_6" + _btn_ting.onClick:Set(function( ... ) + _gamectr:SendAction(1) + com_tip:Dispose() + self._chipeng_tip = nil + end) + local _btn_pass = _lit_fanzi:AddItemFromPool("ui://Main_Majiang/Btn_pass") + _btn_pass.onClick:Set(function( ... ) + _gamectr:SendAction(0) + self._chipeng_tip:Dispose() + self._chipeng_tip = nil + end) + self._view:AddChild(com_tip) + com_tip:Center() + end) + + _gamectr:AddEventListener(CS_GameEvent.EventTing, function(...) + local arg = {...} + local seat = arg[1] + local index = self:GetPos(seat) + local head_info = self._player_info[index] + head_info._view:GetController("ting").selectedIndex = 1 + local info = self._player_card_info[index] + info._player.auto_out_card = true + info:UpdateHandCard() + end) +end + +function M:UpdateRound() + -- self._view:GetChild("tex_round1").text = self._room.curren_round + -- self._view:GetChild("tex_round2").text = self._room.room_config.round + self._view:GetChild("tex_round1").text = self._room.curren_round .. " / " .. self._room.room_config.round + self._view:GetChild("tex_round3").text = self._room.room_config.round-self._room.curren_round +end + +function M:InitPlayerInfoView() + self._player_info = {} + local _player_info = self._player_info + for i = 1, self._room.room_config.people_num do + local tem = self._view:GetChild("player_info" .. i) + _player_info[i] = PlayerInfoView.new(tem,self) + tem.visible = false + end +end + +local discard_frame = 0 +function M:OutCard(card) + -- 防止同一帧内执行两次OutCard事件 + local last_discard_frame = discard_frame + discard_frame = Time.frameCount + --print("帧数:-------------------------",discard_frame, last_discard_frame, discard_frame == last_discard_frame) + if discard_frame == last_discard_frame then + return + end + local _gamectr = ControllerManager.GetController(GameController) + self._room.curren_outcard_seat = -1 + _gamectr:SendOutCard(card, function() + local info = self._player_card_info[1] + self:RemoveCursor() + info:UpdateHandCard() + + info:UpdateOutCardList(nil, card, self._cursor) + self:PlaySound(self._room.self_player.self_user.sex,tostring(card)) + self:PlayMJSound("chupai.mp3") + end) +end + +function M:__FangziTip(tip) + if self.kg_card then + self.kg_card:Dispose() + end + local _gamectr = self._gamectr + local _chipeng_tip = UIPackage.CreateObject("Main_Majiang", "Gcm_action_tips") + _chipeng_tip:GetController("hide_bg").selectedIndex = 1 + self._chipeng_tip = _chipeng_tip + local p = self._room.self_player + -- self._player_card_info[self:GetPos(p.seat)] + + local _lit_fanzi = _chipeng_tip:GetChild("lit_fanzi") + _lit_fanzi:RemoveChildrenToPool() + local _tlist = table.keys(tip.tip_map_type) + + + local tip_hu = false + local count = #_tlist + table.sort(_tlist) + local isHu = false + for k=1,#_tlist do + local td = tip.tip_map_type[_tlist[k]][1] + local url = "ui://Main_Majiang/Btn_fztip" + local weight = td.weight + if tonumber(weight) == 5 then + isHu = true + weight = 8 + url = "ui://Main_Majiang/Btn_hu" + elseif tonumber(weight) == 3 then + weight = 16 + end + local btn_t = _lit_fanzi:AddItemFromPool(url) + if url == "ui://Main_Majiang/Btn_hu" and td.card then + btn_t:GetChild("hupai").icon="ui://Main_Majiang/202_" ..td.card + btn_t:GetController("hupai").selectedIndex=1 + end + btn_t.icon = "ui://Main_Majiang/fztip_"..weight + btn_t.data = { tip, td } + btn_t.onClick:Add(self.__TipAction,self) + end + + local _btn_pass = _lit_fanzi:AddItemFromPool("ui://Main_Majiang/Btn_pass") + _btn_pass.onClick:Set(function() + if isHu then + local guo_msg = MsgWindow.new(self._root_view, "确定要点过吗?", MsgWindow.MsgMode.OkAndCancel) + guo_msg.onOk:Add(function() + _gamectr:SendAction(0) + _chipeng_tip:Dispose() + self._chipeng_tip = nil + guo_msg:Close() + end) + guo_msg:Show() + else + _gamectr:SendAction(0) + _chipeng_tip:Dispose() + self._chipeng_tip = nil + end + end) + + self._view:AddChild(_chipeng_tip) + _chipeng_tip:Center() +end + +function M:__TipAction(context) + local data = context.sender.data + local _gamectr = self._gamectr + local tip = data[1] + local td = data[2] + local list = tip.tip_map_type[td.weight] + if (#list > 1) then + self:_ChiView(list, function(id) + _gamectr:SendAction(id) + self:__CloseTip() + end) + self._chipeng_tip.visible = false + return + end + + _gamectr:SendAction(td.id) + if (self._chipeng_tip == nil) then return end + self._chipeng_tip:Dispose() + self._chipeng_tip = nil +end + +function M:_ChiView(tiplist, callback) + self._chipeng_tip.visible = false + local _pop_tip_choice = UIPackage.CreateObject("Extend_MJ_NingXiang", "Pop_tip_choice") + local list_choose1 = _pop_tip_choice:GetChild("Lst_choose") + local list_choose2 = _pop_tip_choice:GetChild("Lst_choose2") + local crossCtr = _pop_tip_choice:GetController("state") + crossCtr.selectedIndex = #tiplist == 3 and 0 or (#tiplist == 2 and 1 or (#tiplist == 4 and 2 or (#tiplist == 5 and 3 or 4))) + _pop_tip_choice:GetChild("Btn_cross").onClick:Add(function() + _pop_tip_choice:Dispose() + self._chipeng_tip.visible = true + end) + list_choose1:RemoveChildrenToPool() + list_choose2:RemoveChildrenToPool() + for i = 1, #tiplist do + local list_choose = i <= 3 and list_choose1 or list_choose2 + local item_choose = list_choose:AddItemFromPool() + item_choose:GetController("type").selectedIndex = (1 == tiplist[i].weight or 2 == tiplist[i].weight) and 1 or 0 + if tiplist[i].weight ~= 1 then + for j = 1, 4 do + item_choose:GetChild("card"..j).icon = UIPackage.GetItemURL("Main_Majiang", self:GetPrefix() .. "202_"..tiplist[i].card) + end + else + local tem = {} + table.insert(tem, tiplist[i].opcard[1]) + table.insert(tem, tiplist[i].opcard[2]) + local tcard = tiplist[i].card + table.insert(tem, tcard) + table.sort(tem, function(a, b) + return a < b + end) + item_choose:GetChild("card1").icon = UIPackage.GetItemURL("Main_Majiang", self:GetPrefix() .. "202_"..tem[1]) + item_choose:GetChild("card2").icon = UIPackage.GetItemURL("Main_Majiang", self:GetPrefix() .. "202_"..tem[2]) + item_choose:GetChild("card4").icon = UIPackage.GetItemURL("Main_Majiang", self:GetPrefix() .. "202_"..tem[3]) + local cardpos = tem[2] > tcard and 1 or (tem[2] < tcard and 4 or 2) + + item_choose:GetChild("card" .. cardpos):GetController("color").selectedIndex = 1 + end + item_choose.onClick:Add(function() + callback(tiplist[i].id) + end) + end + _pop_tip_choice.xy = Vector2((self._view.width - _pop_tip_choice.width)/2, (self._view.height - _pop_tip_choice.height)/2) + self._view:AddChild(_pop_tip_choice) + self._pop_tip_choice = _pop_tip_choice +end + +function M:__QsHu(data) + local seat = data.seat + if seat == DataManager.CurrenRoom.self_player.seat then + if self._com_qishou then + self._com_qishou:Dispose() + self._com_qishou = nil + end + end + if data.niao and #data.niao > 0 then + local shaizi = UIPackage.CreateObject("Extend_MJ_NingXiang", "Ani_shaizi") + local dice1 = data.niao[1].card + local dice2 = data.niao[2].card + shaizi:GetChild("shaizi1").icon = UIPackage.GetItemURL("Extend_MJ_NingXiang", "shaizi" .. dice1) + shaizi:GetChild("shaizi2").icon = UIPackage.GetItemURL("Extend_MJ_NingXiang", "shaizi" .. dice2) + self._view:AddChild(shaizi) + shaizi:Center() + + coroutine.start(function() + -- coroutine.wait(0.5) + -- shaizi:GetController("c1").selectedIndex = 1 + coroutine.wait(1.5) + local xy = shaizi.xy + local head_info = self._player_info[self:GetPos(seat)] + local target_xy = self._view:GlobalToLocal(head_info._view:LocalToGlobal(head_info:GetHeadCenter())) + local diff_x = (target_xy.x - 0.5 * shaizi.width) - xy.x + local diff_y = (target_xy.y - 0.5 * shaizi.height) - xy.y + self._tween_shaizi = TweenUtils.TweenFloat(0,1,1,function(value) + shaizi.x = xy.x + diff_x * value + shaizi.y = xy.y + diff_y * value + end) + coroutine.wait(1.2) + shaizi:Dispose() + end) + end + local qs_data = data.data + local allShowCards = {} + local ShowCardsNum = {} + local types = {} + local showAllCards = false + local qs_type = data.type -- 6是起手胡 8是中途 + for i = 1, #qs_data do + local cards = {} + local opcard =qs_data[i].opcard + local qtype = qs_data[i].type + if not types[qtype] then types[qtype] = qs_data[i].value end + if qtype == 23 or qtype == 24 or qtype == 27 then + showAllCards = true + allShowCards = opcard + end + if not showAllCards then + for j = 1, #opcard do + local card = opcard[j] + if cards[card] then + cards[card] = cards[card] + 1 + else + cards[card] = 1 + end + end + for k,v in pairs(cards) do + local card = k + if ShowCardsNum[card] then + if ShowCardsNum[card] < cards[card] then + ShowCardsNum[card] = cards[card] + end + else + ShowCardsNum[card] = cards[card] + end + end + end + end + if not showAllCards then + for i,v in pairs(ShowCardsNum) do + for j = 1, v do + table.insert(allShowCards, i) + end + end + else + + end + local info = self._player_card_info[self:GetPos(seat)] + local pNode = info._mask_liangpai + self.QSHList={} + coroutine.start(function() + -- 获取父节点的中心坐标,作为基准点 + local centerX = pNode.width * 0.5 + local centerY = pNode.height * 0.5 + + -- 计算所有提示框的总宽度,以便整体居中显示 + local totalWidth = 0 + local tipsTemp = {} -- 临时存储创建的对象,用于第二次遍历设置位置 + + -- 第一次遍历:创建对象并计算总宽度 + for i, v in pairs(types) do + local show_tip = UIPackage.CreateObject("Extend_MJ_NingXiang", "Tip_qishou") + show_tip:GetChild("icon").url = "ui://Extend_MJ_NingXiang/qs" .. i + show_tip:GetChild("num").text = v + + -- 先添加到父节点,确保 width/height 可用(如果UI包中已定义大小则可直接用,否则需添加后获取) + pNode:AddChild(show_tip) + + table.insert(tipsTemp, {obj = show_tip, type = i, value = v}) + totalWidth = totalWidth + show_tip.width + end + + -- 定义间距 + local spacing = 10 -- 两个提示框之间的间隙 + + -- 计算起始 X 坐标,使整排提示框在父节点中水平居中 + -- 起始X = 中心X - (总宽度 + 总间距) / 2 + local totalSpacing = spacing * (#tipsTemp - 1) + local startX = centerX - (totalWidth + totalSpacing) * 0.5 + + local currentX = startX + + -- 第二次遍历:设置每个提示框的具体位置 + for k, data in ipairs(tipsTemp) do + local show_tip = data.obj + + -- 设置 Y 轴位置:保持在父节点垂直居中 (或者你可以固定一个值,如 centerY - show_tip.height * 0.5) + show_tip.y = centerY - show_tip.height * 0.5 + + -- 设置 X 轴位置:从 startX 开始,依次累加宽度和间距 + show_tip.x = currentX + + -- 更新下一个对象的 X 坐标 + currentX = currentX + show_tip.width + spacing + + -- 加入销毁列表 + table.insert(self.QSHList, show_tip) + end + end) + table.sort(allShowCards, ViewUtil.HandCardSort) + info:UpdateHandCard(false, false, allShowCards) + coroutine.start(function() + coroutine.wait(0.5) + self._popEvent = true + coroutine.wait(4) + self._room.room_config.banyiquan=true + if not (self._room.room_config.banyiquan and qs_type == 6) then + info:UpdateHandCard(false, false, {}) + end + --self._popEvent = true + end) +end + + +function M:ClearQSHTips() + if self.QSHList and #self.QSHList>0 then + for i=1,#self.QSHList do + self.QSHList[i]:Dispose() + end + self.QSHList=nil + end +end + + +function M:__KaiGang(data) + local seat = data["seat"] + local kg_info = data["info"] + local dice1 = kg_info["diceNum1"] + local dice2 = kg_info["diceNum2"] + local cardList = kg_info["cardList"] + local info = self._player_card_info[self:GetPos(seat)] + local p = self._room:GetPlayerBySeat(seat) + local card = p.outcard_list[#p.outcard_list] + + local shaizi = UIPackage.CreateObject("Extend_MJ_NingXiang", "Ani_shaizi") + shaizi:GetChild("shaizi1").icon = UIPackage.GetItemURL("Extend_MJ_NingXiang", "shaizi" .. dice1) + shaizi:GetChild("shaizi2").icon = UIPackage.GetItemURL("Extend_MJ_NingXiang", "shaizi" .. dice2) + self._view:AddChild(shaizi) + shaizi:Center() + + if self.kg_card then self.kg_card:Dispose() end + self.kg_card = UIPackage.CreateObject("Extend_MJ_NingXiang", "kai_gang") + local gang_list = self.kg_card:GetChild("list") + gang_list:RemoveChildrenToPool() + for i = 1, #cardList do + local item = gang_list:AddItemFromPool() + item.icon = UIPackage.GetItemURL("Main_Majiang", self:GetPrefix() .. "201_" .. cardList[i]) + end + if p.seat == self._room.self_player.seat then + if not info._player then info._player = {} end + info._player.auto_out_card = true + info:UpdateHandCard() + end + coroutine.start(function() + -- coroutine.wait(0.5) + -- shaizi:GetController("c1").selectedIndex = 1 + coroutine.wait(1.5) + local xy = shaizi.xy + local head_info = self._player_info[self:GetPos(seat)] + local target_xy = self._view:GlobalToLocal(head_info._view:LocalToGlobal(head_info:GetHeadCenter())) + local diff_x = (target_xy.x - 0.5 * shaizi.width) - xy.x + local diff_y = (target_xy.y - 0.5 * shaizi.height) - xy.y + self._tween_shaizi = TweenUtils.TweenFloat(0,1,1,function(value) + shaizi.x = xy.x + diff_x * value + shaizi.y = xy.y + diff_y * value + end) + coroutine.wait(1.2) + shaizi:Dispose() + + self._view:AddChild(self.kg_card) + self.kg_card:Center() + info:UpdateOutCardList(nil,card, self._cursor) + self._view:GetChild("remaining_card").text = string.format("剩余%d张牌",self._room.remain_cards) + + coroutine.wait(1) + self._popEvent = true + end) +end + +function M:__Haidi() + -- if DataManager.CurrenRoom.self_player.entrust then return end + local item = UIPackage.CreateObject("Extend_MJ_NingXiang", "hai_di") + local btn_confirm = item:GetChild("btn_confirm") + local btn_cancel = item:GetChild("btn_cancel") + local _gamectr = self._gamectr + btn_confirm.onClick:Add(function() + _gamectr:SendAction(1) + item:Dispose() + end) + btn_cancel.onClick:Add(function() + _gamectr:SendAction(0) + item:Dispose() + end) + self._view:AddChild(item) + item:Center() + self._com_haidi = item +end + + +function M:__PiaoNiaoTip() + local obj_piao = UIPackage.CreateObject("Main_Majiang", "panel_piao_niao") + self._view:AddChild(obj_piao) + obj_piao.x = (self._view.width - obj_piao.width) * 0.5 + obj_piao.y = self._view.height * 0.6 + local piaoState=obj_piao:GetController('piao') + piaoState.selectedIndex=1 + for i = 1, 4 do + obj_piao:GetChild("btn_" .. i).onClick:Add(function() + self._gamectr:SendAction(i - 1) + obj_piao:Dispose() + end) + end + self._com_piao = obj_piao +end + + +function M:__PiaoNiaoTip1() + local obj_piao = UIPackage.CreateObject("Main_Majiang", "panel_piao_niao") + self._view:AddChild(obj_piao) + obj_piao.x = (self._view.width - obj_piao.width) * 0.5 + obj_piao.y = self._view.height * 0.6 + local piaoState=obj_piao:GetController('piao') + + local tconfig=DataManager.CurrenRoom.room_config.config + + + + local piaoList={} + + for i = 1, 4 do + local piaoT=obj_piao:GetChild("btn_" .. i) + table.insert(piaoList,piaoT) + piaoT.onClick:Add(function() + self._gamectr:SendAction(i - 1) + obj_piao:Dispose() + end) + + end + self._com_piao = obj_piao + + + + if tconfig.piao_niao<2 then + for i=1,#piaoList do + piaoList[i].visible=true + end + piaoState.selectedIndex=1 + else + piaoList[1].visible=false + for i=2,#piaoList do + piaoList[i].visible=tconfig["piao"..(i-1)] + end + piaoState.selectedIndex=2 + end + +end + +function M:OnFangziAction(...) + self._popEvent = false + if self.kg_card then + self.kg_card:Dispose() + end + self:__CloseTip() + local arg = {...} + local _player_card_info = self._player_card_info + local fz = arg[1] + local player = arg[2] + local index = arg[3] + + local info = _player_card_info[self:GetPos(player.seat)] + local pNode = info._mask_liangpai + local effect = UIPackage.CreateObject("Extend_MJ_NingXiang", "FzEffect") + + local fangzi = "" + local fz_sound = "" + if fz.type == FZType.Peng then + fangzi = "碰" + fz_sound = "peng"..math.random(1, 3) + elseif fz.type == FZType.Chi then + fangzi = "吃" + fz_sound = "chi"..math.random(1, 3) + else + if fz.opengang then + fangzi = "杠" + fz_sound = "gang"..math.random(1, 2) + else + fangzi = "补" + fz_sound = "buzhang" + end + end + self:PlaySound(player.self_user.sex,fz_sound) + effect:GetChild("word1").icon = UIPackage.GetItemURL("Main_Majiang", fangzi) + effect:GetChild("word2").icon = UIPackage.GetItemURL("Main_Majiang", fangzi) + + effect.touchable = false + effect:GetTransition("t2"):Play() + pNode:AddChild(effect) + + coroutine.start(function() + coroutine.wait(0.3) + self._popEvent = true + end) + + coroutine.start(function() + coroutine.wait(1.8) + effect:Dispose() + end) + + self:RemoveCursor() + if (player.seat ~= fz.from_seat) then + local fs_info = _player_card_info[self:GetPos(fz.from_seat)] + fs_info:UpdateOutCardList() + end + info:UpdateFzList(fz, index, true) + + local getcard = fz.type == FZType.Peng or fz.type == FZType.Chi + info:UpdateHandCard(getcard) + + self:PlayMJSound("fangzi.mp3") + end + +function M:RunNiao(list, start_seat) + local _room = self._room + --local _niao_View = self._niao_View + self._niao_View = UIPackage.CreateObject("Extend_MJ_NingXiang","Panel_Birds") + self._view:AddChild(self._niao_View) + self._niao_View:Center() + local _niao_View = self._niao_View + local list_niao_card = self._niao_View:GetChild("Lst_birds") + list_niao_card:RemoveChildrenToPool() + for i = 1, #list do + --添加背面的麻將 + local item = list_niao_card:AddItemFromPool() + item.icon = UIPackage.GetItemURL("Main_Majiang", "202_00") + item:GetChild("tex_score").text = "+" .. list[i].score + end + for i = 1, #list do + --顯示正面 + local item = list_niao_card:GetChildAt(i - 1) + local card = list[i].card + -- coroutine.wait(0.3) + item:GetTransition("appear"):Play() + item.icon = UIPackage.GetItemURL("Main_Majiang", self:GetPrefix() .. "201_"..card) + if list[i].score > 0 then item:GetController("bg").selectedIndex = 1 end + end + coroutine.start(function() + coroutine.wait(1.5) + _niao_View:Dispose() + self._popEvent = true + end) +end + +function M:ReloadRoom(bskip) + local room = self._room + + if bskip == nil or bskip == false then + if not room.playing then + self._state.selectedIndex = 2 + else + self._state.selectedIndex = 1 + self._room._reload_flag = true + end + + end + + if room.kg_card and #room.kg_card ~= 0 then + self.kg_card = UIPackage.CreateObject("Extend_MJ_NingXiang", "kai_gang") + for i = 1, #room.kg_card do + local item = self.kg_card:GetChild("list"):AddItemFromPool() + item.icon = UIPackage.GetItemURL("Main_Majiang", self:GetPrefix() .. "201_" .. room.kg_card[i]) + end + self._view:AddChild(self.kg_card) + self.kg_card:Center() + end + for i = 1, #room.player_list do + local p = room.player_list[i] + local info = self._player_card_info[self:GetPos(p.seat)] + local head_info = self._player_info[self:GetPos(p.seat)] + head_info:UpdateScore() + head_info._view:GetChild('zhanji').visible = true + local num = p.total_hp or 0 + if num > 0 then + head_info._view:GetController('text_color').selectedIndex = 0 + head_info._view:GetChild('text_jifen').text = "+" .. d2ad(num) + else + head_info._view:GetController('text_color').selectedIndex = 1 + head_info._view:GetChild('text_jifen').text = d2ad(num) + end + + if p.win_count~=nil and p.win_count >= 3 then + head_info._view:GetController("three_win").selectedIndex = 1 + head_info._view:GetChild("com_three_win"):GetChild("tex_win").text = p.win_count + end + if p.ting then + head_info._view:GetController("ting").selectedIndex = 1 + end + for i = 1, #p.fz_list do + info:UpdateFzList(p.fz_list[i], -1) + end + if p == room.self_player and p.auto_play then + if not info._player then info._player = {} end + info._player.auto_out_card = true + end + info:UpdateHandCard() + if p.seat == room.last_outcard_seat then + local card = p.outcard_list[#p.outcard_list] + info:UpdateOutCardList(nil,card, self._cursor) + elseif p.seat == room.curren_outcard_seat then + info:UpdateHandCard(true) + info:UpdateOutCardList() + else + info:UpdateOutCardList() + end + if p.seat == room.banker_seat then + local head = self._player_info[self:GetPos(p.seat)] + head:MarkBank(true) + end + + if bskip == nil or bskip == false then + if p.ready and room.playing == false then + self._player_info[self:GetPos(p.seat)]:Ready(true) + end + end + if p.piao_niao~=nil and p.piao_niao > 0 then + local head_info = self._player_info[self:GetPos(p.seat)] + head_info._view:GetChild("mask_piao").title = "飘分 " .. p.piao_niao + head_info._view:GetController("piao_niao").selectedIndex = 1 + end + end + + if bskip == nil or bskip == false then + self:UpdateCardBox(self:GetPos(room.curren_outcard_seat)) + self._tex_LeftCard.text = room.left_count + self:UpdateRound() + end + local me = room.self_player + if room.curren_outcard_seat == me.seat and me.auto_play then + self:OutCard(me.draw_card) + me.draw_card = nil + end +end + +function M:GetPos(seat) + local pos = 0 + if seat ~= 0 then + pos = ViewUtil.GetPos(self._room.self_player.seat, seat, self._room.room_config.people_num) + end + return pos +end + +function M:PlaySound(sex,path) + MJMainView.PlaySound(self, "NingXiang_MJ", sex, path) +end + +function M:PlayerChangeLineState() +end + +function M:UpdateCardBox(seat) + local index = seat + local people_num = self._room.room_config.people_num + if people_num == 2 and seat == 2 then + index = 3 + elseif people_num == 3 and seat == 3 then + index = 4 + end + self._ctr_cardbox.selectedIndex = index +end + +function M:__CloseTip() + if (self._chipeng_tip) then + self._chipeng_tip:Dispose() + self._chipeng_tip = nil + end + if (self._pop_tip_choice) then + self._pop_tip_choice:Dispose() + self._pop_tip_choice = nil + end +end + +-- 托管时关闭一些提示窗口,如起手胡、吃碰提示、海底,由扩展实现 +function M:closeTipOnTuoguan() + self:__CloseTip() + if self._com_haidi then + self._com_haidi:Dispose() + self._com_haidi = nil + end + if self._com_qishou then + self._com_qishou:Dispose() + self._com_qishou = nil + end + -- if self._com_piao then + -- self._com_piao:Dispose() + -- self._com_piao = nil + -- end +end + +function M:Destroy() + MJMainView.Destroy(self) + UIPackage.RemovePackage("extend/majiang/ningxiang/ui/Extend_MJ_NingXiang") + if self._tween_shaizi then + TweenUtils.Kill(self._tween_shaizi) + end +end + +return M \ No newline at end of file diff --git a/lua_probject/extend_project/extend/majiang/ningxiang/EXPlayBackView.lua b/lua_probject/extend_project/extend/majiang/ningxiang/EXPlayBackView.lua new file mode 100644 index 00000000..f55aaf5f --- /dev/null +++ b/lua_probject/extend_project/extend/majiang/ningxiang/EXPlayBackView.lua @@ -0,0 +1,395 @@ +local MJPlayBackView = require("main.majiang.MJPlayBackView") +local EXRoomConfig = import(".EXRoomConfig") +local PlayerInfoView = require("Game.View.PlayerInfoView") +local EXClearingView = import(".EXClearingView") + +local Record_Event = import(".RecordEvent") + + +local M = {} + +--- Create a new +function M.new() + setmetatable(M,{__index = MJPlayBackView}) + local self = setmetatable({}, {__index = M}) + self.class = "CS_PlayBackView" + self:init() + + return self +end + + +function M:InitView(url) + local room = self._room + UIPackage.AddPackage("extend/majiang/ningxiang/ui/Extend_MJ_NingXiang") + MJPlayBackView.InitView(self,"ui://Main_Majiang/Main_"..room.room_config.people_num) + local _cardbox = self._view:GetChild("cardbox") + --self._view:GetChild("panel_record"):GetChild("btn_LastStep").enabled = false + self._ctr_cardbox = _cardbox:GetController("c1") + self._tex_round = self._view:GetChild("tex_round") + self._tex_LeftCard = self._view:GetChild("remaining_card") + self._anchor = self._view:GetChild("mask_tips") + self._eventmap = {} + + self._cmdmap = {} + self._cmdmap[Record_Event.Evt_QiShou] = self.CmdQiShou + self._cmdmap[Record_Event.Evt_GetCard] = self.CmdGetCard + self._cmdmap[Record_Event.Evt_OutCard] = self.CmdOutCard + self._cmdmap[Record_Event.Evt_Action] = self.CmdAction + self._cmdmap[Record_Event.Evt_Win] = self.CmdWin + self._cmdmap[Record_Event.Evt_Niao] = self.CmdNiao + self._cmdmap[Record_Event.Evt_KaiGang] = self.CmdKaiGang + self._cmdmap[Record_Event.Evt_Piao] = self.CmdPiao + self._cmdmap[Record_Event.Evt_Result] = self.CmdResult +end + +function M:FillRoomData(data) + MJPlayBackView.FillRoomData(self) + local room = self._room + -- if room.room_config.people_num ~= 4 then + -- for i = 1, 4 do + -- self._view:GetChild("player_info" .. i).visible = false + -- end + -- local num + -- for i = 1, room.room_config.people_num do + -- if room.room_config.people_num == 3 and i == 3 then + -- num = 4 + -- elseif room.room_config.people_num == 2 and i == 2 then + -- num = 3 + -- else + -- num = i + -- end + -- local tem= self._view:GetChild("player_card_info" .. num) + -- self._player_card_info[i] = self:NewMJPlayerCardInfoView(tem, i) + + -- local tem = self._view:GetChild("player_info" .. num) + -- self._player_info[i] = PlayerInfoView.new(tem, self) + -- end + -- for i = 1,#room.player_list do + -- local p = room.player_list[i] + -- local index = self:GetPos(p.seat) + -- local card_info = self._player_card_info[index] + -- local info = self._player_info[index] + -- card_info:SetPlayer(p) + -- card_info:FillData() + -- info:FillData(p) + -- info._view.visible = true + -- end + -- end + + if self._win_pic then self._win_pic:Dispose() end + if self._niao then self._niao:Dispose() end + self._currentStep = 0 + local room = DataManager.CurrenRoom + local _player_card_info = self._player_card_info + local left_count = data.info.left_card + self:UpdateLeftCard(left_count) + local round = data.info.round + self:UpdateRound(round) + local roominfo_panel = self._view:GetChild("roominfo_panel1") + roominfo_panel:GetChild("tex_roomid").text = room.room_id + roominfo_panel:GetChild("tex_gametype").text = room.room_config:GetGameName() + + for i = 1, #room.player_list do + local p = room.player_list[i] + local card_info = _player_card_info[self:GetPos(p.seat)] + card_info:Clear() + table.sort(p.card_list, ViewUtil.HandCardSort) + card_info:UpdateHandCard(false, true) + self._player_info[i]._view:GetController("piao_niao").selectedIndex = 0 + end + + self:GenerateAllStepData(data) + self:UpdateStep(1) + -- self:ShowStep(0) +end + +function M:ShowStep(index) + local step = self._step[index + 1] + self:UpdateLeftCard(step.left_card) + --self._ctr_cardbox.selectedIndex = step.current_out_seat + self:UpdateCardBox(step.current_out_seat) + self:UpdateStep(index + 1) + if step.cmd ~= Record_Event.Evt_OutCard then + self:RemoveCursor() + end + for i = 1, #step.player_card_data do + local p = self._room:GetPlayerBySeat(i) + local info = self._player_card_info[self:GetPos(i)] + p.card_list = step.player_card_data[i].card_list + p.outcard_list = step.player_card_data[i].outcard_list + p.fz_list = step.player_card_data[i].fz_list + p.hand_left_count = #p.card_list + info:Clear() + info:ResetFzList() + p.piao_niao = step.player_card_data[i].piao_niao + local head_info = self._player_info[self:GetPos(i)] + if p.piao_niao and p.piao_niao > 0 then + head_info._view:GetChild("mask_piao").title = "飘分 " .. p.piao_niao + head_info._view:GetController("piao_niao").selectedIndex = 1 + else + head_info._view:GetController("piao_niao").selectedIndex = 0 + end + if step.cmd == Record_Event.Evt_OutCard and i == step.last_out_seat then + local card = p.outcard_list[#p.outcard_list] + info:UpdateOutCardList(nil, nil, self._cursor) + else + info:UpdateOutCardList() + end + if step.cmd == Record_Event.Evt_GetCard and p.seat == step.current_out_seat then + info:UpdateHandCard(true, true) + else + info:UpdateHandCard(false, true) + end + end + if step.cmd == Record_Event.Evt_Win then + self._win_pic = UIPackage.CreateObjectFromURL("ui://Main_Majiang/胡") + local info = self._player_card_info[self:GetPos(step.win)] + info._mask_liangpai:AddChild(self._win_pic) + self._win_pic:Center() + else + if self._win_pic then + self._win_pic:Dispose() + end + end + if step.cmd == Record_Event.Evt_Niao then + local niao_list = step.niao + self._niao = UIPackage.CreateObjectFromURL("ui://Extend_MJ_NingXiang/Panel_Birds") + local list = self._niao:GetChild("Lst_birds") + list:RemoveChildrenToPool() + for i = 1, #niao_list do + local item = list:AddItemFromPool() + item.icon = UIPackage.GetItemURL("Main_Majiang", self:GetPrefix() .."201_"..niao_list[i].card) + if niao_list[i].score > 0 then + item:GetController("bg").selectedIndex = 2 + end + end + self._view:AddChild(self._niao) + self._view:AddChild(self._view:GetChild("panel_record")) + self._niao:Center() + elseif step.cmd == Record_Event.Evt_KaiGang then + self._kaigang = UIPackage.CreateObject("Extend_MJ_NingXiang", "kai_gang") + local cards = step.card + local gang_list = self._kaigang:GetChild("list") + gang_list:RemoveChildrenToPool() + for i = 1, #cards do + local item = gang_list:AddItemFromPool() + item.icon = UIPackage.GetItemURL("Main_Majiang", self:GetPrefix() .."201_" .. cards[i]) + end + self._view:AddChild(self._kaigang) + self._kaigang:Center() + elseif step.cmd == Record_Event.Evt_QiShou then + local data = step.qs_data + self._QS = UIPackage.CreateObject("Extend_MJ_NingXiang", "showAll") + local list = self._QS:GetChild("n0") + list:RemoveChildrenToPool() + for i = 1, #data do + local item = list:AddItemFromPool() + item:GetChild("icon").url = "ui://Extend_MJ_NingXiang/qs" .. data[i].type + item:GetChild("num").text = data[i].value + end + local info = self._player_card_info[self:GetPos(step.qs_seat)] + info._mask_liangpai:AddChild(self._QS) + self._QS:Center() + else + -- 因为 开杠 和 鸟 不会连续出现,不然此处需要分开判断 + if self._niao then + self._niao:Dispose() + end + if self._kaigang then + self._kaigang:Dispose() + end + if self._QS then + self._QS:Dispose() + end + end + if step.cmd == Record_Event.Evt_Result then + if not self.result then + self.result = EXClearingView.new(self._root_view, true) + self.result:InitData(0, self._room, step.result_data) + self.result._view.x = (GRoot.inst.width - self.result._view.width) * -0.5 + self.result._view.width = GRoot.inst.width + self.result._view.height = GRoot.inst.height + self.result._view:GetChild("btn_confirm").visible = false + self._anchor:AddChild(self.result._view) + self.result._view.x = self._anchor.x * -1 + self.result._view.y = self._anchor.y * -1 + else + self.result._view.visible = true + end + -- self.result._view:Center() + else + if self.result then + self.result._view.visible = false + end + end +end + +function M:GenerateAllStepData(data) + local cmdList = self.cmdList + self._step = {} + local step = {} + local info = data.info + step.cmd = "" + step.left_card = info.left_card + step.last_out_seat = 0 + step.current_out_seat = 1 + step.win = 0 + step.niao = 0 + + step.player_card_data = {} + for i = 1, #self._room.player_list do + local p = info.playerData[i] + local u = {} + u.seat = p.seat + u.card_list = p.hand_card + u.hand_left_count = #u.card_list + u.fz_list = {} + u.outcard_list = {} + u.piao_niao = p.piao_niao + step.player_card_data[u.seat] = u + end + self._step[#self._step + 1] = step + + for i = 1, #cmdList do + local tem = cmdList[i] + self._cmdmap[tem.cmd](self, tem, i) + end +end + +function M:CmdQiShou(cmd, index) + local data = self:CopyLastStep(index) + data.cmd = cmd.cmd + data.qs_seat = cmd.seat + data.qs_data = cmd.data.data + -- data.qs_card = cmd.data.card +end + +function M:CmdGetCard(cmd, index) + local data = self:CopyLastStep(index) + data.cmd = cmd.cmd + data.current_out_seat = cmd.seat + data.left_card = cmd.data.left_count + local u = data.player_card_data[cmd.seat] + u.card_list[#u.card_list + 1] = cmd.data.card +end + +function M:CmdOutCard(cmd, index) + local data = self:CopyLastStep(index) + data.cmd = cmd.cmd + data.last_out_seat = cmd.seat + local u = data.player_card_data[cmd.seat] + list_remove(u.card_list, cmd.data.card) + table.sort(u.card_list, ViewUtil.HandCardSort) + u.outcard_list[#u.outcard_list + 1] = cmd.data.card +end + +function M:CmdAction(cmd, index) + local data = self:CopyLastStep(index) + data.cmd = cmd.cmd + data.last_out_seat = 0 + data.current_out_seat = cmd.seat + local fz = {} + fz.type = cmd.data.type + fz.card = cmd.data.card + fz.opcard = cmd.data.opcard + fz.kaigang = cmd.data.opengang + local u = data.player_card_data[cmd.seat] + for i = 1, #fz.opcard do + list_remove(u.card_list, fz.opcard[i]) + end + + if fz.type == 1 then + fz.type = FZType.Chi + fz.opcard[#fz.opcard + 1] = fz.card + elseif fz.type ==2 then + fz.type = FZType.Peng + elseif fz.type == 3 or fz.type == 4 then + if #fz.opcard == 1 then + fz.type = FZType.Gang_Peng + elseif #fz.opcard == 3 then + fz.type = FZType.Gang + elseif #fz.opcard == 4 then + fz.type = FZType.Gang_An + end + end + + local uf = data.player_card_data[cmd.data.from_seat] + if fz.type ~= FZType.Gang_An and fz.type ~= FZType.Gang_Peng then + table.remove(uf.outcard_list, #uf.outcard_list) + end + if fz.type ~= FZType.Gang_Peng then + u.fz_list[#u.fz_list + 1] = fz + else + for i = 1, #u.fz_list do + if u.fz_list[i].type == FZType.Peng and u.fz_list[i].card == fz.card then + u.fz_list[i].type = FZType.Gang_Peng + end + end + end +end + +function M:CmdKaiGang(cmd, index) + local data = self:CopyLastStep(index) + data.cmd = cmd.cmd + data.left_card = cmd.data.left_count + data.card = cmd.data.info.cardList +end + +function M:CmdWin(cmd, index) + local data = self:CopyLastStep(index) + data.cmd = cmd.cmd + data.win = cmd.seat +end + +function M:CmdNiao(cmd, index) + local data = self:CopyLastStep(index) + data.cmd = cmd.cmd + data.niao = cmd.data.niao +end + +function M:CmdPiao(cmd, index) + local data = self:CopyLastStep(index) + data.cmd = cmd.cmd + data.player_card_data[cmd.seat].piao_niao = cmd.data.num +end + +function M:CmdResult(cmd, index) + local data = self:CopyLastStep(index) + data.cmd = cmd.cmd + data.result_data = cmd.data +end + +function M:CopyLastStep(index) + local step = {} + local last_step = self._step[index] + step = membe_deep_clone(last_step) + self._step[#self._step + 1] = step + step.result_data = nil + return step +end + +function M:UpdateLeftCard(num) + self._tex_LeftCard.text = "剩余 "..num.." 张牌" +end + +function M:UpdateCardBox(seat) + local index = seat + local people_num = self._room.room_config.people_num + if people_num == 2 and seat == 2 then + index = 3 + elseif people_num == 3 and seat == 3 then + index = 4 + end + self._ctr_cardbox.selectedIndex = index +end + +function M:UpdateRound(round) + self._tex_round.text = "第 "..round.."/"..self._room.room_config.round.." 局" +end + +function M:UpdateStep(step) + self._record:GetChild("tex_step").text = "第 " .. step .. " / " .. #self._step .. "步" +end + +return M \ No newline at end of file diff --git a/lua_probject/extend_project/extend/majiang/ningxiang/EXPlayer.lua b/lua_probject/extend_project/extend/majiang/ningxiang/EXPlayer.lua new file mode 100644 index 00000000..87d2aa37 --- /dev/null +++ b/lua_probject/extend_project/extend/majiang/ningxiang/EXPlayer.lua @@ -0,0 +1,38 @@ + + +local EXPlayer = { + auto, + -- 手牌列表 + card_list = nil, + -- 剩余牌数 + hand_left_count = 0, + -- 出牌列表 + outcard_list = nil, + -- 牌组列表 + fz_list = nil, + + win_count = 0 +} + +local M = EXPlayer + +--- Create a new EXPlayer +function M.new() + setmetatable(M,{__index = Player}) + local self = setmetatable({}, {__index = M}) + self.card_list = {} + self.outcard_list = {} + self.fz_list = {} + return self +end + +-- 清理玩家数据 +function M:Clear() + Player.Clear(self) + self.card_list = {} + self.outcard_list = {} + self.fz_list = {} + self.hand_left_count = 0 +end + +return M \ No newline at end of file diff --git a/lua_probject/extend_project/extend/majiang/ningxiang/EXPlayerInfoView.lua b/lua_probject/extend_project/extend/majiang/ningxiang/EXPlayerInfoView.lua new file mode 100644 index 00000000..f8a5fd69 --- /dev/null +++ b/lua_probject/extend_project/extend/majiang/ningxiang/EXPlayerInfoView.lua @@ -0,0 +1,76 @@ +local PlayerInfoView = require("Game.View.PlayerInfoView") + +local M = {} + +function M.new(view, mainView) + setmetatable(M, {__index = PlayerInfoView}) + local self = setmetatable({}, {__index = M}) + self._view = view + self._main_view = mainView + self:init() + return self +end + +function M:init() + PlayerInfoView.init(self) + self._tex_score = self._view:GetChild("info"):GetChild("tex_score1") + self._tex_score2 = self._view:GetChild("info"):GetChild("tex_score2") + self._ct_score = self._view:GetChild("info"):GetController("score") +end + +function M:ShowInteraction(type,str) + if type == 3 then + Voice.DownLoad(str, function(clip) + if (clip ) then + self:ShowMaskVoice(clip.length) + GameApplication.Instance:PlayVoice(clip) + end + end) + elseif type == 4 then + self:SetChat(str) + elseif type == 2 then + local chat_index = tonumber(str) + self._main_view:PlayChatSound(self._player.self_user.sex,chat_index) + local language, index = self._main_view:GetChatMsgLanguage(chat_index) + self:SetChat(self._main_view.Fix_Msg_Chat[index]) + elseif type == 1 then + self:SetBiaoqing("ui://Chat/"..str) + end +end + +function M:UpdateRemainCard(card_num, hide) + if hide then + self._view:GetController("show_remain").selectedIndex = 0 + else + self._view:GetController("show_remain").selectedIndex = 1 + end + self._view:GetChild("com_remain"):GetChild("tex_remain").text = card_num +end + +function M:FillData(player) + PlayerInfoView.FillData(self, player) + self:UpdateScore(player.total_score) +end + +function M:UpdateScore() + local score = self._player.total_score + local room = DataManager.CurrenRoom + if room:checkHpNonnegative() then + score = d2ad(self._player.cur_hp) + end + if not score then + score = 0 + end + if score < 0 then + self._ct_score.selectedIndex = 1 + self._tex_score2.text = score + else + self._ct_score.selectedIndex = 0 + if not room:checkHpNonnegative() then + score = "+" .. score + end + self._tex_score.text = score + end +end + +return M diff --git a/lua_probject/extend_project/extend/majiang/ningxiang/EXRoomConfig.lua b/lua_probject/extend_project/extend/majiang/ningxiang/EXRoomConfig.lua new file mode 100644 index 00000000..c160d17f --- /dev/null +++ b/lua_probject/extend_project/extend/majiang/ningxiang/EXRoomConfig.lua @@ -0,0 +1,163 @@ + + + +--- +local M = {} + + +--- Create a new RoomConfig +function M.new(config) + setmetatable(M,{__index = RoomConfig}) + local self = setmetatable({}, {__index = M}) + RoomConfig.init(self,config) + self.class = "CS_RoomConfig" + self.round = config["times"] + self.config=config + self.zhuangxian = config["zhuangxian"] + -- self.piaofen = config["piaofen"] + self.zimo = config["zimo"] + self.liuliushun = config["liuliushun"] + self.queyise = config["queyise"] + self.banbanhu = config["banbanhu"] + self.dasixi = config["dasixi"] + self.jiejiegao = config["jiejiegao"] + self.santong = config["santong"] + self.yizhihua = config["yizhihua"] + self.zhongtusixi = config["zhongtusixi"] + self.zhongtuliuliushun = config["zhongtuliuliushun"] + + self.niao_type = config["niao_type"] + self.niao = config["niao"] + self.piao_niao = config["piao_niao"] + self.two_pair = config["two_pair"] + self.no_jiang = config["no_jiang"] + self.four_win = config["four_win"] + self.native_hu = config["native_hu"] + self.queyimen = config["queyimen"] + self.fengding = config["fengding"] + self.banyiquan = config["banyiquan"] + self.menqing = config["menqing"] + self.isHidden = config.isHidden + + return self +end + +function M:GetDes(sp) + sp = sp or " " + local str = self.round and self.round .. "局" .. sp or "" + str = str .. RoomConfig.GetDes(self, sp) + + if (self.zhuangxian) then + str = str .. "庄闲(算分)" + str = str .. sp + end + + if (self.zimo) then + str = str .. "自摸胡" + else + str = str .. "点炮胡" + end + str = str .. sp + + if self.fengding then + str = str .. "封顶" .. sp + end + + if self.banyiquan then + str = str .. "起手胡板一圈" .. sp + end + + if (self.liuliushun) then + str = str .. "六六顺" + str = str .. sp + end + + if (self.queyise) then + str = str .. "缺一色" + str = str .. sp + end + + if (self.banbanhu) then + str = str .. "板板胡" + str = str .. sp + end + + if (self.dasixi) then + str = str .. "大四喜" + str = str .. sp + end + + if (self.jiejiegao) then + str = str .. "节节高" + str = str .. sp + end + + if (self.santong) then + str = str .. "三同" + str = str .. sp + end + + if (self.yizhihua) then + str = str .. "一枝花" + str = str .. sp + end + + if (self.zhongtusixi) then + str = str .. "中途四喜" + str = str .. sp + end + + if (self.zhongtuliuliushun) then + str = str .. "中途六六顺" + str = str .. sp + end + + if (self.piao_niao) then + str = str .. "飘鸟" .. sp + end + + if self.two_pair then + str = str .. "金童玉女" .. sp + end + + if self.no_jiang then + str = str .. "假将胡" .. sp + end + + if self.four_win then + str = str .. "四连冠" .. sp + end + + if self.native_hu then + str = str .. "天听天胡" .. sp + end + + if self.queyimen then + str = str .. "缺一门" .. sp + end + + if self.menqing then + str = str .. "门清" ..sp + end + + str = str .. (self.niao_type == 0 and "鸟加分" or (self.niao_type == 1 and "鸟翻倍" or "长沙抓2鸟")) + str = str .. sp + + if (self.niao) then + str = str .. "抓" .. self.niao .. "鸟" .. sp + end + + str = str.sub(str,1,string.len(str)-string.len(sp)) + return str +end + +function M:GetGameName() + return "长沙麻将" +end + +function M:GetGameJS() + local gamerulepanel= UIPackage.CreateObjectFromURL("ui://Extend_MJ_NingXiang/gamerule") + return gamerulepanel +end + +return M \ No newline at end of file diff --git a/lua_probject/extend_project/extend/majiang/ningxiang/ExtendConfig.lua b/lua_probject/extend_project/extend/majiang/ningxiang/ExtendConfig.lua new file mode 100644 index 00000000..29b71c3a --- /dev/null +++ b/lua_probject/extend_project/extend/majiang/ningxiang/ExtendConfig.lua @@ -0,0 +1,182 @@ +local EXTEND_MODEL_NAME = ... + +local EXGameInfo = import(".EXGameInfo") +local EXMainView = import(".EXMainView") +local EXGameController = import(".EXGameController") +local EXRoomConfig = import(".EXRoomConfig") +local EXPlayBackView =import(".EXPlayBackView") +local MJRoom = require("main.majiang.MJRoom") + +local ExtendConfig = {} + +local M = ExtendConfig + + +function ExtendConfig.new() + setmetatable(M, {__index = IExtendConfig}) + local self = setmetatable({}, {__index = M}) + self.class = "ExtendConfig" + self._viewMap = {} + self._viewMap[ViewManager.View_Main] = EXMainView + self._viewMap[ViewManager.View_PlayBack] = EXPlayBackView + return self +end + +--卸载资源 +function M:UnAllAssets() + UIPackage.RemovePackage("extend/majiang/ningxiang/ui/Info_MJ_NingXiang") + self:UnAssets() +end + +--卸载资源 +function M:UnAssets() + UIPackage.RemovePackage("extend/majiang/ningxiang/ui/Extend_MJ_NingXiang") + ResourcesManager.UnLoadGroup("NingXiang_MJ") +end + +local _gameInfo = nil +function M:GetGameInfo() + if not _gameInfo then + _gameInfo = EXGameInfo.new() + end + return _gameInfo +end + +local _ctr_game = nil +function M:GetGameController() + if _ctr_game == nil then + _ctr_game = EXGameController.new() + end + return _ctr_game +end + +function M:NewRoom() + return MJRoom.new() +end + +function M:FillRoomConfig(room,_config) + room.room_config = EXRoomConfig.new(_config) +end + +function M:FillRoomData(s2croom) + local room = DataManager.CurrenRoom + + local reload = s2croom["reload"] + local _tableInfo = s2croom["tableInfo"] + + local _config = _tableInfo["config"] + room.room_config = EXRoomConfig.new(_config) + + local playerList = _tableInfo["playerData"] + room.curren_round = _tableInfo["round"] + if room.curren_round == 0 and reload then room.curren_round = 1 end + self:FillPlayerData(playerList) + + if (reload) then + local _reloadInfo = s2croom["reloadInfo"] + local _hand_card = _reloadInfo["hand_card"] + room.self_player.card_list = _hand_card + table.sort(_hand_card, ViewUtil.HandCardSort) + + local active_seat = _reloadInfo["active_seat"] + local bank_seat = _reloadInfo["banker_seat"] + local playing = _reloadInfo["playing"] + local _info_list = _reloadInfo["info_list"] + local last_outcard_seat = _reloadInfo["last_outcard_seat"] + room.left_count = _reloadInfo["left_card"] + room.banker_seat = bank_seat + room.curren_outcard_seat = _reloadInfo["curren_outcard_seat"] + room.active_seat = _reloadInfo["active_seat"] + room.last_outcard_seat = last_outcard_seat + room.playing = playing + local _ok_list = _reloadInfo["okinfo"] + if _ok_list then room.kg_card = _ok_list.cardList end + for i=1,#_info_list do + local tem = _info_list[i] + local playerid = tem["playerid"] + local auto_play = tem["auto"] + local p = room:GetPlayerById(playerid) + local outcard_list = tem["outcard_list"] + p.outcard_list = outcard_list + p.total_score = tem["score"] + p.hand_left_count = tem["card_count"] + p.auto_play = auto_play + if auto_play then + p.draw_card = tem["draw_card"] + end + p.ting = tem["ting"] + p.win_count = tem["win_count"] + p.piao_niao = tem["piao_niao"] or 0 + -- p.entrust = tem["entrust"] or false + local opcard = tem["opcard"] + for k=1,#opcard do + local op = opcard[k] + local fz = {} + fz.type = op["type"] + fz.card = op["card"] + fz.opengang = op["opengang"] + if fz.type == FZType.Chi then + fz.opcard = {} + fz.opcard[1] = op["opcard"][1] + fz.opcard[2] = fz.card + fz.opcard[3] = op["opcard"][2] + end + p.fz_list[#p.fz_list+1] = fz + end + if (not playing and room.curren_round > 0) or room.status == 1 then + self.GetGameController():PlayerReady() + end + end + end +end + +function M:FillPlayBackData(pd_data) + local room = DataManager.CurrenRoom + local _tableInfo = pd_data["info"] + + local _config = _tableInfo["config"] + room.room_id = _tableInfo.roomid + room.room_config = EXRoomConfig.new(_config) + room.owner_id = _config["ownerid"] + local active_seat = _tableInfo["active_seat"] + local bank_seat = _tableInfo["banker_seat"] + room.left_count = _tableInfo["left_card"] + room.banker_seat = bank_seat + room.curren_turn_seat = active_seat + room.curren_round = _tableInfo["round"] + + local _info_list = _tableInfo["playerData"] + for i = 1,#_info_list do + local _jp = _info_list[i] + local p = room:NewPlayer() + p.seat = _jp["seat"] + local online = _jp["online"] + p.line_state = online + p.ready = _jp["ready"] == 1 and true or false + local pid = _jp["aid"] + p.piao_niao = _jp["piao_niao"] + if p.seat == 1 then room.self_player = p end + local u = User.new() + u.account_id = pid + p.self_user = u + u.nick_name = _jp["nick"] + u.head_url = _jp["portrait"] + u.sex = _jp["sex"] + p.self_user.host_ip = p.self_user.host_ip + local _hand_card = _jp["hand_card"] + p.card_list = _hand_card + --room.self_player.card_list = _hand_card + table.sort(_hand_card, ViewUtil.HandCardSort) + p.total_score = _jp["score"] + p.hand_left_count = #_hand_card + if _jp.hp_info then + room.room_config.isNonnegative = 1 + p.cur_hp = _jp.hp_info.cur_hp + end + + room:AddPlayer(p) + end + room.cmdList = pd_data["cmdList"] +end + +return M \ No newline at end of file diff --git a/lua_probject/extend_project/extend/majiang/ningxiang/HuTipView.lua b/lua_probject/extend_project/extend/majiang/ningxiang/HuTipView.lua new file mode 100644 index 00000000..071fe058 --- /dev/null +++ b/lua_probject/extend_project/extend/majiang/ningxiang/HuTipView.lua @@ -0,0 +1,118 @@ +local FZTipList = require("main.majiang.FZData") + +local HuTipView = { + _view_start_pos = nil, + _touch_start_pos = nil, +} + +local M = HuTipView + +function M.new(main_view) + local self = {} + self.class = "HuTipView" + setmetatable(self,{__index = HuTipView}) + self._main_view = main_view + self:init() + return self +end + +local function SetObjEnabled(obj, enabled) + obj.visible = enabled + obj.touchable = enabled +end + +function M:OnTouchBegin(context) + self._view_start_pos = Vector2(self._view.x, self._view.y) + self._touch_start_pos = self._main_view._view:GlobalToLocal(Vector2(context.inputEvent.x, context.inputEvent.y)) +end +function M:OnTouchMove(context) + local xy = self._main_view._view:GlobalToLocal(Vector2.New(context.inputEvent.x,context.inputEvent.y)) + local dist = Vector2(xy.x - self._touch_start_pos.x, xy.y - self._touch_start_pos.y) + local posx = self._view_start_pos.x + dist.x + local posy = self._view_start_pos.y + dist.y + local max_x = self._main_view._view.width - self._view.width + local max_y = self._main_view._view.height - self._view.height + self._view.x = posx < 0 and 0 or posx > max_x and max_x or posx + self._view.y = posy < 0 and 0 or posy > max_y and max_y or posy +end + +function M:init() + UIPackage.AddPackage("extend/majiang/ningxiang/ui/Extend_MJ_NingXiang") + self._view = UIPackage.CreateObjectFromURL("ui://Extend_MJ_NingXiang/Hu_tip") + self._main_view._view:AddChild(self._view) + local width = self._view.width + local m_width = self._main_view._view.width + local m_height = self._main_view._view.height + -- 初始位置 + self._view.x = 0 + self._view.y = 0.75 * m_height + SetObjEnabled(self._view, false) + self._view.onTouchBegin:Add(handler(self, self.OnTouchBegin)) + self._view.onTouchMove:Add(handler(self, self.OnTouchMove)) +end + +function M:FillData(cards) + local lst_card = self._view:GetChild("lst_card") + lst_card:RemoveChildrenToPool() + local num = #cards + if num > 0 then + if num > 3 and num <= 28 then + self._view.width = 191 + (num - 3) * 38 + -- self._view.height = 69 + (math.ceil(num / 7) - 1) * 56 + else + self._view.width = 191 + end + for i = 1, num do + local item = lst_card:AddItemFromPool() + local card = cards[i] + item:GetChild("icon").icon = "ui://Main_Majiang/" .. self:GetPrefix() .. "202_" .. card + item:GetChild("tex_num").text = self:CountCardLeftNum(card) .. "张" + end + SetObjEnabled(self._view, true) + else + SetObjEnabled(self._view, false) + end +end + +function M:CountCardLeftNum(card) + local player_list = DataManager.CurrenRoom.player_list + local count = 4 + for i = 1, #player_list do + local p = player_list[i] + if p.card_list then + for j = 1, #p.card_list do + if p.card_list[j] == card then + count = count - 1 + end + end + end + for j = 1, #p.outcard_list do + if p.outcard_list[j] == card then + count = count - 1 + end + end + for j = 1, #p.fz_list do + local fz = p.fz_list[j] + if fz.type == FZType.Chi then + for k = 1, #fz.opcard do + if card == fz.opcard[k] then + count = count - 1 + break + end + end + else + local num = fz.type == FZType.Peng and 3 or 4 + if card == fz.card then + count = count - num + end + end + end + end + return count +end + +function M:GetPrefix() + return get_majiang_prefix(DataManager.CurrenRoom.game_id) +end + +return M \ No newline at end of file diff --git a/lua_probject/extend_project/extend/majiang/ningxiang/MJPlayerCardInfoView.lua b/lua_probject/extend_project/extend/majiang/ningxiang/MJPlayerCardInfoView.lua new file mode 100644 index 00000000..fcde11b9 --- /dev/null +++ b/lua_probject/extend_project/extend/majiang/ningxiang/MJPlayerCardInfoView.lua @@ -0,0 +1,116 @@ +local MJPlayerCardInfoView = require("main.majiang.MJPlayerCardInfoView") +local ViewUtil = require("Game.View.ViewUtil") +local M = {} + +function M.new(view,mainView) + setmetatable(M, {__index = MJPlayerCardInfoView}) + local self = setmetatable({},{__index = M}) + self.class = "PlayerCardInfoView" + self._view = view + self._mainView = mainView + self:init() + return self +end + +local function CardPos(obj, area, oder, loc, offset) + offset = offset or 0 + local location = loc + if oder == AreaOderType.left_right then + obj.x = location + offset + location = obj.x + obj.width + elseif oder == AreaOderType.up_down then + obj.y = location + offset + location = obj.y + obj.height + elseif oder == AreaOderType.right_left then + obj.x = (area.width - obj.width) - location - offset + location = location + obj.width + elseif oder == AreaOderType.down_up then + obj.y = area.height - obj.height - location - offset + location = location + obj.height + end + return location +end + +-- function M:UpdateHandCard(getcard, mp, opcard) +-- -- mp 是否明牌 +-- -- 如果不明牌,但是有 opcard 表示是起手胡 +-- getcard = getcard or false +-- mp = mp or false +-- local handcard_list = self._mask_data["handcard_list"] +-- local oder = handcard_list["oder"] +-- local _player = self._player +-- local comp_back = handcard_list["comp_back"] +-- local comp = handcard_list["comp"] +-- local outcard_list = self._mask_data["outcard_list"] +-- local card = outcard_list["card"] + +-- self._area_handcard_list:RemoveChildren(0, -1, true) +-- local opnum = opcard and #opcard or -1 +-- if not mp and opnum > -1 then +-- -- 起手胡板牌记录,手牌变化两次后,板牌收回 +-- self.__show_qs_hu_times = 1 +-- self.__qs_hu_cards = opcard +-- elseif self.__qs_hu_cards and opnum == -1 and self.__show_qs_hu_times > 0 then +-- self.__show_qs_hu_times = self.__show_qs_hu_times - 1 +-- opcard = self.__qs_hu_cards +-- opnum = #opcard +-- end +-- local loc = 0 +-- if not mp then +-- local comp_back = handcard_list["comp_back"] +-- if self._current_card_type == 2 then +-- comp_back = comp_back.."_3d" +-- end +-- for i = 0, _player.hand_left_count -1 do +-- local obj +-- local offset = (getcard and i == _player.hand_left_count - 1) and 15 or 0 +-- if i < opnum then +-- obj = UIPackage.CreateObject("Main_Majiang", comp) +-- self:fillCard(obj, card, opcard[i + 1]) +-- else +-- obj = UIPackage.CreateObject("Main_Majiang", comp_back) +-- end +-- if opnum ~= -1 then +-- loc = CardPos(obj, self._area_handcard_list, oder, loc, offset) +-- else +-- ViewUtil.CardPos(obj, self._area_handcard_list, oder, i, offset) +-- end +-- --改变左右两边的手牌的x值 +-- if self._current_card_type == 2 and (oder == AreaOderType.down_up or oder == AreaOderType.up_down) then +-- obj.x = i * -7.0 +-- end +-- if (oder == AreaOderType.down_up) then +-- self._area_handcard_list:AddChildAt(obj, 0) +-- else +-- self._area_handcard_list:AddChild(obj) +-- end +-- end +-- else +-- local outcard_list = self._mask_data["outcard_list"] +-- local comp = handcard_list["comp"] +-- local card = outcard_list["card"] +-- --print("comp"..comp) +-- -- print(vardump(_player.card_list)) + +-- if self._current_card_type == 2 then +-- comp = comp.."_3d" +-- end +-- for i = 0, #_player.card_list -1 do +-- local obj = UIPackage.CreateObject("Main_Majiang", comp) +-- self:fillCard(obj,card,_player.card_list[i+1]) +-- local offset = getcard and (i == _player.hand_left_count - 1 and 15 or 0) +-- ViewUtil.CardPos(obj, self._area_handcard_list, oder, i, offset) +-- --改变左右两边的手牌的x值 +-- if self._current_card_type == 2 and (oder == AreaOderType.down_up or oder == AreaOderType.up_down) then +-- obj.x = i * -7 +-- end +-- if (oder == AreaOderType.down_up) then +-- self._area_handcard_list:AddChildAt(obj, 0) +-- else +-- self._area_handcard_list:AddChild(obj) +-- end +-- end +-- end +-- end + +return M \ No newline at end of file diff --git a/lua_probject/extend_project/extend/majiang/ningxiang/MJPlayerSelfCardInfoView.lua b/lua_probject/extend_project/extend/majiang/ningxiang/MJPlayerSelfCardInfoView.lua new file mode 100644 index 00000000..003db705 --- /dev/null +++ b/lua_probject/extend_project/extend/majiang/ningxiang/MJPlayerSelfCardInfoView.lua @@ -0,0 +1,207 @@ +local MJPlayerSelfCardInfoView = require("main.majiang.MJPlayerSelfCardInfoView") +local MJPlayerCardInfoView = require("main.majiang.MJPlayerCardInfoView") +local CardCheck = import(".CardCheck") + +local M = {} +-- +function M.new(view,mainView) + setmetatable(MJPlayerSelfCardInfoView, {__index = MJPlayerCardInfoView}) + setmetatable(M, {__index = MJPlayerSelfCardInfoView}) + local self = setmetatable({},{__index = M}) + self.class = "PlayerSelfCardInfoView" + self._view = view + self._mainView = mainView + self:init() + return self +end + +function M:ShowHuTip(card_list) + local fz_list = DataManager.CurrenRoom.self_player.fz_list + local tingList = CardCheck.tingPai(card_list, fz_list, DataManager.CurrenRoom.room_config.no_jiang) + self._mainView._hu_tip:FillData(tingList) +end + +function M:UpdateHandCard(getcard, mp, opcard) + MJPlayerSelfCardInfoView.UpdateHandCard(self, getcard, mp) + local _carViewList = self._carViewList + local card_list = DataManager.CurrenRoom.self_player.card_list + self:ShowHuTip(card_list) + if getcard then + self._out_card = true + local card_list = membe_clone(DataManager.CurrenRoom.self_player.card_list) + -- 记录需要标记听牌提示的牌 + local lst_mark = {} + local total_num = 0 + for i = 1, #_carViewList do + local btn = _carViewList[i].card + local card = self:GetCard(btn) + list_remove(card_list, card) + local tingList = CardCheck.tingPai(card_list, DataManager.CurrenRoom.self_player.fz_list, DataManager.CurrenRoom.room_config.no_jiang) + if #tingList > 0 then + local count = 0 + for j = 1, #tingList do + count = count + self._mainView:CountCardLeftNum(tingList[j]) + end + local tem = {} + tem.item = btn + tem.count = count + total_num = total_num + count + table.insert(lst_mark, tem) + end + table.insert(card_list, card) + end + table.sort(lst_mark, function(a, b) + return a.count > b.count + end) + -- 如果几张牌的可胡牌数一致,也只显示'三角',可胡牌数不一致才显示'多' + local all_same = #lst_mark ~= 0 and lst_mark[1].count == total_num / #lst_mark or false + for i = 1, #lst_mark do + local tem = lst_mark[i] + if all_same or tem.count < lst_mark[1].count then + tem.item:GetController("mark_ting").selectedIndex = 1 + else + tem.item:GetController("mark_ting").selectedIndex = 2 + end + end + else + for i = 1, #_carViewList do + local btn = _carViewList[i].card + if btn:GetController("mark_ting").selectedIndex ~= 0 then + btn:GetController("mark_ting").selectedIndex = 0 + end + end + self._out_card = false + end + local opnum = opcard and #opcard or -1 + if not mp and opnum > -1 then + -- 起手胡板牌记录,手牌变化两次后,板牌收回 + self.__show_qs_hu_times = 2 + self.__qs_hu_cards = opcard + elseif self.__qs_hu_cards and opnum == -1 and self.__show_qs_hu_times > 0 then + self.__show_qs_hu_times = self.__show_qs_hu_times - 1 + opcard = self.__qs_hu_cards + opnum = #opcard + end + if opcard then + if #opcard > 0 then + for i = #opcard, 1, -1 do + for j = 1, #_carViewList do + local btn = _carViewList[j].card + local card = self:GetCard(btn) + local tem = string.gsub(btn.icon, "ui://Main_Majiang/" .. self:GetPrefix(), "") + if card == tonumber(opcard[i]) and string.sub(tem, 1, 3) == "201" then + btn.icon = "ui://Main_Majiang/" .. self:GetPrefix() .. "202_" .. card + -- list_remove(opcard, card) + break + end + end + end + else + for i = 1, #_carViewList do + local btn = _carViewList[i].card + local tem = string.gsub(btn.icon, "ui://Main_Majiang/", "") + local tlist = string.split(tem, "_") + btn.icon = "ui://Main_Majiang/" .. self:GetPrefix() .. "201_" .. tlist[2] + end + end + end +end + +function M:__OnClickHandCard(context) + local button = context.sender + local _carViewList = self._carViewList + local refresh = true + local card_list = {} + for i=1,#_carViewList do + local btn = _carViewList[i].card + local card = self:GetCard(btn) + if btn ~= button and btn.selected == true then + if button.data.card_item == card then + refresh = false + else + self._mainView:markOutCards(false, card) + end + btn.selected = false + end + if not btn.selected then + table.insert(card_list, card) + end + end + + if self._out_card then + self:ShowHuTip(card_list) + end + + if refresh then + if button.selected then + self._mainView:markOutCards(true, button.data.card_item) + else + self._mainView:markOutCards(false, button.data.card_item) + end + end + + local _room = DataManager.CurrenRoom + -- if (Utils.IsDoubleClick(context) and _room.curren_outcard_seat == _room.self_player.seat) then + -- local card = button.data + -- self._mainView:OutCard(card.card_item) + -- end + if not button.selected and _room.curren_outcard_seat == _room.self_player.seat then + local card = button.data + self._mainView:OutCard(card.card_item) + end +end + +function M:__OnDragEnd(context, offset) + if self.outcard_button then + self.outcard_button:Dispose() + self.outcard_button = nil + end + local button = context.sender + -- + --button:RemoveFromParent() + local card = button.data + local _room = DataManager.CurrenRoom + + -- print("button.y"..button.y .. "_room.curren_outcard_seat".._room.curren_outcard_seat) + -- print(button.y - card.old_postion.y) + -- if (button.y < -55 and _room.curren_outcard_seat == _room.self_player.seat) and self:CheckPlayerOnlineState() then + if (button.y - card.old_postion.y < -50 and _room.curren_outcard_seat == _room.self_player.seat) then + self._mainView:OutCard(card.card_item) + button.touchable = false + self.outcard_button = button + else + self._area_handcard_list:AddChildAt(button, card.index) + button:TweenMove(card.old_postion, 0.2) + end +end + +function M:CheckPlayerOnlineState() + local room = DataManager.CurrenRoom + for i = 1, #room.player_list do + if room.player_list[i].line_state == 0 then + return false + end + end + return true +end +function M:Clear(bskip) + --self._ctr_state.selectedIndex = 0 + self._area_fz_list.x = self._src_fz_list.x + self._area_fz_list.y = self._src_fz_list.y + self._area_fz_list.width = self._src_fz_list.z + self._area_fz_list.height = self._src_fz_list.w + + self._area_fz_list:RemoveChildren(0, -1, true) + self._area_handcard_list:RemoveChildren(0, -1, true) + self._area_outcard_list:RemoveChildren(0, -1, true) + if bskip == nil or bskip == false then + self._mask_liangpai:RemoveChildren(0, -1, true) + end + + for i=1,#self._carViewList do + self._carViewList[i].card:Dispose() + end + self._carViewList = {} + +end +return M \ No newline at end of file diff --git a/lua_probject/extend_project/extend/majiang/ningxiang/Protocol.lua b/lua_probject/extend_project/extend/majiang/ningxiang/Protocol.lua new file mode 100644 index 00000000..035dea56 --- /dev/null +++ b/lua_probject/extend_project/extend/majiang/ningxiang/Protocol.lua @@ -0,0 +1,68 @@ +local Protocol = { + -- 发牌协议 + GAME_EVT_PLAYER_DEAL = "811", + + -- 出牌 + GAME_DIS_CARD = "611", + + -- 出牌事件 + GAME_EVT_DISCARD = "812", + + -- 出牌提示事件 + GAME_EVT_DISCARD_TIP = "813", + + -- 放子提示事件 + GAME_EVT_FZTIPS = "814", + + -- 提示选择行为 + GAME_ACTION = "612", + + -- action 事件 + GAME_EVT_ACTION = "815", + + -- 胡牌事件 + GAME_EVT_HU = "816", + + -- 小结算 + GAME_EVT_RESULT1 = "817", + + -- 大结算 + GAME_EVT_RESULT2 = "818", + + -- 抓牌 + GAME_EVT_DRAW = "819", + + -- 转盘指向事件 + GAME_EVT_CHANGE_ACTIVE_PLAYER = "820", + + -- 鸟 + GAME_EVT_NIAO = "821", + + -- 起手胡提示 + GAME_EVT_QSTIP = "822", + + -- 起手胡事件 + GAME_EVT_QSWIN = "823", + + -- 开杠 + GAME_EVT_OPENKONG = "824", + + -- 海底 + GAME_EVT_HAIDI = "825", + + -- 飘鸟提示 + GAME_EVT_PIAOTIP = "833", + + -- 飘鸟事件 + GAME_EVT_PIAO = "834", + + GAME_EVT_TING_TIP = "835", + + GAME_EVT_TING = "836", + + GAME_XIPAI = "20836", + GAME_EVENT_XIPAI = "20837", + GAME_EVENT_NOTIFY_XIPAI = "20838", +} + +return Protocol \ No newline at end of file diff --git a/lua_probject/extend_project/extend/majiang/ningxiang/RecordEvent.lua b/lua_probject/extend_project/extend/majiang/ningxiang/RecordEvent.lua new file mode 100644 index 00000000..47b92546 --- /dev/null +++ b/lua_probject/extend_project/extend/majiang/ningxiang/RecordEvent.lua @@ -0,0 +1,14 @@ +local Record_Event = { + Evt_QiShou = "QSWin", + Evt_GetCard = "GetCard", + Evt_OutCard = "OutCard", + Evt_Action = "Action", + -- Evt_HaiDi = "HaiDi", + Evt_KaiGang = "OpenKong", + Evt_Win = "Win", + Evt_Niao = "Niao", + Evt_Piao = "PiaoNiao", + Evt_Result = "Result", +} + +return Record_Event \ No newline at end of file diff --git a/wb_new_ui/.objs/metas/niy3ldiw/l9mn14.info b/wb_new_ui/.objs/metas/niy3ldiw/l9mn14.info index 237a66a1..3c2b605a 100644 --- a/wb_new_ui/.objs/metas/niy3ldiw/l9mn14.info +++ b/wb_new_ui/.objs/metas/niy3ldiw/l9mn14.info @@ -37,6 +37,9 @@ "n51_fmkv": { "collapsed": true }, + "n89_qmn4": { + "collapsed": true + }, "n15_pt1r": { "hidden": true }, diff --git a/wb_new_ui/.objs/workspace.json b/wb_new_ui/.objs/workspace.json index 332c8b99..f69512d8 100644 --- a/wb_new_ui/.objs/workspace.json +++ b/wb_new_ui/.objs/workspace.json @@ -15,56 +15,7 @@ "auxline2": true, "doc.activeDoc": "ui://niy3ldiwl9mn14", "libview.twoColumn": false, - "libview.expandedNodes": [ - "egnzysm7", - "/", - "egnzysm7", - "/component/", - "egnzysm7", - "/component/EPCDWHZMui/", - "egnzysm7", - "/component/clearing/", - "egnzysm7", - "/images/", - "egnzysm7", - "/images/EPCDXTMui/", - "ypulwxjh", - "/", - "ypulwxjh", - "/images/", - "ypulwxjh", - "/images/EPFLSXTMui/", - "4ismcalc", - "/", - "442j0uep", - "/", - "442j0uep", - "/images/", - "3n2top74", - "/", - "3n2top74", - "/buttons/", - "3n2top74", - "/images/", - "3n2top74", - "/images/EPRXTMui/", - "3n2top74", - "/images/MMXTMui/", - "niy3ldiw", - "/", - "niy3ldiw", - "/images/", - "niy3ldiw", - "/images/EPYYXTMui/", - "3z9lj55v", - "/", - "3z9lj55v", - "/buttons/", - "3z9lj55v", - "/images/", - "3z9lj55v", - "/images/MMXTMui/" - ], + "libview.expandedNodes": [], "auxline1": true, "snapToGrid": true, "test.orientation": "landscape", diff --git a/wb_new_ui/assets/Extend_MJ_NingXiang/Btn_chat.xml b/wb_new_ui/assets/Extend_MJ_NingXiang/Btn_chat.xml new file mode 100644 index 00000000..3ff8e21f --- /dev/null +++ b/wb_new_ui/assets/Extend_MJ_NingXiang/Btn_chat.xml @@ -0,0 +1,11 @@ + + + + + + + + + +