progress.gui_script 981 B

123456789101112131415161718192021222324252627282930313233343536
  1. -- set the width of the horizontal progress bar
  2. local function update_horizontal(p)
  3. local node = gui.get_node("horizontal")
  4. local size = gui.get_size(node)
  5. size.x = p * 400 -- max width is 400 pixel
  6. gui.set_size(node, size)
  7. end
  8. -- set value of numeric progress indicator (in percent from 0% to 100%)
  9. local function update_numeric(p)
  10. local node = gui.get_node("numeric")
  11. local percent = math.floor(p * 100)
  12. gui.set_text(node, tostring(percent) .. "%")
  13. end
  14. -- update radial/circle progress by changing the fill angle
  15. local function update_radial(p)
  16. local node = gui.get_node("radial")
  17. local angle = p * 360 -- full circle is 360 degrees
  18. gui.set_fill_angle(node, angle)
  19. end
  20. function init(self)
  21. self.time = 0
  22. end
  23. function update(self, dt)
  24. self.time = self.time + dt
  25. -- calculate a value between 0.0 and 1.0
  26. -- the value will gradually increas from 0 to 1 during 3 seconds
  27. local p = (self.time % 3) / 3
  28. update_numeric(p)
  29. update_horizontal(p)
  30. update_radial(p)
  31. end