Skip to content

Commit

Permalink
Added connection to room via Steam. Awfully glitchy.
Browse files Browse the repository at this point in the history
  • Loading branch information
al-arz committed Aug 3, 2016
1 parent eccfd4c commit dd05626
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public String getMessage() {
return message;
}

//ToDo: what about returning a Server and not a String?
public String getServer() {
return server;
}
Expand Down
22 changes: 22 additions & 0 deletions tMediator/src/com/seroperson/mediator/utils/Connector.java
Original file line number Diff line number Diff line change
@@ -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());
}
}
}
}
41 changes: 24 additions & 17 deletions tMediator/src/com/seroperson/mediator/viewer/ServerViewer.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,14 @@
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;
import java.awt.event.WindowEvent;
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;

Expand All @@ -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 {

Expand All @@ -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();
Expand Down Expand Up @@ -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() {

Expand All @@ -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);

}

Expand Down

0 comments on commit dd05626

Please sign in to comment.