Added entity filering support and fixed minor bug
This commit is contained in:
parent
5018464a41
commit
8cba2626be
3 changed files with 48 additions and 12 deletions
|
|
@ -134,9 +134,21 @@ struct Launcher
|
|||
vec2 position;
|
||||
ComponentRef[] add_comps;
|
||||
ushort[] rem_comps;
|
||||
ushort[] filter;
|
||||
|
||||
bool filterEntity(ref const Entity entity)
|
||||
{
|
||||
EntityMeta meta = entity.getMeta();
|
||||
foreach(id;filter)
|
||||
{
|
||||
if(!meta.hasComponent(id))return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void removeEntity(IteratorSystem.EntitiesData data)
|
||||
{
|
||||
if(!filterEntity(data.entity[0]))return;
|
||||
foreach(i;0..data.length)
|
||||
{
|
||||
vec2 rel_vec = data.location[i] - position;
|
||||
|
|
@ -147,6 +159,7 @@ struct Launcher
|
|||
|
||||
void addComponent(IteratorSystem.EntitiesData data)
|
||||
{
|
||||
if(!filterEntity(data.entity[0]))return;
|
||||
foreach(i;0..data.length)
|
||||
{
|
||||
vec2 rel_vec = data.location[i] - position;
|
||||
|
|
@ -157,6 +170,7 @@ struct Launcher
|
|||
|
||||
void overrideComponent(IteratorSystem.EntitiesData data)
|
||||
{
|
||||
if(!filterEntity(data.entity[0]))return;
|
||||
foreach(i;0..data.length)
|
||||
{
|
||||
vec2 rel_vec = data.location[i] - position;
|
||||
|
|
@ -171,6 +185,7 @@ struct Launcher
|
|||
|
||||
void removeComponent(IteratorSystem.EntitiesData data)
|
||||
{
|
||||
if(!filterEntity(data.entity[0]))return;
|
||||
foreach(i;0..data.length)
|
||||
{
|
||||
vec2 rel_vec = data.location[i] - position;
|
||||
|
|
@ -185,6 +200,7 @@ struct Launcher
|
|||
Iterator iterator;
|
||||
iterator.size2 = size2;
|
||||
iterator.position = position;
|
||||
iterator.filter = gui_manager.filter_list[];
|
||||
|
||||
switch(used_tool)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -27,6 +27,8 @@ struct GUIManager
|
|||
Vector!ComponentGUI components;
|
||||
Vector!TemplateGUI templates;
|
||||
Vector!ComponentEditGUI edit_components;
|
||||
Vector!bool filter;
|
||||
Vector!ushort filter_list;
|
||||
|
||||
int selected_template = 0;
|
||||
int selected_component = 0;
|
||||
|
|
@ -62,8 +64,14 @@ struct GUIManager
|
|||
if(comp.variables)Mallocator.dispose(comp.variables);
|
||||
comp.variables = null;
|
||||
comp.used = 0;
|
||||
comp.name = null;
|
||||
}
|
||||
foreach(ref comp; filter)
|
||||
{
|
||||
comp = false;
|
||||
}
|
||||
|
||||
filter_list.clear();
|
||||
systems.clear();
|
||||
templates.clear();
|
||||
components.clear();
|
||||
|
|
@ -384,16 +392,14 @@ struct GUIManager
|
|||
{
|
||||
if(igListBoxHeaderInt("Components",cast(int)components.length,cast(int)components.length))
|
||||
{
|
||||
foreach(i, comp; components)
|
||||
{
|
||||
foreach(i, comp; components)
|
||||
if(igSelectable(comp.name,selected_component == i,0,ImVec2(0,0)))
|
||||
{
|
||||
if(igSelectable(comp.name,selected_component == i,0,ImVec2(0,0)))
|
||||
{
|
||||
selected_component = cast(uint)i;
|
||||
}
|
||||
selected_component = cast(uint)i;
|
||||
}
|
||||
igListBoxFooter();
|
||||
}
|
||||
igListBoxFooter();
|
||||
}
|
||||
if(igIsItemHovered(0))igSetTooltip("Select component to add/remove (SHIFT + Scroll)");
|
||||
}
|
||||
|
|
@ -407,26 +413,40 @@ struct GUIManager
|
|||
style.Colors[ImGuiCol_Header] = col;
|
||||
}
|
||||
|
||||
private void genFilterList()
|
||||
{
|
||||
filter_list.clear();
|
||||
foreach(i, comp; filter)
|
||||
{
|
||||
if(comp)
|
||||
{
|
||||
filter_list.add(cast(ushort)i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void filterGUI()
|
||||
{
|
||||
ImGuiStyle * style = igGetStyle();
|
||||
ImVec4 col = style.Colors[ImGuiCol_Header];
|
||||
style.Colors[ImGuiCol_Header] = style.Colors[ImGuiCol_TextSelectedBg];
|
||||
|
||||
if(filter.length < edit_components.length)filter.length(edit_components.length);
|
||||
|
||||
int length = 0;
|
||||
foreach(comp; edit_components)
|
||||
{
|
||||
if(comp.name !is null)length++;
|
||||
}
|
||||
|
||||
if(length && igListBoxHeaderInt("Components",cast(int)length,cast(int)length))
|
||||
if(length && igListBoxHeaderInt("Components##FilterComponents",cast(int)length,cast(int)length))
|
||||
{
|
||||
foreach(i, comp; edit_components)
|
||||
foreach(i, ref comp; edit_components)
|
||||
{
|
||||
if(comp.name is null)return;
|
||||
if(igSelectable(comp.name,false,0,ImVec2(0,0)))
|
||||
if(comp.name is null)continue;
|
||||
if(igSelectableBoolPtr(comp.name,&filter[i],0,ImVec2(0,0)))
|
||||
{
|
||||
|
||||
genFilterList();
|
||||
}
|
||||
}
|
||||
igListBoxFooter();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue