From a128e0d2340d15454d132e3173d65ed8ad2074a1 Mon Sep 17 00:00:00 2001 From: SimonFlapse Date: Sat, 12 Oct 2019 16:57:31 +0200 Subject: [PATCH] Added player count to waiting gui --- map_gen/maps/space_race/config.lua | 2 +- map_gen/maps/space_race/gui/load_gui.lua | 57 +++++++++++++----------- map_gen/maps/space_race/lobby.lua | 7 +-- map_gen/maps/space_race/map_info.lua | 3 +- map_gen/maps/space_race/scenario.lua | 12 +++-- 5 files changed, 43 insertions(+), 38 deletions(-) diff --git a/map_gen/maps/space_race/config.lua b/map_gen/maps/space_race/config.lua index ddcd8494..1e4e9f0d 100644 --- a/map_gen/maps/space_race/config.lua +++ b/map_gen/maps/space_race/config.lua @@ -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, diff --git a/map_gen/maps/space_race/gui/load_gui.lua b/map_gen/maps/space_race/gui/load_gui.lua index eedb71cc..4cbf066a 100644 --- a/map_gen/maps/space_race/gui/load_gui.lua +++ b/map_gen/maps/space_race/gui/load_gui.lua @@ -5,16 +5,19 @@ local Public = {} -- -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 -- -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 diff --git a/map_gen/maps/space_race/lobby.lua b/map_gen/maps/space_race/lobby.lua index 0684e96d..98b37e31 100644 --- a/map_gen/maps/space_race/lobby.lua +++ b/map_gen/maps/space_race/lobby.lua @@ -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 diff --git a/map_gen/maps/space_race/map_info.lua b/map_gen/maps/space_race/map_info.lua index 574cbca3..d571bd66 100644 --- a/map_gen/maps/space_race/map_info.lua +++ b/map_gen/maps/space_race/map_info.lua @@ -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( diff --git a/map_gen/maps/space_race/scenario.lua b/map_gen/maps/space_race/scenario.lua index f79092ed..47875e2a 100644 --- a/map_gen/maps/space_race/scenario.lua +++ b/map_gen/maps/space_race/scenario.lua @@ -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