Added Base Classes for interactable List/TreeEntries

This commit is contained in:
Speiger 2021-09-09 23:14:14 +02:00
parent 3bc7dcdf44
commit 9c947c4898
3 changed files with 105 additions and 4 deletions

View File

@ -41,6 +41,7 @@ public class WindowComponent extends PanelComponent implements IButtonComponent,
public static final int DEFAULT_FLAGS = WINDOW_FLAGS | FLAG_RESIZEABLE | FLAG_MOVEABLE;
public static final int FIXED_SIZE_WINDOW = WINDOW_FLAGS | FLAG_MOVEABLE;
public static final int FIXED_SIZE_POPUP = WINDOW_FLAG_CLOSEABLE | FLAG_MOVEABLE;
public static final int DYNAMIC_POPUP = FIXED_SIZE_POPUP | FLAG_RESIZEABLE;
public static final int UNCLOSEABLE_WINDOW = WINDOW_FLAG_MINIMIZEABLE | FLAG_RESIZEABLE | FLAG_MOVEABLE;
public static final int SUB_WINDOW = WINDOW_FLAG_MINIMIZEABLE | FLAG_RESIZEABLE | FLAG_RESIZE_INVERT;

View File

@ -0,0 +1,88 @@
package speiger.src.coreengine.rendering.gui.components.list;
import java.util.Map;
import java.util.UUID;
import speiger.src.coreengine.rendering.gui.GuiComponent;
import speiger.src.coreengine.rendering.gui.base.IButtonComponent;
public class BaseClickableListEntry extends BaseListEntry implements IButtonComponent
{
@Override
public boolean isComponentColliding(int mouseX, int mouseY)
{
for(int i = 0,m=components.size();i<m;i++)
{
GuiComponent comp = components.get(i);
if(comp instanceof IButtonComponent && ((IButtonComponent)comp).isComponentColliding(mouseX, mouseY)) return true;
}
return false;
}
@Override
public boolean onClick(int button, int mouseX, int mouseY)
{
for(int i = 0,m=components.size();i<m;i++)
{
GuiComponent comp = components.get(i);
if(!(comp instanceof IButtonComponent)) continue;
IButtonComponent btn = (IButtonComponent)comp;
if(btn.isComponentColliding(mouseX, mouseY) && btn.onClick(button, mouseX, mouseY)) return true;
}
return false;
}
@Override
public boolean onDrag(int mouseX, int mouseY)
{
for(int i = 0,m=components.size();i<m;i++)
{
GuiComponent comp = components.get(i);
if(comp instanceof IButtonComponent && ((IButtonComponent)comp).onDrag(mouseX, mouseY)) return true;
}
return false;
}
@Override
public void onRelease(int button, int mouseX, int mouseY)
{
for(int i = 0,m=components.size();i<m;i++)
{
GuiComponent comp = components.get(i);
if(comp instanceof IButtonComponent)
{
IButtonComponent btn = (IButtonComponent)comp;
if(btn.isComponentColliding(mouseX, mouseY))
{
btn.onRelease(button, mouseX, mouseY);
return;
}
btn.onFocusLost();
}
}
}
@Override
public boolean onScroll(int scroll, int mouseX, int mouseY)
{
for(int i = 0,m=components.size();i<m;i++)
{
GuiComponent comp = components.get(i);
if(!(comp instanceof IButtonComponent)) continue;
IButtonComponent btn = (IButtonComponent)comp;
if(btn.isComponentColliding(mouseX, mouseY) && btn.onScroll(scroll, mouseX, mouseY)) return true;
}
return false;
}
@Override
public void collectTooltips(GuiComponent comp, int mouseX, int mouseY, float particalTicks, Map<UUID, GuiComponent> collector)
{
for(int i = 0,m=components.size();i<m;i++)
{
GuiComponent subComb = components.get(i);
if(!(subComb instanceof IButtonComponent)) continue;
subComb.collectTooltips(mouseX, mouseY, particalTicks, collector);
}
}
}

View File

@ -1,11 +1,13 @@
package speiger.src.coreengine.rendering.gui.components.tree;
import java.util.Map;
import java.util.UUID;
import speiger.src.coreengine.rendering.gui.GuiComponent;
import speiger.src.coreengine.rendering.gui.base.IButtonComponent;
public class BaseClickableTreeEntry extends BaseTreeEntry implements IButtonComponent
{
@Override
public boolean isComponentColliding(int mouseX, int mouseY)
{
@ -29,7 +31,7 @@ public class BaseClickableTreeEntry extends BaseTreeEntry implements IButtonComp
}
return false;
}
@Override
public boolean onDrag(int mouseX, int mouseY)
{
@ -40,7 +42,7 @@ public class BaseClickableTreeEntry extends BaseTreeEntry implements IButtonComp
}
return false;
}
@Override
public void onRelease(int button, int mouseX, int mouseY)
{
@ -73,4 +75,14 @@ public class BaseClickableTreeEntry extends BaseTreeEntry implements IButtonComp
return false;
}
}
@Override
public void collectTooltips(GuiComponent comp, int mouseX, int mouseY, float particalTicks, Map<UUID, GuiComponent> collector)
{
for(int i = 0,m=components.size();i<m;i++)
{
GuiComponent subComb = components.get(i);
if(!(subComb instanceof IButtonComponent)) continue;
subComb.collectTooltips(mouseX, mouseY, particalTicks, collector);
}
}
}