mirror of
https://github.com/PixelGuys/Cubyz.git
synced 2025-08-03 19:28:49 -04:00
Pause GUI
This commit is contained in:
parent
ea804535d2
commit
1e454b0340
@ -46,6 +46,7 @@ import io.cubyz.multiplayer.client.CubzClient;
|
|||||||
import io.cubyz.multiplayer.server.CubzServer;
|
import io.cubyz.multiplayer.server.CubzServer;
|
||||||
import io.cubyz.ui.DebugGUI;
|
import io.cubyz.ui.DebugGUI;
|
||||||
import io.cubyz.ui.MainMenuGUI;
|
import io.cubyz.ui.MainMenuGUI;
|
||||||
|
import io.cubyz.ui.PauseGUI;
|
||||||
import io.cubyz.ui.UISystem;
|
import io.cubyz.ui.UISystem;
|
||||||
import io.cubyz.utils.DiscordIntegration;
|
import io.cubyz.utils.DiscordIntegration;
|
||||||
import io.cubyz.utils.TextureConverter;
|
import io.cubyz.utils.TextureConverter;
|
||||||
@ -261,7 +262,10 @@ public class Cubyz implements IGameLogic {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (window.isKeyPressed(GLFW.GLFW_KEY_ESCAPE) && mouse.isGrabbed()) {
|
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()) {
|
if (mouse.isLeftButtonPressed() && !mouse.isGrabbed()) {
|
||||||
mouse.setGrabbed(true);
|
mouse.setGrabbed(true);
|
||||||
|
@ -63,4 +63,7 @@ public abstract class Component {
|
|||||||
|
|
||||||
public abstract void render(long nvg, Window src);
|
public abstract void render(long nvg, Window src);
|
||||||
|
|
||||||
|
public void init(long nvg, Window src) {}
|
||||||
|
public void dispose(long nvg, Window src) {}
|
||||||
|
|
||||||
}
|
}
|
50
cubyz-client/src/io/cubyz/ui/PauseGUI.java
Normal file
50
cubyz-client/src/io/cubyz/ui/PauseGUI.java
Normal file
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -60,7 +60,6 @@ public class Button extends Component {
|
|||||||
NGraphics.fillRect(x, y, width, height);
|
NGraphics.fillRect(x, y, width, height);
|
||||||
NGraphics.setColor(255, 255, 255);
|
NGraphics.setColor(255, 255, 255);
|
||||||
NGraphics.setFont("OpenSans Bold", fontSize);
|
NGraphics.setFont("OpenSans Bold", fontSize);
|
||||||
|
|
||||||
NGraphics.drawText(x + (width / 2) - ((text.length() * 5) / 2), (int) (y + (height / 2) - fontSize / 2), text);
|
NGraphics.drawText(x + (width / 2) - ((text.length() * 5) / 2), (int) (y + (height / 2) - fontSize / 2), text);
|
||||||
//int ascent = NGraphics.getAscent("ahh");
|
//int ascent = NGraphics.getAscent("ahh");
|
||||||
}
|
}
|
||||||
|
37
cubyz-client/src/io/cubyz/ui/components/Container.java
Normal file
37
cubyz-client/src/io/cubyz/ui/components/Container.java
Normal file
@ -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<Component> 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user