diff --git a/cubyz-client/src/io/cubyz/client/Cubyz.java b/cubyz-client/src/io/cubyz/client/Cubyz.java index 85f8d47b..96ab02b8 100644 --- a/cubyz-client/src/io/cubyz/client/Cubyz.java +++ b/cubyz-client/src/io/cubyz/client/Cubyz.java @@ -46,6 +46,7 @@ import io.cubyz.multiplayer.client.CubzClient; import io.cubyz.multiplayer.server.CubzServer; import io.cubyz.ui.DebugGUI; import io.cubyz.ui.MainMenuGUI; +import io.cubyz.ui.PauseGUI; import io.cubyz.ui.UISystem; import io.cubyz.utils.DiscordIntegration; import io.cubyz.utils.TextureConverter; @@ -261,7 +262,10 @@ public class Cubyz implements IGameLogic { } } if (window.isKeyPressed(GLFW.GLFW_KEY_ESCAPE) && mouse.isGrabbed()) { - mouse.setGrabbed(false); + if (gameUI.getMenuGUI() == null) { + Keyboard.setKeyPressed(GLFW.GLFW_KEY_ESCAPE, false); + gameUI.setMenu(new PauseGUI()); + } } if (mouse.isLeftButtonPressed() && !mouse.isGrabbed()) { mouse.setGrabbed(true); diff --git a/cubyz-client/src/io/cubyz/ui/Component.java b/cubyz-client/src/io/cubyz/ui/Component.java index 9ed3ce68..0e0bb992 100644 --- a/cubyz-client/src/io/cubyz/ui/Component.java +++ b/cubyz-client/src/io/cubyz/ui/Component.java @@ -63,4 +63,7 @@ public abstract class Component { public abstract void render(long nvg, Window src); + public void init(long nvg, Window src) {} + public void dispose(long nvg, Window src) {} + } \ No newline at end of file diff --git a/cubyz-client/src/io/cubyz/ui/PauseGUI.java b/cubyz-client/src/io/cubyz/ui/PauseGUI.java new file mode 100644 index 00000000..1ce656ba --- /dev/null +++ b/cubyz-client/src/io/cubyz/ui/PauseGUI.java @@ -0,0 +1,50 @@ +package io.cubyz.ui; + +import org.jungle.Keyboard; +import org.jungle.Window; +import org.lwjgl.glfw.GLFW; + +import io.cubyz.client.Cubyz; +import io.cubyz.ui.components.Button; + +public class PauseGUI extends MenuGUI { + + private Button exit; + private Button game; + + @Override + public void init(long nvg) { + Cubyz.mouse.setGrabbed(false); + exit = new Button(); + game = new Button(); + exit.setText("Exit to main menu"); + game.setText("Continue"); + + game.setOnAction(() -> { + Cubyz.mouse.setGrabbed(true); + Cubyz.gameUI.setMenu(null); + }); + + exit.setSize(200, 50); + game.setSize(200, 50); + } + + @Override + public void render(long nvg, Window win) { + if (Keyboard.isKeyPressed(GLFW.GLFW_KEY_ESCAPE)) { + Keyboard.setKeyPressed(GLFW.GLFW_KEY_ESCAPE, false); + Cubyz.mouse.setGrabbed(true); + Cubyz.gameUI.setMenu(null); + } + game.setPosition(win.getWidth() / 2 - 100, 100); + exit.setPosition(win.getWidth() / 2 - 100, win.getHeight() - 100); + exit.render(nvg, win); + game.render(nvg, win); + } + + @Override + public boolean isFullscreen() { + return true; + } + +} diff --git a/cubyz-client/src/io/cubyz/ui/components/Button.java b/cubyz-client/src/io/cubyz/ui/components/Button.java index 857e7a39..9229b42b 100644 --- a/cubyz-client/src/io/cubyz/ui/components/Button.java +++ b/cubyz-client/src/io/cubyz/ui/components/Button.java @@ -60,7 +60,6 @@ public class Button extends Component { NGraphics.fillRect(x, y, width, height); NGraphics.setColor(255, 255, 255); NGraphics.setFont("OpenSans Bold", fontSize); - NGraphics.drawText(x + (width / 2) - ((text.length() * 5) / 2), (int) (y + (height / 2) - fontSize / 2), text); //int ascent = NGraphics.getAscent("ahh"); } diff --git a/cubyz-client/src/io/cubyz/ui/components/Container.java b/cubyz-client/src/io/cubyz/ui/components/Container.java new file mode 100644 index 00000000..fca4eaf9 --- /dev/null +++ b/cubyz-client/src/io/cubyz/ui/components/Container.java @@ -0,0 +1,37 @@ +package io.cubyz.ui.components; + +import java.util.ArrayList; + +import org.jungle.Window; + +import io.cubyz.ui.Component; + +public class Container extends Component { + + protected ArrayList childrens; + + public Container() { + childrens = new ArrayList<>(); + } + + public void add(Component comp) { + if (comp == this) throw new IllegalArgumentException("comp == this"); + childrens.add(comp); + } + + public void remove(Component comp) { + childrens.remove(comp); + } + + public void remove(int index) { + childrens.remove(index); + } + + @Override + public void render(long nvg, Window src) { + for (Component child : childrens) { + child.render(nvg, src); + } + } + +} diff --git a/cubyz-client/src/io/cubyz/ui/components/ScrollingContainer.java b/cubyz-client/src/io/cubyz/ui/components/ScrollingContainer.java new file mode 100644 index 00000000..8683f30f --- /dev/null +++ b/cubyz-client/src/io/cubyz/ui/components/ScrollingContainer.java @@ -0,0 +1,49 @@ +package io.cubyz.ui.components; + +import org.jungle.MouseInput; +import org.jungle.Window; + +import io.cubyz.client.Cubyz; +import io.cubyz.ui.Component; +import io.cubyz.ui.NGraphics; + +public class ScrollingContainer extends Container { + + int maxY = 0; + int scrollY = 0; + int scrollBarWidth = 20; + + int mPickY = -1; + + public void render(long nvg, Window src) { + MouseInput mouse = Cubyz.mouse; + maxY = 0; + for (Component child : childrens) { + maxY = Math.max(maxY, child.getY()); + child.setY(child.getY() - scrollY); + child.render(nvg, src); + child.setY(child.getY() + scrollY); + } + if (maxY > height) { + NGraphics.setColor(0, 0, 0); + NGraphics.fillRect(x + width - scrollBarWidth, y, scrollBarWidth, 10); + if (mPickY == -1) { + if (mouse.getX() > x + width - scrollBarWidth && mouse.getX() < x + width) { + if (mouse.getY() > y && mouse.getY() < height) { + if (mouse.isLeftButtonPressed()) { + mPickY = (int) mouse.getY(); + } + } + } + } else { + if (mouse.isLeftButtonPressed()) { + scrollY = (int) Math.min(maxY, mouse.getY() - mPickY); + } else { + mPickY = -1; + } + } + } + scrollY = Math.min(maxY, scrollY); + } + +}