import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileInputStream;
import javax.swing.JOptionPane;
import org.lwjgl.LWJGLException;
import org.lwjgl.Sys;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.newdawn.slick.AppGameContainer;
import org.newdawn.slick.Color;
import org.newdawn.slick.Font;
import org.newdawn.slick.Game;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.openal.Audio;
import org.newdawn.slick.openal.AudioLoader;
public class MeusDorfusIIv6 implements Game{
public static Font font = null;
public static GUI TheGUI;
// public static Audio TheAudio1;
public static GameContainer container;
public static MeusDorfus CURRENT;
// public static Audio TheAudio2;
public static GUI_DIALOG dialog1 = null;
public static DisplayMode fullscreen = null;
public static DisplayMode nonfullscreen = null;
public static boolean soundallowed = true;
public MeusDorfusIIv6() {
}
/**
* @param args
*/
public static void main(String[] args) {
/*String[] languages = {"English", "Deutsch"};
int result = JOptionPane.showOptionDialog(null, "Chose your language:", "Meus Dorfus II: Language...", 0, JOptionPane.QUESTION_MESSAGE, null, languages, languages[0]);
if(result == JOptionPane.CLOSED_OPTION){
JOptionPane.showMessageDialog(null, "The game is going to use English as the language.");
Language.CURRENTLANGUAGE = Language.LANGUAGE_ENGLISH;
}
else{
Language.CURRENTLANGUAGE = result;
}
*/
MeusDorfusIIv6 m = new MeusDorfusIIv6();
STARTUP.THIS = new STARTUP(m.new STARTUPOKActionListener());
STARTUP.THIS.setVisible(true);
}
public class STARTUPOKActionListener implements ActionListener{
@Override
public void actionPerformed(ActionEvent arg0) {
STARTUP.THIS.setVisible(false);
MeusDorfusIIv6.soundallowed = STARTUP.THIS.checkbox1.isSelected();
if(STARTUP.THIS.combobox1.getSelectedIndex() == 0){
Language.CURRENTLANGUAGE = Language.LANGUAGE_ENGLISH;
}
else if(STARTUP.THIS.combobox1.getSelectedIndex() == 1){
Language.CURRENTLANGUAGE = Language.LANGUAGE_GERMAN;
}
else{
Language.CURRENTLANGUAGE = Language.LANGUAGE_ENGLISH;
}
/*if(System.getProperty("os.name").contains("Mac")){
MeusDorfusIIv6.macosxtest();
return;
}*/
try{
AppGameContainer app = new AppGameContainer(new MeusDorfusIIv6(), 900, 500, false);
DisplayMode[] modes = null;
try {
modes = Display.getAvailableDisplayModes();
} catch (Exception e) {
e.printStackTrace();
modes =null;
}
if(modes != null){
MeusDorfusIIv6.nonfullscreen = modes[STARTUP.THIS.combobox2.getSelectedIndex()+1];
MeusDorfusIIv6.fullscreen = modes[STARTUP.THIS.combobox2.getSelectedIndex()+1];
app.setDisplayMode(modes[STARTUP.THIS.combobox2.getSelectedIndex()+1].getWidth(), modes[STARTUP.THIS.combobox2.getSelectedIndex()+1].getHeight(), STARTUP.THIS.checkbox2.isSelected());
app.start();
}
else{
MeusDorfusIIv6.fullscreen = null;
MeusDorfusIIv6.nonfullscreen = null;
try {
modes = Display.getAvailableDisplayModes();
int b = 0;
int c = 0;
int d = (int) (Toolkit.getDefaultToolkit().getScreenSize().getWidth()-50);
int e = (int) (Toolkit.getDefaultToolkit().getScreenSize().getHeight()-100);
for(int a = 0;a < modes.length;a++){
if(modes[a].getHeight() > c){
if(modes[a].getWidth() < d && modes[a].getHeight() < e){
c = modes[a].getHeight();
b = a;
}
}
}
app.setDisplayMode(modes[b].getWidth(), modes[b].getHeight(), STARTUP.THIS.checkbox2.isSelected());
} catch (LWJGLException e1) {
e1.printStackTrace();
}
}
}
catch(Exception e){
e.printStackTrace();
Sys.alert("", "ERROR: " + e.getLocalizedMessage());
}
}
}
@Override
public void init(GameContainer container) throws SlickException {
try{
container.setIcon(ImageLoader.icon);
// File f = new File("snd/P002_Menue.wav");
// MeusDorfusIIv6.TheAudio1 = AudioLoader.getAudio("WAV", new FileInputStream(f));
// MeusDorfusIIv6.TheAudio2 = AudioLoader.getAudio("WAV", new FileInputStream(new File("snd/S005_Extreme_Chilling_loopable.wav")));
MeusDorfusIIv6.initGUI(GUISplash.THIS);
container.setMusicOn(soundallowed);
container.setShowFPS(false);
}
catch(Exception e){
e.printStackTrace();
}
}
@Override
public void update(GameContainer container, int delta) throws SlickException {
MeusDorfusIIv6.container = container;
if(container.getInput().isKeyPressed(Input.KEY_F11)){
if(container.isFullscreen()){
if(MeusDorfusIIv6.nonfullscreen != null){
AppGameContainer app = (AppGameContainer) container;
app.setDisplayMode(MeusDorfusIIv6.nonfullscreen.getWidth(), MeusDorfusIIv6.nonfullscreen.getHeight(), false);
}
else{
AppGameContainer app = (AppGameContainer) container;
try {
DisplayMode[] modes = Display.getAvailableDisplayModes();
int b = 0;
int c = 0;
int d = (int) (Toolkit.getDefaultToolkit().getScreenSize().getWidth()-50);
int e = (int) (Toolkit.getDefaultToolkit().getScreenSize().getHeight()-100);
for(int a = 0;a < modes.length;a++){
if(modes[a].getHeight() > c){
if(modes[a].getWidth() < d && modes[a].getHeight() < e){
c = modes[a].getHeight();
b = a;
}
}
}
app.setDisplayMode(modes[b].getWidth(), modes[b].getHeight(), false);
} catch (LWJGLException e1) {
e1.printStackTrace();
}
}
}
else{
if(MeusDorfusIIv6.fullscreen != null){
AppGameContainer app = (AppGameContainer) container;
app.setDisplayMode(MeusDorfusIIv6.fullscreen.getWidth(), MeusDorfusIIv6.fullscreen.getHeight(), true);
}
else{
AppGameContainer app = (AppGameContainer) container;
try {
DisplayMode[] modes = Display.getAvailableDisplayModes();
int b = 0;
int c = 0;
int d = (int) (Toolkit.getDefaultToolkit().getScreenSize().getWidth()-50);
int e = (int) (Toolkit.getDefaultToolkit().getScreenSize().getHeight()-100);
for(int a = 0;a < modes.length;a++){
if(modes[a].getHeight() > c){
if(modes[a].getWidth() < d && modes[a].getHeight() < e){
c = modes[a].getHeight();
b = a;
}
}
}
app.setDisplayMode(modes[b].getWidth(), modes[b].getHeight(), true);
} catch (LWJGLException e1) {
e1.printStackTrace();
}
}
}
}
if(container.getInput().isKeyPressed(Input.KEY_F3)){
if(container.isShowingFPS()){
container.setShowFPS(false);
}
else{
container.setShowFPS(true);
}
}
if(MeusDorfusIIv6.TheGUI instanceof GUINormalHouseView || MeusDorfusIIv6.TheGUI instanceof GUIDorfuebersicht || MeusDorfusIIv6.TheGUI instanceof GUIOverview){
if(MeusDorfusIIv6.CURRENT != null){
MeusDorfusIIv6.CURRENT.update();
}
}
if(MeusDorfusIIv6.dialog1 != null){
MeusDorfusIIv6.dialog1.update(container, delta);
}
else{
MeusDorfusIIv6.TheGUI.update(container, delta);
}
}
@Override
public void render(GameContainer container, Graphics g)
throws SlickException {
MeusDorfusIIv6.font = g.getFont();
g.setColor(Color.black);
if(MeusDorfusIIv6.dialog1 != null){
MeusDorfusIIv6.dialog1.render(container, g);
}
else{
try{
MeusDorfusIIv6.TheGUI.render(container, g);
}
catch(Exception e){
e.printStackTrace();
}
}
}
@Override
public boolean closeRequested() {
GUIDialog.THIS.realInit(Language.getString(Language.CloseRequestText), Language.getString(Language.CloseRequestTitle), new closeRequestDialogAnswer(), MeusDorfusIIv6.TheGUI, GUIDialog.OPTION_YES_NO);
MeusDorfusIIv6.dialog1 = GUIDialog.THIS;
return false;
}
public class closeRequestDialogAnswer implements DialogAnswer{
@Override
public void answer(int answer) {
if(answer == GUIDialog.OPTION_YES){
System.exit(0);
}
}
}
@Override
public String getTitle() {
return "Meus Dorfus II";
}
public static void cannotInit(){
Sys.alert("", Language.getString(Language.CanntoInit));
}
public static void drawStackedBG1(GameContainer container, Graphics g){
int widthOfBG = ImageLoader.getImage(ImageLoader.bg1).getWidth();
int heightOfBG = ImageLoader.getImage(ImageLoader.bg1).getHeight();
int tileWidth = 100;
int tileHeight = 100;
for(int a = 0;a < ((container.getWidth()/tileWidth)+1);a++){
for(int b = 0;b < ((container.getHeight()/tileHeight)+1);b++){
g.drawImage(ImageLoader.getImage(ImageLoader.bg1),
tileWidth*a, tileHeight*b,
(tileWidth*a)+tileWidth, (tileHeight*b)+tileHeight,
0,
0,
widthOfBG,
heightOfBG
);
}
}
}
public static void initGUI(GUI tHIS){
MeusDorfusIIv6.TheGUI = tHIS;
if(MeusDorfusIIv6.TheGUI.inited == false){
try {
MeusDorfusIIv6.TheGUI.init(MeusDorfusIIv6.container);
MeusDorfusIIv6.TheGUI.inited = true;
} catch (SlickException e) {
e.printStackTrace();
MeusDorfusIIv6.cannotInit();
}
}
}
public static void macosxtest(){
try {
AppGameContainer app = new AppGameContainer(new MeusDorfusIIv6(), 900, 500, false);
try {
DisplayMode[] modes = Display.getAvailableDisplayModes();
double width = (double)Toolkit.getDefaultToolkit().getScreenSize().getWidth();
double height = (double)Toolkit.getDefaultToolkit().getScreenSize().getHeight();
double width_height = width/height;
for(int a = 0;a < modes.length;a++){
try{
double modes_a_width_height = (double)modes[a].getWidth()/(double)modes[a].getHeight();
if(/*width_height == modes_a_width_height && */(Toolkit.getDefaultToolkit().getScreenSize().getWidth()-50)>modes[a].getWidth() && (Toolkit.getDefaultToolkit().getScreenSize().getHeight()-50)>modes[a].getHeight()){
app.setDisplayMode(modes[a].getWidth(), modes[a].getHeight(), false);
System.out.println("Das Programm bevorzugt den " + (a+1) + ". Modus, denn dort betr‰gt die Weite " + modes[a].getWidth() + " und die Hˆhe " + modes[a].getHeight());
break;
}
if((a+1) == modes.length){
System.out.println("Das Programm mag keinen der Modi...");
}
}
catch(Exception e2){
}
}
} catch (LWJGLException e1) {
e1.printStackTrace();
}
app.start();
}
catch (Exception e) {
e.printStackTrace();
Sys.alert("ERROR:", e.getMessage());
System.exit(-1);
}
}
/**
* Gibt den x-Wert wieder, den man braucht um zum Beispiel den ScheiflButton in die Mitte zu bekommen.
* M¸sste auch mit y-Wert und Hˆhe funken ^^
* @param bigwidth Z.B. container.getWidth()
* @param smallwidth z.B. button.getWidth()
* @return z.B. x vom Button, damit er in der mitte ist
*/
public static double getMiddel(float bigwidth, float smallwidth) {
return (((double)bigwidth/(double)2)-((double)smallwidth/(double)2));
}
}