Downloader_UI.gd 1010 B

12345678910111213141516171819202122232425262728293031323334
  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. hide()
  11. # Called every frame. 'delta' is the elapsed time since the previous frame.
  12. #func _process(delta):
  13. # pass
  14. func _on_status_updated(download):
  15. var now = OS.get_ticks_msec()
  16. var timeElapsed=1#(now-last_update)/1000
  17. last_update = now
  18. var diff = (download._downloaded_size - last_downloaded) / 1024
  19. var speed = diff / timeElapsed
  20. last_downloaded = download._downloaded_size
  21. rect_size = $VBoxContainer.rect_size
  22. $VBoxContainer/name.text = download._current_url
  23. $VBoxContainer/size.text = "size: %s"%download._file_size
  24. $VBoxContainer/downloaded.text = "downloaded: %s"%download._downloaded_size
  25. $VBoxContainer/speed.text = "%skb/s"%speed
  26. $VBoxContainer/ProgressBar.value = download._downloaded_percent