Skip to content

Commit

Permalink
added Battlefield ZoneView and DocumetnController
Browse files Browse the repository at this point in the history
  • Loading branch information
bazola committed Sep 19, 2014
1 parent 3189478 commit 209f684
Show file tree
Hide file tree
Showing 6 changed files with 189 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.cardshifter.client;

import com.cardshifter.server.outgoing.UseableActionMessage;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import javafx.scene.layout.Pane;

public class BattlefieldZoneView extends ZoneView {

private final Map<Integer, CardBattlefieldDocumentController> cardMap = new HashMap<>();

public BattlefieldZoneView(int cardId, Pane pane) {
super(cardId, pane);
}

public void addCardHandController(int cardId, CardBattlefieldDocumentController controller) {
this.cardMap.put(cardId, controller);
super.addPane(cardId, controller.getRootPane());
}

public void removeCardHandDocumentController(int cardId) {
super.removePane(cardId);
this.cardMap.remove(cardId);
}

public CardBattlefieldDocumentController getCardHandController(int cardId) {
return this.cardMap.get(cardId);
}

@Override
public int getSize() {
return this.cardMap.size();
}

@Override
public Set getAllIds() {
return this.cardMap.keySet();
}

public void highlightCard(int cardId, UseableActionMessage message) {
CardBattlefieldDocumentController card = this.cardMap.get(cardId);
card.setCardActive(message);
super.removePane(cardId);
super.addPane(cardId, card.getRootPane());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package com.cardshifter.client;

import com.cardshifter.server.outgoing.CardInfoMessage;
import com.cardshifter.server.outgoing.UseableActionMessage;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.control.Label;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.AnchorPane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;

public class CardBattlefieldDocumentController implements Initializable {

@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 AnchorPane anchorPane;

private AnchorPane root;
private final CardInfoMessage card;
private final GameClientController controller;
private UseableActionMessage message;

public CardBattlefieldDocumentController(CardInfoMessage message, GameClientController controller) {
try {
FXMLLoader loader = new FXMLLoader(getClass().getResource("CardBattlefieldDocument.fxml"));
loader.setController(this);
root = loader.load();
}
catch (Exception e) {
throw new RuntimeException(e);
}

this.card = message;
this.controller = controller;
this.setCardId();
this.setCardLabels();
}

public AnchorPane getRootPane() {
return this.anchorPane;
}

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

private void actionOnClick(MouseEvent event) {
System.out.println("Action detected on card" + this.cardId.textProperty());
this.controller.createAndSendMessage(this.message);
background.setFill(Color.BLACK);
}

private void setCardId() {
int newId = card.getId();
cardId.setText(String.format("CardId = %d", newId));
}

private void setCardLabels() {
for(String key : this.card.getProperties().keySet()) {
if (key.equals("SICKNESS")) {

} else if (key.equals("ATTACK")) {
strength.setText(this.card.getProperties().get(key).toString());
} else if (key.equals("HEALTH")) {
health.setText(this.card.getProperties().get(key).toString());
} else if (key.equals("ATTACK_AVAILABLE")) {

}
}
}

//Boilerplate code
@Override
public void initialize(URL url, ResourceBundle rb) {
// TODO
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ public CardHandDocumentController(CardInfoMessage message, GameClientController
this.setCardId();
this.setCardLabels();
}

public CardInfoMessage getCard() {
return this.card;
}

public AnchorPane getRootPane() {
return this.anchorPane;
Expand All @@ -62,6 +66,7 @@ public void setCardActive(UseableActionMessage message) {
private void actionOnClick(MouseEvent event) {
System.out.println("Action detected on card" + this.cardId.textProperty());
this.controller.createAndSendMessage(this.message);
background.setFill(Color.BLACK);
}

private void setCardId() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,11 +245,11 @@ private void assignZoneIdForZoneMessage(ZoneMessage message) {
if (message.getName().equals("Battlefield")) {
if(message.getOwner() == this.playerId) {
this.playerBattlefieldId = message.getId();
this.zoneViewMap.put(message.getId(), new ZoneView(message.getId(), playerBattlefieldPane));
this.zoneViewMap.put(message.getId(), new BattlefieldZoneView(message.getId(), playerBattlefieldPane));

} else {
this.opponentBattlefieldId = message.getId();
this.zoneViewMap.put(message.getId(), new ZoneView(message.getId(), opponentBattlefieldPane));
this.zoneViewMap.put(message.getId(), new BattlefieldZoneView(message.getId(), opponentBattlefieldPane));
}
} else if (message.getName().equals("Hand")) {
if (message.getOwner() == this.playerId) {
Expand Down Expand Up @@ -287,6 +287,9 @@ private void processCardInfoMessage(CardInfoMessage message) {
}
}
private void addCardToOpponentBattlefieldPane(CardInfoMessage message) {
BattlefieldZoneView opponentBattlefield = (BattlefieldZoneView)this.zoneViewMap.get(opponentBattlefieldId);
CardBattlefieldDocumentController card = new CardBattlefieldDocumentController(message, this);
opponentBattlefield.addCardHandController(message.getId(), card);
}
private void addCardToOpponentHandPane(CardInfoMessage message) {
}
Expand Down Expand Up @@ -346,13 +349,14 @@ private void processZoneChangeMessage(ZoneChangeMessage message) {
if (this.zoneViewMap.containsKey(sourceZoneId) && this.zoneViewMap.containsKey(destinationZoneId)) {

if (sourceZoneId == opponentHandId) {

} else if (sourceZoneId == playerHandId) {
PlayerHandZoneView sourceZone = (PlayerHandZoneView)this.zoneViewMap.get(sourceZoneId);
CardHandDocumentController card = sourceZone.getCardHandController(cardId);
CardBattlefieldDocumentController newCard = new CardBattlefieldDocumentController(card.getCard(), this);

ZoneView destinationZone = this.zoneViewMap.get(destinationZoneId);
destinationZone.addPane(cardId, card.getRootPane());
BattlefieldZoneView destinationZone = (BattlefieldZoneView)this.zoneViewMap.get(destinationZoneId);
destinationZone.addCardHandController(cardId, newCard);

sourceZone.removeCardHandDocumentController(cardId);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>

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

<AnchorPane fx:id="anchorPane" prefHeight="112.0" prefWidth="85.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
<children>

<!-- Card Background -->
<Rectangle fx:id="background" arcHeight="5.0" arcWidth="5.0" height="116.0" layoutY="-3.0" stroke="BLACK" strokeType="INSIDE" width="89.0" />

<!-- 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">
<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 =" />
<Label fx:id="cardType" layoutX="12.0" layoutY="20.0" text="Type" />
<Label fx:id="creatureType" layoutX="12.0" layoutY="36.0" text="Type" textFill="WHITE" />

</children>
</AnchorPane>
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,18 @@

<!-- temporary action box -->
<HBox fx:id="actionBox" alignment="CENTER" layoutX="14.0" layoutY="580.0" nodeOrientation="LEFT_TO_RIGHT" prefHeight="25.0" prefWidth="1107.0" scaleShape="false" spacing="10" />
<AnchorPane layoutX="239.0" layoutY="211.0" prefHeight="98.0" prefWidth="810.0">
<AnchorPane layoutX="239.0" layoutY="237.0" prefHeight="132.0" prefWidth="810.0">
<children>
<Rectangle arcHeight="5.0" arcWidth="5.0" fill="#b0d9ff" height="99.0" stroke="BLACK" strokeType="INSIDE" width="810.0" />
<Rectangle arcHeight="5.0" arcWidth="5.0" fill="#b0d9ff" height="132.0" stroke="BLACK" strokeType="INSIDE" width="810.0" />

<!-- Battlefields -->
<HBox fx:id="playerBattlefieldPane" prefHeight="98.0" prefWidth="809.0" spacing="10.0" />
<HBox fx:id="playerBattlefieldPane" layoutX="19.0" layoutY="11.0" prefHeight="110.0" prefWidth="772.0" spacing="10.0" />
</children>
</AnchorPane>
<AnchorPane layoutX="239.0" layoutY="105.0" prefHeight="98.0" prefWidth="809.0">
<children>
<Rectangle arcHeight="5.0" arcWidth="5.0" fill="#f59782" height="99.0" stroke="BLACK" strokeType="INSIDE" width="810.0" />
<HBox fx:id="opponentBattlefieldPane" layoutX="1.0" layoutY="1.0" prefHeight="98.0" prefWidth="809.0" spacing="10.0" />
<Rectangle arcHeight="5.0" arcWidth="5.0" fill="#f59782" height="127.0" stroke="BLACK" strokeType="INSIDE" width="810.0" />
<HBox fx:id="opponentBattlefieldPane" layoutX="19.0" layoutY="9.0" prefHeight="110.0" prefWidth="772.0" spacing="10.0" />
</children>
</AnchorPane>

Expand Down

0 comments on commit 209f684

Please sign in to comment.