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:
Mergul 2020-06-10 14:13:01 +02:00
parent e76c5ccdb2
commit 5018464a41
4 changed files with 237 additions and 100 deletions

View file

@ -71,6 +71,7 @@ struct Launcher
float tool_repeat = 0;
float repeat_time = 0;
bool tool_show = true;
bool override_ = true;
bool tool_mode = true;
ToolCircle* tool_circle;
@ -154,6 +155,20 @@ struct Launcher
}
}
void overrideComponent(IteratorSystem.EntitiesData data)
{
foreach(i;0..data.length)
{
vec2 rel_vec = data.location[i] - position;
float length = rel_vec.x * rel_vec.x + rel_vec.y * rel_vec.y;
if(length < size2)
{
gEM.removeComponents(data.entity[i].id, rem_comps);
gEM.addComponents(data.entity[i].id, add_comps);
}
}
}
void removeComponent(IteratorSystem.EntitiesData data)
{
foreach(i;0..data.length)
@ -200,7 +215,13 @@ struct Launcher
{
ComponentRef[1] comps = [gui_manager.getSelectedComponent()];
iterator.add_comps = comps;
manager.callEntitiesFunction!IteratorSystem(&iterator.addComponent);
if(launcher.override_)
{
ushort[1] rcomps = [gui_manager.getSelectedComponent().component_id];
iterator.rem_comps = rcomps;
manager.callEntitiesFunction!IteratorSystem(&iterator.overrideComponent);
}
else manager.callEntitiesFunction!IteratorSystem(&iterator.addComponent);
}
else
{
@ -330,6 +351,33 @@ void mainLoop(void* arg)
*cast(bool*)arg = false;
return;
}
else if(event.type == SDL_KEYDOWN)
{
if(event.key.state)
{
if(SDL_GetModState() & KMOD_CTRL)
{
switch(event.key.keysym.scancode)
{
case SDL_SCANCODE_1:launcher.used_tool=Tool.entity_spawner;break;
case SDL_SCANCODE_2:launcher.used_tool=Tool.component_manipulator;break;
case SDL_SCANCODE_3:launcher.used_tool=Tool.selector;break;
default:break;
}
}
else
{
switch(event.key.keysym.scancode)
{
case SDL_SCANCODE_1:break;
case SDL_SCANCODE_2:break;
case SDL_SCANCODE_3:break;
case SDL_SCANCODE_4:break;
default:break;
}
}
}
}
else if(event.type == SDL_WINDOWEVENT)
{
switch(event.window.event)
@ -383,17 +431,32 @@ void mainLoop(void* arg)
{
float sign = 1;
if(event.wheel.y < 0)sign = -1;
float val = sign * event.wheel.y * launcher.tool_repeat * 0.25;
float val = /*sign * event.wheel.y */ launcher.tool_repeat * 0.25;
if(val < 0.1)val = 0.1;
launcher.tool_repeat -= sign * val;
if(launcher.tool_repeat < 0)launcher.tool_repeat = 0;
else if(launcher.tool_repeat > 1000)launcher.tool_repeat = 1000;
}
else if(SDL_GetModState() & KMOD_SHIFT)
{
int sign = 1;
if(event.wheel.y < 0)sign = -1;
switch(launcher.used_tool)
{
case Tool.entity_spawner:
launcher.gui_manager.selectTemplate(launcher.gui_manager.selected_template-sign);
break;
case Tool.component_manipulator:
launcher.gui_manager.selectComponent(launcher.gui_manager.selected_component-sign);
break;
default:break;
}
}
else
{
int sign = 1;
if(event.wheel.y < 0)sign = -1;
int val = sign * event.wheel.y * launcher.tool_size / 4;
int val = /*sign * event.wheel.y */ launcher.tool_size / 4;
if(val < 1)val = 1;
launcher.tool_size -= sign * val;
if(launcher.tool_size < 1)launcher.tool_size = 1;
@ -503,22 +566,11 @@ void mainLoop(void* arg)
}
if(igBeginMenu("Show",true))
{
if(igMenuItemBool("Statistics",null,launcher.show_stat_wnd,true))
{
launcher.show_stat_wnd = !launcher.show_stat_wnd;
}
else if(igMenuItemBool("Demo",null,launcher.show_demo_wnd,true))
{
launcher.show_demo_wnd = !launcher.show_demo_wnd;
}
else if(igMenuItemBool("Tips",null,launcher.show_tips,true))
{
launcher.show_tips = !launcher.show_tips;
}
else if(igMenuItemBool("Virual keys",null,launcher.show_virtual_keys_wnd,true))
{
launcher.show_virtual_keys_wnd = !launcher.show_virtual_keys_wnd;
}
igMenuItemBoolPtr("Statistics",null,&launcher.show_stat_wnd,true);
igMenuItemBoolPtr("Demo",null,&launcher.show_demo_wnd,true);
igMenuItemBoolPtr("Tips",null,&launcher.show_tips,true);
igMenuItemBoolPtr("Virual keys",null,&launcher.show_virtual_keys_wnd,true);
igMenuItemBoolPtr("Profile",null,&launcher.show_profile_wnd,true);
igEndMenu();
}
if(igBeginMenu("Style",true))
@ -655,12 +707,25 @@ void mainLoop(void* arg)
}
igEndCombo();
}
if(igIsItemHovered(0))igSetTooltip("Select tool (CTRL + 1,2,3)");
igCheckbox("Show Tool", &launcher.tool_show);
if(igIsItemHovered(0))igSetTooltip("Show/hide graphical tool representation");
if(launcher.used_tool == Tool.component_manipulator)
{
igSameLine(0,4);
igCheckbox("Override", &launcher.override_);
}
//igSelectable("Selectabe",false,ImGuiSelectableFlags_None,ImVec2(0,0));
if(igRadioButtonBool("Add", launcher.tool_mode))launcher.tool_mode = true;
igSameLine(0,0);
if(igRadioButtonBool("Remove", !launcher.tool_mode))launcher.tool_mode = false;
if(launcher.used_tool != Tool.selector)
{
if(igRadioButtonBool("Add", launcher.tool_mode))launcher.tool_mode = true;
if(igIsItemHovered(0))igSetTooltip("Tool should adding (Entities or components)");
igSameLine(0,4);
if(igRadioButtonBool("Remove", !launcher.tool_mode))launcher.tool_mode = false;
if(igIsItemHovered(0))igSetTooltip("Tool should removing (Entities or components)");
}
igSliderInt("Tool size", &launcher.tool_size, 0, 256, null);
igSliderFloat("Tool repeat", &launcher.tool_repeat, 0, 1024, null, 4);
launcher.gui_manager.toolGui();
@ -668,7 +733,16 @@ void mainLoop(void* arg)
}
igEndGroup();
ImDrawList_AddRect(draw_list, igGetItemRectMin(), ImVec2(igGetWindowPos().x+igGetWindowWidth()-2,igGetItemRectMax().y), igColorConvertFloat4ToU32(ImVec4(0.4,0.4,0.4,0.4)), 2, ImDrawCornerFlags_All, 1);
//igBeginGroup();
if(igCollapsingHeader("Filter", ImGuiTreeNodeFlags_SpanAvailWidth))
{
igIndent(8);
launcher.gui_manager.filterGUI();
igUnindent(8);
}
//igEndGroup();
//ImDrawList_AddRect(draw_list, igGetItemRectMin(), ImVec2(igGetWindowPos().x+igGetWindowWidth()-2,igGetItemRectMax().y), igColorConvertFloat4ToU32(ImVec4(0.4,0.4,0.4,0.4)), 2, ImDrawCornerFlags_All, 1);
//igEndChild();
//igEndChildFrame();
@ -975,8 +1049,8 @@ int app_main(int argc, char** argv)
import demos.space_invaders;
import demos.particles;
// launcher.switchDemo(&spaceInvadersStart,&spaceInvadersLoop,&spaceInvadersEnd,&spaceInvadersEvent,SpaceInvaders.tips);
// launcher.switchDemo(&particlesStart,&particlesLoop,&particlesEnd,&particlesEvent,ParticlesDemo.tips);
launcher.switchDemo(&simpleStart,&simpleLoop,&simpleEnd,&simpleEvent,Simple.tips);
launcher.switchDemo(&particlesStart,&particlesLoop,&particlesEnd,&particlesEvent,ParticlesDemo.tips);
// launcher.switchDemo(&simpleStart,&simpleLoop,&simpleEnd,&simpleEvent,Simple.tips);
}
int key_num;