Skip to content

Commit

Permalink
Merge pull request #2 from yongkangchen/master
Browse files Browse the repository at this point in the history
拉取
  • Loading branch information
yuan195820 authored Jan 30, 2018
2 parents c2a9ec4 + 79db126 commit fe11a24
Show file tree
Hide file tree
Showing 6 changed files with 1,497 additions and 520 deletions.
6 changes: 0 additions & 6 deletions Assets/Simple/Lua/game.lua
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,6 @@ return {
play = function()
local init_room = require "room"
return function(player_data, on_over)
player_data = table.copy(player_data)
if player_data.room_data.visitor_id then
player_data.id = player_data.room_data.visitor_id
room_data.is_visit = true
end

local game_name = player_data.room_data.game_name
local play = require(game_name .. "." .. game_name)
return init_room(play, player_data, on_over)
Expand Down
9 changes: 6 additions & 3 deletions Assets/Simple/Lua/lobby.lua
Original file line number Diff line number Diff line change
Expand Up @@ -43,28 +43,31 @@ return function(player_data)

local do_enter_game
local function enter_room(room_id)
local room_data, visitor_id = server:enter(room_id)
room_data.visitor_id = visitor_id

local room_data, is_visit = server:enter(room_id)
local error = ENTER_ERROR[room_data]
if error then
show_hint(error)
return false
end

room_data.is_visit = is_visit

UI.Active(transform, false)
do_enter_game(room_data)
return true
end

local function create_room(game_name, money_type, num, ...)
local room_data = server:create(game_name, money_type, num, ...)

local error = CREATE_ERROR[room_data]
if error then
show_hint(error)
return false
end

room_data.is_visit = room_data.host_start

UI.Active(transform, false)
do_enter_game(room_data)
return true
Expand Down
136 changes: 104 additions & 32 deletions Assets/Simple/Lua/room.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ return function(init_game, player_data, on_over)
local on_close
local room_data = player_data.room_data
local player_id = player_data.id

if room_data.visitor_id then
player_id = room_data.visitor_id
room_data.is_visit = true
end

local role_tbl

local transform = UI.InitPrefab("room")
Expand Down Expand Up @@ -63,8 +69,8 @@ return function(init_game, player_data, on_over)

local function do_quit()
-- LERR("room_data: %s", table.dump(room_data))
if room_data.is_visit then
server.room_out(true)
if room_data.is_visit or (room_data.host_start and room_data.start_count == 0 and room_data.host_id == player_id) then
server.room_out()
player_data.room_data = nil
close()
return
Expand All @@ -86,11 +92,19 @@ return function(init_game, player_data, on_over)
end
end

local function hide_waiting()
UI.Active(transform:Find("waiting"), false)
local blink = transform:Find("desk/blink")
if blink then
UI.Active(blink, true)
end

if room_data.is_visit then
local watch_game = UI.InitPrefab("watch_game", transform)
UI.Active(watch_game, true)
UI.OnClick(watch_game, "quit", do_quit)
if room_data.is_visit then
local sit_down = transform:Find("sit_down")
if sit_down then
sit_down.localPosition = UnityEngine.Vector3(0, 0, 0)
end
end
end

UI.OnClick(transform, "buttons/quit", do_quit)
Expand All @@ -103,14 +117,6 @@ return function(init_game, player_data, on_over)
UI.Active(transform:Find("buttons/voice"), false)
UI.Active(transform:Find("buttons/chat"), false)

local function hide_waiting()
UI.Active(transform:Find("waiting"), false)
local blink = transform:Find("desk/blink")
if blink then
UI.Active(blink, true)
end
end

local prepare = UI.GetComponent(transform, "waiting/prepare", UIToggle)

if not player_data.is_playback then
Expand All @@ -119,6 +125,7 @@ return function(init_game, player_data, on_over)
end)

server.renter()

if room_data.round ~= 1 then
server.ready(true)
end
Expand All @@ -131,27 +138,68 @@ return function(init_game, player_data, on_over)
local startgame = UI.Child(transform, "waiting/startgame")
UI.Active(startgame, false)

if game_cfg.CAN_MID_ENTER then
UI.OnClick(transform, "waiting/startgame", function()
server.start_game()
end)
UI.OnClick(transform, "waiting/startgame", function()
server.start_game()
end)

local show_sit_down
if room_data.can_visit_enter then
UI.Active(transform:Find("waiting/prepare"), false)
UI.Active(transform:Find("waiting/cancel"), false)

if room_data.is_visit then
local sit_down = transform:Find("sit_down")
if sit_down then
show_sit_down = function()
UI.Active(sit_down, room_data.is_visit and room_data.player_size > (table.length(role_tbl) - 1))
end

UI.OnClick(sit_down, nil, function()
server.enter()
end)

if room_data.start_count > 0 then
sit_down.localPosition = UnityEngine.Vector3(0, 0, 0)
else
show_sit_down()
end
end
else
if room_data.host_start and player_id == room_data.host_id then
UI.Active(transform:Find("waiting/invite"), false) --TODO: 这里要处理?
UI.Active(transform:Find("waiting"), true)
end
end
end

local function can_startgame()
if game_cfg.CAN_MID_ENTER then
if game_cfg.CAN_MID_ENTER or room_data.can_visit_enter then
local ready_count = 0
local can_start = false
for _,role in pairs(role_tbl) do

for _, role in pairs(role_tbl) do
if role.data.is_ready then
ready_count = ready_count + 1
end

if role.data.idx == 1 and role.data.id == player_id then
can_start = true
if room_data.host_start then
if player_id == room_data.host_id then
can_start = true
end
else
if role.data.idx == 1 and role.data.id == player_id then
can_start = true
end
end
end

if can_start and ready_count > 1 and ready_count == table.length(role_tbl) and room_data.start_count == 0 then
local player_size = table.length(role_tbl)
if room_data.is_visit then
player_size = player_size - 1
-- ready_count = ready_count - 1
end

if can_start and room_data.start_count == 0 and ready_count > 1 and ready_count == player_size then
UI.Active(startgame, true)
return
end
Expand All @@ -160,10 +208,6 @@ return function(init_game, player_data, on_over)
end

server.listen(msg.READY, function(id, is_ready, count)
if room_data.is_visit then
return
end

if id == player_id then
prepare.value = is_ready
end
Expand Down Expand Up @@ -202,6 +246,9 @@ return function(init_game, player_data, on_over)
show_hint("已经退出房间!")
end
role_tbl[pid] = nil
if show_sit_down then
show_sit_down()
end
end)

server.listen(msg.APPLY, function(dismiss_tbl, dismiss_time)
Expand All @@ -218,8 +265,24 @@ return function(init_game, player_data, on_over)
end)
end)

server.listen(msg.VISITOR, function(visit_player, is_sit)
if player_data.id == visit_player and is_sit then
room_data.is_visit = nil
if on_close then
on_close()
end
return
end

-- if type(visit_player) == "table" then
-- --TODO: 填充数据
-- else
-- --TODO: 删除
-- end
end)

local on_init_role
server.listen(msg.INIT, function(data, distance)
server.listen(msg.INIT, function(data, distance) --观战状态进入游戏
data.src_distance = distance
if distance < 0 then
distance = distance + room_data.player_size
Expand All @@ -243,17 +306,26 @@ return function(init_game, player_data, on_over)
hide_waiting()
role.start(true)
else
if not room_data.is_visit then
role.prepare(data.is_ready)
end
role.prepare(data.is_ready)
if room_data.round > 1 then
role.show_score()
end
end
role.score(data.score)

if room_data.host_start then --房主坐下
can_startgame()
end

if show_sit_down then
show_sit_down()
end
end)

on_init_role, role_tbl, on_close = init_game(table.copy(player_data), transform, close)
local game_player_data = table.copy(player_data)
game_player_data.id = player_id

on_init_role, role_tbl, on_close = init_game(game_player_data, transform, close)

player_data.role_tbl = role_tbl

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
59 changes: 59 additions & 0 deletions Assets/UI/Res/205房间游戏中(3人)/words_zuoxia.png.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit fe11a24

Please sign in to comment.