402 lines
12 KiB
Lua
402 lines
12 KiB
Lua
-- 排行和战绩窗口
|
||
-- author:谌建军
|
||
|
||
RankView = {}
|
||
|
||
|
||
local M = RankView
|
||
|
||
function RankView.new( main_view,video )
|
||
UIPackage.AddPackage("base/rank/ui/Rank")
|
||
setmetatable(M, {__index = BaseWindow})
|
||
local self = setmetatable({}, {__index = M})
|
||
self.class = "RankView"
|
||
self._animation = false
|
||
self._full = true
|
||
self._full_offset = false
|
||
self._close_destroy = true
|
||
self._main_view = main_view
|
||
self._video = video
|
||
self._put_map = false
|
||
self._new_hide = false
|
||
self._queue = false
|
||
self:init("ui://Rank/Main")
|
||
return self
|
||
end
|
||
|
||
function M:init( url )
|
||
|
||
BaseWindow.init(self,url)
|
||
|
||
self._view:GetController("tab").selectedIndex = self._video and 1 or 0
|
||
self._curren_tex = ""
|
||
self._curren_len = 0
|
||
local develop_panel = self._view:GetChild("n70")
|
||
self.tex_roomid = develop_panel:GetChild("tex_roomid")
|
||
self.tex_roomid.text = ""
|
||
for i = 0, 9 do
|
||
local btn = develop_panel:GetChild("btn_" .. i)
|
||
btn.onClick:Add(function()
|
||
|
||
if self._curren_len < 6 then
|
||
|
||
self._curren_tex = self._curren_tex .. i
|
||
self._curren_len = self._curren_len + 1
|
||
self.tex_roomid.text = self._curren_tex
|
||
|
||
if self._curren_len == 6 then
|
||
|
||
ViewUtil.ShowModalWait(self._root_view)
|
||
local loddyCtr1 = ControllerManager.GetController(LoddyController)
|
||
loddyCtr1:RequestRecordList(function (result)
|
||
ViewUtil.CloseModalWait()
|
||
if self._is_destroy then
|
||
return
|
||
end
|
||
if result == Table_Error_code.ERR_TIMEOUT then
|
||
self:readData()
|
||
return
|
||
end
|
||
if result == 0 then
|
||
self:InitRecord1(loddyCtr1.recordList, true)
|
||
end
|
||
end, self._curren_tex)
|
||
end
|
||
end
|
||
end)
|
||
end
|
||
|
||
develop_panel:GetChild("btn_del").onClick:Add(function()
|
||
if self._curren_len > 0 then
|
||
self._curren_len = self._curren_len - 1
|
||
self._curren_tex = string.sub(self._curren_tex, 0, self._curren_len)
|
||
self.tex_roomid.text = self._curren_tex
|
||
end
|
||
end)
|
||
|
||
develop_panel:GetChild("btn_retype").onClick:Add(function()
|
||
self._curren_tex = ""
|
||
self._curren_len = 0
|
||
self.tex_roomid.text = self._curren_tex
|
||
end)
|
||
|
||
|
||
end
|
||
|
||
function M:readData()
|
||
local view = self._view
|
||
|
||
local record_list_1 = view:GetChild("n26")
|
||
record_list_1:RemoveChildrenToPool()
|
||
|
||
local loddyCtr1 = ControllerManager.GetController(LoddyController)
|
||
loddyCtr1:RequestRecordList(function (result)
|
||
if self._is_destroy then
|
||
return
|
||
end
|
||
if result == Table_Error_code.ERR_TIMEOUT then
|
||
self:readData()
|
||
return
|
||
end
|
||
|
||
|
||
self:InitRecord1(loddyCtr1.recordList)
|
||
|
||
end)
|
||
end
|
||
|
||
function M:Show()
|
||
BaseWindow.Show(self)
|
||
UpdateBeat:Remove(self._main_view.OnUpdate, self._main_view)
|
||
-- self:readData()
|
||
end
|
||
|
||
function M:Destroy()
|
||
BaseWindow.Destroy(self)
|
||
UpdateBeat:Add(self._main_view.OnUpdate, self._main_view)
|
||
end
|
||
|
||
local load_head_num = 0
|
||
function M:InitRecord1(recordList, develop_tool)
|
||
|
||
--print("InitRecord1=========")
|
||
pt(recordList)
|
||
local main_view = self._view
|
||
-- 战绩 list
|
||
local record_list_1, ctr_recored, ctr_no_record
|
||
if develop_tool then
|
||
|
||
ctr_recored = main_view:GetController("developer")
|
||
ctr_recored.selectedIndex = 1
|
||
|
||
record_list_1 = main_view:GetChild("lst_record")
|
||
local btn_backto_search = main_view:GetChild("btn_backto_search")
|
||
btn_backto_search.onClick:Set(function()
|
||
|
||
ctr_recored.selectedIndex = 0
|
||
|
||
self._curren_tex = ""
|
||
self._curren_len = 0
|
||
self.tex_roomid.text = ""
|
||
end)
|
||
ctr_no_record = self._view:GetController("noRecordData2")
|
||
else
|
||
record_list_1 = main_view:GetChild("n26")
|
||
ctr_no_record = self._view:GetController("noRecordData")
|
||
end
|
||
record_list_1:RemoveChildrenToPool()
|
||
ctr_no_record.selectedIndex = #recordList == 0 and 1 or 0
|
||
for i=1, #recordList do
|
||
|
||
local record_list_item = recordList[i]
|
||
local total_score_list = record_list_item.TotalScoreList
|
||
local item = record_list_1:AddItemFromPool()
|
||
|
||
local player_item_list = item:GetChild("big_round")
|
||
local more_person = #total_score_list >= 6
|
||
if more_person then
|
||
item:GetController("person_num").selectedIndex = 1
|
||
else
|
||
item:GetController("person_num").selectedIndex = 0
|
||
end
|
||
|
||
|
||
local game_id = record_list_item.GameId
|
||
local game_data = ExtendManager.GetGameData(game_id)
|
||
local room_type_str = record_list_item.GameInfo.name
|
||
local room_id_str = record_list_item.RoomId
|
||
local time =tonumber(record_list_item.Time)
|
||
local room_time_str = os.date("%Y-%m-%d %H:%M", time)
|
||
local item_score_list = record_list_item.GameTimes
|
||
local play_back_id = record_list_item.PlayBackId
|
||
-- 显示 房间号 房间类型 时间
|
||
item:GetChild("RoomType").asTextField.text = room_type_str
|
||
item:GetChild("RoomID").asTextField.text = room_id_str
|
||
item:GetChild("Time").asTextField.text = room_time_str
|
||
if record_list_item.hp_times and record_list_item.hp_times ~= 0 then
|
||
item:GetChild("tex_times").text = record_list_item.hp_times .. "倍"
|
||
else
|
||
item:GetChild("tex_times").text = ""
|
||
end
|
||
player_item_list:RemoveChildrenToPool()
|
||
local hpOnOff = record_list_item.hpOnOff
|
||
local hpType = record_list_item.GameInfo.hpType
|
||
-- 显示 每个玩家的 名字和 分数
|
||
-- player_list 是聊天室数据
|
||
local player_list = {}
|
||
for j=1,#total_score_list do
|
||
local player_list_item = total_score_list[j]
|
||
local player_item = player_item_list:AddItemFromPool()
|
||
player_item:GetChild("n0").text = player_list_item.Name
|
||
local player_score = player_item:GetChild("n1")
|
||
local score = player_list_item.Score
|
||
if hpOnOff == 1 and hpType > 1 then
|
||
score = score / 10
|
||
end
|
||
if score < 0 then
|
||
player_item:GetController("num_color").selectedIndex = 1
|
||
else
|
||
player_item:GetController("num_color").selectedIndex = 0
|
||
end
|
||
|
||
player_score.text = score >= 0 and "+"..score or score
|
||
player_list[j] = {}
|
||
player_list[j].id = player_list_item.Id
|
||
player_list[j].score = score
|
||
player_list[j].house = 0
|
||
player_list[j].nick = player_list_item.Name
|
||
end
|
||
-- 点击事件
|
||
item.onClick:Add(function ()
|
||
|
||
self:ShowRecord2(play_back_id, room_type_str, room_id_str, room_time_str,item_score_list, game_id, develop_tool, record_list_item)
|
||
end)
|
||
-- 分享
|
||
item:GetChild("btn_screenshot").onClick:Set(function()
|
||
ViewUtil.ShowModalWait(self._view, "正在分享...")
|
||
local result_view = UIPackage.CreateObjectFromURL("ui://Rank/ResultView")
|
||
result_view.visible = false
|
||
self._view:AddChild(result_view)
|
||
result_view:GetChild("tex_roomnum").text = room_id_str .. " " .. room_type_str
|
||
result_view:GetChild("tex_data").text = room_time_str
|
||
result_view:GetChild("btn_confirm").onClick:Set(function() result_view:Dispose() end)
|
||
local lst_p = result_view:GetChild("list_result")
|
||
local lst_p2 = result_view:GetChild("list_result2")
|
||
load_head_num = #total_score_list
|
||
local count = #total_score_list
|
||
for j = 1, count do
|
||
local p = total_score_list[j]
|
||
local item = nil
|
||
if count < 6 or (count >= 6 and j <= math.ceil(count / 2)) then
|
||
item = lst_p:AddItemFromPool()
|
||
else
|
||
item = lst_p2:AddItemFromPool()
|
||
end
|
||
item:GetChild("name").text = p.Name
|
||
local score = p.Score
|
||
if hpOnOff == 1 and hpType > 1 then
|
||
score = score / 10
|
||
end
|
||
item:GetChild("score").text = score
|
||
if score < 0 then item:GetController("di").selectedIndex = 1 end
|
||
if p.Portrait and p.Portrait ~= "" then
|
||
ImageLoad.Load(p.Portrait, item:GetChild("n9")._iconObject, 1, function( ... )
|
||
load_head_num = load_head_num - 1
|
||
end)
|
||
else
|
||
load_head_num = load_head_num - 1
|
||
end
|
||
end
|
||
coroutine.start(function ( ... )
|
||
local left_time = 4
|
||
while (true) do
|
||
if load_head_num == 0 or left_time == 0 then
|
||
result_view.visible = true
|
||
coroutine.wait(0.2)
|
||
ShareScreenShotWithOption(function()
|
||
result_view:Dispose()
|
||
end)
|
||
ViewUtil.CloseModalWait()
|
||
break
|
||
end
|
||
coroutine.wait(1)
|
||
left_time = left_time - 1
|
||
end
|
||
end)
|
||
end)
|
||
item:GetChild("btn_link").onClick:Set(function()
|
||
local group_id = record_list_item.group_id and tonumber(record_list_item.group_id) or 0
|
||
ShareChatRoom(record_list_item.RoomId, tostring(os.time()), #item_score_list, room_type_str, group_id, player_list, self._root_view)
|
||
end)
|
||
end
|
||
end
|
||
|
||
function M:ShowRecord2(playback_id, room_type, room_id, room_time, item_score, game_id, develop_tool, record_item)
|
||
local record_list_2
|
||
if develop_tool then
|
||
record_list_2 = self._view:GetChild("lst_round")
|
||
self._view:GetController("developer").selectedIndex = 2
|
||
else
|
||
record_list_2 = self._view:GetChild("n29")
|
||
self._view:GetController("Record").selectedIndex = 1
|
||
end
|
||
|
||
local hpOnOff = record_item.hpOnOff
|
||
local hpType = record_item.GameInfo.hpType
|
||
|
||
record_list_2:RemoveChildrenToPool()
|
||
for i=1,#item_score do
|
||
local item_player_info = item_score[i]
|
||
local play_back_id = item_player_info.PlayBackId
|
||
local player_score = item_player_info.PlayerList
|
||
|
||
local record_item_2 = record_list_2:AddItemFromPool("ui://Rank/Record_Item_2")
|
||
local player_item_list = record_item_2:GetChild("List")
|
||
local more_person = #player_score >= 6
|
||
|
||
if more_person then
|
||
record_item_2:GetController("person_num").selectedIndex = 1
|
||
else
|
||
record_item_2:GetController("person_num").selectedIndex = 0
|
||
end
|
||
|
||
-- 设置房间信息
|
||
record_item_2:GetChild("RoomType").text = room_type
|
||
record_item_2:GetChild("RoomID").text = room_id
|
||
--record_item_2:GetChild("Time").text = room_time
|
||
record_item_2:GetChild("Number").text = tostring(i)
|
||
|
||
player_item_list:RemoveChildrenToPool()
|
||
for j=1,#player_score do
|
||
|
||
local player_item = player_item_list:AddItemFromPool()
|
||
player_item:GetChild("n0").text = player_score[j].Name
|
||
local player_score_text = player_item:GetChild("n1")
|
||
local score = player_score[j].Score
|
||
if hpOnOff == 1 and hpType > 1 then
|
||
score = score / 10
|
||
end
|
||
if score < 0 then
|
||
player_item:GetController("num_color").selectedIndex = 1
|
||
else
|
||
player_item:GetController("num_color").selectedIndex = 0
|
||
end
|
||
player_score_text.text = score >= 0 and "+"..score or score
|
||
|
||
end
|
||
local btn_play_back = record_item_2:GetChild("btn_play_back")
|
||
btn_play_back.onClick:Set(function()
|
||
--print("点击进入回放=====")
|
||
if DataManager.SelfUser.playback[playback_id] ~= nil and DataManager.SelfUser.playback[playback_id][i] ~= nil then
|
||
local room = ExtendManager.GetExtendConfig(game_id):NewRoom()
|
||
DataManager.CurrenRoom = room
|
||
room.game_id = game_id
|
||
local extend = ExtendManager.GetExtendConfig(game_id)
|
||
extend:FillPlayBackData(DataManager.SelfUser.playback[playback_id][i])
|
||
if not room.self_player then
|
||
room.self_player = room:GetPlayerBySeat(1)
|
||
end
|
||
local main = self:GenaratePlayBack(ViewManager.View_PlayBack, game_id)
|
||
main._currentId = playback_id
|
||
main._currentRound = i
|
||
main._totalRound = #item_score
|
||
main:FillRoomData(DataManager.SelfUser.playback[playback_id][i])
|
||
else
|
||
ViewUtil.ShowModalWait(self._view)
|
||
local _data = {}
|
||
_data["military_id"] = playback_id
|
||
_data["round"] = tostring(i)
|
||
local loddyCtr1 = ControllerManager.GetController(LoddyController)
|
||
loddyCtr1:RequestPlayBack(_data,function(code,data)
|
||
ViewUtil.CloseModalWait()
|
||
if code == 0 then
|
||
if DataManager.SelfUser.playback[playback_id] ~= nil then
|
||
DataManager.SelfUser.playback[playback_id][i] = data
|
||
else
|
||
local playback_data = {}
|
||
playback_data[i] = data
|
||
DataManager.SelfUser.playback[playback_id] = playback_data
|
||
end
|
||
|
||
local main = self:GenaratePlayBack(ViewManager.View_PlayBack, game_id)
|
||
main._currentId = playback_id
|
||
main._currentRound = i
|
||
main._totalRound = #item_score
|
||
--print(main)
|
||
main:FillRoomData(data)
|
||
elseif code == 25 then
|
||
ViewUtil.ErrorTip(code, "回放未找到!")
|
||
btn_play_back.grayed = true
|
||
end
|
||
end, record_item.GameInfo)
|
||
|
||
end
|
||
end)
|
||
end
|
||
end
|
||
|
||
function M:GenaratePlayBack(id, game_id, ...)
|
||
local tem =nil
|
||
local dview_class = nil
|
||
if not dview_class then
|
||
local exconfig = ExtendManager.GetExtendConfig(game_id)
|
||
dview_class = exconfig:GetView(id)
|
||
--print(dview_class)
|
||
end
|
||
if not dview_class then
|
||
return
|
||
end
|
||
local arg = {...}
|
||
tem = dview_class.new(...)
|
||
tem.Id = id
|
||
tem:Show()
|
||
return tem
|
||
end
|
||
|
||
function M:Destroy()
|
||
BaseWindow.Destroy(self)
|
||
UIPackage.RemovePackage("base/rank/ui/Rank")
|
||
end
|
||
|
||
return M
|