1
0
mirror of https://github.com/Refactorio/RedMew.git synced 2025-01-30 04:30:58 +02:00

Added player count to waiting gui

This commit is contained in:
SimonFlapse 2019-10-12 16:57:31 +02:00
parent 8a304ccb69
commit a128e0d234
5 changed files with 43 additions and 38 deletions

View File

@ -1,5 +1,5 @@
local Config = {
version = 'v0.2',
version = 'v0.3',
players_needed_to_start_game = 1,
bootstrap_period = 60 * 60 * 10, -- 10 minutes
player_kill_reward = 25,

View File

@ -5,16 +5,19 @@ local Public = {}
-- <Load GUI start>
function Public.show_gui(event)
function Public.show_gui(event, message)
local frame
local player = game.get_player(event.player_index)
local center = player.gui.center
local gui = center['Space-Race-Waiting']
local gui = center['Space-Race-Lobby']
if (gui) then
Gui.destroy(gui)
end
frame = player.gui.center.add {name = 'Space-Race-Waiting', type = 'frame', direction = 'vertical', style = 'captionless_frame'}
local show_timer = message == nil
local caption = message or 'Waiting for map to generate\n\n... Please wait ...\n'
frame = player.gui.center.add {name = 'Space-Race-Lobby', type = 'frame', direction = 'vertical', style = 'captionless_frame'}
frame.style.minimal_width = 300
@ -42,45 +45,49 @@ function Public.show_gui(event)
label_flow.style.horizontal_align = 'center'
label_flow.style.horizontally_stretchable = true
local label = label_flow.add {type = 'label', caption = 'Waiting for map to generate\n\n... Please wait ...\n'}
local label = label_flow.add {type = 'label', caption = caption}
label.style.horizontal_align = 'center'
label.style.single_line = false
label.style.font = 'default'
label.style.font_color = Color.yellow
local started_tick = remote.call('space-race', 'get_started_tick')
local time = game.tick - started_tick
if show_timer then
local started_tick = remote.call('space-race', 'get_started_tick')
local time = game.tick - started_tick
if time > 60 then
local minutes = (time / 3600)
minutes = minutes - minutes % 1
time = time - (minutes * 3600)
local seconds = (time / 60)
seconds = seconds - seconds % 1
time = minutes .. ' minutes and ' .. seconds .. ' seconds'
else
local seconds = (time - (time % 60)) / 60
time = seconds .. ' seconds'
if time > 60 then
local minutes = (time / 3600)
minutes = minutes - minutes % 1
time = time - (minutes * 3600)
local seconds = (time / 60)
seconds = seconds - seconds % 1
time = minutes .. ' minutes and ' .. seconds .. ' seconds'
else
local seconds = (time - (time % 60)) / 60
time = seconds .. ' seconds'
end
label = label_flow.add {type = 'label', caption = '[color=blue]Time elapsed: ' .. time .. ' [/color]'}
label.style.horizontal_align = 'center'
label.style.single_line = false
label.style.font = 'default'
end
label = label_flow.add {type = 'label', caption = '[color=blue]Time elapsed: ' .. time .. ' [/color]'}
label.style.horizontal_align = 'center'
label.style.single_line = false
label.style.font = 'default'
end
-- <Load GUI end>
function Public.show_gui_to_all()
function Public.show_gui_to_all(message)
for _, player in pairs(game.connected_players) do
Public.show_gui({player_index = player.index})
if player.force ~= 'player' then
Public.show_gui({player_index = player.index}, message)
end
end
end
function Public.remove_gui()
for _, player in pairs(game.connected_players) do
for _, player in pairs(game.players) do
local center = player.gui.center
local gui = center['Space-Race-Waiting']
local gui = center['Space-Race-Lobby']
if (gui) then
Gui.destroy(gui)
end

View File

@ -29,8 +29,7 @@ local players_needed = config.players_needed_to_start_game
local function check_snake_map_gen()
local surface = game.get_surface('snake')
return surface.get_tile({snake_check_x, -snake_check_y}).name == 'out-of-map'
and surface.get_tile({snake_check_x, snake_check_y}).name == 'out-of-map'
return surface.get_tile({snake_check_x, -snake_check_y}).name == 'out-of-map' and surface.get_tile({snake_check_x, snake_check_y}).name == 'out-of-map'
end
local snake_generate =
@ -41,7 +40,9 @@ local snake_generate =
local position = {x = -floor(size), y = 5}
local max_food = config.snake.max_food
local speed = config.snake.speed
snake_game.start_game(surface, position, size, speed, max_food)
if not snake_game.is_running() then
snake_game.start_game(surface, position, size, speed, max_food)
end
else
Task.set_timeout_in_ticks(5, delay_snake_checker)
end

View File

@ -43,8 +43,7 @@ Coming Soon:
- Capture the Flag
- Team Death Match (Lol. NO)
Current Version: v0.2
]]
Current Version: ]] .. config.version
)
ScenarioInfo.set_new_info(

View File

@ -397,13 +397,11 @@ local function check_ready_to_start()
Event.add_removable_nth_tick(60, check_map_gen_is_done)
end
else
game.print(
'[color=yellow]' ..
primitives.force_USA.name ..
' has [/color][color=red]' ..
num_usa_players ..
'[/color][color=yellow] players | ' .. primitives.force_USSR.name .. ' has [/color][color=red]' .. num_ussr_players .. '[/color][color=yellow] players | [/color][color=red]' .. players_needed - num_players .. '[/color][color=yellow] more players needed to start! [/color]'
)
local message = primitives.force_USA.name ..
' has ' ..
num_usa_players ..
' players\n ' .. primitives.force_USSR.name .. ' has ' .. num_ussr_players .. ' players\n\n' .. players_needed - num_players .. ' more players needed to start!'
load_gui.show_gui_to_all(message)
end
end