2022-12-04 18:23:46 -07:00
|
|
|
extends Spatial
|
|
|
|
|
|
|
|
var active = false
|
|
|
|
onready var fsm: AnimationNodeStateMachinePlayback = $Animations/AnimationTree.get("parameters/playback")
|
2022-12-05 09:46:58 -07:00
|
|
|
export var default_screen_color = Color(0.886275, 1, 0, 1)
|
2022-12-04 19:20:58 -07:00
|
|
|
export var screen_off_color = Color(0.0, 0.0, 0.0)
|
|
|
|
var is_screen_on: bool
|
2022-12-04 18:23:46 -07:00
|
|
|
|
2022-12-05 09:46:58 -07:00
|
|
|
onready var util = get_node("/root/Util")
|
|
|
|
onready var player = util.player
|
2022-12-04 19:20:58 -07:00
|
|
|
|
|
|
|
func _ready():
|
|
|
|
is_screen_on = false
|
|
|
|
turn_screen_off()
|
|
|
|
|
|
|
|
func turn_screen_off():
|
|
|
|
var mat = $Animations/walkie_talkie/Body.get_active_material(1)
|
2022-12-05 09:46:58 -07:00
|
|
|
mat.albedo_color = screen_off_color
|
|
|
|
mat.emission_enabled = false
|
2022-12-04 19:20:58 -07:00
|
|
|
is_screen_on = false
|
|
|
|
|
|
|
|
func turn_screen_on():
|
|
|
|
var mat = $Animations/walkie_talkie/Body.get_active_material(1)
|
2022-12-05 09:46:58 -07:00
|
|
|
mat.albedo_color = default_screen_color
|
|
|
|
mat.emission_enabled = true
|
2022-12-04 19:20:58 -07:00
|
|
|
is_screen_on = true
|
|
|
|
|
|
|
|
func toggle_screen():
|
|
|
|
if is_screen_on:
|
|
|
|
turn_screen_off()
|
|
|
|
else:
|
|
|
|
turn_screen_on()
|
2022-12-04 18:23:46 -07:00
|
|
|
|
2022-12-05 09:46:58 -07:00
|
|
|
|
|
|
|
func make_active():
|
2022-12-04 18:23:46 -07:00
|
|
|
if active:
|
2022-12-05 09:46:58 -07:00
|
|
|
return
|
|
|
|
if fsm.is_playing():
|
|
|
|
fsm.travel("WalkieTalkieEnter")
|
2022-12-04 18:23:46 -07:00
|
|
|
else:
|
2022-12-05 09:46:58 -07:00
|
|
|
fsm.start("WalkieTalkieEnter")
|
|
|
|
$StaticBuzz.play()
|
|
|
|
$StaticFizz.play()
|
|
|
|
$Talk.play()
|
|
|
|
$Whale1.play()
|
|
|
|
$Whale2.play()
|
|
|
|
turn_screen_on()
|
|
|
|
$Click.play()
|
|
|
|
active = true
|
2022-12-04 18:23:46 -07:00
|
|
|
|
2022-12-05 09:46:58 -07:00
|
|
|
func make_inactive():
|
|
|
|
if not active:
|
|
|
|
return
|
|
|
|
fsm.travel("WalkieTalkieLeave")
|
|
|
|
$StaticBuzz.stop()
|
|
|
|
$StaticFizz.stop()
|
|
|
|
$Talk.stop()
|
|
|
|
$Whale1.stop()
|
|
|
|
$Whale2.stop()
|
|
|
|
turn_screen_off()
|
|
|
|
$Click.play()
|
|
|
|
active = false
|
|
|
|
|
|
|
|
func toggle_active():
|
|
|
|
if active:
|
|
|
|
make_inactive()
|
|
|
|
else:
|
|
|
|
make_active()
|
|
|
|
|
|
|
|
|
2022-12-04 18:23:46 -07:00
|
|
|
func put_away():
|
|
|
|
fsm.travel("WalkieTalkieLeave")
|
|
|
|
if $DestroyTimer.is_stopped():
|
|
|
|
$DestroyTimer.start(1)
|
|
|
|
|
|
|
|
func _process(_delta):
|
|
|
|
if Input.is_action_just_pressed("toggle_walkie_talkie"):
|
2022-12-05 09:46:58 -07:00
|
|
|
toggle_active()
|
|
|
|
if not active or not fsm.is_playing():
|
|
|
|
return
|
|
|
|
if player.is_ground_sprinting():
|
|
|
|
fsm.travel("WalkieTalkieWalking")
|
|
|
|
else:
|
|
|
|
fsm.travel("WalkieTalkieIdle")
|
2022-12-04 19:20:58 -07:00
|
|
|
|
|
|
|
|
|
|
|
func _on_ScreenFlicker_timeout():
|
|
|
|
if active:
|
|
|
|
toggle_screen()
|