|
31 | 31 | import com.almasb.fxgl.scene.SubScene; |
32 | 32 | import com.almasb.fxgl.ui.FXGLScrollPane; |
33 | 33 | import com.almasb.fxgl.ui.FontType; |
| 34 | +import com.github.codestorm.bounceverse.systems.manager.metrics.LeaderboardManager; |
34 | 35 |
|
35 | 36 | import javafx.animation.FadeTransition; |
36 | 37 | import javafx.beans.binding.Bindings; |
37 | 38 | import javafx.beans.property.SimpleObjectProperty; |
38 | 39 | import javafx.collections.FXCollections; |
39 | 40 | import javafx.event.ActionEvent; |
40 | 41 | import javafx.event.EventHandler; |
41 | | -import javafx.geometry.*; |
| 42 | +import javafx.geometry.HPos; |
| 43 | +import javafx.geometry.Insets; |
| 44 | +import javafx.geometry.Point2D; |
| 45 | +import javafx.geometry.Pos; |
| 46 | +import javafx.geometry.VPos; |
42 | 47 | import javafx.scene.Node; |
43 | | -import javafx.scene.control.*; |
| 48 | +import javafx.scene.control.Button; |
| 49 | +import javafx.scene.control.CheckBox; |
| 50 | +import javafx.scene.control.ChoiceBox; |
| 51 | +import javafx.scene.control.ListCell; |
| 52 | +import javafx.scene.control.ListView; |
| 53 | +import javafx.scene.control.ScrollPane; |
| 54 | +import javafx.scene.control.Tooltip; |
44 | 55 | import javafx.scene.effect.BlendMode; |
45 | 56 | import javafx.scene.effect.GaussianBlur; |
46 | 57 | import javafx.scene.input.KeyEvent; |
47 | 58 | import javafx.scene.input.MouseEvent; |
48 | | -import javafx.scene.layout.*; |
| 59 | +import javafx.scene.layout.ColumnConstraints; |
| 60 | +import javafx.scene.layout.GridPane; |
| 61 | +import javafx.scene.layout.HBox; |
| 62 | +import javafx.scene.layout.Pane; |
| 63 | +import javafx.scene.layout.Priority; |
| 64 | +import javafx.scene.layout.RowConstraints; |
| 65 | +import javafx.scene.layout.StackPane; |
| 66 | +import javafx.scene.layout.VBox; |
49 | 67 | import javafx.scene.paint.Color; |
50 | 68 | import javafx.scene.paint.CycleMethod; |
51 | 69 | import javafx.scene.paint.LinearGradient; |
|
58 | 76 | import javafx.util.StringConverter; |
59 | 77 |
|
60 | 78 | import java.time.format.DateTimeFormatter; |
61 | | -import java.util.*; |
| 79 | +import java.util.ArrayList; |
| 80 | +import java.util.List; |
| 81 | +import java.util.Set; |
62 | 82 | import java.util.function.Supplier; |
63 | 83 |
|
64 | 84 | /** |
@@ -381,7 +401,12 @@ private MenuBox createExtraMenu() { |
381 | 401 | var itemCredits = new MenuButton("menu.credits"); |
382 | 402 | itemCredits.setMenuContent(this::createContentCredits); |
383 | 403 |
|
384 | | - return new MenuBox(itemAchievements, itemCredits); |
| 404 | + var itemLeaderboard = new MenuButton("temp.key"); |
| 405 | + itemLeaderboard.btn.textProperty().unbind(); |
| 406 | + itemLeaderboard.btn.setText("LEADERBOARD"); |
| 407 | + itemLeaderboard.setMenuContent(this::createContentLeaderboard); |
| 408 | + |
| 409 | + return new MenuBox(itemAchievements, itemCredits, itemLeaderboard); |
385 | 410 | } |
386 | 411 |
|
387 | 412 | private void switchMenuTo(Node menuNode) { |
@@ -704,6 +729,80 @@ protected MenuContent createContentAchievements() { |
704 | 729 | return content; |
705 | 730 | } |
706 | 731 |
|
| 732 | + protected MenuContent createContentLeaderboard() { |
| 733 | + log.debug("createContentLeaderboard()"); |
| 734 | + |
| 735 | + var leaderboardManager = LeaderboardManager.getInstance(); |
| 736 | + leaderboardManager.reload(); |
| 737 | + |
| 738 | + var blitzScores = leaderboardManager.getEndlessLeaderboard(); |
| 739 | + |
| 740 | + var contentBox = new VBox(20); |
| 741 | + contentBox.setAlignment(Pos.TOP_CENTER); |
| 742 | + |
| 743 | + var title = |
| 744 | + FXGL.getUIFactoryService() |
| 745 | + .newText("LEADERBOARD", Color.ORANGE, FontType.MONO, 27.0); |
| 746 | + |
| 747 | + var grid = new GridPane(); |
| 748 | + grid.setAlignment(Pos.CENTER); |
| 749 | + grid.setHgap(30); |
| 750 | + grid.setVgap(10); |
| 751 | + |
| 752 | + grid.getColumnConstraints() |
| 753 | + .add(new ColumnConstraints(60, 60, 60, Priority.ALWAYS, HPos.CENTER, true)); // Rank |
| 754 | + grid.getColumnConstraints() |
| 755 | + .add( |
| 756 | + new ColumnConstraints( |
| 757 | + 200, 200, 200, Priority.ALWAYS, HPos.LEFT, true)); // Name |
| 758 | + grid.getColumnConstraints() |
| 759 | + .add( |
| 760 | + new ColumnConstraints( |
| 761 | + 150, 150, 150, Priority.ALWAYS, HPos.RIGHT, true)); // Score |
| 762 | + |
| 763 | + grid.addRow( |
| 764 | + 0, |
| 765 | + FXGL.getUIFactoryService().newText("Rank", Color.NAVAJOWHITE, FontType.MONO, 21.0), |
| 766 | + FXGL.getUIFactoryService() |
| 767 | + .newText("Player", Color.NAVAJOWHITE, FontType.MONO, 21.0), |
| 768 | + FXGL.getUIFactoryService() |
| 769 | + .newText("Score", Color.NAVAJOWHITE, FontType.MONO, 21.0)); |
| 770 | + |
| 771 | + int rank = 1; |
| 772 | + if (blitzScores.isEmpty()) { |
| 773 | + var noDataText = |
| 774 | + FXGL.getUIFactoryService() |
| 775 | + .newText("No data available.", Color.GRAY, FontType.UI, 16.0); |
| 776 | + grid.add(noDataText, 0, 1); |
| 777 | + GridPane.setColumnSpan(noDataText, 3); |
| 778 | + } else { |
| 779 | + for (var score : blitzScores) { |
| 780 | + grid.addRow( |
| 781 | + rank, |
| 782 | + FXGL.getUIFactoryService() |
| 783 | + .newText("#" + rank, Color.YELLOW, FontType.MONO, 18.0), |
| 784 | + FXGL.getUIFactoryService() |
| 785 | + .newText(score.name(), Color.CYAN, FontType.MONO, 18.0), |
| 786 | + FXGL.getUIFactoryService() |
| 787 | + .newText( |
| 788 | + String.valueOf(score.score()), |
| 789 | + Color.LIGHTGREEN, |
| 790 | + FontType.MONO, |
| 791 | + 18.0)); |
| 792 | + rank++; |
| 793 | + } |
| 794 | + } |
| 795 | + |
| 796 | + var scrollPane = new FXGLScrollPane(grid); |
| 797 | + scrollPane.setPrefHeight(getAppHeight() / 2.0); |
| 798 | + scrollPane.setPrefWidth(500); |
| 799 | + scrollPane.setStyle("-fx-background: black;"); |
| 800 | + |
| 801 | + contentBox.getChildren().addAll(title, scrollPane); |
| 802 | + |
| 803 | + return new MenuContent(contentBox); |
| 804 | + } |
| 805 | + |
707 | 806 | private void showProfileDialog() { |
708 | 807 | ChoiceBox<String> profilesBox = |
709 | 808 | FXGL.getUIFactoryService().newChoiceBox(FXCollections.observableArrayList()); |
@@ -818,7 +917,9 @@ public MenuButton(String stringKey) { |
818 | 917 | btn.setAlignment(Pos.CENTER_LEFT); |
819 | 918 | btn.setStyle("-fx-background-color: transparent"); |
820 | 919 |
|
821 | | - final var p = new Polygon(0.0, 0.0, 220.0, 0.0, 250.0, 35.0, 0.0, 35.0); |
| 920 | + btn.setPrefWidth(280); |
| 921 | + |
| 922 | + final var p = new Polygon(0.0, 0.0, 270.0, 0.0, 300.0, 35.0, 0.0, 35.0); |
822 | 923 | p.setMouseTransparent(true); |
823 | 924 |
|
824 | 925 | var g = |
|
0 commit comments