Skip to content

Commit

Permalink
- added color to components (that changes with player color)
Browse files Browse the repository at this point in the history
  • Loading branch information
NLucas0 committed Aug 5, 2023
1 parent f65f91a commit 837155f
Show file tree
Hide file tree
Showing 9 changed files with 180 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ public void newPlayerJoin(String input) {
// get own color id
if (parent.colorId.isEmpty()) {
parent.colorId = players.elementAt(players.size() - 1).getColor();
Platform.runLater(() -> {
SceneController.getInstance().setMainColor(parent.colorId);
});
}

Platform.runLater(() -> {
Expand Down Expand Up @@ -190,7 +193,10 @@ public void error(String input) {
}

public void displayGameScreen(String input) {
Platform.runLater(() -> this.wordHunterController = SceneController.getInstance().showGamePage());
Platform.runLater(() -> {
this.wordHunterController = SceneController.getInstance().showGamePage();
SceneController.getInstance().setMainColor(parent.colorId);
});
}

public void endGameScreen(String input) {
Expand All @@ -207,6 +213,7 @@ public void endGameScreen(String input) {
Platform.runLater(() -> {
parent.getWinnerPageController().updateScoreList(players);
parent.getWinnerPageController().updateWinner(winner);
SceneController.getInstance().setMainColor(parent.colorId);
});

try {
Expand Down
25 changes: 22 additions & 3 deletions src/main/java/com/wordhunter/client/ui/SceneController.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.wordhunter.client.ui;

import com.wordhunter.client.logic.ClientMain;
import javafx.application.Platform;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
Expand All @@ -15,6 +16,7 @@ public class SceneController {
// components
private Stage stage;
private Scene scene;
public Parent root;
private ReconnectionOverlay reconnectionOverlay;

// device screen size
Expand Down Expand Up @@ -48,7 +50,7 @@ private SceneController()
}

public void showStartPage() {
Parent root = null;
root = null;
try {
root = FXMLLoader.load(Objects.requireNonNull(getClass().getResource("StartPage.fxml")));
} catch (IOException e) {
Expand All @@ -62,8 +64,25 @@ public void showStartPage() {
stage.show();
}

public void setMainColor(String color)
{
// get lighter version
String newHex = color;
if(color.length() >= 7 && color.startsWith("#")) {
// make lighter by increasing value by 55
int r = Integer.parseInt(color.substring(1, 3), 16) + 55;
int g = Integer.parseInt(color.substring(3, 5), 16) + 55;
int b = Integer.parseInt(color.substring(5, 7), 16) + 55;
newHex = "#"
+ Integer.toHexString(r)
+ Integer.toHexString(g)
+ Integer.toHexString(b);
}
root.setStyle("-bg-main: " + newHex + ";-bg-main-dark: " + color + ";");
}

public void showWaitingPage() {
Parent root = null;
root = null;
try {
root = FXMLLoader.load(Objects.requireNonNull(getClass().getResource("ServerPage.fxml")));
} catch (IOException e) {
Expand All @@ -79,7 +98,7 @@ public void showWaitingPage() {
public WordHunterController showGamePage() {
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("WordHunter.fxml"));

Parent root = null;
root = null;
try {
root = fxmlLoader.load();
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class PlayerListCell extends Label
public PlayerListCell(Player player)
{
this.setText(player.getName());
this.setStyle("-fx-text-fill: " + player.getColor() + ";");
this.setStyle("-fx-background-radius: 10;-fx-text-fill: " + player.getColor() + ";");
}
}

Expand Down
15 changes: 9 additions & 6 deletions src/main/java/com/wordhunter/client/ui/WordPane.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class WordPane extends StackPane {
// Constant
// Word font
private static final Font FONT = new Font("Arial", 20);
public static final String BORDER = "-fx-border-color: #000000; -fx-border-width: 2px;";
public static final String BORDER = "-fx-border-color: -border-color; -fx-border-width: 2;";
public static final Color DEFAULT_COLOR = Color.WHITE;

// Member variables
Expand Down Expand Up @@ -62,11 +62,14 @@ public void initAnimation(long interval){
if (animation != null) {
closeAnimation();
}
animation = new FadeTransition(Duration.millis(interval), this.label);
animation.setFromValue(1);
animation.setToValue(0);
animation.setCycleCount(1);
animation.play();
if (interval > 0) {
animation = new FadeTransition(Duration.millis(interval), this.label);
double currentOpacity = this.label.getOpacity();
animation.setFromValue(currentOpacity);
animation.setToValue(0);
animation.setCycleCount(1);
animation.play();
}
}

public void closeAnimation() {
Expand Down
15 changes: 9 additions & 6 deletions src/main/java/com/wordhunter/server/ServerAcceptClients.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ class ServerAcceptClients extends Thread {
*/
public ServerAcceptClients() {
// setup color vector
colorIds.add("#F00");
colorIds.add("#0F0");
colorIds.add("#00F");
colorIds.add("#F0F");
colorIds.add("#FF0");
colorIds.add("#0FF");
colorIds.add("#8b5dc8"); // purple
colorIds.add("#5dc866"); // green
colorIds.add("#c8c15d"); // yellow
colorIds.add("#5d6fc8"); // blue
colorIds.add("#c85daf"); // pink
colorIds.add("#c87b5d"); // orange
}


Expand Down Expand Up @@ -130,6 +130,9 @@ else if (ServerMain.clientLimit <= ServerMain.playerList.size()) {
{
ServerMain.sendMessageToClient(client, "error" + ServerMain.messageDelimiter
+ "username taken");
in.close();
client.close();
continue;
}
// create player obj and store socket in there
newPlayerJoinHandle(msg[1], client);
Expand Down
28 changes: 12 additions & 16 deletions src/main/resources/com/wordhunter/client/ui/ServerPage.fxml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>

<!--waiting room page. Shows players currently in server + time until game start-->

<?import javafx.geometry.Insets?>
Expand All @@ -10,49 +11,44 @@
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>

<StackPane styleClass="main_container"
xmlns="http://javafx.com/javafx" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="com.wordhunter.client.ui.ServerPageController"
stylesheets="@WordHunterStyleSheet.css">
<VBox alignment="CENTER">
<StackPane styleClass="main_container" stylesheets="@WordHunterStyleSheet.css" xmlns="http://javafx.com/javafx/18" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.wordhunter.client.ui.ServerPageController">
<VBox alignment="CENTER" styleClass="secondary_container">
<StackPane.margin>
<Insets/>
<Insets />
</StackPane.margin>
<padding>
<Insets left="50.0" right="50.0"/>
<Insets left="50.0" right="50.0" />
</padding>
<!-- top section-->
<HBox alignment="CENTER" prefHeight="100.0" prefWidth="200.0">
<Label text="Server IP:">
<font>
<Font size="35.0"/>
<Font size="35.0" />
</font>
</Label>
<Label fx:id="serverIPLabel" text="XXXXXXXXXX">
<font>
<Font size="35.0"/>
<Font size="35.0" />
</font>
</Label>
</HBox>
<!-- player list -->
<ScrollPane hbarPolicy="NEVER" maxHeight="-Infinity" maxWidth="-Infinity" prefHeight="338.0"
prefWidth="700.0" VBox.vgrow="ALWAYS">
<ScrollPane id="playerList" hbarPolicy="NEVER" maxHeight="-Infinity" maxWidth="-Infinity" prefHeight="338.0" prefWidth="700.0" VBox.vgrow="ALWAYS">
<VBox.margin>
<Insets/>
<Insets />
</VBox.margin>
<ListView fx:id="playerView" focusTraversable="false" mouseTransparent="true" prefHeight="400.0"
prefWidth="702.0"/>
<ListView fx:id="playerView" focusTraversable="false" mouseTransparent="true" prefHeight="400.0" prefWidth="702.0" />
</ScrollPane>
<!-- player name -->
<Label fx:id="currentPlayerLabel" alignment="CENTER" contentDisplay="CENTER" text="Current Player: ">
<font>
<Font size="30.0"/>
<Font size="30.0" />
</font>
</Label>
<!-- timer -->
<Label fx:id="startTimer" alignment="CENTER" text="Game will start in x mins">
<font>
<Font size="24.0"/>
<Font size="24.0" />
</font>
</Label>
</VBox>
Expand Down
30 changes: 13 additions & 17 deletions src/main/resources/com/wordhunter/client/ui/StartPage.fxml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>

<!--start page. Gives option to create or join server. gets username + server IP-->

<?import javafx.geometry.Insets?>
Expand All @@ -8,51 +9,46 @@
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>


<VBox alignment="CENTER" spacing="10.0" styleClass="main_container"
xmlns="http://javafx.com/javafx" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="com.wordhunter.client.ui.StartPageController"
stylesheets="@WordHunterStyleSheet.css">
<VBox id="main_page_bg" alignment="CENTER" spacing="10.0" styleClass="main_container" stylesheets="@WordHunterStyleSheet.css" xmlns="http://javafx.com/javafx/18" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.wordhunter.client.ui.StartPageController">
<padding>
<Insets left="50.0" right="50.0"/>
<Insets left="50.0" right="50.0" />
</padding>
<!--title-->
<Label text="Welcome to Word Hunter!!!!">
<font>
<Font size="48.0"/>
<Font size="48.0" />
</font>
<VBox.margin>
<Insets bottom="30.0"/>
<Insets bottom="30.0" />
</VBox.margin>
</Label>
<!--username enter-->
<Label text="Enter your username:" textAlignment="CENTER">
<font>
<Font size="24.0"/>
<Font size="24.0" />
</font>
</Label>
<TextField fx:id="usernameField" maxWidth="-Infinity" prefHeight="25.0" prefWidth="300.0"/>
<TextField fx:id="usernameField" maxWidth="-Infinity" prefHeight="25.0" prefWidth="300.0" />
<!--create server-->
<Button mnemonicParsing="false" onAction="#createButtonClicked" prefHeight="50.0" prefWidth="300.0"
text="Create Server">
<Button mnemonicParsing="false" onAction="#createButtonClicked" prefHeight="50.0" prefWidth="300.0" text="Create Server">
<font>
<Font size="36.0"/>
<Font size="36.0" />
</font>
<VBox.margin>
<Insets bottom="30.0"/>
<Insets bottom="30.0" />
</VBox.margin>
</Button>
<!--server IP enter-->
<Label fx:id="label" text="Enter Server's IP address.">
<font>
<Font size="24.0"/>
<Font size="24.0" />
</font>
</Label>
<TextField fx:id="ipAddressField" alignment="CENTER" maxWidth="-Infinity" prefHeight="25.0" prefWidth="300.0"/>
<TextField fx:id="ipAddressField" alignment="CENTER" maxWidth="-Infinity" prefHeight="25.0" prefWidth="300.0" />
<!--join server-->
<Button mnemonicParsing="false" onAction="#joinButtonClicked" prefHeight="50.0" prefWidth="300.0" text="Join Server">
<font>
<Font size="36.0"/>
<Font size="36.0" />
</font>
</Button>
</VBox>
19 changes: 11 additions & 8 deletions src/main/resources/com/wordhunter/client/ui/WordHunter.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>

<StackPane minHeight="-Infinity" minWidth="-Infinity" styleClass="main_container" stylesheets="@WordHunterStyleSheet.css" xmlns="http://javafx.com/javafx/20.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.wordhunter.client.ui.WordHunterController">
<VBox alignment="CENTER" spacing="10.0">
<StackPane minHeight="-Infinity" minWidth="-Infinity" styleClass="main_container" stylesheets="@WordHunterStyleSheet.css" xmlns="http://javafx.com/javafx/18" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.wordhunter.client.ui.WordHunterController">
<VBox alignment="CENTER" spacing="10.0" styleClass="secondary_container">
<padding>
<Insets bottom="30.0" left="50.0" right="50.0" top="30.0" />
<Insets bottom="10.0" left="30.0" right="30.0" top="10.0" />
</padding>
<!--health bar-->
<HBox alignment="CENTER" VBox.vgrow="NEVER">
Expand All @@ -32,7 +32,7 @@
</Label>
</HBox>
<!--main grid-->
<GridPane fx:id="grids" alignment="CENTER" scaleShape="false" style="-fx-background-color: #00000011;" VBox.vgrow="SOMETIMES">
<GridPane id="grid" fx:id="grids" alignment="CENTER" scaleShape="false" VBox.vgrow="ALWAYS">
<columnConstraints>
<ColumnConstraints percentWidth="20.0" />
<ColumnConstraints percentWidth="20.0" />
Expand All @@ -49,10 +49,13 @@
</rowConstraints>
</GridPane>
<!--text input-->
<TextField fx:id="userInputField" alignment="CENTER" maxHeight="-Infinity" maxWidth="-Infinity" prefHeight="25.0" prefWidth="600.0" promptText="Start Typing a Word on Screen...">
<font>
<Font size="21.0" />
</font>
<TextField id="userInput" fx:id="userInputField" alignment="CENTER" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" prefHeight="40.0" prefWidth="600.0" promptText="Start Typing a Word on Screen..." VBox.vgrow="NEVER">
<font>
<Font size="20.0" />
</font>
</TextField>
<StackPane.margin>
<Insets bottom="20.0" left="30.0" right="30.0" top="20.0" />
</StackPane.margin>
</VBox>
</StackPane>
Loading

0 comments on commit 837155f

Please sign in to comment.