-
Notifications
You must be signed in to change notification settings - Fork 0
@mhawryluk/rpg 82 points earned popup #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
5931cfb
363fc49
ddb2dde
a2c4aac
eeb1ed7
901e572
4e92d73
61ca3d6
38561c0
75325b6
1b3bcee
4a764ce
713d04e
93895ac
dc7bbfa
8f97fe1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,16 @@ | ||
| package io.rpg.gui; | ||
|
|
||
| import io.rpg.gui.model.LocationModel; | ||
| import io.rpg.model.GameObjectStandIn; | ||
| import javafx.event.EventType; | ||
| import io.rpg.gui.popups.PointsEarnedPopup; | ||
| import javafx.fxml.FXML; | ||
| import javafx.fxml.FXMLLoader; | ||
| import javafx.fxml.Initializable; | ||
| import javafx.geometry.Rectangle2D; | ||
| import javafx.scene.Parent; | ||
| import javafx.scene.Scene; | ||
| import javafx.scene.image.ImageView; | ||
| import javafx.scene.input.KeyEvent; | ||
| import javafx.scene.layout.HBox; | ||
| import javafx.scene.layout.Pane; | ||
| import javafx.stage.Stage; | ||
|
|
||
| import java.io.IOException; | ||
| import java.net.URL; | ||
|
|
@@ -28,6 +26,8 @@ public class LocationController implements Initializable { | |
| private LocationModel model; | ||
| private Scene scene; | ||
|
|
||
| private final PointsEarnedPopup pointsPopup = new PointsEarnedPopup(); | ||
|
|
||
| public static LocationController load() throws IOException { | ||
| FXMLLoader loader = new FXMLLoader(FXML_URL); | ||
| loader.load(); | ||
|
|
@@ -63,6 +63,8 @@ public void onKeyTyped(KeyEvent event) { | |
|
|
||
| System.out.println(event); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| Stage pointPopupStage = pointsPopup.getPopup(5, scene); | ||
| pointPopupStage.show(); | ||
| } | ||
|
|
||
| public LocationModel getModel(){ | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,58 @@ | ||||||
| package io.rpg.gui.popups; | ||||||
|
|
||||||
| import javafx.fxml.FXMLLoader; | ||||||
| import javafx.scene.Parent; | ||||||
| import javafx.scene.Scene; | ||||||
| import javafx.scene.paint.Color; | ||||||
| import javafx.stage.Stage; | ||||||
| import javafx.stage.StageStyle; | ||||||
| import javafx.stage.Window; | ||||||
| import javafx.util.Pair; | ||||||
|
|
||||||
| import java.io.IOException; | ||||||
| import java.util.Objects; | ||||||
|
|
||||||
| public class PointsEarnedPopup { | ||||||
|
|
||||||
| private final FXMLLoader loader = new FXMLLoader(Objects.requireNonNull(PointsEarnedPopup.class.getResource("points-earned-view.fxml")));; | ||||||
| private Parent root; | ||||||
| private PointsPopupController controller; | ||||||
| private final Scene popupScene; | ||||||
|
|
||||||
| public PointsEarnedPopup(){ | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| // read FXML view | ||||||
| try { | ||||||
| root = loader.load(); | ||||||
| } catch (IOException e) { | ||||||
| e.printStackTrace(); | ||||||
| } | ||||||
|
|
||||||
| popupScene = new Scene(root, Color.TRANSPARENT); | ||||||
| } | ||||||
|
|
||||||
| public Stage getPopup(int pointsCount, Scene scene){ | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| // fill dynamic view components | ||||||
| if (controller == null) controller = loader.getController(); | ||||||
| controller.setPointsCount(pointsCount); | ||||||
| Pair<Double, Double> backgroundDims = controller.setBackgroundImage("file:assets/point-popup-bg.png"); | ||||||
|
|
||||||
| // create popup stage | ||||||
| Stage popupStage = new Stage(StageStyle.TRANSPARENT); | ||||||
| Window window = scene.getWindow(); | ||||||
| popupStage.initOwner(window); | ||||||
|
|
||||||
| // add and center popupScene on popup stage | ||||||
| popupStage.setScene(popupScene); | ||||||
| popupStage.setX(window.getX() + window.getWidth()/2 - backgroundDims.getKey()/2); | ||||||
| popupStage.setY(window.getY() + window.getHeight()/2 - backgroundDims.getValue()/2); | ||||||
|
|
||||||
| // close popup after clicking aside | ||||||
| popupStage.focusedProperty().addListener((obs, wasFocused, isNowFocused) -> { | ||||||
| if (!isNowFocused) { | ||||||
| popupStage.close(); | ||||||
| } | ||||||
| }); | ||||||
|
|
||||||
| return popupStage; | ||||||
| } | ||||||
| } | ||||||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,28 @@ | ||||||||
| package io.rpg.gui.popups; | ||||||||
|
|
||||||||
| import javafx.fxml.FXML; | ||||||||
| import javafx.scene.control.Label; | ||||||||
| import javafx.scene.image.Image; | ||||||||
| import javafx.scene.layout.*; | ||||||||
| import javafx.util.Pair; | ||||||||
|
|
||||||||
| public class PointsPopupController { | ||||||||
|
|
||||||||
| @FXML private Label label; | ||||||||
| @FXML private Pane background; | ||||||||
|
|
||||||||
| protected void setPointsCount(int pointsCount) { | ||||||||
| label.setText("Earned " + pointsCount + " points!"); | ||||||||
| } | ||||||||
|
|
||||||||
| protected Pair<Double, Double> setBackgroundImage(String url){ | ||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| BackgroundImage backgroundImg= new BackgroundImage( | ||||||||
| new Image(url), | ||||||||
| BackgroundRepeat.NO_REPEAT, BackgroundRepeat.NO_REPEAT, | ||||||||
| BackgroundPosition.DEFAULT, | ||||||||
| BackgroundSize.DEFAULT | ||||||||
| ); | ||||||||
| background.setBackground(new Background(backgroundImg)); | ||||||||
| return new Pair<>(background.getPrefWidth(), background.getPrefHeight()); | ||||||||
| } | ||||||||
| } | ||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
|
|
||
| <?import javafx.scene.control.Label?> | ||
| <?import javafx.scene.layout.Pane?> | ||
| <?import javafx.scene.text.Font?> | ||
|
|
||
| <Pane fx:id="background" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="175.0" prefWidth="350.0" xmlns="http://javafx.com/javafx/17" xmlns:fx="http://javafx.com/fxml/1" fx:controller="io.rpg.gui.popups.PointsPopupController"> | ||
| <children> | ||
| <Label fx:id="label" alignment="CENTER" layoutX="18.0" layoutY="14.0" prefHeight="150.0" prefWidth="243.0" text="Label" textAlignment="CENTER" textFill="#fdd835" wrapText="true"> | ||
| <font> | ||
| <Font name="Courier Bold" size="30.0" /> | ||
| </font> | ||
| </Label> | ||
| </children> | ||
| </Pane> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These paths should be loaded from configuration. I guess its fine for now and we can do this in separate PR after #6 is merged.