Skip to content

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
GZYangKui committed Jan 30, 2023
1 parent faf159b commit 9f55ccd
Show file tree
Hide file tree
Showing 18 changed files with 168 additions and 126 deletions.
6 changes: 0 additions & 6 deletions app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,6 @@
<artifactId>javafx-fxml</artifactId>
<version>${javafx.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.controlsfx/controlsfx -->
<dependency>
<groupId>org.controlsfx</groupId>
<artifactId>controlsfx</artifactId>
<version>11.1.2</version>
</dependency>
<dependency>
<groupId>cn.navclub</groupId>
<artifactId>nes4j-bin</artifactId>
Expand Down
72 changes: 72 additions & 0 deletions app/src/main/java/cn/navclub/nes4j/app/control/IconPopup.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package cn.navclub.nes4j.app.control;

import cn.navclub.nes4j.app.control.skin.IconPopupSkin;
import javafx.animation.FadeTransition;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.scene.control.PopupControl;
import javafx.scene.control.Skin;
import javafx.scene.image.Image;
import javafx.stage.Screen;
import javafx.util.Duration;

/**
* A icon popup implement.
*
* @author <a href="https://github.com/GZYangKui">GZYangKui</a>
*/
public class IconPopup extends PopupControl {
private final FadeTransition transition;
private final ObjectProperty<Image> image;

public IconPopup() {
this.setAutoFix(true);
this.transition = new FadeTransition();
this.transition.setToValue(0);
this.transition.setFromValue(1.0);
this.transition.setOnFinished(event -> this.hide());
this.transition.setDuration(Duration.millis(1000));
this.image = new SimpleObjectProperty<>(this, "image", null);

this.setOnShown(event -> {
this.transition.stop();
this.transition.setNode(this.getSkin().getNode());
this.transition.setDelay(Duration.millis(500));
this.transition.play();
this.calculateXY();
});
}

public IconPopup(Image image) {
this();
this.setImage(image);
}

@Override
protected Skin<?> createDefaultSkin() {
return new IconPopupSkin(this);
}

public Image getImage() {
return image.get();
}

public ObjectProperty<Image> imageProperty() {
return image;
}

public void setImage(Image image) {
this.image.set(image);
}

private void calculateXY() {
var screen = Screen.getPrimary();
var rect = screen.getVisualBounds();

var x = (rect.getWidth() - this.getWidth()) / 2;
var y = (rect.getHeight() - this.getHeight()) - 10;

this.setX(x);
this.setY(y);
}
}
104 changes: 0 additions & 104 deletions app/src/main/java/cn/navclub/nes4j/app/control/StatusIndicator.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package cn.navclub.nes4j.app.control.skin;

import cn.navclub.nes4j.app.assets.FXResource;
import cn.navclub.nes4j.app.control.IconPopup;
import javafx.scene.Node;
import javafx.scene.control.Skin;
import javafx.scene.image.ImageView;
import javafx.scene.layout.VBox;


public class IconPopupSkin implements Skin<IconPopup> {
private VBox node;
@SuppressWarnings("all")
private final ImageView icon;
private final IconPopup popup;

public IconPopupSkin(IconPopup popup) {
this.popup = popup;
this.node = new VBox();
this.icon = new ImageView();

this.icon.imageProperty().bind(popup.imageProperty());

this.node.getChildren().add(this.icon);
this.node.getStyleClass().add("text-popup");
this.node.getStylesheets().add(FXResource.loadStyleSheet("TextPopup.css"));
}

@Override
public IconPopup getSkinnable() {
return this.popup;
}

@Override
public Node getNode() {
return node;
}

@Override
public void dispose() {
this.node = null;
this.icon.imageProperty().unbind();
}
}
16 changes: 14 additions & 2 deletions app/src/main/java/cn/navclub/nes4j/app/view/GameWorld.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import cn.navclub.nes4j.app.assets.FXResource;
import cn.navclub.nes4j.app.INes;
import cn.navclub.nes4j.app.audio.JavaXAudio;
import cn.navclub.nes4j.app.control.IconPopup;
import cn.navclub.nes4j.app.service.TaskService;
import cn.navclub.nes4j.app.dialog.DHandle;
import cn.navclub.nes4j.app.event.FPSTracer;
Expand All @@ -24,6 +25,7 @@
import javafx.scene.control.*;
import javafx.scene.image.PixelFormat;
import javafx.scene.image.WritableImage;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
Expand Down Expand Up @@ -56,16 +58,17 @@ public class GameWorld extends Stage {
private volatile int fps;
private Debugger debugger;
private TaskService<Void> service;
private final IconPopup speedPopup;

public GameWorld() {
var scene = new Scene(FXResource.loadFXML(this));

this.scale = 3;

this.ctx = canvas.getGraphicsContext2D();
this.eventQueue = new LinkedBlockingDeque<>();

this.tracer = new FPSTracer(it -> this.fps = it);
this.speedPopup = new IconPopup(FXResource.loadImage("speed.png"));

this.intBuffer = IntBuffer.allocate(this.scale * this.scale);
this.image = new WritableImage(this.scale * Frame.width, this.scale * Frame.height);
Expand All @@ -74,7 +77,7 @@ public GameWorld() {
this.setHeight(600);
this.setScene(scene);
this.setResizable(false);
this.getScene().getStylesheets().add(FXResource.loadStyleSheet("common.css"));
this.getScene().getStylesheets().add(FXResource.loadStyleSheet("Common.css"));


this.setOnCloseRequest(event -> this.dispose(null));
Expand All @@ -94,6 +97,15 @@ public GameWorld() {
}
}
}

//Change emulator speed
if (code == KeyCode.ADD || code == KeyCode.SUBTRACT) {
if (log.isDebugEnabled()) {
log.debug("Change ppu output frame action:{}", code);
}
this.instance.speed(code == KeyCode.ADD ? -1 : 1);
this.speedPopup.show(this);
}
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
/**Game hall text color**/
-nes4j-game-hall-text-fill: #000000;
/**Game hall list-cell select background color**/
-nes4j-game-hall-list-cell-active: linear-gradient(to right, #D6E0F0, #DDE4EF, #E6EAEF, #EAEBED);
-nes4j-game-hall-list-cell-active: linear-gradient(to right, #b4cbf3, #c6d6ef, #cfddef, #e4e7ef);
/**Game hall list-cell select text fill*/
-nes4j-game-hall-list-cell-text: #5185fd;
/**Default list view select row background color**/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@import "common.css";
@import "Common.css";

.text-area {
-fx-padding: 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@import "common.css";
@import "Common.css";

.box, .content {
-fx-spacing: 2em;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@import "common.css";
@import "Common.css";

GridPane {
-fx-hgap: 1em;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@import "common.css";
@import "Common.css";

GridPane {
-fx-vgap: 1em;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@import "common.css";
@import "Common.css";

.navbar *, .assort, .flow-pane .game-tray .label, .empty .label {
-fx-font-size: 1.4em;
Expand Down Expand Up @@ -53,6 +53,7 @@
}

.assort {
-fx-padding: 0;
-fx-background-insets: 0;
}

Expand All @@ -68,12 +69,12 @@
-fx-shape: 'M970.666667 213.333333H546.586667a10.573333 10.573333 0 0 1-7.54-3.126666L429.793333 100.953333A52.986667 52.986667 0 0 0 392.08 85.333333H96a53.393333 53.393333 0 0 0-53.333333 53.333334v704a53.393333 53.393333 0 0 0 53.333333 53.333333h874.666667a53.393333 53.393333 0 0 0 53.333333-53.333333V266.666667a53.393333 53.393333 0 0 0-53.333333-53.333334z m-275.866667 374.82c-25.486667 33.926667-71.333333 74.92-148.666667 132.913334a21.333333 21.333333 0 0 1-25.6 0c-77.333333-58-123.18-98.986667-148.666666-132.913334S341.333333 528.273333 341.333333 497.233333C341.333333 434.793333 392.126667 384 454.566667 384A112.893333 112.893333 0 0 1 533.333333 415.9 112.893333 112.893333 0 0 1 612.1 384c62.44 0 113.233333 50.793333 113.233333 113.233333 0 31.04-5.106667 57.08-30.533333 90.92z';
}

.assort .list-cell {
.assort .tree-cell {
-fx-background-color: -nes4j-game-hall-list-view;
-fx-focus-traversable: false;
}

.assort .list-cell:selected {
.assort .tree-cell:selected {
-fx-text-fill: -nes4j-game-hall-list-cell-text;
-fx-background-color: -nes4j-game-hall-list-cell-active;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@import "common.css";
@import "Common.css";

.left-box, .right-box {
-fx-spacing: .5em;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@import "common.css";
@import "Common.css";

VBox {
-fx-spacing: 1em;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
@import "Common.css";

.text-popup {
-fx-padding: 2em 3em;
-fx-alignment: CENTER;
-fx-border-radius: .5em;
-fx-background-radius: .5em;
-fx-background-color: rgba(0, 0, 0, .8);
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 9f55ccd

Please sign in to comment.