1
0
mirror of https://github.com/Refactorio/RedMew.git synced 2024-12-12 10:04:40 +02:00

Added a notification sound for toast messages

This commit is contained in:
Lynn 2019-02-02 14:21:43 +01:00
parent 0179a1d96d
commit 9892d1a569
2 changed files with 20 additions and 9 deletions

View File

@ -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

View File

@ -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)