Skip to content

Commit

Permalink
bug fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
alrz1999 committed Jul 8, 2019
1 parent dba9fdf commit dabf80e
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 57 deletions.
49 changes: 22 additions & 27 deletions src/client/ResponseHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import controller.fxmlControllers.LoginPageController;
import javafx.application.Platform;
import javafx.fxml.FXMLLoader;
import javafx.scene.control.Alert;
import models.Game;
import server.Response;

Expand Down Expand Up @@ -76,6 +77,8 @@ private void handleLoginPageResponse() {
}

private void handleCollectionResponse() {
if (response.getCollection() != null)
CollectionFxmlController.setCollection(response.getCollection());
switch (response.getResponseType()) {
case CREATE_DECK_SUCCESSFULLY:
Platform.runLater(() -> collectionController.decks.getItems().add(response.getDeckToAdd()));
Expand All @@ -84,49 +87,41 @@ private void handleCollectionResponse() {
removeDeck(response.getDeckToRemove());
break;
case DUPLICATE_DECK:
Platform.runLater(() -> collectionController.makeAlert("Error while making deck", "This name was used before!"));
Platform.runLater(() -> collectionController.makeAlert("Error while making deck", "This name was used before!", Alert.AlertType.ERROR));
break;
case MORE_THAN_ONE_HERO_ERROR:
case MORE_THAN_20_NORMAL_CARD_ERROR:
case MORE_THAN_ONE_ITEM_ERROR:
Platform.runLater(() -> collectionController.makeAlert("Error while adding cards to deck", response.getResponseType().getMessage()));
Platform.runLater(() -> collectionController.makeAlert("Error while adding cards to deck", response.getResponseType().getMessage(), Alert.AlertType.ERROR));
break;
case SUCCESSFULLY_MOVE_CARD_TO_DECK:
addCardToDeck();
break;
case SUCCESSFULLY_REMOVE_CARD_FROM_DECK:
removeCardFromDeck();
Platform.runLater(() -> collectionController.updateDeckCards());
break;
case MAIN_DECK_SELECTED:
Platform.runLater(() -> collectionController.makeAlert("new main deck selected", null));
Platform.runLater(() -> collectionController.makeAlert("new main deck selected", null, Alert.AlertType.INFORMATION));
break;
case ENTER_COLLECTION:
Platform.runLater(new Runnable() {
@Override
public void run() {
CollectionFxmlController.setCollection(response.getCollection());
FXMLLoader loader = new FXMLLoader(getClass().getResource("/view/fxmls/collectionPage.fxml"));
try {
Main.getStage().getScene().setRoot(loader.load());
} catch (IOException e) {
e.printStackTrace();
}
ResponseHandler.getInstance().setCollectionController(loader.getController());
}
});


loadCollection();
}

}

private void removeCardFromDeck() {

private void loadCollection() {
Platform.runLater(new Runnable() {
@Override
public void run() {
CollectionFxmlController.setCollection(response.getCollection());
FXMLLoader loader = new FXMLLoader(getClass().getResource("/view/fxmls/collectionPage.fxml"));
try {
Main.getStage().getScene().setRoot(loader.load());
} catch (IOException e) {
e.printStackTrace();
}
ResponseHandler.getInstance().setCollectionController(loader.getController());
}
});
}

private void addCardToDeck() {

}

private void removeDeck(String deckToRemove) {
Platform.runLater(() -> {
Expand Down
38 changes: 27 additions & 11 deletions src/controller/fxmlControllers/CollectionFxmlController.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,6 @@ private void addCardToDeckBtn() {
for (CardContainer cardContainer : collectionCards) {
if (cardContainer.getCheckBox().isSelected()) {
selectedCards.add(cardContainer.getCard().getName());
//todo
setCardContainer(cardContainer.getCard(), deckCardsFlowPane, deckCards);
collection.getDeck(decks.getValue()).addToDeck(cardContainer.getCard());
//todo
}
}
request.setCardsToAddToDeck(selectedCards);
Expand All @@ -114,23 +110,29 @@ private void selectMainDeckBtn() {
setMainDeckButton.setOnAction(event -> {
if (decks.getValue() == null)
return;
collection.selectMainDeck(decks.getValue());
Request request = new Request(Environment.COLLECTION);
request.setRequestType(RequestType.SELECT_MAIN_DECK);
request.setMainDeck(decks.getValue());
RequestSender.getInstance().sendRequest(request);
});
}

private void removeCardFromDeckBtn() {
removeFromDeckButton.setOnAction(event -> {
if (decks.getValue() == null)
return;
Deck selectedDeck = collection.getDeck(decks.getValue());
Request request = new Request(Environment.COLLECTION);
request.setRequestType(RequestType.REMOVE_CARD_FROM_DECK);
request.setDeckToRemoveCardFrom(decks.getValue());
ArrayList<String> cards = new ArrayList<>();

for (CardContainer card : deckCards) {
if (card.getCheckBox().isSelected()) {
selectedDeck.removeFromDeck(card.getCard());
deckCardsFlowPane.getChildren().remove(card.getAnchorPane());
cards.add(card.getCard().getName());
}
}
deckCards.removeIf(cardContainer -> cardContainer.getCheckBox().isSelected());
request.setCardsToRemoveFromDeck(cards);
RequestSender.getInstance().sendRequest(request);
});
}

Expand Down Expand Up @@ -182,6 +184,15 @@ private void showSelectedDeckCards() {
};

decks.setOnAction(eventEventHandler);
addCardToDeckButton.setOnAction(eventEventHandler);
}

public void updateDeckCards(){
deckCardsFlowPane.getChildren().clear();
deckCards = new ArrayList<>();
for (Placeable card : collection.getDeck(decks.getValue()).getDeckCards()) {
setCardContainer(card, deckCardsFlowPane, deckCards);
}
}

public static void setCollection(Collection collection1) {
Expand All @@ -199,12 +210,17 @@ public void backAction() {



public void makeAlert(String headerText, String contentText) {
Alert alert = new Alert(Alert.AlertType.ERROR);
public void makeAlert(String headerText, String contentText,Alert.AlertType alertType) {
Alert alert = new Alert(alertType);
alert.setTitle("Error");
alert.setHeaderText(headerText);
alert.setContentText(contentText);
alert.showAndWait();
}

public static Collection getCollection() {
return collection;
}


}
5 changes: 3 additions & 2 deletions src/controller/logicController/CollectionController.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public void createDeck(String deckName, ResponseSender responseSender) {
} catch (Exceptions.DuplicateNameForDeck duplicateNameForDeck) {
response.setResponseType(ResponseType.DUPLICATE_DECK);
}
response.setCollection(collection);
responseSender.sendResponse(response);
}

Expand Down Expand Up @@ -179,19 +180,19 @@ public void addCardToDeck(Request request, ResponseSender responseSender) {
}
}
//todo maybe need to add deck arraylist to the response
response.setCollection(collection);
responseSender.sendResponse(response);
}

public void removeCardFromDeck(Request request, ResponseSender responseSender) {
Response response = new Response(Environment.COLLECTION);
response.setResponseType(ResponseType.SUCCESSFULLY_REMOVE_CARD_FROM_DECK);
response.setDeckToRemoveCardFrom(request.getDeckToRemoveCardFrom());
response.setCardsToRemoveFromDeck(request.getCardsToRemoveFromDeck());
ArrayList<String> cards = request.getCardsToRemoveFromDeck();
Deck deck = collection.getDeck(request.getDeckToRemoveCardFrom());
for (String card : cards) {
deck.removeFromDeck(card);
}
response.setCollection(collection);
responseSender.sendResponse(response);
}

Expand Down
6 changes: 5 additions & 1 deletion src/models/Deck.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,12 @@ public void removeFromDeck(String name) {
cards.remove(card);
break;
}

}
if (hero != null && hero.getName().equals(name)){
hero = null;
}
if (item != null && item.getName().equals(name))
item = null;
}

/**
Expand Down
32 changes: 16 additions & 16 deletions src/view/fxmls/wrapperClasses/CardContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.AnchorPane;
import models.Card;
import models.Placeable;
import models.Shop;
import models.Spell;
import models.*;


public class CardContainer {
Expand Down Expand Up @@ -57,7 +54,7 @@ private CardContainer(String name) {
healthPointLabel.setLayoutX(200);
healthPointLabel.setLayoutY(214);

nameLabel = new Label(name);
nameLabel = new Label(name+"\n"+c.getClass().getSimpleName());
nameLabel.setStyle("-fx-font-size: 18px;-fx-text-fill: white;-fx-text-alignment: center;-fx-text-overrun: ELLIPSIS;-fx-alignment: center;" +
"-fx-pref-width: 290;-fx-pref-height: 86;-fx-font-weight: bold");
nameLabel.setLayoutX(6);
Expand All @@ -71,18 +68,21 @@ private CardContainer(String name) {
checkBox.setLayoutY(390);
checkBox.setStyle("-fx-font-size: 20");

imageView = new ImageView(new Image(c.getPath()));
imageView.setFitHeight(191);
imageView.setFitWidth(235);
imageView.setX(40);
imageView.setY(10);
if (!(c instanceof Spell)) {
imageView.setScaleX(1.5);
imageView.setScaleY(1.5);
}


anchorPane.getChildren().addAll(manaLabel, attackPointLabel, healthPointLabel, nameLabel, checkBox,imageView);
if (!(c instanceof Item)) {
imageView = new ImageView(new Image(c.getPath()));
imageView.setFitHeight(191);
imageView.setFitWidth(235);
imageView.setX(40);
imageView.setY(10);
if (!(c instanceof Spell)) {
imageView.setScaleX(1.5);
imageView.setScaleY(1.5);
}
anchorPane.getChildren().addAll(manaLabel, attackPointLabel, healthPointLabel, nameLabel, checkBox, imageView);
}else {
anchorPane.getChildren().addAll(manaLabel, attackPointLabel, healthPointLabel, nameLabel, checkBox);
}


}
Expand Down

0 comments on commit dabf80e

Please sign in to comment.