extends highscoregui with filter, refactor some stuff
This commit is contained in:
parent
f78dc29751
commit
2a20d1b43a
@ -37,7 +37,7 @@ import tonegod.gui.core.Screen;
|
|||||||
*
|
*
|
||||||
* @author Darth Affe
|
* @author Darth Affe
|
||||||
*/
|
*/
|
||||||
public class GameGUI extends Panel {
|
public class GameGUI extends Panel implements Gui{
|
||||||
|
|
||||||
private GameListener listener;
|
private GameListener listener;
|
||||||
private Button btnStart;
|
private Button btnStart;
|
||||||
@ -185,4 +185,7 @@ public class GameGUI extends Panel {
|
|||||||
this.player = player;
|
this.player = player;
|
||||||
this.addControl(new GuiPlayerPointsControl(player, this));
|
this.addControl(new GuiPlayerPointsControl(player, this));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void refresh() {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -26,6 +26,7 @@ import org.wyrez.shootingstars.gui.model.Score;
|
|||||||
import org.wyrez.shootingstars.helper.ScreenHelper;
|
import org.wyrez.shootingstars.helper.ScreenHelper;
|
||||||
import tonegod.gui.controls.buttons.Button;
|
import tonegod.gui.controls.buttons.Button;
|
||||||
import tonegod.gui.controls.text.Label;
|
import tonegod.gui.controls.text.Label;
|
||||||
|
import tonegod.gui.controls.text.TextField;
|
||||||
import tonegod.gui.controls.windows.Panel;
|
import tonegod.gui.controls.windows.Panel;
|
||||||
import tonegod.gui.core.Screen;
|
import tonegod.gui.core.Screen;
|
||||||
|
|
||||||
@ -38,6 +39,8 @@ public class HighscoreGUI extends Panel implements Gui {
|
|||||||
private HighscoreListener listener;
|
private HighscoreListener listener;
|
||||||
private HighscoreManager highscoreManager;
|
private HighscoreManager highscoreManager;
|
||||||
private ScreenHelper screenHelper;
|
private ScreenHelper screenHelper;
|
||||||
|
private Panel plnScores;
|
||||||
|
private TextField txtFilter;
|
||||||
|
|
||||||
public HighscoreGUI(Screen screen, HighscoreListener listener, HighscoreManager highscoreManager, ScreenHelper screenHelper) {
|
public HighscoreGUI(Screen screen, HighscoreListener listener, HighscoreManager highscoreManager, ScreenHelper screenHelper) {
|
||||||
super(screen, new Vector2f(0f, 0f), new Vector2f(1280f, 720f));
|
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.highscoreManager = highscoreManager;
|
||||||
this.screenHelper = screenHelper;
|
this.screenHelper = screenHelper;
|
||||||
this.setIgnoreMouse(true);
|
this.setIgnoreMouse(true);
|
||||||
this.setIsVisible(false);
|
this.setIsVisible(false);
|
||||||
|
plnScores = new Panel(screen, new Vector2f(0f, 0f),new Vector2f(0f, 0f));
|
||||||
create();
|
create();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,10 +68,12 @@ public class HighscoreGUI extends Panel implements Gui {
|
|||||||
float marginScoreNameLeft = screenHelper.calcX(14f);
|
float marginScoreNameLeft = screenHelper.calcX(14f);
|
||||||
float marginScorePointsLeft = screenHelper.calcX(300f);
|
float marginScorePointsLeft = screenHelper.calcX(300f);
|
||||||
float marginScoreSongNameLeft = screenHelper.calcX(600f);
|
float marginScoreSongNameLeft = screenHelper.calcX(600f);
|
||||||
|
|
||||||
float marginScoreTop = screenHelper.calcY(50f);
|
|
||||||
|
|
||||||
float labelFontSize = screenHelper.calcX(20f);
|
float labelFontSize = screenHelper.calcX(20f);
|
||||||
|
|
||||||
|
float buttonHeight = screenHelper.calcY(40f);
|
||||||
|
float buttonWidth = screenHelper.calcX(153f);
|
||||||
|
float buttonFontSize = screenHelper.calcX(20f);
|
||||||
|
|
||||||
List<Score> highscores = highscoreManager.getScores();
|
List<Score> highscores = highscoreManager.getScores();
|
||||||
|
|
||||||
@ -83,15 +89,66 @@ public class HighscoreGUI extends Panel implements Gui {
|
|||||||
lblScoreSongNameHead.setText("Song Name");
|
lblScoreSongNameHead.setText("Song Name");
|
||||||
lblScoreSongNameHead.setFontSize(labelFontSize);
|
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<Score> 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<Score> highscores = highscoreManager.getScores();
|
||||||
|
drawHighscores(highscores);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void drawHighscores(List<Score> 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;
|
int maxScores = 0;
|
||||||
if (highscores.size() > 10) {
|
if (scores.size() > 10) {
|
||||||
maxScores = 10;
|
maxScores = 10;
|
||||||
} else {
|
} else {
|
||||||
maxScores = highscores.size();
|
maxScores = scores.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < maxScores; i++) {
|
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)));
|
Label lblScoreName = new Label(screen, new Vector2f(startPointx + marginScoreNameLeft, startPointy + marginScoreTop), new Vector2f(screenHelper.calcX(250f), screenHelper.calcY(40f)));
|
||||||
lblScoreName.setText(score.getPlayerName());
|
lblScoreName.setText(score.getPlayerName());
|
||||||
lblScoreName.setFontSize(labelFontSize);
|
lblScoreName.setFontSize(labelFontSize);
|
||||||
@ -101,30 +158,13 @@ public class HighscoreGUI extends Panel implements Gui {
|
|||||||
lblScorePoints.setFontSize(labelFontSize);
|
lblScorePoints.setFontSize(labelFontSize);
|
||||||
|
|
||||||
Label lblScoreSongName = new Label(screen, new Vector2f(startPointx + marginScoreSongNameLeft, startPointy + marginScoreTop), new Vector2f(screenHelper.calcX(600f), screenHelper.calcY(40f)));
|
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);
|
lblScoreSongName.setFontSize(labelFontSize);
|
||||||
|
|
||||||
this.addChild(lblScoreName);
|
plnScores.addChild(lblScoreName);
|
||||||
this.addChild(lblScorePoints);
|
plnScores.addChild(lblScorePoints);
|
||||||
this.addChild(lblScoreSongName);
|
plnScores.addChild(lblScoreSongName);
|
||||||
marginScoreTop += screenHelper.calcY(50f);
|
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() {
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -31,7 +31,7 @@ import tonegod.gui.core.Screen;
|
|||||||
*
|
*
|
||||||
* @author Darth Affe
|
* @author Darth Affe
|
||||||
*/
|
*/
|
||||||
public class LoadingGui extends Panel {
|
public class LoadingGui extends Panel implements Gui{
|
||||||
|
|
||||||
private Label lblStatus;
|
private Label lblStatus;
|
||||||
private Indicator indProgress;
|
private Indicator indProgress;
|
||||||
@ -78,4 +78,7 @@ public class LoadingGui extends Panel {
|
|||||||
lblStatus.setText(progress.getText());
|
lblStatus.setText(progress.getText());
|
||||||
indProgress.setCurrentValue(progress.getValue());
|
indProgress.setCurrentValue(progress.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void refresh() {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -30,7 +30,6 @@ import tonegod.gui.controls.lists.Slider;
|
|||||||
import tonegod.gui.controls.text.Label;
|
import tonegod.gui.controls.text.Label;
|
||||||
import tonegod.gui.controls.text.TextField;
|
import tonegod.gui.controls.text.TextField;
|
||||||
import tonegod.gui.controls.windows.Panel;
|
import tonegod.gui.controls.windows.Panel;
|
||||||
import tonegod.gui.controls.windows.TabControl;
|
|
||||||
import tonegod.gui.core.Screen;
|
import tonegod.gui.core.Screen;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -44,11 +44,11 @@ public class HighscoreManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public List<Score> getScores() {
|
public List<Score> getScores() {
|
||||||
sort();
|
sort(scores);
|
||||||
return scores;
|
return scores;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sort() {
|
private void sort(List<Score> scores) {
|
||||||
Collections.sort(scores, scoreComparator);
|
Collections.sort(scores, scoreComparator);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,6 +57,22 @@ public class HighscoreManager {
|
|||||||
scores.add(new Score(songName, optionSettings.getUsername(), score));
|
scores.add(new Score(songName, optionSettings.getUsername(), score));
|
||||||
updateScoreFile(optionSettings.getUsername(), score, songName);
|
updateScoreFile(optionSettings.getUsername(), score, songName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Score> getScoresWithSongName(String songName) {
|
||||||
|
List<Score> tempScores = new ArrayList<Score>();
|
||||||
|
|
||||||
|
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() {
|
private void loadScoreFile() {
|
||||||
try {
|
try {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user