Buttons!
This commit is contained in:
parent
10b4a3b455
commit
dc80e82281
8 changed files with 184 additions and 197 deletions
|
|
@ -41,7 +41,7 @@ public class EntityPlayer extends EntityLiving
|
||||||
this.health = 20F;
|
this.health = 20F;
|
||||||
this.maxHealth = 20F;
|
this.maxHealth = 20F;
|
||||||
this.speed = .6F;
|
this.speed = .6F;
|
||||||
this.heldItem = new ItemFist().setCursor();
|
this.heldItem = new ItemFist();
|
||||||
}
|
}
|
||||||
|
|
||||||
public EntityPlayer()
|
public EntityPlayer()
|
||||||
|
|
@ -59,6 +59,10 @@ public class EntityPlayer extends EntityLiving
|
||||||
@Override
|
@Override
|
||||||
public void update(float delta)
|
public void update(float delta)
|
||||||
{
|
{
|
||||||
|
if(Mouse.getNativeCursor() == null && this.heldItem != null)
|
||||||
|
{
|
||||||
|
this.heldItem.setCursor();
|
||||||
|
}
|
||||||
int motion = (int) (this.speed * delta);
|
int motion = (int) (this.speed * delta);
|
||||||
int verticalMotion = (int) (motion * motionMultiplier);
|
int verticalMotion = (int) (motion * motionMultiplier);
|
||||||
if (Keyboard.isKeyDown(Keyboard.KEY_A) && this.box.getX() > 0 && !(this.state == State.STUNNED))
|
if (Keyboard.isKeyDown(Keyboard.KEY_A) && this.box.getX() > 0 && !(this.state == State.STUNNED))
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,12 @@
|
||||||
package com.oitsjustjose.crawlnbrawl;
|
package com.oitsjustjose.crawlnbrawl;
|
||||||
|
|
||||||
import com.oitsjustjose.crawlnbrawl.Entity.Living.EntityMonster;
|
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.AudioManager;
|
||||||
import com.oitsjustjose.crawlnbrawl.Manager.SceneManager;
|
import com.oitsjustjose.crawlnbrawl.Manager.SceneManager;
|
||||||
import com.oitsjustjose.crawlnbrawl.Manager.ScreenshotManager;
|
import com.oitsjustjose.crawlnbrawl.Manager.ScreenshotManager;
|
||||||
import com.oitsjustjose.crawlnbrawl.Scene.Dungeon;
|
import com.oitsjustjose.crawlnbrawl.Scene.Dungeon;
|
||||||
|
import com.oitsjustjose.crawlnbrawl.Scene.GUIButton;
|
||||||
import com.oitsjustjose.crawlnbrawl.Scene.Menu;
|
import com.oitsjustjose.crawlnbrawl.Scene.Menu;
|
||||||
import com.oitsjustjose.crawlnbrawl.Scene.Scene;
|
import com.oitsjustjose.crawlnbrawl.Scene.Scene;
|
||||||
import com.oitsjustjose.crawlnbrawl.Util.Config;
|
import com.oitsjustjose.crawlnbrawl.Util.Config;
|
||||||
|
|
@ -49,11 +51,10 @@ public class Game
|
||||||
|
|
||||||
public void initGame()
|
public void initGame()
|
||||||
{
|
{
|
||||||
com.oitsjustjose.crawlnbrawl.Scene.Menu gameMenu = new com.oitsjustjose.crawlnbrawl.Scene.Menu();
|
Menu menu = new Menu();
|
||||||
gameMenu.addItem("Play", new Dungeon());
|
menu.addButton(new GUIButton((Display.getWidth() / 2) - 64, (Display.getHeight() / 2) - 64, 128, 32, "Play"), new Dungeon());
|
||||||
gameMenu.addSpecial("Exit", Menu.DO_EXIT);
|
menu.addButton(new GUIButton((Display.getWidth() / 2) - 64, (Display.getHeight() / 2) - 16, 128, 32, "Exit"), null);
|
||||||
|
Scene currScene = menu;
|
||||||
Scene currScene = gameMenu;
|
|
||||||
|
|
||||||
while (currScene.go())
|
while (currScene.go())
|
||||||
{
|
{
|
||||||
|
|
@ -61,7 +62,7 @@ public class Game
|
||||||
|
|
||||||
if (currScene == null)
|
if (currScene == null)
|
||||||
{
|
{
|
||||||
currScene = gameMenu;
|
currScene = menu;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,6 @@ public class Item
|
||||||
*/
|
*/
|
||||||
public Item setCursor()
|
public Item setCursor()
|
||||||
{
|
{
|
||||||
|
|
||||||
InputStream stream = ResourceLoader.getResourceAsStream("assets/textures/items/".replace("/", File.separator) + iconString + ".png");
|
InputStream stream = ResourceLoader.getResourceAsStream("assets/textures/items/".replace("/", File.separator) + iconString + ".png");
|
||||||
BufferedImage cursorImg;
|
BufferedImage cursorImg;
|
||||||
try
|
try
|
||||||
|
|
|
||||||
|
|
@ -28,5 +28,4 @@ public class SceneManager
|
||||||
{
|
{
|
||||||
this.currentSceneLevel = s;
|
this.currentSceneLevel = s;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -80,11 +80,6 @@ public class Dungeon extends SceneLevel
|
||||||
initScene();
|
initScene();
|
||||||
}
|
}
|
||||||
|
|
||||||
// public static Living getInstance()
|
|
||||||
// {
|
|
||||||
// return instance;
|
|
||||||
// }
|
|
||||||
|
|
||||||
public void initFont()
|
public void initFont()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|
@ -173,18 +168,18 @@ public class Dungeon extends SceneLevel
|
||||||
}
|
}
|
||||||
|
|
||||||
Menu menu = new Menu();
|
Menu menu = new Menu();
|
||||||
|
|
||||||
if (player == null || player.getState() == EntityPlayer.State.DEAD)
|
if (player == null || player.getState() == EntityPlayer.State.DEAD)
|
||||||
{
|
{
|
||||||
menu.addItem("Play Again", new Dungeon());
|
menu.addButton(new GUIButton((Display.getWidth() / 2) - 64, (Display.getHeight() / 2) - 64, 128, 32, "Play Again"), new Dungeon());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
menu.addItem("Resume", this);
|
menu.addButton(new GUIButton((Display.getWidth() / 2) - 64, (Display.getHeight() / 2) - 64, 128, 32, "Resume"), this);
|
||||||
}
|
}
|
||||||
menu.addSpecial("Exit", Menu.DO_EXIT);
|
menu.addButton(new GUIButton((Display.getWidth() / 2) - 64, (Display.getHeight() / 2) - 16, 128, 32, "Exit"), null);
|
||||||
|
|
||||||
return menu;
|
return menu;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
117
src/com/oitsjustjose/crawlnbrawl/Scene/GUIButton.java
Normal file
117
src/com/oitsjustjose/crawlnbrawl/Scene/GUIButton.java
Normal file
|
|
@ -0,0 +1,117 @@
|
||||||
|
package com.oitsjustjose.crawlnbrawl.Scene;
|
||||||
|
|
||||||
|
import com.oitsjustjose.crawlnbrawl.Manager.AudioManager;
|
||||||
|
import com.oitsjustjose.crawlnbrawl.Util.FileUtils;
|
||||||
|
import org.lwjgl.input.Mouse;
|
||||||
|
import org.lwjgl.opengl.Display;
|
||||||
|
import org.lwjgl.opengl.GL11;
|
||||||
|
import org.lwjgl.util.Rectangle;
|
||||||
|
import org.newdawn.slick.Color;
|
||||||
|
import org.newdawn.slick.TrueTypeFont;
|
||||||
|
import org.newdawn.slick.opengl.TextureImpl;
|
||||||
|
import org.newdawn.slick.util.ResourceLoader;
|
||||||
|
|
||||||
|
import java.awt.Font;
|
||||||
|
import java.awt.FontFormatException;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class GUIButton
|
||||||
|
{
|
||||||
|
private String buttonText;
|
||||||
|
private Rectangle box;
|
||||||
|
private Color color;
|
||||||
|
private Color textColor;
|
||||||
|
private TrueTypeFont font;
|
||||||
|
private boolean hovering;
|
||||||
|
|
||||||
|
public GUIButton(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)
|
||||||
|
{
|
||||||
|
this.box = new Rectangle(x, y, w, h);
|
||||||
|
this.buttonText = text;
|
||||||
|
this.color = color;
|
||||||
|
this.textColor = textColor;
|
||||||
|
initFont();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void initFont()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
File fontFile = new File("natives/justabit.ttf".replace("/", File.separator)).getAbsoluteFile();
|
||||||
|
if (!fontFile.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, fontFile).deriveFont(32F);
|
||||||
|
font = new TrueTypeFont(awtFont, false);
|
||||||
|
}
|
||||||
|
catch (IOException | FontFormatException e)
|
||||||
|
{
|
||||||
|
font = new TrueTypeFont(new Font("Arial", Font.PLAIN, 32), false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isClicked()
|
||||||
|
{
|
||||||
|
Rectangle mouse = new Rectangle(Mouse.getX(), Display.getHeight() - Mouse.getY(), 1, 1);
|
||||||
|
if (box.intersects(mouse) && Mouse.isButtonDown(0))
|
||||||
|
{
|
||||||
|
AudioManager.getInstance().play("menu_select");
|
||||||
|
// Sleep before processing the action
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Thread.sleep(100);
|
||||||
|
}
|
||||||
|
catch (InterruptedException e)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void update()
|
||||||
|
{
|
||||||
|
Rectangle mouse = new Rectangle(Mouse.getX(), Display.getHeight() - Mouse.getY(), 1, 1);
|
||||||
|
this.hovering = box.intersects(mouse);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void draw()
|
||||||
|
{
|
||||||
|
TextureImpl.bindNone();
|
||||||
|
float x = (float) box.getX();
|
||||||
|
float y = (float) box.getY();
|
||||||
|
float w = (float) box.getWidth();
|
||||||
|
float h = (float) box.getHeight();
|
||||||
|
|
||||||
|
if (this.hovering)
|
||||||
|
{
|
||||||
|
GL11.glColor3f(color.r + (0.1F), color.g + (0.1F), color.b + (0.1F));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
GL11.glColor3f(color.r, color.g, color.b);
|
||||||
|
}
|
||||||
|
GL11.glBegin(GL11.GL_QUADS);
|
||||||
|
GL11.glVertex2f(x, y);
|
||||||
|
GL11.glVertex2f(x + w, y);
|
||||||
|
GL11.glVertex2f(x + w, y + h);
|
||||||
|
GL11.glVertex2f(x, y + h);
|
||||||
|
GL11.glEnd();
|
||||||
|
|
||||||
|
font.drawString(x + (w / 2) - (font.getWidth(buttonText) / 2), y + (h / 2) - (font.getHeight(buttonText) / 2), buttonText, textColor);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Rectangle getHitBox()
|
||||||
|
{
|
||||||
|
return box;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,168 +1,39 @@
|
||||||
package com.oitsjustjose.crawlnbrawl.Scene;
|
package com.oitsjustjose.crawlnbrawl.Scene;
|
||||||
|
|
||||||
import com.oitsjustjose.crawlnbrawl.Game;
|
import org.lwjgl.LWJGLException;
|
||||||
import com.oitsjustjose.crawlnbrawl.Manager.AudioManager;
|
import org.lwjgl.input.Mouse;
|
||||||
import com.oitsjustjose.crawlnbrawl.Tile.TileBackground;
|
|
||||||
import com.oitsjustjose.crawlnbrawl.Util.FileUtils;
|
|
||||||
import com.oitsjustjose.crawlnbrawl.Util.Helper;
|
|
||||||
import org.lwjgl.input.Keyboard;
|
|
||||||
import org.lwjgl.opengl.Display;
|
import org.lwjgl.opengl.Display;
|
||||||
import org.lwjgl.opengl.GL11;
|
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;
|
|
||||||
|
|
||||||
import java.awt.Font;
|
import java.util.LinkedHashMap;
|
||||||
import java.awt.FontFormatException;
|
|
||||||
import java.awt.Toolkit;
|
|
||||||
import java.awt.font.TextAttribute;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class Menu extends Scene
|
public class Menu extends Scene
|
||||||
{
|
{
|
||||||
public static final int DO_EXIT = 0;
|
private LinkedHashMap<GUIButton, Scene> buttons;
|
||||||
private List<Item> items;
|
private Scene nextScene;
|
||||||
private int currItem;
|
|
||||||
private long lastChanged;
|
|
||||||
private TileBackground bg;
|
|
||||||
private TrueTypeFont menuFont;
|
|
||||||
private TrueTypeFont selectedFont;
|
|
||||||
private TrueTypeFont titleFont;
|
|
||||||
|
|
||||||
public Menu()
|
public Menu()
|
||||||
{
|
{
|
||||||
items = new LinkedList<>();
|
|
||||||
lastChanged = Helper.getTime();
|
|
||||||
bg = new TileBackground("menu");
|
|
||||||
HashMap<TextAttribute, Integer> titleAttributes = new HashMap<>();
|
|
||||||
titleAttributes.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
|
|
||||||
|
|
||||||
HashMap<TextAttribute, Integer> selectedAttributes = new HashMap<>();
|
|
||||||
selectedAttributes.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
File font = new File("natives/justabit.ttf".replace("/", File.separator)).getAbsoluteFile();
|
Mouse.setNativeCursor(null);
|
||||||
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);
|
|
||||||
|
|
||||||
awtFont = Font.createFont(Font.TRUETYPE_FONT, font).deriveFont(selectedAttributes).deriveFont(Font.BOLD).deriveFont(52F);
|
|
||||||
selectedFont = new TrueTypeFont(awtFont, false);
|
|
||||||
|
|
||||||
awtFont = Font.createFont(Font.TRUETYPE_FONT, font).deriveFont(40F);
|
|
||||||
menuFont = new TrueTypeFont(awtFont, false);
|
|
||||||
}
|
}
|
||||||
catch (IOException | FontFormatException e)
|
catch (LWJGLException e)
|
||||||
{
|
{
|
||||||
titleFont = new TrueTypeFont(new Font("Arial", Font.PLAIN, 64).deriveFont(titleAttributes).deriveFont(64F), false);
|
|
||||||
selectedFont = new TrueTypeFont(new Font("Arial", Font.BOLD, 52).deriveFont(selectedAttributes).deriveFont(Font.BOLD).deriveFont(52F), false);
|
|
||||||
menuFont = new TrueTypeFont(new Font("Arial", Font.PLAIN, 40).deriveFont(40F), false);
|
|
||||||
}
|
}
|
||||||
|
buttons = new LinkedHashMap<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
// reset menu
|
public void addButton(GUIButton button, Scene scene)
|
||||||
public void clear()
|
|
||||||
{
|
{
|
||||||
items.clear();
|
buttons.put(button, scene);
|
||||||
}
|
|
||||||
|
|
||||||
public void addItem(String label, Scene s)
|
|
||||||
{
|
|
||||||
items.add(new Item(label, s));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addSpecial(String label, int tag)
|
|
||||||
{
|
|
||||||
items.add(new Special(label, tag));
|
|
||||||
}
|
|
||||||
|
|
||||||
public Scene nextScene()
|
|
||||||
{
|
|
||||||
return items.get(currItem).scene;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean drawFrame(float delta)
|
public boolean drawFrame(float delta)
|
||||||
{
|
{
|
||||||
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
|
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
|
||||||
|
GL11.glClearColor(0.15F, 0.15F, 0.15F, 0F);
|
||||||
bg.draw();
|
|
||||||
|
|
||||||
while (Keyboard.next())
|
|
||||||
{
|
|
||||||
if (Keyboard.getEventKeyState()) // key was pressed
|
|
||||||
{
|
|
||||||
switch (Keyboard.getEventKey())
|
|
||||||
{
|
|
||||||
case Keyboard.KEY_W:
|
|
||||||
AudioManager.getInstance().play("menu_move");
|
|
||||||
currItem--;
|
|
||||||
if (currItem < 0)
|
|
||||||
{
|
|
||||||
currItem += items.size(); // go to end
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case Keyboard.KEY_UP:
|
|
||||||
AudioManager.getInstance().play("menu_move");
|
|
||||||
currItem--;
|
|
||||||
if (currItem < 0)
|
|
||||||
{
|
|
||||||
currItem += items.size(); // go to end
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case Keyboard.KEY_S:
|
|
||||||
AudioManager.getInstance().play("menu_move");
|
|
||||||
currItem = (currItem + 1) % items.size();
|
|
||||||
break;
|
|
||||||
case Keyboard.KEY_DOWN:
|
|
||||||
AudioManager.getInstance().play("menu_move");
|
|
||||||
currItem = (currItem + 1) % items.size();
|
|
||||||
break;
|
|
||||||
case Keyboard.KEY_RETURN:
|
|
||||||
AudioManager.getInstance().play("menu_select");
|
|
||||||
Item item = items.get(currItem);
|
|
||||||
if (item instanceof Special)
|
|
||||||
{
|
|
||||||
switch (((Special) item).tag)
|
|
||||||
{
|
|
||||||
case DO_EXIT:
|
|
||||||
exit();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
case Keyboard.KEY_F2:
|
|
||||||
Game.getInstance().screenshotManager.takeScreenshot();
|
|
||||||
break;
|
|
||||||
case Keyboard.KEY_F11:
|
|
||||||
if (Display.isFullscreen())
|
|
||||||
{
|
|
||||||
Game.getInstance().setDisplayMode(Game.getInstance().config.resolutionWidth, Game.getInstance().config.resolutionHeight, false);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Game.getInstance().setDisplayMode(Toolkit.getDefaultToolkit().getScreenSize().width, Toolkit.getDefaultToolkit().getScreenSize().height, true);
|
|
||||||
}
|
|
||||||
Display.setResizable(true);
|
|
||||||
GL11.glViewport(0, 0, Display.getWidth(), Display.getHeight());
|
|
||||||
GL11.glMatrixMode(GL11.GL_PROJECTION);
|
|
||||||
GL11.glLoadIdentity();
|
|
||||||
GL11.glOrtho(0, Display.getWidth(), Display.getHeight(), 0, 1, -1);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Screen resize handler
|
// Screen resize handler
|
||||||
if (Display.wasResized())
|
if (Display.wasResized())
|
||||||
{
|
{
|
||||||
|
|
@ -172,57 +43,58 @@ public class Menu extends Scene
|
||||||
GL11.glOrtho(0, Display.getWidth(), Display.getHeight(), 0, 1, -1);
|
GL11.glOrtho(0, Display.getWidth(), Display.getHeight(), 0, 1, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
float spacing = Display.getHeight() / (items.size() + 4);
|
|
||||||
float offset = 2 * spacing;
|
|
||||||
|
|
||||||
TextureImpl.bindNone();
|
|
||||||
titleFont.drawString((Display.getWidth() / 2) - (titleFont.getWidth("Crawl 'n Brawl") / 2), 64F, "Crawl 'n Brawl", new Color(0, 123, 124));
|
|
||||||
|
|
||||||
for (int i = 0; i < items.size(); i++)
|
|
||||||
{
|
|
||||||
if (i == currItem)
|
|
||||||
{
|
|
||||||
TextureImpl.bindNone();
|
|
||||||
|
|
||||||
selectedFont.drawString(Display.getWidth() / 2 - (selectedFont.getWidth(items.get(i).label) / 2), offset, items.get(i).label, new Color(85, 124, 0));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
TextureImpl.bindNone();
|
|
||||||
menuFont.drawString(Display.getWidth() / 2 - (menuFont.getWidth(items.get(i).label) / 2), offset, items.get(i).label, new Color(74, 91, 37));
|
|
||||||
}
|
|
||||||
|
|
||||||
offset += spacing;
|
|
||||||
}
|
|
||||||
|
|
||||||
// font binds a texture, so let's turn it off..
|
|
||||||
GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);
|
GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);
|
||||||
|
|
||||||
|
updateButtons();
|
||||||
|
drawButtons();
|
||||||
|
|
||||||
|
if (Mouse.isButtonDown(0))
|
||||||
|
{
|
||||||
|
for (GUIButton b : buttons.keySet())
|
||||||
|
{
|
||||||
|
if (b.isClicked())
|
||||||
|
{
|
||||||
|
nextScene = buttons.get(b);
|
||||||
|
if (nextScene == null)
|
||||||
|
{
|
||||||
|
System.exit(0);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void updateButtons()
|
||||||
// a menu item: label and associated Scene to jump to
|
|
||||||
private static class Item
|
|
||||||
{
|
{
|
||||||
public String label;
|
int buttonCount = buttons.keySet().size();
|
||||||
public Scene scene;
|
|
||||||
|
|
||||||
public Item(String label, Scene s)
|
for (GUIButton b : buttons.keySet())
|
||||||
{
|
{
|
||||||
this.label = label;
|
b.update();
|
||||||
this.scene = s;
|
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);
|
||||||
|
buttonCount -= 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class Special extends Item
|
public void drawButtons()
|
||||||
{
|
{
|
||||||
public int tag;
|
for (GUIButton b : buttons.keySet())
|
||||||
|
|
||||||
public Special(String label, int tag)
|
|
||||||
{
|
{
|
||||||
super(label, null);
|
b.draw();
|
||||||
this.tag = tag;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
public Scene nextScene()
|
||||||
|
{
|
||||||
|
return nextScene;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -117,17 +117,17 @@ public class Surface extends SceneLevel
|
||||||
{
|
{
|
||||||
return new Dungeon();
|
return new Dungeon();
|
||||||
}
|
}
|
||||||
|
|
||||||
Menu menu = new Menu();
|
Menu menu = new Menu();
|
||||||
if (player == null || player.getState() == EntityPlayer.State.DEAD)
|
if (player == null || player.getState() == EntityPlayer.State.DEAD)
|
||||||
{
|
{
|
||||||
menu.addItem("Play Again", new Dungeon());
|
menu.addButton(new GUIButton((Display.getWidth() / 2) - 64, (Display.getHeight() / 2) - 64, 128, 32, "Play Again"), new Dungeon());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
menu.addItem("Resume", this);
|
menu.addButton(new GUIButton((Display.getWidth() / 2) - 64, (Display.getHeight() / 2) - 64, 128, 32, "Resume"), this);
|
||||||
}
|
}
|
||||||
menu.addSpecial("Exit", Menu.DO_EXIT);
|
menu.addButton(new GUIButton((Display.getWidth() / 2) - 64, (Display.getHeight() / 2) - 16, 128, 32, "Exit"), null);
|
||||||
|
|
||||||
return menu;
|
return menu;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue