Renamed alot of GUI stuff for consistancy, worked on saves GUI, added

vsync setting.
This commit is contained in:
jsrobson10 2020-07-23 14:22:12 +10:00
parent 96eb85d55a
commit fdf5fad146
41 changed files with 368 additions and 238 deletions

View File

@ -42,7 +42,7 @@ public class Camera
projection_sun = Matrix4.multiply(projection_sun, Matrix4.rotate(-angle - 180, 0, 1, 0)); projection_sun = Matrix4.multiply(projection_sun, Matrix4.rotate(-angle - 180, 0, 1, 0));
projection_sun = Matrix4.multiply(projection_sun, Matrix4.rotate(20, 0, 0, 1)); projection_sun = Matrix4.multiply(projection_sun, Matrix4.rotate(20, 0, 0, 1));
projection_sun = Matrix4.multiply(projection_sun, Matrix4.rotate(-time, 1, 0, 0)); projection_sun = Matrix4.multiply(projection_sun, Matrix4.rotate(-time, 1, 0, 0));
projection_sun = Matrix4.multiply(projection_sun, Matrix4.translate(0, 0, -16)); projection_sun = Matrix4.multiply(projection_sun, Matrix4.translate(0, 0, -(16*Chunk.RENDER_DISTANCE+16)));
projection_sun = Matrix4.multiply(projection_sun, Matrix4.scale(new Vec3d(1/20.0, 1/20.0, -1/32.0))); projection_sun = Matrix4.multiply(projection_sun, Matrix4.scale(new Vec3d(1.0/20.0, 1.0/20.0, -1.0/(32*Chunk.RENDER_DISTANCE+32))));
} }
} }

View File

@ -92,7 +92,7 @@ public class DisplayRender
GL33.glTexParameteri(GL33.GL_TEXTURE_2D, GL33.GL_TEXTURE_MAG_FILTER, GL33.GL_LINEAR); GL33.glTexParameteri(GL33.GL_TEXTURE_2D, GL33.GL_TEXTURE_MAG_FILTER, GL33.GL_LINEAR);
GL33.glTexParameteri(GL33.GL_TEXTURE_2D, GL33.GL_TEXTURE_WRAP_S, GL33.GL_CLAMP_TO_BORDER); GL33.glTexParameteri(GL33.GL_TEXTURE_2D, GL33.GL_TEXTURE_WRAP_S, GL33.GL_CLAMP_TO_BORDER);
GL33.glTexParameteri(GL33.GL_TEXTURE_2D, GL33.GL_TEXTURE_WRAP_T, GL33.GL_CLAMP_TO_BORDER); GL33.glTexParameteri(GL33.GL_TEXTURE_2D, GL33.GL_TEXTURE_WRAP_T, GL33.GL_CLAMP_TO_BORDER);
GL33.glTexParameterfv(GL33.GL_TEXTURE_2D, GL33.GL_TEXTURE_BORDER_COLOR, new float[] {0, 0, 0, 0}); GL33.glTexParameterfv(GL33.GL_TEXTURE_2D, GL33.GL_TEXTURE_BORDER_COLOR, new float[] {1, 1, 1, 1});
GL33.glFramebufferTexture(GL33.GL_FRAMEBUFFER, GL33.GL_DEPTH_ATTACHMENT, depth, 0); GL33.glFramebufferTexture(GL33.GL_FRAMEBUFFER, GL33.GL_DEPTH_ATTACHMENT, depth, 0);
return depth; return depth;
@ -116,7 +116,7 @@ public class DisplayRender
GL33.glEnable(GL33.GL_DEPTH_TEST); GL33.glEnable(GL33.GL_DEPTH_TEST);
GL33.glUniform4f(Main.window.glsl_color, 1, 1, 1, 1); GL33.glUniform4f(Main.window.glsl_color, 1, 1, 1, 1);
GL33.glUniform4f(Main.window.glsl_discard_coords, -1, -1, 1, 1); GL33.glUniform1i(Main.window.glsl_do_discard_coords, 0);
ColorRange range = Main.world.getLayer().layergen.getLightLevel(); ColorRange range = Main.world.getLayer().layergen.getLightLevel();

View File

@ -85,14 +85,17 @@ public class DisplayRenderUI
model_health_b.setModel(matrix); model_health_b.setModel(matrix);
model_health_b.render(); model_health_b.render();
GL33.glUniform4f(Main.window.glsl_discard_coords, -1, -1, (float)MathHelpers.map( GL33.glUniform1i(Main.window.glsl_do_discard_coords, 1);
GL33.glUniform4f(Main.window.glsl_discard_coords, -10, -10, (float)MathHelpers.map(
Main.player.getHealth(), Main.player.getHealth(),
0, Main.player.maxHealth(), 0, Main.player.maxHealth(),
offset, model_health_f.getWidth() + offset), 1); offset, offset + model_health_f.getWidth()), 10);
model_health_f.setModel(matrix); model_health_f.setModel(matrix);
model_health_f.render(); model_health_f.render();
GL33.glUniform1i(Main.window.glsl_do_discard_coords, 0);
double temperature = MathHelpers.smoothStep(Main.player.getTemperature()); double temperature = MathHelpers.smoothStep(Main.player.getTemperature());
double hydration = MathHelpers.smoothStep(1 - Main.player.getHydration()) * 0.75; double hydration = MathHelpers.smoothStep(1 - Main.player.getHydration()) * 0.75;

View File

@ -1,9 +1,5 @@
package projectzombie.display; package projectzombie.display;
import static org.lwjgl.opengl.GL11.GL_FLOAT;
import static org.lwjgl.opengl.GL20.glEnableVertexAttribArray;
import static org.lwjgl.opengl.GL20.glVertexAttribPointer;
import java.nio.IntBuffer; import java.nio.IntBuffer;
import org.lwjgl.BufferUtils; import org.lwjgl.BufferUtils;
@ -28,7 +24,8 @@ import projectzombie.settings.Settings;
public class DisplayWindow implements IMainloopTask public class DisplayWindow implements IMainloopTask
{ {
public static boolean fullscreen = true; public static boolean fullscreen;
public static boolean vsync;
private long window; private long window;
private long monitor; private long monitor;
@ -48,6 +45,7 @@ public class DisplayWindow implements IMainloopTask
public int glsl_color; public int glsl_color;
public int glsl_contrast; public int glsl_contrast;
public int glsl_discard_coords; public int glsl_discard_coords;
public int glsl_do_discard_coords;
public int glsl_model; public int glsl_model;
public int glsl_camera; public int glsl_camera;
public int glsl_projection; public int glsl_projection;
@ -70,6 +68,12 @@ public class DisplayWindow implements IMainloopTask
public int glsl_effect_red_freq; public int glsl_effect_red_freq;
public int glsl_effect_chill; public int glsl_effect_chill;
public static void setVSync(boolean status)
{
vsync = status;
GLFW.glfwSwapInterval(vsync ? 1 : 0);
}
public int getWidth() { public int getWidth() {
return this.width; return this.width;
} }
@ -121,7 +125,7 @@ public class DisplayWindow implements IMainloopTask
// Make the cursor invisible // Make the cursor invisible
GLFW.glfwSetInputMode(this.window, GLFW.GLFW_CURSOR, GLFW.GLFW_CURSOR_HIDDEN); GLFW.glfwSetInputMode(this.window, GLFW.GLFW_CURSOR, GLFW.GLFW_CURSOR_HIDDEN);
GLFW.glfwSwapInterval(0); setVSync(vsync);
// Show the window // Show the window
//GLFW.glfwShowWindow(this.window); //GLFW.glfwShowWindow(this.window);
@ -137,6 +141,7 @@ public class DisplayWindow implements IMainloopTask
glsl_projection_sun = GL33.glGetUniformLocation(environmentRenderer.program, "projection_sun"); glsl_projection_sun = GL33.glGetUniformLocation(environmentRenderer.program, "projection_sun");
glsl_time = GL33.glGetUniformLocation(environmentRenderer.program, "time"); glsl_time = GL33.glGetUniformLocation(environmentRenderer.program, "time");
glsl_discard_coords = GL33.glGetUniformLocation(environmentRenderer.program, "discard_coords"); glsl_discard_coords = GL33.glGetUniformLocation(environmentRenderer.program, "discard_coords");
glsl_do_discard_coords = GL33.glGetUniformLocation(environmentRenderer.program, "do_discard_coords");
glsl_color = GL33.glGetUniformLocation(environmentRenderer.program, "color"); glsl_color = GL33.glGetUniformLocation(environmentRenderer.program, "color");
glsl_contrast = GL33.glGetUniformLocation(environmentRenderer.program, "contrast"); glsl_contrast = GL33.glGetUniformLocation(environmentRenderer.program, "contrast");
glsl_billboard = GL33.glGetUniformLocation(environmentRenderer.program, "billboard"); glsl_billboard = GL33.glGetUniformLocation(environmentRenderer.program, "billboard");
@ -183,8 +188,8 @@ public class DisplayWindow implements IMainloopTask
1, 1, 1, 1,
}, GL33.GL_STATIC_DRAW); }, GL33.GL_STATIC_DRAW);
glVertexAttribPointer(0, 2, GL_FLOAT, false, Float.BYTES * 2, 0); GL33.glVertexAttribPointer(0, 2, GL33.GL_FLOAT, false, Float.BYTES * 2, 0);
glEnableVertexAttribArray(0); GL33.glEnableVertexAttribArray(0);
int[] ptr = new int[1]; int[] ptr = new int[1];
GL33.glGetIntegerv(GL33.GL_MAX_TEXTURE_SIZE, ptr); GL33.glGetIntegerv(GL33.GL_MAX_TEXTURE_SIZE, ptr);

View File

@ -57,7 +57,9 @@ public class InputGUI implements Input
public void hotbarGoto(boolean state, int pos) {} public void hotbarGoto(boolean state, int pos) {}
@Override @Override
public void hotbarShift(boolean state, int amount) {} public void hotbarShift(boolean state, int amount) {
gui.onScroll(amount);
}
@Override @Override
public void mousePos(Vec2d pos) public void mousePos(Vec2d pos)

View File

@ -3,10 +3,9 @@ package projectzombie.menu;
import projectzombie.Main; import projectzombie.Main;
import projectzombie.input.types.InputGUI; import projectzombie.input.types.InputGUI;
import projectzombie.menu.gui.GUIButtonGroup; import projectzombie.menu.gui.GUIButtonGroup;
import projectzombie.menu.gui.GUIButtonGroupPause;
import projectzombie.menu.gui.GUI; import projectzombie.menu.gui.GUI;
import projectzombie.menu.gui.components.ButtonBasic; import projectzombie.menu.gui.GUIButtonBasic;
import projectzombie.menu.gui.components.ButtonGroupPause;
import projectzombie.menu.gui.components.OverlayBackground;
public class MenuDeath extends Menu public class MenuDeath extends Menu
{ {
@ -20,11 +19,9 @@ public class MenuDeath extends Menu
this.gui = new GUI(); this.gui = new GUI();
this.input = new InputGUI(this.gui); this.input = new InputGUI(this.gui);
gui.add(new OverlayBackground()); GUIButtonGroup group = new GUIButtonGroupPause();
GUIButtonGroup group = new ButtonGroupPause(); group.add(new GUIButtonBasic("Quit", button -> {
group.add(new ButtonBasic("Quit", button -> {
Main.menu = new MenuMain(); Main.menu = new MenuMain();
})); }));

View File

@ -7,12 +7,11 @@ import bdf.types.BdfObject;
import projectzombie.Main; import projectzombie.Main;
import projectzombie.input.types.InputGUI; import projectzombie.input.types.InputGUI;
import projectzombie.menu.gui.GUIButtonGroup; import projectzombie.menu.gui.GUIButtonGroup;
import projectzombie.menu.gui.GUIButtonGroupPause;
import projectzombie.menu.gui.GUILabelPause;
import projectzombie.menu.gui.GUI; import projectzombie.menu.gui.GUI;
import projectzombie.menu.gui.components.ButtonBasic; import projectzombie.menu.gui.GUIBackToMenu;
import projectzombie.menu.gui.components.ButtonGroupPause; import projectzombie.menu.gui.GUIButtonBasic;
import projectzombie.menu.gui.components.GUIBackToMenu;
import projectzombie.menu.gui.components.LabelPause;
import projectzombie.menu.gui.components.OverlayBackground;
public class MenuGamePause extends Menu public class MenuGamePause extends Menu
{ {
@ -26,12 +25,11 @@ public class MenuGamePause extends Menu
this.gui = new GUIBackToMenu(Main.menu); this.gui = new GUIBackToMenu(Main.menu);
this.input = new InputGUI(this.gui); this.input = new InputGUI(this.gui);
gui.add(new OverlayBackground()); gui.add(new GUILabelPause("Game Paused"));
gui.add(new LabelPause("Game Paused"));
GUIButtonGroup group = new ButtonGroupPause(); GUIButtonGroup group = new GUIButtonGroupPause();
group.add(new ButtonBasic("Save And Exit", button -> { group.add(new GUIButtonBasic("Save And Exit", button -> {
saveAndQuit(); saveAndQuit();
})); }));

View File

@ -21,7 +21,7 @@ import projectzombie.menu.gui.GUIItemSlot;
import projectzombie.menu.gui.GUIItemSlotGetter; import projectzombie.menu.gui.GUIItemSlotGetter;
import projectzombie.menu.gui.GUIItemSlotGetterStorage; import projectzombie.menu.gui.GUIItemSlotGetterStorage;
import projectzombie.menu.gui.GUI; import projectzombie.menu.gui.GUI;
import projectzombie.menu.gui.components.GUIBackToMenu; import projectzombie.menu.gui.GUIBackToMenu;
import projectzombie.model.Model; import projectzombie.model.Model;
import projectzombie.util.gl.GlHelpers; import projectzombie.util.gl.GlHelpers;
import projectzombie.util.math.ItemStack; import projectzombie.util.math.ItemStack;

View File

@ -7,9 +7,9 @@ import projectzombie.Main;
import projectzombie.init.Layers; import projectzombie.init.Layers;
import projectzombie.input.types.InputGUI; import projectzombie.input.types.InputGUI;
import projectzombie.menu.gui.GUIButtonGroup; import projectzombie.menu.gui.GUIButtonGroup;
import projectzombie.menu.gui.GUILabelMain;
import projectzombie.menu.gui.GUI; import projectzombie.menu.gui.GUI;
import projectzombie.menu.gui.components.ButtonBasic; import projectzombie.menu.gui.GUIButtonBasic;
import projectzombie.menu.gui.components.LabelMain;
public class MenuMain extends Menu public class MenuMain extends Menu
{ {
@ -26,19 +26,19 @@ public class MenuMain extends Menu
this.gui = new GUI(); this.gui = new GUI();
this.input = new InputGUI(gui); this.input = new InputGUI(gui);
gui.add(new LabelMain()); gui.add(new GUILabelMain());
GUIButtonGroup group = new GUIButtonGroup(); GUIButtonGroup group = new GUIButtonGroup();
group.add(new ButtonBasic("Play", button -> { group.add(new GUIButtonBasic("Play", button -> {
Main.menu = new MenuSaves(Main.menu); Main.menu = new MenuSaves(Main.menu);
})); }));
group.add(new ButtonBasic("Settings", button -> { group.add(new GUIButtonBasic("Settings", button -> {
Main.menu = new MenuSettings(Main.menu); Main.menu = new MenuSettings(Main.menu);
})); }));
group.add(new ButtonBasic("Quit", button -> { group.add(new GUIButtonBasic("Quit", button -> {
Main.mainloop.stop(); Main.mainloop.stop();
})); }));

View File

@ -12,19 +12,21 @@ import projectzombie.input.types.InputGUI;
import projectzombie.menu.gui.GUI; import projectzombie.menu.gui.GUI;
import projectzombie.menu.gui.GUIAlignment; import projectzombie.menu.gui.GUIAlignment;
import projectzombie.menu.gui.GUIButton; import projectzombie.menu.gui.GUIButton;
import projectzombie.menu.gui.GUIButtonBasic;
import projectzombie.menu.gui.GUIButtonCallback;
import projectzombie.menu.gui.GUILabel; import projectzombie.menu.gui.GUILabel;
import projectzombie.menu.gui.GUISavesCard; import projectzombie.menu.gui.GUISavesCard;
import projectzombie.menu.gui.GUIButtonModel; import projectzombie.menu.gui.GUIButtonModel;
import projectzombie.menu.gui.components.ButtonBasic; import projectzombie.menu.gui.GUIButtonSetting;
import projectzombie.menu.gui.components.ButtonCallback; import projectzombie.menu.gui.GUIContainerSlider;
import projectzombie.menu.gui.components.ButtonSetting;
public class MenuSaves extends Menu public class MenuSaves extends Menu
{ {
private static final Random rand = new Random(); private static final Random rand = new Random();
private Menu parent; private Menu parent;
private GUI gui, gui_cards; private GUIContainerSlider slider;
private GUI gui;
public MenuSaves(Menu parent) public MenuSaves(Menu parent)
{ {
@ -34,34 +36,25 @@ public class MenuSaves extends Menu
doGameRender = parent.doGameRender; doGameRender = parent.doGameRender;
showIngameGUI = parent.showIngameGUI; showIngameGUI = parent.showIngameGUI;
gui = new GUI() gui = new GUI();
{
@Override
public void render()
{
GL33.glUniform4f(Main.window.glsl_discard_coords, -0.5f, -0.5f, 0.5f, 0.5f);
super.render();
GL33.glUniform4f(Main.window.glsl_discard_coords, -1, -1, 1, 1);
}
};
gui_cards = new GUI();
input = new InputGUI(gui); input = new InputGUI(gui);
keepMouse = false; keepMouse = false;
ButtonBasic buttonBack = new ButtonBasic("Back", button -> { GUIButtonBasic buttonBack = new GUIButtonBasic("Back", button -> {
Main.menu = parent; Main.menu = parent;
}); });
ButtonBasic buttonCreate = new ButtonBasic("Create", button -> { GUIButtonBasic buttonCreate = new GUIButtonBasic("Create", button -> {
Layers.createWorld(null, rand.nextLong()); Layers.createWorld(null, rand.nextLong());
Main.menu = new MenuGame(); Main.menu = new MenuGame();
}); });
slider = new GUIContainerSlider(new Vec2d(-20, -5), new Vec2d(40, 10), 10);
GUISavesCard savesCard = new GUISavesCard(new Vec2d(0, 0)); GUISavesCard savesCard = new GUISavesCard(new Vec2d(0, 0));
gui_cards.add(savesCard); slider.add(savesCard);
buttonBack.setAlign(GUIAlignment.RIGHT); buttonBack.setAlign(GUIAlignment.RIGHT);
buttonCreate.setAlign(GUIAlignment.LEFT); buttonCreate.setAlign(GUIAlignment.LEFT);
@ -73,11 +66,11 @@ public class MenuSaves extends Menu
labelSaves.setText("Saves"); labelSaves.setText("Saves");
labelSaves.setSize(new Vec2d(1, 1)); labelSaves.setSize(new Vec2d(1, 1));
labelSaves.setPos(new Vec2d(0, 6.8)); labelSaves.setPos(new Vec2d(0, 6.8));
gui_cards.add(labelSaves); gui.add(labelSaves);
gui.add(buttonBack); gui.add(buttonBack);
gui.add(buttonCreate); gui.add(buttonCreate);
gui.add(gui_cards); gui.add(slider);
} }
@Override @Override

View File

@ -8,21 +8,20 @@ import projectzombie.display.DisplayWindow;
import projectzombie.entity.EntityParticle; import projectzombie.entity.EntityParticle;
import projectzombie.input.types.InputGUI; import projectzombie.input.types.InputGUI;
import projectzombie.menu.gui.GUIButton; import projectzombie.menu.gui.GUIButton;
import projectzombie.menu.gui.GUIButtonBasic;
import projectzombie.menu.gui.GUIButtonGroup; import projectzombie.menu.gui.GUIButtonGroup;
import projectzombie.menu.gui.GUIButtonSetting;
import projectzombie.menu.gui.GUI; import projectzombie.menu.gui.GUI;
import projectzombie.menu.gui.GUIBackToMenu;
import projectzombie.menu.gui.GUISelectableDirection; import projectzombie.menu.gui.GUISelectableDirection;
import projectzombie.menu.gui.GUILabel; import projectzombie.menu.gui.GUILabel;
import projectzombie.menu.gui.components.ButtonBasic;
import projectzombie.menu.gui.components.ButtonSetting;
import projectzombie.menu.gui.components.GUIBackToMenu;
import projectzombie.menu.gui.components.OverlayBackground;
import projectzombie.settings.SettingQuality; import projectzombie.settings.SettingQuality;
import projectzombie.settings.Settings; import projectzombie.settings.Settings;
import projectzombie.world.chunk.Chunk; import projectzombie.world.chunk.Chunk;
public class MenuSettings extends Menu public class MenuSettings extends Menu
{ {
public ButtonSetting buttonFullscreen; public GUIButtonSetting buttonFullscreen;
private GUI gui; private GUI gui;
private Menu menuOld; private Menu menuOld;
@ -51,19 +50,25 @@ public class MenuSettings extends Menu
GUIButtonGroup group = new GUIButtonGroup(); GUIButtonGroup group = new GUIButtonGroup();
group.setPos(new Vec2d(-1, 4)); group.setPos(new Vec2d(-1, 4));
group.add(new ButtonSetting("FPS: " + (DisplayRenderUI.showFPS ? "On" : "Off"), button -> { group.add(new GUIButtonSetting("FPS: " + (DisplayRenderUI.showFPS ? "On" : "Off"), button -> {
DisplayRenderUI.showFPS = !DisplayRenderUI.showFPS; DisplayRenderUI.showFPS = !DisplayRenderUI.showFPS;
button.setText("FPS: " + (DisplayRenderUI.showFPS ? "On" : "Off")); button.setText("FPS: " + (DisplayRenderUI.showFPS ? "On" : "Off"));
Settings.update(); Settings.update();
})); }));
group.add(buttonFullscreen = new ButtonSetting("Fullscreen: " + (DisplayWindow.fullscreen ? "On" : "Off"), group.add(new GUIButtonSetting("VSync: " + (DisplayWindow.vsync ? "On" : "Off"), button -> {
DisplayWindow.setVSync(!DisplayWindow.vsync);
button.setText("VSync: " + (DisplayWindow.vsync ? "On" : "Off"));
Settings.update();
}));
group.add(buttonFullscreen = new GUIButtonSetting("Fullscreen: " + (DisplayWindow.fullscreen ? "On" : "Off"),
button -> { button -> {
Main.window.toggleFullscreen(); Main.window.toggleFullscreen();
button.setText("Fullscreen: " + (DisplayWindow.fullscreen ? "On" : "Off")); button.setText("Fullscreen: " + (DisplayWindow.fullscreen ? "On" : "Off"));
})); }));
group.add(new ButtonSetting("Debug mode: " + (DisplayRenderUI.debug ? "On" : "Off"), group.add(new GUIButtonSetting("Debug mode: " + (DisplayRenderUI.debug ? "On" : "Off"),
button -> button ->
{ {
DisplayRenderUI.debug = !DisplayRenderUI.debug; DisplayRenderUI.debug = !DisplayRenderUI.debug;
@ -71,7 +76,7 @@ public class MenuSettings extends Menu
Settings.update(); Settings.update();
})); }));
group.add(new ButtonSetting("Render distance: "+Chunk.RENDER_DISTANCE, button -> { group.add(new GUIButtonSetting("Render distance: "+Chunk.RENDER_DISTANCE, button -> {
Chunk.RENDER_DISTANCE += 1; Chunk.RENDER_DISTANCE += 1;
if(Chunk.RENDER_DISTANCE > 8) { if(Chunk.RENDER_DISTANCE > 8) {
Chunk.RENDER_DISTANCE = 2; Chunk.RENDER_DISTANCE = 2;
@ -80,7 +85,7 @@ public class MenuSettings extends Menu
Settings.update(); Settings.update();
})); }));
group.add(new ButtonSetting("Shadows: " + render(DisplayRender.getShadowQuality()), button -> group.add(new GUIButtonSetting("Shadows: " + render(DisplayRender.getShadowQuality()), button ->
{ {
SettingQuality quality = DisplayRender.getShadowQuality(); SettingQuality quality = DisplayRender.getShadowQuality();
@ -127,10 +132,6 @@ public class MenuSettings extends Menu
gui = new GUIBackToMenu(menuOld); gui = new GUIBackToMenu(menuOld);
input = new InputGUI(gui); input = new InputGUI(gui);
if(doGameRender) {
gui.add(new OverlayBackground());
}
gui.add(group); gui.add(group);
GUILabel labelSettings = new GUILabel(); GUILabel labelSettings = new GUILabel();
@ -139,7 +140,7 @@ public class MenuSettings extends Menu
labelSettings.setPos(new Vec2d(0, 6.8)); labelSettings.setPos(new Vec2d(0, 6.8));
gui.add(labelSettings); gui.add(labelSettings);
GUIButton buttonBack = new ButtonBasic("Back", new Vec2d(0, -8), button -> { GUIButton buttonBack = new GUIButtonBasic("Back", new Vec2d(0, -8), button -> {
Main.menu = menuOld; Main.menu = menuOld;
}); });

View File

@ -2,6 +2,7 @@ package projectzombie.menu.gui;
import java.util.ArrayList; import java.util.ArrayList;
import gl_engine.matrix.Matrix4;
import gl_engine.vec.Vec2d; import gl_engine.vec.Vec2d;
public class GUI implements GUIContainer public class GUI implements GUIContainer
@ -24,14 +25,14 @@ public class GUI implements GUIContainer
} }
@Override @Override
public void render(Vec2d mousePos) { public void render(Matrix4 matrix, Vec2d mousePos, boolean canHover) {
for(GUIComponent c : components) { for(GUIComponent c : components) {
c.render(mousePos); c.render(matrix, mousePos, canHover);
} }
} }
public void render() { public void render() {
this.render(mousePos); this.render(Matrix4.identity(), mousePos, true);
} }
@Override @Override
@ -141,4 +142,15 @@ public class GUI implements GUIContainer
} }
} }
@Override
public void onScroll(Vec2d mousePos, double amount) {
for(GUIComponent c : components) {
c.onScroll(mousePos, amount);
}
}
public void onScroll(int amount) {
onScroll(mousePos, amount / 10.0);
}
} }

View File

@ -1,8 +1,7 @@
package projectzombie.menu.gui.components; package projectzombie.menu.gui;
import projectzombie.Main; import projectzombie.Main;
import projectzombie.menu.Menu; import projectzombie.menu.Menu;
import projectzombie.menu.gui.GUI;
public class GUIBackToMenu extends GUI public class GUIBackToMenu extends GUI
{ {

View File

@ -69,7 +69,7 @@ public class GUIButton implements GUIComponent, GUISelectable
} }
@Override @Override
public void render(Vec2d mousePos) public void render(Matrix4 matrix, Vec2d mousePos, boolean canHover)
{ {
if(this.dirty) { if(this.dirty) {
this.updateMatrix(); this.updateMatrix();
@ -77,14 +77,14 @@ public class GUIButton implements GUIComponent, GUISelectable
} }
ModelGui model; ModelGui model;
boolean mouseHover = InputMode.Controller ? this.selected : this.checkMouseHover(mousePos); boolean mouseHover = InputMode.Controller ? this.selected : (this.checkMouseHover(mousePos) && canHover);
if(mouseHover) { if(mouseHover) {
model = Models.UI_BUTTON_HOVER; model = Models.UI_BUTTON_HOVER;
} else { } else {
model = Models.UI_BUTTON; model = Models.UI_BUTTON;
} }
model.setModel(matrix); model.setModel(Matrix4.multiply(this.matrix, matrix));
model.render(); model.render();
Text.render(text, matrix_text); Text.render(text, matrix_text);
@ -171,6 +171,9 @@ public class GUIButton implements GUIComponent, GUISelectable
@Override @Override
public void onRightClick(Vec2d pos) { public void onRightClick(Vec2d pos) {
}
@Override
public void onScroll(Vec2d mousePos, double amount) {
} }
} }

View File

@ -0,0 +1,27 @@
package projectzombie.menu.gui;
import gl_engine.vec.Vec2d;
public class GUIButtonBasic extends GUIButton {
private GUIButtonCallback callback;
public GUIButtonBasic(String text, GUIButtonCallback callback) {
setText(text);
this.callback = callback;
}
public GUIButtonBasic(String text, Vec2d pos, GUIButtonCallback callback) {
this(text, callback);
setPos(pos);
}
@Override
public void onMouseClick(Vec2d pos) {
super.onMouseClick(pos);
callback.onClick(this);
}
}

View File

@ -0,0 +1,5 @@
package projectzombie.menu.gui;
public interface GUIButtonCallback {
public void onClick(GUIButton button);
}

View File

@ -2,6 +2,7 @@ package projectzombie.menu.gui;
import java.util.ArrayList; import java.util.ArrayList;
import gl_engine.matrix.Matrix4;
import gl_engine.vec.Vec2d; import gl_engine.vec.Vec2d;
public class GUIButtonGroup implements GUIContainer public class GUIButtonGroup implements GUIContainer
@ -36,9 +37,9 @@ public class GUIButtonGroup implements GUIContainer
} }
@Override @Override
public void render(Vec2d mousePos) { public void render(Matrix4 matrix, Vec2d mousePos, boolean canHover) {
for(GUIButton b : buttons) { for(GUIButton b : buttons) {
b.render(mousePos); b.render(matrix, mousePos, canHover);
} }
} }
@ -97,4 +98,11 @@ public class GUIButtonGroup implements GUIContainer
} }
} }
@Override
public void onScroll(Vec2d mousePos, double amount) {
for(GUIButton c : buttons) {
c.onScroll(mousePos, amount);
}
}
} }

View File

@ -1,15 +1,14 @@
package projectzombie.menu.gui.components; package projectzombie.menu.gui;
import gl_engine.vec.Vec2d; import gl_engine.vec.Vec2d;
import projectzombie.Main; import projectzombie.Main;
import projectzombie.menu.MenuSettings; import projectzombie.menu.MenuSettings;
import projectzombie.menu.gui.GUIButtonGroup;
public class ButtonGroupPause extends GUIButtonGroup public class GUIButtonGroupPause extends GUIButtonGroup
{ {
public ButtonGroupPause() public GUIButtonGroupPause()
{ {
add(new ButtonBasic("Settings", button -> { add(new GUIButtonBasic("Settings", button -> {
Main.menu.input.mousePos(new Vec2d(0, 0)); Main.menu.input.mousePos(new Vec2d(0, 0));
Main.menu = new MenuSettings(Main.menu); Main.menu = new MenuSettings(Main.menu);
})); }));

View File

@ -28,11 +28,11 @@ public class GUIButtonModel implements GUIComponent
} }
@Override @Override
public void render(Vec2d mousePos) public void render(Matrix4 matrix, Vec2d mousePos, boolean canHover)
{ {
Model model = checkMouseHover(mousePos) ? this.modelHover : this.model; Model model = (checkMouseHover(mousePos) && canHover) ? this.modelHover : this.model;
model.setModel(Matrix4.translate(pos.x, pos.y, 0)); model.setModel(Matrix4.multiply(Matrix4.translate(pos.x, pos.y, 0), matrix));
model.render(); model.render();
} }
@ -66,4 +66,8 @@ public class GUIButtonModel implements GUIComponent
public void onBack() { public void onBack() {
} }
@Override
public void onScroll(Vec2d mousePos, double amount) {
}
} }

View File

@ -1,13 +1,12 @@
package projectzombie.menu.gui.components; package projectzombie.menu.gui;
import gl_engine.vec.Vec2d; import gl_engine.vec.Vec2d;
import projectzombie.menu.gui.GUIAlignment;
import projectzombie.settings.Settings; import projectzombie.settings.Settings;
public class ButtonSetting extends ButtonBasic public class GUIButtonSetting extends GUIButtonBasic
{ {
public ButtonSetting(String text, ButtonCallback callback) { public GUIButtonSetting(String text, GUIButtonCallback callback) {
super(text, callback); super(text, callback);
this.setAlign(GUIAlignment.RIGHT); this.setAlign(GUIAlignment.RIGHT);

View File

@ -1,16 +1,18 @@
package projectzombie.menu.gui; package projectzombie.menu.gui;
import gl_engine.matrix.Matrix4;
import gl_engine.vec.Vec2d; import gl_engine.vec.Vec2d;
public interface GUIComponent public interface GUIComponent
{ {
public void render(Vec2d mousePos); public void render(Matrix4 matrix, Vec2d mousePos, boolean canHover);
public void update(Vec2d mousePos); public void update(Vec2d mousePos);
public boolean checkMouseHover(Vec2d pos); public boolean checkMouseHover(Vec2d mousePos);
public void onRightClick(Vec2d pos); public void onScroll(Vec2d mousePos, double amount);
public void onMouseClick(Vec2d pos); public void onRightClick(Vec2d mousePos);
public void onMouseClick(Vec2d mousePos);
public void onActivate(); public void onActivate();
public void onBack(); public void onBack();
} }

View File

@ -0,0 +1,145 @@
package projectzombie.menu.gui;
import java.util.ArrayList;
import org.lwjgl.opengl.GL33;
import gl_engine.matrix.Matrix4;
import gl_engine.vec.Vec2d;
import gl_engine.vec.Vec4d;
import projectzombie.Main;
public class GUIContainerSlider implements GUIComponent, GUIContainer
{
private ArrayList<GUIComponent> components = new ArrayList<GUIComponent>();
private Vec2d pos;
private Vec2d size;
private double length;
private double scroll = 0;
public GUIContainerSlider(Vec2d pos, Vec2d size, double length) {
this.pos = pos;
this.size = size;
this.length = length;
}
public void setLength(double length) {
this.length = length;
}
@Override
public void add(GUIComponent c) {
components.add(c);
}
@Override
public void render(Matrix4 matrix, Vec2d mousePos, boolean canHover)
{
if(mousePos.y < pos.y || mousePos.y > pos.y + size.y) {
canHover = false;
}
matrix = Matrix4.multiply(matrix, Matrix4.translate(0, -scroll, 0));
mousePos = mousePos.add(new Vec2d(0, scroll));
GL33.glUniform1i(Main.window.glsl_do_discard_coords, 1);
GL33.glUniform4f(Main.window.glsl_discard_coords,
(float)pos.x, (float)pos.y, (float)(pos.x + size.x), (float)(pos.y + size.y));
for(GUIComponent c : components) {
c.render(matrix, mousePos, canHover);
}
GL33.glUniform1i(Main.window.glsl_do_discard_coords, 0);
}
@Override
public void update(Vec2d mousePos)
{
if(mousePos.y < pos.y || mousePos.y > pos.y + size.y) {
return;
}
mousePos = mousePos.add(new Vec2d(0, scroll));
for(GUIComponent c : components) {
c.update(mousePos);
}
}
@Override
public boolean checkMouseHover(Vec2d pos) {
return true;
}
@Override
public void onRightClick(Vec2d mousePos)
{
if(mousePos.y < pos.y || mousePos.y > pos.y + size.y) {
return;
}
mousePos = mousePos.add(new Vec2d(0, scroll));
for(GUIComponent c : components) {
if(c.checkMouseHover(mousePos)) {
c.onRightClick(mousePos);
}
}
}
@Override
public void onMouseClick(Vec2d mousePos)
{
if(mousePos.y < pos.y || mousePos.y > pos.y + size.y) {
return;
}
mousePos = mousePos.add(new Vec2d(0, scroll));
for(GUIComponent c : components) {
if(c.checkMouseHover(mousePos)) {
c.onMouseClick(mousePos);
}
}
}
@Override
public void onActivate() {
for(GUIComponent c : components) {
c.onActivate();
}
}
@Override
public void onBack() {
for(GUIComponent c : components) {
c.onBack();
}
}
@Override
public void onScroll(Vec2d mousePos, double amount)
{
// Only scroll if the mouse is hovering over the scroll area
if(
mousePos.x > pos.x && mousePos.x < pos.x + size.x &&
mousePos.y > pos.y && mousePos.y < pos.y + size.y)
{
scroll -= amount;
if(scroll < 0) {
scroll = 0;
}
if(scroll > length) {
scroll = length;
}
}
for(GUIComponent c : components) {
c.onScroll(mousePos, amount);
}
}
}

View File

@ -22,12 +22,12 @@ public class GUIItemHolder implements GUIComponent
} }
@Override @Override
public void render(Vec2d mousePos) public void render(Matrix4 matrix, Vec2d mousePos, boolean canHover)
{ {
if(!holding.isEmpty()) if(!holding.isEmpty())
{ {
Model model = holding.item.getModel(holding.meta).getGuiModel(); Model model = holding.item.getModel(holding.meta).getGuiModel();
Matrix4 matrix = Matrix4.translate(mousePos.x - 0.425, mousePos.y - 0.425, 0); matrix = Matrix4.multiply(Matrix4.translate(mousePos.x - 0.425, mousePos.y - 0.425, 0), matrix);
model.setModel(matrix); model.setModel(matrix);
model.render(); model.render();
@ -188,4 +188,8 @@ public class GUIItemHolder implements GUIComponent
} }
} }
@Override
public void onScroll(Vec2d mousePos, double amount) {
}
} }

View File

@ -48,11 +48,11 @@ public class GUIItemSlot implements GUIComponent
} }
@Override @Override
public void render(Vec2d mousePos) public void render(Matrix4 matrix, Vec2d mousePos, boolean canHover)
{ {
ItemStack stack = getter.getItemStack(); ItemStack stack = getter.getItemStack();
Matrix4 matrix = Matrix4.translate(pos.x, pos.y, 0); matrix = Matrix4.multiply(Matrix4.translate(pos.x, pos.y, 0), matrix);
Model model = stack.item.getModel(stack.meta).getGuiModel(); Model model = stack.item.getModel(stack.meta).getGuiModel();
if(stack.isEmpty()) { if(stack.isEmpty()) {
@ -65,7 +65,7 @@ public class GUIItemSlot implements GUIComponent
model.render(); model.render();
} }
if(checkMouseHover(mousePos)) if(checkMouseHover(mousePos) && canHover)
{ {
double offset = (0.85 - hitboxSize) / 2; double offset = (0.85 - hitboxSize) / 2;
Matrix4 hover_matrix = Matrix4.multiply(matrix, Matrix4.translate(offset, offset, 0)); Matrix4 hover_matrix = Matrix4.multiply(matrix, Matrix4.translate(offset, offset, 0));
@ -122,5 +122,8 @@ public class GUIItemSlot implements GUIComponent
public void update(Vec2d mousePos) { public void update(Vec2d mousePos) {
} }
@Override
public void onScroll(Vec2d mousePos, double amount) {
}
} }

View File

@ -29,7 +29,7 @@ public class GUILabel implements GUIComponent
} }
@Override @Override
public void render(Vec2d mousePos) public void render(Matrix4 matrix, Vec2d mousePos, boolean canHover)
{ {
double off = 0; double off = 0;
@ -45,7 +45,6 @@ public class GUILabel implements GUIComponent
break; break;
} }
Matrix4 matrix = Matrix4.identity();
matrix = Matrix4.multiply(matrix, Matrix4.scale(new Vec3d(size, 1))); matrix = Matrix4.multiply(matrix, Matrix4.scale(new Vec3d(size, 1)));
matrix = Matrix4.multiply(matrix, Matrix4.translate(pos.x - off, pos.y, 1)); matrix = Matrix4.multiply(matrix, Matrix4.translate(pos.x - off, pos.y, 1));
@ -77,4 +76,8 @@ public class GUILabel implements GUIComponent
public void onRightClick(Vec2d pos) { public void onRightClick(Vec2d pos) {
} }
@Override
public void onScroll(Vec2d mousePos, double amount) {
}
} }

View File

@ -0,0 +1,12 @@
package projectzombie.menu.gui;
import gl_engine.vec.Vec2d;
public class GUILabelMain extends GUILabel
{
public GUILabelMain() {
setText("Project Zombie");
setSize(new Vec2d(1.2, 1.2));
setPos(new Vec2d(0, 3.2));
}
}

View File

@ -0,0 +1,12 @@
package projectzombie.menu.gui;
import gl_engine.vec.Vec2d;
public class GUILabelPause extends GUILabel
{
public GUILabelPause(String text) {
setText(text);
setPos(new Vec2d(0, 2.4));
setSize(new Vec2d(1, 1));
}
}

View File

@ -1,48 +0,0 @@
package projectzombie.menu.gui;
import gl_engine.vec.Vec2d;
import gl_engine.vec.Vec3d;
import gl_engine.vec.Vec4d;
public class GUIOverlay implements GUIComponent
{
Vec4d color = new Vec4d(0, 0, 0, 0);
public void setColor(Vec3d color) {
this.color = new Vec4d(color.x, color.y, color.z, this.color.m);
}
public void setColor(Vec4d color) {
this.color = color;
}
@Override
public void render(Vec2d mousePos) {
}
@Override
public boolean checkMouseHover(Vec2d pos) {
return false;
}
@Override
public void onMouseClick(Vec2d pos) {
}
@Override
public void onBack() {
}
@Override
public void onActivate() {
}
@Override
public void update(Vec2d mousePos) {
}
@Override
public void onRightClick(Vec2d pos) {
}
}

View File

@ -40,13 +40,13 @@ public class GUISavesCard implements GUIComponent
} }
@Override @Override
public void render(Vec2d mousePos) public void render(Matrix4 matrix, Vec2d mousePos, boolean canHover)
{ {
LABEL.setModel(Matrix4.translate(pos.x, pos.y, 0)); LABEL.setModel(Matrix4.multiply(Matrix4.translate(pos.x, pos.y, 0), matrix));
LABEL.render(); LABEL.render();
buttonDelete.render(mousePos); buttonDelete.render(matrix, mousePos, canHover);
buttonPlay.render(mousePos); buttonPlay.render(matrix, mousePos, canHover);
} }
@Override @Override
@ -89,4 +89,8 @@ public class GUISavesCard implements GUIComponent
buttonPlay.onBack(); buttonPlay.onBack();
} }
@Override
public void onScroll(Vec2d mousePos, double amount) {
}
} }

View File

@ -1,28 +0,0 @@
package projectzombie.menu.gui.components;
import gl_engine.vec.Vec2d;
import projectzombie.menu.gui.GUIButton;
public class ButtonBasic extends GUIButton {
private ButtonCallback callback;
public ButtonBasic(String text, ButtonCallback callback) {
setText(text);
this.callback = callback;
}
public ButtonBasic(String text, Vec2d pos, ButtonCallback callback) {
this(text, callback);
setPos(pos);
}
@Override
public void onMouseClick(Vec2d pos) {
super.onMouseClick(pos);
callback.onClick(this);
}
}

View File

@ -1,7 +0,0 @@
package projectzombie.menu.gui.components;
import projectzombie.menu.gui.GUIButton;
public interface ButtonCallback {
public void onClick(GUIButton button);
}

View File

@ -1,13 +0,0 @@
package projectzombie.menu.gui.components;
import gl_engine.vec.Vec2d;
import projectzombie.menu.gui.GUILabel;
public class LabelMain extends GUILabel
{
public LabelMain() {
setText("Project Zombie");
setSize(new Vec2d(1.2, 1.2));
setPos(new Vec2d(0, 3.2));
}
}

View File

@ -1,13 +0,0 @@
package projectzombie.menu.gui.components;
import gl_engine.vec.Vec2d;
import projectzombie.menu.gui.GUILabel;
public class LabelPause extends GUILabel
{
public LabelPause(String text) {
setText(text);
setPos(new Vec2d(0, 2.4));
setSize(new Vec2d(1, 1));
}
}

View File

@ -1,11 +0,0 @@
package projectzombie.menu.gui.components;
import gl_engine.vec.Vec4d;
import projectzombie.menu.gui.GUIOverlay;
public class OverlayBackground extends GUIOverlay
{
public OverlayBackground() {
setColor(new Vec4d(0, 0, 0, 0.5));
}
}

View File

@ -42,6 +42,14 @@ public class Settings implements IBdfClassManager
if(nl.get("fullscreen").getType() == BdfTypes.BOOLEAN) { if(nl.get("fullscreen").getType() == BdfTypes.BOOLEAN) {
DisplayWindow.fullscreen = nl.get("fullscreen").getBoolean(); DisplayWindow.fullscreen = nl.get("fullscreen").getBoolean();
} else {
DisplayWindow.fullscreen = true;
}
if(nl.get("vsync").getType() == BdfTypes.BOOLEAN) {
DisplayWindow.vsync = nl.get("vsync").getBoolean();
} else {
DisplayWindow.vsync = true;
} }
if(nl.get("shadow_size").getType() == BdfTypes.INTEGER) if(nl.get("shadow_size").getType() == BdfTypes.INTEGER)
@ -110,7 +118,8 @@ public class Settings implements IBdfClassManager
nl.set("show_fps", BdfObject.withBoolean(DisplayRenderUI.showFPS)); nl.set("show_fps", BdfObject.withBoolean(DisplayRenderUI.showFPS));
nl.set("debug", BdfObject.withBoolean(DisplayRenderUI.debug)); nl.set("debug", BdfObject.withBoolean(DisplayRenderUI.debug));
nl.set("shadow_size", BdfObject.withInteger(shadow_size)); nl.set("shadow_size", BdfObject.withInteger(shadow_size));
nl.set("fullscreen", BdfObject.withBoolean(Main.window.fullscreen)); nl.set("fullscreen", BdfObject.withBoolean(DisplayWindow.fullscreen));
nl.set("vsync", BdfObject.withBoolean(DisplayWindow.vsync));
} }
public static void init() { public static void init() {

View File

@ -23,6 +23,7 @@ uniform vec3 lighting_day_high;
uniform vec2 lightmap_offset; uniform vec2 lightmap_offset;
uniform vec2 lightmap_size; uniform vec2 lightmap_size;
uniform int do_discard_coords;
uniform vec4 discard_coords; uniform vec4 discard_coords;
uniform vec4 color; uniform vec4 color;
@ -100,7 +101,7 @@ void main()
FragColor.b = min(1, FragColor.b); FragColor.b = min(1, FragColor.b);
} }
discard(textureRGB.a == 0 || ( discard(textureRGB.a == 0 || (do_discard_coords == 1 && (
pVertex.x < discard_coords.x || pVertex.y < discard_coords.y || pVertex.x < discard_coords.x || pVertex.y < discard_coords.y ||
pVertex.x > discard_coords.z || pVertex.y > discard_coords.w)); pVertex.x > discard_coords.z || pVertex.y > discard_coords.w)));
} }

View File

@ -66,9 +66,8 @@ void main()
vec4 pos = vec4(aPos, 1) * (mod(type >> 3, 2) == 1 ? billboard : (mod(type, 2) == 1 ? rotated : mat4(1))) * vec4 pos = vec4(aPos, 1) * (mod(type >> 3, 2) == 1 ? billboard : (mod(type, 2) == 1 ? rotated : mat4(1))) *
translate(aOffset) * model; translate(aOffset) * model;
vec4 vertex = pos * projection; gl_Position = pos * projection;
gl_Position = vertex; pVertex = pos.xy / pos.w;
pVertex = vertex.xy / vertex.w;
if(mode == 0) { if(mode == 0) {
pCameraDepth = mod(type >> 4, 2) == 1 ? 0 : min(1, mist * (-(pos * camera).z * 0.5 + 0.5)); pCameraDepth = mod(type >> 4, 2) == 1 ? 0 : min(1, mist * (-(pos * camera).z * 0.5 + 0.5));

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.0 KiB

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

@ -79,6 +79,7 @@
./gui/button_play.png ./gui/button_play.png
./gui/slot_armor_legs.png ./gui/slot_armor_legs.png
./gui/inventory.png ./gui/inventory.png
./gui/selection_box.png
./gui/label.png ./gui/label.png
./gui/slot_clothing_pants.png ./gui/slot_clothing_pants.png
./gui/health_empty.png ./gui/health_empty.png

Binary file not shown.