/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package thegame.layers;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Point;
import java.awt.Rectangle;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JOptionPane;
import net.sf.jiga.xtended.impl.Sprite;
import net.sf.jiga.xtended.impl.game.RenderingScene;
import net.sf.jiga.xtended.impl.game.TextLayout;
import net.sf.jiga.xtended.impl.game.gl.GLFX;
import net.sf.jiga.xtended.impl.game.gl.GLHandler;
import net.sf.jiga.xtended.impl.game.gl.Sf3Texture;
import net.sf.jiga.xtended.impl.game.gl.SpriteGLHandler;
import net.sf.jiga.xtended.impl.game.gl.geom.GLGeom;
import net.sf.jiga.xtended.kernel.JXAenvUtils;
import net.sf.jiga.xtended.ui.UIMessage;
import org.lwjgl.opengl.GL11;
import thegame.FieldGui;
import static thegame.FieldGui.SCREEN_DEFAULT;
import thegame.gui.SelectionMenuCell;
import thegame.gui.SelectionMenuComponent;
import thegame.Thegamelayer;
import thegame.gui.GameMenuElement;
import thegame.gui.SelectionMenu;
import thegame.gui.toolkit.TextureTK;
/**
*
* @author www.b23prodtm.info
*/
public class GameMenu extends Thegamelayer {
public GameMenu(FieldGui gui) {
super(gui, "Game Menu");
menu = new ArrayList<SelectionMenuCell>();
menu_play = new ArrayList<SelectionMenuCell>();
GameMenuElement._addToMenu(gui, menu, "MENU_exit", new Runnable() {
public void run() {
if (JOptionPane.OK_OPTION == (GameMenu.this.gui.getScene().isFullscreen() ? JOptionPane.OK_OPTION : UIMessage.showConfirmDialog(GameMenu.this.gui.getScene(), "Do you wish to exit Java now ?", "exit Java ?", JOptionPane.OK_CANCEL_OPTION))) {
System.exit(0);
}
}
}, null);
GameMenuElement._addToMenu(gui, menu, "MENU_options", new Runnable() {
public void run() {
GameMenu.this.gui.getScene().setLoading(true);
GameMenu.this.gui.getGameInterface().options();
GameMenu.this.gui.getScene().setLoading(false);
}
}, null);
GameMenuElement._addToMenu(gui, menu, (GameMenu.this.gui.getLayout() & RenderingScene.options.MODE_EXT_FIXED.bitMask()) != 0 ? "-" : "MENU_fullscreen", new Runnable() {
public void run() {
GameMenu.this.gui.switchFullScreen();
}
}, null);
GameMenuElement._addToMenu(gui, menu, "MENU_play", new Runnable() {
public void run() {
GameMenu.this.gui.getMenu_handler().setCurrent(play_menu);
}
}, null);
GameMenuElement._addToMenu(gui, menu_play, "MENU_play_onePlr", new Runnable() {
public void run() {
GameMenu.this.gui.getGameInterface().playAgainstMachine();
}
}, null);
GameMenuElement._addToMenu(gui, menu_play, "MENU_play_twoPlr", new Runnable() {
public void run() {
GameMenu.this.gui.getGameInterface().playAgainstHuman();
}
}, null);
GameMenuElement._addToMenu(gui, menu_play, "MENU_play_twoNetHOST", new Runnable() {
public void run() {
GameMenu.this.gui.getGameInterface().runServerMode();
}
}, null);
GameMenuElement._addToMenu(gui, menu_play, "MENU_play_twoNetCLIENT", new Runnable() {
public void run() {
GameMenu.this.gui.getGameInterface().runClientMode();
}
}, null);
root_menu = new SelectionMenuComponent(gui, "Main Menu", menu);
play_menu = new SelectionMenuComponent(gui, "Play Menu", root_menu, menu_play);
}
private List<SelectionMenuCell> menu_play, menu;
protected SelectionMenuComponent root_menu, play_menu;
boolean showReadme = true;
@Override
protected void doLoad() {
super.doLoad();
if (showReadme) {
URL readme = getClass().getResource("/readme.txt");
if (readme == null) {
System.out.println("no readme file found in jar resources /readme.txt");
} else {
try {
BufferedReader readmeSTREAM = new BufferedReader(new InputStreamReader(readme.openStream()));
if (readmeSTREAM.ready()) {
gui.consoleHide();
gui.getScene().getGCO().clearContents();
gui.logLn("README FILE >>");
String line;
while ((line = readmeSTREAM.readLine()) != null) {
gui.logLn(line);
}
gui.logLn("<< README FILE");
gui.getScene().getGCO().scrollTop();
}
readmeSTREAM.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
gui.setBgSnd(gui._soundInterface.get("SFX_SNDTRK_menu"), true);
root_menu.reset();
play_menu.reset();
gui.getMenu_handler().setCurrent(root_menu);
}
@Override
protected void doUnload() {
super.doUnload();
gui.getBgSnd().stop();
}
@Override
protected void doLoadOnGL(RenderingScene context) {
super.doLoadOnGL(context);
final SpriteGLHandler spBg = RenderingScene._GLloadSprite((Sprite) gui.getCacheEntry("GFX_MENU_BACKGROUND"), context);
final SpriteGLHandler sp = RenderingScene._GLloadSprite((Sprite) gui.getCacheEntry("GFX_LOGO"), context);
context.doTaskOnGL(new Runnable() {
public void run() {
TextureTK._do.bindTex(spBg);
TextureTK._do.changeFiltering(spBg, GL11.GL_LINEAR);
TextureTK._do.unbindTex();
TextureTK._do.bindTex(sp);
TextureTK._do.changeFiltering(sp, GL11.GL_LINEAR);
TextureTK._do.unbindTex();
}
});
}
@Override
protected void renderToGL(RenderingScene context) {
super.renderToGL(context);
if (context.isLoading()) {
return;
} else if (showReadme) {
gui.consoleShow();
showReadme = false;
}
float z = gui.bgDepth;
Dimension dim = gui._rbGetDim("GFX_MENU_BACKGROUND").ROI.getSize();
dim = FieldGui._GLgetDimZRatio(context, z, FieldGui._fillDim(context.getSize(), dim, true, true));
Sprite._GLRenderSprite(context, Sprite._GLHandlers.getHandler(gui.getCacheHashEntry("GFX_MENU_BACKGROUND")), new Rectangle(context._getLogoPosition(context, TextLayout.POS.CENTER, TextLayout.POS.BOTTOM, dim), dim), z,
GLFX.gfx.FX_DOWNREFLEXION_EXT, new Point(0, context.getHeight()), null, 0, null, null, null);
context.getHud_user().pushContent("stage", getName(), TextLayout.POS.CENTER, TextLayout.POS.BOTTOM, true);
z = gui.menuDepth;
Dimension menuSize = new Dimension((int) ((float) context.getWidth() * .5f), (int) ((float) context.getHeight() * .8f));
Rectangle menuBounds = new Rectangle(
(int) Math.round((float) (context.getWidth() - menuSize.width) / 2f),
context.getHeight() - menuSize.height,
menuSize.width,
menuSize.height);
menuBounds.setSize(FieldGui._GLgetDimZRatio(context, z, menuSize));
gui.getMenu_handler().getCurrent().setBounds(menuBounds);
gui.getMenu_handler().getCurrent().GLpaintComponent(context, z, GLFX.gfx.FX_DOWNREFLEXION_EXT, new Point(0, context.getHeight()), GLGeom.getGlowingColor(Color.ORANGE, gui.glow.glow));
z++;
dim = FieldGui._fillDim(new Dimension((int) ((float) context.getWidth() / 4f), (int) ((float) context.getHeight() / 4f)), FieldGui._rbGetDim("GFX_LOGO").ROI.getSize(), true, false);
dim = gui._GLgetDimZRatio(context, z, dim);
SpriteGLHandler spLogo = Sprite._GLHandlers.getHandler(gui.getCacheHashEntry("GFX_LOGO"));
Sprite._GLRenderSprite(context, spLogo, new Rectangle(context._getLogoPosition(context, TextLayout.POS.CENTER, TextLayout.POS.TOP, dim), dim), z,
GLFX.gfx.FX_DOWNREFLEXION_EXT, new Point(0, context.getHeight()), GLGeom.getGlowingColor(Color.ORANGE, gui.glow.glow),
0, null, null, null);
}
}