Skip to content

Commit

Permalink
Merge branch 'javafx' of github.com:Cardshifter/Cardshifter into clie…
Browse files Browse the repository at this point in the history
…nt-server
  • Loading branch information
Zomis committed Oct 6, 2014
2 parents a440b3e + 4e47684 commit e8b47d5
Show file tree
Hide file tree
Showing 8 changed files with 141 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@

import com.cardshifter.api.CardshifterConstants;
import com.cardshifter.api.both.ChatMessage;
import com.cardshifter.api.both.InviteRequest;
import com.cardshifter.api.both.InviteResponse;
import com.cardshifter.api.incoming.LoginMessage;
import com.cardshifter.api.incoming.ServerQueryMessage;
import com.cardshifter.api.incoming.ServerQueryMessage.Request;
Expand All @@ -49,6 +51,7 @@ public class GameClientLobby implements Initializable {
@FXML private TextField messageBox;
@FXML private Button sendMessageButton;
@FXML private AnchorPane inviteButton;
@FXML private AnchorPane inviteWindow;

private final ObjectMapper mapper = new ObjectMapper();
private final Set<GameClientController> gamesRunning = new HashSet<>();
Expand All @@ -62,6 +65,7 @@ public class GameClientLobby implements Initializable {
private Thread listenThread;
private final Map<String, Integer> usersOnlineList = new HashMap<>();
private String userForGameInvite;
private InviteRequest currentGameRequest;

public void acceptConnectionSettings(String ipAddress, int port, String userName) {
// this is passed into this object after it is automatically created by the FXML document
Expand Down Expand Up @@ -140,20 +144,18 @@ private void processMessageFromServer(Message message) {
}

if (message instanceof NewGameMessage) {
NewGameMessage msg = (NewGameMessage) message;
startNewGame(msg);
}

if (message instanceof UserStatusMessage) {
this.startNewGame((NewGameMessage)message);
} else if (message instanceof UserStatusMessage) {
this.processUserStatusMessage((UserStatusMessage)message);
}
if (message instanceof ChatMessage) {
} else if (message instanceof ChatMessage) {
ChatMessage msg = (ChatMessage) message;
chatOutput(msg.getFrom() + ": " + msg.getMessage());
}
if (message instanceof ServerErrorMessage) {
this.chatOutput(msg.getFrom() + ": " + msg.getMessage());
} else if (message instanceof ServerErrorMessage) {
ServerErrorMessage msg = (ServerErrorMessage) message;
chatOutput("SERVER ERROR: " + msg.getMessage());
this.chatOutput("SERVER ERROR: " + msg.getMessage());
} else if (message instanceof InviteRequest) {
this.currentGameRequest = (InviteRequest)message;
this.createInviteWindow((InviteRequest)message);
}
}

Expand Down Expand Up @@ -181,10 +183,6 @@ private void startNewGame(NewGameMessage message) {
}
}

private void chatOutput(String string) {
Platform.runLater(() -> this.chatMessages.getItems().add(string));

}
private void processUserStatusMessage(UserStatusMessage message) {
if (message.getStatus() == Status.ONLINE) {
this.usersOnlineList.put(message.getName(), message.getUserId());
Expand All @@ -196,6 +194,31 @@ private void processUserStatusMessage(UserStatusMessage message) {
this.usersOnline.getItems().addAll(this.usersOnlineList.keySet());
}


private void chatOutput(String string) {
Platform.runLater(() -> this.chatMessages.getItems().add(string));
}

private void createInviteWindow(InviteRequest message) {
this.inviteWindow.setVisible(true);
this.inviteWindow.getChildren().add(new InviteWindow(message, this).getRootPane());
}

public void acceptGameRequest(MouseEvent event) {
this.send(new InviteResponse(this.currentGameRequest.getId(), true));
this.closeInviteWindow();
}

public void declineGameRequest(MouseEvent event) {
this.send(new InviteResponse(this.currentGameRequest.getId(), false));
this.closeInviteWindow();
}

private void closeInviteWindow() {
this.inviteWindow.getChildren().clear();
this.inviteWindow.setVisible(false);
}

private void selectUserForGameInvite(MouseEvent event) {
String selected = this.usersOnline.getSelectionModel().getSelectedItem();
if (selected != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.cardshifter.client;

import com.cardshifter.api.both.InviteRequest;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.control.Label;
import javafx.scene.layout.AnchorPane;

public class InviteWindow {

@FXML private AnchorPane rootPane;
@FXML private Label nameLabel;
@FXML private AnchorPane noButton;
@FXML private AnchorPane yesButton;

private final InviteRequest message;
private final GameClientLobby lobby;

public InviteWindow(InviteRequest message, GameClientLobby lobby) {
try {
FXMLLoader loader = new FXMLLoader(getClass().getResource("InviteWindowDocument.fxml"));
loader.setController(this);
loader.load();
} catch (Exception e) {
throw new RuntimeException(e);
}

this.message = message;
this.lobby = lobby;

this.nameLabel.setText(message.getName());
this.yesButton.setOnMouseClicked(lobby::acceptGameRequest);
this.noButton.setOnMouseClicked(lobby::declineGameRequest);
}

public AnchorPane getRootPane() {
return this.rootPane;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ public final class CardBattlefieldDocumentController extends CardView implements
@FXML private Label strength;
@FXML private Label health;
@FXML private Label cardId;
@FXML private Label cardType;
@FXML private Label creatureType;
@FXML private Rectangle background;
@FXML private Circle sicknessCircle;
Expand Down Expand Up @@ -98,15 +97,15 @@ public void setCardAttackActive(UseableActionMessage message) {
this.message = message;
this.anchorPane.setOnMouseClicked(this::actionOnClick);
background.setFill(Color.DARKGREEN);

this.setUpScrapButton();
}

public void setCardActive(UseableActionMessage message) {
this.isActive = true;
this.message = message;
this.anchorPane.setOnMouseClicked(this::actionOnClick);
//this.anchorPane.setOnMouseClicked(this::actionOnClick);
background.setFill(Color.YELLOW);
this.setUpScrapButton();
}

public void removeCardActive() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@ public final class CardHandDocumentController extends CardView {
@FXML private Label cardId;
@FXML private Label manaCost;
@FXML private Label scrapCost;
@FXML private Label cardType;
@FXML private Label creatureType;
@FXML private Label enchStrength;
@FXML private Label enchHealth;
@FXML private Label abilityText;
@FXML private Rectangle background;
@FXML private AnchorPane anchorPane;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.text.*?>
<?import javafx.scene.shape.*?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>


<AnchorPane fx:id="rootPane" prefHeight="240.0" prefWidth="400.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8">
<children>
<Rectangle arcHeight="5.0" arcWidth="5.0" fill="#0055a4" height="240.0" stroke="BLACK" strokeType="INSIDE" width="400.0" />
<Rectangle arcHeight="5.0" arcWidth="5.0" fill="#b1bdff" height="120.0" layoutX="15.0" layoutY="14.0" stroke="BLACK" strokeType="INSIDE" width="370.0" />
<Label layoutX="28.0" layoutY="22.0" text="Accept invite from">
<font>
<Font name="System Bold" size="36.0" />
</font>
</Label>
<Label fx:id="nameLabel" layoutX="166.0" layoutY="84.0" text="name" textAlignment="CENTER">
<font>
<Font name="System Bold" size="24.0" />
</font>
</Label>
<AnchorPane fx:id="yesButton" layoutX="15.0" layoutY="152.0" prefHeight="73.0" prefWidth="151.0">
<children>
<Rectangle arcHeight="5.0" arcWidth="5.0" fill="#2bab35" height="73.0" stroke="BLACK" strokeType="INSIDE" width="151.0" />
<Label layoutX="42.0" layoutY="15.0" text="Yes">
<font>
<Font name="System Bold" size="36.0" />
</font>
</Label>
</children>
</AnchorPane>
<AnchorPane fx:id="noButton" layoutX="234.0" layoutY="152.0" prefHeight="73.0" prefWidth="151.0">
<children>
<Rectangle arcHeight="5.0" arcWidth="5.0" fill="#a4300d" height="73.0" stroke="BLACK" strokeType="INSIDE" width="151.0" />
<Label layoutX="50.0" layoutY="15.0" text="No">
<font>
<Font name="System Bold" size="36.0" />
</font>
</Label>
</children>
</AnchorPane>
</children>
</AnchorPane>
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,6 @@
</Label>
</children>
</AnchorPane>
<AnchorPane fx:id="inviteWindow" prefHeight="275.0" prefWidth="400.0" visible="false" AnchorPane.bottomAnchor="100.0" AnchorPane.leftAnchor="200.0" AnchorPane.rightAnchor="200.0" AnchorPane.topAnchor="100.0" />
</children>
</AnchorPane>
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,21 @@

<!-- Non Functional Card Layout Pieces -->
<Rectangle arcHeight="5.0" arcWidth="5.0" fill="#b90707" height="105.0" layoutX="5.0" layoutY="2.0" stroke="BLACK" strokeType="INSIDE" width="79.0" />
<Label layoutX="53.0" layoutY="73.0" text="/" textFill="WHITE">
<Label layoutX="53.0" layoutY="46.0" text="/" textFill="WHITE">
<font>
<Font size="18.0" />
</font>
</Label>

<!-- Card Labels -->
<Label fx:id="strength" layoutX="40.0" layoutY="76.0" text="#" textFill="WHITE" />
<Label fx:id="health" layoutX="69.0" layoutY="77.0" text="#" textFill="WHITE" />
<Label fx:id="cardId" layoutX="12.0" layoutY="4.0" text="Card Id =" textFill="WHITE" />
<Label fx:id="cardType" layoutX="12.0" layoutY="20.0" text="Type" textFill="WHITE" />
<Label fx:id="creatureType" layoutX="12.0" layoutY="36.0" text="Type" textFill="WHITE" />
<Label fx:id="strength" layoutX="39.0" layoutY="51.0" text="#" textFill="WHITE" />
<Label fx:id="health" layoutX="69.0" layoutY="51.0" text="#" textFill="WHITE" />
<Label fx:id="cardId" layoutX="7.0" layoutY="6.0" text="Card Id =" textFill="WHITE" />
<Label fx:id="creatureType" layoutX="8.0" layoutY="27.0" text="Type" textFill="WHITE" />
<Circle fx:id="sicknessCircle" fill="#bfc6cd" layoutX="45.0" layoutY="36.0" radius="23.0" stroke="BLACK" strokeType="INSIDE" visible="false" />

<!-- Scrap Button -->
<Button fx:id="scrapButton" layoutX="7.0" layoutY="66.0" mnemonicParsing="false" prefHeight="37.0" prefWidth="30.0" text="S" visible="false" />
<Button fx:id="scrapButton" layoutX="19.0" layoutY="77.0" mnemonicParsing="false" prefHeight="24.0" prefWidth="53.0" text="Scrap" visible="false" />

</children>
</AnchorPane>
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,21 @@

<!-- Non Functional Card Layout Pieces -->
<Rectangle arcHeight="5.0" arcWidth="5.0" fill="#b90707" height="164.0" layoutX="12.0" layoutY="12.0" stroke="BLACK" strokeType="INSIDE" width="106.0" />
<Rectangle arcHeight="5.0" arcWidth="5.0" height="16.0" layoutX="12.0" layoutY="127.0" stroke="BLACK" strokeType="INSIDE" width="106.0" />
<Label layoutX="93.0" layoutY="105.0" text="/" textFill="WHITE">
<Rectangle arcHeight="5.0" arcWidth="5.0" height="16.0" layoutX="12.0" layoutY="106.0" stroke="BLACK" strokeType="INSIDE" width="106.0" />
<Label layoutX="87.0" layoutY="83.0" text="/" textFill="WHITE">
<font>
<Font size="18.0" />
</font>
</Label>
<Label layoutX="18.0" layoutY="86.0" text="Card Type =" textFill="WHITE" />

<!-- Card Labels -->
<Label fx:id="strength" layoutX="78.0" layoutY="108.0" text="#" textFill="WHITE" />
<Label fx:id="health" layoutX="108.0" layoutY="108.0" text="#" textFill="WHITE" />
<Label fx:id="cardId" layoutX="34.0" layoutY="14.0" text="Card Id =" textFill="WHITE" />
<Label fx:id="strength" layoutX="73.0" layoutY="86.0" text="#" textFill="WHITE" />
<Label fx:id="health" layoutX="103.0" layoutY="87.0" text="#" textFill="WHITE" />
<Label fx:id="cardId" layoutX="16.0" layoutY="17.0" text="Card Id =" textFill="WHITE" />
<Label fx:id="manaCost" layoutX="17.0" layoutY="45.0" text="Mana Cost =" textFill="WHITE" />
<Label fx:id="scrapCost" layoutX="17.0" layoutY="61.0" text="Scrap Cost =" textFill="WHITE" />
<Label fx:id="cardType" layoutX="19.0" layoutY="108.0" text="Type" textFill="WHITE" />
<Label fx:id="enchStrength" layoutX="16.0" layoutY="140.0" text="Ench Str =" textFill="WHITE" />
<Label fx:id="enchHealth" layoutX="17.0" layoutY="156.0" prefHeight="16.0" prefWidth="95.0" text="Ench Hth =" textFill="WHITE" />
<Label fx:id="creatureType" layoutX="19.0" layoutY="127.0" text="Type" textFill="WHITE" />
<Label fx:id="creatureType" layoutX="15.0" layoutY="106.0" text="Type" textFill="WHITE" />
<Label fx:id="abilityText" layoutX="16.0" layoutY="125.0" text="Ability" textFill="WHITE" />

</children>
</AnchorPane>

0 comments on commit e8b47d5

Please sign in to comment.