Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,29 @@

public abstract class Achievement {

protected final String nameKey;
protected final String descriptionKey;
protected final int rewardCoins;
protected boolean completed = false;

public Achievement(String nameKey, String descriptionKey, int rewardCoins) {
this.nameKey = nameKey;
this.descriptionKey = descriptionKey;
this.rewardCoins = rewardCoins;
}

public String getNameKey() {
return nameKey;
}

public String getDescriptionKey() {
return descriptionKey;
}

public int getRewardCoins() {
return rewardCoins;
}

public boolean isCompleted() {
return completed;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,14 @@ public class AchievementManager {
private final List<Achievement> activeAchievements = new ArrayList<>();

public AchievementManager() {
// Register all available achievements here
allAchievements.add(new KillCountAchievement(10, 50));
allAchievements.add(new KillCountAchievement(20, 100));
registerAchievements();
}

private void registerAchievements() {
allAchievements.add(new KillCountAchievement("ach_kill_10_name", "ach_kill_10_desc", 10, 50));
allAchievements.add(new KillCountAchievement("ach_kill_20_name", "ach_kill_20_desc", 20, 100));
allAchievements.add(new KillCountAchievement("ach_kill_50_name", "ach_kill_50_desc", 50, 250));
allAchievements.add(new KillCountAchievement("ach_kill_100_name", "ach_kill_100_desc", 100, 500));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[💄Spotless - Format] reported by reviewdog 🐶

Suggested change
allAchievements.add(new KillCountAchievement("ach_kill_100_name", "ach_kill_100_desc", 100, 500));
allAchievements.add(
new KillCountAchievement("ach_kill_100_name", "ach_kill_100_desc", 100, 500));

}

// Called once when the game starts
Expand Down Expand Up @@ -43,6 +48,10 @@ public List<Achievement> getActiveAchievements() {
return activeAchievements;
}

public List<Achievement> getAllAchievements() {
return allAchievements;
}

public Achievement getActiveAchievement() {
if (activeAchievements.isEmpty()) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,16 @@
public class KillCountAchievement extends Achievement {

private final int targetKills;
private final int rewardCoins;

private int currentKills = 0;
private boolean completed = false;

public KillCountAchievement(int targetKills, int rewardCoins) {
public KillCountAchievement(String nameKey, String descriptionKey, int targetKills, int rewardCoins) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[💄Spotless - Format] reported by reviewdog 🐶

Suggested change
public KillCountAchievement(String nameKey, String descriptionKey, int targetKills, int rewardCoins) {
public KillCountAchievement(
String nameKey, String descriptionKey, int targetKills, int rewardCoins) {

super(nameKey, descriptionKey, rewardCoins);
this.targetKills = targetKills;
this.rewardCoins = rewardCoins;
}

public String getDescription() {
return "Kill " + targetKills + " dinosaurs";
}

public boolean isCompleted() {
return completed;
return com.dinosaur.dinosaurexploder.utils.LanguageManager.getInstance().getTranslation(descriptionKey)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[💄Spotless - Format] reported by reviewdog 🐶

Suggested change
return com.dinosaur.dinosaurexploder.utils.LanguageManager.getInstance().getTranslation(descriptionKey)
return com.dinosaur.dinosaurexploder.utils.LanguageManager.getInstance()
.getTranslation(descriptionKey)

.replace("##", String.valueOf(targetKills));
}

public void onDinosaurKilled() {
Expand All @@ -40,10 +34,15 @@ public void update(double tpf) {
}

public void onComplete() {
FXGL.getNotificationService().pushNotification("Achievement unlocked: " + getDescription());
String achievementName = com.dinosaur.dinosaurexploder.utils.LanguageManager.getInstance().getTranslation(nameKey);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[💄Spotless - Format] reported by reviewdog 🐶

Suggested change
String achievementName = com.dinosaur.dinosaurexploder.utils.LanguageManager.getInstance().getTranslation(nameKey);
String achievementName =
com.dinosaur.dinosaurexploder.utils.LanguageManager.getInstance().getTranslation(nameKey);

FXGL.getNotificationService().pushNotification("Achievement unlocked: " + achievementName);
}

public int getTargetKills() {
return targetKills;
}

public int getRewardCoins() {
return rewardCoins;
public int getCurrentKills() {
return currentKills;
}
}
144 changes: 144 additions & 0 deletions src/main/java/com/dinosaur/dinosaurexploder/view/AchievementsMenu.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
package com.dinosaur.dinosaurexploder.view;

import static com.almasb.fxgl.dsl.FXGLForKtKt.getUIFactoryService;

import com.almasb.fxgl.app.scene.FXGLMenu;
import com.almasb.fxgl.app.scene.MenuType;
import com.almasb.fxgl.dsl.FXGL;
import com.dinosaur.dinosaurexploder.achievements.Achievement;
import com.dinosaur.dinosaurexploder.achievements.AchievementManager;
import com.dinosaur.dinosaurexploder.achievements.KillCountAchievement;
import com.dinosaur.dinosaurexploder.constants.GameConstants;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[💄Spotless - Format] reported by reviewdog 🐶

Suggested change
import com.dinosaur.dinosaurexploder.constants.GameConstants;

import com.dinosaur.dinosaurexploder.utils.LanguageManager;
import com.dinosaur.dinosaurexploder.utils.MenuHelper;
import java.io.FileNotFoundException;
import java.util.List;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.ScrollPane;
import javafx.scene.effect.DropShadow;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[💄Spotless - Format] reported by reviewdog 🐶

Suggested change
import javafx.scene.effect.DropShadow;

import javafx.scene.image.ImageView;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[💄Spotless - Format] reported by reviewdog 🐶

Suggested change
import javafx.scene.layout.Priority;

import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.text.Text;
import javafx.scene.text.TextAlignment;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[💄Spotless - Format] reported by reviewdog 🐶

Suggested change
import javafx.scene.text.TextAlignment;

import javafx.scene.text.TextFlow;

public class AchievementsMenu extends FXGLMenu {

private final LanguageManager languageManager;
private final AchievementManager achievementManager;

public AchievementsMenu() {
super(MenuType.MAIN_MENU);
this.languageManager = LanguageManager.getInstance();

// Try to get AchievementManager from world properties, otherwise create a temporary one
AchievementManager am = FXGL.getWorldProperties().getOptional("achievementManager").map(o -> (AchievementManager)o).orElse(null);
if (am == null) {
am = new AchievementManager();
}
this.achievementManager = am;

try {
buildMenu();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
Comment on lines +33 to +51
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[💄Spotless - Format] reported by reviewdog 🐶

Suggested change
private final LanguageManager languageManager;
private final AchievementManager achievementManager;
public AchievementsMenu() {
super(MenuType.MAIN_MENU);
this.languageManager = LanguageManager.getInstance();
// Try to get AchievementManager from world properties, otherwise create a temporary one
AchievementManager am = FXGL.getWorldProperties().getOptional("achievementManager").map(o -> (AchievementManager)o).orElse(null);
if (am == null) {
am = new AchievementManager();
}
this.achievementManager = am;
try {
buildMenu();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
private final LanguageManager languageManager;
private final AchievementManager achievementManager;
public AchievementsMenu() {
super(MenuType.MAIN_MENU);
this.languageManager = LanguageManager.getInstance();
// Try to get AchievementManager from world properties, otherwise create a temporary one
AchievementManager am =
FXGL.getWorldProperties()
.getOptional("achievementManager")
.map(o -> (AchievementManager) o)
.orElse(null);
if (am == null) {
am = new AchievementManager();

}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[💄Spotless - Format] reported by reviewdog 🐶

Suggested change
this.achievementManager = am;

private void buildMenu() throws FileNotFoundException {
ImageView background = MenuHelper.createAnimatedBackground(getAppWidth(), getAppHeight());
TextFlow title = MenuHelper.createTitleFlow(languageManager.getTranslation("achievements"), getAppWidth());

VBox contentBox = createAchievementsList();
ScrollPane scrollPane = createScrollPane(contentBox);

Button backButton = MenuHelper.createStyledButton(languageManager.getTranslation("back"));
backButton.setOnAction(event -> fireResume());

VBox mainLayout = new VBox(20, title, scrollPane, backButton);
mainLayout.setAlignment(Pos.CENTER);
mainLayout.setPadding(new Insets(30, 40, 30, 40));
mainLayout.setPrefWidth(getAppWidth());
mainLayout.setPrefHeight(getAppHeight());

getContentRoot().getChildren().addAll(background, mainLayout);
Comment on lines +54 to +70
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[💄Spotless - Format] reported by reviewdog 🐶

Suggested change
private void buildMenu() throws FileNotFoundException {
ImageView background = MenuHelper.createAnimatedBackground(getAppWidth(), getAppHeight());
TextFlow title = MenuHelper.createTitleFlow(languageManager.getTranslation("achievements"), getAppWidth());
VBox contentBox = createAchievementsList();
ScrollPane scrollPane = createScrollPane(contentBox);
Button backButton = MenuHelper.createStyledButton(languageManager.getTranslation("back"));
backButton.setOnAction(event -> fireResume());
VBox mainLayout = new VBox(20, title, scrollPane, backButton);
mainLayout.setAlignment(Pos.CENTER);
mainLayout.setPadding(new Insets(30, 40, 30, 40));
mainLayout.setPrefWidth(getAppWidth());
mainLayout.setPrefHeight(getAppHeight());
getContentRoot().getChildren().addAll(background, mainLayout);
try {
buildMenu();
} catch (FileNotFoundException e) {
e.printStackTrace();

}

private ScrollPane createScrollPane(VBox content) {
ScrollPane pane = new ScrollPane(content);
pane.setFitToWidth(true);
pane.setPrefWidth(480);
pane.setMaxWidth(480);
pane.setPrefViewportHeight(450);

pane.setStyle(
"-fx-background: rgba(0, 0, 0, 0.8);"
+ "-fx-background-color: rgba(0, 0, 0, 0.8);"
+ "-fx-border-color: rgba(0, 220, 0, 0.7);"
+ "-fx-border-width: 2;"
+ "-fx-border-radius: 10;"
+ "-fx-background-radius: 10;");

pane.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
pane.setVbarPolicy(ScrollPane.ScrollBarPolicy.AS_NEEDED);

return pane;
Comment on lines +72 to +91
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[💄Spotless - Format] reported by reviewdog 🐶

Suggested change
private ScrollPane createScrollPane(VBox content) {
ScrollPane pane = new ScrollPane(content);
pane.setFitToWidth(true);
pane.setPrefWidth(480);
pane.setMaxWidth(480);
pane.setPrefViewportHeight(450);
pane.setStyle(
"-fx-background: rgba(0, 0, 0, 0.8);"
+ "-fx-background-color: rgba(0, 0, 0, 0.8);"
+ "-fx-border-color: rgba(0, 220, 0, 0.7);"
+ "-fx-border-width: 2;"
+ "-fx-border-radius: 10;"
+ "-fx-background-radius: 10;");
pane.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
pane.setVbarPolicy(ScrollPane.ScrollBarPolicy.AS_NEEDED);
return pane;
}
private void buildMenu() throws FileNotFoundException {
ImageView background = MenuHelper.createAnimatedBackground(getAppWidth(), getAppHeight());
TextFlow title =
MenuHelper.createTitleFlow(languageManager.getTranslation("achievements"), getAppWidth());
VBox contentBox = createAchievementsList();
ScrollPane scrollPane = createScrollPane(contentBox);
Button backButton = MenuHelper.createStyledButton(languageManager.getTranslation("back"));
backButton.setOnAction(event -> fireResume());
VBox mainLayout = new VBox(20, title, scrollPane, backButton);
mainLayout.setAlignment(Pos.CENTER);
mainLayout.setPadding(new Insets(30, 40, 30, 40));
mainLayout.setPrefWidth(getAppWidth());
mainLayout.setPrefHeight(getAppHeight());
getContentRoot().getChildren().addAll(background, mainLayout);
}
private ScrollPane createScrollPane(VBox content) {
ScrollPane pane = new ScrollPane(content);
pane.setFitToWidth(true);
pane.setPrefWidth(480);
pane.setMaxWidth(480);
pane.setPrefViewportHeight(450);
pane.setStyle(
"-fx-background: rgba(0, 0, 0, 0.8);"
+ "-fx-background-color: rgba(0, 0, 0, 0.8);"
+ "-fx-border-color: rgba(0, 220, 0, 0.7);"
+ "-fx-border-width: 2;"
+ "-fx-border-radius: 10;"
+ "-fx-background-radius: 10;");
pane.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
pane.setVbarPolicy(ScrollPane.ScrollBarPolicy.AS_NEEDED);
return pane;
}
private VBox createAchievementsList() {
VBox list = new VBox(15);
list.setPadding(new Insets(10));
list.setAlignment(Pos.TOP_CENTER);
list.setStyle("-fx-background-color: transparent;");
List<Achievement> achievements = achievementManager.getAllAchievements();
for (Achievement achievement : achievements) {
list.getChildren().add(createAchievementBox(achievement));

}

private VBox createAchievementsList() {
VBox list = new VBox(15);
list.setPadding(new Insets(10));
list.setAlignment(Pos.TOP_CENTER);
list.setStyle("-fx-background-color: transparent;");

List<Achievement> achievements = achievementManager.getAllAchievements();
for (Achievement achievement : achievements) {
list.getChildren().add(createAchievementBox(achievement));
}
Comment on lines +94 to +103
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[💄Spotless - Format] reported by reviewdog 🐶

Suggested change
private VBox createAchievementsList() {
VBox list = new VBox(15);
list.setPadding(new Insets(10));
list.setAlignment(Pos.TOP_CENTER);
list.setStyle("-fx-background-color: transparent;");
List<Achievement> achievements = achievementManager.getAllAchievements();
for (Achievement achievement : achievements) {
list.getChildren().add(createAchievementBox(achievement));
}
return list;
}


return list;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[💄Spotless - Format] reported by reviewdog 🐶

Suggested change
return list;
private VBox createAchievementBox(Achievement achievement) {
String name = languageManager.getTranslation(achievement.getNameKey());
String description = "";
if (achievement instanceof KillCountAchievement) {
description = ((KillCountAchievement) achievement).getDescription();
} else {
description = languageManager.getTranslation(achievement.getDescriptionKey());

}

private VBox createAchievementBox(Achievement achievement) {
String name = languageManager.getTranslation(achievement.getNameKey());
String description = "";
if (achievement instanceof KillCountAchievement) {
description = ((KillCountAchievement) achievement).getDescription();
} else {
description = languageManager.getTranslation(achievement.getDescriptionKey());
}

Label nameLabel = new Label(name);
nameLabel.setStyle("-fx-font-family: 'Public Pixel'; -fx-font-size: 14px; -fx-text-fill: #00FF00; -fx-font-weight: bold;");

Text descText = getUIFactoryService().newText(description, Color.WHITE, 12);
descText.setWrappingWidth(400);

HBox statusBox = new HBox(10);
statusBox.setAlignment(Pos.CENTER_LEFT);

boolean isCompleted = achievement.isCompleted();
Label statusLabel = new Label(isCompleted ? languageManager.getTranslation("unlocked").toUpperCase() : languageManager.getTranslation("locked").toUpperCase());
statusLabel.setStyle("-fx-font-family: 'Public Pixel'; -fx-font-size: 10px; -fx-text-fill: " + (isCompleted ? "#00FF00" : "#FF6666") + ";");

Label rewardLabel = new Label(languageManager.getTranslation("reward") + ": " + achievement.getRewardCoins() + " " + languageManager.getTranslation("coin"));
rewardLabel.setStyle("-fx-font-family: 'Public Pixel'; -fx-font-size: 10px; -fx-text-fill: #FFFF00;");

VBox box = new VBox(8, nameLabel, descText, new HBox(20, statusLabel, rewardLabel));
box.setPadding(new Insets(15));
box.setStyle(
"-fx-background-color: rgba(0, 0, 0, 0.6);"
+ "-fx-background-radius: 8;"
+ "-fx-border-color: " + (isCompleted ? "rgba(0, 255, 0, 0.5)" : "rgba(255, 255, 255, 0.2)") + ";"
+ "-fx-border-width: 1;"
+ "-fx-border-radius: 8;");

return box;
}
Comment on lines +108 to +143
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[💄Spotless - Format] reported by reviewdog 🐶

Suggested change
private VBox createAchievementBox(Achievement achievement) {
String name = languageManager.getTranslation(achievement.getNameKey());
String description = "";
if (achievement instanceof KillCountAchievement) {
description = ((KillCountAchievement) achievement).getDescription();
} else {
description = languageManager.getTranslation(achievement.getDescriptionKey());
}
Label nameLabel = new Label(name);
nameLabel.setStyle("-fx-font-family: 'Public Pixel'; -fx-font-size: 14px; -fx-text-fill: #00FF00; -fx-font-weight: bold;");
Text descText = getUIFactoryService().newText(description, Color.WHITE, 12);
descText.setWrappingWidth(400);
HBox statusBox = new HBox(10);
statusBox.setAlignment(Pos.CENTER_LEFT);
boolean isCompleted = achievement.isCompleted();
Label statusLabel = new Label(isCompleted ? languageManager.getTranslation("unlocked").toUpperCase() : languageManager.getTranslation("locked").toUpperCase());
statusLabel.setStyle("-fx-font-family: 'Public Pixel'; -fx-font-size: 10px; -fx-text-fill: " + (isCompleted ? "#00FF00" : "#FF6666") + ";");
Label rewardLabel = new Label(languageManager.getTranslation("reward") + ": " + achievement.getRewardCoins() + " " + languageManager.getTranslation("coin"));
rewardLabel.setStyle("-fx-font-family: 'Public Pixel'; -fx-font-size: 10px; -fx-text-fill: #FFFF00;");
VBox box = new VBox(8, nameLabel, descText, new HBox(20, statusLabel, rewardLabel));
box.setPadding(new Insets(15));
box.setStyle(
"-fx-background-color: rgba(0, 0, 0, 0.6);"
+ "-fx-background-radius: 8;"
+ "-fx-border-color: " + (isCompleted ? "rgba(0, 255, 0, 0.5)" : "rgba(255, 255, 255, 0.2)") + ";"
+ "-fx-border-width: 1;"
+ "-fx-border-radius: 8;");
return box;
}
Label nameLabel = new Label(name);
nameLabel.setStyle(
"-fx-font-family: 'Public Pixel'; -fx-font-size: 14px; -fx-text-fill: #00FF00; -fx-font-weight: bold;");
Text descText = getUIFactoryService().newText(description, Color.WHITE, 12);
descText.setWrappingWidth(400);
HBox statusBox = new HBox(10);
statusBox.setAlignment(Pos.CENTER_LEFT);
boolean isCompleted = achievement.isCompleted();
Label statusLabel =
new Label(
isCompleted
? languageManager.getTranslation("unlocked").toUpperCase()
: languageManager.getTranslation("locked").toUpperCase());
statusLabel.setStyle(
"-fx-font-family: 'Public Pixel'; -fx-font-size: 10px; -fx-text-fill: "
+ (isCompleted ? "#00FF00" : "#FF6666")
+ ";");
Label rewardLabel =
new Label(
languageManager.getTranslation("reward")
+ ": "
+ achievement.getRewardCoins()
+ " "
+ languageManager.getTranslation("coin"));
rewardLabel.setStyle(
"-fx-font-family: 'Public Pixel'; -fx-font-size: 10px; -fx-text-fill: #FFFF00;");
VBox box = new VBox(8, nameLabel, descText, new HBox(20, statusLabel, rewardLabel));
box.setPadding(new Insets(15));
box.setStyle(
"-fx-background-color: rgba(0, 0, 0, 0.6);"
+ "-fx-background-radius: 8;"
+ "-fx-border-color: "
+ (isCompleted ? "rgba(0, 255, 0, 0.5)" : "rgba(255, 255, 255, 0.2)")
+ ";"
+ "-fx-border-width: 1;"
+ "-fx-border-radius: 8;");
return box;
}

}
Loading
Loading