Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added assets/point-popup-bg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 9 additions & 5 deletions src/main/java/io/rpg/HelloApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.stage.Stage;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.config.Configurator;
import javafx.util.Pair;

import java.io.IOException;
Expand All @@ -17,16 +21,16 @@
public class HelloApplication extends Application {
@Override
public void start(Stage stage) throws IOException {
Image someMap = new Image("C:\\Dev\\rpg-io\\assets\\map.png");
Image someMap10x10 = new Image("C:\\Dev\\rpg-io\\assets\\map10x10.png");
Image someDude1 = new Image("C:\\Dev\\rpg-io\\assets\\someDude.png");
Image someDude2 = new Image("C:\\Dev\\rpg-io\\assets\\someDudeButGreen.png");
Image someMap = new Image("file:assets/map.png");
Image someMap10x10 = new Image("file:assets/map10x10.png");
Image someDude1 = new Image("file:assets/someDude.png");
Image someDude2 = new Image("file:assets/someDudeButGreen.png");
Comment on lines +24 to +27
Copy link
Collaborator

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.


DisplayLayer displayLayer = new DisplayLayer(stage);
displayLayer.showLocation()
.setBackgroundImage(someMap)
.addMapObject(new GameObjectStandIn(new Pair<>(0,0), someDude1))
.addMapObject(new GameObjectStandIn(new Pair<>(0,5), someDude1))
.addMapObject(new GameObjectStandIn(new Pair<>(5,5), someDude2));
}
}
}
10 changes: 6 additions & 4 deletions src/main/java/io/rpg/gui/LocationController.java
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;
Expand All @@ -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();
Expand Down Expand Up @@ -63,6 +63,8 @@ public void onKeyTyped(KeyEvent event) {

System.out.println(event);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#6 Introduces log4j, we should switch and use one logger in whole project.


Stage pointPopupStage = pointsPopup.getPopup(5, scene);
pointPopupStage.show();
}

public LocationModel getModel(){
Expand Down
58 changes: 58 additions & 0 deletions src/main/java/io/rpg/gui/popups/PointsEarnedPopup.java
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(){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public PointsEarnedPopup(){
public PointsEarnedPopup() {

// 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){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public Stage getPopup(int pointsCount, Scene scene){
public Stage getPopup(int pointsCount, Scene scene) {

// 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;
}
}
28 changes: 28 additions & 0 deletions src/main/java/io/rpg/gui/popups/PointsPopupController.java
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){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
protected Pair<Double, Double> setBackgroundImage(String url){
protected Pair<Double, Double> setBackgroundImage(String url) {

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());
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
}
}

3 changes: 2 additions & 1 deletion src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
opens io.rpg.model.location to com.google.gson;
opens io.rpg.model.object to com.google.gson;
opens io.rpg.model.data to com.google.gson;

opens io.rpg.gui to javafx.fxml;
opens io.rpg.gui.popups to javafx.fxml;

exports io.rpg;
}
15 changes: 15 additions & 0 deletions src/main/resources/io/rpg/gui/popups/points-earned-view.fxml
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>