main.lua 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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}, condition="And"},
  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. for i,node in ipairs(array) do node.id = i end
  14. local selected_node = nil
  15. function not_in(v,t)
  16. for k,e in ipairs(t) do
  17. if v == e then return false end
  18. end
  19. return true
  20. end
  21. function draw_action_node(node)
  22. local v = 0
  23. imgui.BeginChildFrame(node.id,0,64, true, {"NoInputs"})
  24. local x,y = imgui.GetCursorPos()
  25. imgui.InvisibleButton("",-1,-1)
  26. if imgui.IsItemClicked() then
  27. selected_node = node
  28. end
  29. imgui.SetCursorPos(x,y)
  30. imgui.Text(node.name)
  31. imgui.Separator()
  32. imgui.EndChildFrame()
  33. end
  34. function draw_array()
  35. imgui.Begin("Array")
  36. imgui.BeginChild("", 0,0, true)
  37. imgui.Columns(2)
  38. local nodes_drawn_in_containers = {}
  39. for i,node in ipairs(array) do
  40. if node.type == "Action" and not_in(i, nodes_drawn_in_containers) then
  41. draw_action_node(node)
  42. elseif node.type == "Container" then
  43. if node.condition == "Or" then
  44. imgui.PushStyleColor("ChildWindowBg", 0.2,0,0,1)
  45. elseif node.condition == "And" then
  46. imgui.PushStyleColor("ChildWindowBg", 0,0.2,0,1)
  47. else
  48. imgui.PushStyleColor("ChildWindowBg", 0,0,0,1)
  49. end
  50. imgui.BeginChild("Container "..i, 0,104, true, {"NoInputs"})
  51. local x,y = imgui.GetCursorPos()
  52. imgui.InvisibleButton("",-1,-1)
  53. if imgui.IsItemClicked() then
  54. selected_node = node
  55. end
  56. imgui.SetCursorPos(x,y)
  57. imgui.Text("Condition | "..node.condition)
  58. imgui.Separator()
  59. imgui.Columns(#node.holding, nil, false)
  60. imgui.PopStyleColor(1)
  61. for k,v in ipairs(node.holding) do
  62. nodes_drawn_in_containers[#nodes_drawn_in_containers + 1] = v
  63. local node = array[v]
  64. draw_action_node(node)
  65. imgui.NextColumn()
  66. end
  67. imgui.PushStyleColor("ChildWindowBg", 1,0,0,1)
  68. imgui.EndChild()
  69. imgui.PopStyleColor(1)
  70. end
  71. end
  72. imgui.NextColumn()
  73. if selected_node then
  74. imgui.Text(selected_node.name)
  75. end
  76. imgui.Button("OK")
  77. imgui.EndChild()
  78. imgui.End()
  79. end
  80. local iui_state = {
  81. array={cbk = draw_array, show=true}
  82. }
  83. function love.load()
  84. end
  85. function love.update(dt)
  86. imgui.NewFrame()
  87. end
  88. function love.draw()
  89. if imgui.BeginMainMenuBar() then
  90. if imgui.BeginMenu("Test") then
  91. for k,v in pairs(iui_state) do
  92. if imgui.MenuItem(k, nil, v.show) then
  93. iui_state[k].show = not iui_state[k].show
  94. end
  95. end
  96. imgui.EndMenu()
  97. end
  98. end
  99. imgui.EndMainMenuBar()
  100. for k,v in pairs(iui_state) do
  101. if v.show then v.cbk() end
  102. end
  103. imgui.Render()
  104. end
  105. function love.quit()
  106. imgui.ShutDown()
  107. end
  108. --
  109. -- User inputs
  110. --
  111. function love.textinput(t)
  112. imgui.TextInput(t)
  113. if not imgui.GetWantCaptureKeyboard() then
  114. -- Pass event to the game
  115. end
  116. end
  117. function love.keypressed(key)
  118. imgui.KeyPressed(key)
  119. if not imgui.GetWantCaptureKeyboard() then
  120. -- Pass event to the game
  121. end
  122. end
  123. function love.keyreleased(key)
  124. imgui.KeyReleased(key)
  125. if not imgui.GetWantCaptureKeyboard() then
  126. -- Pass event to the game
  127. end
  128. end
  129. function love.mousemoved(x, y)
  130. imgui.MouseMoved(x, y)
  131. if not imgui.GetWantCaptureMouse() then
  132. -- Pass event to the game
  133. end
  134. end
  135. function love.mousepressed(x, y, button)
  136. imgui.MousePressed(button)
  137. if not imgui.GetWantCaptureMouse() then
  138. -- Pass event to the game
  139. end
  140. end
  141. function love.mousereleased(x, y, button)
  142. imgui.MouseReleased(button)
  143. if not imgui.GetWantCaptureMouse() then
  144. -- Pass event to the game
  145. end
  146. end
  147. function love.wheelmoved(x, y)
  148. imgui.WheelMoved(y)
  149. if not imgui.GetWantCaptureMouse() then
  150. -- Pass event to the game
  151. end
  152. end