From dd05626f7b92105de9f1e0d978a669417aa89d4c Mon Sep 17 00:00:00 2001 From: CorCor Date: Wed, 3 Aug 2016 18:03:10 +0300 Subject: [PATCH] Added connection to room via Steam. Awfully glitchy. --- .../seroperson/mediator/MediatorDesktop.java | 21 +++++++++- .../mediator/tori/stuff/Global.java | 1 + .../seroperson/mediator/utils/Connector.java | 22 ++++++++++ .../mediator/viewer/ServerViewer.java | 41 +++++++++++-------- 4 files changed, 67 insertions(+), 18 deletions(-) create mode 100644 tMediator/src/com/seroperson/mediator/utils/Connector.java diff --git a/tMediator-desktop/src/com/seroperson/mediator/MediatorDesktop.java b/tMediator-desktop/src/com/seroperson/mediator/MediatorDesktop.java index 3488af6..afeefd2 100644 --- a/tMediator-desktop/src/com/seroperson/mediator/MediatorDesktop.java +++ b/tMediator-desktop/src/com/seroperson/mediator/MediatorDesktop.java @@ -3,10 +3,14 @@ import java.awt.Frame; import java.awt.TrayIcon; import java.awt.TrayIcon.MessageType; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; import javax.swing.JFrame; import com.seroperson.mediator.tori.stuff.Global; +import com.seroperson.mediator.tori.stuff.Server; +import com.seroperson.mediator.utils.Connector; public class MediatorDesktop extends Mediator { @@ -50,7 +54,22 @@ public void handleThrow(final Throwable t) { @Override public void handleGlobal(Global g) { - tray.displayMessage(new StringBuilder("tMediator | Ingame broadcast by ").append(g.getPlayer()).toString(), g.getMessage(), MessageType.INFO); + final Server server = getServerByRoom(g.getServer()); + if (server != null) + { + tray.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + try { + Connector.connectToServer(server); + } + catch (Exception ex) { + System.err.println(ex.getMessage()); + } + } + }); + tray.displayMessage(new StringBuilder("tMediator | Ingame broadcast by ").append(g.getPlayer()).toString(), g.getMessage(), MessageType.INFO); + } } } diff --git a/tMediator/src/com/seroperson/mediator/tori/stuff/Global.java b/tMediator/src/com/seroperson/mediator/tori/stuff/Global.java index 0285822..ce04ad7 100644 --- a/tMediator/src/com/seroperson/mediator/tori/stuff/Global.java +++ b/tMediator/src/com/seroperson/mediator/tori/stuff/Global.java @@ -18,6 +18,7 @@ public String getMessage() { return message; } + //ToDo: what about returning a Server and not a String? public String getServer() { return server; } diff --git a/tMediator/src/com/seroperson/mediator/utils/Connector.java b/tMediator/src/com/seroperson/mediator/utils/Connector.java new file mode 100644 index 0000000..29046c8 --- /dev/null +++ b/tMediator/src/com/seroperson/mediator/utils/Connector.java @@ -0,0 +1,22 @@ +package com.seroperson.mediator.utils; + +import com.seroperson.mediator.tori.stuff.Server; + +import java.awt.*; +import java.net.URI; + +public class Connector { + public static void connectToServer(Server server) + { + final String room = server.getRoom(); + if (!room.equals("unknown room")) { + try { + final String uri = "steam://run/248570//+connect%20join%20" + room; + System.out.println(uri); + Desktop.getDesktop().browse(new URI(uri)); + } catch (Exception ex) { + System.err.println(ex.getMessage()); + } + } + } +} diff --git a/tMediator/src/com/seroperson/mediator/viewer/ServerViewer.java b/tMediator/src/com/seroperson/mediator/viewer/ServerViewer.java index 972cc70..5732a2a 100644 --- a/tMediator/src/com/seroperson/mediator/viewer/ServerViewer.java +++ b/tMediator/src/com/seroperson/mediator/viewer/ServerViewer.java @@ -1,9 +1,6 @@ package com.seroperson.mediator.viewer; -import java.awt.BorderLayout; -import java.awt.Container; -import java.awt.Dimension; -import java.awt.Toolkit; +import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.WindowAdapter; @@ -11,15 +8,7 @@ import java.util.ArrayList; import java.util.List; -import javax.swing.Box; -import javax.swing.JButton; -import javax.swing.JFrame; -import javax.swing.JLabel; -import javax.swing.JScrollPane; -import javax.swing.JSplitPane; -import javax.swing.JTabbedPane; -import javax.swing.ScrollPaneConstants; -import javax.swing.WindowConstants; +import javax.swing.*; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; @@ -28,6 +17,7 @@ import com.badlogic.gdx.utils.ObjectMap.Values; import com.seroperson.mediator.tori.stuff.Player; import com.seroperson.mediator.tori.stuff.Server; +import com.seroperson.mediator.utils.Connector; public class ServerViewer extends JFrame { @@ -49,9 +39,9 @@ public ServerViewer(final ServerViewerContainer con) { setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); setVisible(true); - setResizable(false); - setLocation(d.width / 2-480/2/2, d.height / 2-480/2/2); - setSize(480 / 2, 480 / 2); + setResizable(true); + setLocation(d.width / 2-480/2/2, d.height / 2-640/2/2); + setSize(480 / 2, 640 / 2); addWindowListener(getWindowListener()); final Container c = getContentPane(); @@ -88,6 +78,8 @@ public void stateChanged(final ChangeEvent e) { jsp = new JSplitPane(JSplitPane.VERTICAL_SPLIT, infoPanel, jsps); jsp.setContinuousLayout(false); + JPanel p = new JPanel(new BorderLayout()); + final JButton close = new JButton("Close"); close.addActionListener(new ActionListener() { @@ -110,9 +102,24 @@ public void actionPerformed(final ActionEvent e) { }); + final JButton connect = new JButton("Connect"); + connect.addActionListener(new ActionListener() { + + @Override + public void actionPerformed(final ActionEvent e) { + final Server server = servers.get(indexmap.get(tabbedpane.getSelectedIndex())); + if (server.getPlayers().length > 0) + { + Connector.connectToServer(server); + } + } + }); + + p.add(connect, BorderLayout.NORTH); + p.add(close, BorderLayout.SOUTH); c.add(jsp, BorderLayout.CENTER); c.add(tabbedpane, BorderLayout.NORTH); - c.add(close, BorderLayout.SOUTH); + c.add(p, BorderLayout.SOUTH); }