top_panel.gd 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. extends Node2D
  2. # Declare member variables here. Examples:
  3. # var a = 2
  4. # var b = "text"
  5. onready var panel_height = 0.2 * get_viewport().size.y
  6. var BG_COLOR = ColorN("black")
  7. var bg_rect
  8. var ping_ratio = 0.2
  9. var time_left_v_ratio = 0.3
  10. var planet
  11. onready var target_y = -panel_height*2
  12. var ping_rect
  13. var jam_progress_bar
  14. var time_left_bar
  15. func activate(_planet):
  16. print("top_panel activated")
  17. planet = _planet
  18. target_y = 0.0
  19. for c in [time_left_bar,jam_progress_bar,ping_rect]:
  20. c.activate()
  21. func deactivate():
  22. for c in [time_left_bar,jam_progress_bar,ping_rect]:
  23. c.deactivate()
  24. planet = null
  25. target_y = -panel_height*2
  26. # Called when the node enters the scene tree for the first time.
  27. func _ready():
  28. var ping_rect_width
  29. var progress_width
  30. ping_rect_width = get_viewport().size.x * ping_ratio
  31. progress_width = get_viewport().size.x - ping_rect_width
  32. var time_left_bar_height = time_left_v_ratio*panel_height
  33. var jam_progress_bar_height = panel_height - time_left_bar_height
  34. bg_rect = ColorRect.new()
  35. bg_rect.rect_size = Vector2(get_viewport().size.x, panel_height)
  36. bg_rect.color = ColorN("black")
  37. call_deferred("add_child", bg_rect)
  38. ping_rect = PingRect.new()
  39. ping_rect.rect_size = Vector2(ping_rect_width,panel_height)
  40. call_deferred("add_child",ping_rect)
  41. jam_progress_bar = JamProgressBar.new()
  42. jam_progress_bar.rect_position = Vector2(ping_rect_width,0)
  43. jam_progress_bar.rect_size = Vector2(progress_width,jam_progress_bar_height)
  44. call_deferred("add_child",jam_progress_bar)
  45. time_left_bar = TimeLeftBar.new()
  46. time_left_bar.rect_position = Vector2(ping_rect_width,jam_progress_bar_height)
  47. time_left_bar.rect_size = Vector2(progress_width,time_left_bar_height)
  48. call_deferred("add_child",time_left_bar)
  49. pass # Replace with function body.
  50. func _process(delta):
  51. position.y += (target_y - position.y)*0.11