Demo GUI fixes and improvements plus some shortcuts
-added option to override components (by remove them before adding) -added shortcuts for tools -fixed mouse scroll on WASM -addding entity filtering option (WIP) -added some tooltips -remove Components duplicates in ComponentManipulator menu -fixed ImGUI controls IDs -added possibility to change values of component to add
This commit is contained in:
parent
e76c5ccdb2
commit
5018464a41
4 changed files with 237 additions and 100 deletions
|
|
@ -28,8 +28,24 @@ struct GUIManager
|
|||
Vector!TemplateGUI templates;
|
||||
Vector!ComponentEditGUI edit_components;
|
||||
|
||||
uint selected_tempalte = 0;
|
||||
uint selected_component = 0;
|
||||
int selected_template = 0;
|
||||
int selected_component = 0;
|
||||
|
||||
void selectTemplate(int id)
|
||||
{
|
||||
if(templates.length == 0)return;
|
||||
selected_template = id;
|
||||
while(selected_template < 0)selected_template += cast(int)templates.length;
|
||||
while(selected_template >= templates.length)selected_template -= cast(int)templates.length;
|
||||
}
|
||||
|
||||
void selectComponent(int id)
|
||||
{
|
||||
if(components.length == 0)return;
|
||||
selected_component = id;
|
||||
while(selected_component < 0)selected_component += cast(int)components.length;
|
||||
while(selected_component >= components.length)selected_component -= cast(int)components.length;
|
||||
}
|
||||
|
||||
void clear()
|
||||
{
|
||||
|
|
@ -51,13 +67,13 @@ struct GUIManager
|
|||
systems.clear();
|
||||
templates.clear();
|
||||
components.clear();
|
||||
selected_tempalte = 0;
|
||||
selected_template = 0;
|
||||
selected_component = 0;
|
||||
}
|
||||
|
||||
EntityTemplate* getSelectedTemplate()
|
||||
{
|
||||
if(templates.length > selected_tempalte)return templates[selected_tempalte].tmpl;
|
||||
if(templates.length > selected_template)return templates[selected_template].tmpl;
|
||||
else return null;
|
||||
}
|
||||
|
||||
|
|
@ -271,57 +287,65 @@ struct GUIManager
|
|||
}
|
||||
}
|
||||
|
||||
void componentGUI(ushort comp_id, void* data_ptr)
|
||||
{
|
||||
vec4 color;
|
||||
if(comp_id >= edit_components.length)return;
|
||||
if(edit_components[comp_id].used)
|
||||
{
|
||||
if(igCollapsingHeader(edit_components[comp_id].name, ImGuiTreeNodeFlags_SpanAvailWidth | ImGuiTreeNodeFlags_DefaultOpen))
|
||||
{
|
||||
igIndent(8);
|
||||
foreach(ref VariableGUI var;edit_components[comp_id].variables[0 .. edit_components[comp_id].used])
|
||||
{
|
||||
igPushIDPtr(&var);
|
||||
switch(var.type)
|
||||
{
|
||||
case VariableGUI.Type.byte_:
|
||||
igDragScalarClamp(var.name, ImGuiDataType_S8, data_ptr+var.offset, 0.1, cast(void*)&var.int_.min, cast(void*)&var.int_.max, null, 1);
|
||||
break;
|
||||
case VariableGUI.Type.ubyte_:
|
||||
igDragScalarClamp(var.name, ImGuiDataType_U8, data_ptr+var.offset, 0.1, cast(void*)&var.int_.min, cast(void*)&var.int_.max, null, 1);
|
||||
break;
|
||||
case VariableGUI.Type.short_:
|
||||
igDragScalarClamp(var.name, ImGuiDataType_S16, data_ptr+var.offset, 0.1, cast(void*)&var.int_.min, cast(void*)&var.int_.max, null, 1);
|
||||
break;
|
||||
case VariableGUI.Type.ushort_:
|
||||
igDragScalarClamp(var.name, ImGuiDataType_U16, data_ptr+var.offset, 0.1, cast(void*)&var.int_.min, cast(void*)&var.int_.max, null, 1);
|
||||
break;
|
||||
case VariableGUI.Type.int_:
|
||||
igDragScalarClamp(var.name, ImGuiDataType_S32, data_ptr+var.offset, 0.1, cast(void*)&var.int_.min, cast(void*)&var.int_.max, null, 1);
|
||||
break;
|
||||
case VariableGUI.Type.uint_:
|
||||
igDragScalarClamp(var.name, ImGuiDataType_U32, data_ptr+var.offset, 0.1, cast(void*)&var.int_.min, cast(void*)&var.int_.max, null, 1);
|
||||
break;
|
||||
case VariableGUI.Type.float_:
|
||||
igDragScalarClamp(var.name, ImGuiDataType_Float, data_ptr+var.offset, 0.1, cast(void*)&var.float_.min, cast(void*)&var.float_.max, "%2.2f", 1);
|
||||
break;
|
||||
case VariableGUI.Type.color:
|
||||
color = colorUintToVec4(*cast(uint*)(data_ptr+var.offset));
|
||||
if(igColorEdit4(var.name, color.data, ImGuiColorEditFlags_None))
|
||||
*cast(uint*)(data_ptr+var.offset) = colorVec4ToUint(color);
|
||||
break;
|
||||
default:break;
|
||||
}
|
||||
igPopID();
|
||||
}
|
||||
//igPopID();
|
||||
igUnindent(8);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void entityComponentsGUI()
|
||||
{
|
||||
EntityTemplate* tmpl = templates[selected_tempalte].tmpl;
|
||||
EntityTemplate* tmpl = templates[selected_template].tmpl;
|
||||
EntityManager.EntityInfo* info = tmpl.info;
|
||||
void* data_ptr = tmpl.entity_data.ptr;
|
||||
vec4 color;
|
||||
foreach(comp_id; info.components)
|
||||
{
|
||||
if(comp_id >= edit_components.length)break;
|
||||
void* data_ptr = tmpl.entity_data.ptr;
|
||||
void* comp_ptr = data_ptr + info.tmpl_deltas[comp_id];
|
||||
if(edit_components[comp_id].used)
|
||||
{
|
||||
if(igCollapsingHeader(edit_components[comp_id].name, ImGuiTreeNodeFlags_SpanAvailWidth | ImGuiTreeNodeFlags_DefaultOpen))
|
||||
{
|
||||
igIndent(8);
|
||||
foreach(ref VariableGUI var;edit_components[comp_id].variables[0 .. edit_components[comp_id].used])
|
||||
{
|
||||
switch(var.type)
|
||||
{
|
||||
case VariableGUI.Type.byte_:
|
||||
igDragScalarClamp(var.name, ImGuiDataType_S8, comp_ptr+var.offset, 1, cast(void*)&var.int_.min, cast(void*)&var.int_.max, null, 1);
|
||||
break;
|
||||
case VariableGUI.Type.ubyte_:
|
||||
igDragScalarClamp(var.name, ImGuiDataType_U8, comp_ptr+var.offset, 1, cast(void*)&var.int_.min, cast(void*)&var.int_.max, null, 1);
|
||||
break;
|
||||
case VariableGUI.Type.short_:
|
||||
igDragScalarClamp(var.name, ImGuiDataType_S16, comp_ptr+var.offset, 1, cast(void*)&var.int_.min, cast(void*)&var.int_.max, null, 1);
|
||||
break;
|
||||
case VariableGUI.Type.ushort_:
|
||||
igDragScalarClamp(var.name, ImGuiDataType_U16, comp_ptr+var.offset, 1, cast(void*)&var.int_.min, cast(void*)&var.int_.max, null, 1);
|
||||
break;
|
||||
case VariableGUI.Type.int_:
|
||||
igDragScalarClamp(var.name, ImGuiDataType_S32, comp_ptr+var.offset, 1, cast(void*)&var.int_.min, cast(void*)&var.int_.max, null, 1);
|
||||
break;
|
||||
case VariableGUI.Type.uint_:
|
||||
igDragScalarClamp(var.name, ImGuiDataType_U32, comp_ptr+var.offset, 1, cast(void*)&var.int_.min, cast(void*)&var.int_.max, null, 1);
|
||||
break;
|
||||
case VariableGUI.Type.float_:
|
||||
igDragScalarClamp(var.name, ImGuiDataType_Float, comp_ptr+var.offset, 1, cast(void*)&var.float_.min, cast(void*)&var.float_.max, null, 1);
|
||||
break;
|
||||
case VariableGUI.Type.color:
|
||||
color = colorUintToVec4(*cast(uint*)(comp_ptr+var.offset));
|
||||
if(igColorEdit4(var.name, color.data, ImGuiColorEditFlags_None))
|
||||
*cast(uint*)(comp_ptr+var.offset) = colorVec4ToUint(color);
|
||||
break;
|
||||
default:break;
|
||||
}
|
||||
}
|
||||
igUnindent(8);
|
||||
}
|
||||
}
|
||||
componentGUI(comp_id, comp_ptr);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -342,14 +366,15 @@ struct GUIManager
|
|||
{
|
||||
foreach(i, tmpl; templates)
|
||||
{
|
||||
if(igSelectable(tmpl.name,selected_tempalte == i,ImGuiSelectableFlags_AllowDoubleClick,ImVec2(0,0)))
|
||||
if(igSelectable(tmpl.name,selected_template == i,ImGuiSelectableFlags_AllowDoubleClick,ImVec2(0,0)))
|
||||
{
|
||||
selected_tempalte = cast(uint)i;
|
||||
selected_template = cast(uint)i;
|
||||
}
|
||||
}
|
||||
igListBoxFooter();
|
||||
}
|
||||
}
|
||||
if(igIsItemHovered(0))igSetTooltip("Select entity to spawn (SHIFT + Scroll)");
|
||||
}
|
||||
style.Colors[ImGuiCol_Header] = col;
|
||||
entityComponentsGUI();
|
||||
|
|
@ -370,7 +395,10 @@ struct GUIManager
|
|||
igListBoxFooter();
|
||||
}
|
||||
}
|
||||
if(igIsItemHovered(0))igSetTooltip("Select component to add/remove (SHIFT + Scroll)");
|
||||
}
|
||||
style.Colors[ImGuiCol_Header] = col;
|
||||
componentGUI(components[selected_component].component_id, components[selected_component].data);
|
||||
break;
|
||||
case Tool.selector:
|
||||
break;
|
||||
|
|
@ -378,4 +406,33 @@ struct GUIManager
|
|||
|
||||
style.Colors[ImGuiCol_Header] = col;
|
||||
}
|
||||
|
||||
void filterGUI()
|
||||
{
|
||||
ImGuiStyle * style = igGetStyle();
|
||||
ImVec4 col = style.Colors[ImGuiCol_Header];
|
||||
style.Colors[ImGuiCol_Header] = style.Colors[ImGuiCol_TextSelectedBg];
|
||||
|
||||
int length = 0;
|
||||
foreach(comp; edit_components)
|
||||
{
|
||||
if(comp.name !is null)length++;
|
||||
}
|
||||
|
||||
if(length && igListBoxHeaderInt("Components",cast(int)length,cast(int)length))
|
||||
{
|
||||
foreach(i, comp; edit_components)
|
||||
{
|
||||
if(comp.name is null)return;
|
||||
if(igSelectable(comp.name,false,0,ImVec2(0,0)))
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
igListBoxFooter();
|
||||
}
|
||||
if(igIsItemHovered(0))igSetTooltip("Select components to filter while tool work.\nComponents are only changed for filtered entities.");
|
||||
|
||||
style.Colors[ImGuiCol_Header] = col;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue