-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #146 from einaskoi/per/merge
Per/merge
- Loading branch information
Showing
25 changed files
with
879 additions
and
638 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
...va/edu/ntnu/idi/idatt2003/gruppe42/controller/appcontrollers/HustlersContentRenderer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| package edu.ntnu.idi.idatt2003.gruppe42.controller.appcontrollers; | ||
|
|
||
| import javafx.geometry.Insets; | ||
| import javafx.scene.control.Label; | ||
| import javafx.scene.layout.Region; | ||
| import javafx.scene.layout.VBox; | ||
| import javafx.scene.text.Font; | ||
| import javafx.scene.text.Text; | ||
| import javafx.scene.text.TextFlow; | ||
|
|
||
| /** | ||
| * Renders formatted tutorial chapter text into a VBox content area. | ||
| */ | ||
| public record HustlersContentRenderer(VBox contentBody) { | ||
|
|
||
| private static final String ACCENT = "#a0720a"; | ||
| private static final String ACCENT_DIM = "#c9a84c"; | ||
| private static final String TEXT_PRIMARY = "#1a1a1a"; | ||
|
|
||
| /** | ||
| * Creates a renderer targeting the given content body. | ||
| * | ||
| * @param contentBody the VBox to render content into | ||
| */ | ||
| public HustlersContentRenderer { | ||
| } | ||
|
|
||
| /** | ||
| * Clears the content body and renders the given raw text. | ||
| * | ||
| * @param rawText the chapter body text to render | ||
| */ | ||
| public void render(final String rawText) { | ||
| contentBody.getChildren().clear(); | ||
| for (String para : rawText.split("\n\n")) { | ||
| para = para.trim(); | ||
| if (para.isEmpty()) { | ||
| continue; | ||
| } | ||
|
|
||
| if (isSectionHeader(para)) { | ||
| renderSectionHeader(para); | ||
| } else { | ||
| renderParagraph(para); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private void renderSectionHeader(final String text) { | ||
| Region divider = new Region(); | ||
| divider.setPrefHeight(1); | ||
| divider.setMaxWidth(32); | ||
| divider.setStyle("-fx-background-color: " + ACCENT_DIM + ";"); | ||
| VBox.setMargin(divider, new Insets(4, 0, 5, 0)); | ||
|
|
||
| Label header = new Label(text); | ||
| header.setStyle( | ||
| "-fx-text-fill: " + ACCENT + ";" | ||
| + "-fx-font-size: 10px;" | ||
| + "-fx-font-weight: bold;" | ||
| + "-fx-font-family: 'Georgia';" | ||
| ); | ||
| contentBody.getChildren().addAll(divider, header); | ||
| } | ||
|
|
||
| private void renderParagraph(final String para) { | ||
| TextFlow flow = new TextFlow(); | ||
| flow.setLineSpacing(3); | ||
| String[] lines = para.split("\n"); | ||
| for (int i = 0; i < lines.length; i++) { | ||
| Text t = new Text((i > 0 ? "\n" : "") + lines[i]); | ||
| t.setStyle("-fx-fill: " + TEXT_PRIMARY + ";"); | ||
| t.setFont(Font.font("Georgia", 12.5)); | ||
| flow.getChildren().add(t); | ||
| } | ||
| contentBody.getChildren().add(flow); | ||
| } | ||
|
|
||
| private boolean isSectionHeader(final String text) { | ||
| String stripped = text.replaceAll("[^a-zA-Z]", ""); | ||
| return !stripped.isEmpty() && stripped.equals(stripped.toUpperCase()) && text.length() < 60; | ||
| } | ||
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
...main/java/edu/ntnu/idi/idatt2003/gruppe42/controller/viewcontrollers/DesktopBindings.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| package edu.ntnu.idi.idatt2003.gruppe42.controller.viewcontrollers; | ||
|
|
||
| import edu.ntnu.idi.idatt2003.gruppe42.controller.PopupsController; | ||
| import edu.ntnu.idi.idatt2003.gruppe42.controller.TimeAndWeatherController; | ||
| import edu.ntnu.idi.idatt2003.gruppe42.controller.appcontrollers.StockAppController; | ||
| import edu.ntnu.idi.idatt2003.gruppe42.model.App; | ||
| import edu.ntnu.idi.idatt2003.gruppe42.model.Player; | ||
| import edu.ntnu.idi.idatt2003.gruppe42.view.views.DesktopView; | ||
| import javafx.application.Platform; | ||
|
|
||
| /** | ||
| * Responsible for binding UI components and listeners to game state in the desktop view. | ||
| */ | ||
| public record DesktopBindings(DesktopView desktopView, Player player, | ||
| TimeAndWeatherController timeAndWeatherController, | ||
| StockAppController stockAppController, | ||
| PopupsController popupsController, | ||
| DesktopDialogController dialogController, | ||
| Runnable onAdvanceWeek) { | ||
|
|
||
| private static final int SATURDAY_INDEX = 6; | ||
| private static final int SUNDAY_INDEX = 0; | ||
|
|
||
| /** | ||
| * Creates a new DesktopBindings instance. | ||
| * | ||
| * @param desktopView the desktop view | ||
| * @param player the player model | ||
| * @param timeAndWeatherController the time and weather controller | ||
| * @param stockAppController the stock app controller | ||
| * @param popupsController the popups controller | ||
| * @param dialogController the dialog controller | ||
| * @param onAdvanceWeek callback to advance the week | ||
| */ | ||
| public DesktopBindings { | ||
|
|
||
| } | ||
|
|
||
| /** | ||
| * Binds all UI components and listeners. | ||
| */ | ||
| public void setup() { | ||
| setupDesktopUi(); | ||
| setupListeners(); | ||
| syncInitialState(); | ||
| } | ||
|
|
||
| private void setupDesktopUi() { | ||
| desktopView.getNextWeekButton().setOnAction(event -> handleAdvanceWeek()); | ||
| desktopView.getSettingsButton().setOnAction(event -> popupsController.show(App.SETTINGS)); | ||
|
|
||
| timeAndWeatherController.dayIndexProperty().addListener((obs, oldDay, newDay) -> { | ||
| int day = newDay.intValue(); | ||
| boolean isWeekend = day == SATURDAY_INDEX || day == SUNDAY_INDEX; | ||
| Platform.runLater(() -> stockAppController.setWeekend(isWeekend)); | ||
| if (day == SATURDAY_INDEX) { | ||
| Platform.runLater(dialogController::showWeekendRapport); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| private void setupListeners() { | ||
| timeAndWeatherController.hourProperty().addListener((obs, ov, nv) -> { | ||
| desktopView.updateClock(timeAndWeatherController.getTimeString()); | ||
| player.updateStatus(); | ||
| }); | ||
|
|
||
| timeAndWeatherController.dayIndexProperty().addListener((obs, ov, nv) -> { | ||
| String dayName = timeAndWeatherController.getDayOfWeekString(); | ||
| desktopView.updateDay(dayName, dayName.equals("SUN")); | ||
| }); | ||
|
|
||
| timeAndWeatherController.weekIndexProperty().addListener((obs, ov, nv) -> | ||
| desktopView.updateWeek(timeAndWeatherController.getWeekString())); | ||
|
|
||
| timeAndWeatherController.weatherProperty().addListener((obs, ov, nv) -> | ||
| desktopView.updateWeather(nv)); | ||
|
|
||
| timeAndWeatherController.temperatureProperty().addListener((obs, ov, nv) -> | ||
| desktopView.updateTemperature(String.valueOf(nv))); | ||
|
|
||
| player.addNameListener(name -> | ||
| Platform.runLater(() -> desktopView.updatePlayerName(name))); | ||
|
|
||
| player.updateStatus(); | ||
| player.addStatusListener(s -> | ||
| Platform.runLater(() -> desktopView.updatePlayerStatus(s.name()))); | ||
| } | ||
|
|
||
| private void syncInitialState() { | ||
| desktopView.updateClock(timeAndWeatherController.getTimeString()); | ||
| String startDay = timeAndWeatherController.getDayOfWeekString(); | ||
| desktopView.updateDay(startDay, startDay.equals("SUN")); | ||
| desktopView.updateWeek(timeAndWeatherController.getWeekString()); | ||
| desktopView.updateWeather(timeAndWeatherController.weatherProperty().get()); | ||
| desktopView.updateTemperature( | ||
| String.valueOf(timeAndWeatherController.temperatureProperty().get())); | ||
| desktopView.updatePlayerName(player.getName()); | ||
| } | ||
|
|
||
| private void handleAdvanceWeek() { | ||
| if (player.isInDebt()) { | ||
| dialogController.showDebtWarning(); | ||
| } else { | ||
| onAdvanceWeek.run(); | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.