| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178 |
- local imgui = require("imgui")
- local array = {
- {name="Test", type="Action"},
- {name="Test2", type="Action"},
- {name="Cont", type="Container", holding={4,5,6,7,8}, condition="And"},
- {name="Held", type="Action"},
- {name="Held", type="Action"},
- {name="Held", type="Action"},
- {name="Held", type="Action"},
- {name="Held", type="Action"},
- {name="Held", type="Action"}
- }
- for i,node in ipairs(array) do node.id = i end
- local selected_node = nil
- 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_action_node(node)
- local v = 0
- imgui.BeginChildFrame(node.id,0,64, true, {"NoInputs"})
- local x,y = imgui.GetCursorPos()
- imgui.InvisibleButton("",-1,-1)
- if imgui.IsItemClicked() then
- selected_node = node
- end
- imgui.SetCursorPos(x,y)
- imgui.Text(node.name)
- imgui.Separator()
- imgui.EndChildFrame()
- end
- function draw_array()
- imgui.Begin("Array")
- imgui.BeginChild("", 0,0, true)
- imgui.Columns(2)
- 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
- draw_action_node(node)
- elseif node.type == "Container" then
- if node.condition == "Or" then
- imgui.PushStyleColor("ChildWindowBg", 0.2,0,0,1)
- elseif node.condition == "And" then
- imgui.PushStyleColor("ChildWindowBg", 0,0.2,0,1)
- else
- imgui.PushStyleColor("ChildWindowBg", 0,0,0,1)
- end
- imgui.BeginChild("Container "..i, 0,104, true, {"NoInputs"})
- local x,y = imgui.GetCursorPos()
- imgui.InvisibleButton("",-1,-1)
- if imgui.IsItemClicked() then
- selected_node = node
- end
- imgui.SetCursorPos(x,y)
- imgui.Text("Condition | "..node.condition)
- imgui.Separator()
- imgui.Columns(#node.holding, nil, false)
- imgui.PopStyleColor(1)
- for k,v in ipairs(node.holding) do
- nodes_drawn_in_containers[#nodes_drawn_in_containers + 1] = v
- local node = array[v]
- draw_action_node(node)
- imgui.NextColumn()
- end
- imgui.PushStyleColor("ChildWindowBg", 1,0,0,1)
- imgui.EndChild()
- imgui.PopStyleColor(1)
- end
- end
- imgui.NextColumn()
- if selected_node then
- imgui.Text(selected_node.name)
- end
- imgui.Button("OK")
- 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
|