diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 9e985da..278d60b 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -5,33 +5,12 @@ - - - - - - - - - - - - - - - + - - - - - - - - - - - + + + + - + - @@ -1079,7 +1051,7 @@ - + @@ -1118,21 +1090,6 @@ - - - - - - - - - - - - - - - @@ -1203,14 +1160,6 @@ - - - - - - - - @@ -1235,14 +1184,6 @@ - - - - - - - - @@ -1258,19 +1199,11 @@ - + - - - - - - - - @@ -1297,48 +1230,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -1375,30 +1266,12 @@ - - - - - - - - - - - - - - - - - - @@ -1410,16 +1283,6 @@ - - - - - - - - - - @@ -1436,14 +1299,6 @@ - - - - - - - - @@ -1457,7 +1312,7 @@ - + @@ -1517,7 +1372,7 @@ - + @@ -1527,7 +1382,7 @@ - + @@ -1555,10 +1410,18 @@ + + + + + + + + - - + + @@ -1567,6 +1430,126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Client/src/com/texttwist/client/pages/MatchSetup.java b/Client/src/com/texttwist/client/pages/MatchSetup.java index de81b20..4507aaa 100644 --- a/Client/src/com/texttwist/client/pages/MatchSetup.java +++ b/Client/src/com/texttwist/client/pages/MatchSetup.java @@ -2,6 +2,7 @@ package com.texttwist.client.pages; import com.texttwist.client.constants.Palette; import com.texttwist.client.ui.*; +import models.Response; import javax.swing.*; import java.awt.*; @@ -14,16 +15,15 @@ import java.util.concurrent.Callable; public class MatchSetup extends Page{ public TTContainer matchSetupContainer; - MatchSetup(JFrame window) throws IOException { + public MatchSetupController matchSetupController; + + MatchSetup(JFrame window) throws Exception { super(window); + matchSetupController = new MatchSetupController(); createUIComponents(); window.setVisible(true); } - private Callable addUserToInvitationList(){ - return null; - } - //TODO Spostare i metodi di fetches nella classe MatchSetupService per separare MVC private DefaultListModel fetchUsers(){ DefaultListModel usersList = new DefaultListModel(); @@ -48,7 +48,7 @@ public class MatchSetup extends Page{ } @Override - public void createUIComponents() throws IOException { + public void createUIComponents() throws Exception { addLogo(root); matchSetupContainer = new TTContainer( @@ -66,36 +66,12 @@ public class MatchSetup extends Page{ null, matchSetupContainer); - TTLabel playerFinder_flavourText = new TTLabel( - new Point(20,40), - new Dimension(350,50), - "Search players to invite...", - new Font(Palette.inputBox_font.getFontName(), Font.ITALIC, 18), - null, - matchSetupContainer); - TTSearchBar searchUserBar = new TTSearchBar( new Point(20, 80), new Dimension(250, 40), "Username", - new DefaultListModel(), - addUserToInvitationList(), matchSetupContainer); - TTLabel playerToSendInvite_flavourText = new TTLabel( - new Point(305,40), - new Dimension(350,50), - "Click on user for remove it", - new Font(Palette.inputBox_font.getFontName(), Font.ITALIC, 18), - null, - matchSetupContainer); - - TTScrollList playerToSendInvite = new TTScrollList( - new Point(305, 80), - new Dimension(232, 135), - new DefaultListModel(), - matchSetupContainer); - addFooter(root); addNext(footer, new Font(Palette.inputBox_font.getFontName(), Font.BOLD, 40), @@ -104,7 +80,20 @@ public class MatchSetup extends Page{ new Callable() { @Override public Object call() throws Exception { - return new Game(Page.window); + //If server response ok, start play, else error + Response res = matchSetupController.play(searchUserBar.list); + if (res.code == 200){ + //OK, go to next page and show popup + return new Game(Page.window); + } else { + return new TTDialog("alert", res.message, + new Callable() { + @Override + public Object call() throws Exception { + return new MatchSetup(Page.window); + } + },null); + } } }); diff --git a/Client/src/com/texttwist/client/pages/MatchSetupController.java b/Client/src/com/texttwist/client/pages/MatchSetupController.java new file mode 100644 index 0000000..7f6e265 --- /dev/null +++ b/Client/src/com/texttwist/client/pages/MatchSetupController.java @@ -0,0 +1,27 @@ +package com.texttwist.client.pages; + +import com.texttwist.client.App; +import models.Response; + +import javax.swing.*; +import java.net.MalformedURLException; +import java.rmi.NotBoundException; +import java.rmi.RemoteException; + +/** + * Created by loke on 18/06/2017. + */ +public class MatchSetupController { + + public MatchSetupController(){} + public Response play(DefaultListModel userNames) throws RemoteException, NotBoundException, MalformedURLException { + + System.out.print(userNames.toString()); + /* Response res = App.authService.login(userName,password); + if (res.code == 200){ + App.sessionService.create(userName, res.data.get("token").toString()); + }*/ + return null; + } + +} diff --git a/Client/src/com/texttwist/client/pages/Page.java b/Client/src/com/texttwist/client/pages/Page.java index 62f6398..3e01a48 100644 --- a/Client/src/com/texttwist/client/pages/Page.java +++ b/Client/src/com/texttwist/client/pages/Page.java @@ -34,7 +34,7 @@ public class Page { window.add(root); } - public void createUIComponents() throws IOException {} + public void createUIComponents() throws Exception {} public void addLogo(TTContainer parent) { TTContainer container = new TTContainer( diff --git a/Client/src/com/texttwist/client/ui/TTSearchBar.java b/Client/src/com/texttwist/client/ui/TTSearchBar.java index 9c0dbd4..344c42e 100644 --- a/Client/src/com/texttwist/client/ui/TTSearchBar.java +++ b/Client/src/com/texttwist/client/ui/TTSearchBar.java @@ -1,5 +1,7 @@ package com.texttwist.client.ui; import com.texttwist.client.constants.Palette; +import com.texttwist.client.pages.MatchSetup; + import javax.swing.*; import java.awt.*; import java.awt.event.KeyAdapter; @@ -12,34 +14,103 @@ import java.util.concurrent.Callable; /** * Created by loke on 14/06/2017. */ -public class TTSearchBar extends TTInputField{ +public class TTSearchBar extends TTContainer{ private DefaultListModel matchedUsers = new DefaultListModel(); + public DefaultListModel list = new DefaultListModel(); + + private Callable add(TTInputField ctx){ + return new Callable() { + @Override + public Object call() throws Exception { + String username = ctx.getText(); + ctx.setText(""); + list.addElement(username); + return null; + } + }; + } + + public TTSearchBar(Point position, Dimension dimension, String placeholer, - DefaultListModel listModel, - Callable clickHandler, - TTContainer parent){ + TTContainer parent) throws Exception { - super(position, dimension, placeholer, parent); + super(position, dimension, Palette.inputBox_backgroundColor, -1, parent); setBackground(Palette.scrollPanel_backgroundColor); setFont(Palette.inputBox_font); setBounds(position.x, position.y, dimension.width, dimension.height); setPreferredSize(dimension); setForeground(Palette.fontColor); - TTScrollList userList = new TTScrollList( + TTLabel playerFinder_flavourText = new TTLabel( + new Point(20,40), + new Dimension(350,50), + "Player to invite", + new Font(Palette.inputBox_font.getFontName(), Font.ITALIC, 18), + null, + parent); + + TTInputField usernameField = new TTInputField( + new Point(20,80), + new Dimension(250,45), + "Username", + parent); + /* TTScrollList userList = new TTScrollList( new Point(20,120), new Dimension(250,95), matchedUsers, parent - ); + );*/ - addKeyListener(new KeyAdapter() { + TTButton addUser = new TTButton( + new Point(70,140), + new Dimension(150,50), + "Add!", + add(usernameField), + parent); + + + TTLabel playerToSendInvite_flavourText = new TTLabel( + new Point(305,40), + new Dimension(350,50), + "Double-Click on user for remove", + new Font(Palette.inputBox_font.getFontName(), Font.ITALIC, 18), + null, + parent); + + TTScrollList playerToSendInvite = new TTScrollList( + new Point(305, 80), + new Dimension(232, 135), + list, + parent); + + + playerToSendInvite.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent evt) { + super.mouseClicked(evt); + JList thisList = (JList)evt.getSource(); + if (evt.getClickCount() == 2) { + // Double-click detected + int index = thisList.locationToIndex(evt.getPoint()); + list.remove(index); + } + } + }); + + usernameField.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { super.keyPressed(e); + if(e.getKeyCode() == 10){ + try { + add(usernameField).call(); + } catch (Exception e1) { + e1.printStackTrace(); + } + } //Every time i press a key, execute a search of users } }); diff --git a/server.log b/server.log index 19a8a4f..1664219 100644 --- a/server.log +++ b/server.log @@ -768,3 +768,63 @@ LOGGER (Server): Sun Jun 18 14:12:33 CEST 2017 - Server starting ... LOGGER (Server): Sun Jun 18 14:12:33 CEST 2017 - Auth Service running at 9999 port... LOGGER (Server): Sun Jun 18 14:12:33 CEST 2017 - Server started LOGGER (Server): Sun Jun 18 14:12:33 CEST 2017 - Game Service is running at 10000 port... +LOGGER (Server): Sun Jun 18 20:14:59 CEST 2017 - Server starting ... +LOGGER (Server): Sun Jun 18 20:14:59 CEST 2017 - Auth Service running at 9999 port... +LOGGER (Server): Sun Jun 18 20:14:59 CEST 2017 - Server started +LOGGER (Server): Sun Jun 18 20:14:59 CEST 2017 - Game Service is running at 10000 port... +LOGGER (Server): Sun Jun 18 20:16:35 CEST 2017 - Server starting ... +LOGGER (Server): Sun Jun 18 20:16:35 CEST 2017 - Auth Service running at 9999 port... +LOGGER (Server): Sun Jun 18 20:16:35 CEST 2017 - Server started +LOGGER (Server): Sun Jun 18 20:16:35 CEST 2017 - Game Service is running at 10000 port... +LOGGER (Server): Sun Jun 18 20:16:46 CEST 2017 - Invoked register with username=asd AND password=asd +LOGGER (Server): Sun Jun 18 20:16:46 CEST 2017 - Registration successfull +LOGGER (Server): Sun Jun 18 20:16:48 CEST 2017 - Invoked login with username=asd AND password=asd +LOGGER (Server): Sun Jun 18 20:16:48 CEST 2017 - Login successfull +LOGGER (Server): Sun Jun 18 20:21:13 CEST 2017 - Invoked login with username=asd AND password=asd +LOGGER (Server): Sun Jun 18 20:21:13 CEST 2017 - Login successfull +LOGGER (Server): Sun Jun 18 20:24:50 CEST 2017 - Invoked login with username=asd AND password=asd +LOGGER (Server): Sun Jun 18 20:24:50 CEST 2017 - Login successfull +LOGGER (Server): Sun Jun 18 20:25:42 CEST 2017 - Invoked login with username=asd AND password=asd +LOGGER (Server): Sun Jun 18 20:25:43 CEST 2017 - Login successfull +LOGGER (Server): Sun Jun 18 20:30:07 CEST 2017 - Server starting ... +LOGGER (Server): Sun Jun 18 20:30:07 CEST 2017 - Auth Service running at 9999 port... +LOGGER (Server): Sun Jun 18 20:30:07 CEST 2017 - Server started +LOGGER (Server): Sun Jun 18 20:30:07 CEST 2017 - Game Service is running at 10000 port... +LOGGER (Server): Sun Jun 18 20:30:10 CEST 2017 - Invoked register with username=asd AND password=asd +LOGGER (Server): Sun Jun 18 20:30:10 CEST 2017 - Registration successfull +LOGGER (Server): Sun Jun 18 20:30:13 CEST 2017 - Invoked login with username=asd AND password=asd +LOGGER (Server): Sun Jun 18 20:30:13 CEST 2017 - Login successfull +LOGGER (Server): Sun Jun 18 20:33:00 CEST 2017 - Invoked login with username=asd AND password=asd +LOGGER (Server): Sun Jun 18 20:33:00 CEST 2017 - Login successfull +LOGGER (Server): Sun Jun 18 20:35:20 CEST 2017 - Invoked login with username=asd AND password=asd +LOGGER (Server): Sun Jun 18 20:35:20 CEST 2017 - Login successfull +LOGGER (Server): Sun Jun 18 20:48:47 CEST 2017 - Invoked login with username=asd AND password=asd +LOGGER (Server): Sun Jun 18 20:48:47 CEST 2017 - Login successfull +LOGGER (Server): Sun Jun 18 20:50:42 CEST 2017 - Invoked login with username=asd AND password=asd +LOGGER (Server): Sun Jun 18 20:50:42 CEST 2017 - Login successfull +LOGGER (Server): Sun Jun 18 20:52:12 CEST 2017 - Invoked login with username=asd AND password=asd +LOGGER (Server): Sun Jun 18 20:52:12 CEST 2017 - Login successfull +LOGGER (Server): Sun Jun 18 20:52:51 CEST 2017 - Invoked login with username=asd AND password=asd +LOGGER (Server): Sun Jun 18 20:52:51 CEST 2017 - Login successfull +LOGGER (Server): Sun Jun 18 20:53:05 CEST 2017 - Invoked login with username=asd AND password=asd +LOGGER (Server): Sun Jun 18 20:53:05 CEST 2017 - Login successfull +LOGGER (Server): Sun Jun 18 20:54:02 CEST 2017 - Invoked login with username=asd AND password=asd +LOGGER (Server): Sun Jun 18 20:54:02 CEST 2017 - Login successfull +LOGGER (Server): Sun Jun 18 20:54:57 CEST 2017 - Invoked login with username=asd AND password=asd +LOGGER (Server): Sun Jun 18 20:54:57 CEST 2017 - Login successfull +LOGGER (Server): Sun Jun 18 20:56:00 CEST 2017 - Invoked login with username=asd AND password=asd +LOGGER (Server): Sun Jun 18 20:56:00 CEST 2017 - Login successfull +LOGGER (Server): Sun Jun 18 20:59:49 CEST 2017 - Invoked login with username=asd AND password=asd +LOGGER (Server): Sun Jun 18 20:59:49 CEST 2017 - Login successfull +LOGGER (Server): Sun Jun 18 21:00:12 CEST 2017 - Invoked login with username=asd AND password=asd +LOGGER (Server): Sun Jun 18 21:00:12 CEST 2017 - Login successfull +LOGGER (Server): Sun Jun 18 21:03:01 CEST 2017 - Server starting ... +LOGGER (Server): Sun Jun 18 21:03:01 CEST 2017 - Auth Service running at 9999 port... +LOGGER (Server): Sun Jun 18 21:03:01 CEST 2017 - Server started +LOGGER (Server): Sun Jun 18 21:03:01 CEST 2017 - Game Service is running at 10000 port... +LOGGER (Server): Sun Jun 18 21:03:07 CEST 2017 - Invoked register with username=asd AND password=asd +LOGGER (Server): Sun Jun 18 21:03:07 CEST 2017 - Registration successfull +LOGGER (Server): Sun Jun 18 21:03:09 CEST 2017 - Invoked login with username=asd AND password=asd +LOGGER (Server): Sun Jun 18 21:03:09 CEST 2017 - Login successfull +LOGGER (Server): Sun Jun 18 21:13:00 CEST 2017 - Invoked login with username=asd AND password=asd +LOGGER (Server): Sun Jun 18 21:13:00 CEST 2017 - Login successfull