From 9fb797009092b481ee4620a8237427fe08d47d1c Mon Sep 17 00:00:00 2001 From: kfernandez31 Date: Tue, 24 May 2022 09:30:03 +0200 Subject: [PATCH 01/10] Merged with main --- .../controllers/PerkStoreController.java | 23 +++++++++++++++++++ .../controllers/TaskSelectionController.java | 2 +- .../idlearn/scenes/scenes/PerkStore.fxml | 2 +- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/scenes/src/main/java/mimuw/idlearn/scenes/controllers/PerkStoreController.java b/scenes/src/main/java/mimuw/idlearn/scenes/controllers/PerkStoreController.java index f78a749..6b683c9 100644 --- a/scenes/src/main/java/mimuw/idlearn/scenes/controllers/PerkStoreController.java +++ b/scenes/src/main/java/mimuw/idlearn/scenes/controllers/PerkStoreController.java @@ -3,18 +3,41 @@ import javafx.fxml.FXML; import javafx.scene.control.Button; import javafx.scene.layout.BorderPane; +import javafx.scene.layout.VBox; import mimuw.idlearn.scenes.ResourceHandler; +import java.io.IOException; import java.net.URL; import java.util.ResourceBundle; public class PerkStoreController extends GenericController { @FXML private BorderPane mainBorderPane; + @FXML + private VBox perksVBox; @Override public void initialize(URL url, ResourceBundle resourceBundle) { Button pointsBtn = ResourceHandler.createUserPointsButton(); mainBorderPane.setTop(pointsBtn); + + Button perkBtn = new Button("Memory upgrade"); + double btnWidth = perksVBox.getMaxWidth(); + perkBtn.setMaxWidth(btnWidth); + perkBtn.getStylesheets().add(ResourceHandler.Style.toExternalForm()); + perkBtn.getStyleClass().add("greenButton"); //TODO: add a ResourceHandler method that creates such a stylish button in one line + + perksVBox.getChildren().add(perkBtn); + + /* taskBtn.setOnAction((event) -> { + try { + enterNextScene(ResourceHandler.Task, new TaskController(taskTitle)); + } catch (IOException e) { + e.printStackTrace(); + } + });*/ + + //PerkManager.incrementMemoryPerk() + perksVBox.getChildren().add(perkBtn); } } diff --git a/scenes/src/main/java/mimuw/idlearn/scenes/controllers/TaskSelectionController.java b/scenes/src/main/java/mimuw/idlearn/scenes/controllers/TaskSelectionController.java index de4189c..54a12ee 100644 --- a/scenes/src/main/java/mimuw/idlearn/scenes/controllers/TaskSelectionController.java +++ b/scenes/src/main/java/mimuw/idlearn/scenes/controllers/TaskSelectionController.java @@ -33,9 +33,9 @@ private void setStyleOfButtonForCompletedTask(Button taskBtn) { /** Loads all the user's available tasks as clickable buttons **/ @Override public void initialize(URL url, ResourceBundle resourceBundle) { - Set completedTasks = PointsGiver.getCompletedTasks(); Button pointsBtn = ResourceHandler.createUserPointsButton(); mainBorderPane.setTop(pointsBtn); + Set completedTasks = PointsGiver.getCompletedTasks(); List tasks = new java.util.ArrayList<>(DataManager.getUnlockedTasks()); Collections.sort(tasks); diff --git a/scenes/src/main/resources/mimuw/idlearn/scenes/scenes/PerkStore.fxml b/scenes/src/main/resources/mimuw/idlearn/scenes/scenes/PerkStore.fxml index 9f1de6e..c770775 100644 --- a/scenes/src/main/resources/mimuw/idlearn/scenes/scenes/PerkStore.fxml +++ b/scenes/src/main/resources/mimuw/idlearn/scenes/scenes/PerkStore.fxml @@ -28,7 +28,7 @@
- +
From b4033b750bd0127a374d804025765e7ed6adc557 Mon Sep 17 00:00:00 2001 From: kfernandez31 Date: Tue, 24 May 2022 09:56:04 +0200 Subject: [PATCH 02/10] Added perk-buying functionality front-end --- .../mimuw/idlearn/scenes/ResourceHandler.java | 14 ++++++ .../controllers/PerkStoreController.java | 49 ++++++++++++------- .../controllers/TaskSelectionController.java | 5 +- 3 files changed, 47 insertions(+), 21 deletions(-) diff --git a/scenes/src/main/java/mimuw/idlearn/scenes/ResourceHandler.java b/scenes/src/main/java/mimuw/idlearn/scenes/ResourceHandler.java index 822b105..0ac472c 100644 --- a/scenes/src/main/java/mimuw/idlearn/scenes/ResourceHandler.java +++ b/scenes/src/main/java/mimuw/idlearn/scenes/ResourceHandler.java @@ -123,6 +123,20 @@ public static Alert createAlert(Alert.AlertType alertType, String s, ButtonType. return alert; } + /** + * Wrapper for creating a clickable green button with styling. + * @param s: the button's text + * @param maxWidth: the max width of the button + * @return the button + */ + public static Button createGreenButton(String s, double maxWidth) { + Button btn = new Button(s); + btn.setMaxWidth(maxWidth); + btn.getStylesheets().add(ResourceHandler.Style.toExternalForm()); + btn.getStyleClass().add("greenButton"); + return btn; + } + //TODO: remove this private static final String loremIpsum = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."; public static String repeatLorem(int n) { return loremIpsum.repeat(Math.max(0, n)); } diff --git a/scenes/src/main/java/mimuw/idlearn/scenes/controllers/PerkStoreController.java b/scenes/src/main/java/mimuw/idlearn/scenes/controllers/PerkStoreController.java index 6b683c9..8b7d7b0 100644 --- a/scenes/src/main/java/mimuw/idlearn/scenes/controllers/PerkStoreController.java +++ b/scenes/src/main/java/mimuw/idlearn/scenes/controllers/PerkStoreController.java @@ -1,14 +1,21 @@ package mimuw.idlearn.scenes.controllers; import javafx.fxml.FXML; +import javafx.scene.control.Alert; import javafx.scene.control.Button; +import javafx.scene.control.ButtonType; import javafx.scene.layout.BorderPane; import javafx.scene.layout.VBox; +import mimuw.idlearn.packages.ProblemPackage; import mimuw.idlearn.scenes.ResourceHandler; +import mimuw.idlearn.userdata.DataManager; +import mimuw.idlearn.userdata.NotEnoughPointsException; import java.io.IOException; import java.net.URL; +import java.util.Optional; import java.util.ResourceBundle; +import java.util.Set; public class PerkStoreController extends GenericController { @FXML @@ -21,23 +28,31 @@ public void initialize(URL url, ResourceBundle resourceBundle) { Button pointsBtn = ResourceHandler.createUserPointsButton(); mainBorderPane.setTop(pointsBtn); - Button perkBtn = new Button("Memory upgrade"); - double btnWidth = perksVBox.getMaxWidth(); - perkBtn.setMaxWidth(btnWidth); - perkBtn.getStylesheets().add(ResourceHandler.Style.toExternalForm()); - perkBtn.getStyleClass().add("greenButton"); //TODO: add a ResourceHandler method that creates such a stylish button in one line - - perksVBox.getChildren().add(perkBtn); - - /* taskBtn.setOnAction((event) -> { - try { - enterNextScene(ResourceHandler.Task, new TaskController(taskTitle)); - } catch (IOException e) { - e.printStackTrace(); - } - });*/ + Set titles = PerkManager.getPerkNames(); + double btnWidth = perksVBox.getWidth(); + for (String title : titles) { + Button perkBtn = ResourceHandler.createGreenButton(title, btnWidth); + perksVBox.getChildren().add(perkBtn); + perkBtn.setOnAction((event) -> buyPerk(title)); + } + } - //PerkManager.incrementMemoryPerk() - perksVBox.getChildren().add(perkBtn); + private void buyPerk(String title) { + Alert alert; + try { + DataManager.payPoints(0); //todo: replace with actual cost + + alert = ResourceHandler.createAlert(Alert.AlertType.INFORMATION, + "Acquired perk \"" + title + "\"", ButtonType.OK + ); + alert.setHeaderText("Success!"); + PerkManager.upgradePerk(title); + } catch (NotEnoughPointsException e) { + alert = ResourceHandler.createAlert(Alert.AlertType.WARNING, + "Gather more points and try again", ButtonType.OK + ); + alert.setHeaderText("Not enough points!"); + } + alert.show(); } } diff --git a/scenes/src/main/java/mimuw/idlearn/scenes/controllers/TaskSelectionController.java b/scenes/src/main/java/mimuw/idlearn/scenes/controllers/TaskSelectionController.java index 54a12ee..33e4bdf 100644 --- a/scenes/src/main/java/mimuw/idlearn/scenes/controllers/TaskSelectionController.java +++ b/scenes/src/main/java/mimuw/idlearn/scenes/controllers/TaskSelectionController.java @@ -42,10 +42,7 @@ public void initialize(URL url, ResourceBundle resourceBundle) { double btnWidth = tasksVBox.getMaxWidth(); for (final String taskTitle : tasks) { - Button taskBtn = new Button(taskTitle); - taskBtn.setMaxWidth(btnWidth); - taskBtn.getStylesheets().add(ResourceHandler.Style.toExternalForm()); - taskBtn.getStyleClass().add("greenButton"); + Button taskBtn = ResourceHandler.createGreenButton(taskTitle, btnWidth); tasksVBox.getChildren().add(taskBtn); // make the style change dynamically From ecfab0dcd0cd842384f8f18a336e9692a360d30c Mon Sep 17 00:00:00 2001 From: Antoni Date: Tue, 24 May 2022 09:58:11 +0200 Subject: [PATCH 03/10] Added perk buying backend --- .../mimuw/idlearn/IdLearnApplication.java | 4 ++ .../controllers/PerkStoreController.java | 1 + .../mimuw/idlearn/scoring/PointsGiver.java | 2 +- userdata/pom.xml | 6 +++ .../mimuw/idlearn/userdata/DataManager.java | 14 ++++-- .../mimuw/idlearn/userdata/PerkManager.java | 46 +++++++++++++++++++ .../java/mimuw/idlearn/userdata/Perks.java | 5 ++ userdata/src/main/java/module-info.java | 3 +- 8 files changed, 76 insertions(+), 5 deletions(-) create mode 100644 userdata/src/main/java/mimuw/idlearn/userdata/PerkManager.java create mode 100644 userdata/src/main/java/mimuw/idlearn/userdata/Perks.java diff --git a/application/src/main/java/mimuw/idlearn/IdLearnApplication.java b/application/src/main/java/mimuw/idlearn/IdLearnApplication.java index c9d0c17..1f2467e 100644 --- a/application/src/main/java/mimuw/idlearn/IdLearnApplication.java +++ b/application/src/main/java/mimuw/idlearn/IdLearnApplication.java @@ -24,6 +24,7 @@ import mimuw.idlearn.scenes.preloading.LoadTask; import mimuw.idlearn.scoring.PointsGiver; import mimuw.idlearn.userdata.DataManager; +import mimuw.idlearn.userdata.PerkManager; import java.io.IOException; import java.util.ArrayList; @@ -57,6 +58,9 @@ public void start(Stage stage) throws IOException { // Start data manager DataManager.init(); + // Start perk manager + PerkManager.init(); + // Start points giver PointsGiver.loadSpeeds(); diff --git a/scenes/src/main/java/mimuw/idlearn/scenes/controllers/PerkStoreController.java b/scenes/src/main/java/mimuw/idlearn/scenes/controllers/PerkStoreController.java index 8b7d7b0..89380ac 100644 --- a/scenes/src/main/java/mimuw/idlearn/scenes/controllers/PerkStoreController.java +++ b/scenes/src/main/java/mimuw/idlearn/scenes/controllers/PerkStoreController.java @@ -10,6 +10,7 @@ import mimuw.idlearn.scenes.ResourceHandler; import mimuw.idlearn.userdata.DataManager; import mimuw.idlearn.userdata.NotEnoughPointsException; +import mimuw.idlearn.userdata.PerkManager; import java.io.IOException; import java.net.URL; diff --git a/scoring/src/main/java/mimuw/idlearn/scoring/PointsGiver.java b/scoring/src/main/java/mimuw/idlearn/scoring/PointsGiver.java index e5125bd..c1efd1f 100644 --- a/scoring/src/main/java/mimuw/idlearn/scoring/PointsGiver.java +++ b/scoring/src/main/java/mimuw/idlearn/scoring/PointsGiver.java @@ -109,7 +109,7 @@ public static void exit() { } public static void loadSpeeds() { - HashMap speeds = DataManager.getPointsGiving(); + Map speeds = DataManager.getPointsGiving(); Date date = new Date(); for (Map.Entry entry : speeds.entrySet()) { diff --git a/userdata/pom.xml b/userdata/pom.xml index 3d216f1..b7a9f10 100644 --- a/userdata/pom.xml +++ b/userdata/pom.xml @@ -43,5 +43,11 @@ ${junit.version} test + + mimuw + idlang + 2.0.0 + compile + \ No newline at end of file diff --git a/userdata/src/main/java/mimuw/idlearn/userdata/DataManager.java b/userdata/src/main/java/mimuw/idlearn/userdata/DataManager.java index 4aca624..ee907d9 100644 --- a/userdata/src/main/java/mimuw/idlearn/userdata/DataManager.java +++ b/userdata/src/main/java/mimuw/idlearn/userdata/DataManager.java @@ -23,8 +23,14 @@ public static class PointsGiving { } private static class Data { public long points = 0; - public ArrayList unlockedTasks = new ArrayList<>(List.of(STARTING_TASKS)); - public HashMap pointsGiving = new HashMap<>(); + public List unlockedTasks = new ArrayList<>(List.of(STARTING_TASKS)); + public Map pointsGiving = new HashMap<>(); + public Map perks = new HashMap<>(); + public Data() { + for (String perk : PerkManager.getPerkNames()) { + perks.put(perk, 0); + } + } } private static Data data = new Data(); @@ -81,7 +87,9 @@ public static void setGiverData(String task, long time, long points) throws IOEx data.pointsGiving.put(task, pg); saveData(); } - public static HashMap getPointsGiving() {return new HashMap<>(data.pointsGiving);} + public static Map getPointsGiving() {return new HashMap<>(data.pointsGiving);} + + public static Map getPerks() {return data.perks;} private static void saveData() throws IOException { System.out.println("Saving to file: " + saveFile.getAbsolutePath()); diff --git a/userdata/src/main/java/mimuw/idlearn/userdata/PerkManager.java b/userdata/src/main/java/mimuw/idlearn/userdata/PerkManager.java new file mode 100644 index 0000000..5a9397c --- /dev/null +++ b/userdata/src/main/java/mimuw/idlearn/userdata/PerkManager.java @@ -0,0 +1,46 @@ +package mimuw.idlearn.userdata; + +import mimuw.idlearn.idlang.logic.base.ResourceCounter; + +import java.util.Collections; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +public class PerkManager { + + private static Map perks; + private static Set PERK_NAMES = new HashSet<>(Collections.singleton("Memory")); + + private static void implementPerk(String perkName) { + switch (perkName) { + case "Memory": + ResourceCounter.MAX_MEMORY = 100_000 * (1 + perks.get("Memory")); + break; + default: + throw new RuntimeException("Invalid perk name"); + } + } + + public static void setPerkLevel(String name, int level) { + perks.put(name, level); + implementPerk(name); + } + public static void upgradePerk(String name) { + int perkLevel = perks.get(name); + perks.put(name, perkLevel + 1); + implementPerk(name); + } + + + public static void init() { + perks = DataManager.getPerks(); + for (String perkName : perks.keySet()) { + implementPerk(perkName); + } + } + + public static Set getPerkNames() { + return PERK_NAMES; + } +} diff --git a/userdata/src/main/java/mimuw/idlearn/userdata/Perks.java b/userdata/src/main/java/mimuw/idlearn/userdata/Perks.java new file mode 100644 index 0000000..3d8fc1c --- /dev/null +++ b/userdata/src/main/java/mimuw/idlearn/userdata/Perks.java @@ -0,0 +1,5 @@ +package mimuw.idlearn.userdata; + +public class Perks { + public int memoryLevel; +} diff --git a/userdata/src/main/java/module-info.java b/userdata/src/main/java/module-info.java index 85f5096..c8046cb 100644 --- a/userdata/src/main/java/module-info.java +++ b/userdata/src/main/java/module-info.java @@ -2,8 +2,9 @@ requires mimuw.idlearn.core; requires org.yaml.snakeyaml; requires mimuw.idlearn.packages; + requires mimuw.idlearn.idlang; - opens mimuw.idlearn.userdata to org.yaml.snakeyaml; + opens mimuw.idlearn.userdata to org.yaml.snakeyaml; exports mimuw.idlearn.userdata; } \ No newline at end of file From a1b7f13a3647826405a789a5972236c4e917ef5f Mon Sep 17 00:00:00 2001 From: Antoni Date: Tue, 24 May 2022 10:04:30 +0200 Subject: [PATCH 04/10] Added automatic saving of perk levels --- .../src/main/java/mimuw/idlearn/userdata/DataManager.java | 2 +- .../src/main/java/mimuw/idlearn/userdata/PerkManager.java | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/userdata/src/main/java/mimuw/idlearn/userdata/DataManager.java b/userdata/src/main/java/mimuw/idlearn/userdata/DataManager.java index ee907d9..bdd3ff4 100644 --- a/userdata/src/main/java/mimuw/idlearn/userdata/DataManager.java +++ b/userdata/src/main/java/mimuw/idlearn/userdata/DataManager.java @@ -91,7 +91,7 @@ public static void setGiverData(String task, long time, long points) throws IOEx public static Map getPerks() {return data.perks;} - private static void saveData() throws IOException { + public static void saveData() throws IOException { System.out.println("Saving to file: " + saveFile.getAbsolutePath()); if (!saveFile.isFile()) { saveFile.getParentFile().mkdirs(); diff --git a/userdata/src/main/java/mimuw/idlearn/userdata/PerkManager.java b/userdata/src/main/java/mimuw/idlearn/userdata/PerkManager.java index 5a9397c..e53717d 100644 --- a/userdata/src/main/java/mimuw/idlearn/userdata/PerkManager.java +++ b/userdata/src/main/java/mimuw/idlearn/userdata/PerkManager.java @@ -2,6 +2,7 @@ import mimuw.idlearn.idlang.logic.base.ResourceCounter; +import java.io.IOException; import java.util.Collections; import java.util.HashSet; import java.util.Map; @@ -26,10 +27,11 @@ public static void setPerkLevel(String name, int level) { perks.put(name, level); implementPerk(name); } - public static void upgradePerk(String name) { + public static void upgradePerk(String name) throws IOException { int perkLevel = perks.get(name); perks.put(name, perkLevel + 1); implementPerk(name); + DataManager.saveData(); } From a726152c4e01a4d25bc854ed7917ef227e1f0dc3 Mon Sep 17 00:00:00 2001 From: kfernandez31 Date: Tue, 24 May 2022 21:18:04 +0200 Subject: [PATCH 05/10] Added some extra security in TaskController --- .../controllers/PerkStoreController.java | 2 +- .../scenes/controllers/TaskController.java | 16 +++++++++++-- .../idlearn/scenes/scenes/PerkStore.fxml | 23 +++++++++++++------ 3 files changed, 31 insertions(+), 10 deletions(-) diff --git a/scenes/src/main/java/mimuw/idlearn/scenes/controllers/PerkStoreController.java b/scenes/src/main/java/mimuw/idlearn/scenes/controllers/PerkStoreController.java index 89380ac..3b59b76 100644 --- a/scenes/src/main/java/mimuw/idlearn/scenes/controllers/PerkStoreController.java +++ b/scenes/src/main/java/mimuw/idlearn/scenes/controllers/PerkStoreController.java @@ -30,7 +30,7 @@ public void initialize(URL url, ResourceBundle resourceBundle) { mainBorderPane.setTop(pointsBtn); Set titles = PerkManager.getPerkNames(); - double btnWidth = perksVBox.getWidth(); + double btnWidth = perksVBox.getWidth(); //TODO: nie działa for (String title : titles) { Button perkBtn = ResourceHandler.createGreenButton(title, btnWidth); perksVBox.getChildren().add(perkBtn); diff --git a/scenes/src/main/java/mimuw/idlearn/scenes/controllers/TaskController.java b/scenes/src/main/java/mimuw/idlearn/scenes/controllers/TaskController.java index 4e6d60e..6a641bd 100644 --- a/scenes/src/main/java/mimuw/idlearn/scenes/controllers/TaskController.java +++ b/scenes/src/main/java/mimuw/idlearn/scenes/controllers/TaskController.java @@ -123,9 +123,21 @@ private void submitSolution(CodeBox codeBox) { String tmp = e.toString(); alert = ResourceHandler.createAlert(Alert.AlertType.ERROR, tmp.substring(2 + tmp.indexOf(":")), ButtonType.OK); alert.setHeaderText("Out of array bounds!"); - } catch (SimulationException | IOException e) { + } catch (Exception e) { + String text = "A"; + if (e instanceof IOException) { + text += "n internal I/O"; + // the two cases below should never occur + } else if (e instanceof SimulationException) { + assert false; + text += " compilation"; + } else { + assert false; + text += "n unexpected"; + } + text += " error occurred!"; alert = ResourceHandler.createAlert(Alert.AlertType.ERROR, "Contact your local IdLearn developer for help", ButtonType.OK); - alert.setHeaderText("An " + (e instanceof IOException? "internal I/O" : "unexpected") + " error occurred!"); + alert.setHeaderText(text); e.printStackTrace(); } finally { assert alert != null; diff --git a/scenes/src/main/resources/mimuw/idlearn/scenes/scenes/PerkStore.fxml b/scenes/src/main/resources/mimuw/idlearn/scenes/scenes/PerkStore.fxml index c770775..1ef35ca 100644 --- a/scenes/src/main/resources/mimuw/idlearn/scenes/scenes/PerkStore.fxml +++ b/scenes/src/main/resources/mimuw/idlearn/scenes/scenes/PerkStore.fxml @@ -6,9 +6,9 @@ - + -
- + + + + + + + + + +
- - - - + + + +
From 3abab9cb71bdc8e9caccf433dc39d069838371e9 Mon Sep 17 00:00:00 2001 From: kfernandez31 Date: Tue, 24 May 2022 21:42:18 +0200 Subject: [PATCH 06/10] Fixed perk button width --- .../mimuw/idlearn/scenes/ResourceHandler.java | 9 +++++++++ .../controllers/PerkStoreController.java | 16 +++++++++------- .../controllers/TaskSelectionController.java | 13 ++----------- .../mimuw/idlearn/scenes/scenes/PerkStore.fxml | 18 +++++++++++------- 4 files changed, 31 insertions(+), 25 deletions(-) diff --git a/scenes/src/main/java/mimuw/idlearn/scenes/ResourceHandler.java b/scenes/src/main/java/mimuw/idlearn/scenes/ResourceHandler.java index 0ac472c..bd46202 100644 --- a/scenes/src/main/java/mimuw/idlearn/scenes/ResourceHandler.java +++ b/scenes/src/main/java/mimuw/idlearn/scenes/ResourceHandler.java @@ -137,6 +137,15 @@ public static Button createGreenButton(String s, double maxWidth) { return btn; } + /** + * Changes the style of the button for a completed/unlocked asset, + * so that it's different from the others of its type. + * @param taskBtn: button of an asset + */ + public static void setStyleForUnlockedAsset(Button taskBtn) { + taskBtn.setStyle("-fx-background-color: #029c5b;"); + } + //TODO: remove this private static final String loremIpsum = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."; public static String repeatLorem(int n) { return loremIpsum.repeat(Math.max(0, n)); } diff --git a/scenes/src/main/java/mimuw/idlearn/scenes/controllers/PerkStoreController.java b/scenes/src/main/java/mimuw/idlearn/scenes/controllers/PerkStoreController.java index 3b59b76..41dae0d 100644 --- a/scenes/src/main/java/mimuw/idlearn/scenes/controllers/PerkStoreController.java +++ b/scenes/src/main/java/mimuw/idlearn/scenes/controllers/PerkStoreController.java @@ -5,8 +5,8 @@ import javafx.scene.control.Button; import javafx.scene.control.ButtonType; import javafx.scene.layout.BorderPane; +import javafx.scene.layout.Region; import javafx.scene.layout.VBox; -import mimuw.idlearn.packages.ProblemPackage; import mimuw.idlearn.scenes.ResourceHandler; import mimuw.idlearn.userdata.DataManager; import mimuw.idlearn.userdata.NotEnoughPointsException; @@ -14,15 +14,14 @@ import java.io.IOException; import java.net.URL; -import java.util.Optional; import java.util.ResourceBundle; import java.util.Set; public class PerkStoreController extends GenericController { - @FXML - private BorderPane mainBorderPane; @FXML private VBox perksVBox; + @FXML + private BorderPane mainBorderPane; @Override public void initialize(URL url, ResourceBundle resourceBundle) { @@ -30,7 +29,7 @@ public void initialize(URL url, ResourceBundle resourceBundle) { mainBorderPane.setTop(pointsBtn); Set titles = PerkManager.getPerkNames(); - double btnWidth = perksVBox.getWidth(); //TODO: nie działa + double btnWidth = perksVBox.getMaxWidth(); for (String title : titles) { Button perkBtn = ResourceHandler.createGreenButton(title, btnWidth); perksVBox.getChildren().add(perkBtn); @@ -39,21 +38,24 @@ public void initialize(URL url, ResourceBundle resourceBundle) { } private void buyPerk(String title) { - Alert alert; + Alert alert = null; try { DataManager.payPoints(0); //todo: replace with actual cost + PerkManager.upgradePerk(title); alert = ResourceHandler.createAlert(Alert.AlertType.INFORMATION, "Acquired perk \"" + title + "\"", ButtonType.OK ); alert.setHeaderText("Success!"); - PerkManager.upgradePerk(title); } catch (NotEnoughPointsException e) { alert = ResourceHandler.createAlert(Alert.AlertType.WARNING, "Gather more points and try again", ButtonType.OK ); alert.setHeaderText("Not enough points!"); + } catch (IOException e) { + e.printStackTrace(); } + assert alert != null; alert.show(); } } diff --git a/scenes/src/main/java/mimuw/idlearn/scenes/controllers/TaskSelectionController.java b/scenes/src/main/java/mimuw/idlearn/scenes/controllers/TaskSelectionController.java index 33e4bdf..22d0b2f 100644 --- a/scenes/src/main/java/mimuw/idlearn/scenes/controllers/TaskSelectionController.java +++ b/scenes/src/main/java/mimuw/idlearn/scenes/controllers/TaskSelectionController.java @@ -21,15 +21,6 @@ public class TaskSelectionController extends GenericController { @FXML private BorderPane mainBorderPane; - /** - * Makes the button of a completed task darker and gives it a popup on click. - * This assumes the task's text has been set. - * @param taskBtn: button of a task - */ - private void setStyleOfButtonForCompletedTask(Button taskBtn) { - taskBtn.setStyle("-fx-background-color: #029c5b;"); - } - /** Loads all the user's available tasks as clickable buttons **/ @Override public void initialize(URL url, ResourceBundle resourceBundle) { @@ -48,10 +39,10 @@ public void initialize(URL url, ResourceBundle resourceBundle) { // make the style change dynamically PointsGiver.connectToTaskCompletion(event -> { if (event.value() == taskTitle) - setStyleOfButtonForCompletedTask(taskBtn); + ResourceHandler.setStyleForUnlockedAsset(taskBtn); }); if (completedTasks.contains(taskTitle)) - setStyleOfButtonForCompletedTask(taskBtn); + ResourceHandler.setStyleForUnlockedAsset(taskBtn); taskBtn.setOnAction((event) -> { try { diff --git a/scenes/src/main/resources/mimuw/idlearn/scenes/scenes/PerkStore.fxml b/scenes/src/main/resources/mimuw/idlearn/scenes/scenes/PerkStore.fxml index 1ef35ca..68b903d 100644 --- a/scenes/src/main/resources/mimuw/idlearn/scenes/scenes/PerkStore.fxml +++ b/scenes/src/main/resources/mimuw/idlearn/scenes/scenes/PerkStore.fxml @@ -1,12 +1,16 @@ - - - - - + + + + + + + + + - +