Chat.gd 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. extends Popper
  2. class_name Chat
  3. var label
  4. var tw = Tween.new()
  5. var sp = AudioStreamPlayer3D.new()
  6. var just_spawned
  7. var buffer = Array()
  8. signal buffer_ended
  9. var cur_message = 0
  10. var offset = Vector3(0,-8,0)
  11. onready var clock = find_parent("MAIN").find_node("Clock")
  12. func _process(delta):
  13. if Input.is_action_just_pressed("interact"):
  14. if just_spawned:
  15. just_spawned=false
  16. return
  17. #print("detecting input")
  18. read_buffer()
  19. just_spawned=false
  20. func _ready():
  21. just_spawned = true
  22. #print("chat readying")
  23. add_child(tw)
  24. scale = Vector3(0.078,0.078,0.078)
  25. connect("buffer_ended",self,"end")
  26. clock.stop_time()
  27. #print("chat ready")
  28. get_parent().get_parent().root()
  29. func end():
  30. if not clock.startlock:
  31. clock.start_time()
  32. get_parent().get_parent().PLAYER.end_chat()
  33. func read_buffer():
  34. if buffer==null:
  35. return
  36. if cur_message<buffer.size():
  37. message(buffer[cur_message])
  38. cur_message+=1
  39. else:
  40. emit_signal("buffer_ended")
  41. cur_message=0
  42. buffer=null
  43. func message(msg):
  44. play_sound()
  45. if label!=null:
  46. label.queue_free()
  47. label = Label3D.new()
  48. label.text = msg
  49. label.color = Color8(200,200,110)
  50. label.power = 2.0
  51. label.translation = offset
  52. tw.interpolate_property(label,"translation",offset,Vector3(0,0,0),1.0,Tween.TRANS_CUBIC,Tween.EASE_OUT)
  53. tw.start()
  54. add_child(label)
  55. func close():
  56. queue_free()
  57. # Called every frame. 'delta' is the elapsed time since the previous frame.
  58. #func _process(delta):
  59. # pass