main.lua 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. local imgui = require("imgui")
  2. local array = {
  3. {name="Test", type="Action"},
  4. {name="Test2", type="Action"},
  5. {name="Cont", type="Container", holding={4,5,6,7,8}},
  6. {name="Held", type="Action"},
  7. {name="Held", type="Action"},
  8. {name="Held", type="Action"},
  9. {name="Held", type="Action"},
  10. {name="Held", type="Action"},
  11. {name="Held", type="Action"}
  12. }
  13. function not_in(v,t)
  14. for k,e in ipairs(t) do
  15. if v == e then return false end
  16. end
  17. return true
  18. end
  19. function draw_array()
  20. imgui.Begin("Array")
  21. imgui.BeginChild("", 0,0, true)
  22. local nodes_drawn_in_containers = {}
  23. for i,node in ipairs(array) do
  24. if node.type == "Action" and not_in(i, nodes_drawn_in_containers) then
  25. imgui.BeginChildFrame(i, 0,48, true)
  26. imgui.Text(node.name)
  27. imgui.EndChildFrame()
  28. elseif node.type == "Container" then
  29. imgui.BeginChild("Container "..i, 0,64, true)
  30. imgui.Columns(#node.holding, nil, false)
  31. for k,v in ipairs(node.holding) do
  32. nodes_drawn_in_containers[#nodes_drawn_in_containers + 1] = v
  33. local node = array[v]
  34. imgui.BeginChildFrame(v,0,48, true)
  35. imgui.Text(node.name..v)
  36. imgui.Separator()
  37. imgui.EndChildFrame()
  38. imgui.NextColumn()
  39. end
  40. imgui.EndChild()
  41. end
  42. end
  43. imgui.EndChild()
  44. imgui.End()
  45. end
  46. local iui_state = {
  47. array={cbk = draw_array, show=true}
  48. }
  49. function love.load()
  50. end
  51. function love.update(dt)
  52. imgui.NewFrame()
  53. end
  54. function love.draw()
  55. if imgui.BeginMainMenuBar() then
  56. if imgui.BeginMenu("Test") then
  57. for k,v in pairs(iui_state) do
  58. if imgui.MenuItem(k, nil, v.show) then
  59. iui_state[k].show = not iui_state[k].show
  60. end
  61. end
  62. imgui.EndMenu()
  63. end
  64. end
  65. imgui.EndMainMenuBar()
  66. for k,v in pairs(iui_state) do
  67. if v.show then v.cbk() end
  68. end
  69. imgui.Render()
  70. end
  71. function love.quit()
  72. imgui.ShutDown()
  73. end
  74. --
  75. -- User inputs
  76. --
  77. function love.textinput(t)
  78. imgui.TextInput(t)
  79. if not imgui.GetWantCaptureKeyboard() then
  80. -- Pass event to the game
  81. end
  82. end
  83. function love.keypressed(key)
  84. imgui.KeyPressed(key)
  85. if not imgui.GetWantCaptureKeyboard() then
  86. -- Pass event to the game
  87. end
  88. end
  89. function love.keyreleased(key)
  90. imgui.KeyReleased(key)
  91. if not imgui.GetWantCaptureKeyboard() then
  92. -- Pass event to the game
  93. end
  94. end
  95. function love.mousemoved(x, y)
  96. imgui.MouseMoved(x, y)
  97. if not imgui.GetWantCaptureMouse() then
  98. -- Pass event to the game
  99. end
  100. end
  101. function love.mousepressed(x, y, button)
  102. imgui.MousePressed(button)
  103. if not imgui.GetWantCaptureMouse() then
  104. -- Pass event to the game
  105. end
  106. end
  107. function love.mousereleased(x, y, button)
  108. imgui.MouseReleased(button)
  109. if not imgui.GetWantCaptureMouse() then
  110. -- Pass event to the game
  111. end
  112. end
  113. function love.wheelmoved(x, y)
  114. imgui.WheelMoved(y)
  115. if not imgui.GetWantCaptureMouse() then
  116. -- Pass event to the game
  117. end
  118. end