forked from unfa/liblast
Made the game mute itself automatically when loosing focus
parent
32a7aba47c
commit
407b512889
19
Game/Main.gd
19
Game/Main.gd
|
@ -23,6 +23,7 @@ var player_scene = preload("res://Assets/Characters/Player.tscn")
|
|||
var local_player: Node = null
|
||||
|
||||
var local_player_focus_previous: GameFocus # to store focus that should be set after AWAY is gone
|
||||
var mute_previous: bool
|
||||
|
||||
class PlayerInfo:
|
||||
var name: String
|
||||
|
@ -79,17 +80,32 @@ var game_score_limit = 10 #15
|
|||
|
||||
const destroy_free_player_crash_workaround = true
|
||||
|
||||
func get_mute() -> bool:
|
||||
return AudioServer.is_bus_mute(0)
|
||||
|
||||
func set_mute(mute) -> void:
|
||||
if mute == null: # toggle
|
||||
AudioServer.set_bus_mute(0, not get_mute())
|
||||
else:
|
||||
AudioServer.set_bus_mute(0, mute)
|
||||
# update the HUD icon
|
||||
hud.get_node("MuteIcon").visible = get_mute()
|
||||
|
||||
func _notification(what: int) -> void:
|
||||
match what:
|
||||
NOTIFICATION_APPLICATION_FOCUS_OUT:
|
||||
Engine.target_fps = 5
|
||||
mute_previous = get_mute()
|
||||
set_mute(true)
|
||||
if local_player:
|
||||
local_player_focus_previous = focus
|
||||
focus = GameFocus.AWAY
|
||||
|
||||
|
||||
NOTIFICATION_APPLICATION_FOCUS_IN:
|
||||
# `0` means "unlimited".
|
||||
Engine.target_fps = 0
|
||||
set_mute(mute_previous)
|
||||
if local_player:
|
||||
focus = local_player_focus_previous
|
||||
|
||||
|
@ -206,8 +222,7 @@ func _input(_event) -> void:
|
|||
chat.chat_notification("Screenshot taken: " + str(res))
|
||||
|
||||
if Input.is_action_just_pressed("mute_audio"):
|
||||
AudioServer.set_bus_mute(0, not AudioServer.is_bus_mute(0))
|
||||
hud.get_node("MuteIcon").visible = AudioServer.is_bus_mute(0)
|
||||
set_mute(null)
|
||||
|
||||
@rpc(any_peer, call_local, reliable) func game_over(winner):
|
||||
if local_player:
|
||||
|
|
Loading…
Reference in New Issue