implemented menu features while game is running, also added base functions to menu

This commit is contained in:
shebang
2015-01-13 14:49:32 +01:00
parent 7d9c236214
commit 216e88202b
4 changed files with 113 additions and 38 deletions
+10
View File
@@ -10,6 +10,7 @@ import de.heatup.timers.HardwareResetTimers;
import de.heatup.ui.actionPanel.ActionControl;
import de.heatup.ui.actionPanel.ActionWatcher;
import de.heatup.ui.actionPanel.HardewareManipulate;
import de.heatup.ui.menu.MenuPanel;
public class KeyBindings extends KeyAdapter {
final private static int progressBarTimer = 7;
@@ -44,8 +45,17 @@ public class KeyBindings extends KeyAdapter {
case KeyEvent.VK_ESCAPE:
if ( esc ) {
esc = false;
MenuPanel.setStartGameLabel("[ Spiel Starten ]");
MenuPanel.setShowCreditsLabel("[ Credits anzeigen ]");
MenuPanel.setShowTutorialLabel("[ Credits anzeigen ]");
MenuPanel.setShowHighscoreLabel("[ Highscore anzeigen ]");
} else {
esc = true;
MenuPanel.setStartGameLabel(" weiter mit >>ESC<< ");
MenuPanel.setShowCreditsLabel("");
MenuPanel.setShowTutorialLabel("");
MenuPanel.setShowHighscoreLabel("");
}
break;
case KeyEvent.VK_A:
+12 -4
View File
@@ -26,6 +26,7 @@ import de.heatup.objects.StaticObject;
import de.heatup.timers.HardwareResetTimers;
import de.heatup.ui.actionPanel.ActionControl;
import de.heatup.ui.actionPanel.ActionWatcher;
import de.heatup.ui.menu.CreditsPanel;
import de.heatup.ui.menu.MenuPanel;
@@ -51,6 +52,8 @@ public class Main extends JFrame implements Runnable {
private static JPanel leftPanel;
private static JPanel rightPanel;
private static JPanel actionPanel;
private static JPanel creditsPanel;
private static JPanel menuPanel;
@@ -101,11 +104,15 @@ public class Main extends JFrame implements Runnable {
MenuPanel.setMenuPanel();
menuPanel = MenuPanel.getMenuPanel();
CreditsPanel.setCreditsPanel();
creditsPanel = CreditsPanel.getCreditsPanel();
outerPanel.add(statusPanel,BorderLayout.NORTH);
outerPanel.add(leftPanel, BorderLayout.WEST);
outerPanel.add(rightPanel, BorderLayout.EAST);
outerPanel.add(gamePanel,BorderLayout.CENTER);
outerPanel.add(actionPanel,BorderLayout.SOUTH);
outerPanel.add(actionPanel,BorderLayout.SOUTH);
outerPanel.add(creditsPanel, BorderLayout.CENTER);
outerPanel.add(menuPanel, BorderLayout.CENTER);
add(outerPanel);
@@ -120,8 +127,7 @@ public class Main extends JFrame implements Runnable {
PanelBuilder.actionPanel.setBackground(Color.BLACK);
PanelBuilder.statusPanel.setBackground(Color.BLACK);
/*
* entfernen wenn getter verwendet wird.
*/
@@ -152,7 +158,9 @@ public class Main extends JFrame implements Runnable {
}
public static boolean getPause() {
return pause;
}
public static void main(String[] args) {
+31 -3
View File
@@ -1,13 +1,18 @@
package de.heatup.ui.menu;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import de.heatup.logging.Logger;
import de.heatup.ui.FontLoader;
import de.heatup.ui.PanelBuilder;
public class CreditsPanel {
@@ -19,11 +24,12 @@ public class CreditsPanel {
private static Font emulogic;
private static Font emulogicHeadline;
private static Font emulogicDivider;
private static Font emulogicSmall;
private static Font ttfbase;
// panels and labels
private static JPanel headline, divider, divider2, name1, name2, name3, name4, name5;
private static JLabel headlineLabel, dividerLabel, dividerLabel2, name1Label, name2Label, name3Label, name4Label, name5Label;
private static JPanel headline, divider, divider2, name1, name2, name3, name4, name5, exit;
private static JLabel headlineLabel, dividerLabel, dividerLabel2, name1Label, name2Label, name3Label, name4Label, name5Label, exitLabel;
public CreditsPanel() { }
@@ -36,6 +42,7 @@ public class CreditsPanel {
emulogicHeadline = ttfbase.deriveFont(Font.PLAIN, 28);
emulogic = ttfbase.deriveFont(Font.PLAIN, 12);
emulogicDivider = ttfbase.deriveFont(Font.PLAIN, 20);
emulogicSmall = ttfbase.deriveFont(Font.PLAIN, 10);
createCredits();
}
@@ -106,6 +113,26 @@ public class CreditsPanel {
name5Label.setFont(emulogic);
name5.add(name5Label);
exit = new JPanel();
exit.setBackground(Color.BLACK);
exitLabel = new JLabel("[ zurück zum Menü ]");
exitLabel.setForeground(Color.YELLOW);
exitLabel.setFont(emulogicSmall);
exitLabel.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
// @TODO: implement show credits
CreditsPanel.getCreditsPanel().setVisible(false);
PanelBuilder.getOuterPanel().add(MenuPanel.getMenuPanel(), BorderLayout.CENTER);
MenuPanel.getMenuPanel().setVisible(true);
Logger.write("back to menu");
}
});
exit.add(exitLabel);
credits.add(headline);
@@ -116,10 +143,11 @@ public class CreditsPanel {
credits.add(name4);
credits.add(name5);
credits.add(divider2);
credits.add(exit);
}
public static JPanel getCreditsPanel() {
credits.setVisible(false);
credits.setVisible(true);
return credits;
}
}
+60 -31
View File
@@ -7,8 +7,10 @@ import java.awt.event.MouseEvent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import sun.security.util.PendingException;
import de.heatup.logging.Logger;
import de.heatup.ui.FontLoader;
import de.heatup.ui.KeyBindings;
import de.heatup.ui.Main;
import de.heatup.ui.PanelBuilder;
import de.heatup.ui.StatusPanelAdder;
@@ -38,6 +40,26 @@ public class MenuPanel {
/** not in usage yet */
}
public static JLabel getStartGameLabel() {
return startGame;
}
public static void setStartGameLabel(String text) {
startGame.setText(text);
}
public static void setShowCreditsLabel(String text) {
showCredits.setText(text);
}
public static void setShowTutorialLabel(String text) {
showTutorial.setText(text);
}
public static void setShowHighscoreLabel(String text) {
showHighscore.setText(text);
}
public static void setMenuPanel() {
menuPanel.setPreferredSize(new Dimension(800,600));
@@ -71,41 +93,43 @@ public class MenuPanel {
start = new JPanel();
start.setBackground(Color.BLACK);
startGame = new JLabel("[ Spiel starten ]");
startGame = new JLabel();
startGame.setText("[ Spiel starten ]");
startGame.setForeground(Color.YELLOW);
startGame.setFont(emulogic);
startGame.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
// @TODO: implement start game
// just a trie
// StatusPanel bauen
StatusPanelAdder.setPanel(PanelBuilder.statusPanel);
StatusPanelAdder.createPanel();
if(gameExists == 1) {
// StatusPanel bauen
StatusPanelAdder.setPanel(PanelBuilder.statusPanel);
StatusPanelAdder.createPanel();
// ActionPanel bauen
ActionControl.setPanel(PanelBuilder.actionPanel);
PanelBuilder.createGame(1);
gameExists = 2;
menuPanel.setVisible(false);
PanelBuilder.getOuterPanel().add(PanelBuilder.getGamePanel(),BorderLayout.CENTER);
// PanelBuilder.getGamePanel().setSize(800, 600);
// PanelBuilder.getGamePanel().setVisible(true);
//** game, action, status panel redraw and check visibility */
Logger.write("Game Started via menu");
// ActionPanel bauen
ActionControl.setPanel(PanelBuilder.actionPanel);
PanelBuilder.createGame(1);
gameExists = 2;
menuPanel.setVisible(false);
PanelBuilder.getOuterPanel().add(PanelBuilder.getGamePanel(),BorderLayout.CENTER);
//** game, action, status panel redraw and check visibility */
Logger.write("Game Started via menu");
} else if (gameExists == 2) {
if(Main.getPause()) {
}
Logger.write("game already started");
}
}
});
start.add(startGame);
start.add(startGame);
}
/**
@@ -121,8 +145,7 @@ public class MenuPanel {
endGame.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
// @TODO: implement end game
Logger.write("game ended");
System.exit(0);
}
});
@@ -163,10 +186,16 @@ public class MenuPanel {
showCredits.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
// @TODO: implement show credits
menuPanel.setVisible(false);
Logger.write("show credits");
if(gameExists == 1) {
menuPanel.setVisible(false);
PanelBuilder.getOuterPanel().add(CreditsPanel.getCreditsPanel(), BorderLayout.CENTER);
Logger.write("show credits");
} else if(gameExists == 2) {
Logger.write("cant show credits while game is running");
}
}
});