init.lua 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. local class, object = require("class"), require("class.object")
  2. local Console = require("debug_overlay.console")
  3. local Graphs = require("debug_overlay.graphs")
  4. local Watch = require("debug_overlay.watch")
  5. require("imgui")
  6. local Debug = class(object)
  7. function Debug:init()
  8. self.debug_menus = {
  9. Debug = {
  10. Console = Console:new(),
  11. Watch = Watch:new(),
  12. Graphs = Graphs:new(),
  13. }
  14. }
  15. self.console = self.debug_menus.Debug.Console
  16. self.watch = self.debug_menus.Debug.Watch
  17. end
  18. function Debug:register_menu(menu_name, windows)
  19. assert(not self.debug_menus[menu_name])
  20. self.debug_menus[menu_name] = windows
  21. end
  22. function Debug:render()
  23. self.debug_menus.Debug.Graphs:update()
  24. if imgui.BeginMainMenuBar() then
  25. for menu,windows in pairs(self.debug_menus) do
  26. -- Menu
  27. if imgui.BeginMenu(menu) then
  28. for k,v in pairs(windows) do
  29. if imgui.MenuItem(k, v.shortcut, v.visible) then
  30. v:toggle()
  31. end
  32. end
  33. imgui.EndMenu()
  34. end
  35. end
  36. imgui.EndMainMenuBar()
  37. for menu,windows in pairs(self.debug_menus) do
  38. for k, window in pairs(windows) do
  39. if window.visible then
  40. window:render()
  41. end
  42. end
  43. end
  44. end
  45. end
  46. function Debug:keypressed(key)
  47. for _, windows in pairs(self.debug_menus) do
  48. for __, window in pairs(windows) do
  49. if window.shortcut and key == window.shortcut then
  50. window:toggle()
  51. end
  52. end
  53. end
  54. end
  55. return Debug