dezhou_client/lua_probject/base_project/Game/View/MainRightPanelView.lua

128 lines
3.8 KiB
Lua
Raw Normal View History

2025-12-17 21:08:27 +08:00
local MainRightPanelView = {
-- 查看记录
onLogCallback = nil
}
local M = MainRightPanelView
local function __init(self, mainView, view)
local right_panel = view
local btn_setting = right_panel:GetChild('btn_setting')
btn_setting.onClick:Set(
function()
local _settingView = mainView:NewSettingView()
_settingView.stateIndex = (mainView._room.curren_round >= 1 and mainView._allow_dissmiss) and 2 or 1
_settingView.cd_time = mainView.dismiss_room_cd_time
_settingView:Show()
local room = DataManager.CurrenRoom
_settingView.onCallback:Add(
function(context)
local _gamectr = ControllerManager.GetController(GameController)
if (room.CurnrenState == StateType.Ready) then
_gamectr:LevelRoom(
function(response)
if (response.ReturnCode == 0) then
ViewManager.ChangeView(ViewManager.View_Lobby)
GameApplication.Instance:ShowTips('房间已解散!')
end
end
)
else
_gamectr:AskDismissRoom()
end
end
)
end
)
self._tex_data = right_panel:GetChild('tex_data')
self._tex_time = right_panel:GetChild('tex_time')
self._pb_batteryLevel = right_panel:GetChild('pb_batteryLevel')
self._xinhao = right_panel:GetController('xinhao')
self.ctr_xh = right_panel:GetChild('gcm_xinhao'):GetController('c1')
self.ctr_wifi = right_panel:GetChild('gcm_wifi'):GetController('c1')
self._tex_ping = right_panel:GetChild('gcm_xinhao'):GetChild('n7')
self.ctr_log = right_panel:GetController('log')
local btn_log = right_panel:GetChild('btn_log')
btn_log.onClick:Set(
function()
if self.onLogCallback then
self.onLogCallback()
end
end
)
self._total_time = 0
self:__UpdateTime()
-- self._timer = Timer.New(handler(self,self.__UpdateTime),10,-1,true)
-- self._timer:Start()
end
--- Create a new MainRightPanelView
function MainRightPanelView.new(mainView, view)
local self = setmetatable({}, {__index = M})
self.class = 'MainRightPanelView'
-- 显示选项1是正常2的ping没有括号
self._opt = 1
__init(self, mainView, view)
return self
end
function M:__UpdateTime()
if self._total_time >= 10 then
self._total_time = 0
else
return
end
self:_ShowTime()
end
function M:_ShowTime()
self._tex_data.text = os.date('%Y-%m-%d')
self._tex_time.text = os.date('%H:%M')
if Application.platform == RuntimePlatform.IPhonePlayer or Application.platform == RuntimePlatform.Android then
self._pb_batteryLevel.value = GameApplication.Instance:GetBatteryLevel()
end
local NetworkReachability = UnityEngine.NetworkReachability
local _client = ControllerManager.GameNetClinet
if not _client then
return
end
local ping = _client:getAveragePingTime()
if not ping then
return
end
ping = math.floor(ping / 2)
if ping > 300 then
ping = 300
end
if ping <= 100 then
self.ctr_xh.selectedIndex = 0
elseif ping <= 300 then
self.ctr_xh.selectedIndex = 1
else
self.ctr_xh.selectedIndex = 2
end
local str_ping = '' .. ping .. 'ms'
if self._opt == 2 then
str_ping = ping .. 'ms'
end
self._tex_ping.text = str_ping
end
--
function M:OnUpdate(deltaTime)
self:__UpdateTime()
self._total_time = self._total_time + deltaTime
end
function M:Destroy()
-- self._timer:Stop()
end
return M