Skip to content

Commit

Permalink
Merge pull request #118 from einaskoi/per/bugs
Browse files Browse the repository at this point in the history
fix major popup bugs with pane in desktop view
  • Loading branch information
einaskoi authored May 15, 2026
2 parents 3ad0a9e + c65df0f commit 572dbab
Show file tree
Hide file tree
Showing 10 changed files with 164 additions and 99 deletions.
Empty file removed .claude/settings.local.json
Empty file.
1 change: 0 additions & 1 deletion .claude/worktrees/nostalgic-liskov-9129de
Submodule nostalgic-liskov-9129de deleted from 6064d3
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
import edu.ntnu.idi.idatt2003.gruppe42.View.Popup;
import java.util.List;
import java.util.Optional;

import javafx.geometry.Point2D;
import javafx.scene.control.Button;
import javafx.scene.layout.Pane;
import javafx.scene.layout.StackPane;

/** Manages popup behavior. */
public final class PopupsController {
Expand Down Expand Up @@ -59,22 +58,29 @@ public void bindOpenButton(Button button, App type) {
}

private void makeDraggable(Popup popup) {
StackPane root = popup.getRoot();
Pane root = popup.getRoot();
double[] offset = new double[2];
double[] maxXY = new double[2];

popup.getHeader().setOnMousePressed(event -> {
offset[0] = event.getSceneX() - root.getLayoutX();
offset[1] = event.getSceneY() - root.getLayoutY();
if (root.getParent() instanceof Pane parent) {
maxXY[0] = parent.getWidth() - root.getWidth();
maxXY[1] = parent.getHeight() - root.getHeight();
Point2D local = parent.sceneToLocal(event.getSceneX(), event.getSceneY());
offset[0] = local.getX() - root.getLayoutX();
offset[1] = local.getY() - root.getLayoutY();
}
event.consume();
});

popup.getHeader().setOnMouseDragged(event -> {
root.setLayoutX(Math.max(0, Math.min(event.getSceneX() - offset[0], maxXY[0])));
root.setLayoutY(Math.max(0, Math.min(event.getSceneY() - offset[1], maxXY[1])));
if (root.getParent() instanceof Pane parent) {
Point2D local = parent.sceneToLocal(event.getSceneX(), event.getSceneY());
double newX = local.getX() - offset[0];
double newY = local.getY() - offset[1];
double maxX = parent.getWidth() - root.getWidth();
double maxY = parent.getHeight() - root.getHeight();
root.setLayoutX(Math.max(0, Math.min(newX, maxX)));
root.setLayoutY(Math.max(0, Math.min(newY, maxY)));
}
event.consume();
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import javafx.scene.input.ClipboardContent;
import javafx.scene.input.Dragboard;
import javafx.scene.input.TransferMode;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.Pane;
import javafx.scene.layout.Region;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
Expand All @@ -55,7 +55,7 @@ public final class DesktopViewController {
private final TimeAndWeatherController timeAndWeatherController;
private final MarketController marketController;
private final StockAppController stockAppController;
private final SettingsAppController settingsAppController; // ← added
private final SettingsAppController settingsAppController;
private final WeekendRapportApp weekendRapportApp = new WeekendRapportApp();
private final WarningApp warningApp = new WarningApp();
private final GameOverApp gameOverApp = new GameOverApp();
Expand Down Expand Up @@ -97,7 +97,7 @@ public DesktopViewController(
settingsAppController.setLoggedIn(true);

settingsAppController.setOnGradientChanged(cfg ->
desktopView.getRoot().setStyle(
desktopView.getDesktopPane().setStyle(
SettingsApp.buildCssGradient(cfg.colorA(), cfg.colorB(), cfg.direction())));

settingsAppController.setOnPlayerNameChanged(name -> player.setName(name));
Expand All @@ -112,7 +112,6 @@ public DesktopViewController(
popups.add(newsApp);
popups.add(bankApp);


this.popupsController = popupsController;
this.popupsController.addPopups(popups);

Expand All @@ -126,11 +125,13 @@ public DesktopViewController(

this.desktopView = new DesktopView(this);
setupListeners();
BorderPane root = desktopView.getRoot();

Pane root = desktopView.getRoot();
Pane overlay = desktopView.getPopupOverlay();

for (Popup p : popupsController.getPopups()) {
desktopView.registerPopup(p.getRoot());
root.getChildren().add(p.getRoot());
overlay.getChildren().add(p.getRoot());
}

weekendRapportApp.centerInParent();
Expand All @@ -141,7 +142,7 @@ public DesktopViewController(
desktopView.registerModal(ModalLayer.WARNING, warningApp.getRoot());
desktopView.registerModal(ModalLayer.GAME_OVER, gameOverApp.getRoot());

root.getChildren().addAll(
overlay.getChildren().addAll(
desktopView.getOverlay(ModalLayer.RAPPORT), weekendRapportApp.getRoot(),
desktopView.getOverlay(ModalLayer.WARNING), warningApp.getRoot(),
desktopView.getOverlay(ModalLayer.GAME_OVER), gameOverApp.getRoot()
Expand Down Expand Up @@ -169,7 +170,6 @@ public DesktopViewController(
stockAppController.setWeekend(startDay == SATURDAY_INDEX || startDay == SUNDAY_INDEX);
}


private void setupListeners() {
timeAndWeatherController.hourProperty().addListener((o, ov, nv) ->
desktopView.updateClock(timeAndWeatherController.getTimeString()));
Expand All @@ -191,7 +191,6 @@ private void setupListeners() {
player.getNameProperty().addListener((obs, ov, nv) ->
desktopView.updatePlayerName(nv));

// Initial sync
desktopView.updateClock(timeAndWeatherController.getTimeString());
String startDay = timeAndWeatherController.getDayOfWeekString();
desktopView.updateDay(startDay, startDay.equals("SUN"));
Expand All @@ -201,9 +200,6 @@ private void setupListeners() {
desktopView.updatePlayerName(player.getName());
}

/**
* Shows the weekend rapport at the end of the week.
*/
private void showWeekendRapport() {
int week = timeAndWeatherController.weekIndexProperty().get();
List<Transaction> transactions = player.getTransactionArchive().getTransactions(week);
Expand All @@ -218,9 +214,6 @@ private void showWeekendRapport() {
desktopView.enterLayer(ModalLayer.RAPPORT);
}

/**
* Wires the weekend rapport buttons.
*/
private void wireWeekendRapport() {
weekendRapportApp.getContinueButton().setOnAction(event -> {
weekendRapportApp.getRoot().setVisible(false);
Expand All @@ -229,10 +222,6 @@ private void wireWeekendRapport() {
});
}


/**
* Handles the request to advance to the next week.
*/
private void handleAdvanceWeek() {
if (player.isInDebt()) {
showDebtWarning();
Expand All @@ -241,16 +230,11 @@ private void handleAdvanceWeek() {
}
}

/**
* Performs the actual week advancement.
*/
private void doAdvanceWeek() {
marketController.advanceWeek();
timeAndWeatherController.advanceWeek();
}


/** Shows debt warning. */
private void showDebtWarning() {
warningApp.configure(
"💔",
Expand All @@ -272,7 +256,6 @@ private void showDebtWarning() {
showWarning();
}

/** Shows market closed warning. */
private void showMarketClosedWarning() {
warningApp.configure(
"🔒",
Expand All @@ -284,7 +267,6 @@ private void showMarketClosedWarning() {
showWarning();
}

/** Shows insufficient funds warning. */
private void showInsufficientFundsWarning() {
warningApp.configure(
"\uD83E\uDD7A",
Expand All @@ -296,26 +278,21 @@ private void showInsufficientFundsWarning() {
showWarning();
}

/** Displays warning modal. */
private void showWarning() {
warningApp.show();
desktopView.enterLayer(ModalLayer.WARNING);
}

/** Dismisses the warning. */
private void dismissWarning() {
warningApp.getRoot().setVisible(false);
desktopView.exitLayer(ModalLayer.WARNING);
}


/** Shows the game over screen. */
private void showGameOver() {
gameOverApp.show();
desktopView.enterLayer(ModalLayer.GAME_OVER);
}

/** Wires game over buttons. */
private void wireGameOver() {
gameOverApp.getStartOverButton().setOnAction(event -> {
if (onGameOver != null) onGameOver.run();
Expand All @@ -327,13 +304,10 @@ public void setOnGameOver(final Runnable callback) {
this.onGameOver = callback;
}


/** Handles logout action. */
private void handleLogout() {
if (onGameOver != null) onGameOver.run();
}


/** Creates an app button. */
public Button createAppButton(final App type) {
Button button = new Button(type.getDisplayName());
Expand Down Expand Up @@ -394,7 +368,6 @@ public void configureCellAsDropTarget(final StackPane cell) {
});
}


/** @return the player model. */
public Player getPlayer() {
return player;
Expand All @@ -410,8 +383,6 @@ public DesktopView getDesktopView() {
return desktopView;
}


/** Calculates net income. */
private static BigDecimal calculateNetIncome(final List<Transaction> transactions) {
BigDecimal net = BigDecimal.ZERO;
for (Transaction t : transactions) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@

import edu.ntnu.idi.idatt2003.gruppe42.Model.App;
import edu.ntnu.idi.idatt2003.gruppe42.View.Popup;
import javafx.geometry.Insets;
import javafx.scene.control.Label;
import javafx.scene.layout.VBox;
import javafx.scene.layout.HBox;
import javafx.scene.control.Button;
import javafx.scene.layout.Priority;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.scene.paint.Color;
import javafx.geometry.Pos;
import javafx.scene.shape.Rectangle;

/**
* A popup for the app store app.
Expand All @@ -12,8 +23,10 @@ public class AppStoreApp extends Popup {
* Constructs a new app store popup.
*/
public AppStoreApp() {
super(400, 300, 100, 100, App.APPSTORE);
// Add App store specific content here
super(500, 450, 100, 100, App.APPSTORE);
buildContent();
}

private void buildContent() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,72 @@

import edu.ntnu.idi.idatt2003.gruppe42.Model.App;
import edu.ntnu.idi.idatt2003.gruppe42.View.Popup;
import javafx.geometry.Insets;
import javafx.scene.control.Label;
import javafx.scene.layout.VBox;
import javafx.scene.layout.HBox;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.geometry.Pos;
import javafx.scene.shape.Circle;

/** Mail app popup. */
public class MailApp extends Popup {

/** Constructs the Mail app. */
public MailApp() {
super(400, 300, 140, 140, App.MAIL);
// Add Mail specific content here
super(450, 400, 140, 140, App.MAIL);
buildContent();
}

private void buildContent() {
content.setPadding(new Insets(20));
content.setSpacing(15);

Label title = new Label("Inbox");
title.setFont(Font.font("System", FontWeight.BOLD, 22));
content.getChildren().add(title);

VBox mailList = new VBox(10);
mailList.getChildren().addAll(
createMailItem("System", "Welcome to the Matrix", "Your journey begins now. Stay focused.", "10:24 AM"),
createMailItem("HR", "Onboarding Documents", "Please sign the attached NDA.", "Yesterday"),
createMailItem("Bank", "Account Security Alert", "A new login was detected from Dubai.", "2 days ago")
);
content.getChildren().add(mailList);
}

private VBox createMailItem(String sender, String subject, String preview, String time) {
VBox item = new VBox(5);
item.setPadding(new Insets(12));
item.setStyle("-fx-background-color: #ffffff; -fx-border-color: #eeeeee; -fx-border-radius: 8; -fx-background-radius: 8;");

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

Circle avatar = new Circle(15, Color.web("#007AFF"));
Label senderLabel = new Label(sender);
senderLabel.setFont(Font.font("System", FontWeight.BOLD, 14));

javafx.scene.layout.Region spacer = new javafx.scene.layout.Region();
HBox.setHgrow(spacer, javafx.scene.layout.Priority.ALWAYS);

Label timeLabel = new Label(time);
timeLabel.setTextFill(Color.GRAY);
timeLabel.setFont(Font.font(12));

top.getChildren().addAll(avatar, senderLabel, spacer, timeLabel);

Label subLabel = new Label(subject);
subLabel.setFont(Font.font("System", FontWeight.MEDIUM, 13));

Label prevLabel = new Label(preview);
prevLabel.setTextFill(Color.GRAY);
prevLabel.setWrapText(true);

item.getChildren().addAll(top, subLabel, prevLabel);
return item;
}

}
Loading

0 comments on commit 572dbab

Please sign in to comment.