diff --git a/src/main/java/com/lapisberry/Main.java b/src/main/java/com/lapisberry/Main.java index 7767bf8..aeabb8a 100644 --- a/src/main/java/com/lapisberry/Main.java +++ b/src/main/java/com/lapisberry/Main.java @@ -30,6 +30,7 @@ public void start(Stage stage) { public static void createServer() { server = new Server(); + new Thread(server, "Server thread").start(); } public static void closeServer() { diff --git a/src/main/java/com/lapisberry/gui/scenes/JoinScene.java b/src/main/java/com/lapisberry/gui/scenes/JoinScene.java index 2dd1268..edd6ebc 100644 --- a/src/main/java/com/lapisberry/gui/scenes/JoinScene.java +++ b/src/main/java/com/lapisberry/gui/scenes/JoinScene.java @@ -2,7 +2,6 @@ import com.lapisberry.Main; import com.lapisberry.gui.MediaController; -import com.lapisberry.net.Server; import javafx.geometry.Pos; import javafx.scene.Scene; import javafx.scene.control.Button; @@ -13,6 +12,8 @@ import javafx.scene.text.Text; import javafx.scene.text.TextAlignment; +import java.util.concurrent.atomic.AtomicReference; + import static com.lapisberry.gui.FontPreloader.*; public class JoinScene extends Scene { @@ -60,18 +61,22 @@ private InputField(String promptText) { private static class JoinButton extends Button { private JoinButton(String text) { super(text); + final Background regularBackground = new Background(new BackgroundFill(Color.valueOf("00C2FF"), new CornerRadii(40), null)); + final Background hoverBackground = new Background(new BackgroundFill(Color.valueOf("00A6D1"), new CornerRadii(40), null)); + final Background pressedBackground = new Background(new BackgroundFill(Color.valueOf("0089A9"), new CornerRadii(40), null)); + setFont(Font.loadFont(Inter_SemiBold, 40)); - setBackground(new Background(new BackgroundFill(Color.valueOf("00C2FF"), new CornerRadii(40), null))); + setBackground(regularBackground); setMaxWidth(274); setMinHeight(80); setAlignment(Pos.CENTER); setOnMouseEntered(e -> { - setBackground(new Background(new BackgroundFill(Color.valueOf("00A6D1"), new CornerRadii(40), null))); + setBackground(hoverBackground); setCursor(javafx.scene.Cursor.HAND); }); - setOnMouseExited(e -> setBackground(new Background(new BackgroundFill(Color.valueOf("00C2FF"), new CornerRadii(40), null)))); - setOnMousePressed(e -> setBackground(new Background(new BackgroundFill(Color.valueOf("0089A9"), new CornerRadii(40), null)))); - setOnMouseReleased(e -> setBackground(new Background(new BackgroundFill(Color.valueOf("00A6D1"), new CornerRadii(40), null)))); + setOnMouseExited(e -> setBackground(regularBackground)); + setOnMousePressed(e -> setBackground(pressedBackground)); + setOnMouseReleased(e -> setBackground(hoverBackground)); setOnAction(e -> { Main.getPrimaryStage().setScene(new LobbyScene()); MediaController.playMediaOnce(MediaController.buttonClickSound); @@ -84,25 +89,43 @@ private static class CreateServerButton extends Button { private CreateServerButton() { super("Create Server"); + final Background blueRegularBackground = new Background(new BackgroundFill(Color.valueOf("00C2FF"), new CornerRadii(40), null)); + final Background blueHoverBackground = new Background(new BackgroundFill(Color.valueOf("00A6D1"), new CornerRadii(40), null)); + final Background bluePressedBackground = new Background(new BackgroundFill(Color.valueOf("0089A9"), new CornerRadii(40), null)); + + final Background redRegularBackground = new Background(new BackgroundFill(Color.valueOf("FF0000"), new CornerRadii(40), null)); + final Background redHoverBackground = new Background(new BackgroundFill(Color.valueOf("D10000"), new CornerRadii(40), null)); + final Background redPressedBackground = new Background(new BackgroundFill(Color.valueOf("890000"), new CornerRadii(40), null)); + + AtomicReference regularBackground = new AtomicReference<>(blueRegularBackground); + AtomicReference hoverBackground = new AtomicReference<>(blueHoverBackground); + AtomicReference pressedBackground = new AtomicReference<>(bluePressedBackground); + setFont(Font.loadFont(Inter_SemiBold, 18)); - setBackground(new Background(new BackgroundFill(Color.valueOf("00C2FF"), new CornerRadii(20), null))); + setBackground(regularBackground.get()); setMaxWidth(180); setMinHeight(40); setAlignment(Pos.CENTER); setOnMouseEntered(e -> { - setBackground(new Background(new BackgroundFill(Color.valueOf("00A6D1"), new CornerRadii(20), null))); + setBackground(hoverBackground.get()); setCursor(javafx.scene.Cursor.HAND); }); - setOnMouseExited(e -> setBackground(new Background(new BackgroundFill(Color.valueOf("00C2FF"), new CornerRadii(20), null)))); - setOnMousePressed(e -> setBackground(new Background(new BackgroundFill(Color.valueOf("0089A9"), new CornerRadii(20), null)))); - setOnMouseReleased(e -> setBackground(new Background(new BackgroundFill(Color.valueOf("00A6D1"), new CornerRadii(20), null)))); + setOnMouseExited(e -> setBackground(regularBackground.get())); + setOnMousePressed(e -> setBackground(pressedBackground.get())); + setOnMouseReleased(e -> setBackground(hoverBackground.get())); setOnAction(e -> { if (isServerCreated) { - setText("Create Server"); Main.closeServer(); + setText("Create Server"); + regularBackground.set(blueRegularBackground); + hoverBackground.set(blueHoverBackground); + pressedBackground.set(bluePressedBackground); } else { - setText("Close Server"); Main.createServer(); + setText("Close Server"); + regularBackground.set(redRegularBackground); + hoverBackground.set(redHoverBackground); + pressedBackground.set(redPressedBackground); } isServerCreated = !isServerCreated; }); diff --git a/src/main/java/com/lapisberry/net/Server.java b/src/main/java/com/lapisberry/net/Server.java index 4e27a14..75cb4c4 100644 --- a/src/main/java/com/lapisberry/net/Server.java +++ b/src/main/java/com/lapisberry/net/Server.java @@ -2,7 +2,6 @@ import com.lapisberry.utils.Config; -import java.io.Closeable; import java.io.IOException; import java.net.ServerSocket; import java.net.Socket;