127 lines
4.0 KiB
Lua
127 lines
4.0 KiB
Lua
|
|
-- 显示玩家间距离
|
|||
|
|
-- Edit by chengy
|
|||
|
|
|
|||
|
|
PlayerDistanceView = {}
|
|||
|
|
|
|||
|
|
local M = PlayerDistanceView
|
|||
|
|
|
|||
|
|
function PlayerDistanceView.new(show_warning,style,callback)
|
|||
|
|
setmetatable(M, {__index = BaseWindow})
|
|||
|
|
local self = setmetatable({}, {__index = M})
|
|||
|
|
self.class = "PlayerDistanceView"
|
|||
|
|
self._close_destroy = false
|
|||
|
|
self._close_zone = true
|
|||
|
|
self.callback = callback
|
|||
|
|
self:init("ui://Common/com_Distance", show_warning,style)
|
|||
|
|
return self
|
|||
|
|
end
|
|||
|
|
function M:init(url, show_warning,style)
|
|||
|
|
BaseWindow.init(self,url)
|
|||
|
|
local _mainView = self._view
|
|||
|
|
self._view:GetChild("btn_close2").onClick:Add(function()
|
|||
|
|
self:Destroy()
|
|||
|
|
end)
|
|||
|
|
self:ShowPlayerDistance()
|
|||
|
|
if show_warning then
|
|||
|
|
self._view:GetController("warn").selectedIndex = 1
|
|||
|
|
end
|
|||
|
|
style = style or 0
|
|||
|
|
self._view:GetController("style").selectedIndex = style
|
|||
|
|
|
|||
|
|
--[[self._view:GetChild("btn_exit").onClick:Set(function()
|
|||
|
|
if self.callback then
|
|||
|
|
self.callback(false)
|
|||
|
|
end
|
|||
|
|
end)--]]
|
|||
|
|
self._view:GetChild("btn_continue").onClick:Set(function()
|
|||
|
|
if self.callback then
|
|||
|
|
self.callback(true)
|
|||
|
|
end
|
|||
|
|
end)
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
function M:ShowPlayerDistance()
|
|||
|
|
local room = DataManager.CurrenRoom
|
|||
|
|
local view = self._view
|
|||
|
|
local num = room.room_config.people_num
|
|||
|
|
local list = room.player_list
|
|||
|
|
view:GetController("people").selectedIndex = num - 2
|
|||
|
|
local com_dist = view:GetChild("dist_p" .. num)
|
|||
|
|
local p_list = {}
|
|||
|
|
local isHidden = false
|
|||
|
|
if room and room.playback ~= true and room.room_config and room.room_config.isHidden then
|
|||
|
|
isHidden = room.room_config.isHidden == 1
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
for i = 1, #list do
|
|||
|
|
local u = list[i].self_user
|
|||
|
|
local index = ViewUtil.GetPos(room.self_player.seat, list[i].seat, room.room_config.people_num)
|
|||
|
|
local btn_head = com_dist:GetChild("btn_head" .. index)
|
|||
|
|
|
|||
|
|
if isHidden == false then
|
|||
|
|
ImageLoad.Load(u.head_url, btn_head._iconObject)
|
|||
|
|
end
|
|||
|
|
p_list[index] = list[i]
|
|||
|
|
if not u.location or u.location.default then
|
|||
|
|
com_dist:GetChild("p" .. index).grayed = true
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
-- 需要计算的距离数量
|
|||
|
|
local dis_num = 0
|
|||
|
|
for i = 1, num - 1 do
|
|||
|
|
dis_num = dis_num + i
|
|||
|
|
end
|
|||
|
|
-- 第一个人需要与(所有人 - 1)人比,第二个人需要与(所有人 - 2)人比,以此类推
|
|||
|
|
for i = 1, dis_num do
|
|||
|
|
local text_dist = com_dist:GetChild("text_dest" .. i)
|
|||
|
|
local tem = 0
|
|||
|
|
-- 判断第i个距离是哪两个user间的
|
|||
|
|
local player1, player2
|
|||
|
|
for j = 1, num - 1 do
|
|||
|
|
local tem2 = tem + num - j
|
|||
|
|
if i <= tem2 then
|
|||
|
|
player1 = p_list[j]
|
|||
|
|
player2 = p_list[j + i - tem]
|
|||
|
|
local line = com_dist:GetChild("line" .. i)
|
|||
|
|
self:ShowDistanceDetail(player1, player2, text_dist, line, com_dist)
|
|||
|
|
break
|
|||
|
|
end
|
|||
|
|
tem = tem2
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
function M:ShowDistanceDetail(player1, player2, text_dist, line, com_dist)
|
|||
|
|
local str = ""
|
|||
|
|
local warn_color = self._view:GetChild("tex_warning").color
|
|||
|
|
local change_color = false
|
|||
|
|
if not player1 or not player2 then
|
|||
|
|
str = "未知"
|
|||
|
|
change_color = true
|
|||
|
|
else
|
|||
|
|
local user1 = player1.self_user
|
|||
|
|
local user2 = player2.self_user
|
|||
|
|
if (user1.location and not user1.location.default) and (user2.location and not user2.location.default) then
|
|||
|
|
local dist = user1.location:CalcDistance(user2.location)
|
|||
|
|
if dist > 1 then
|
|||
|
|
str = math.floor(dist + 0.5) .. "km"
|
|||
|
|
else
|
|||
|
|
str = math.floor(dist*1000+0.5) .. "m"
|
|||
|
|
end
|
|||
|
|
if dist < 0.2 then
|
|||
|
|
change_color = true
|
|||
|
|
end
|
|||
|
|
else
|
|||
|
|
str = "未知"
|
|||
|
|
change_color = true
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
text_dist.text = str
|
|||
|
|
if change_color then
|
|||
|
|
text_dist.color = warn_color
|
|||
|
|
line.color = warn_color
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
return M
|