Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.gui;
- import com.game.DrawUtils;
- import com.game.Game;
- import com.game.Leaderboards;
- import java.awt.Color;
- import java.awt.Font;
- import java.awt.Graphics2D;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.util.ArrayList;
- import java.util.Iterator;
- public class LeaderboardsPanel extends GuiPanel {
- private Leaderboards lBoard;
- private int buttonWidth = 100;
- private int backButtonWidth = 220;
- private int buttonSpacing = 20;
- private int buttonY = 120;
- private int buttonHeight = 50;
- private int leaderboardsX = 130;
- private int leaderboardsY;
- private String title;
- private Font titleFont;
- private Font scoreFont;
- private LeaderboardsPanel.State currentState;
- public LeaderboardsPanel() {
- this.leaderboardsY = this.buttonY + this.buttonHeight + 90;
- this.title = "Leaderboards";
- this.titleFont = Game.main.deriveFont(48.0F);
- this.scoreFont = Game.main.deriveFont(30.0F);
- this.currentState = LeaderboardsPanel.State.SCORE;
- this.lBoard = Leaderboards.getInstance();
- this.lBoard.loadScores();
- GuiButton tileButton = new GuiButton(Game.WIDTH / 2 - this.buttonWidth / 2, this.buttonY, this.buttonWidth, this.buttonHeight);
- tileButton.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- LeaderboardsPanel.this.currentState = LeaderboardsPanel.State.TILE;
- }
- });
- tileButton.setText("Tiles");
- this.add(tileButton);
- GuiButton scoreButton = new GuiButton(Game.WIDTH / 2 - this.buttonWidth / 2 - tileButton.getWidth() - this.buttonSpacing, this.buttonY, this.buttonWidth, this.buttonHeight);
- scoreButton.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- LeaderboardsPanel.this.currentState = LeaderboardsPanel.State.SCORE;
- }
- });
- scoreButton.setText("Scores");
- this.add(scoreButton);
- GuiButton timeButton = new GuiButton(Game.WIDTH / 2 + this.buttonWidth / 2 + this.buttonSpacing, this.buttonY, this.buttonWidth, this.buttonHeight);
- timeButton.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- LeaderboardsPanel.this.currentState = LeaderboardsPanel.State.TIME;
- }
- });
- timeButton.setText("Times");
- this.add(timeButton);
- GuiButton backButton = new GuiButton(Game.WIDTH / 2 - this.backButtonWidth / 2, 500, this.backButtonWidth, 60);
- backButton.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- GuiScreen.getInstance().setCurrentPanel("Menu");
- }
- });
- backButton.setText("Back");
- this.add(backButton);
- }
- private void drawLeaderboards(Graphics2D g) {
- ArrayList<String> strings = new ArrayList();
- if (this.currentState == LeaderboardsPanel.State.SCORE) {
- strings = this.convertToStrings(this.lBoard.getTopScores());
- } else if (this.currentState == LeaderboardsPanel.State.TILE) {
- strings = this.convertToStrings(this.lBoard.getTopTiles());
- }
- g.setColor(Color.black);
- g.setFont(this.scoreFont);
- for(int i = 0; i < strings.size(); ++i) {
- String s = i + 1 + ". " + (String)strings.get(i);
- g.drawString(s, this.leaderboardsX, this.leaderboardsY + i * 40);
- }
- }
- private ArrayList<String> convertToStrings(ArrayList<? extends Number> list) {
- ArrayList<String> ret = new ArrayList();
- Iterator var4 = list.iterator();
- while(var4.hasNext()) {
- Number n = (Number)var4.next();
- ret.add(n.toString());
- }
- return ret;
- }
- public void update() {
- }
- public void render(Graphics2D g) {
- super.render(g);
- g.setColor(Color.black);
- g.drawString(this.title, Game.WIDTH / 2 - DrawUtils.getMessageWidth(this.title, this.titleFont, g) / 2, DrawUtils.getMessageHeight(this.title, this.titleFont, g) + 40);
- this.drawLeaderboards(g);
- }
- private static enum State {
- SCORE,
- TILE,
- TIME;
- private State() {
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment