Title stuff

This commit is contained in:
Jose 2017-11-14 09:49:35 -05:00
commit cf8201075a
5 changed files with 47 additions and 21 deletions

View file

@ -1,12 +1,11 @@
package com.oitsjustjose.crawlnbrawl;
import com.oitsjustjose.crawlnbrawl.Entity.Living.EntityMonster;
import com.oitsjustjose.crawlnbrawl.Entity.Living.EntityPlayer;
import com.oitsjustjose.crawlnbrawl.Manager.AudioManager;
import com.oitsjustjose.crawlnbrawl.Manager.SceneManager;
import com.oitsjustjose.crawlnbrawl.Manager.ScreenshotManager;
import com.oitsjustjose.crawlnbrawl.Scene.Dungeon;
import com.oitsjustjose.crawlnbrawl.Scene.GUIButton;
import com.oitsjustjose.crawlnbrawl.Scene.Button;
import com.oitsjustjose.crawlnbrawl.Scene.Menu;
import com.oitsjustjose.crawlnbrawl.Scene.Scene;
import com.oitsjustjose.crawlnbrawl.Util.Config;
@ -14,6 +13,7 @@ import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.lwjgl.opengl.GL11;
import org.newdawn.slick.Color;
import org.newdawn.slick.opengl.PNGDecoder;
import org.newdawn.slick.util.ResourceLoader;
@ -52,8 +52,8 @@ public class Game
public void initGame()
{
Menu menu = new Menu();
menu.addButton(new GUIButton((Display.getWidth() / 2) - 64, (Display.getHeight() / 2) - 64, 128, 32, "Play"), new Dungeon());
menu.addButton(new GUIButton((Display.getWidth() / 2) - 64, (Display.getHeight() / 2) - 16, 128, 32, "Exit"), null);
menu.addButton(new Button((Display.getWidth() / 2) - 64, (Display.getHeight() / 2) - 64, 128, 32, "Play", new Color(200, 200, 200), new Color(85, 124, 0)), new Dungeon());
menu.addButton(new Button((Display.getWidth() / 2) - 64, (Display.getHeight() / 2) - 16, 128, 32, "Exit", new Color(200, 200, 200), new Color(85, 124, 0)), null);
Scene currScene = menu;
while (currScene.go())

View file

@ -16,7 +16,7 @@ import java.awt.FontFormatException;
import java.io.File;
import java.io.IOException;
public class GUIButton
public class Button
{
private String buttonText;
private Rectangle box;
@ -25,12 +25,12 @@ public class GUIButton
private TrueTypeFont font;
private boolean hovering;
public GUIButton(int x, int y, int w, int h, String text)
public Button(int x, int y, int w, int h, String text)
{
this(x, y, w, h, text, new Color(0, 0, 0), new Color(0.9F, 0.9F, 0.9F));
}
public GUIButton(int x, int y, int w, int h, String text, Color textColor, Color color)
public Button(int x, int y, int w, int h, String text, Color textColor, Color color)
{
this.box = new Rectangle(x, y, w, h);
this.buttonText = text;

View file

@ -171,13 +171,13 @@ public class Dungeon extends SceneLevel
if (player == null || player.getState() == EntityPlayer.State.DEAD)
{
menu.addButton(new GUIButton((Display.getWidth() / 2) - 64, (Display.getHeight() / 2) - 64, 128, 32, "Play Again"), new Dungeon());
menu.addButton(new Button((Display.getWidth() / 2) - 64, (Display.getHeight() / 2) - 64, 128, 32, "Play Again", new org.newdawn.slick.Color(200, 200, 200), new org.newdawn.slick.Color(85, 124, 0)), new Dungeon());
}
else
{
menu.addButton(new GUIButton((Display.getWidth() / 2) - 64, (Display.getHeight() / 2) - 64, 128, 32, "Resume"), this);
menu.addButton(new Button((Display.getWidth() / 2) - 64, (Display.getHeight() / 2) - 64, 128, 32, "Resume", new org.newdawn.slick.Color(200, 200, 200), new org.newdawn.slick.Color(85, 124, 0)), this);
}
menu.addButton(new GUIButton((Display.getWidth() / 2) - 64, (Display.getHeight() / 2) - 16, 128, 32, "Exit"), null);
menu.addButton(new Button((Display.getWidth() / 2) - 64, (Display.getHeight() / 2) - 16, 128, 32, "Exit", new org.newdawn.slick.Color(200, 200, 200), new org.newdawn.slick.Color(85, 124, 0)), null);
return menu;
}

View file

@ -1,19 +1,46 @@
package com.oitsjustjose.crawlnbrawl.Scene;
import com.oitsjustjose.crawlnbrawl.Util.FileUtils;
import org.lwjgl.LWJGLException;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.GL11;
import org.newdawn.slick.TrueTypeFont;
import org.newdawn.slick.util.ResourceLoader;
import java.awt.*;
import java.awt.font.TextAttribute;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.LinkedHashMap;
public class Menu extends Scene
{
private LinkedHashMap<GUIButton, Scene> buttons;
private LinkedHashMap<Button, Scene> buttons;
private Scene nextScene;
private TrueTypeFont titleFont;
public Menu()
{
HashMap<TextAttribute, Integer> titleAttributes = new HashMap<>();
titleAttributes.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
try
{
File font = new File("natives/justabit.ttf".replace("/", File.separator)).getAbsoluteFile();
if (!font.exists())
{
System.out.println("Font did not exist; copying...");
FileUtils.copyStream(ResourceLoader.getResourceAsStream("assets/justabit.ttf"), new File("natives/justabit.ttf".replace("/", File.separator)));
}
Font awtFont = Font.createFont(Font.TRUETYPE_FONT, font).deriveFont(titleAttributes).deriveFont(64F);
titleFont = new TrueTypeFont(awtFont, false);
}
catch (IOException | FontFormatException e)
{
titleFont = new TrueTypeFont(new Font("Arial", Font.PLAIN, 64).deriveFont(titleAttributes).deriveFont(64F), false);
}
try
{
Mouse.setNativeCursor(null);
@ -25,7 +52,7 @@ public class Menu extends Scene
buttons = new LinkedHashMap<>();
}
public void addButton(GUIButton button, Scene scene)
public void addButton(Button button, Scene scene)
{
buttons.put(button, scene);
}
@ -42,15 +69,14 @@ public class Menu extends Scene
GL11.glLoadIdentity();
GL11.glOrtho(0, Display.getWidth(), Display.getHeight(), 0, 1, -1);
}
GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);
titleFont.drawString((Display.getWidth() / 2) - (titleFont.getWidth("Crawl 'n Brawl") / 2), 64F, "Crawl 'n Brawl", new org.newdawn.slick.Color(0, 123, 124));
updateButtons();
drawButtons();
if (Mouse.isButtonDown(0))
{
for (GUIButton b : buttons.keySet())
for (Button b : buttons.keySet())
{
if (b.isClicked())
{
@ -71,12 +97,11 @@ public class Menu extends Scene
{
int buttonCount = buttons.keySet().size();
for (GUIButton b : buttons.keySet())
for (Button b : buttons.keySet())
{
b.update();
if (Display.wasResized())
{
System.out.println("fixing buttons");
int x = (Display.getWidth() / 2) - (b.getHitBox().getWidth() / 2);
int y = (Display.getHeight() / 2) - (b.getHitBox().getHeight() * buttonCount) - ((buttonCount - buttons.keySet().size()) * 16);
b.getHitBox().setLocation(x, y);
@ -87,7 +112,7 @@ public class Menu extends Scene
public void drawButtons()
{
for (GUIButton b : buttons.keySet())
for (Button b : buttons.keySet())
{
b.draw();
}

View file

@ -16,6 +16,7 @@ import com.oitsjustjose.crawlnbrawl.Util.FileUtils;
import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.GL11;
import org.newdawn.slick.Color;
import org.newdawn.slick.TrueTypeFont;
import org.newdawn.slick.opengl.TextureImpl;
import org.newdawn.slick.util.ResourceLoader;
@ -121,13 +122,13 @@ public class Surface extends SceneLevel
Menu menu = new Menu();
if (player == null || player.getState() == EntityPlayer.State.DEAD)
{
menu.addButton(new GUIButton((Display.getWidth() / 2) - 64, (Display.getHeight() / 2) - 64, 128, 32, "Play Again"), new Dungeon());
menu.addButton(new Button((Display.getWidth() / 2) - 64, (Display.getHeight() / 2) - 64, 128, 32, "Play Again", new Color(200, 200, 200), new Color(85, 124, 0)), new Dungeon());
}
else
{
menu.addButton(new GUIButton((Display.getWidth() / 2) - 64, (Display.getHeight() / 2) - 64, 128, 32, "Resume"), this);
menu.addButton(new Button((Display.getWidth() / 2) - 64, (Display.getHeight() / 2) - 64, 128, 32, "Resume", new Color(200, 200, 200), new Color(85, 124, 0)), this);
}
menu.addButton(new GUIButton((Display.getWidth() / 2) - 64, (Display.getHeight() / 2) - 16, 128, 32, "Exit"), null);
menu.addButton(new Button((Display.getWidth() / 2) - 64, (Display.getHeight() / 2) - 16, 128, 32, "Exit", new Color(200, 200, 200), new Color(85, 124, 0)), null);
return menu;
}