mirror of
https://github.com/2OOP/pism.git
synced 2026-02-04 02:44:50 +00:00
i think timer fixed it but idk
This commit is contained in:
@@ -1,5 +1,8 @@
|
|||||||
package org.toop.app.widget.display;
|
package org.toop.app.widget.display;
|
||||||
|
|
||||||
|
import javafx.animation.KeyFrame;
|
||||||
|
import javafx.animation.Timeline;
|
||||||
|
import javafx.util.Duration;
|
||||||
import org.toop.app.widget.Widget;
|
import org.toop.app.widget.Widget;
|
||||||
import org.toop.framework.audio.events.AudioEvents;
|
import org.toop.framework.audio.events.AudioEvents;
|
||||||
import org.toop.framework.eventbus.EventFlow;
|
import org.toop.framework.eventbus.EventFlow;
|
||||||
@@ -15,10 +18,13 @@ import javafx.scene.layout.Region;
|
|||||||
import javafx.scene.layout.VBox;
|
import javafx.scene.layout.VBox;
|
||||||
import javafx.scene.text.Text;
|
import javafx.scene.text.Text;
|
||||||
|
|
||||||
|
import java.util.Timer;
|
||||||
|
|
||||||
public class SongDisplay extends VBox implements Widget {
|
public class SongDisplay extends VBox implements Widget {
|
||||||
private final Text songTitle;
|
private final Text songTitle;
|
||||||
private final ProgressBar progressBar;
|
private final ProgressBar progressBar;
|
||||||
private final Text progressText;
|
private final Text progressText;
|
||||||
|
private boolean canClick = true;
|
||||||
|
|
||||||
public SongDisplay() {
|
public SongDisplay() {
|
||||||
new EventFlow()
|
new EventFlow()
|
||||||
@@ -49,10 +55,13 @@ public class SongDisplay extends VBox implements Widget {
|
|||||||
previousButton.getStyleClass().setAll("previous-button");
|
previousButton.getStyleClass().setAll("previous-button");
|
||||||
|
|
||||||
skipButton.setOnAction( event -> {
|
skipButton.setOnAction( event -> {
|
||||||
|
if (!canClick) { return; }
|
||||||
GlobalEventBus.post(new AudioEvents.SkipMusic());
|
GlobalEventBus.post(new AudioEvents.SkipMusic());
|
||||||
|
doCooldown();
|
||||||
});
|
});
|
||||||
|
|
||||||
pauseButton.setOnAction(event -> {
|
pauseButton.setOnAction(event -> {
|
||||||
|
if (!canClick) { return; }
|
||||||
GlobalEventBus.post(new AudioEvents.PauseMusic());
|
GlobalEventBus.post(new AudioEvents.PauseMusic());
|
||||||
if (pauseButton.getText().equals("⏸")) {
|
if (pauseButton.getText().equals("⏸")) {
|
||||||
pauseButton.setText("▶");
|
pauseButton.setText("▶");
|
||||||
@@ -60,10 +69,13 @@ public class SongDisplay extends VBox implements Widget {
|
|||||||
else if (pauseButton.getText().equals("▶")) {
|
else if (pauseButton.getText().equals("▶")) {
|
||||||
pauseButton.setText("⏸");
|
pauseButton.setText("⏸");
|
||||||
}
|
}
|
||||||
|
doCooldown();
|
||||||
});
|
});
|
||||||
|
|
||||||
previousButton.setOnAction( event -> {
|
previousButton.setOnAction( event -> {
|
||||||
|
if (!canClick) { return; }
|
||||||
GlobalEventBus.post(new AudioEvents.PreviousMusic());
|
GlobalEventBus.post(new AudioEvents.PreviousMusic());
|
||||||
|
doCooldown();
|
||||||
});
|
});
|
||||||
|
|
||||||
HBox control = new HBox(10, previousButton, pauseButton, skipButton);
|
HBox control = new HBox(10, previousButton, pauseButton, skipButton);
|
||||||
@@ -110,6 +122,16 @@ public class SongDisplay extends VBox implements Widget {
|
|||||||
return time;
|
return time;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void doCooldown() {
|
||||||
|
canClick = false;
|
||||||
|
Timeline cooldown = new Timeline(
|
||||||
|
new KeyFrame(Duration.millis(300), event -> canClick = true)
|
||||||
|
);
|
||||||
|
cooldown.setCycleCount(1);
|
||||||
|
cooldown.play();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Node getNode() {
|
public Node getNode() {
|
||||||
return this;
|
return this;
|
||||||
|
|||||||
Reference in New Issue
Block a user