diff --git a/src/client/ResponseHandler.java b/src/client/ResponseHandler.java index 5ef966b..d0fdb77 100644 --- a/src/client/ResponseHandler.java +++ b/src/client/ResponseHandler.java @@ -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()); @@ -119,6 +134,7 @@ public void run() { }); } + private void removeDeck(String deckToRemove) { Platform.runLater(() -> { collectionController.decks.getItems().remove(deckToRemove); @@ -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() { diff --git a/src/controller/fxmlControllers/MainMenuController.java b/src/controller/fxmlControllers/MainMenuController.java index 38d0f6c..28027b2 100644 --- a/src/controller/fxmlControllers/MainMenuController.java +++ b/src/controller/fxmlControllers/MainMenuController.java @@ -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() { @@ -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); diff --git a/src/server/RequestHandler.java b/src/server/RequestHandler.java index c096628..e56e431 100644 --- a/src/server/RequestHandler.java +++ b/src/server/RequestHandler.java @@ -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); diff --git a/src/server/ResponseType.java b/src/server/ResponseType.java index 4adb598..35a0890 100644 --- a/src/server/ResponseType.java +++ b/src/server/ResponseType.java @@ -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; diff --git a/src/view/fxmls/wrapperClasses/CardContainer.java b/src/view/fxmls/wrapperClasses/CardContainer.java index 1866a95..f9b0841 100644 --- a/src/view/fxmls/wrapperClasses/CardContainer.java +++ b/src/view/fxmls/wrapperClasses/CardContainer.java @@ -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);