init.lua 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. if self.debug_menus[menu_name] then
  20. self.console:error('Debug : '..menu_name.." debug menu is already registered.")
  21. return
  22. end
  23. self.debug_menus[menu_name] = windows
  24. end
  25. function Debug:render()
  26. self.debug_menus.Debug.Graphs:update()
  27. if imgui.BeginMainMenuBar() then
  28. for menu,windows in pairs(self.debug_menus) do
  29. -- Menu
  30. if imgui.BeginMenu(menu) then
  31. for k,v in pairs(windows) do
  32. if imgui.MenuItem(k, v.shortcut, v.visible) then
  33. v:toggle()
  34. end
  35. end
  36. imgui.EndMenu()
  37. end
  38. end
  39. imgui.EndMainMenuBar()
  40. for menu,windows in pairs(self.debug_menus) do
  41. for k, window in pairs(windows) do
  42. if window.visible then
  43. window:render()
  44. end
  45. end
  46. end
  47. end
  48. end
  49. function Debug:keypressed(key)
  50. for _, windows in pairs(self.debug_menus) do
  51. for __, window in pairs(windows) do
  52. if window.shortcut and key == window.shortcut then
  53. window:toggle()
  54. end
  55. end
  56. end
  57. end
  58. return Debug