Skip to content

Commit

Permalink
Ready for 2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Jo0001 committed Dec 12, 2020
1 parent 98bd721 commit d7aaf24
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 29 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
# Gloomhaven Battle Goal Cards
A simple application to show the Gloomhaven Battle Goal Cards via sockets to all clients

Start with a specific host and port via commandline:
Start server only (no gui):

`java -jar gloomhaven_battle_goal_cards.jar -startserver -port 12345`

Start with a specific host and port via commandline (you still have to manually connect) :

`java -jar gloomhaven_battle_goal_cards.jar -host your-host.com -port 12345`

Note: Still in development -use at your own risk
Note: Still in development - use at your own risk
41 changes: 24 additions & 17 deletions resources/mainUI.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,32 @@
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.BorderPane?>

<BorderPane fx:id="mainScreen" prefHeight="500.0" prefWidth="500.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="de.jo0001.gloomhaven.battleGoalCards.core.Controller">
<BorderPane fx:id="mainScreen" prefHeight="500.0" prefWidth="500.0" xmlns="http://javafx.com/javafx/8"
xmlns:fx="http://javafx.com/fxml/1" fx:controller="de.jo0001.gloomhaven.battleGoalCards.core.Controller">
<center>
<AnchorPane prefHeight="-1.0" prefWidth="-1.0">
<children>
<Button fx:id="btn" layoutX="120.0" layoutY="367.0" mnemonicParsing="false" text="Für alle Anzeigen" />
<AnchorPane fx:id="card1" layoutX="20.0" layoutY="22.0" prefHeight="285.0" prefWidth="200.0" styleClass="side1">
<Button fx:id="btn" layoutX="120.0" layoutY="367.0" mnemonicParsing="false" text="Für alle Anzeigen"/>
<AnchorPane fx:id="card1" layoutX="20.0" layoutY="22.0" prefHeight="285.0" prefWidth="200.0"
styleClass="side1">
<children>
<Label fx:id="title1" layoutX="2.0" layoutY="54.0" prefHeight="17.0" prefWidth="197.0" text="Title" />
<Label fx:id="desc1" layoutX="39.0" layoutY="69.0" prefHeight="163.0" prefWidth="125.0" text="description" />
<Label fx:id="checks1" layoutX="77.0" layoutY="229.0" text="checks" />
<Label fx:id="id1" layoutX="77.0" layoutY="263.0" text="id" />
<Label fx:id="title1" layoutX="2.0" layoutY="54.0" prefHeight="17.0" prefWidth="197.0"
text="Title"/>
<Label fx:id="desc1" layoutX="39.0" layoutY="69.0" prefHeight="163.0" prefWidth="125.0"
text="description"/>
<Label fx:id="checks1" layoutX="77.0" layoutY="229.0" text="checks"/>
<Label fx:id="id1" layoutX="77.0" layoutY="263.0" text="id"/>
</children>
</AnchorPane>
<AnchorPane fx:id="card2" layoutX="274.0" layoutY="22.0" prefHeight="285.0" prefWidth="200.0" styleClass="side1">
<AnchorPane fx:id="card2" layoutX="274.0" layoutY="22.0" prefHeight="285.0" prefWidth="200.0"
styleClass="side1">
<children>
<Label fx:id="title2" layoutX="3.0" layoutY="54.0" prefHeight="17.0" prefWidth="197.0" text="Title" textAlignment="CENTER" />
<Label fx:id="desc2" layoutX="41.0" layoutY="69.0" prefHeight="163.0" prefWidth="125.0" text="description" />
<Label fx:id="checks2" layoutX="77.0" layoutY="229.0" text="checks" />
<Label fx:id="id2" layoutX="77.0" layoutY="263.0" text="id" />
<Label fx:id="title2" layoutX="3.0" layoutY="54.0" prefHeight="17.0" prefWidth="197.0"
text="Title" textAlignment="CENTER"/>
<Label fx:id="desc2" layoutX="41.0" layoutY="69.0" prefHeight="163.0" prefWidth="125.0"
text="description"/>
<Label fx:id="checks2" layoutX="77.0" layoutY="229.0" text="checks"/>
<Label fx:id="id2" layoutX="77.0" layoutY="263.0" text="id"/>
</children>
</AnchorPane>
</children>
Expand All @@ -35,14 +42,14 @@
<menus>
<Menu mnemonicParsing="false" text="Settings">
<items>
<MenuItem fx:id="connect" mnemonicParsing="false" text="Connect" />
<MenuItem fx:id="resetbtn" mnemonicParsing="false" text="Reset" />
<MenuItem fx:id="manageServerBtn" mnemonicParsing="false" text="Start server" />
<MenuItem fx:id="connect" mnemonicParsing="false" text="Connect"/>
<MenuItem fx:id="resetbtn" mnemonicParsing="false" text="Reset"/>
<MenuItem fx:id="manageServerBtn" mnemonicParsing="false" text="Start server"/>
</items>
</Menu>
<Menu mnemonicParsing="false" text="About">
<MenuItem mnemonicParsing="false" text="Version: 1.4.0"/>
<Menu mnemonicParsing="false" text="About">
<MenuItem fx:id="helpBtn" mnemonicParsing="false" text="Info &amp; Help"/>
<MenuItem mnemonicParsing="false" text="Version: 2.0.0"/>
</Menu>
</menus>
</MenuBar>
Expand Down
16 changes: 15 additions & 1 deletion src/de/jo0001/gloomhaven/battleGoalCards/core/AppLauncher.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package de.jo0001.gloomhaven.battleGoalCards.core;

import de.jo0001.gloomhaven.battleGoalCards.network.Server;
import de.jo0001.gloomhaven.battleGoalCards.other.DataHolder;
import de.jo0001.gloomhaven.battleGoalCards.other.DataManager;
import javafx.application.Application;

import java.io.*;
import java.net.BindException;

public class AppLauncher {

Expand All @@ -17,7 +19,19 @@ public static void main(String[] args) throws IOException {
System.out.println("Restarting");
System.exit(-2);
}
if (args.length == 4 && args[0].equalsIgnoreCase("-host") && args[2].equalsIgnoreCase("-port")) {
if (args.length == 3 && args[0].equalsIgnoreCase("-startserver") && args[1].equalsIgnoreCase("-port")) {
try {
Server server = new Server(Integer.parseInt(args[2]));
server.start();
} catch (IllegalArgumentException e) {
System.err.println("Invalid port");
e.printStackTrace();
} catch (BindException e) {
System.err.println("Can't bind to port. Already in use?");
e.printStackTrace();
}
return;
} else if (args.length == 4 && args[0].equalsIgnoreCase("-host") && args[2].equalsIgnoreCase("-port")) {
DataHolder data = new DataHolder(args[1], Integer.parseInt(args[3]));
DataManager.saveData(data);
}
Expand Down
8 changes: 5 additions & 3 deletions src/de/jo0001/gloomhaven/battleGoalCards/core/Controller.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import java.awt.*;
import java.io.IOException;
import java.net.BindException;
import java.net.URI;
import java.net.URL;
import java.util.Optional;
Expand Down Expand Up @@ -77,7 +78,6 @@ public void onBtnPress(ActionEvent buttonEvent) {
resetCard(2);
//showSide(1);
client.getInfo();
client.getInfo();
}
}

Expand Down Expand Up @@ -146,11 +146,13 @@ private void mangeServer(ActionEvent actionEvent) {
startServer(tmpPort);
} catch (NumberFormatException e) {
alert("Invalid port", "Port must contain only numbers. For example 58889", Alert.AlertType.ERROR);
} catch (BindException e) {
alert("Can't bind to port", "Can't bind to port. Already in use?", Alert.AlertType.ERROR);
}
}
}

private void startServer(int tmpPort) {
private void startServer(int tmpPort) throws BindException {
Server s = new Server(tmpPort);
s.start();
}
Expand Down Expand Up @@ -227,7 +229,6 @@ private void prompt(ActionEvent buttonEvent) {
host = res[0];
setUpClient(host, port);
btn.setText("Für alle Anzeigen");
connected = true;
DataManager.saveData(new DataHolder(host, port));

}
Expand All @@ -236,6 +237,7 @@ private void prompt(ActionEvent buttonEvent) {
private void setUpClient(String host, int port) {
client = new Client(host, port, this);
client.start();
connected = true;
}

private void alert(String title, String mes, Alert.AlertType alertType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public void startClient() {
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("Verbindungsfehler");
alert.setHeaderText(null);
alert.setContentText("Es konnte keine Verbindung zu " + host + "unter Port " + port + " herstellen. Bitte versuche es erneut.");
alert.setContentText("Couldn't connect to " + host + " with port " + port + " Please try again");
Stage stage = (Stage) alert.getDialogPane().getScene().getWindow();
stage.getIcons().add(new Image(Client.class.getResourceAsStream("/logo.png")));
alert.showAndWait();
Expand Down
13 changes: 8 additions & 5 deletions src/de/jo0001/gloomhaven/battleGoalCards/network/Server.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package de.jo0001.gloomhaven.battleGoalCards.network;

import java.io.*;
import java.net.BindException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;
Expand All @@ -13,11 +14,13 @@ public class Server extends Thread {
private static final List<Integer> usedIds = new ArrayList<>();
private static final List<Socket> clients = new ArrayList<>();

public Server(int port) {
public Server(int port) throws BindException {
try {
serverSocket = new ServerSocket(port);
} catch (IOException e) {
e.printStackTrace();
} catch (BindException e) {
throw new BindException();
} catch (IOException ioException) {
ioException.printStackTrace();
}
}

Expand Down Expand Up @@ -68,7 +71,7 @@ public static void notifyClients() {
}

//Just for Testing
public static void main(String[] args) {
public static void main(String[] args) throws BindException {
Server s = new Server(58889);
s.runServer();
}
Expand Down Expand Up @@ -101,7 +104,7 @@ public void run() {
try {
if (s != null) {
s.close();
System.out.println(" Socket Closed");
System.out.println("Socket Closed");
}
} catch (IOException ignored) {
}
Expand Down

0 comments on commit d7aaf24

Please sign in to comment.