| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- local imgui = require("imgui")
- local array = {
- {name="Test", type="Action"},
- {name="Test2", type="Action"},
- {name="Cont", type="Container", holding={4,5,6,7,8}},
- {name="Held", type="Action"},
- {name="Held", type="Action"},
- {name="Held", type="Action"},
- {name="Held", type="Action"},
- {name="Held", type="Action"},
- {name="Held", type="Action"}
- }
- function not_in(v,t)
- for k,e in ipairs(t) do
- if v == e then return false end
- end
- return true
- end
- function draw_array()
- imgui.Begin("Array")
- imgui.BeginChild("", 0,0, true)
- local nodes_drawn_in_containers = {}
- for i,node in ipairs(array) do
- if node.type == "Action" and not_in(i, nodes_drawn_in_containers) then
- imgui.BeginChildFrame(i, 0,48, true)
- imgui.Text(node.name)
- imgui.EndChildFrame()
- elseif node.type == "Container" then
- imgui.BeginChild("Container "..i, 0,64, true)
- imgui.Columns(#node.holding, nil, false)
- for k,v in ipairs(node.holding) do
- nodes_drawn_in_containers[#nodes_drawn_in_containers + 1] = v
- local node = array[v]
- imgui.BeginChildFrame(v,0,48, true)
- imgui.Text(node.name..v)
- imgui.Separator()
- imgui.EndChildFrame()
- imgui.NextColumn()
- end
- imgui.EndChild()
- end
- end
- imgui.EndChild()
- imgui.End()
- end
- local iui_state = {
- array={cbk = draw_array, show=true}
- }
- function love.load()
- end
- function love.update(dt)
- imgui.NewFrame()
- end
- function love.draw()
- if imgui.BeginMainMenuBar() then
- if imgui.BeginMenu("Test") then
- for k,v in pairs(iui_state) do
- if imgui.MenuItem(k, nil, v.show) then
- iui_state[k].show = not iui_state[k].show
- end
- end
- imgui.EndMenu()
- end
- end
- imgui.EndMainMenuBar()
- for k,v in pairs(iui_state) do
- if v.show then v.cbk() end
- end
- imgui.Render()
- end
- function love.quit()
- imgui.ShutDown()
- end
- --
- -- User inputs
- --
- function love.textinput(t)
- imgui.TextInput(t)
- if not imgui.GetWantCaptureKeyboard() then
- -- Pass event to the game
- end
- end
- function love.keypressed(key)
- imgui.KeyPressed(key)
- if not imgui.GetWantCaptureKeyboard() then
- -- Pass event to the game
- end
- end
- function love.keyreleased(key)
- imgui.KeyReleased(key)
- if not imgui.GetWantCaptureKeyboard() then
- -- Pass event to the game
- end
- end
- function love.mousemoved(x, y)
- imgui.MouseMoved(x, y)
- if not imgui.GetWantCaptureMouse() then
- -- Pass event to the game
- end
- end
- function love.mousepressed(x, y, button)
- imgui.MousePressed(button)
- if not imgui.GetWantCaptureMouse() then
- -- Pass event to the game
- end
- end
- function love.mousereleased(x, y, button)
- imgui.MouseReleased(button)
- if not imgui.GetWantCaptureMouse() then
- -- Pass event to the game
- end
- end
- function love.wheelmoved(x, y)
- imgui.WheelMoved(y)
- if not imgui.GetWantCaptureMouse() then
- -- Pass event to the game
- end
- end
|