395 lines
16 KiB
HTML
395 lines
16 KiB
HTML
|
|
|
|
|
|
<!DOCTYPE html>
|
|
<html id="htmlId">
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
|
|
<title>Coverage Report > GUI</title>
|
|
<style type="text/css">
|
|
@import "../../css/coverage.css";
|
|
@import "../../css/idea.min.css";
|
|
</style>
|
|
<script type="text/javascript" src="../../js/highlight.min.js"></script>
|
|
<script type="text/javascript" src="../../js/highlightjs-line-numbers.min.js"></script>
|
|
</head>
|
|
|
|
<body>
|
|
<div class="content">
|
|
<div class="breadCrumbs">
|
|
Current scope: <a href="../../index.html">all classes</a>
|
|
<span class="separator">|</span>
|
|
<a href="../index.html">it.polimi.ingsw.gc14.View.GUI</a>
|
|
</div>
|
|
|
|
<h1>Coverage Summary for Class: GUI (it.polimi.ingsw.gc14.View.GUI)</h1>
|
|
|
|
<table class="coverageStats">
|
|
<tr>
|
|
<th class="name">Class</th>
|
|
<th class="coverageStat
|
|
">
|
|
Class, %
|
|
</th>
|
|
<th class="coverageStat
|
|
">
|
|
Method, %
|
|
</th>
|
|
<th class="coverageStat
|
|
">
|
|
Branch, %
|
|
</th>
|
|
<th class="coverageStat
|
|
">
|
|
Line, %
|
|
</th>
|
|
</tr>
|
|
<tr>
|
|
<td class="name">GUI</td>
|
|
<td class="coverageStat">
|
|
<span class="percent">
|
|
0%
|
|
</span>
|
|
<span class="absValue">
|
|
(0/1)
|
|
</span>
|
|
</td>
|
|
<td class="coverageStat">
|
|
<span class="percent">
|
|
0%
|
|
</span>
|
|
<span class="absValue">
|
|
(0/16)
|
|
</span>
|
|
</td>
|
|
<td class="coverageStat">
|
|
<span class="percent">
|
|
0%
|
|
</span>
|
|
<span class="absValue">
|
|
(0/22)
|
|
</span>
|
|
</td>
|
|
<td class="coverageStat">
|
|
<span class="percent">
|
|
0%
|
|
</span>
|
|
<span class="absValue">
|
|
(0/110)
|
|
</span>
|
|
</td>
|
|
</tr>
|
|
|
|
</table>
|
|
|
|
<br/>
|
|
<br/>
|
|
|
|
|
|
<pre>
|
|
<code class="sourceCode" id="sourceCode"> package it.polimi.ingsw.gc14.View.GUI;
|
|
|
|
import it.polimi.ingsw.gc14.Controller.ClientController;
|
|
import it.polimi.ingsw.gc14.ErrorType;
|
|
import it.polimi.ingsw.gc14.Model.MiniModel;
|
|
import it.polimi.ingsw.gc14.View.IView;
|
|
import javafx.animation.FadeTransition;
|
|
import javafx.application.Application;
|
|
import javafx.application.Platform;
|
|
import javafx.fxml.FXMLLoader;
|
|
import javafx.geometry.Rectangle2D;
|
|
import javafx.scene.Parent;
|
|
import javafx.scene.Scene;
|
|
import javafx.scene.input.KeyCode;
|
|
import javafx.scene.input.KeyEvent;
|
|
import javafx.scene.input.KeyCombination;
|
|
import javafx.scene.layout.StackPane;
|
|
|
|
import javafx.scene.paint.Color;
|
|
import javafx.scene.shape.Rectangle;
|
|
import javafx.stage.Screen;
|
|
import javafx.stage.Stage;
|
|
import javafx.util.Duration;
|
|
|
|
import static it.polimi.ingsw.gc14.Model.GamePackage.GameStages.ENDED;
|
|
import static it.polimi.ingsw.gc14.Model.GamePackage.GameStages.TOTEM_CHOICE;
|
|
|
|
/**
|
|
* JavaFX-based GUI implementation of {@link it.polimi.ingsw.gc14.View.IView IView}.
|
|
*
|
|
* <p>Manages the primary stage and switches between the login, totem choice,
|
|
* main game, and leaderboard scenes based on the current game state.
|
|
*/
|
|
<b class="nc"> public class GUI extends Application implements IView {</b>
|
|
/** The primary JavaFX stage. */
|
|
private Stage primaryStage;
|
|
/** Latest mini model received from the server. */
|
|
private volatile MiniModel miniModel;
|
|
/** FXML loader for the login scene. */
|
|
private FXMLLoader loaderLogin;
|
|
/** The login scene. */
|
|
private Scene loginScene;
|
|
/** Controller for the login FXML scene. */
|
|
private LoginFXMLController controllerLogin;
|
|
/** FXML loader for the totem selection scene. */
|
|
private FXMLLoader loaderTotem;
|
|
/** The totem selection scene. */
|
|
private Scene totemScene;
|
|
/** Controller for the totem FXML scene. */
|
|
private TotemFXMLController controllerTotem;
|
|
/** FXML loader for the main game scene. */
|
|
private FXMLLoader loaderMain;
|
|
/** The main game scene. */
|
|
private Scene mainScene;
|
|
/** Controller for the main FXML scene. */
|
|
private MainFXMLController controllerMain;
|
|
/** FXML loader for the leaderboard scene. */
|
|
private FXMLLoader loaderLeaderboard;
|
|
/** The end-of-game leaderboard scene. */
|
|
private Scene leaderboardScene;
|
|
/** Controller for the leaderboard FXML scene. */
|
|
private LeaderboardFXMLController controllerLeaderboard;
|
|
/** Client controller injected before JavaFX startup. */
|
|
private ClientController controller;
|
|
/** When {@code true}, the app re-enters fullscreen automatically after ESC is pressed. */
|
|
<b class="nc"> private boolean autoReenterFullscreen = true;</b>
|
|
/** Guards against overlapping fade transitions. */
|
|
<b class="nc"> private boolean isFading = false;</b>
|
|
|
|
|
|
/**
|
|
* JavaFX entry point: loads all FXML scenes, wires up controllers,
|
|
* configures fullscreen behavior, and shows the login scene.
|
|
*
|
|
* @param stage the primary stage provided by the JavaFX runtime.
|
|
* @throws Exception if any FXML resource cannot be loaded.
|
|
*/
|
|
@Override
|
|
public void start(Stage stage) throws Exception {
|
|
<b class="nc"> this.primaryStage = stage;</b>
|
|
<b class="nc"> loaderLogin = new FXMLLoader(getClass().getResource("/GUIScene/login.fxml"));</b>
|
|
<b class="nc"> loginScene = new Scene(loaderLogin.load());</b>
|
|
<b class="nc"> controllerLogin = loaderLogin.getController();</b>
|
|
<b class="nc"> controllerLogin.setController(controller);</b>
|
|
|
|
|
|
<b class="nc"> loaderTotem = new FXMLLoader(getClass().getResource("/GUIScene/totem.fxml"));</b>
|
|
<b class="nc"> totemScene = new Scene(loaderTotem.load());</b>
|
|
<b class="nc"> controllerTotem = loaderTotem.getController();</b>
|
|
<b class="nc"> controllerTotem.setController(controller);</b>
|
|
|
|
|
|
<b class="nc"> loaderMain = new FXMLLoader(getClass().getResource("/GUIScene/main.fxml"));</b>
|
|
<b class="nc"> mainScene = new Scene(loaderMain.load());</b>
|
|
<b class="nc"> controllerMain = loaderMain.getController();</b>
|
|
<b class="nc"> controllerMain.setController(controller);</b>
|
|
|
|
<b class="nc"> loaderLeaderboard = new FXMLLoader(getClass().getResource("/GUIScene/standing.fxml"));</b>
|
|
<b class="nc"> leaderboardScene = new Scene(loaderLeaderboard.load());</b>
|
|
<b class="nc"> controllerLeaderboard = loaderLeaderboard.getController();</b>
|
|
<b class="nc"> controllerLeaderboard.setController(controller, () -> {</b>
|
|
<b class="nc"> controllerLogin.updateLoginButton(true);</b>
|
|
<b class="nc"> controllerLogin.showError("");</b>
|
|
<b class="nc"> fadeToScene(loginScene);</b>
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
<b class="nc"> wrapScene(loginScene);</b>
|
|
<b class="nc"> wrapScene(totemScene);</b>
|
|
<b class="nc"> wrapScene(mainScene);</b>
|
|
<b class="nc"> wrapScene(leaderboardScene);</b>
|
|
|
|
<b class="nc"> FireParticleSystem fireParticles = new FireParticleSystem(mainScene);</b>
|
|
<b class="nc"> ((StackPane) mainScene.getRoot()).getChildren().add(fireParticles.getPane());</b>
|
|
<b class="nc"> fireParticles.start();</b>
|
|
|
|
<b class="nc"> primaryStage.setScene(loginScene);</b>
|
|
<b class="nc"> Rectangle2D tmp = Screen.getPrimary().getVisualBounds();</b>
|
|
<b class="nc"> primaryStage.setWidth(tmp.getWidth());</b>
|
|
<b class="nc"> primaryStage.setHeight(tmp.getHeight());</b>
|
|
<b class="nc"> primaryStage.setX(tmp.getMinX());</b>
|
|
<b class="nc"> primaryStage.setY(tmp.getMinY());</b>
|
|
<b class="nc"> primaryStage.setResizable(false);</b>
|
|
<b class="nc"> primaryStage.setFullScreenExitHint("");</b>
|
|
<b class="nc"> primaryStage.setFullScreenExitKeyCombination(KeyCombination.NO_MATCH);</b>
|
|
|
|
<b class="nc"> primaryStage.fullScreenProperty().addListener((obs, was, isNow) -> {</b>
|
|
<b class="nc"> if (!isNow && autoReenterFullscreen) {</b>
|
|
<b class="nc"> Platform.runLater(() -> primaryStage.setFullScreen(true));</b>
|
|
}
|
|
});
|
|
|
|
<b class="nc"> primaryStage.addEventFilter(KeyEvent.KEY_PRESSED, e -> {</b>
|
|
<b class="nc"> if (e.getCode() == KeyCode.ESCAPE) {</b>
|
|
<b class="nc"> autoReenterFullscreen = false;</b>
|
|
<b class="nc"> primaryStage.setFullScreen(false);</b>
|
|
<b class="nc"> e.consume();</b>
|
|
<b class="nc"> } else if (e.getCode() == KeyCode.F11) {</b>
|
|
<b class="nc"> autoReenterFullscreen = true;</b>
|
|
<b class="nc"> primaryStage.setFullScreen(true);</b>
|
|
<b class="nc"> e.consume();</b>
|
|
}
|
|
});
|
|
|
|
<b class="nc"> primaryStage.setTitle("Mesos");</b>
|
|
<b class="nc"> primaryStage.setOnCloseRequest(e -> {</b>
|
|
<b class="nc"> Platform.exit();</b>
|
|
<b class="nc"> System.exit(0);</b>
|
|
});
|
|
<b class="nc"> primaryStage.show();</b>
|
|
<b class="nc"> Platform.runLater(() -> primaryStage.setFullScreen(true));</b>
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
* Updates the local mini model reference used by the GUI.
|
|
*
|
|
* @param miniModel the latest mini model received from the server.
|
|
*/
|
|
@Override
|
|
public void setModel(MiniModel miniModel) {
|
|
<b class="nc"> this.miniModel = miniModel;</b>
|
|
}
|
|
|
|
/**
|
|
* Injects the client controller into this GUI.
|
|
*
|
|
* @param controller the client controller to use.
|
|
*/
|
|
public void setController(ClientController controller) {
|
|
<b class="nc"> this.controller=controller;</b>
|
|
}
|
|
|
|
/**
|
|
* Re-renders the GUI on the JavaFX application thread, switching to the
|
|
* appropriate scene based on the current game stage.
|
|
*/
|
|
public void render() {
|
|
<b class="nc"> Platform.runLater(() -> {</b>
|
|
<b class="nc"> if (miniModel == null) return;</b>
|
|
<b class="nc"> if (controller.getMiniModel().currentState.getGameStage() == TOTEM_CHOICE) {</b>
|
|
<b class="nc"> controllerTotem.render();</b>
|
|
<b class="nc"> fadeToScene(totemScene);</b>
|
|
<b class="nc"> } else if (controller.getMiniModel().currentState.getGameStage() == ENDED) {</b>
|
|
<b class="nc"> controllerLeaderboard.render();</b>
|
|
<b class="nc"> fadeToScene(leaderboardScene);</b>
|
|
} else {
|
|
<b class="nc"> controllerMain.render();</b>
|
|
<b class="nc"> fadeToScene(mainScene);</b>
|
|
}
|
|
});
|
|
}
|
|
/**
|
|
* Wraps the current root of {@code scene} in a {@link StackPane} so that
|
|
* fade overlay rectangles can be layered over it during scene transitions.
|
|
*
|
|
* @param scene the scene whose root to wrap.
|
|
*/
|
|
private void wrapScene(Scene scene) {
|
|
<b class="nc"> Parent root = scene.getRoot();</b>
|
|
<b class="nc"> scene.setRoot(new StackPane(root));</b>
|
|
}
|
|
/**
|
|
* Performs a black-overlay crossfade from the current scene to {@code newScene}.
|
|
* No-op if already fading or if {@code newScene} is already displayed.
|
|
*
|
|
* @param newScene the scene to transition to.
|
|
*/
|
|
private void fadeToScene(Scene newScene) {
|
|
<b class="nc"> Scene currentScene = primaryStage.getScene();</b>
|
|
<b class="nc"> if (currentScene == newScene || isFading) return;</b>
|
|
<b class="nc"> isFading = true;</b>
|
|
|
|
<b class="nc"> StackPane currentRoot = (StackPane) currentScene.getRoot();</b>
|
|
<b class="nc"> Rectangle overlay = new Rectangle();</b>
|
|
<b class="nc"> overlay.setFill(Color.BLACK);</b>
|
|
<b class="nc"> overlay.setOpacity(0);</b>
|
|
<b class="nc"> overlay.widthProperty().bind(currentRoot.widthProperty());</b>
|
|
<b class="nc"> overlay.heightProperty().bind(currentRoot.heightProperty());</b>
|
|
<b class="nc"> currentRoot.getChildren().add(overlay);</b>
|
|
|
|
<b class="nc"> FadeTransition fadeOut = new FadeTransition(Duration.millis(500), overlay);</b>
|
|
<b class="nc"> fadeOut.setFromValue(0);</b>
|
|
<b class="nc"> fadeOut.setToValue(1);</b>
|
|
<b class="nc"> fadeOut.setOnFinished(e -> {</b>
|
|
<b class="nc"> currentRoot.getChildren().remove(overlay);</b>
|
|
|
|
<b class="nc"> StackPane newRoot = (StackPane) newScene.getRoot();</b>
|
|
<b class="nc"> Rectangle newOverlay = new Rectangle();</b>
|
|
<b class="nc"> newOverlay.setFill(Color.BLACK);</b>
|
|
<b class="nc"> newOverlay.setOpacity(1);</b>
|
|
<b class="nc"> newOverlay.widthProperty().bind(newRoot.widthProperty());</b>
|
|
<b class="nc"> newOverlay.heightProperty().bind(newRoot.heightProperty());</b>
|
|
<b class="nc"> newRoot.getChildren().add(newOverlay);</b>
|
|
|
|
<b class="nc"> primaryStage.setScene(newScene);</b>
|
|
|
|
<b class="nc"> FadeTransition fadeIn = new FadeTransition(Duration.millis(500), newOverlay);</b>
|
|
<b class="nc"> fadeIn.setFromValue(1);</b>
|
|
<b class="nc"> fadeIn.setToValue(0);</b>
|
|
<b class="nc"> fadeIn.setOnFinished(ev -> {</b>
|
|
<b class="nc"> newRoot.getChildren().remove(newOverlay);</b>
|
|
<b class="nc"> isFading = false;</b>
|
|
});
|
|
<b class="nc"> fadeIn.play();</b>
|
|
});
|
|
<b class="nc"> fadeOut.play();</b>
|
|
}
|
|
|
|
/**
|
|
* Displays an error on the JavaFX application thread.
|
|
*
|
|
* <p>If the server crashed, returns to the login scene and re-enables the login button.
|
|
* Otherwise, delegates to the active scene's error display.
|
|
*
|
|
* @param error the error type.
|
|
* @param message a human-readable description of the error.
|
|
*/
|
|
@Override
|
|
public void showError(ErrorType error,String message) {
|
|
<b class="nc"> Platform.runLater(() -> {</b>
|
|
<b class="nc"> if (error == ErrorType.SERVER_CRASHED) {</b>
|
|
<b class="nc"> controllerLogin.updateLoginButton(true);</b>
|
|
<b class="nc"> controllerLogin.showError(error);</b>
|
|
<b class="nc"> fadeToScene(loginScene);</b>
|
|
} else {
|
|
<b class="nc"> if (miniModel == null) return;</b>
|
|
<b class="nc"> controllerMain.setError(true);</b>
|
|
<b class="nc"> controllerMain.render();</b>
|
|
}
|
|
});
|
|
}
|
|
|
|
}
|
|
</code>
|
|
</pre>
|
|
</div>
|
|
|
|
<script type="text/javascript">
|
|
(function() {
|
|
var msie = false, msie9 = false;
|
|
/*@cc_on
|
|
msie = true;
|
|
@if (@_jscript_version >= 9)
|
|
msie9 = true;
|
|
@end
|
|
@*/
|
|
|
|
if (!msie || msie && msie9) {
|
|
hljs.highlightAll()
|
|
hljs.initLineNumbersOnLoad();
|
|
}
|
|
})();
|
|
</script>
|
|
|
|
<div class="footer">
|
|
|
|
<div style="float:right;">generated on 2026-06-19 22:53</div>
|
|
</div>
|
|
</body>
|
|
</html>
|