hengyang_client/lua_probject/main_project/main/majiang/MJPlayerCardInfoView.lua

359 lines
11 KiB
Lua

AreaOderType = {
left_right = 'left_right',
right_left = 'right_left',
up_down = 'up_down',
down_up = 'down_up'
}
local PlayerCardInfoView = {
_view = nil,
_mainView = nil,
_mask_liangpai = nil,
_mask_data = nil,
_area_handcard_list = nil,
_src_fz_list = nil,
_current_card_type = -1
}
local M = PlayerCardInfoView
--- Create a new PlayerCardInfoView
function M.new(view, mainView)
local self = {}
setmetatable(self, { __index = M })
self._view = view
self._mainView = mainView
self:init()
return self
end
function M:init()
local CardInfo = self._view:GetChild('Text_CardInfo')
self._viewText_cardInfo = json.decode(CardInfo.text)
local CardInfo = self._view:GetChild('Text_CardInfo')
self._viewText_cardInfo = json.decode(CardInfo.text)
self._view_handCardList = self._view:GetChild('List_HandCard')
self._view_FZList = self._view:GetChild('List_FZ')
self._view_outCardList = self._view:GetChild('List_OutCard')
self._viewBtn_getCard = self._view:GetChild('Btn_HandCard')
self._ctr_getCard = self._view:GetController('getCard')
self._ctr_seletedGet = self._view:GetController('seletedGetCard')
end
function M:Clear()
--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)
self._mask_liangpai:RemoveChildren(0, -1, true)
self._view_handCardList:RemoveChildren(0, -1, true)
self._view_outCardList:RemoveChildren(0, -1, true)
self._view_FZList:RemoveChildren(0, -1, true)
self._view_getCard:RemoveChildren(0, -1, true)
self._view_handCardList.selectedIndex = -1
self._click_index = self._view_handCardList.selectedIndex
self._ctr_seletedGet.selectedIndex = 0
end
-- 获取麻将资源前缀
function M:GetPrefix()
-- local card_type = DataManager.CurrenRoom.card_type
-- local prefix = card_type == 1 and "a" or ""
-- return prefix
return get_majiang_prefix(DataManager.CurrenRoom.game_id)
end
function M:fillCard(obj, pos_str, card, use3d)
if DataManager.CurrenRoom.jing and card == DataManager.CurrenRoom.jing and obj:GetController('jing') then
obj:GetController('jing').selectedIndex = 1
end
if self._current_card_type == 2 and (use3d == nil or use3d == true) then
obj.icon = 'ui://MajiangCard3d/' .. 'b' .. pos_str .. card
else
obj.icon = 'ui://Main_Majiang/' .. self:GetPrefix() .. pos_str .. card
end
end
function M:fillCard2(obj, pos_str, card)
if DataManager.CurrenRoom.jing and card == DataManager.CurrenRoom.jing and obj:GetController('jing') then
obj:GetController('jing').selectedIndex = 1
end
obj:GetChild("icon").url = 'ui://Main_Majiang/' .. pos_str .. card
end
function M:getBackCard(card)
return 'ui://Main_Majiang/' .. card
end
function M:GetCard(btn)
local pic_name = split(btn.icon, '/')[4]
local lst = string.split(pic_name, '_')
return tonumber(lst[2] or 0)
end
function M:UpdateHandCard(getcard, mp)
getcard = getcard or false
mp = mp or false
self._view_handCardList:RemoveChildren()
for i = 0, self._player.hand_left_count - 1 do
-- if i >= self._view_handCardList.numItems then
self._view_handCardList:AddItemFromPool()
-- end
end
self._ctr_getCard.selectedIndex = getcard and 1 or 0
end
-- 获取麻将图片资源位置,可以在扩展中复写
function M:GetCardPicPack()
-- if DataManager.CurrenRoom.card_type == 2 then
-- return "MajiangCard3d"
-- else
return 'Main_Majiang'
-- end
end
function M:adjust3dOutPut(obj, area, oder, num, index)
if index >= num then
local row = 1 + math.floor(((index - num) / (num + 2)))
local col = ((index - num) % (num + 2))
if oder == AreaOderType.left_right then
obj.x = obj.x + math.floor((area.width - obj.width * (num + 2)) / 2)
elseif oder == AreaOderType.right_left then
obj.x = obj.x - math.floor((area.width - obj.width * (num + 2)) / 2)
elseif oder == AreaOderType.up_down then
obj.y = obj.y + math.floor((area.height - obj.height * (num + 2)) / 2)
obj.x = obj.x - col * 7 + 7 * (row + 1)
elseif oder == AreaOderType.down_up then
obj.y = obj.y - math.floor((area.height - obj.height * (num + 2)) / 2)
obj.x = obj.x - col * 7 - 7 * (row - 1)
end
else
if oder == AreaOderType.left_right then
obj.x = obj.x + math.floor((area.width - obj.width * num) / 2)
elseif oder == AreaOderType.right_left then
obj.x = obj.x - math.floor((area.width - obj.width * num) / 2)
elseif oder == AreaOderType.up_down then
obj.y = obj.y + math.floor((area.height - obj.height * num) / 2)
obj.x = obj.x - index * 7
elseif oder == AreaOderType.down_up then
obj.y = obj.y - math.floor((area.height - obj.height * num) / 2)
obj.x = obj.x - index * 7
end
end
end
function M:UpdateOutCardList(outcard, card_item, cursor)
outcard = outcard or nil
card_item = card_item or 0
cursor = cursor or nil
local outCardName = self._viewText_cardInfo['Out_Card']
local outcard
local outlist = self._player.outcard_list
for i = 0, #outlist - 1 do
local outcard = self._view_outCardList:AddItemFromPool()
self:fillCard2(outcard, outCardName, outlist[i + 1])
end
end
-- 设置添加角标的方法
function M:SetAddFlag(cb)
self.__addFlag = cb
end
-- 给麻将牌添加flag
function M:AddFlag(index, card, btn)
if not self.__addFlag then
return
end
local str_flag = self.__addFlag(index, card, btn)
btn:GetController('hun').selectedIndex = str_flag == '' and 0 or 1
btn:GetChild('flag').icon = str_flag
end
local function getPos(my_seat, other_seat, total)
local pos = 0
pos = other_seat - my_seat + 1
if pos <= 0 then
pos = pos + total
end
if total ~= 4 and pos == total then
pos = total + 1
end
return pos
end
function M:UpdateFzList(fz, index, show_card)
local fz_list = self._mask_data['fz_list']
local FZame = self._viewText_cardInfo['FZ_Card']
index = index or 0
show_card = show_card or nil
local outCard
-- if self._view_outCardList.numItems < #outlist - 1 then
-- for i = 1, #outlist - 1 do
-- outcard = self._view_outCardList:AddItemFromPool()
-- -- end
-- self:fillCard2(outcard, outCardName, outlist[i])
-- end
-- end
outCard = self._view_FZList:AddItemFromPool()
if fz.type == FZType.Chi then
for i = 1, 3 do
local FZCard = outCard:GetChild(string.format("Comp_Card%d", i))
self:fillCard2(FZCard, FZame, fz.opcard[i])
end
else
local ctr_Four = outCard:GetController("isFour")
for i = 1, 3 do
local FZCard = outCard:GetChild(string.format("Comp_Card%d", i))
print("lingmengfz", string.format("Comp_Card%d", i), FZCard)
self:fillCard2(FZCard, FZame, fz.card)
end
if fz.type == FZType.Peng then
ctr_Four.selectedIndex = 0
else
ctr_Four.selectedIndex = 1
local FZCard = outCard:GetChild(string.format("Comp_Card%d", 4))
self:fillCard2(FZCard, FZame, fz.card)
if fz.type == FZType.Gang_An then
self:fillCard2(FZCard, FZame, '00')
end
end
end
-- self:fillCard2(outcard, outCardName, card_item)
end
function M:GetOutCardByIndex(index)
local outcard_list = self._mask_data['outcard_list']
local oder = outcard_list['oder']
local multi_draw_oder = 0
if (outcard_list['multi_draw_oder']) then
multi_draw_oder = outcard_list['multi_draw_oder']
end
if (oder == AreaOderType.down_up or (multi_draw_oder == 1)) then
return self._area_outcard_list:GetChildAt(self._area_outcard_list.numChildren - index)
else
return self._area_outcard_list:GetChildAt(index - 1)
end
end
function M:ResetFzList()
for i = 1, #self._player.fz_list do
local fz = self._player.fz_list[i]
-- if fz.type ~= FZType.Gang_Peng then
self:UpdateFzList(fz, -1)
-- else
-- self:UpdateFzList(fz, i)
-- end
end
end
local function replace_card(obj, prefix)
local url = obj.icon
if url then
local len = string.len(url)
local pos = string.len('ui://Main_Majiang/') + 1
local head_char = string.sub(url, pos, pos)
local card = string.sub(url, pos, len)
if head_char >= 'a' then
card = string.sub(card, 2, len)
end
obj.icon = 'ui://Main_Majiang/' .. prefix .. card
end
end
function M:ResetCardType()
local old_card_type = self._current_card_type
self._current_card_type = DataManager.CurrenRoom.card_type
--设置3d标志
if self._current_card_type == 2 then
local c3d = self._view:GetController('3d')
if c3d ~= nil then
c3d.selectedIndex = 1
self._area_fz_list.x = self._src_fz_list_3d.x
self._area_fz_list.y = self._src_fz_list_3d.y
self._area_fz_list.width = self._src_fz_list_3d.z
self._area_fz_list.height = self._src_fz_list_3d.w
end
else
local c3d = self._view:GetController('3d')
if c3d ~= nil then
c3d.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
end
end
local change2d = false
if old_card_type == 2 and self._current_card_type ~= 2 then
change2d = true
end
local change3d = false
if old_card_type ~= 2 and self._current_card_type == 2 then
change3d = true
end
if change2d == false and change3d == false and self._current_card_type ~= 2 then
local prefix = self:GetPrefix()
--更新已出牌
for i = 1, self._area_outcard_list.numChildren do
local obj = self._area_outcard_list:GetChildAt(i - 1)
replace_card(obj, prefix)
end
--更新手牌
for i = 1, self._area_handcard_list.numChildren do
local obj = self._area_handcard_list:GetChildAt(i - 1)
replace_card(obj, prefix)
end
--更新放子牌
for i = 1, self._area_fz_list.numChildren do
local com = self._area_fz_list:GetChildAt(i - 1)
for j = 1, 4 do
local obj = com:GetChild('card_' .. j)
if obj then
replace_card(obj, prefix)
end
end
end
end
end
return M