Skip to content

Commit

Permalink
feat(UIFactory): Add inbuilt UI buttons.
Browse files Browse the repository at this point in the history
  • Loading branch information
pawelsa committed May 13, 2026
1 parent 82600ca commit dfbe88c
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions src/main/java/edu/ntnu/idi/idatt/view/components/ui/UIFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
import java.util.function.Consumer;

import edu.ntnu.idi.idatt.session.UserSession;
import edu.ntnu.idi.idatt.view.SceneFactory;
import edu.ntnu.idi.idatt.view.components.elements.IconComponent;
import edu.ntnu.idi.idatt.view.components.elements.SearchBarComponent;
import edu.ntnu.idi.idatt.view.components.primitives.ActionEventHandler;
import edu.ntnu.idi.idatt.view.util.CssUtils;
import edu.ntnu.idi.idatt.view.util.ResourceUtils;
import javafx.beans.binding.Bindings;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Parent;
Expand Down Expand Up @@ -96,10 +96,19 @@ private static Parent createDefaultNavigation(Label titleLabel, List<String> but

UICompositor.Builder navigationBuilder = new UICompositor.Builder()
.parent(new VBox())
.growWithAlignment(Pos.CENTER)
.addContent(titleLabel);

buttons.forEach(b -> navigationBuilder.addContent(b));

navigationBuilder.filler();

if (!SceneFactory.isFinal()) {
Button previous = new Button("Previous");
previous.setOnAction((e) -> SceneFactory.goBack());
navigationBuilder.addContent(previous);
}

UICompositor navigation = navigationBuilder.build();

return navigation.makeUI();
Expand Down Expand Up @@ -131,6 +140,16 @@ public static Parent createMenu(String title, List<String> buttonLables, ActionE

buttons.forEach(b -> menuBuilder.addContent(b));

menuBuilder.filler();

Button progress = new Button("Advance to next week");
progress.setOnAction((e) -> {
UserSession.getInstance().getExchange().advance();
SceneFactory.reloadCurrent();
});

menuBuilder.addContent(progress);

UICompositor menu = menuBuilder.build();

return menu.makeUI();
Expand All @@ -140,10 +159,11 @@ public static Parent createMenu(String title, List<String> buttonLables, ActionE
public static Parent createToolbar(ActionEventHandler menuHandle, ActionEventHandler quitHandle) {
Label balance = new Label();
balance.textProperty().bind(
Bindings.concat("Balance: ", UserSession.getInstance().moneyProperty(), "USD"));
UserSession.getInstance().moneyProperty().asString("Balance: %.2f $"));
Label playerStatus = new Label("Status:" + UserSession.getInstance().getPlayer().getStatus());
Label playerNetWorth = new Label(
"Net Worth: " + UserSession.getInstance().getPlayer().getNetWorth().toString() + " USD");
Label playerNetWorth = new Label();
playerNetWorth.textProperty().bind(
UserSession.getInstance().netWorthProperty().asString("Net Worth: %.2f $"));

CssUtils.apply(balance, CssUtils.MED_TEXT_16);
CssUtils.apply(playerStatus, CssUtils.MED_TEXT_16);
Expand Down

0 comments on commit dfbe88c

Please sign in to comment.