added map choose menu for displaying the highscores

This commit is contained in:
shebang
2015-01-29 12:19:56 +01:00
parent 88113e16cf
commit 8a49c29d46
4 changed files with 458 additions and 87 deletions
@@ -0,0 +1,143 @@
package de.heatup.testing;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridLayout;
import javax.swing.JLabel;
import javax.swing.JPanel;
import de.heatup.highscore.ScoreEntry;
import de.heatup.logging.Logger;
import de.heatup.mapengine.MapEngine;
import de.heatup.ui.FontLoader;
public class HighscorePanel {
private static JPanel highscorePanel = new JPanel();
// panels and labels
private static JPanel headingPanel, dividerPanel;
private static JLabel headingLabel, dividerLabel;
private static JPanel scores;
// Font Loader and font Settings
private static FontLoader fl = new FontLoader();
private static Font ttfbase, emulogicHeading, emulogicDivider, emulogicSmall;
private static int mapID;
private static MapEngine me;
private static int scoreEntries;
public HighscorePanel(int mapID) {
HighscorePanel.mapID = mapID;
getHighscores();
// initialize fonts
ttfbase = FontLoader.getFont();
emulogicHeading = ttfbase.deriveFont(Font.PLAIN, 20);
emulogicDivider = ttfbase.deriveFont(Font.PLAIN, 10);
emulogicSmall = ttfbase.deriveFont(Font.PLAIN, 12);
// build panel
highscorePanel.setLayout(new GridLayout(3, 1));
highscorePanel.setSize(new Dimension(800, 600));
highscorePanel.setBackground(Color.BLACK);
highscorePanel.setFocusable(false);
highscorePanel.setVisible(true);
initHighscorePanelHeading();
highscorePanel.add(headingPanel);
highscorePanel.add(dividerPanel);
initHighscorePanelContent();
highscorePanel.add(scores, BorderLayout.CENTER);
}
private static void initHighscorePanelHeading() {
headingPanel = new JPanel();
headingPanel.setSize(new Dimension(800, 50));
headingPanel.setBackground(Color.BLACK);
headingPanel.setFocusable(false);
headingPanel.setVisible(true);
headingLabel = new JLabel();
headingLabel.setForeground(Color.YELLOW);
headingLabel.setBackground(Color.BLACK);
headingLabel.setFocusable(false);
headingLabel.setVisible(true);
headingLabel.setFont(emulogicHeading);
headingLabel.setText("HeatUP - Highscores");
headingPanel.add(headingLabel);
dividerPanel = new JPanel();
dividerPanel.setSize(new Dimension(800, 50));
dividerPanel.setBackground(Color.BLACK);
dividerPanel.setFocusable(false);
dividerPanel.setVisible(true);
dividerLabel = new JLabel();
dividerLabel.setForeground(Color.YELLOW);
dividerLabel.setBackground(Color.BLACK);
dividerLabel.setFocusable(false);
dividerLabel.setVisible(true);
dividerLabel.setFont(emulogicDivider);
dividerLabel.setText("------------------------------");
dividerPanel.add(dividerLabel);
}
private static void initHighscorePanelContent() {
scores = new JPanel();
scores.setSize(new Dimension(800, 500));
scores.setLayout(new GridLayout(scoreEntries, 1));
scores.setBackground(Color.BLACK);
scores.setFocusable(false);
scores.setVisible(true);
for(ScoreEntry score : me.getHighscoreHandler().getHighscores(me.getMapHash())) {
JLabel l = new JLabel();
l.setBackground(Color.BLACK);
l.setForeground(Color.YELLOW);
l.setFont(emulogicSmall);
l.setVisible(true);
l.setText(score.getName() + " ---> " + score.getScore());
scores.add(l);
}
}
private static void getHighscores() {
if(mapID != 0) {
me = new MapEngine(mapID);
} else if (mapID == 0){
me = new MapEngine();
}
// count Score entries for building the GridLayout
for(ScoreEntry score : me.getHighscoreHandler().getHighscores(me.getMapHash())) {
scoreEntries++;
Logger.write(score.getName() + " " + score.getScore());
}
}
private static JPanel getHighscorePanel() {
return highscorePanel;
}
private static int getMapID() {
return mapID;
}
private static void setMapID(int mapID) {
HighscorePanel.mapID = mapID;
}
}
@@ -1,5 +1,6 @@
package de.heatup.ui.menu;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
@@ -12,110 +13,95 @@ import de.heatup.highscore.ScoreEntry;
import de.heatup.logging.Logger;
import de.heatup.mapengine.MapEngine;
import de.heatup.ui.FontLoader;
import de.heatup.ui.PanelBuilder;
public class HighscorePanel {
// dynamic panels
private static JPanel highscorePanel = new JPanel();
private static JPanel headingPanel;
private static JPanel contentPanel;
// default text panels and labels
// panels and labels
private static JPanel headingPanel, dividerPanel;
private static JLabel headingLabel, dividerLabel;
private static GridLayout grid = new GridLayout(2, 1);
private static JPanel scores;
// Font Loader and font Settings
private static FontLoader fl = new FontLoader();
private static Font ttfbase, emulogicHeading, emulogicDivider, emulogicSmall;
// MapEngine used to get and set the Highscore
private static int mapID;
private static MapEngine me;
private static int scoreEntries = 0;
private static int scoreEntries;
public HighscorePanel() {
public HighscorePanel(int mapID) {
initHighscorePanel();
HighscorePanel.mapID = mapID;
getHighscores();
}
private static void getHighscores() {
// TODO : Init the MapEngine before a new game is started for getting highscores
me = PanelBuilder.getMapEngine();
// only for testing purposes
// me.getHighscoreHandler().setHighscore(me.getMapHash(), "Daniel", 3134);
// me.getHighscoreHandler().setHighscore(me.getMapHash(), "Tim", 2010);
// me.getHighscoreHandler().saveHighscores();
// count Score entries for building the GridLayout
for(ScoreEntry score : me.getHighscoreHandler().getHighscores(me.getMapHash())) {
scoreEntries++;
Logger.write(score.getName()+" "+score.getScore());
}
}
private static void initHighscorePanel() {
highscorePanel.setSize(new Dimension(800, 600));
highscorePanel.setBackground(Color.BLACK);
highscorePanel.setFocusable(false);
// build full highscorePanel
initHeadingPanel();
initContentPanel();
highscorePanel.add(headingPanel);
highscorePanel.add(contentPanel);
highscorePanel.setVisible(true);
}
private static void initHeadingPanel() {
headingPanel = new JPanel();
headingPanel.setSize(new Dimension(800, 50));
headingPanel.setBackground(Color.BLACK);
headingPanel.setFocusable(false);
headingPanel.setLayout(grid);
headingPanel.setVisible(true);
// initialize fonts
ttfbase = FontLoader.getFont();
emulogicHeading = ttfbase.deriveFont(Font.PLAIN, 20);
emulogicDivider = ttfbase.deriveFont(Font.PLAIN, 10);
emulogicSmall = ttfbase.deriveFont(Font.PLAIN, 12);
headingLabel = new JLabel();
headingLabel.setText("HeatUP! - Highscores");
headingLabel.setForeground(Color.YELLOW);
headingLabel.setFont(emulogicHeading);
// build panel
highscorePanel.setLayout(new GridLayout(3, 1));
highscorePanel.setSize(new Dimension(800, 600));
highscorePanel.setBackground(Color.BLACK);
highscorePanel.setFocusable(false);
highscorePanel.setVisible(true);
dividerLabel = new JLabel();
dividerLabel.setText("----------------------------------------");
dividerLabel.setForeground(Color.YELLOW);
dividerLabel.setFont(emulogicDivider);
initHighscorePanelHeading();
highscorePanel.add(headingPanel);
highscorePanel.add(dividerPanel);
initHighscorePanelContent();
highscorePanel.add(scores, BorderLayout.CENTER);
headingPanel.add(headingLabel);
headingPanel.add(dividerLabel);
}
private static void initContentPanel() {
contentPanel = new JPanel();
private static void initHighscorePanelHeading() {
headingPanel = new JPanel();
headingPanel.setSize(new Dimension(800, 50));
headingPanel.setBackground(Color.BLACK);
headingPanel.setFocusable(false);
headingPanel.setVisible(true);
contentPanel.setSize(new Dimension(800, 550));
contentPanel.setBackground(Color.BLACK);
contentPanel.setFocusable(false);
headingLabel = new JLabel();
headingLabel.setForeground(Color.YELLOW);
headingLabel.setBackground(Color.BLACK);
headingLabel.setFocusable(false);
headingLabel.setVisible(true);
headingLabel.setFont(emulogicHeading);
headingLabel.setText("HeatUP - Highscores");
contentPanel.setVisible(true);
headingPanel.add(headingLabel);
// GridLayout for Scores
JPanel scores = new JPanel();
dividerPanel = new JPanel();
dividerPanel.setSize(new Dimension(800, 50));
dividerPanel.setBackground(Color.BLACK);
dividerPanel.setFocusable(false);
dividerPanel.setVisible(true);
dividerLabel = new JLabel();
dividerLabel.setForeground(Color.YELLOW);
dividerLabel.setBackground(Color.BLACK);
dividerLabel.setFocusable(false);
dividerLabel.setVisible(true);
dividerLabel.setFont(emulogicDivider);
dividerLabel.setText("------------------------------");
dividerPanel.add(dividerLabel);
}
private static void initHighscorePanelContent() {
scores = new JPanel();
scores.setSize(new Dimension(800, 500));
scores.setLayout(new GridLayout(scoreEntries, 1));
scores.setBackground(Color.BLACK);
scores.setFocusable(false);
scores.setVisible(true);
getHighscores();
scores.setLayout(new GridLayout(0, scoreEntries));
for(ScoreEntry score : me.getHighscoreHandler().getHighscores(me.getMapHash())) {
JLabel l = new JLabel();
l.setBackground(Color.BLACK);
@@ -126,27 +112,32 @@ public class HighscorePanel {
l.setText(score.getName() + " ---> " + score.getScore());
scores.add(l);
}
contentPanel.add(scores);
}
private static void getHighscores() {
if(mapID != 0) {
me = new MapEngine(mapID);
} else if (mapID == 0){
me = new MapEngine();
}
// count Score entries for building the GridLayout
for(ScoreEntry score : me.getHighscoreHandler().getHighscores(me.getMapHash())) {
scoreEntries++;
Logger.write(score.getName() + " " + score.getScore());
}
}
public static JPanel getHighscorePanel() {
return highscorePanel;
}
public static void setHighscorePanel(JPanel highscorePanel) {
HighscorePanel.highscorePanel = highscorePanel;
public static int getMapID() {
return mapID;
}
public static JPanel getContentPanel() {
return contentPanel;
}
public static void setContentPanel(JPanel contentPanel) {
HighscorePanel.contentPanel = contentPanel;
public static void setMapID(int mapID) {
HighscorePanel.mapID = mapID;
}
}
@@ -0,0 +1,234 @@
package de.heatup.ui.menu;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
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.Main;
import de.heatup.ui.PanelBuilder;
public class MapChooseHighschorePanel {
private static JPanel mapChooseHighscorePanel = new JPanel();
// Panels and Labels for mapChooseHighschorePanek
private static JPanel headingPanel, dividerPanel, map1Panel, map2Panel, map3Panel, map4Panel;
private static JLabel headingLabel, dividerLabel, map1Label, map2Label, map3Label, map4Label;
// Font loader and font Settings
private static FontLoader fl = new FontLoader();
private static Font ttfbase, emulogicHeading, emulogicDivider, emulogicSmall;
// PanelGrid
private static GridLayout grid = new GridLayout(6, 1);
public MapChooseHighschorePanel() {
mapChooseHighscorePanel.setSize(new Dimension(800, 600));
mapChooseHighscorePanel.setBackground(Color.BLACK);
mapChooseHighscorePanel.setFocusable(false);
mapChooseHighscorePanel.setVisible(true);
mapChooseHighscorePanel.setLayout(grid);
// build related fonts
ttfbase = FontLoader.getFont();
emulogicHeading = ttfbase.deriveFont(Font.PLAIN, 30);
emulogicDivider = ttfbase.deriveFont(Font.PLAIN, 20);
emulogicSmall = ttfbase.deriveFont(Font.PLAIN, 18);
initMapChooseHeading();
mapChooseHighscorePanel.add(headingPanel);
mapChooseHighscorePanel.add(dividerPanel);
initMapChooseHighscorePanel();
mapChooseHighscorePanel.add(map1Panel);
mapChooseHighscorePanel.add(map2Panel);
mapChooseHighscorePanel.add(map3Panel);
mapChooseHighscorePanel.add(map4Panel);
}
private static void initMapChooseHeading() {
headingPanel = new JPanel();
headingPanel.setSize(new Dimension(800, 50));
headingPanel.setBackground(Color.BLACK);
headingPanel.setFocusable(false);
headingPanel.setVisible(true);
headingLabel = new JLabel();
headingLabel.setForeground(Color.YELLOW);
headingLabel.setBackground(Color.BLACK);
headingLabel.setVisible(true);
headingLabel.setFont(emulogicHeading);
headingLabel.setText("HeatUp - Highscores");
headingPanel.add(headingLabel);
dividerPanel = new JPanel();
dividerPanel.setSize(new Dimension(800, 50));
dividerPanel.setBackground(Color.BLACK);
dividerPanel.setFocusable(false);
dividerPanel.setVisible(true);
dividerLabel = new JLabel();
dividerLabel.setForeground(Color.YELLOW);
dividerLabel.setBackground(Color.BLACK);
dividerLabel.setVisible(true);
dividerLabel.setFont(emulogicDivider);
dividerLabel.setText("-------------------------------");
dividerPanel.add(dividerLabel);
}
private static void initMapChooseHighscorePanel() {
map1Panel = new JPanel();
map1Panel.setSize(new Dimension(800, 20));
map1Panel.setVisible(true);
map1Panel.setBackground(Color.BLACK);
map1Label = new JLabel();
map1Label.setBackground(Color.BLACK);
map1Label.setForeground(Color.YELLOW);
map1Label.setFont(emulogicSmall);
map1Label.setText("Map -1-");
map1Label.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
MapChooseHighschorePanel.getMapChooseHighscorePanel().setVisible(false);
HighscorePanel p = new HighscorePanel(1);
//HighscorePanel.setMapID(1);
PanelBuilder.getOuterPanel().add(HighscorePanel.getHighscorePanel(), BorderLayout.CENTER);
/**
if(MenuPanel.gameExists == 1) {
} else if(MenuPanel.gameExists == 2) {
if(Main.getPause()) {
}
}
*/
Logger.write("Show Highscore for : " + map1Label.getText());
}
});
map1Panel.add(map1Label);
//
map2Panel = new JPanel();
map2Panel.setSize(new Dimension(800, 20));
map2Panel.setVisible(true);
map2Panel.setBackground(Color.BLACK);
map2Label = new JLabel();
map2Label.setBackground(Color.BLACK);
map2Label.setForeground(Color.YELLOW);
map2Label.setFont(emulogicSmall);
map2Label.setText("Map -2-");
map2Label.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
MapChooseHighschorePanel.getMapChooseHighscorePanel().setVisible(false);
HighscorePanel p = new HighscorePanel(2);
//HighscorePanel.setMapID(2);
PanelBuilder.getOuterPanel().add(HighscorePanel.getHighscorePanel(), BorderLayout.CENTER);
/**
if(MenuPanel.gameExists == 1) {
} else if(MenuPanel.gameExists == 2) {
if(Main.getPause()) {
}
}
*/
Logger.write("Show Highscore for : " + map2Label.getText());
}
});
map2Panel.add(map2Label);
//
map3Panel = new JPanel();
map3Panel.setSize(new Dimension(800, 20));
map3Panel.setVisible(true);
map3Panel.setBackground(Color.BLACK);
map3Label = new JLabel();
map3Label.setBackground(Color.BLACK);
map3Label.setForeground(Color.YELLOW);
map3Label.setFont(emulogicSmall);
map3Label.setText("Map -3-");
map3Label.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
MapChooseHighschorePanel.getMapChooseHighscorePanel().setVisible(false);
HighscorePanel p = new HighscorePanel(3);
//HighscorePanel.setMapID(3);
PanelBuilder.getOuterPanel().add(HighscorePanel.getHighscorePanel(), BorderLayout.CENTER);
/**
if(MenuPanel.gameExists == 1) {
} else if(MenuPanel.gameExists == 2) {
if(Main.getPause()) {
}
}
*/
Logger.write("Show Highscore for : " + map3Label.getText());
}
});
map3Panel.add(map3Label);
//
map4Panel = new JPanel();
map4Panel.setSize(new Dimension(800, 20));
map4Panel.setVisible(true);
map4Panel.setBackground(Color.BLACK);
map4Label = new JLabel();
map4Label.setBackground(Color.BLACK);
map4Label.setForeground(Color.YELLOW);
map4Label.setFont(emulogicSmall);
map4Label.setText("Map -Custom-");
map4Label.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
MapChooseHighschorePanel.getMapChooseHighscorePanel().setVisible(false);
HighscorePanel p = new HighscorePanel(0);
//HighscorePanel.setMapID(0);
PanelBuilder.getOuterPanel().add(HighscorePanel.getHighscorePanel(), BorderLayout.CENTER);
/**
if(MenuPanel.gameExists == 1) {
} else if(MenuPanel.gameExists == 2) {
if(Main.getPause()) {
}
}
*/
Logger.write("Show Highscore for : " + map4Label.getText());
}
});
map4Panel.add(map4Label);
}
public static JPanel getMapChooseHighscorePanel() {
return mapChooseHighscorePanel;
}
}
+5 -2
View File
@@ -172,8 +172,11 @@ public class MenuPanel {
menuPanel.setVisible(false);
HighscorePanel p = new HighscorePanel();
PanelBuilder.getOuterPanel().add(HighscorePanel.getHighscorePanel(), BorderLayout.CENTER);
//HighscorePanel p = new HighscorePanel();
//PanelBuilder.getOuterPanel().add(HighscorePanel.getHighscorePanel(), BorderLayout.CENTER);
MapChooseHighschorePanel p = new MapChooseHighschorePanel();
PanelBuilder.getOuterPanel().add(MapChooseHighschorePanel.getMapChooseHighscorePanel(), BorderLayout.CENTER);
Logger.write("show highscore");
} else if (gameExists == 2) {
Logger.write("cant show scores while game is running");