jx_client_neibu/lua_probject/main_project/main/poker/PKSettingView.lua

176 lines
6.8 KiB
Lua
Raw Normal View History

2025-04-01 10:48:36 +08:00
--local EXMainView = import(".EXMainView")
local SettingView = require('Game.View.SettingView')
local PKSettingView = {
__checkMainViewState = nil,
__changePokerCallBack = nil,
__changePokerSizeCallBack = nil,
}
local M = PKSettingView
2025-04-27 20:22:15 +08:00
function PKSettingView.new(blur_view, show_type, isjiesan, url, cardSizeHandle)
setmetatable(SettingView, { __index = BaseWindow })
setmetatable(M, { __index = SettingView })
local self = setmetatable({}, { __index = M })
2025-04-01 10:48:36 +08:00
self.class = 'PKSettingView'
self._currenIndex = 0
self._blur_view = blur_view
self.onCallback = event('onCallback', true)
self.stateIndex = 0
self.cd_time = 0
self._btn_dismiss_room_enable = true
self._close_destroy = true
self._show_type = show_type
self.isjiesan = isjiesan
2025-04-27 20:22:15 +08:00
self.__changePokerSizeCallBack = cardSizeHandle
2025-04-01 10:48:36 +08:00
if url ~= nil then
self:init(url)
else
2025-04-27 20:22:15 +08:00
self:init('ui://Main_Poker/Setting')
2025-04-01 10:48:36 +08:00
end
2025-04-27 20:22:15 +08:00
2025-04-01 10:48:36 +08:00
return self
end
function M:init(url)
SettingView.init(self, url)
2025-04-27 20:22:15 +08:00
-- -- show_type:1隐藏所有 2隐藏解散和换牌 3隐藏返回和换牌
-- -- 设置界面有换牌功能的需要在mainview中重写方法UpdateCard
-- self._view:GetController('type').selectedIndex = self._show_type
-- -- show_type1玩法的换牌功能
-- if self._show_type == 1 then
-- local room = DataManager.CurrenRoom
-- local c1 = self._view:GetController('paimian')
-- local user_id = DataManager.SelfUser.account_id
-- local json_data = Utils.LoadLocalFile(user_id .. room.game_id .. 'pai')
-- if json_data == nil then
-- local _gamectr = self._gamectr
-- c1.selectedIndex = 0
-- else
-- local _data = json.decode(json_data)
-- local pai = _data['pai']
2025-04-01 10:48:36 +08:00
2025-04-27 20:22:15 +08:00
-- c1.selectedIndex = pai
-- end
2025-04-01 10:48:36 +08:00
2025-04-27 20:22:15 +08:00
-- c1.onChanged:Set(
-- function()
-- if self.__changePokerCallBack then
-- self.__changePokerCallBack(c1.selectedIndex)
-- end
-- --点击换牌按钮后保存当前游戏的牌
-- local user_id = DataManager.SelfUser.account_id
-- local _data = {}
-- _data['pai'] = c1.selectedIndex
-- local key = user_id .. room.game_id .. 'pai'
-- Utils.SaveLocalFile(key, json.encode(_data))
-- end
-- )
2025-04-01 10:48:36 +08:00
2025-04-27 20:22:15 +08:00
-- local card_size = self._view:GetController('card_size')
-- json_data = Utils.LoadLocalFile(user_id .. room.game_id .. 'cardsize')
-- if json_data == nil then
-- local _gamectr = self._gamectr
-- card_size.selectedIndex = 1
-- else
-- local _data = json.decode(json_data)
-- local cardsize = _data['cardsize']
2025-04-01 10:48:36 +08:00
2025-04-27 20:22:15 +08:00
-- card_size.selectedIndex = cardsize
-- end
2025-04-01 10:48:36 +08:00
2025-04-27 20:22:15 +08:00
-- card_size.onChanged:Set(
-- function()
-- if self.__changePokerSizeCallBack then
-- self.__changePokerSizeCallBack(card_size.selectedIndex)
-- end
-- --点击换牌按钮后保存当前游戏的牌
-- local user_id = DataManager.SelfUser.account_id
-- local _data = {}
-- _data['cardsize'] = card_size.selectedIndex
-- local key = user_id .. room.game_id .. 'cardsize'
-- Utils.SaveLocalFile(key, json.encode(_data))
-- end
-- )
2025-04-01 10:48:36 +08:00
2025-04-27 20:22:15 +08:00
-- self._view:GetChild('btn_close').onClick:Add(
-- function(...)
-- self:Destroy()
-- end
-- )
-- end
-- if self.isjiesan then
-- self._view:GetChild('n82').visible = false
-- end
2025-04-01 10:48:36 +08:00
end
2025-04-27 20:22:15 +08:00
-- function M:Show()
-- SettingView.Show(self)
-- -- self:showSettingOption()
-- end
2025-04-01 10:48:36 +08:00
-- 显示设置界面按钮
function M:showSettingOption()
local btn_back = self._view:GetChild('btn_back')
if btn_back ~= nil then
btn_back.onClick:Set(
function()
local room = DataManager.CurrenRoom
local ispanguangzhe = room.self_player.seat == 0
local tip_owner = '您是否退出房间?\n(退出房间后房间将解散)'
local tip = '您是否退出房间?'
local tipStr = ''
if room.agent then
tipStr = '您是否返回?'
else
tipStr =
2025-04-27 20:22:15 +08:00
(not ispanguangzhe and room.owner_id == room.self_player.self_user.account_id) and tip_owner or
tip
2025-04-01 10:48:36 +08:00
end
local _curren_msg = MsgWindow.new(self._root_view, tipStr, MsgWindow.MsgMode.OkAndCancel)
_curren_msg.onOk:Add(
function()
-- 如果游戏已经开始,是旁观者发出退出协议,否则的话不能离开
-- 如果没开始,发出退出协议
-- 不用考虑回放,回放不会显示返回按钮
local state = self.__checkMainViewState()
local _gamectr = ControllerManager.GetController(GameController)
if state > 0 and state < 3 then
if ispanguangzhe then
ViewUtil.ShowModalWait(self._root_view)
_gamectr:LevelRoom(
function(res)
ViewUtil.CloseModalWait()
if res.ReturnCode == 0 then
ViewManager.ChangeView(ViewManager.View_Lobby)
else
ViewUtil.ErrorTip(res.ReturnCode)
end
end
)
else
ViewUtil.ErrorTip(nil, '房间已开始,无法退出游戏。')
end
else
ViewUtil.ShowModalWait(self._root_view)
_gamectr:LevelRoom(
function(res)
ViewUtil.CloseModalWait()
if res.ReturnCode == 0 then
ViewManager.ChangeView(ViewManager.View_Lobby)
else
ViewUtil.ErrorTip(res.ReturnCode)
end
end
)
end
end
)
_curren_msg:Show()
end
)
end
end
return M