TIME_LEFT_BAR.gd 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. extends ColorRect
  2. class_name TimeLeftBar
  3. var max_time_left = 10.0
  4. var time_left = max_time_left
  5. var active = false
  6. var time_left_bar_bg = ColorN("white")
  7. var time_left_bar_fg = ColorN("gray").darkened(0.3)
  8. onready var TOP_PANEL = find_parent("top_panel")
  9. var fg_rect
  10. var ping_label
  11. # Called when the node enters the scene tree for the first time.
  12. func _ready():
  13. color = time_left_bar_bg
  14. fg_rect = ColorRect.new()
  15. fg_rect.color = time_left_bar_fg
  16. fg_rect.rect_size.y = rect_size.y
  17. call_deferred("add_child",fg_rect)
  18. ping_label = FontedLabel.new()
  19. ping_label.rect_size = rect_size
  20. ping_label.font_size = rect_size.y * 0.4
  21. ping_label.align = Label.ALIGN_CENTER
  22. ping_label.valign = Label.ALIGN_CENTER
  23. ping_label.text = "ping label"
  24. ping_label.modulate = ColorN("black")
  25. call_deferred("add_child",ping_label)
  26. func _process(delta):
  27. if active:
  28. time_left -=delta
  29. ping_label.text = str(floor(time_left*10)/10.0)
  30. fg_rect.rect_size.x = (max_time_left - time_left)/max_time_left*rect_size.x
  31. func activate():
  32. active = true
  33. max_time_left = TOP_PANEL.planet.jam_till_finish + 1
  34. time_left = max_time_left
  35. func deactivate():
  36. active = false
  37. # Called every frame. 'delta' is the elapsed time since the previous frame.
  38. #func _process(delta):
  39. # pass