Downloader_UI.gd 1002 B

123456789101112131415161718192021222324252627282930313233
  1. extends Panel
  2. # Declare member variables here. Examples:
  3. # var a = 2
  4. # var b = "text"
  5. var last_downloaded=0
  6. var last_update=OS.get_ticks_msec()
  7. # Called when the node enters the scene tree for the first time.
  8. func _ready():
  9. Messenger.connect("statusUpdate", self, "_on_status_updated")
  10. # Called every frame. 'delta' is the elapsed time since the previous frame.
  11. #func _process(delta):
  12. # pass
  13. func _on_status_updated(download):
  14. var now = OS.get_ticks_msec()
  15. var timeElapsed=1#(now-last_update)/1000
  16. last_update = now
  17. var diff = (download._downloaded_size - last_downloaded) / 1024
  18. var speed = diff / timeElapsed
  19. last_downloaded = download._downloaded_size
  20. rect_size = $VBoxContainer.rect_size
  21. $VBoxContainer/name.text = download._current_url
  22. $VBoxContainer/size.text = "size: %s"%download._file_size
  23. $VBoxContainer/downloaded.text = "downloaded: %s"%download._downloaded_size
  24. $VBoxContainer/speed.text = "%skb/s"%speed
  25. $VBoxContainer/ProgressBar.value = download._downloaded_percent