mirror of
https://github.com/2OOP/pism.git
synced 2026-02-04 10:54:51 +00:00
Fix music display not working (#267)
* Added unsubscribe to EventFlow. ListenerHandler now functional. GlobalEventbus now user listenerHandler * getAllListeners * Removed nulls * Fixed stress tests * Added docs, no more list creation when adding events to the bus. * Fixed unsubscribe not working. * Moved away from deprecated functions * moved from wildcard to typed * Moved away from deprecated function * Added debugging to GlobalEventBus * Fixed cleaning flow * Fixed unsubscribe all * Fixed unsubscribe all * Removed unused import * Added LoadingWidget.java for server feedback * Replace deprecated with correct function
This commit is contained in:
committed by
GitHub
parent
81740acd04
commit
12a20a224e
@@ -1,18 +1,23 @@
|
||||
package org.toop.app;
|
||||
|
||||
import javafx.application.Platform;
|
||||
import javafx.geometry.Pos;
|
||||
import org.toop.app.game.Connect4Game;
|
||||
import org.toop.app.game.ReversiGame;
|
||||
import org.toop.app.game.TicTacToeGame;
|
||||
import org.toop.app.widget.WidgetContainer;
|
||||
import org.toop.app.widget.complex.LoadingWidget;
|
||||
import org.toop.app.widget.popup.ChallengePopup;
|
||||
import org.toop.app.widget.popup.ErrorPopup;
|
||||
import org.toop.app.widget.popup.SendChallengePopup;
|
||||
import org.toop.app.widget.view.ServerView;
|
||||
import org.toop.framework.eventbus.EventFlow;
|
||||
import org.toop.framework.eventbus.ListenerHandler;
|
||||
import org.toop.framework.networking.clients.TournamentNetworkingClient;
|
||||
import org.toop.framework.networking.events.NetworkEvents;
|
||||
import org.toop.framework.networking.types.NetworkingConnector;
|
||||
import org.toop.local.AppContext;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
@@ -69,24 +74,35 @@ public final class Server {
|
||||
return;
|
||||
}
|
||||
|
||||
new EventFlow()
|
||||
final int reconnectAttempts = 10;
|
||||
|
||||
LoadingWidget loading = new LoadingWidget(0, reconnectAttempts);
|
||||
loading.show(Pos.CENTER);
|
||||
|
||||
var a = new EventFlow()
|
||||
.addPostEvent(NetworkEvents.StartClient.class,
|
||||
new TournamentNetworkingClient(),
|
||||
new NetworkingConnector(ip, parsedPort, 10, 1, TimeUnit.SECONDS)
|
||||
)
|
||||
.onResponse(NetworkEvents.StartClientResponse.class, e -> {
|
||||
this.user = user;
|
||||
clientId = e.clientId();
|
||||
new NetworkingConnector(ip, parsedPort, reconnectAttempts, 1, TimeUnit.SECONDS)
|
||||
);
|
||||
|
||||
new EventFlow().addPostEvent(new NetworkEvents.SendLogin(clientId, user)).postEvent();
|
||||
a.onResponse(NetworkEvents.StartClientResponse.class, e -> {
|
||||
|
||||
primary = new ServerView(user, this::sendChallenge, this::disconnect);
|
||||
WidgetContainer.getCurrentView().transitionNext(primary);
|
||||
a.unsubscribe("startclient");
|
||||
|
||||
startPopulateScheduler();
|
||||
populateGameList();
|
||||
loading.hide();
|
||||
this.user = user;
|
||||
clientId = e.clientId();
|
||||
|
||||
}).postEvent();
|
||||
new EventFlow().addPostEvent(new NetworkEvents.SendLogin(clientId, user)).postEvent();
|
||||
|
||||
primary = new ServerView(user, this::sendChallenge, this::disconnect);
|
||||
WidgetContainer.getCurrentView().transitionNext(primary);
|
||||
|
||||
startPopulateScheduler();
|
||||
populateGameList();
|
||||
}, false, "startclient").listen(NetworkEvents.ConnectTry.class, e -> {
|
||||
Platform.runLater(() -> loading.setAmount(e.amount()));
|
||||
}).postEvent();
|
||||
|
||||
new EventFlow().listen(this::handleReceivedChallenge)
|
||||
.listen(this::handleMatchResponse);
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
package org.toop.app.widget.complex;
|
||||
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.control.ProgressBar;
|
||||
import javafx.scene.layout.HBox;
|
||||
|
||||
public class LoadingWidget extends ViewWidget implements Update { // TODO make of widget type
|
||||
private final ProgressBar progressBar;
|
||||
|
||||
private Runnable success = () -> {};
|
||||
private Runnable failure = () -> {};
|
||||
private int maxAmount;
|
||||
private int amount;
|
||||
private float percentage = 0.0f;
|
||||
|
||||
|
||||
public LoadingWidget(int startAmount, int maxAmount) {
|
||||
|
||||
amount = startAmount;
|
||||
this.maxAmount = maxAmount;
|
||||
|
||||
progressBar = new ProgressBar();
|
||||
|
||||
HBox box = new HBox(10, progressBar);
|
||||
add(Pos.CENTER, box);
|
||||
}
|
||||
|
||||
public void setMaxAmount(int maxAmount) {
|
||||
this.maxAmount = maxAmount;
|
||||
}
|
||||
|
||||
public void setAmount(int amount) {
|
||||
this.amount = amount;
|
||||
update();
|
||||
}
|
||||
|
||||
public void setAmount() {
|
||||
setAmount(this.amount+1);
|
||||
}
|
||||
|
||||
public void setOnSuccess(Runnable onSuccess) {
|
||||
success = onSuccess;
|
||||
}
|
||||
|
||||
public void setOnFailure(Runnable onFailure) {
|
||||
failure = onFailure;
|
||||
}
|
||||
|
||||
public void triggerSuccess() {
|
||||
success.run();
|
||||
}
|
||||
|
||||
public void triggerFailure() {
|
||||
failure.run();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
if (amount >= maxAmount) {
|
||||
triggerSuccess();
|
||||
System.out.println("triggered");
|
||||
this.hide();
|
||||
return;
|
||||
} else if (amount < 0) {
|
||||
triggerFailure();
|
||||
System.out.println("triggerFailure");
|
||||
this.hide();
|
||||
return;
|
||||
}
|
||||
|
||||
percentage = (float) amount / maxAmount;
|
||||
progressBar.setProgress(percentage);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package org.toop.app.widget.complex;
|
||||
|
||||
public interface Update {
|
||||
void update();
|
||||
}
|
||||
@@ -22,7 +22,7 @@ public class SongDisplay extends VBox implements Widget {
|
||||
|
||||
public SongDisplay() {
|
||||
new EventFlow()
|
||||
.listen(this::updateTheSong);
|
||||
.listen(AudioEvents.PlayingMusic.class, this::updateTheSong, false);
|
||||
|
||||
setAlignment(Pos.CENTER);
|
||||
setMaxHeight(Region.USE_PREF_SIZE);
|
||||
|
||||
Reference in New Issue
Block a user