From fbbab9c3ed1d3363c0efff48823b42c1a15930ba Mon Sep 17 00:00:00 2001 From: elahe Date: Wed, 3 Feb 2021 15:29:18 +0330 Subject: [PATCH] menus done --- .../Controller/Menus/EventPageController.java | 2 +- .../Menus/EventSettingsController.java | 89 +++++-------------- .../Controller/Menus/EventsTabController.java | 88 ++++++------------ .../Menus/FriendProfileController.java | 23 ----- ...FriendRequestManagementPageController.java | 52 +++++++---- .../Menus/FriendsTabController.java | 14 ++- src/com/plato/Controller/Server.java | 14 ++- 7 files changed, 103 insertions(+), 179 deletions(-) diff --git a/src/com/plato/Controller/Menus/EventPageController.java b/src/com/plato/Controller/Menus/EventPageController.java index ef9b407..f6b3730 100644 --- a/src/com/plato/Controller/Menus/EventPageController.java +++ b/src/com/plato/Controller/Menus/EventPageController.java @@ -43,7 +43,7 @@ public void initialize (URL location, ResourceBundle resources) { } public void joinEvent (String eventID) throws IOException { - dataOutputStream.writeUTF("participateInEvent"); + dataOutputStream.writeUTF("participateInEvent_" + eventID); dataOutputStream.flush(); //EventController.getInstance().participateInEvent(eventID); } diff --git a/src/com/plato/Controller/Menus/EventSettingsController.java b/src/com/plato/Controller/Menus/EventSettingsController.java index 4726e02..7784e25 100644 --- a/src/com/plato/Controller/Menus/EventSettingsController.java +++ b/src/com/plato/Controller/Menus/EventSettingsController.java @@ -1,6 +1,5 @@ package Controller.Menus; -import Controller.MainController; import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.StringProperty; import javafx.event.ActionEvent; @@ -10,7 +9,8 @@ import javafx.scene.layout.GridPane; import javafx.stage.Stage; -import java.awt.event.MouseEvent; +import java.io.DataInputStream; +import java.io.DataOutputStream; import java.net.URL; import java.util.ResourceBundle; @@ -21,31 +21,8 @@ public class EventSettingsController implements Initializable { public MenuButton eventTypeMenu, gameMenu, minReqMenu; public GridPane gridPane; private StringProperty eventSettings; - private MouseEvent mouseEvent; - private ActionEvent actionEvent; - - - - public EventSettingsController() { - this.mouseEvent = null; - this.actionEvent = null; - } - - public MouseEvent getMouseEvent() { - return mouseEvent; - } - - public void setMouseEvent(MouseEvent mouseEvent) { - this.mouseEvent = mouseEvent; - } - - public void setActionEvent(ActionEvent actionEvent) { - this.actionEvent = actionEvent; - } - - public ActionEvent getActionEvent() { - return actionEvent; - } + private DataInputStream dataInputStream; + private DataOutputStream dataOutputStream; public static void setStage (Stage stage) { EventSettingsController.stage = stage; @@ -99,7 +76,7 @@ private String getEventSettingsAsString () { return "%s|%s|%s".formatted(eventTypeMenu.getText(), gameMenu.getText(), minReqMenu.getText()); } - public void isLoginTimes () { + public void isLoginTimes (ActionEvent actionEvent) { gameMenu.setVisible(false); minReqMenu.setVisible(true); @@ -113,39 +90,27 @@ public void isLoginTimes () { }}); } - resetPageWrite(getActionEvent()); - } - public void isLoginTimesWrite(ActionEvent actionEvent) { - setActionEvent(actionEvent); - MainController.write("EventSettings.isLoginTimes"); + resetPage(actionEvent); } - public void resetPage () { + + public void resetPage (ActionEvent actionEvent) { minReqMenu.setText("Minimum Requirement"); gameMenu.setText("Game name"); eventTypeMenu.setText(((MenuItem) actionEvent.getSource()).getText()); } - public void resetPageWrite(ActionEvent actionEvent) { - setActionEvent(actionEvent); - MainController.write("EventSettings.resetPage"); - } - public void closeStage () { + + public void closeStage (ActionEvent actionEvent) { stage.close(); } - public void closeStageWrite(ActionEvent actionEvent) { - setActionEvent(actionEvent); - MainController.write("EventSettings.closeStage"); - } - public void isMVPInGame () { + + public void isMVPInGame (ActionEvent actionEvent) { gameMenu.setVisible(true); minReqMenu.setVisible(false); - resetPageWrite(getActionEvent()); - } - public void isMVPInGameWrite(ActionEvent actionEvent) { - setActionEvent(actionEvent); - MainController.write("EventSettings.isMVPInGame"); + resetPage(actionEvent); } - public void isPlayTimes () { + + public void isPlayTimes (ActionEvent actionEvent) { minReqMenu.setVisible(true); gameMenu.setVisible(true); @@ -159,13 +124,10 @@ public void isPlayTimes () { }}); } - resetPageWrite(getActionEvent()); - } - public void isPlayTimeWrite(ActionEvent actionEvent) { - setActionEvent(actionEvent); - MainController.write("EventSettings.isPlayTimes"); + resetPage(actionEvent); } - public void isWinTimes () { + + public void isWinTimes (ActionEvent actionEvent) { minReqMenu.setVisible(true); gameMenu.setVisible(true); @@ -179,13 +141,10 @@ public void isWinTimes () { }}); } - resetPageWrite(getActionEvent()); + resetPage(actionEvent); } - public void isWinTimesWrite(ActionEvent actionEvent) { - setActionEvent(actionEvent); - MainController.write("EventSettings.isWinTimes"); - } - public void isWinTimesNonStop () { + + public void isWinTimesNonStop (ActionEvent actionEvent) { minReqMenu.setVisible(true); gameMenu.setVisible(true); @@ -199,10 +158,6 @@ public void isWinTimesNonStop () { }}); } - resetPageWrite(getActionEvent()); - } - public void isWinTimesNonStopWrite(ActionEvent actionEvent) { - setActionEvent(actionEvent); - MainController.write("EventSettings.isWinTimesNonStop"); + resetPage(actionEvent); } } diff --git a/src/com/plato/Controller/Menus/EventsTabController.java b/src/com/plato/Controller/Menus/EventsTabController.java index 99c127d..6d1cb66 100644 --- a/src/com/plato/Controller/Menus/EventsTabController.java +++ b/src/com/plato/Controller/Menus/EventsTabController.java @@ -3,6 +3,7 @@ import Controller.AccountRelated.AccountController; import Controller.AccountRelated.EventController; import Controller.MainController; +import Model.AccountRelated.Account; import Model.AccountRelated.Event; import Model.AccountRelated.Gamer; import com.google.gson.Gson; @@ -46,42 +47,21 @@ public class EventsTabController implements Initializable { public ListView eventsList; public Pane eventInfo; public GridPane gridPane; - private MouseEvent mouseEvent; - private ActionEvent actionEvent; private static DataOutputStream dataOutputStream; private static DataInputStream dataInputStream; private static Socket socket; + private Object Account; - public EventsTabController() { - this.mouseEvent = null; - this.actionEvent = null; - } - - public MouseEvent getMouseEvent() { - return mouseEvent; - } - - public ActionEvent getActionEvent() { - return actionEvent; - } - - public void setMouseEvent(MouseEvent mouseEvent) { - this.mouseEvent = mouseEvent; - } - - public void setActionEvent(ActionEvent actionEvent) { - this.actionEvent = actionEvent; - } - public static void setGamerOrAdmin (boolean gamerOrAdmin) { EventsTabController.gamerOrAdmin = gamerOrAdmin; } - public void filter (ActionEvent actionEvent) { + public void filter (ActionEvent actionEvent) throws IOException { LinkedList eventsToShow; - // TODO: 2/3/2021 - Gamer gamer = (Gamer) AccountController.getInstance().getCurrentAccLoggedIn(); + dataOutputStream.writeUTF("getCurrentAccLoggedIn_"); + dataOutputStream.flush(); + Gamer gamer = (Gamer) new Gson().fromJson(dataInputStream.readUTF() , (Type) Account); String showWhich = (showInSession.isSelected() ? "y" : "n") + (showUpcoming.isSelected() ? "y" : "n") + (showParticipatingIn.isSelected() ? "y" : "n"); @@ -97,10 +77,8 @@ public void filter (ActionEvent actionEvent) { updateList(Event.getSortedEvents(eventsToShow)); } - public void filterWrite(ActionEvent actionEvent) { - MainController.write("EventsTab.filter"); - } - public void createEvent () { + + public void createEvent (ActionEvent actionEvent) { try { EventCreateOrEditPageController.setIsForCreateOrInfo(true); Stage stage = MainController.getInstance().createAndReturnNewStage( @@ -115,10 +93,7 @@ public void createEvent () { e.printStackTrace(); } } - public void createEventWrite(ActionEvent actionEvent) { - setActionEvent(actionEvent); - MainController.write("EventsTab.createEvent"); - } + @Override public void initialize (URL location, ResourceBundle resources) { if (gamerOrAdmin) @@ -195,51 +170,51 @@ public void updateList (LinkedList eventsToShow) { new Button() {{ try { dataOutputStream.writeUTF("getCurrentAccLoggedIn"); - } catch (IOException e) { - e.printStackTrace(); - } - try { dataOutputStream.flush(); } catch (IOException e) { e.printStackTrace(); } Gamer currentLoggedIn = null; // TODO: 2/3/2021 - // currentLoggedIn = (Gamer) new Gson().fromJson(dataInputStream.readUTF(), (Type) Account); + try { + currentLoggedIn = (Gamer) new Gson().fromJson(dataInputStream.readUTF(), (Type) Account); + } catch (IOException exception) { + exception.printStackTrace(); + } ; // is already participating in event if (event.participantExists(currentLoggedIn.getUsername())) { setText("Drop-out"); setOnAction(e -> { try { - dataOutputStream.writeUTF("stopParticipatingInEvent"); + dataOutputStream.writeUTF("stopParticipatingInEvent_" + event.getEventID()); + dataOutputStream.flush(); } catch (IOException exception) { exception.printStackTrace(); } + //EventController.getInstance().stopParticipatingInEvent(event.getEventID()); try { - dataOutputStream.flush(); + filter(new ActionEvent()); } catch (IOException exception) { exception.printStackTrace(); } - EventController.getInstance().stopParticipatingInEvent(event.getEventID()); - filter(new ActionEvent()); }); } else { setText("Join"); setOnAction(e -> { try { - dataOutputStream.writeUTF("participateInEvent"); + dataOutputStream.writeUTF("participateInEvent_"); + dataOutputStream.flush(); } catch (IOException exception) { exception.printStackTrace(); } + //EventController.getInstance().participateInEvent(event.getEventID()); try { - dataOutputStream.flush(); + filter(new ActionEvent()); } catch (IOException exception) { exception.printStackTrace(); } - //EventController.getInstance().participateInEvent(event.getEventID()); - filter(new ActionEvent()); }); } @@ -311,8 +286,9 @@ public void updateList (LinkedList eventsToShow) { } private void removeEvent (Event event) throws IOException { - - Event.removeEvent(event.getEventID()); + dataOutputStream.writeUTF("removeEvent_" + event.getEventID()); + dataOutputStream.flush(); + // Event.removeEvent(event.getEventID()); filter(new ActionEvent()); } @@ -342,20 +318,12 @@ private void displayEventInfo (Event event) { } } - public void mouseIsOut () { + public void mouseIsOut (MouseEvent mouseEvent) { ((Button) mouseEvent.getSource()).setOpacity(0.8); } - public void mouseIsOutWrite(MouseEvent mouseEvent) { - setMouseEvent(mouseEvent); - MainController.write("EventsTab.mouseIsOut"); - } - public void mouseIsOver () { - ((Button) getMouseEvent().getSource()).setOpacity(1); - } - public void mouseIsOverWrite(MouseEvent mouseEvent) { - setMouseEvent(mouseEvent); - MainController.write("EventsTab.mouseIsOver"); + public void mouseIsOver (MouseEvent mouseEvent) { + ((Button) mouseEvent.getSource()).setOpacity(1); } } diff --git a/src/com/plato/Controller/Menus/FriendProfileController.java b/src/com/plato/Controller/Menus/FriendProfileController.java index aceaf05..838de84 100644 --- a/src/com/plato/Controller/Menus/FriendProfileController.java +++ b/src/com/plato/Controller/Menus/FriendProfileController.java @@ -26,34 +26,11 @@ public class FriendProfileController implements Initializable { public Label reversiDraws, reversiScore, reversiWins, reversiLosses; public Label battleseaScore, battleseaWins, battleseaLosses, battleseaDraws; public ImageView pfp; - private MouseEvent mouseEvent; - private ActionEvent actionEvent; private static DataOutputStream dataOutputStream; private static DataInputStream dataInputStream; private static Socket socket; - public FriendProfileController() { - this.mouseEvent = null; - this.actionEvent = null; - } - - public MouseEvent getMouseEvent() { - return mouseEvent; - } - - public ActionEvent getActionEvent() { - return actionEvent; - } - - public void setMouseEvent(MouseEvent mouseEvent) { - this.mouseEvent = mouseEvent; - } - - public void setActionEvent(ActionEvent actionEvent) { - this.actionEvent = actionEvent; - } - public static Gamer getFrnd () { return frnd; } diff --git a/src/com/plato/Controller/Menus/FriendRequestManagementPageController.java b/src/com/plato/Controller/Menus/FriendRequestManagementPageController.java index 09dacc6..65b7495 100644 --- a/src/com/plato/Controller/Menus/FriendRequestManagementPageController.java +++ b/src/com/plato/Controller/Menus/FriendRequestManagementPageController.java @@ -43,7 +43,6 @@ public class FriendRequestManagementPageController implements Initializable { private static DataOutputStream dataOutputStream; private static DataInputStream dataInputStream; private static Socket socket; - private Object Account; public static void setStage (Stage stage) { @@ -57,9 +56,9 @@ public void sendFriendReq (ActionEvent actionEvent) throws IOException { } private void updateAvailableGamersList () throws IOException { - dataOutputStream.writeUTF("getCurrentAccLoggedIn"); - dataOutputStream.flush(); - Gamer currentLoggedIn = (Gamer)new Gson().fromJson(dataInputStream.readUTF(), (Type) Account); +// dataOutputStream.writeUTF("getCurrentAccLoggedIn"); +// dataOutputStream.flush(); + Gamer currentLoggedIn = (Gamer) AccountController.getInstance().getCurrentAccLoggedIn(); availableForFrndReqList.getItems().clear(); for (Gamer gamer : Gamer.getGamers(Gamer.getAvailableGamersForFrndReq(currentLoggedIn), search.getText())) { @@ -100,7 +99,13 @@ private void updateAvailableGamersList () throws IOException { setPadding(new Insets(2.5, 2.5, 2.5, 2.5)); setOnMouseEntered(e -> setOpacity(0.8)); setOnMouseExited(e -> setOpacity(1)); - setOnMouseClicked(e -> sendFriendReqDone(username.getText())); + setOnMouseClicked(e -> { + try { + sendFriendReqDone(username.getText()); + } catch (IOException exception) { + exception.printStackTrace(); + } + }); }}; circle.setCenterX(pfp.getFitHeight() / 2); @@ -113,18 +118,24 @@ private void updateAvailableGamersList () throws IOException { } } - private void sendFriendReqDone (String usernameTo) { - FriendRequestController.getInstance().sendFrndRequest(usernameTo); + private void sendFriendReqDone (String usernameTo) throws IOException { + dataOutputStream.writeUTF("sendFrndRequest_" + usernameTo); + dataOutputStream.flush(); + // FriendRequestController.getInstance().sendFrndRequest(usernameTo); availableForFrndReqList.getItems().removeIf(item -> ((Label) item.getChildren().get(1)).getText().equals(usernameTo)); } - private void declineFriendReq (String usernameFrom) { - FriendRequestController.getInstance().declineFriendReq(usernameFrom); + private void declineFriendReq (String usernameFrom) throws IOException { + dataOutputStream.writeUTF("declineFriendReq_" + usernameFrom); + dataOutputStream.flush(); + //FriendRequestController.getInstance().declineFriendReq(usernameFrom); frndReqsGottenList.getItems().removeIf(item -> ((Label) item.getChildren().get(1)).getText().equals(usernameFrom)); } - private void acceptFriendReq (String usernameFrom) { - FriendRequestController.getInstance().acceptFriendReq(usernameFrom); + private void acceptFriendReq (String usernameFrom) throws IOException { + dataOutputStream.writeUTF("acceptFriendReq_" + usernameFrom); + dataOutputStream.flush(); + //FriendRequestController.getInstance().acceptFriendReq(usernameFrom); frndReqsGottenList.getItems().removeIf(item -> ((Label) item.getChildren().get(1)).getText().equals(usernameFrom)); } @@ -139,8 +150,7 @@ public void initialize (URL url, ResourceBundle resourceBundle) { for (FriendRequest friendRequest : FriendRequest.getFriendReq(AccountController.getInstance().getCurrentAccLoggedIn().getUsername())) { - // TODO: 2/3/2021 - //Gamer gamerFrom = (Gamer) Account.getAccount(friendRequest.getFromUsername()); + Gamer gamerFrom = (Gamer) Account.getAccount(friendRequest.getFromUsername()); Circle circle = new Circle(50); @@ -180,7 +190,13 @@ public void initialize (URL url, ResourceBundle resourceBundle) { setPadding(new Insets(5, 5, 5, 5)); setOnMouseEntered(e -> setOpacity(0.8)); setOnMouseExited(e -> setOpacity(1)); - setOnMouseClicked(e -> acceptFriendReq(username.getText())); + setOnMouseClicked(e -> { + try { + acceptFriendReq(username.getText()); + } catch (IOException exception) { + exception.printStackTrace(); + } + }); }}; Button declineBtn = new Button() {{ setStyle("-fx-background-image: url('https://i.imgur.com/kMFxd9Q.png');" + @@ -191,7 +207,13 @@ public void initialize (URL url, ResourceBundle resourceBundle) { setPadding(new Insets(5, 5, 5, 5)); setOnMouseEntered(e -> setOpacity(0.8)); setOnMouseExited(e -> setOpacity(1)); - setOnMouseClicked(e -> declineFriendReq(username.getText())); + setOnMouseClicked(e -> { + try { + declineFriendReq(username.getText()); + } catch (IOException exception) { + exception.printStackTrace(); + } + }); }}; circle.setCenterX(pfp.getFitHeight() / 2); diff --git a/src/com/plato/Controller/Menus/FriendsTabController.java b/src/com/plato/Controller/Menus/FriendsTabController.java index b5d92b9..93842e6 100644 --- a/src/com/plato/Controller/Menus/FriendsTabController.java +++ b/src/com/plato/Controller/Menus/FriendsTabController.java @@ -39,8 +39,6 @@ public class FriendsTabController implements Initializable { public ListView frndsList; private static DataInputStream dataInputStream; private static DataOutputStream dataOutputStream; - private Object Account; - @Override public void initialize (URL url, ResourceBundle resourceBundle) { try { @@ -52,12 +50,11 @@ public void initialize (URL url, ResourceBundle resourceBundle) { public void updateFrndsList (ActionEvent actionEvent) throws IOException { frndsList.getItems().clear(); - dataOutputStream.writeUTF("getCurrentAccLoggedIn"); - dataOutputStream.flush(); - Gamer currentAccLoggedIn = (Gamer) new Gson().fromJson(dataInputStream.readUTF(), (Type) Account); +// dataOutputStream.writeUTF("getCurrentAccLoggedIn"); +// dataOutputStream.flush(); + Gamer currentAccLoggedIn = (Gamer) AccountController.getInstance().getCurrentAccLoggedIn(); for (String frndUN : currentAccLoggedIn.getFrnds()) { - // TODO: 2/3/2021 - //Gamer frndAcc = (Gamer) Account.getAccount(frndUN); + Gamer frndAcc = (Gamer) Account.getAccount(frndUN); Circle circle = new Circle(40); @@ -124,7 +121,7 @@ public void updateFrndsList (ActionEvent actionEvent) throws IOException { private void unfriend (String frndUN) throws IOException { dataOutputStream.writeUTF("removeFriend_"+frndUN); dataOutputStream.flush(); - GamerController.getInstance().removeFriend(frndUN); + //GamerController.getInstance().removeFriend(frndUN); if (FriendProfileController.getFrnd() != null && FriendProfileController.getFrnd().getUsername().equals(frndUN)) frndProfile.getChildren().clear(); @@ -136,7 +133,6 @@ private void unfriend (String frndUN) throws IOException { private void displayFriendProfile (String frndUn) { try { frndProfile.getChildren().clear(); - // TODO: 2/3/2021 FriendProfileController.setFrnd((Gamer) Account.getAccount(frndUn)); frndProfile.getChildren().add(FXMLLoader.load(new File("src/com/plato/View/Menus/FriendProfile.fxml").toURI().toURL())); GridPane.setValignment(frndProfile.getChildren().get(0), VPos.CENTER); diff --git a/src/com/plato/Controller/Server.java b/src/com/plato/Controller/Server.java index f9a5939..8affb9b 100644 --- a/src/com/plato/Controller/Server.java +++ b/src/com/plato/Controller/Server.java @@ -1,9 +1,6 @@ package Controller; -import Controller.AccountRelated.AccountController; -import Controller.AccountRelated.EventController; -import Controller.AccountRelated.GamerController; -import Controller.AccountRelated.MessageController; +import Controller.AccountRelated.*; import Controller.GameRelated.BattleSea.BattleSeaController; import Controller.GameRelated.BattleSea.BombController; import Controller.GameRelated.BattleSea.ShipController; @@ -198,6 +195,15 @@ public void run() { double prize = Double.parseDouble(receivedInfo[4]); EventController.getInstance().createEvent(receivedInfo[1],receivedInfo[2],receivedInfo[3],EventCreateOrEditPageController.getEvent().getStart(), EventCreateOrEditPageController.getEvent().getEnd(),prize,receivedInfo[5]); break; + case "sendFrndRequest": + FriendRequestController.getInstance().sendFrndRequest(receivedInfo[1]); + break; + case "declineFriendReq" : + FriendRequestController.getInstance().declineFriendReq(receivedInfo[1]); + break; + case "acceptFriendReq" : + FriendRequestController.getInstance().acceptFriendReq(receivedInfo[1]); + break; } }catch (IOException | BombController.CoordinateAlreadyBombedException | ReversiController.PlayerHasAlreadyPlacedDiskException | EventController.GameNameCantBeEmptyException e){ System.out.println("connection closed!");