-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added Battlefield ZoneView and DocumetnController
- Loading branch information
Showing
6 changed files
with
189 additions
and
10 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
cardshifter-fx/src/main/java/com/cardshifter/client/BattlefieldZoneView.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
|
||
} |
88 changes: 88 additions & 0 deletions
88
cardshifter-fx/src/main/java/com/cardshifter/client/CardBattlefieldDocumentController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
cardshifter-fx/src/main/resources/com/cardshifter/client/CardBattlefieldDocument.fxml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters