Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/client/ResponseHandler.java
#	src/server/ResponseType.java
#	src/view/fxmls/wrapperClasses/CardContainer.java
  • Loading branch information
AhmadZafarani committed Jul 8, 2019
2 parents b5ba5da + fc00b1c commit 2523c7e
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 9 deletions.
39 changes: 38 additions & 1 deletion src/client/ResponseHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,27 @@ private void handleResponse() {

private void handleLoginPageResponse() {
if (response.getResponseType().equals(SUCCESSFUL_SIGN_IN)) {
Platform.runLater(() -> Main.getStage().getScene().setRoot(Main.getMainMenu()));
loadMainMenu();
Main.setToken(response.getAuthToken());
} else
Platform.runLater(() -> Main.getLoginPageController().appearLabel(((ResponseType) response.getResponseType()).getMessage()));
}

private void loadMainMenu() {
Platform.runLater(new Runnable() {
@Override
public void run() {
FXMLLoader loader = new FXMLLoader(getClass().getResource("/view/fxmls/mainMenu.fxml"));
mainMenuController = loader.getController();
try {
Main.getStage().getScene().setRoot(loader.load());
} catch (IOException e) {
e.printStackTrace();
}
}
});
}

private void handleCollectionResponse() {
if (response.getCollection() != null)
CollectionFxmlController.setCollection(response.getCollection());
Expand Down Expand Up @@ -119,6 +134,7 @@ public void run() {
});
}


private void removeDeck(String deckToRemove) {
Platform.runLater(() -> {
collectionController.decks.getItems().remove(deckToRemove);
Expand All @@ -129,7 +145,28 @@ private void removeDeck(String deckToRemove) {
}

private void handleBattleResponse() {
switch (response.getResponseType()) {
case MAIN_DECK_IS_VALID:
loadBattleMenu();
break;
case MAIN_DECK_IS_NOT_VALID:
Platform.runLater(() -> mainMenuController.appearLabel(response.getResponseType().getMessage()));
break;
}
}

private void loadBattleMenu() {
Platform.runLater(new Runnable() {
@Override
public void run() {
FXMLLoader loader = new FXMLLoader(getClass().getResource("/view/fxmls/battleMenu.fxml"));
try {
Main.getStage().getScene().setRoot(loader.load());
} catch (IOException e) {
e.printStackTrace();
}
}
});
}

private void handleShopResponse() {
Expand Down
10 changes: 4 additions & 6 deletions src/controller/fxmlControllers/MainMenuController.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,9 @@ private void exit() {
}

private void goToBattle() {
if (!accountController.getAccount().isReadyToPlay()) {
appearLabel(ErrorType.MAIN_DECK_IS_NOT_VALID.getMessage());
return;
}
Game.getInstance().loadPage(exitButton, "/view/fxmls/battleMenu.fxml");
Request request = new Request(Environment.MAIN_MENU);
request.setRequestType(RequestType.ENTER_BATTLE);
RequestSender.getInstance().sendRequest(request);
}

private void logout() {
Expand All @@ -75,7 +73,7 @@ private void showMatchHistories() {
Game.getInstance().loadPage(exitButton, "/view/fxmls/matchHistories.fxml");
}

private void appearLabel(String text) {
public void appearLabel(String text) {
error.setText(text);
error.setStyle("-fx-background-color: rgba(255, 212, 134, 0.48)");
error.setVisible(true);
Expand Down
11 changes: 11 additions & 0 deletions src/server/RequestHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,20 @@ private void handleMainMenuRequest(Request request) {
case ENTER_COLLECTION:
sendCollection(request);
break;
case ENTER_BATTLE:
enterBattle(request);
}
}

private void enterBattle(Request request) {
Response response = new Response(Environment.BATTLE);
if (Main.getOnlineAccounts().get(request.getOuthToken()).isReadyToPlay())
response.setResponseType(ResponseType.MAIN_DECK_IS_VALID);
else
response.setResponseType(ResponseType.MAIN_DECK_IS_NOT_VALID);
responseSender.sendResponse(response);
}

private void sendCollection(Request request) {
Response response = new Response(Environment.COLLECTION);
response.setResponseType(ResponseType.ENTER_COLLECTION);
Expand Down
5 changes: 5 additions & 0 deletions src/server/ResponseType.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ public enum ResponseType {
SEARCH_IN_SHOP(""),
GET_SHOP_CARDS(""),
SUCCESSFULL_SELL("you bought\n")
ENTER_SHOP("enter shop"),
//battle responses
MAIN_DECK_IS_NOT_VALID("selected deck is invalid"),
MAIN_DECK_IS_VALID("choose single player or multi player"),

;
private String message;

Expand Down
2 changes: 0 additions & 2 deletions src/view/fxmls/wrapperClasses/CardContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,6 @@ public void createContainer(Placeable c) {
checkBox.setLayoutX(21);
checkBox.setLayoutY(390);
checkBox.setStyle("-fx-font-size: 20");


if (!(c instanceof Item)) {
imageView = new ImageView(new Image(c.getPath()));
imageView.setFitHeight(191);
Expand Down

0 comments on commit 2523c7e

Please sign in to comment.