From 9e423c84f2b70ce6d65775a73105110c96644184 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dexter=20Castor=20D=C3=B6pping?= Date: Mon, 3 Oct 2022 18:35:50 +0200 Subject: [PATCH] Add button for removing component (EntityRemoveComponent) --- components.lua | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/components.lua b/components.lua index 955ed36..5081c5b 100644 --- a/components.lua +++ b/components.lua @@ -9,6 +9,7 @@ component_types = { } local components_watching = {} +local components_to_remove = {} function unwatch_component(component_id) components_watching[component_id] = nil @@ -55,9 +56,15 @@ function show_component_windows() unwatch_component(component) end end + + for _, pair in ipairs(components_to_remove) do + local entity_id, component_id = unpack(pair) + EntityRemoveComponent(entity_id, component_id) + end + components_to_remove = {} end -function toggle_component_button(entity_id, component_id) +function component_attributes(entity_id, component_id) local enabled = ComponentGetIsEnabled(component_id) imgui.Text("Enabled: " .. tostring(enabled)) imgui.SameLine() @@ -65,6 +72,14 @@ function toggle_component_button(entity_id, component_id) if imgui.Button("Toggle") then EntitySetComponentIsEnabled(entity_id, component_id, not enabled) end + + imgui.PushStyleColor(imgui.Col.Button, 1, 0.4, 0.4) + imgui.PushStyleColor(imgui.Col.ButtonHovered, 1, 0.6, 0.6) + imgui.PushStyleColor(imgui.Col.ButtonActive, 0.8, 0.4, 0.4) + if imgui.Button("Remove") then + table.insert(components_to_remove, {entity_id, component_id}) + end + imgui.PopStyleColor(3) end {% set supported_fields = [ @@ -144,7 +159,7 @@ function show_{{ component.name }}_window(entity_id, component_id) imgui.Separator() - toggle_component_button(entity_id, component_id) + component_attributes(entity_id, component_id) show_{{ component.name }}_fields(component_id)