Added entity filering support and fixed minor bug

This commit is contained in:
Mergul 2020-06-10 15:35:42 +02:00
parent 5018464a41
commit 8cba2626be
3 changed files with 48 additions and 12 deletions

View file

@ -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)
{

View file

@ -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();
@ -383,7 +391,6 @@ struct GUIManager
if(components.length)
{
if(igListBoxHeaderInt("Components",cast(int)components.length,cast(int)components.length))
{
{
foreach(i, comp; components)
{
@ -394,7 +401,6 @@ struct GUIManager
}
igListBoxFooter();
}
}
if(igIsItemHovered(0))igSetTooltip("Select component to add/remove (SHIFT + Scroll)");
}
style.Colors[ImGuiCol_Header] = col;
@ -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();

View file

@ -50,7 +50,7 @@ struct Entity
return true;
}
EntityMeta getMeta()
EntityMeta getMeta() const
{
EntityMeta meta;
meta.block = gEM.getMetaData(&this);