diff --git a/features/gui/toast.lua b/features/gui/toast.lua index b3f7162f..56575c9b 100644 --- a/features/gui/toast.lua +++ b/features/gui/toast.lua @@ -70,7 +70,8 @@ end ---Toast to a specific player ---@param player LuaPlayer ---@param duration number in seconds -local function toast_to(player, duration) +---@param sound string sound to play, nil to not play anything +local function toast_to(player, duration, sound) local frame_holder = player.gui.left.add({type = 'flow'}) local frame = @@ -109,6 +110,10 @@ local function toast_to(player, duration) active_toasts[id] = frame_holder + if sound then + player.play_sound({path = sound, volume_modifier = 1}) + end + return container end @@ -162,8 +167,10 @@ on_tick = ---@param player LuaPlayer ---@param duration table ---@param template function -function Public.toast_player_template(player, duration, template) - local container = toast_to(player, duration) +---@param sound string sound to play, nil to not play anything +function Public.toast_player_template(player, duration, template, sound) + sound = sound or 'utility/new_objective' + local container = toast_to(player, duration, sound) if container then template(container, player) end @@ -174,11 +181,13 @@ end ---@param force LuaForce ---@param duration number ---@param template function -function Public.toast_force_template(force, duration, template) +---@param sound string sound to play, nil to not play anything +function Public.toast_force_template(force, duration, template, sound) + sound = sound or 'utility/new_objective' local players = force.connected_players for i = 1, #players do local player = players[i] - template(toast_to(player, duration), player) + template(toast_to(player, duration, sound), player) end end @@ -186,11 +195,13 @@ end ---to add contents to and a player as second argument. ---@param duration number ---@param template function -function Public.toast_all_players_template(duration, template) +---@param sound string sound to play, nil to not play anything +function Public.toast_all_players_template(duration, template, sound) + sound = sound or 'utility/new_objective' local players = game.connected_players for i = 1, #players do local player = players[i] - template(toast_to(player, duration), player) + template(toast_to(player, duration, sound), player) end end diff --git a/map_gen/maps/diggy/feature/experience.lua b/map_gen/maps/diggy/feature/experience.lua index 5762b2c1..40cc7ad0 100644 --- a/map_gen/maps/diggy/feature/experience.lua +++ b/map_gen/maps/diggy/feature/experience.lua @@ -2,6 +2,7 @@ local Event = require 'utils.event' local Game = require 'utils.game' local Global = require 'utils.global' +local Toast = require 'features.gui.toast' local ForceControl = require 'features.force_control' local ScoreTable = require 'map_gen.maps.diggy.score_table' local Retailer = require 'features.retailer' @@ -530,8 +531,7 @@ function Experience.register(cfg) --Adds a function that'll be executed at every level up ForceControlBuilder.register_on_every_level(function (level_reached, force) - force.print(format('%s Leveled up to %d!', '## - ', level_reached)) - force.play_sound{path='utility/new_objective', volume_modifier = 1 } + Toast.toast_force(force, 10 , format('Your team has reached level %d!', level_reached)) Experience.update_inventory_slots(force, level_reached) Experience.update_mining_speed(force, level_reached) Experience.update_health_bonus(force, level_reached)