Feat/game-ui #182
@@ -1,13 +1,13 @@
|
||||
package ch.unibas.dmi.dbis.cs108.casono.client.ui.chatui;
|
||||
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.TextField;
|
||||
import javafx.scene.layout.VBox;
|
||||
import javafx.scene.control.Label;
|
||||
import java.time.LocalTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.ScrollPane;
|
||||
import javafx.scene.control.TextField;
|
||||
import javafx.scene.layout.VBox;
|
||||
|
||||
/**
|
||||
* Controller-Klasse für das Chat-System innerhalb der Spieloberfläche.
|
||||
@@ -39,6 +39,8 @@ public class ChatController {
|
||||
@FXML
|
||||
private ScrollPane chatScrollPane;
|
||||
|
||||
private static final int CHAT_PADDING = 20;
|
||||
|
||||
/**
|
||||
* Initialisiert den ChatController nach dem Laden der FXML.
|
||||
*/
|
||||
@@ -73,7 +75,7 @@ public class ChatController {
|
||||
Label label = new Label("[" + time + "] " + player + ": " + message);
|
||||
label.getStyleClass().add("info-text");
|
||||
label.setWrapText(true); // Zeilenumbruch aktivieren
|
||||
label.maxWidthProperty().bind(chatVBox.widthProperty().subtract(20));
|
||||
label.maxWidthProperty().bind(chatVBox.widthProperty().subtract(CHAT_PADDING));
|
||||
chatVBox.getChildren().add(label);
|
||||
}
|
||||
|
||||
|
||||
+2
-11
@@ -1,18 +1,8 @@
|
||||
package ch.unibas.dmi.dbis.cs108.casono.client.ui.gameui;
|
||||
|
||||
// import javafx.application.Platform;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.Label;
|
||||
// import javafx.scene.control.TextField;
|
||||
// import javafx.scene.input.KeyCode;
|
||||
// import javafx.scene.input.KeyEvent;
|
||||
// import javafx.scene.input.MouseEvent;
|
||||
// import javafx.scene.layout.HBox;
|
||||
// import javafx.scene.layout.AnchorPane;
|
||||
import javafx.scene.layout.VBox;
|
||||
// import javafx.stage.Stage;
|
||||
// import javafx.scene.Scene;
|
||||
// import javafx.scene.web.WebView;
|
||||
|
||||
/**
|
||||
* Controller für die Casino-Spielfläche.
|
||||
@@ -32,7 +22,8 @@ public class CasinoGameController {
|
||||
@FXML private Label welcomeText;
|
||||
@FXML private VBox casinoTable;
|
||||
|
||||
// TODO: Test-Logik: wird durch echte Spielinteraktionen ersetzt, sobald die GameEngine fertig ist
|
||||
// TODO: Test-Logik: wird durch echte Spielinteraktionen ersetzt,
|
||||
// sobald die GameEngine fertig ist
|
||||
@FXML
|
||||
public void onTableClick() {
|
||||
welcomeText.setText("Einsatz akzeptiert!");
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
package ch.unibas.dmi.dbis.cs108.casono.client.ui.gameui;
|
||||
|
||||
import java.io.IOException;
|
||||
import javafx.application.Application;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Hauptklasse für das Casino-Spiel-UI.
|
||||
*
|
||||
@@ -20,6 +19,9 @@ import java.io.IOException;
|
||||
*/
|
||||
public class CasinoGameUI extends Application {
|
||||
|
||||
private static final int DEFAULT_WIDTH = 1200;
|
||||
private static final int DEFAULT_HEIGHT = 800;
|
||||
|
||||
/**
|
||||
* Startet die Haupt-Stage der Anwendung.
|
||||
*
|
||||
@@ -28,11 +30,13 @@ public class CasinoGameUI extends Application {
|
||||
*/
|
||||
@Override
|
||||
public void start(Stage stage) throws IOException {
|
||||
FXMLLoader fxmlLoader = new FXMLLoader(CasinoGameUI.class.getResource("/ui-structure/casinogameui.fxml"));
|
||||
Scene scene = new Scene(fxmlLoader.load(), 1200, 800);
|
||||
FXMLLoader fxmlLoader =
|
||||
new FXMLLoader(CasinoGameUI.class.getResource("/ui-structure/casinogameui.fxml"));
|
||||
Scene scene = new Scene(fxmlLoader.load(), DEFAULT_WIDTH, DEFAULT_HEIGHT);
|
||||
stage.setTitle("Casono (GAME)");
|
||||
|
||||
stage.getIcons().add(new javafx.scene.image.Image(getClass().getResource("/images/logoinverted.png").toExternalForm()));
|
||||
String iconPath = getClass().getResource("/images/logoinverted.png").toExternalForm();
|
||||
stage.getIcons().add(new javafx.scene.image.Image(iconPath));
|
||||
stage.setScene(scene);
|
||||
stage.setFullScreen(true);
|
||||
stage.show();
|
||||
|
||||
+370
-190
@@ -1,23 +1,33 @@
|
||||
package ch.unibas.dmi.dbis.cs108.casono.client.ui.gameui.gameuicomponents;
|
||||
|
||||
import java.net.CookieHandler;
|
||||
import java.net.CookieManager;
|
||||
import java.net.CookiePolicy;
|
||||
import java.net.URI;
|
||||
import java.util.HashSet;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import javafx.application.Platform;
|
||||
import javafx.geometry.Insets;
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.control.Alert;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.ButtonType;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.TextField;
|
||||
import javafx.scene.image.Image;
|
||||
import javafx.scene.image.ImageView;
|
||||
import javafx.scene.layout.*;
|
||||
import javafx.scene.input.KeyCode;
|
||||
import javafx.scene.layout.HBox;
|
||||
import javafx.scene.layout.Priority;
|
||||
import javafx.scene.layout.StackPane;
|
||||
import javafx.scene.layout.VBox;
|
||||
import javafx.scene.shape.Rectangle;
|
||||
import javafx.scene.web.WebEngine;
|
||||
import javafx.scene.web.WebView;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
import java.net.*;
|
||||
import java.util.HashSet;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Experimenteller integrierter Browser für Casono.
|
||||
*
|
||||
@@ -49,10 +59,27 @@ import java.util.Set;
|
||||
* - Automatische Cookie-Löschung beim Schließen
|
||||
*/
|
||||
public class CasinoBrowserController {
|
||||
|
||||
private static final Set<String> TRUSTED_DOMAINS = new HashSet<>();
|
||||
|
||||
private static final CookieManager COOKIE_MANAGER =
|
||||
new CookieManager(null, CookiePolicy.ACCEPT_ORIGINAL_SERVER);
|
||||
|
||||
private static final org.apache.logging.log4j.Logger LOGGER =
|
||||
org.apache.logging.log4j.LogManager.getLogger(CasinoBrowserController.class);
|
||||
|
||||
private static final int LOGO_HEIGHT = 40;
|
||||
private static final int CORNER_RADIUS = 40;
|
||||
private static final int HBOX_SPACIN = 10;
|
||||
private static final int VBOX_SPACING = 10;
|
||||
private static final int PADDING_SIZE = 10;
|
||||
private static final int WINDOW_WIDTH = 1200;
|
||||
private static final int WINDOW_HEIGHT = 800;
|
||||
private static final int ALERT_WIDTH = 600;
|
||||
private static final int ALERT_HEIGHT = 300;
|
||||
private static final String LOGO_PATH = "/images/logoinverted.png";
|
||||
private static final String LOGO_PATH_MAIN = "/images/logo.png";
|
||||
|
||||
static {
|
||||
CookieHandler.setDefault(COOKIE_MANAGER);
|
||||
|
||||
@@ -104,174 +131,44 @@ public class CasinoBrowserController {
|
||||
|
||||
engine.setJavaScriptEnabled(false);
|
||||
|
||||
// Popup Blocker
|
||||
engine.setCreatePopupHandler(config -> {
|
||||
Alert alert = new Alert(Alert.AlertType.WARNING);
|
||||
alert.setTitle("Popup blockiert");
|
||||
alert.setHeaderText(null);
|
||||
alert.setContentText("Popup wurde aus Sicherheitsgründen blockiert.");
|
||||
|
||||
try {
|
||||
Image logo =
|
||||
new Image(CasinoBrowserController.class.getResourceAsStream("/images/logoinverted.png"));
|
||||
Image logomain =
|
||||
new Image(CasinoBrowserController.class.getResourceAsStream("/images/logo.png"));
|
||||
|
||||
if (logo != null) {
|
||||
Stage alertStage = (Stage) alert.getDialogPane().getScene().getWindow();
|
||||
if (alertStage != null) {
|
||||
alertStage.getIcons().add(logo);
|
||||
}
|
||||
}
|
||||
|
||||
if (logomain != null) {
|
||||
ImageView logoView = new ImageView(logomain);
|
||||
logoView.setFitHeight(40);
|
||||
logoView.setPreserveRatio(true);
|
||||
alert.setGraphic(logoView);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.err.println("Logo konnte nicht geladen werden");
|
||||
}
|
||||
|
||||
alert.showAndWait();
|
||||
return null;
|
||||
});
|
||||
configurePopupBlocker(engine);
|
||||
|
||||
webView.getStyleClass().add("web-view");
|
||||
|
||||
StackPane webContainer = new StackPane(webView);
|
||||
webContainer.getStyleClass().add("browser-web-view");
|
||||
VBox.setVgrow(webContainer, Priority.ALWAYS);
|
||||
StackPane webContainer = createWebContainer(webView);
|
||||
|
||||
Rectangle clip = new Rectangle();
|
||||
clip.setArcWidth(40);
|
||||
clip.setArcHeight(40);
|
||||
clip.setArcWidth(CORNER_RADIUS);
|
||||
clip.setArcHeight(CORNER_RADIUS);
|
||||
webView.setClip(clip);
|
||||
|
||||
webView.widthProperty().addListener((o,a,b)->clip.setWidth(b.doubleValue()));
|
||||
webView.heightProperty().addListener((o,a,b)->clip.setHeight(b.doubleValue()));
|
||||
webView.widthProperty().addListener((o, a, b) ->
|
||||
clip.setWidth(b.doubleValue()));
|
||||
webView.heightProperty().addListener((o, a, b) ->
|
||||
clip.setHeight(b.doubleValue()));
|
||||
|
||||
ImageView browserLogo = new ImageView();
|
||||
ImageView browserLogo = loadLogos(stage);
|
||||
|
||||
try {
|
||||
Image logo =
|
||||
new Image(CasinoBrowserController.class.getResourceAsStream("/images/logoinverted.png"));
|
||||
Image logomain =
|
||||
new Image(CasinoBrowserController.class.getResourceAsStream("/images/logo.png"));
|
||||
TextField urlField = createUrlField(url);
|
||||
Label securityLabel = createSecurityLabel();
|
||||
|
||||
if (logo != null) {
|
||||
stage.getIcons().add(logo);
|
||||
}
|
||||
Button jsToggle = createJsToggle(engine);
|
||||
Button backBtn = createBackButton(engine);
|
||||
Button fwdBtn = createForwardButton(engine);
|
||||
Button reloadBtn = createReloadButton(engine);
|
||||
Button closeBtn = createCloseButton(stage, webView);
|
||||
configureUrlEvents(engine, urlField, securityLabel);
|
||||
|
||||
if (logomain != null) {
|
||||
browserLogo.setImage(logomain);
|
||||
browserLogo.setFitHeight(30);
|
||||
browserLogo.setPreserveRatio(true);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.err.println("Logo konnte nicht geladen werden");
|
||||
}
|
||||
|
||||
// URL Feld
|
||||
TextField urlField = new TextField(url);
|
||||
urlField.getStyleClass().add("gray-input-field");
|
||||
HBox.setHgrow(urlField, Priority.ALWAYS);
|
||||
|
||||
Label securityLabel = new Label("SICHER");
|
||||
securityLabel.getStyleClass().add("security-label");
|
||||
|
||||
// JS Toggle
|
||||
Button jsToggle = new Button("JS EINSCHALTEN");
|
||||
jsToggle.getStyleClass().add("red-button");
|
||||
|
||||
jsToggle.setOnAction(e -> {
|
||||
javascriptEnabled = !javascriptEnabled;
|
||||
engine.setJavaScriptEnabled(javascriptEnabled);
|
||||
|
||||
if (javascriptEnabled) {
|
||||
jsToggle.setText("JS AUSSCHALTEN");
|
||||
jsToggle.getStyleClass().removeAll("red-button");
|
||||
jsToggle.getStyleClass().add("yellow-button");
|
||||
|
||||
} else {
|
||||
jsToggle.setText("JS EINSCHALTEN");
|
||||
jsToggle.getStyleClass().removeAll("yellow-button");
|
||||
jsToggle.getStyleClass().add("red-button");
|
||||
}
|
||||
});
|
||||
|
||||
// Navigation
|
||||
Button backBtn = new Button("<");
|
||||
backBtn.getStyleClass().add("gray-button");
|
||||
backBtn.setOnAction(e -> {
|
||||
if(engine.getHistory().getCurrentIndex() > 0){
|
||||
engine.getHistory().go(-1);
|
||||
}
|
||||
});
|
||||
|
||||
Button fwdBtn = new Button(">");
|
||||
fwdBtn.getStyleClass().add("gray-button");
|
||||
fwdBtn.setOnAction(e -> {
|
||||
if(engine.getHistory().getCurrentIndex() <
|
||||
engine.getHistory().getEntries().size()-1){
|
||||
engine.getHistory().go(1);
|
||||
}
|
||||
});
|
||||
|
||||
// Reload Button
|
||||
Button reloadBtn = new Button("⟳");
|
||||
reloadBtn.getStyleClass().add("gray-button");
|
||||
reloadBtn.setOnAction(e -> engine.reload());
|
||||
|
||||
// Close
|
||||
Button closeBtn = new Button("X");
|
||||
closeBtn.getStyleClass().add("red-button");
|
||||
closeBtn.setOnAction(e -> {
|
||||
webView.getEngine().load("about:blank");
|
||||
clearCookies();
|
||||
stage.close();
|
||||
|
||||
});
|
||||
|
||||
// URL Enter
|
||||
urlField.setOnAction(e ->
|
||||
loadUrlSafely(engine, urlField.getText(), securityLabel));
|
||||
engine.locationProperty().addListener((obs,o,n)->urlField.setText(n));
|
||||
|
||||
// Taskbar
|
||||
HBox taskbar = new HBox(
|
||||
10,
|
||||
browserLogo,
|
||||
backBtn,
|
||||
fwdBtn,
|
||||
reloadBtn,
|
||||
urlField,
|
||||
jsToggle,
|
||||
securityLabel,
|
||||
closeBtn
|
||||
HBox taskbar = new HBox(HBOX_SPACIN, browserLogo, backBtn, fwdBtn,
|
||||
reloadBtn, urlField, jsToggle, securityLabel, closeBtn
|
||||
);
|
||||
|
||||
taskbar.getStyleClass().add("taskbar-browser");
|
||||
taskbar.setAlignment(Pos.CENTER_LEFT);
|
||||
|
||||
// Root
|
||||
VBox root = new VBox(10, taskbar, webContainer);
|
||||
root.getStyleClass().add("browser-root");
|
||||
root.setPadding(new Insets(10));
|
||||
Scene scene = new Scene(root,1200,800);
|
||||
var css = CasinoBrowserController.class.getResource("/ui-structure/casinogameui.css");
|
||||
Scene scene = createScene(taskbar, webContainer);
|
||||
|
||||
if(css != null) {
|
||||
scene.getStylesheets().add(css.toExternalForm());
|
||||
}
|
||||
|
||||
// F5 Reload
|
||||
scene.setOnKeyPressed(event -> {
|
||||
switch (event.getCode()) {
|
||||
case F5 -> engine.reload();
|
||||
}
|
||||
});
|
||||
configureKeyEvents(scene, engine);
|
||||
|
||||
stage.setScene(scene);
|
||||
stage.setTitle("Casono Browser");
|
||||
@@ -280,6 +177,276 @@ public class CasinoBrowserController {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* WebView Container
|
||||
*
|
||||
* @param webView WebView Inhalt
|
||||
* @return StackPane Container
|
||||
*/
|
||||
public static StackPane createWebContainer(WebView webView) {
|
||||
StackPane webContainer = new StackPane(webView);
|
||||
webContainer.getStyleClass().add("browser-web-view");
|
||||
VBox.setVgrow(webContainer, Priority.ALWAYS);
|
||||
|
||||
return webContainer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Popup Blocker
|
||||
*
|
||||
* @param engine WebEngine nutzen
|
||||
*/
|
||||
public static void configurePopupBlocker(WebEngine engine) {
|
||||
engine.setCreatePopupHandler(config -> {
|
||||
Alert alert = new Alert(Alert.AlertType.WARNING);
|
||||
alert.setTitle("Popup blockiert");
|
||||
alert.setHeaderText(null);
|
||||
alert.setContentText("Popup wurde aus Sicherheitsgründen blockiert.");
|
||||
|
||||
try {
|
||||
var stream = CasinoBrowserController.class.getResourceAsStream(LOGO_PATH);
|
||||
Image logo = new Image(stream);
|
||||
|
||||
// Variable 'streamM' abgekürzt, um das 100-Zeichen-Limit (LineLength)
|
||||
// einzuhalten
|
||||
var streamM = CasinoBrowserController.class.getResourceAsStream(LOGO_PATH_MAIN);
|
||||
Image logomain = new Image(streamM);
|
||||
|
||||
if (logo != null) {
|
||||
Stage alertStage = (Stage) alert.getDialogPane().getScene().getWindow();
|
||||
if (alertStage != null) {
|
||||
alertStage.getIcons().add(logo);
|
||||
}
|
||||
}
|
||||
|
||||
if (logomain != null) {
|
||||
ImageView logoView = new ImageView(logomain);
|
||||
logoView.setFitHeight(LOGO_HEIGHT);
|
||||
logoView.setPreserveRatio(true);
|
||||
alert.setGraphic(logoView);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("Logo konnte nicht geladen werden");
|
||||
}
|
||||
|
||||
alert.showAndWait();
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Logos laden
|
||||
*
|
||||
* @param stage Fenster Stage
|
||||
* @return ImageView Logo
|
||||
*/
|
||||
private static ImageView loadLogos(Stage stage) {
|
||||
ImageView browserLogo = new ImageView();
|
||||
|
||||
try {
|
||||
var stream = CasinoBrowserController.class.getResourceAsStream(LOGO_PATH);
|
||||
Image logo = new Image(stream);
|
||||
|
||||
// Variable 'streamM' abgekürzt, um das 100-Zeichen-Limit (LineLength)
|
||||
// einzuhalten
|
||||
var streamM = CasinoBrowserController.class.getResourceAsStream(LOGO_PATH_MAIN);
|
||||
Image logomain = new Image(streamM);
|
||||
|
||||
if (logo != null) {
|
||||
stage.getIcons().add(logo);
|
||||
}
|
||||
|
||||
if (logomain != null) {
|
||||
browserLogo.setImage(logomain);
|
||||
browserLogo.setFitHeight(LOGO_HEIGHT);
|
||||
browserLogo.setPreserveRatio(true);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("Logo konnte nicht geladen werden");
|
||||
}
|
||||
|
||||
return browserLogo;
|
||||
}
|
||||
|
||||
/**
|
||||
* URL Feld
|
||||
*
|
||||
* @param url Start URL
|
||||
* @return TextField Eingabe
|
||||
*/
|
||||
public static TextField createUrlField(String url) {
|
||||
TextField urlField = new TextField(url);
|
||||
urlField.getStyleClass().add("gray-input-field");
|
||||
HBox.setHgrow(urlField, Priority.ALWAYS);
|
||||
|
||||
return urlField;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sicherheits Label
|
||||
*
|
||||
* @return Label Anzeige
|
||||
*/
|
||||
public static Label createSecurityLabel() {
|
||||
Label securityLabel = new Label("SICHER");
|
||||
securityLabel.getStyleClass().add("security-label");
|
||||
|
||||
return securityLabel;
|
||||
}
|
||||
|
||||
/**
|
||||
* JS Toggle
|
||||
*
|
||||
* @param engine WebEngine nutzen
|
||||
* @return Button Umschalten
|
||||
*/
|
||||
public static Button createJsToggle(WebEngine engine){
|
||||
Button jsToggle = new Button("JS EINSCHALTEN");
|
||||
jsToggle.getStyleClass().add("red-button");
|
||||
|
||||
jsToggle.setOnAction(e -> {
|
||||
javascriptEnabled = !javascriptEnabled;
|
||||
engine.setJavaScriptEnabled(javascriptEnabled);
|
||||
|
||||
if (javascriptEnabled) {
|
||||
jsToggle.setText("JS AUSSCHALTEN");
|
||||
jsToggle.getStyleClass().removeAll("red-button");
|
||||
jsToggle.getStyleClass().add("yellow-button");
|
||||
|
||||
} else {
|
||||
jsToggle.setText("JS EINSCHALTEN");
|
||||
jsToggle.getStyleClass().removeAll("yellow-button");
|
||||
jsToggle.getStyleClass().add("red-button");
|
||||
}
|
||||
});
|
||||
|
||||
return jsToggle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Zurück Button
|
||||
*
|
||||
* @param engine WebEngine nutzen
|
||||
* @return Button Zurück
|
||||
*/
|
||||
public static Button createBackButton(WebEngine engine) {
|
||||
Button backBtn = new Button("<");
|
||||
backBtn.getStyleClass().add("gray-button");
|
||||
backBtn.setOnAction(e -> {
|
||||
if (engine.getHistory().getCurrentIndex() > 0) {
|
||||
engine.getHistory().go(-1);
|
||||
}
|
||||
});
|
||||
|
||||
return backBtn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Vorwärts Button
|
||||
*
|
||||
* @param engine WebEngine nutzen
|
||||
* @return Button Vorwärts
|
||||
*/
|
||||
public static Button createForwardButton(WebEngine engine) {
|
||||
Button fwdBtn = new Button(">");
|
||||
fwdBtn.getStyleClass().add("gray-button");
|
||||
fwdBtn.setOnAction(e -> {
|
||||
if (engine.getHistory().getCurrentIndex() <
|
||||
engine.getHistory().getEntries().size() - 1) {
|
||||
engine.getHistory().go(1);
|
||||
}
|
||||
});
|
||||
|
||||
return fwdBtn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reload Button
|
||||
*
|
||||
* @param engine WebEngine nutzen
|
||||
* @return Button Reload
|
||||
*/
|
||||
public static Button createReloadButton(WebEngine engine) {
|
||||
Button reloadBtn = new Button("⟳");
|
||||
reloadBtn.getStyleClass().add("gray-button");
|
||||
reloadBtn.setOnAction(e -> engine.reload());
|
||||
return reloadBtn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Close Button
|
||||
*
|
||||
* @param stage Fenster Stage
|
||||
* @param webView WebView Inhalt
|
||||
* @return Button Schließen
|
||||
*/
|
||||
public static Button createCloseButton(Stage stage, WebView webView) {
|
||||
Button closeBtn = new Button("X");
|
||||
closeBtn.getStyleClass().add("red-button");
|
||||
closeBtn.setOnAction(e -> {
|
||||
webView.getEngine().load("about:blank");
|
||||
clearCookies();
|
||||
stage.close();
|
||||
|
||||
});
|
||||
|
||||
return closeBtn;
|
||||
}
|
||||
|
||||
/**
|
||||
* URL Events
|
||||
*
|
||||
* @param engine WebEngine nutzen
|
||||
* @param urlField URL Textfeld
|
||||
* @param securityLabel Sicherheits Label
|
||||
*/
|
||||
public static void configureUrlEvents(WebEngine engine,
|
||||
TextField urlField,
|
||||
Label securityLabel) {
|
||||
urlField.setOnAction(e ->
|
||||
loadUrlSafely(engine, urlField.getText(), securityLabel));
|
||||
engine.locationProperty().addListener((obs, o, n) ->
|
||||
urlField.setText(n));
|
||||
}
|
||||
|
||||
/**
|
||||
* Scene erstellen
|
||||
*
|
||||
* @param taskbar Taskbar HBox
|
||||
* @param webContainer Web Container
|
||||
* @return Scene Fenster
|
||||
*/
|
||||
public static Scene createScene(HBox taskbar, StackPane webContainer) {
|
||||
VBox root = new VBox(VBOX_SPACING, taskbar, webContainer);
|
||||
root.getStyleClass().add("browser-root");
|
||||
root.setPadding(new Insets(PADDING_SIZE));
|
||||
|
||||
Scene scene = new Scene(root, WINDOW_WIDTH, WINDOW_HEIGHT);
|
||||
|
||||
var css = CasinoBrowserController.class
|
||||
.getResource("/ui-structure/casinogameui.css");
|
||||
|
||||
if (css != null) {
|
||||
scene.getStylesheets().add(css.toExternalForm());
|
||||
}
|
||||
|
||||
return scene;
|
||||
}
|
||||
|
||||
/**
|
||||
* Key Events
|
||||
*
|
||||
* @param scene Scene Fenster
|
||||
* @param engine WebEngine nutzen
|
||||
*/
|
||||
public static void configureKeyEvents(Scene scene, WebEngine engine) {
|
||||
scene.setOnKeyPressed(event -> {
|
||||
if (event.getCode() == KeyCode.F5) {
|
||||
engine.reload();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Lädt eine URL in den Browser, nachdem grundlegende Sicherheitsprüfungen
|
||||
* durchgeführt wurden.
|
||||
@@ -299,20 +466,20 @@ public class CasinoBrowserController {
|
||||
*/
|
||||
private static void loadUrlSafely(WebEngine engine, String url, Label securityLabel) {
|
||||
try {
|
||||
if(!url.startsWith("http")) {
|
||||
if (!url.startsWith("http")) {
|
||||
url = "https://" + url;
|
||||
}
|
||||
|
||||
URI uri = new URI(url);
|
||||
|
||||
// HTTPS Pflicht
|
||||
if(!"https".equalsIgnoreCase(uri.getScheme())) {
|
||||
if (!"https".equalsIgnoreCase(uri.getScheme())) {
|
||||
securityLabel.setText("BLOCKIERT");
|
||||
return;
|
||||
}
|
||||
|
||||
String host = uri.getHost();
|
||||
if(host == null) {
|
||||
if (host == null) {
|
||||
securityLabel.setText("ERROR");
|
||||
return;
|
||||
}
|
||||
@@ -321,44 +488,57 @@ public class CasinoBrowserController {
|
||||
boolean trusted = TRUSTED_DOMAINS.stream().anyMatch(domain ->
|
||||
host.equals(domain) || host.endsWith("." + domain));
|
||||
|
||||
if(!trusted) {
|
||||
Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
|
||||
|
||||
alert.setTitle("Unbekannte Website");
|
||||
alert.setHeaderText("Diese Website ist nicht bekannt");
|
||||
alert.setContentText(
|
||||
host + "\n\nDiese Seite ist nicht vom Casono Browser verifiziert.\nMöchten Sie sie trotzdem öffnen?"
|
||||
);
|
||||
|
||||
Image logo = new Image(CasinoBrowserController.class.getResourceAsStream("/images/logoinverted.png"));
|
||||
if (logo != null) {
|
||||
Stage stage = (Stage) alert.getDialogPane().getScene().getWindow();
|
||||
if(stage != null) {
|
||||
stage.getIcons().add(logo);
|
||||
}
|
||||
ImageView logomain = new ImageView(logo);
|
||||
logomain.setFitHeight(50);
|
||||
logomain.setPreserveRatio(true);
|
||||
alert.setGraphic(logomain);
|
||||
}
|
||||
|
||||
alert.getDialogPane().setPrefSize(600,300);
|
||||
Optional<ButtonType> result = alert.showAndWait();
|
||||
|
||||
if(result.isEmpty() || result.get() != ButtonType.OK) {
|
||||
if (!trusted) {
|
||||
if (!showUnknownWebsiteAlert(host)) {
|
||||
securityLabel.setText("BLOCKIERT");
|
||||
return;
|
||||
}
|
||||
|
||||
securityLabel.setText("UNBEKANNT");
|
||||
} else {
|
||||
securityLabel.setText("SICHER");
|
||||
}
|
||||
engine.load(uri.toString());
|
||||
}
|
||||
|
||||
catch (Exception e) {
|
||||
} catch (Exception e) {
|
||||
securityLabel.setText("ERROR");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Zeigt Warnung an.
|
||||
*
|
||||
* @param host Website Host
|
||||
* @return OK gedrückt
|
||||
*/
|
||||
private static boolean showUnknownWebsiteAlert(String host) {
|
||||
Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
|
||||
|
||||
alert.setTitle("Unbekannte Website");
|
||||
alert.setHeaderText("Diese Website ist nicht bekannt");
|
||||
alert.setContentText(
|
||||
host + "\n\nDiese Seite ist nicht vom " +
|
||||
"Casono Browser verifiziert.\nMöchten Sie sie trotzdem öffnen?"
|
||||
);
|
||||
|
||||
var stream = CasinoBrowserController.class.getResourceAsStream(LOGO_PATH);
|
||||
Image logo = new Image(stream);
|
||||
if (logo != null) {
|
||||
Stage stage = (Stage) alert.getDialogPane().getScene().getWindow();
|
||||
if (stage != null) {
|
||||
stage.getIcons().add(logo);
|
||||
}
|
||||
ImageView logomain = new ImageView(logo);
|
||||
logomain.setFitHeight(LOGO_HEIGHT);
|
||||
logomain.setPreserveRatio(true);
|
||||
alert.setGraphic(logomain);
|
||||
}
|
||||
|
||||
alert.getDialogPane().setPrefSize(ALERT_WIDTH, ALERT_HEIGHT);
|
||||
Optional<ButtonType> result = alert.showAndWait();
|
||||
|
||||
if (result.isEmpty() || result.get() != ButtonType.OK) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
+15
-7
@@ -18,11 +18,18 @@ import javafx.scene.layout.HBox;
|
||||
*/
|
||||
public class TaskbarController {
|
||||
|
||||
private static final org.apache.logging.log4j.Logger LOGGER =
|
||||
org.apache.logging.log4j.LogManager.getLogger(CasinoBrowserController.class);
|
||||
|
||||
@FXML private HBox taskbar;
|
||||
@FXML private TextField taskbarInput;
|
||||
|
||||
private double xOffset = 0;
|
||||
private double yOffset = 0;
|
||||
private static final double TASKBAR_SCALE = 0.9;
|
||||
private static final int MIN_CREDITS = 5;
|
||||
private static final int MAX_CREDITS = 100000;
|
||||
private static final int CREDIT_STEP = 5;
|
||||
|
||||
/**
|
||||
* Wird aufgerufen, wenn die Taskleiste mit der Maus gedrückt wird.
|
||||
@@ -40,7 +47,8 @@ public class TaskbarController {
|
||||
* Wird aufgerufen, während die Taskleiste mit der Maus gezogen wird.
|
||||
* Aktualisiert die Position und skaliert die Taskleiste leicht zur visuellen Rückmeldung.
|
||||
*
|
||||
* TODO: Es muss noch gefixt werden, dass die Taskleiste nicht aus dem Fenster verschwinden kann.
|
||||
* TODO: Es muss noch gefixt werden, dass die Taskleiste nicht aus dem
|
||||
* Fenster verschwinden kann.
|
||||
*
|
||||
* @param event Das Mausereignis
|
||||
*/
|
||||
@@ -49,8 +57,8 @@ public class TaskbarController {
|
||||
taskbar.setLayoutX(event.getSceneX() - xOffset);
|
||||
taskbar.setLayoutY(event.getSceneY() - yOffset);
|
||||
|
||||
taskbar.setScaleX(0.9);
|
||||
taskbar.setScaleY(0.9);
|
||||
taskbar.setScaleX(TASKBAR_SCALE);
|
||||
taskbar.setScaleY(TASKBAR_SCALE);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -108,15 +116,15 @@ public class TaskbarController {
|
||||
try {
|
||||
int credits = Integer.parseInt(input.trim());
|
||||
|
||||
if (credits >= 5 && credits <= 100000 && credits % 5 == 0) {
|
||||
if (credits >= MIN_CREDITS && credits <= MAX_CREDITS && credits % CREDIT_STEP == 0) {
|
||||
// TODO: Credits müssen an die GameEngine gesendet werden
|
||||
System.out.println("Einsatz gesetzt: " + credits + " Casono Credits");
|
||||
LOGGER.info("Einsatz gesetzt: {} Casono Credits", credits);
|
||||
taskbarInput.clear();
|
||||
} else {
|
||||
System.out.println("Fehler: Nur 5er-Schritte (5, 10, ... 100.000) erlaubt!");
|
||||
LOGGER.info("Fehler: Nur 5er-Schritte (5, 10, ... 100.000) erlaubt!");
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
System.out.println("Fehler: Bitte nur eine Zahl eingeben!");
|
||||
LOGGER.info("Fehler: Bitte nur eine Zahl eingeben!");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user