Initial refactor of GUI
This commit is contained in:
@@ -5,6 +5,7 @@ import it.polimi.ingsw.gc14.Model.Game;
|
||||
import it.polimi.ingsw.gc14.Model.MiniModel;
|
||||
import it.polimi.ingsw.gc14.Network.NetworkEvent;
|
||||
import it.polimi.ingsw.gc14.Network.RMI.Common.IClientCallback;
|
||||
import javafx.application.Platform;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.rmi.RemoteException;
|
||||
@@ -39,8 +40,10 @@ public class ClientCallbackImpl extends UnicastRemoteObject implements IClientCa
|
||||
*/
|
||||
@Override
|
||||
public void onGameInit(MiniModel model) throws RemoteException {
|
||||
Platform.runLater(() -> {
|
||||
clientController.setModel(model);
|
||||
clientController.view.render();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -57,7 +60,10 @@ public class ClientCallbackImpl extends UnicastRemoteObject implements IClientCa
|
||||
if(event.getIsError()) {
|
||||
clientController.view.showError(event.toString());
|
||||
} else {
|
||||
clientController.view.applyAndRender(event);
|
||||
Platform.runLater(() -> {
|
||||
event.apply(clientController.miniModel);
|
||||
clientController.view.render();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import it.polimi.ingsw.gc14.Model.MiniModel;
|
||||
import it.polimi.ingsw.gc14.Network.IClient;
|
||||
import it.polimi.ingsw.gc14.Network.NetworkEvent;
|
||||
import it.polimi.ingsw.gc14.Network.NetworkEvents.*;
|
||||
import javafx.application.Platform;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.*;
|
||||
@@ -163,14 +164,17 @@ public class TCPClient implements IClient {
|
||||
if (event.getIsError()) {
|
||||
controller.view.showError(event.toString());
|
||||
} else {
|
||||
controller.view.applyAndRender(event);
|
||||
Platform.runLater(() -> {
|
||||
event.apply(controller.miniModel);
|
||||
controller.view.render();
|
||||
});
|
||||
}
|
||||
|
||||
} else if (read instanceof MiniModel model) {
|
||||
synchronized (controller) {
|
||||
Platform.runLater(() -> {
|
||||
controller.setModel(model);
|
||||
controller.view.render();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
} catch (ClassNotFoundException e) {
|
||||
|
||||
@@ -109,25 +109,17 @@ public class GUI extends Application implements IView {
|
||||
|
||||
public void applyAndRender(NetworkEvent event) {
|
||||
Platform.runLater(() -> {
|
||||
if (event!=null) {
|
||||
event.apply(miniModel);
|
||||
}
|
||||
if (controller.miniModel.currentState.getGameStage() == TOTEM_CHOICE) {
|
||||
primaryStage.setScene(totemScene);
|
||||
controllerTotem.render();
|
||||
} else if (controller.miniModel.currentState.getGameStage() == GameStages.ENDED) {
|
||||
boolean sceneChange = primaryStage.getScene() != leaderboardScene;
|
||||
primaryStage.setScene(leaderboardScene);
|
||||
if (sceneChange) {
|
||||
primaryStage.setMaximized(false);
|
||||
Platform.runLater(() -> primaryStage.setMaximized(true));
|
||||
}
|
||||
controllerLeaderboard.render();
|
||||
} else {
|
||||
boolean sceneChange = primaryStage.getScene() != mainScene; // ← era un'altra scena?
|
||||
primaryStage.setScene(mainScene);
|
||||
if (sceneChange) {
|
||||
primaryStage.setMaximized(false);
|
||||
Platform.runLater(() -> primaryStage.setMaximized(true));
|
||||
}
|
||||
controllerMain.render(event);
|
||||
controllerMain.initPopup(mainScene);
|
||||
}
|
||||
@@ -135,10 +127,6 @@ public class GUI extends Application implements IView {
|
||||
}
|
||||
|
||||
public void render() {
|
||||
if (!Platform.isFxApplicationThread()) {
|
||||
Platform.runLater(this::render);
|
||||
return;
|
||||
}
|
||||
if (controller.miniModel.currentState.getGameStage() == TOTEM_CHOICE) {
|
||||
primaryStage.setScene(totemScene);
|
||||
controllerTotem.render();
|
||||
@@ -147,6 +135,7 @@ public class GUI extends Application implements IView {
|
||||
controllerLeaderboard.render();
|
||||
}else {
|
||||
primaryStage.setScene(mainScene);
|
||||
controllerMain.initPopup(mainScene);
|
||||
controllerMain.render();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,10 +105,6 @@ public class MainFXMLController {
|
||||
|
||||
// ==== RENDER ====
|
||||
public void render() {
|
||||
if (mainHBox.getWidth() == 0 || mainHBox.getHeight() == 0) {
|
||||
Platform.runLater(() -> render());
|
||||
return;
|
||||
}
|
||||
renderUpper();
|
||||
renderBoard();
|
||||
renderLower();
|
||||
|
||||
@@ -7,7 +7,6 @@ import it.polimi.ingsw.gc14.Network.NetworkEvent;
|
||||
public interface IView {
|
||||
public void setModel(MiniModel miniModel);
|
||||
public void render();
|
||||
public void applyAndRender(NetworkEvent event);
|
||||
public void showMessage(String message);
|
||||
public void showError(String message);
|
||||
|
||||
|
||||
@@ -59,10 +59,6 @@ public class TUI implements IView {
|
||||
this.model = model;
|
||||
this.username = "";
|
||||
}
|
||||
public void applyAndRender(NetworkEvent event) {
|
||||
event.apply(model);
|
||||
render();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the username of the local player.
|
||||
|
||||
Reference in New Issue
Block a user