Added support for key modifiers; GUI can now be opened and closed with the same button (if no widget has focus). Closes #6

This commit is contained in:
Marcel Konrad
2019-10-18 19:11:39 +02:00
parent 3bf7cce0f1
commit 932bdc397f
2 changed files with 34 additions and 3 deletions

View File

@@ -15,6 +15,7 @@ import exopandora.worldhandler.Main;
import exopandora.worldhandler.WorldHandler;
import exopandora.worldhandler.builder.impl.BuilderWorldHandler;
import exopandora.worldhandler.config.Config;
import exopandora.worldhandler.event.KeyHandler;
import exopandora.worldhandler.gui.button.EnumIcon;
import exopandora.worldhandler.gui.button.GuiButtonIcon;
import exopandora.worldhandler.gui.button.GuiButtonTab;
@@ -628,6 +629,25 @@ public class GuiWorldHandler extends Container
return super.mouseClicked(mouseX, mouseY, keyCode);
}
@Override
public boolean keyPressed(int keyCode, int scanCode, int modifiers)
{
boolean focused = this.getFocused() != null;
if(focused && this.getFocused() instanceof Widget)
{
focused = ((Widget) this.getFocused()).isFocused();
}
if(!focused && KeyHandler.isPressed(KeyHandler.KEY_WORLD_HANDLER, keyCode))
{
this.onClose();
return true;
}
return super.keyPressed(keyCode, scanCode, modifiers);
}
@Override
public void onClose()
{