From 2a20d1b43a46a3bf11396d5de334beb413a1885c Mon Sep 17 00:00:00 2001 From: TheCodeBoat Date: Fri, 28 Jun 2013 09:43:30 +0200 Subject: [PATCH] extends highscoregui with filter, refactor some stuff --- .../org/wyrez/shootingstars/gui/GameGUI.java | 5 +- .../wyrez/shootingstars/gui/HighscoreGUI.java | 96 +++++++++++++------ .../wyrez/shootingstars/gui/LoadingGui.java | 5 +- .../wyrez/shootingstars/gui/OptionsGUI.java | 1 - .../gui/manager/HighscoreManager.java | 20 +++- 5 files changed, 94 insertions(+), 33 deletions(-) diff --git a/ShootingStars/src/org/wyrez/shootingstars/gui/GameGUI.java b/ShootingStars/src/org/wyrez/shootingstars/gui/GameGUI.java index 14669b4..2359b62 100644 --- a/ShootingStars/src/org/wyrez/shootingstars/gui/GameGUI.java +++ b/ShootingStars/src/org/wyrez/shootingstars/gui/GameGUI.java @@ -37,7 +37,7 @@ import tonegod.gui.core.Screen; * * @author Darth Affe */ -public class GameGUI extends Panel { +public class GameGUI extends Panel implements Gui{ private GameListener listener; private Button btnStart; @@ -185,4 +185,7 @@ public class GameGUI extends Panel { this.player = player; this.addControl(new GuiPlayerPointsControl(player, this)); } + + public void refresh() { + } } diff --git a/ShootingStars/src/org/wyrez/shootingstars/gui/HighscoreGUI.java b/ShootingStars/src/org/wyrez/shootingstars/gui/HighscoreGUI.java index c1f76ad..44fc0f5 100644 --- a/ShootingStars/src/org/wyrez/shootingstars/gui/HighscoreGUI.java +++ b/ShootingStars/src/org/wyrez/shootingstars/gui/HighscoreGUI.java @@ -26,6 +26,7 @@ import org.wyrez.shootingstars.gui.model.Score; import org.wyrez.shootingstars.helper.ScreenHelper; import tonegod.gui.controls.buttons.Button; import tonegod.gui.controls.text.Label; +import tonegod.gui.controls.text.TextField; import tonegod.gui.controls.windows.Panel; import tonegod.gui.core.Screen; @@ -38,6 +39,8 @@ public class HighscoreGUI extends Panel implements Gui { private HighscoreListener listener; private HighscoreManager highscoreManager; private ScreenHelper screenHelper; + private Panel plnScores; + private TextField txtFilter; public HighscoreGUI(Screen screen, HighscoreListener listener, HighscoreManager highscoreManager, ScreenHelper screenHelper) { super(screen, new Vector2f(0f, 0f), new Vector2f(1280f, 720f)); @@ -45,7 +48,8 @@ public class HighscoreGUI extends Panel implements Gui { this.highscoreManager = highscoreManager; this.screenHelper = screenHelper; this.setIgnoreMouse(true); - this.setIsVisible(false); + this.setIsVisible(false); + plnScores = new Panel(screen, new Vector2f(0f, 0f),new Vector2f(0f, 0f)); create(); } @@ -64,10 +68,12 @@ public class HighscoreGUI extends Panel implements Gui { float marginScoreNameLeft = screenHelper.calcX(14f); float marginScorePointsLeft = screenHelper.calcX(300f); float marginScoreSongNameLeft = screenHelper.calcX(600f); - - float marginScoreTop = screenHelper.calcY(50f); - + float labelFontSize = screenHelper.calcX(20f); + + float buttonHeight = screenHelper.calcY(40f); + float buttonWidth = screenHelper.calcX(153f); + float buttonFontSize = screenHelper.calcX(20f); List highscores = highscoreManager.getScores(); @@ -83,15 +89,66 @@ public class HighscoreGUI extends Panel implements Gui { lblScoreSongNameHead.setText("Song Name"); lblScoreSongNameHead.setFontSize(labelFontSize); + drawHighscores(highscores); + + Button btnBack = new ButtonBase(screen, new Vector2f(startPointx + screenHelper.calcX(1060f), startPointy + screenHelper.calcY(622.8f)), new Vector2f(buttonWidth, buttonHeight)) { + @Override + public void onButtonMouseLeftUp(MouseButtonEvent evt, boolean toggled) { + listener.back(); + } + }; + btnBack.setText("Back"); + btnBack.setFontSize(buttonFontSize); + + txtFilter = new TextField(screen, new Vector2f(screenHelper.calcX(800f), screenHelper.calcY(15f)), new Vector2f(screenHelper.calcX(280f), screenHelper.calcY(40f))); + + Button btnFilter = new ButtonBase(screen, new Vector2f(screenHelper.calcX(1092f), screenHelper.calcY(15f)), new Vector2f(buttonWidth, buttonHeight)) { + @Override + public void onButtonMouseLeftUp(MouseButtonEvent evt, boolean toggled) { + List scores = highscoreManager.getScoresWithSongName(txtFilter.getText()); + drawHighscores(scores); + } + }; + btnFilter.setText("Filter Song Name"); + btnFilter.setFontSize(buttonFontSize); + + this.addChild(lblScoreNameHead); + this.addChild(lblScorePointsHead); + this.addChild(lblScoreSongNameHead); + this.addChild(plnScores); + this.addChild(txtFilter); + this.addChild(btnFilter); + this.addChild(btnBack); + } + + public void refresh() { + List highscores = highscoreManager.getScores(); + drawHighscores(highscores); + } + + private void drawHighscores(List scores) { + plnScores.detachAllChildren(); + + float startPointx = screenHelper.calcX(32f); + float startPointy = screenHelper.calcY(18f); + + float marginScoreNameLeft = screenHelper.calcX(14f); + float marginScorePointsLeft = screenHelper.calcX(300f); + float marginScoreSongNameLeft = screenHelper.calcX(600f); + + float marginScoreTop = screenHelper.calcY(50f); + + float labelFontSize = screenHelper.calcX(20f); + int maxScores = 0; - if (highscores.size() > 10) { + if (scores.size() > 10) { maxScores = 10; } else { - maxScores = highscores.size(); + maxScores = scores.size(); } for (int i = 0; i < maxScores; i++) { - Score score = highscores.get(i); + Score score = scores.get(i); Label lblScoreName = new Label(screen, new Vector2f(startPointx + marginScoreNameLeft, startPointy + marginScoreTop), new Vector2f(screenHelper.calcX(250f), screenHelper.calcY(40f))); lblScoreName.setText(score.getPlayerName()); lblScoreName.setFontSize(labelFontSize); @@ -101,30 +158,13 @@ public class HighscoreGUI extends Panel implements Gui { lblScorePoints.setFontSize(labelFontSize); Label lblScoreSongName = new Label(screen, new Vector2f(startPointx + marginScoreSongNameLeft, startPointy + marginScoreTop), new Vector2f(screenHelper.calcX(600f), screenHelper.calcY(40f))); - + lblScoreSongName.setText(score.getSongName()); lblScoreSongName.setFontSize(labelFontSize); - this.addChild(lblScoreName); - this.addChild(lblScorePoints); - this.addChild(lblScoreSongName); + plnScores.addChild(lblScoreName); + plnScores.addChild(lblScorePoints); + plnScores.addChild(lblScoreSongName); marginScoreTop += screenHelper.calcY(50f); } - - Button btnBack = new ButtonBase(screen, new Vector2f(startPointx + screenHelper.calcX(1060f), startPointy + screenHelper.calcY(622.8f)), new Vector2f(screenHelper.calcX(153f), screenHelper.calcY(40f))) { - @Override - public void onButtonMouseLeftUp(MouseButtonEvent evt, boolean toggled) { - listener.back(); - } - }; - btnBack.setText("Back"); - btnBack.setFontSize(labelFontSize); - - this.addChild(lblScoreNameHead); - this.addChild(lblScorePointsHead); - this.addChild(lblScoreSongNameHead); - this.addChild(btnBack); - } - - public void refresh() { } } diff --git a/ShootingStars/src/org/wyrez/shootingstars/gui/LoadingGui.java b/ShootingStars/src/org/wyrez/shootingstars/gui/LoadingGui.java index 4d9cc8f..fb0649e 100644 --- a/ShootingStars/src/org/wyrez/shootingstars/gui/LoadingGui.java +++ b/ShootingStars/src/org/wyrez/shootingstars/gui/LoadingGui.java @@ -31,7 +31,7 @@ import tonegod.gui.core.Screen; * * @author Darth Affe */ -public class LoadingGui extends Panel { +public class LoadingGui extends Panel implements Gui{ private Label lblStatus; private Indicator indProgress; @@ -78,4 +78,7 @@ public class LoadingGui extends Panel { lblStatus.setText(progress.getText()); indProgress.setCurrentValue(progress.getValue()); } + + public void refresh() { + } } diff --git a/ShootingStars/src/org/wyrez/shootingstars/gui/OptionsGUI.java b/ShootingStars/src/org/wyrez/shootingstars/gui/OptionsGUI.java index 686a0d6..cea9104 100644 --- a/ShootingStars/src/org/wyrez/shootingstars/gui/OptionsGUI.java +++ b/ShootingStars/src/org/wyrez/shootingstars/gui/OptionsGUI.java @@ -30,7 +30,6 @@ import tonegod.gui.controls.lists.Slider; import tonegod.gui.controls.text.Label; import tonegod.gui.controls.text.TextField; import tonegod.gui.controls.windows.Panel; -import tonegod.gui.controls.windows.TabControl; import tonegod.gui.core.Screen; /** diff --git a/ShootingStars/src/org/wyrez/shootingstars/gui/manager/HighscoreManager.java b/ShootingStars/src/org/wyrez/shootingstars/gui/manager/HighscoreManager.java index f5a4b9e..e93201f 100644 --- a/ShootingStars/src/org/wyrez/shootingstars/gui/manager/HighscoreManager.java +++ b/ShootingStars/src/org/wyrez/shootingstars/gui/manager/HighscoreManager.java @@ -44,11 +44,11 @@ public class HighscoreManager { } public List getScores() { - sort(); + sort(scores); return scores; } - private void sort() { + private void sort(List scores) { Collections.sort(scores, scoreComparator); } @@ -57,6 +57,22 @@ public class HighscoreManager { scores.add(new Score(songName, optionSettings.getUsername(), score)); updateScoreFile(optionSettings.getUsername(), score, songName); } + + public List getScoresWithSongName(String songName) { + List tempScores = new ArrayList(); + + try { + ResultSet rs = connector.excecuteQuery(connection, "SELECT * FROM Scores WHERE LOWER(SongName) LIKE LOWER('%" + songName + "%');"); + while (rs.next()) { + tempScores.add(new Score(rs.getString("SongName"), rs.getString("Name"), rs.getInt("Points"))); + } + rs.close(); + } catch (Exception ex) { + ex.printStackTrace(); + } + sort(tempScores); + return tempScores; + } private void loadScoreFile() { try {